Prevent the infinite boot-looping.

- When the device is already previsioned, just exiting itself will cause
  the boot-loop, because the Activity is re-triggered as HOME.
- If the case, remove itself to prevent from the boot-loop.

Bug: 249501464
Test: build sdk_emu_x86_64 and check if it boots successfully.
Change-Id: I19b11b8f389f9a47d6885a604d5a7c59b4665a26
diff --git a/provision/EmulatorProvisonLib/src/com/android/sdksetup/ProvisionActivity.java b/provision/EmulatorProvisonLib/src/com/android/sdksetup/ProvisionActivity.java
index 7fa2c97..8353d0a 100644
--- a/provision/EmulatorProvisonLib/src/com/android/sdksetup/ProvisionActivity.java
+++ b/provision/EmulatorProvisonLib/src/com/android/sdksetup/ProvisionActivity.java
@@ -48,6 +48,9 @@
             preProvivion();
             doProvision();
             postProvision();
+        } else {
+            Log.w(TAG(), "Already provisioned, remove itself.");
+            removeSelf();
         }
 
         finish();  // terminate the activity.
@@ -63,17 +66,21 @@
     protected void postProvision() {
         mStatusBarManager.setDisabledForSetup(false);
 
-        // remove this activity from the package manager.
-        getPackageManager().setComponentEnabledSetting(
-            new ComponentName(this, this.getClass()),
-            PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
-            PackageManager.DONT_KILL_APP);
+        removeSelf();
 
         // Add a persistent setting to allow other apps to know the device has been provisioned.
         Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
         Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
     }
 
+    // remove this activity from the package manager.
+    protected void removeSelf() {
+        getPackageManager().setComponentEnabledSetting(
+                new ComponentName(this, this.getClass()),
+                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                PackageManager.DONT_KILL_APP);
+    }
+
     protected void doProvision() {
         provisionWifi("AndroidWifi");
         provisionKeyboard("qwerty2");