From 141417ac2977b1f2e288a94cdb508e8049966702 Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Mon, 28 Oct 2019 11:12:48 -0700 Subject: [PATCH] Refactor LMS to use SystemService Adopt SystemService based initialization for LocationManagerService. No behavioral changes, just adopts the existing initialization framework for LMS. Test: manual Change-Id: Ic03e5e3fdacb1d3d79e7ba739b673a1c6146c673 --- .../server/LocationManagerService.java | 31 +++++++++++++++++-- .../java/com/android/server/SystemServer.java | 19 +----------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index 0a63bf89b21f7..b870444fc819e 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -128,6 +128,32 @@ import java.util.concurrent.TimeUnit; * updates and alerts. */ public class LocationManagerService extends ILocationManager.Stub { + + /** + * Controls lifecycle of LocationManagerService. + */ + public static class Lifecycle extends SystemService { + + private LocationManagerService mService; + + public Lifecycle(Context context) { + super(context); + mService = new LocationManagerService(context); + } + + @Override + public void onStart() { + publishBinderService(Context.LOCATION_SERVICE, mService); + } + + @Override + public void onBootPhase(int phase) { + if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { + mService.systemRunning(); + } + } + } + private static final String TAG = "LocationManagerService"; public static final boolean D = Log.isLoggable(TAG, Log.DEBUG); @@ -234,8 +260,7 @@ public class LocationManagerService extends ILocationManager.Stub { @GuardedBy("mLock") private final LocationUsageLogger mLocationUsageLogger; - public LocationManagerService(Context context) { - super(); + private LocationManagerService(Context context) { mContext = context; mHandler = FgThread.getHandler(); mLocationUsageLogger = new LocationUsageLogger(); @@ -254,7 +279,7 @@ public class LocationManagerService extends ILocationManager.Stub { // most startup is deferred until systemRunning() } - public void systemRunning() { + private void systemRunning() { synchronized (mLock) { initializeLocked(); } diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 58830487a0feb..3973790612656 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -1133,7 +1133,6 @@ public final class SystemServer { StatusBarManagerService statusBar = null; INotificationManager notification = null; - LocationManagerService location = null; CountryDetectorService countryDetector = null; ILockSettings lockSettings = null; MediaRouterService mediaRouter = null; @@ -1430,12 +1429,7 @@ public final class SystemServer { t.traceEnd(); t.traceBegin("StartLocationManagerService"); - try { - location = new LocationManagerService(context); - ServiceManager.addService(Context.LOCATION_SERVICE, location); - } catch (Throwable e) { - reportWtf("starting Location Manager", e); - } + mSystemServiceManager.startService(LocationManagerService.Lifecycle.class); t.traceEnd(); t.traceBegin("StartCountryDetectorService"); @@ -2019,7 +2013,6 @@ public final class SystemServer { final NetworkStatsService networkStatsF = networkStats; final NetworkPolicyManagerService networkPolicyF = networkPolicy; final ConnectivityService connectivityF = connectivity; - final LocationManagerService locationF = location; final CountryDetectorService countryDetectorF = countryDetector; final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater; final InputManagerService inputManagerF = inputManager; @@ -2175,16 +2168,6 @@ public final class SystemServer { } t.traceEnd(); - - t.traceBegin("MakeLocationServiceReady"); - try { - if (locationF != null) { - locationF.systemRunning(); - } - } catch (Throwable e) { - reportWtf("Notifying Location Service running", e); - } - t.traceEnd(); t.traceBegin("MakeCountryDetectionServiceReady"); try { if (countryDetectorF != null) {