From ae0261e2204da67b96c3562004b5a57e27746eb6 Mon Sep 17 00:00:00 2001 From: Arnab Sen Date: Sat, 1 Jul 2023 11:38:27 +0530 Subject: [PATCH] Unlock non-secure users automatically (2/2) ...while moving apps or media content from internal storage to adopted storage and vice-versa. Currently, for FBE enabled devices, whenever move is triggered for either app or media content, there is a prompt for user to enter their lockscreen credentials in order to unlock storage if the user has one. But if the user does not have a lockscreen credential set and is not running,the wizard page is stuck. This leads to a bad user experience. StorageWizardMigrateConfirm & StorageWizardMoveConfirm uses ChooseLockSettingsHelper to launch the authentication method set by the user in order to unlock the storage. But, it does not handle the use-case where user has no authentication set and not running, causing return to the wizard activities, thus blocking the flow. This CL solves the issue by, checking if the user is not secure, attempt unlock the storage otherwise prompt the user to unlock. Bug: 305978187 Test: manual Steps 1. Create multiple users with atleast one user with an authentication method setup and one without authentication (apart from system user) 2. Install same apps for all users and also add some content to the media storage. 3. Format an SD Card as adopted. 4. Attempt to move content. 5. Check that the wizard is not stuck and it is prompting the locked users to authenticate. 6. Reboot 7. After reboot, Go to Settings > All Apps > app_name > Storage & Cache 8. Tap on "Change" under Storage and Select Adopted storage. 9. Check the same as Step#5 Change-Id: Ib72e9073386457711cc1d2ba745a24cbea91cd8a --- .../deviceinfo/StorageWizardMigrateConfirm.java | 14 ++++++++++++-- .../deviceinfo/StorageWizardMoveConfirm.java | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java index f65dd24ed25..1e0c184613e 100644 --- a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java +++ b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java @@ -30,6 +30,7 @@ import android.util.Log; import android.view.View; import android.widget.Toast; +import com.android.internal.widget.LockPatternUtils; import com.android.settings.R; import com.android.settings.overlay.FeatureFactory; import com.android.settings.password.ChooseLockSettingsHelper; @@ -97,10 +98,19 @@ public class StorageWizardMigrateConfirm extends StorageWizardBase { @Override public void onNavigateNext(View view) { // Ensure that all users are unlocked so that we can move their data + final LockPatternUtils lpu = new LockPatternUtils(this); if (StorageManager.isFileEncrypted()) { for (UserInfo user : getSystemService(UserManager.class).getUsers()) { - if (!StorageManager.isUserKeyUnlocked(user.id)) { - Log.d(TAG, "User " + user.id + " is currently locked; requesting unlock"); + if (StorageManager.isUserKeyUnlocked(user.id)) { + continue; + } + if (!lpu.isSecure(user.id)) { + Log.d(TAG, "Unsecured user " + user.id + " is currently locked; attempting " + + "automatic unlock"); + lpu.unlockUserKeyIfUnsecured(user.id); + } else { + Log.d(TAG, "Secured user " + user.id + " is currently locked; requesting " + + "manual unlock"); final CharSequence description = TextUtils.expandTemplate( getText(R.string.storage_wizard_move_unlock), user.name); final ChooseLockSettingsHelper.Builder builder = diff --git a/src/com/android/settings/deviceinfo/StorageWizardMoveConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardMoveConfirm.java index da96104589a..bf16ab0f972 100644 --- a/src/com/android/settings/deviceinfo/StorageWizardMoveConfirm.java +++ b/src/com/android/settings/deviceinfo/StorageWizardMoveConfirm.java @@ -33,6 +33,7 @@ import android.util.Log; import android.view.View; import com.android.internal.util.Preconditions; +import com.android.internal.widget.LockPatternUtils; import com.android.settings.R; import com.android.settings.password.ChooseLockSettingsHelper; @@ -79,10 +80,19 @@ public class StorageWizardMoveConfirm extends StorageWizardBase { @Override public void onNavigateNext(View view) { // Ensure that all users are unlocked so that we can move their data + final LockPatternUtils lpu = new LockPatternUtils(this); if (StorageManager.isFileEncrypted()) { for (UserInfo user : getSystemService(UserManager.class).getUsers()) { - if (!StorageManager.isUserKeyUnlocked(user.id)) { - Log.d(TAG, "User " + user.id + " is currently locked; requesting unlock"); + if (StorageManager.isUserKeyUnlocked(user.id)) { + continue; + } + if (!lpu.isSecure(user.id)) { + Log.d(TAG, "Unsecured user " + user.id + " is currently locked; attempting " + + "automatic unlock"); + lpu.unlockUserKeyIfUnsecured(user.id); + } else { + Log.d(TAG, "Secured user " + user.id + " is currently locked; requesting " + + "manual unlock"); final CharSequence description = TextUtils.expandTemplate( getText(R.string.storage_wizard_move_unlock), user.name); final ChooseLockSettingsHelper.Builder builder =