Make SystemService constructor take a Context.

This change simplifies the process of initializing a SystemService
by folding the onCreate() step back into the constructor.  It removes
some ambuiguity about what work should happen in the constructor and
should make it possible for services to retain most of their final
fields after refactoring into the new pattern.

Change-Id: I25f41af0321bc01898658ab44b369f9c5d16800b
diff --git a/core/java/com/android/server/SystemService.java b/core/java/com/android/server/SystemService.java
index d69293a..0c89f94 100644
--- a/core/java/com/android/server/SystemService.java
+++ b/core/java/com/android/server/SystemService.java
@@ -23,24 +23,24 @@
 /**
  * The base class for services running in the system process. Override and implement
  * the lifecycle event callback methods as needed.
- *
+ * <p>
  * The lifecycle of a SystemService:
- *
- * {@link #onCreate(android.content.Context)} is called to initialize the
- * service.
- *
- * {@link #onStart()} is called to get the service running. It is common
- * for services to publish their Binder interface at this point. All required
- * dependencies are also assumed to be ready to use.
- *
- * Then {@link #onBootPhase(int)} is called as many times as there are boot phases
+ * </p><ul>
+ * <li>The constructor is called and provided with the system {@link Context}
+ * to initialize the system service.
+ * <li>{@link #onStart()} is called to get the service running.  The service should
+ * publish its binder interface at this point using
+ * {@link #publishBinderService(String, IBinder)}.  It may also publish additional
+ * local interfaces that other services within the system server may use to access
+ * privileged internal functions.
+ * <li>Then {@link #onBootPhase(int)} is called as many times as there are boot phases
  * until {@link #PHASE_BOOT_COMPLETE} is sent, which is the last boot phase. Each phase
  * is an opportunity to do special work, like acquiring optional service dependencies,
  * waiting to see if SafeMode is enabled, or registering with a service that gets
  * started after this one.
- *
- * NOTE: All lifecycle methods are called from the same thread that created the
- * SystemService.
+ * </ul><p>
+ * NOTE: All lifecycle methods are called from the system server's main looper thread.
+ * </p>
  *
  * {@hide}
  */
@@ -54,17 +54,34 @@
     public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;
     public static final int PHASE_BOOT_COMPLETE = 1000;
 
-    private SystemServiceManager mManager;
-    private Context mContext;
+    private final Context mContext;
 
