From 5bbc1166f3b3068d53d7c7e11a51c3bddc229f56 Mon Sep 17 00:00:00 2001 From: Jigar Thakkar Date: Wed, 14 Feb 2024 21:01:17 +0000 Subject: [PATCH] Use SetScreenLockDialogActivity to power screen lock setup prompt With this change, we move to using SetScreenLockDialogActivity to enable the prompt to set up the screen lock. This prompt is shown whenever someone taps the private space settings page option to either setup/unlock the space. We will also be using the same dialog prompt in other places in the framework (UserManagerService.requestQuietModeEnabled) as well. Test: atest PrivateSpaceAuthenticationActivityTest Bug: 316129700 Flag: android.multiuser.show_set_screen_lock_dialog Change-Id: Ib9fe009d3b36e0eea242fbf894e616b1efcb9d6b --- .../PrivateSpaceAuthenticationActivity.java | 45 ++++++++++++------- .../PrivateSpaceAuthenticationActivityTest.kt | 11 +++-- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java b/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java index 149c0d6881e..63b1dc95a98 100644 --- a/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java +++ b/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java @@ -18,6 +18,8 @@ package com.android.settings.privatespace; import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD; +import static com.android.internal.app.SetScreenLockDialogActivity.LAUNCH_REASON_PRIVATE_SPACE_SETTINGS_ACCESS; + import android.app.ActivityOptions; import android.app.AlertDialog; import android.app.KeyguardManager; @@ -37,6 +39,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; import com.android.internal.annotations.VisibleForTesting; +import com.android.internal.app.SetScreenLockDialogActivity; import com.android.settings.R; import com.android.settings.core.SubSettingLauncher; import com.android.settingslib.transition.SettingsTransitionHelper; @@ -112,23 +115,31 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { private void promptToSetDeviceLock() { Log.d(TAG, "Show prompt to set device lock before using private space feature"); - new AlertDialog.Builder(this) - .setTitle(R.string.no_device_lock_title) - .setMessage(R.string.no_device_lock_summary) - .setPositiveButton( - R.string.no_device_lock_action_label, - (DialogInterface dialog, int which) -> { - Log.d(TAG, "Start activity to set new device lock"); - mSetDeviceLock.launch(new Intent(ACTION_SET_NEW_PASSWORD)); - }) - .setNegativeButton( - R.string.no_device_lock_cancel, - (DialogInterface dialog, int which) -> finish()) - .setOnCancelListener( - (DialogInterface dialog) -> { - finish(); - }) - .show(); + if (android.multiuser.Flags.showSetScreenLockDialog()) { + Intent setScreenLockPromptIntent = + SetScreenLockDialogActivity + .createBaseIntent(LAUNCH_REASON_PRIVATE_SPACE_SETTINGS_ACCESS); + startActivity(setScreenLockPromptIntent); + finish(); + } else { + new AlertDialog.Builder(this) + .setTitle(R.string.no_device_lock_title) + .setMessage(R.string.no_device_lock_summary) + .setPositiveButton( + R.string.no_device_lock_action_label, + (DialogInterface dialog, int which) -> { + Log.d(TAG, "Start activity to set new device lock"); + mSetDeviceLock.launch(new Intent(ACTION_SET_NEW_PASSWORD)); + }) + .setNegativeButton( + R.string.no_device_lock_cancel, + (DialogInterface dialog, int which) -> finish()) + .setOnCancelListener( + (DialogInterface dialog) -> { + finish(); + }) + .show(); + } } private KeyguardManager getKeyguardManager() { diff --git a/tests/uitests/src/com/android/settings/ui/privatespace/PrivateSpaceAuthenticationActivityTest.kt b/tests/uitests/src/com/android/settings/ui/privatespace/PrivateSpaceAuthenticationActivityTest.kt index 87514716082..8eadd9dde92 100644 --- a/tests/uitests/src/com/android/settings/ui/privatespace/PrivateSpaceAuthenticationActivityTest.kt +++ b/tests/uitests/src/com/android/settings/ui/privatespace/PrivateSpaceAuthenticationActivityTest.kt @@ -18,9 +18,11 @@ package com.android.settings.ui.privatespace import android.os.Flags +import android.platform.test.annotations.RequiresFlagsDisabled import android.platform.test.annotations.RequiresFlagsEnabled import android.platform.test.flag.junit.DeviceFlagsValueProvider import android.provider.Settings +import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By @@ -77,15 +79,18 @@ class PrivateSpaceAuthenticationActivityTest { Thread.sleep(1000) device.assertHasTexts(listOf(SET_LOCK_BUTTON,CANCEL_TEXT)) device.clickObject(By.text(SET_LOCK_BUTTON)) - device.assertHasTexts(listOf(LOCK_SCREEN_TITLE)) + Thread.sleep(1000) + device.assertHasTexts(listOf(PATTERN_TEXT, PIN_TEXT, PASSWORD_TEXT)) } private companion object { // Items we really want to always show - val PRIVATE_SPACE_SETTING = "Private Space" + val PRIVATE_SPACE_SETTING = "Private space" const val SET_LOCK_BUTTON = "Set screen lock" val CANCEL_TEXT = "Cancel" val DIALOG_TITLE = "Set a screen lock" - val LOCK_SCREEN_TITLE = "Choose screen lock" + val PATTERN_TEXT = "Pattern" + val PIN_TEXT = "PIN" + val PASSWORD_TEXT = "Password" } }