Only finish Setup Wizard Activity when fully done
Wait for the ACTION_FINISHED broadcast before finishing the Activity. This prevents the Setup Wizard from being re-launched when it is still set as the default home screen, which it continues to be until the exit worker changes as part of its finishSetupWizard call. Skip SetupWizardExitActivity during the normal finish process, moving common exit operations to SetupWizardUtils. Change-Id: I1c59553e7dcaf934fb81dce9bf901ec0f2bb7b59
This commit is contained in:
committed by
Michael Bestas
parent
f58c0f4b83
commit
63bbec0258
@@ -47,6 +47,7 @@ import android.content.res.Resources;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.os.Binder;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -58,12 +59,17 @@ import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.work.OneTimeWorkRequest;
|
||||
import androidx.work.OutOfQuotaPolicy;
|
||||
import androidx.work.WorkManager;
|
||||
|
||||
import org.lineageos.internal.util.PackageManagerUtils;
|
||||
import org.lineageos.setupwizard.BiometricActivity;
|
||||
import org.lineageos.setupwizard.BluetoothSetupActivity;
|
||||
import org.lineageos.setupwizard.NetworkSetupActivity;
|
||||
import org.lineageos.setupwizard.ScreenLockActivity;
|
||||
import org.lineageos.setupwizard.SetupWizardApp;
|
||||
import org.lineageos.setupwizard.SetupWizardExitWorker;
|
||||
import org.lineageos.setupwizard.SimMissingActivity;
|
||||
import org.lineageos.setupwizard.wizardmanager.WizardManager;
|
||||
|
||||
@@ -207,10 +213,33 @@ public class SetupWizardUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void startSetupWizardExitProcedure(Context context) {
|
||||
try {
|
||||
WorkManager.getInstance(context).enqueue(new OneTimeWorkRequest.Builder(
|
||||
SetupWizardExitWorker.class).setExpedited(
|
||||
OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST).build());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// finishSetupWizard -- called by the exit worker -- disables components at the end,
|
||||
// including the WorkManager component required here, so this is likely an error finding
|
||||
// that component. The worker only needs to run once. We can assume it already has.
|
||||
Log.w(TAG, "Could not start SetupWizardExitWorker. It has likely already run.", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void finishSetupWizard(Context context) {
|
||||
if (LOGV) {
|
||||
Log.v(TAG, "finishSetupWizard");
|
||||
}
|
||||
ContentResolver contentResolver = context.getContentResolver();
|
||||
Settings.Global.putInt(contentResolver,
|
||||
Settings.Global.DEVICE_PROVISIONED, 1);
|
||||
final int userSetupComplete =
|
||||
Settings.Secure.getInt(contentResolver, Settings.Secure.USER_SETUP_COMPLETE, 0);
|
||||
if (userSetupComplete != 0 && !SetupWizardUtils.isManagedProfile(context)) {
|
||||
Log.e(TAG, "finishSetupWizard, but userSetupComplete=" + userSetupComplete + "! "
|
||||
+ "This should not happen!");
|
||||
}
|
||||
Settings.Secure.putInt(contentResolver,
|
||||
Settings.Secure.USER_SETUP_COMPLETE, 1);
|
||||
if (hasLeanback(context)) {
|
||||
@@ -218,9 +247,20 @@ public class SetupWizardUtils {
|
||||
Settings.Secure.TV_USER_SETUP_COMPLETE, 1);
|
||||
}
|
||||
|
||||
disableComponent(context, WizardManager.class);
|
||||
disableComponentsAndSendFinishedBroadcast(context);
|
||||
}
|
||||
|
||||
private static void disableComponentsAndSendFinishedBroadcast(Context context) {
|
||||
if (LOGV) {
|
||||
Log.v(TAG, "Disabling Setup Wizard components and sending FINISHED broadcast.");
|
||||
}
|
||||
disableHome(context);
|
||||
context.sendStickyBroadcastAsUser(
|
||||
new Intent(SetupWizardApp.ACTION_FINISHED),
|
||||
Binder.getCallingUserHandle());
|
||||
disableComponentSets(context, GET_RECEIVERS | GET_SERVICES);
|
||||
// Note: The WizardManager component is disabled when the WizardManager exits,
|
||||
// which happens when FinishActivity calls nextAction while completing.
|
||||
}
|
||||
|
||||
public static boolean isBluetoothDisabled() {
|
||||
|
Reference in New Issue
Block a user