-    final void init(Context context, SystemServiceManager manager) {
+    /**
+     * Initializes the system service.
+     * <p>
+     * Subclasses must define a single argument constructor that accepts the context
+     * and passes it to super.
+     * </p>
+     *
+     * @param context The system server context.
+     */
+    public SystemService(Context context) {
         mContext = context;
-        mManager = manager;
-        onCreate(context);
     }
 
+    /**
+     * Gets the system context.
+     */
+    public final Context getContext() {
+        return mContext;
+    }
+
+    /**
+     * Returns true if the system is running in safe mode.
+     * TODO: we should define in which phase this becomes valid
+     */
     public final boolean isSafeMode() {
-        return mManager.isSafeMode();
+        return getManager().isSafeMode();
     }
 
     /**
@@ -126,8 +143,8 @@
         return LocalServices.getService(type);
     }
 
-    public final Context getContext() {
-        return mContext;
+    private SystemServiceManager getManager() {
+        return LocalServices.getService(SystemServiceManager.class);
     }
 
 //    /**
diff --git a/core/java/com/android/server/SystemServiceManager.java b/core/java/com/android/server/SystemServiceManager.java
index 06ad7f4..6c853be 100644
--- a/core/java/com/android/server/SystemServiceManager.java
+++ b/core/java/com/android/server/SystemServiceManager.java
@@ -17,14 +17,15 @@
 package com.android.server;
 
 import android.content.Context;
-import android.util.Log;
 import android.util.Slog;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 
 /**
  * Manages creating, starting, and other lifecycle events of
- * {@link com.android.server.SystemService}s.
+ * {@link com.android.server.SystemService system services}.
  *
  * {@hide}
  */
@@ -68,24 +69,43 @@
      */
     @SuppressWarnings("unchecked")
     public <T extends SystemService> T startService(Class<T> serviceClass) {
-        final T serviceInstance = (T)createInstance(serviceClass);
+        final String name = serviceClass.getName();
+        Slog.i(TAG, "Starting " + name);
+
+        // Create the service.
+        if (!SystemService.class.isAssignableFrom(serviceClass)) {
+            throw new RuntimeException("Failed to create " + name
+                    + ": service must extend " + SystemService.class.getName());
+        }
+        final T service;
         try {
-            Slog.i(TAG, "Creating " + serviceClass.getSimpleName());
-            serviceInstance.init(mContext, this);
-        } catch (Throwable e) {
-            throw new RuntimeException("Failed to create service " + serviceClass.getName(), e);
+            Constructor<T> constructor = serviceClass.getConstructor(Context.class);
+            service = constructor.newInstance(mContext);
+        } catch (InstantiationException ex) {
+            throw new RuntimeException("Failed to create service " + name
+                    + ": service could not be instantiated", ex);
+        } catch (IllegalAccessException ex) {
+            throw new RuntimeException("Failed to create service " + name
+                    + ": service must have a public constructor with a Context argument", ex);
+        } catch (NoSuchMethodException ex) {
+            throw new RuntimeException("Failed to create service " + name
+                    + ": service must have a public constructor with a Context argument", ex);
+        } catch (InvocationTargetException ex) {
+            throw new RuntimeException("Failed to create service " + name
+                    + ": service constructor threw an exception", ex);
         }
 
-        mServices.add(serviceInstance);
+        // Register it.
+        mServices.add(service);
 
+        // Start it.
         try {
-            Slog.i(TAG, "Starting " + serviceClass.getSimpleName());
-            serviceInstance.onStart();
-        } catch (Throwable e) {
-            throw new RuntimeException("Failed to start service " + serviceClass.getName(), e);
+            service.onStart();
+        } catch (RuntimeException ex) {
+            throw new RuntimeException("Failed to start service " + name
+                    + ": onStart threw an exception", ex);
         }
-
-        return serviceInstance;
+        return service;
     }
 
     /**
@@ -107,9 +127,11 @@
             final SystemService service = mServices.get(i);
             try {
                 service.onBootPhase(mCurrentPhase);
-            } catch (Throwable e) {
-                reportWtf("Service " + service.getClass().getName() +
-                        " threw an Exception processing boot phase " + mCurrentPhase, e);
+            } catch (Exception ex) {
+                throw new RuntimeException("Failed to boot service "
+                        + service.getClass().getName()
+                        + ": onBootPhase threw an exception during phase "
+                        + mCurrentPhase, ex);
             }
         }
     }
@@ -144,34 +166,4 @@
 
         Slog.e(TAG, builder.toString());
     }
-
-    private SystemService createInstance(Class<?> clazz) {
-        // Make sure it's a type we expect
-        if (!SystemService.class.isAssignableFrom(clazz)) {
-            reportWtf("Class " + clazz.getName() + " does not extend " +
-                    SystemService.class.getName());
-        }
-
-        try {
-            return (SystemService) clazz.newInstance();
-        } catch (InstantiationException e) {
-            reportWtf("Class " + clazz.getName() + " is abstract", e);
-        } catch (IllegalAccessException e) {
-            reportWtf("Class " + clazz.getName() +
-                    " must have a public no-arg constructor", e);
-        }
-        return null;
-    }
-
-    private static void reportWtf(String message) {
-        reportWtf(message, null);
-    }
-
-    private static void reportWtf(String message, Throwable e) {
-        Slog.i(TAG, "******************************");
-        Log.wtf(TAG, message, e);
-
-        // Make sure we die
-        throw new RuntimeException(message, e);
-    }
 }
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetService.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetService.java
index 3378e3d..e208677 100644
--- a/services/appwidget/java/com/android/server/appwidget/AppWidgetService.java
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetService.java
@@ -53,13 +53,13 @@
 
     static final String TAG = "AppWidgetService";
 
-    Context mContext;
-    Handler mSaveStateHandler;
+    final Context mContext;
+    final Handler mSaveStateHandler;
 
-    SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
+    final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
 
-    @Override
-    public void onCreate(Context context) {
+    public AppWidgetService(Context context) {
+        super(context);
         mContext = context;
 
         mSaveStateHandler = BackgroundThread.getHandler();
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
index c6dc5e6..ca2f7b1 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/BackupManagerService.java
@@ -274,6 +274,20 @@
     // Watch the device provisioning operation during setup
     ContentObserver mProvisionedObserver;
 
+    public static final class Lifecycle extends SystemService {
+        private final BackupManagerService mService;
+
+        public Lifecycle(Context context) {
+            super(context);
+            mService = new BackupManagerService(context);
+        }
+
+        @Override
+        public void onStart() {
+            publishBinderService(Context.BACKUP_SERVICE, mService);
+        }
+    }
+
     class ProvisionedObserver extends ContentObserver {
         public ProvisionedObserver(Handler handler) {
             super(handler);
diff --git a/services/backup/java/com/android/server/backup/BackupManagerSystemService.java b/services/backup/java/com/android/server/backup/BackupManagerSystemService.java
deleted file mode 100644
index db2c94a..0000000
--- a/services/backup/java/com/android/server/backup/BackupManagerSystemService.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.backup;
-
-import android.content.Context;
-
-import com.android.server.SystemService;
-
-public class BackupManagerSystemService extends SystemService {
-    private BackupManagerService mBackupManagerImpl;
-
-    @Override
-    public void onCreate(Context context) {
-        mBackupManagerImpl = new BackupManagerService(context);
-    }
-
-    @Override
-    public void onStart() {
-        publishBinderService(Context.BACKUP_SERVICE, mBackupManagerImpl);
-    }
-}
-
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java
index 3cdf170..96063d5 100644
--- a/services/core/java/com/android/server/AlarmManagerService.java
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -319,6 +319,10 @@
     static final BatchTimeOrder sBatchOrder = new BatchTimeOrder();
     final ArrayList<Batch> mAlarmBatches = new ArrayList<Batch>();
 
+    public AlarmManagerService(Context context) {
+        super(context);
+    }
+
     static long convertToElapsed(long when, int type) {
         final boolean isRtc = (type == RTC || type == RTC_WAKEUP);
         if (isRtc) {
diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java
index de912dc..ad693d0 100644
--- a/services/core/java/com/android/server/UiModeManagerService.java
+++ b/services/core/java/com/android/server/UiModeManagerService.java
@@ -88,6 +88,10 @@
 
     private PowerManager.WakeLock mWakeLock;
 
+    public UiModeManagerService(Context context) {
+        super(context);
+    }
+
     private static Intent buildHomeIntent(String category) {
         Intent intent = new Intent(Intent.ACTION_MAIN);
         intent.addCategory(category);
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 74e18c0..46891f5 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1866,11 +1866,11 @@
         }
     }
 
-    public static class Lifecycle extends SystemService {
-        private ActivityManagerService mService;
+    public static final class Lifecycle extends SystemService {
+        private final ActivityManagerService mService;
 
-        @Override
-        public void onCreate(Context context) {
+        public Lifecycle(Context context) {
+            super(context);
             mService = new ActivityManagerService(context);
         }
 
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index d5ee838..6be6405 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -124,7 +124,7 @@
     private static final int DISPLAY_BLANK_STATE_BLANKED = 1;
     private static final int DISPLAY_BLANK_STATE_UNBLANKED = 2;
 
-    private Context mContext;
+    private final Context mContext;
     private final DisplayManagerHandler mHandler;
     private final Handler mUiHandler;
     private final DisplayAdapterListener mDisplayAdapterListener;
@@ -208,7 +208,9 @@
     private final DisplayViewport mTempDefaultViewport = new DisplayViewport();
     private final DisplayViewport mTempExternalTouchViewport = new DisplayViewport();
 
-    public DisplayManagerService() {
+    public DisplayManagerService(Context context) {
+        super(context);
+        mContext = context;
         mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
         mUiHandler = UiThread.getHandler();
         mDisplayAdapterListener = new DisplayAdapterListener();
@@ -216,11 +218,6 @@
     }
 
     @Override
-    public void onCreate(Context context) {
-        mContext = context;
-    }
-
-    @Override
     public void onStart() {
         mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER);
 
diff --git a/services/core/java/com/android/server/lights/LightsService.java b/services/core/java/com/android/server/lights/LightsService.java
index 62dc090..62c0ec9 100644
--- a/services/core/java/com/android/server/lights/LightsService.java
+++ b/services/core/java/com/android/server/lights/LightsService.java
@@ -156,8 +156,9 @@
         }
     };
 
-    @Override
-    public void onCreate(Context context) {
+    public LightsService(Context context) {
+        super(context);
+
         mNativePointer = init_native();
 
         for (int i = 0; i < LightsManager.LIGHT_ID_COUNT; i++) {
@@ -182,6 +183,7 @@
         }
     };
 
+    @Override
     protected void finalize() throws Throwable {
         finalize_native(mNativePointer);
         super.finalize();
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index db4cf31d..6ee8989 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1118,6 +1118,10 @@
         return out;
     }
 
+    public NotificationManagerService(Context context) {
+        super(context);
+    }
+
     @Override
     public void onStart() {
         mAm = ActivityManagerNative.getDefault();
diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java
index e2ff146..6185e50 100644
--- a/services/core/java/com/android/server/pm/Installer.java
+++ b/services/core/java/com/android/server/pm/Installer.java
@@ -18,6 +18,7 @@
 
 import com.android.server.SystemService;
 
+import android.content.Context;
 import android.content.pm.PackageStats;
 import android.net.LocalSocket;
 import android.net.LocalSocketAddress;
@@ -39,6 +40,10 @@
     byte buf[] = new byte[1024];
     int buflen = 0;
 
+    public Installer(Context context) {
+        super(context);
+    }
+
     @Override
     public void onStart() {
         Slog.i(TAG, "Waiting for installd to be ready.");
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 94876bb..9606baa 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -168,7 +168,7 @@
     // effectively and terminate the dream.
     private static final int DREAM_BATTERY_LEVEL_DRAIN_CUTOFF = 5;
 
-    private Context mContext;
+    private final Context mContext;
     private LightsManager mLightsManager;
     private BatteryService mBatteryService;
     private DisplayManagerInternal mDisplayManagerInternal;
@@ -374,7 +374,9 @@
     private static native void nativeSetInteractive(boolean enable);
     private static native void nativeSetAutoSuspend(boolean enable);
 
-    public PowerManagerService() {
+    public PowerManagerService(Context context) {
+        super(context);
+        mContext = context;
         synchronized (mLock) {
             mWakeLockSuspendBlocker = createSuspendBlockerLocked("PowerManagerService.WakeLocks");
             mDisplaySuspendBlocker = createSuspendBlockerLocked("PowerManagerService.Display");
@@ -391,11 +393,6 @@
     }
 
     @Override
-    public void onCreate(Context context) {
-        mContext = context;
-    }
-
-    @Override
     public void onStart() {
         publishBinderService(Context.POWER_SERVICE, new BinderService());
         publishLocalService(PowerManagerInternal.class, new LocalService());
diff --git a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
index 8805084..43a99e0 100644
--- a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
+++ b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
@@ -89,11 +89,11 @@
     private long mLastReportedFreeMemTime;
     boolean mLowMemFlag=false;
     private boolean mMemFullFlag=false;
-    private ContentResolver mResolver;
-    private long mTotalMemory;  // on /data
-    private StatFs mDataFileStats;
-    private StatFs mSystemFileStats;
-    private StatFs mCacheFileStats;
+    private final ContentResolver mResolver;
+    private final long mTotalMemory;  // on /data
+    private final StatFs mDataFileStats;
+    private final StatFs mSystemFileStats;
+    private final StatFs mCacheFileStats;
 
     private static final File DATA_PATH = Environment.getDataDirectory();
     private static final File SYSTEM_PATH = Environment.getRootDirectory();
@@ -102,10 +102,10 @@
     private long mThreadStartTime = -1;
     boolean mClearSucceeded = false;
     boolean mClearingCache;
-    private Intent mStorageLowIntent;
-    private Intent mStorageOkIntent;
-    private Intent mStorageFullIntent;
-    private Intent mStorageNotFullIntent;
+    private final Intent mStorageLowIntent;
+    private final Intent mStorageOkIntent;
+    private final Intent mStorageFullIntent;
+    private final Intent mStorageNotFullIntent;
     private CachePackageDataObserver mClearCacheObserver;
     private CacheFileDeletedObserver mCacheFileDeletedObserver;
     private static final int _TRUE = 1;
@@ -134,7 +134,7 @@
     * Handler that checks the amount of disk space on the device and sends a
     * notification if the device runs low on disk space
     */
-    private Handler mHandler = new Handler() {
+    private final Handler mHandler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
             //don't handle an invalid message
@@ -310,12 +310,8 @@
                 delay);
     }
 
