From f58b595b6f25ceb57163e23c829996e2818494e1 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Sat, 30 May 2015 18:29:55 +0200 Subject: [PATCH] cmsdk: do not crash system if CustomTileListenerService isn't present Change-Id: I786f3e791f0fe9fad12cc48846b6d4f8687dff8c JIRA: NIGHTLIES-1249 Signed-off-by: Jorge Ruesga --- .../cyanogenmod/app/CMStatusBarManager.java | 7 ++++-- .../app/CustomTileListenerService.java | 23 +++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/java/cyanogenmod/app/CMStatusBarManager.java b/src/java/cyanogenmod/app/CMStatusBarManager.java index 481be29e..efc841c3 100644 --- a/src/java/cyanogenmod/app/CMStatusBarManager.java +++ b/src/java/cyanogenmod/app/CMStatusBarManager.java @@ -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; } } diff --git a/src/java/cyanogenmod/app/CustomTileListenerService.java b/src/java/cyanogenmod/app/CustomTileListenerService.java index 9d2929ab..ea99da95 100644 --- a/src/java/cyanogenmod/app/CustomTileListenerService.java +++ b/src/java/cyanogenmod/app/CustomTileListenerService.java @@ -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; }