cmsdk: do not crash system if CustomTileListenerService isn't present

Change-Id: I786f3e791f0fe9fad12cc48846b6d4f8687dff8c
JIRA: NIGHTLIES-1249
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
This commit is contained in:
Jorge Ruesga 2015-05-30 18:29:55 +02:00 committed by Adnan Begovic
parent 3f7e428fdd
commit f58b595b6f
2 changed files with 19 additions and 11 deletions

View File

@ -231,7 +231,10 @@ public class CMStatusBarManager {
return sService;
}
IBinder b = ServiceManager.getService(CMContextConstants.CM_STATUS_BAR_SERVICE);
sService = ICMStatusBarManager.Stub.asInterface(b);
return sService;
if (b != null) {
sService = ICMStatusBarManager.Stub.asInterface(b);
return sService;
}
return null;
}
}

View File

@ -91,12 +91,15 @@ public class CustomTileListenerService extends Service {
*/
public void registerAsSystemService(Context context, ComponentName componentName,
int currentUser) throws RemoteException {
if (mWrapper == null) {
mWrapper = new ICustomTileListenerWrapper();
if (isBound()) {
return;
}
ICMStatusBarManager statusBarInterface = mStatusBarService;
if (mStatusBarService != null) {
mWrapper = new ICustomTileListenerWrapper();
statusBarInterface.registerListener(mWrapper, componentName, currentUser);
mCurrentUser = currentUser;
}
ICMStatusBarManager statusBarInterface = getStatusBarInterface();
statusBarInterface.registerListener(mWrapper, componentName, currentUser);
mCurrentUser = currentUser;
}
/**
@ -107,9 +110,11 @@ public class CustomTileListenerService extends Service {
* @hide
*/
public void unregisterAsSystemService() throws RemoteException {
if (mWrapper != null) {
ICMStatusBarManager statusBarInterface = getStatusBarInterface();
if (isBound()) {
ICMStatusBarManager statusBarInterface = mStatusBarService;
statusBarInterface.unregisterListener(mWrapper, mCurrentUser);
mWrapper = null;
mStatusBarService = null;
}
}
@ -210,7 +215,7 @@ public class CustomTileListenerService extends Service {
public final void removeCustomTile(String pkg, String tag, int id) {
if (!isBound()) return;
try {
getStatusBarInterface().removeCustomTileFromListener(
mStatusBarService.removeCustomTileFromListener(
mWrapper, pkg, tag, id);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact cmstautusbar manager", ex);
@ -218,7 +223,7 @@ public class CustomTileListenerService extends Service {
}
private boolean isBound() {
if (mWrapper == null) {
if (mWrapper == null || getStatusBarInterface() == null) {
Log.w(TAG, "CustomTile listener service not yet bound.");
return false;
}