-    /**
-    * Constructor to run service. initializes the disk space threshold value
-    * and posts an empty message to kickstart the process.
-    */
-    @Override
-    public void onCreate(Context context) {
+    public DeviceStorageMonitorService(Context context) {
+        super(context);
         mLastReportedFreeMemTime = 0;
         mResolver = context.getContentResolver();
         //create StatFs object
@@ -335,6 +331,10 @@
         mStorageNotFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
     }
 
+    /**
+    * Initializes the disk space threshold value and posts an empty message to
+    * kickstart the process.
+    */
     @Override
     public void onStart() {
         // cache storage thresholds
diff --git a/services/core/java/com/android/server/twilight/TwilightService.java b/services/core/java/com/android/server/twilight/TwilightService.java
index 8feb97b..a71961c 100644
--- a/services/core/java/com/android/server/twilight/TwilightService.java
+++ b/services/core/java/com/android/server/twilight/TwilightService.java
@@ -65,6 +65,10 @@
 
     TwilightState mTwilightState;
 
+    public TwilightService(Context context) {
+        super(context);
+    }
+
     @Override
     public void onStart() {
         mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index af36246..296d852 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -25,6 +25,7 @@
 import com.android.internal.util.XmlUtils;
 import com.android.internal.widget.LockPatternUtils;
 import com.android.org.conscrypt.TrustedCertificateStore;
+import com.android.server.SystemService;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -149,6 +150,26 @@
      */
     private boolean mHasFeature;
 
+    public static final class Lifecycle extends SystemService {
+        private DevicePolicyManagerService mService;
+
+        public Lifecycle(Context context) {
+            super(context);
+            mService = new DevicePolicyManagerService(context);
+        }
+
+        @Override
+        public void onStart() {
+            publishBinderService(Context.DEVICE_POLICY_SERVICE, mService);
+        }
+
+        @Override
+        public void onBootPhase(int phase) {
+            if (phase == PHASE_LOCK_SETTINGS_READY) {
+                mService.systemReady();
+            }
+        }
+    }
     public static class DevicePolicyData {
         int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
         int mActivePasswordLength = 0;
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerSystemService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerSystemService.java
deleted file mode 100644
index 160aa39..0000000
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerSystemService.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.devicepolicy;
-
-import android.content.Context;
-
-import com.android.server.SystemService;
-
-/**
- * SystemService wrapper for the DevicePolicyManager implementation. Publishes
- * Context.DEVICE_POLICY_SERVICE.
- */
-public final class DevicePolicyManagerSystemService extends SystemService {
-    private DevicePolicyManagerService mDevicePolicyManagerImpl;
-
-    @Override
-    public void onCreate(Context context) {
-        mDevicePolicyManagerImpl = new DevicePolicyManagerService(context);
-    }
-
-    @Override
-    public void onStart() {
-        publishBinderService(Context.DEVICE_POLICY_SERVICE, mDevicePolicyManagerImpl);
-    }
-
-    @Override
-    public void onBootPhase(int phase) {
-        if (phase == PHASE_LOCK_SETTINGS_READY) {
-            mDevicePolicyManagerImpl.systemReady();
-        }
-    }
-}
\ No newline at end of file
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 269c056..f941ffe 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -106,9 +106,9 @@
      * them from the build system somehow.
      */
     private static final String BACKUP_MANAGER_SERVICE_CLASS =
-            "com.android.server.backup.BackupManagerSystemService";
+            "com.android.server.backup.BackupManagerService$Lifecycle";
     private static final String DEVICE_POLICY_MANAGER_SERVICE_CLASS =
-            "com.android.server.devicepolicy.DevicePolicyManagerSystemService";
+            "com.android.server.devicepolicy.DevicePolicyManagerService$Lifecycle";
     private static final String APPWIDGET_SERVICE_CLASS =
             "com.android.server.appwidget.AppWidgetService";
     private static final String PRINT_MANAGER_SERVICE_CLASS =
@@ -211,6 +211,7 @@
 
         // Create the system service manager.
         mSystemServiceManager = new SystemServiceManager(mSystemContext);
+        LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
 
         // Start services.
         try {
diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java
index 1e35678..c6fdbe5 100644
--- a/services/print/java/com/android/server/print/PrintManagerService.java
+++ b/services/print/java/com/android/server/print/PrintManagerService.java
@@ -66,13 +66,13 @@
  */
 
 public final class PrintManagerService extends SystemService {
+    private final PrintManagerImpl mPrintManagerImpl;
 
-    private PrintManagerImpl mPrintManagerImpl;
-
-    @Override
-    public void onCreate(Context context) {
+    public PrintManagerService(Context context) {
+        super(context);
         mPrintManagerImpl = new PrintManagerImpl(context);
     }
+
     @Override
     public void onStart() {
         publishBinderService(Context.PRINT_SERVICE, mPrintManagerImpl);