ActivityManager: Make sure BOOT_COMPLETED Intent is sent when running headless

Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index f98b668..0d1d620 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -2870,6 +2870,13 @@
     }
 
     boolean startHomeActivityLocked(int userId) {
+        if (mHeadless) {
+            // Added because none of the other calls to ensureBootCompleted seem to fire
+            // when running headless.
+            ensureBootCompleted();
+            return false;
+        }
+
         if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL
                 && mTopAction == null) {
             // We are running in factory test mode, but unable to find
@@ -4918,7 +4925,7 @@
         synchronized (this) {
             booting = mBooting;
             mBooting = false;
-            enableScreen = !mBooted;
+            enableScreen = !mBooted && !mHeadless;
             mBooted = true;
         }