From 1e33dc8fdf3f722ecd32cc586b2a9515de24a242 Mon Sep 17 00:00:00 2001 From: Fyodor Kupolov Date: Thu, 21 Jan 2016 12:02:58 -0800 Subject: [PATCH] Use SystemService lifecycle API in input method service Change-Id: Ic17667df60b30e5355b61a3601ad27a000cab3a3 --- .../server/InputMethodManagerService.java | 26 ++++++++++++++++++- .../java/com/android/server/SystemServer.java | 16 +----------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java index 798a04aaeee7a..4a123df997205 100644 --- a/services/core/java/com/android/server/InputMethodManagerService.java +++ b/services/core/java/com/android/server/InputMethodManagerService.java @@ -742,6 +742,31 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } + public static final class Lifecycle extends SystemService { + private InputMethodManagerService mService; + + public Lifecycle(Context context) { + super(context); + mService = new InputMethodManagerService(context); + } + + @Override + public void onStart() { + LocalServices.addService(InputMethodManagerInternal.class, + new LocalServiceImpl(mService.mHandler)); + publishBinderService(Context.INPUT_METHOD_SERVICE, mService); + } + + @Override + public void onBootPhase(int phase) { + if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { + StatusBarManagerService statusBarService = (StatusBarManagerService) ServiceManager + .getService(Context.STATUS_BAR_SERVICE); + mService.systemRunning(statusBarService); + } + } + } + public InputMethodManagerService(Context context) { mIPackageManager = AppGlobals.getPackageManager(); mContext = context; @@ -894,7 +919,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } }, filter); - LocalServices.addService(InputMethodManagerInternal.class, new LocalServiceImpl(mHandler)); } private void resetDefaultImeLocked(Context context) { diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 7ce945bf933e3..1f818e42d9ca4 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -570,7 +570,6 @@ public final class SystemServer { StatusBarManagerService statusBar = null; INotificationManager notification = null; - InputMethodManagerService imm = null; WallpaperManagerService wallpaper = null; LocationManagerService location = null; CountryDetectorService countryDetector = null; @@ -581,14 +580,7 @@ public final class SystemServer { // Bring up services needed for UI. if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { - traceBeginAndSlog("StartInputMethodManagerService"); - try { - imm = new InputMethodManagerService(context); - ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm); - } catch (Throwable e) { - reportWtf("starting Input Manager Service", e); - } - Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); + mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class); traceBeginAndSlog("StartAccessibilityManagerService"); try { @@ -1167,7 +1159,6 @@ public final class SystemServer { final ConnectivityService connectivityF = connectivity; final NetworkScoreService networkScoreF = networkScore; final WallpaperManagerService wallpaperF = wallpaper; - final InputMethodManagerService immF = imm; final LocationManagerService locationF = location; final CountryDetectorService countryDetectorF = countryDetector; final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater; @@ -1263,11 +1254,6 @@ public final class SystemServer { } catch (Throwable e) { reportWtf("Notifying WallpaperService running", e); } - try { - if (immF != null) immF.systemRunning(statusBarF); - } catch (Throwable e) { - reportWtf("Notifying InputMethodService running", e); - } try { if (locationF != null) locationF.systemRunning(); } catch (Throwable e) {