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.RemoteException;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
@ -43,6 +44,7 @@ import java.util.LinkedList;
*/
public class KeyguardExternalView extends View implements ViewTreeObserver.OnPreDrawListener,
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
@ -107,29 +109,45 @@ public class KeyguardExternalView extends View implements ViewTreeObserver.OnPre
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
try {
mExternalViewProvider = IKeyguardExternalViewProvider.Stub.asInterface(
IExternalViewProviderFactory.Stub.asInterface(service).
createExternalView(null));
mExternalViewProvider.registerCallback(
KeyguardExternalView.this.mKeyguardExternalViewCallbacks);
mService = service;
mService.linkToDeath(KeyguardExternalView.this, 0);
executeQueue();
IExternalViewProviderFactory factory = IExternalViewProviderFactory.Stub.asInterface(service);
if (factory != null) {
mExternalViewProvider = IKeyguardExternalViewProvider.Stub.asInterface(
factory.createExternalView(null));
if (mExternalViewProvider != null) {
mExternalViewProvider.registerCallback(
KeyguardExternalView.this.mKeyguardExternalViewCallbacks);
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) {
e.printStackTrace();
}
// We should unbind the service if we failed to connect to the provider
if (mService != service && service != null) {
mContext.unbindService(mServiceConnection);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
try {
mExternalViewProvider.unregisterCallback(
KeyguardExternalView.this.mKeyguardExternalViewCallbacks);
} catch (RemoteException e) {
if (mExternalViewProvider != null) {
try {
mExternalViewProvider.unregisterCallback(
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;
}
};