OSDN Git Service

Eliminate power manager latency for boot completed.
authorJeff Brown <jeffbrown@google.com>
Fri, 8 Aug 2014 02:06:49 +0000 (19:06 -0700)
committerJeff Brown <jeffbrown@google.com>
Tue, 12 Aug 2014 00:13:03 +0000 (17:13 -0700)
The power manager disables the power button until boot completed
occurs.  If there are many pending broadcasts in the queue, it
may be possible for BOOT_COMPLETED to be delayed for several
seconds after boot.

To avoid the delay, introduced a new boot phase which is
sent to system services immediately when boot completed happens.

Bug: 13398280
Change-Id: I1833d2ffb20305009dd76363b43e534034f1d0a2

core/java/com/android/server/SystemService.java
services/core/java/com/android/server/am/ActivityManagerService.java
services/core/java/com/android/server/power/PowerManagerService.java
services/java/com/android/server/SystemServer.java

index 43a05d0..6e67970 100644 (file)
@@ -73,9 +73,12 @@ public abstract class SystemService {
     public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;
 
     /**
-     * After receiving this boot phase, services must have finished all boot-related work.
+     * After receiving this boot phase, services can allow user interaction with the device.
+     * This phase occurs when boot has completed and the home application has started.
+     * System services may prefer to listen to this phase rather than registering a
+     * broadcast receiver for ACTION_BOOT_COMPLETED to reduce overall latency.
      */
-    public static final int PHASE_BOOT_COMPLETE = 1000;
+    public static final int PHASE_BOOT_COMPLETED = 1000;
 
     private final Context mContext;
 
index 22d8e32..298d6d3 100755 (executable)
@@ -5648,6 +5648,9 @@ public final class ActivityManagerService extends ActivityManagerNative
         // Register receivers to handle package update events
         mPackageMonitor.register(mContext, Looper.getMainLooper(), false);
 
+        // Let system services know.
+        mSystemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETED);
+
         synchronized (this) {
             // Ensure that any processes we had put on hold are now started
             // up.
index d1182e9..14cbd66 100644 (file)
@@ -474,6 +474,19 @@ public final class PowerManagerService extends com.android.server.SystemService
         Watchdog.getInstance().addThread(mHandler);
     }
 
+    @Override
+    public void onBootPhase(int phase) {
+        if (phase == PHASE_BOOT_COMPLETED) {
+            // This is our early signal that the system thinks it has finished booting.
+            // However, the boot animation may still be running for a few more seconds
+            // since it is ultimately in charge of when it terminates.
+            // Defer transitioning into the boot completed state until the animation exits.
+            // We do this so that the screen does not start to dim prematurely before
+            // the user has actually had a chance to interact with the device.
+            startWatchingForBootAnimationFinished();
+        }
+    }
+
     public void systemReady(IAppOpsService appOps) {
         synchronized (mLock) {
             mSystemReady = true;
@@ -516,11 +529,6 @@ public final class PowerManagerService extends com.android.server.SystemService
             mContext.registerReceiver(new BatteryReceiver(), filter, null, mHandler);
 
             filter = new IntentFilter();
-            filter.addAction(Intent.ACTION_BOOT_COMPLETED);
-            filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
-            mContext.registerReceiver(new BootCompletedReceiver(), filter, null, mHandler);
-
-            filter = new IntentFilter();
             filter.addAction(Intent.ACTION_DREAMING_STARTED);
             filter.addAction(Intent.ACTION_DREAMING_STOPPED);
             mContext.registerReceiver(new DreamReceiver(), filter, null, mHandler);
@@ -2404,19 +2412,6 @@ public final class PowerManagerService extends com.android.server.SystemService
         }
     }
 
-    private final class BootCompletedReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // This is our early signal that the system thinks it has finished booting.
-            // However, the boot animation may still be running for a few more seconds
-            // since it is ultimately in charge of when it terminates.
-            // Defer transitioning into the boot completed state until the animation exits.
-            // We do this so that the screen does not start to dim prematurely before
-            // the user has actually had a chance to interact with the device.
-            startWatchingForBootAnimationFinished();
-        }
-    }
-
     private final class DreamReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
index e70f0cf..a3c10fd 100644 (file)
@@ -1184,7 +1184,6 @@ public final class SystemServer {
                 } catch (Throwable e) {
                     reportWtf("Notifying MmsService running", e);
                 }
-                mSystemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETE);
             }
         });
     }