Maybe fix issue #17700474: manta: high occurrence of device booted...

...but dev.bootcomplete flag is not set

Rework things to address a few issues I found:

- When the activity goes idle, the way we were handling finishing the
  boot there was calling finishBooting() with the lock held, but it
  shouldn't.  We now dispatch that and turning on the screen together
  in a separate message.

- Make sure we don't try to start the home activity until we have
  reached the point of the system being ready and mBooting being set.
  This ensures we don't do any work prematurely.

Change-Id: If30c1f287af73bc2164e7aadbe98022ae42cc5e7
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 83a8d45..e9f0558 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -421,6 +421,11 @@
     }
 
     boolean resumeHomeStackTask(int homeStackTaskType, ActivityRecord prev) {
+        if (!mService.mBooting && !mService.mBooted) {
+            // Not ready yet!
+            return false;
+        }
+
         if (homeStackTaskType == RECENTS_ACTIVITY_TYPE) {
             mWindowManager.showRecentApps();
             return false;
@@ -2295,9 +2300,7 @@
             activityRemoved |= r.task.stack.destroyActivityLocked(r, true, "finish-idle");
         }
 
-        if (booting) {
-            mService.finishBooting();
-        } else {
+        if (!booting) {
             // Complete user switch
             if (startingUsers != null) {
                 for (int i = 0; i < startingUsers.size(); i++) {
@@ -2318,8 +2321,8 @@
         //dump();
         //mWindowManager.dump();
 
-        if (enableScreen) {
-            mService.postEnableScreenAfterBootLocked();
+        if (booting || enableScreen) {
+            mService.postFinishBooting(booting, enableScreen);
         }
 
         if (activityRemoved) {
@@ -2584,7 +2587,6 @@
                         r.mLaunchTaskBehind);
             }
         }
-        resumeHomeStackTask(HOME_ACTIVITY_TYPE, null);
     }
 
     void moveTaskToStack(int taskId, int stackId, boolean toTop) {