Revert^2 "Don't launch the real home for User 0 in Headless mode."

This reverts commit 3c9fbb5d8b841e817bc5029a6f91b26f1336e947.

Reason for revert: Roll forward the orginial CL with the fix of the package name change.

=== Original CL ===
Don't launch the real home for User 0 in Headless mode.

During the boot process, the launcher for User 0 can be shown unexpectedly, we won't launch User 0's read home to avoid it.
After boot, when switching to User 0, FallbackHome will not be called, since User 0 is already unlocked.

Bug: 166670668
Test: Factory reset and check if the launcher is shown before SUW.
Change-Id: Ia6bb117d12e5967410d99508c5fc0620f486b455
Merged-In: Ia6bb117d12e5967410d99508c5fc0620f486b455
(cherry-picked from commit 5f428149095909386bf2e405c92632f83c563cc0)
diff --git a/src/com/android/car/settings/FallbackHome.java b/src/com/android/car/settings/FallbackHome.java
index 63e4b9f..559bb18 100644
--- a/src/com/android/car/settings/FallbackHome.java
+++ b/src/com/android/car/settings/FallbackHome.java
@@ -19,6 +19,7 @@
 import static android.car.settings.CarSettings.Global.ENABLE_USER_SWITCH_DEVELOPER_MESSAGE;
 
 import android.app.Activity;
+import android.car.userlib.UserHelper;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -53,6 +54,8 @@
 
     private boolean mProvisioned;
 
+    private boolean mFinished;
+
     private final Runnable mProgressTimeoutRunnable = () -> {
         View v = getLayoutInflater().inflate(
                 R.layout.fallback_home_finishing_boot, /* root= */ null);
@@ -135,6 +138,10 @@
     protected void onDestroy() {
         super.onDestroy();
         unregisterReceiver(mReceiver);
+        if (!mFinished) {
+            LOG.d("User " + getUserId() + " FallbackHome is finished");
+            finishFallbackHome();
+        }
     }
 
     private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -160,15 +167,25 @@
                         + "one soon?");
                 mHandler.sendEmptyMessageDelayed(0, 500);
             } else {
-                LOG.d("User " + getUserId() + " unlocked and real home ("
-                        + homeInfo.activityInfo.packageName + ") found; let's go!");
-                getSystemService(PowerManager.class).userActivity(
-                        SystemClock.uptimeMillis(), false);
-                finishAndRemoveTask();
+                String homePackageName = homeInfo.activityInfo.packageName;
+                if (UserHelper.isHeadlessSystemUser(getUserId())) {
+                    // This is the transient state in HeadlessSystemMode to boot for user 10+.
+                    LOG.d("User 0 unlocked, but will not launch real home: " + homePackageName);
+                    return;
+                }
+                LOG.d("User " + getUserId() + " unlocked and real home (" + homePackageName
+                        + ") found; let's go!");
+                finishFallbackHome();
             }
         }
     }
 
+    private void finishFallbackHome() {
+        getSystemService(PowerManager.class).userActivity(SystemClock.uptimeMillis(), false);
+        finishAndRemoveTask();
+        mFinished = true;
+    }
+
     private Handler mHandler = new Handler() {
         @Override
         public void handleMessage(Message msg) {