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,29 +109,45 @@ 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 {
mExternalViewProvider = IKeyguardExternalViewProvider.Stub.asInterface( IExternalViewProviderFactory factory = IExternalViewProviderFactory.Stub.asInterface(service);
IExternalViewProviderFactory.Stub.asInterface(service). if (factory != null) {
createExternalView(null)); mExternalViewProvider = IKeyguardExternalViewProvider.Stub.asInterface(
mExternalViewProvider.registerCallback( factory.createExternalView(null));
KeyguardExternalView.this.mKeyguardExternalViewCallbacks); if (mExternalViewProvider != null) {
mService = service; mExternalViewProvider.registerCallback(
mService.linkToDeath(KeyguardExternalView.this, 0); KeyguardExternalView.this.mKeyguardExternalViewCallbacks);
executeQueue(); mService = service;
mService.linkToDeath(KeyguardExternalView.this, 0);
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) {
try { if (mExternalViewProvider != null) {
mExternalViewProvider.unregisterCallback( try {
KeyguardExternalView.this.mKeyguardExternalViewCallbacks); mExternalViewProvider.unregisterCallback(
} catch (RemoteException e) { KeyguardExternalView.this.mKeyguardExternalViewCallbacks);
} catch (RemoteException e) {
}
mExternalViewProvider = null;
}
if (mService != null) {
mService.unlinkToDeath(KeyguardExternalView.this, 0);
mService = null;
} }
mExternalViewProvider = null;
mService.unlinkToDeath(KeyguardExternalView.this, 0);
mService = null;
} }
}; };