ExtViews: Guard against bad LLS providers

Add checks in onServiceConnected to make sure the provider was
created correctly and if not, log it and move on without imploding
the universe.

Change-Id: I6929a02631685636e2c52c2d6d13883f0c3a13c4
TICKET: CNYNGOS-2217
This commit is contained in:
d34d 2016-03-08 18:27:29 -08:00 committed by Gerrit Code Review
parent 2f2d432495
commit 32788b0555

View File

@ -28,6 +28,7 @@ import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.WindowManager; import android.view.WindowManager;
@ -43,6 +44,7 @@ import java.util.LinkedList;
*/ */
public class KeyguardExternalView extends View implements ViewTreeObserver.OnPreDrawListener, public class KeyguardExternalView extends View implements ViewTreeObserver.OnPreDrawListener,
IBinder.DeathRecipient { IBinder.DeathRecipient {
private static final String TAG = KeyguardExternalView.class.getSimpleName();
/** /**
* An extra passed via an intent that provides a list of permissions that should be requested * An extra passed via an intent that provides a list of permissions that should be requested
@ -107,30 +109,46 @@ public class KeyguardExternalView extends View implements ViewTreeObserver.OnPre
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
try { try {
IExternalViewProviderFactory factory = IExternalViewProviderFactory.Stub.asInterface(service);
if (factory != null) {
mExternalViewProvider = IKeyguardExternalViewProvider.Stub.asInterface( mExternalViewProvider = IKeyguardExternalViewProvider.Stub.asInterface(
IExternalViewProviderFactory.Stub.asInterface(service). factory.createExternalView(null));
createExternalView(null)); if (mExternalViewProvider != null) {
mExternalViewProvider.registerCallback( mExternalViewProvider.registerCallback(
KeyguardExternalView.this.mKeyguardExternalViewCallbacks); KeyguardExternalView.this.mKeyguardExternalViewCallbacks);
mService = service; mService = service;
mService.linkToDeath(KeyguardExternalView.this, 0); mService.linkToDeath(KeyguardExternalView.this, 0);
executeQueue(); executeQueue();
} else {
Log.e(TAG, "Unable to get external view provider");
}
} else {
Log.e(TAG, "Unable to get external view provider factory");
}
} catch (RemoteException e) { } catch (RemoteException e) {
e.printStackTrace(); e.printStackTrace();
} }
// We should unbind the service if we failed to connect to the provider
if (mService != service && service != null) {
mContext.unbindService(mServiceConnection);
}
} }
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
if (mExternalViewProvider != null) {
try { try {
mExternalViewProvider.unregisterCallback( mExternalViewProvider.unregisterCallback(
KeyguardExternalView.this.mKeyguardExternalViewCallbacks); KeyguardExternalView.this.mKeyguardExternalViewCallbacks);
} catch (RemoteException e) { } catch (RemoteException e) {
} }
mExternalViewProvider = null; mExternalViewProvider = null;
}
if (mService != null) {
mService.unlinkToDeath(KeyguardExternalView.this, 0); mService.unlinkToDeath(KeyguardExternalView.this, 0);
mService = null; mService = null;
} }
}
}; };
private final IKeyguardExternalViewCallbacks mKeyguardExternalViewCallbacks = private final IKeyguardExternalViewCallbacks mKeyguardExternalViewCallbacks =