Loading src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java +46 −19 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD; import android.app.AlertDialog; import android.app.KeyguardManager; import android.app.PendingIntent; import android.app.settings.SettingsEnums; import android.content.Context; import android.content.DialogInterface; Loading Loading @@ -53,11 +54,12 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { private KeyguardManager mKeyguardManager; private final ActivityResultLauncher<Intent> mSetDeviceLock = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), this::onSetDeviceLockResult); private final ActivityResultLauncher<Intent> mVerifyDeviceLock = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), this::onVerifyDeviceLock); registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), this::onVerifyDeviceLock); static class Injector { PrivateSpaceMaintainer injectPrivateSpaceMaintainer(Context context) { Loading @@ -71,17 +73,14 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { if (Flags.allowPrivateProfile()) { ThemeHelper.trySetDynamicColor(this); mPrivateSpaceMaintainer = new Injector().injectPrivateSpaceMaintainer( getApplicationContext()); mPrivateSpaceMaintainer = new Injector().injectPrivateSpaceMaintainer(getApplicationContext()); if (getKeyguardManager().isDeviceSecure()) { if (savedInstanceState == null) { Intent credentialIntent = mPrivateSpaceMaintainer.getPrivateProfileLockCredentialIntent(); if (credentialIntent != null) { mVerifyDeviceLock.launch(credentialIntent); if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) { unlockAndLaunchPrivateSpaceSettings(this); } else { Log.e(TAG, "verifyCredentialIntent is null even though device lock is set"); finish(); authenticatePrivateSpaceEntry(); } } } else { Loading @@ -96,14 +95,10 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { @VisibleForTesting public void onLockAuthentication(Context context) { if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) { new SubSettingLauncher(context) .setDestination(PrivateSpaceDashboardFragment.class.getName()) .setTransitionType( SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE) .setSourceMetricsCategory(SettingsEnums.PRIVATE_SPACE_SETTINGS) .launch(); unlockAndLaunchPrivateSpaceSettings(context); } else { startActivity(new Intent(context, PrivateSpaceSetupActivity.class)); finish(); } } Loading Loading @@ -142,15 +137,47 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { if (result != null) { if (getKeyguardManager().isDeviceSecure()) { onLockAuthentication(this); } } else { finish(); } } } private void onVerifyDeviceLock(@Nullable ActivityResult result) { if (result != null && result.getResultCode() == RESULT_OK) { onLockAuthentication(this); } else { finish(); } } private void unlockAndLaunchPrivateSpaceSettings(Context context) { SubSettingLauncher privateSpaceSettings = new SubSettingLauncher(context) .setDestination(PrivateSpaceDashboardFragment.class.getName()) .setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE) .setSourceMetricsCategory(SettingsEnums.PRIVATE_SPACE_SETTINGS); if (mPrivateSpaceMaintainer.isPrivateSpaceLocked()) { mPrivateSpaceMaintainer.unlockPrivateSpace( PendingIntent.getActivity( context, /* requestCode */ 0, privateSpaceSettings.toIntent(), PendingIntent.FLAG_IMMUTABLE) .getIntentSender()); } else { privateSpaceSettings.launch(); } finish(); } private void authenticatePrivateSpaceEntry() { Intent credentialIntent = mPrivateSpaceMaintainer.getPrivateProfileLockCredentialIntent(); if (credentialIntent != null) { mVerifyDeviceLock.launch(credentialIntent); } else { Log.e(TAG, "verifyCredentialIntent is null even though device lock is set"); finish(); } } } src/com/android/settings/privatespace/PrivateSpaceMaintainer.java +12 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.app.IActivityManager; import android.app.KeyguardManager; import android.content.Context; import android.content.Intent; import android.content.IntentSender; import android.content.pm.UserInfo; import android.os.Flags; import android.os.RemoteException; Loading Loading @@ -241,6 +242,17 @@ public class PrivateSpaceMaintainer { return false; } /** * Checks if private space exists and requests to disable quiet mode. * * @param intentSender target to start when the user is unlocked */ public synchronized void unlockPrivateSpace(IntentSender intentSender) { if (mUserHandle != null) { mUserManager.requestQuietModeEnabled(false, mUserHandle, intentSender); } } /** Returns true if private space exists and is running, otherwise returns false */ @VisibleForTesting synchronized boolean isPrivateProfileRunning() { Loading Loading
src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java +46 −19 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD; import android.app.AlertDialog; import android.app.KeyguardManager; import android.app.PendingIntent; import android.app.settings.SettingsEnums; import android.content.Context; import android.content.DialogInterface; Loading Loading @@ -53,11 +54,12 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { private KeyguardManager mKeyguardManager; private final ActivityResultLauncher<Intent> mSetDeviceLock = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), this::onSetDeviceLockResult); private final ActivityResultLauncher<Intent> mVerifyDeviceLock = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), this::onVerifyDeviceLock); registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), this::onVerifyDeviceLock); static class Injector { PrivateSpaceMaintainer injectPrivateSpaceMaintainer(Context context) { Loading @@ -71,17 +73,14 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { if (Flags.allowPrivateProfile()) { ThemeHelper.trySetDynamicColor(this); mPrivateSpaceMaintainer = new Injector().injectPrivateSpaceMaintainer( getApplicationContext()); mPrivateSpaceMaintainer = new Injector().injectPrivateSpaceMaintainer(getApplicationContext()); if (getKeyguardManager().isDeviceSecure()) { if (savedInstanceState == null) { Intent credentialIntent = mPrivateSpaceMaintainer.getPrivateProfileLockCredentialIntent(); if (credentialIntent != null) { mVerifyDeviceLock.launch(credentialIntent); if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) { unlockAndLaunchPrivateSpaceSettings(this); } else { Log.e(TAG, "verifyCredentialIntent is null even though device lock is set"); finish(); authenticatePrivateSpaceEntry(); } } } else { Loading @@ -96,14 +95,10 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { @VisibleForTesting public void onLockAuthentication(Context context) { if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) { new SubSettingLauncher(context) .setDestination(PrivateSpaceDashboardFragment.class.getName()) .setTransitionType( SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE) .setSourceMetricsCategory(SettingsEnums.PRIVATE_SPACE_SETTINGS) .launch(); unlockAndLaunchPrivateSpaceSettings(context); } else { startActivity(new Intent(context, PrivateSpaceSetupActivity.class)); finish(); } } Loading Loading @@ -142,15 +137,47 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity { if (result != null) { if (getKeyguardManager().isDeviceSecure()) { onLockAuthentication(this); } } else { finish(); } } } private void onVerifyDeviceLock(@Nullable ActivityResult result) { if (result != null && result.getResultCode() == RESULT_OK) { onLockAuthentication(this); } else { finish(); } } private void unlockAndLaunchPrivateSpaceSettings(Context context) { SubSettingLauncher privateSpaceSettings = new SubSettingLauncher(context) .setDestination(PrivateSpaceDashboardFragment.class.getName()) .setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE) .setSourceMetricsCategory(SettingsEnums.PRIVATE_SPACE_SETTINGS); if (mPrivateSpaceMaintainer.isPrivateSpaceLocked()) { mPrivateSpaceMaintainer.unlockPrivateSpace( PendingIntent.getActivity( context, /* requestCode */ 0, privateSpaceSettings.toIntent(), PendingIntent.FLAG_IMMUTABLE) .getIntentSender()); } else { privateSpaceSettings.launch(); } finish(); } private void authenticatePrivateSpaceEntry() { Intent credentialIntent = mPrivateSpaceMaintainer.getPrivateProfileLockCredentialIntent(); if (credentialIntent != null) { mVerifyDeviceLock.launch(credentialIntent); } else { Log.e(TAG, "verifyCredentialIntent is null even though device lock is set"); finish(); } } }
src/com/android/settings/privatespace/PrivateSpaceMaintainer.java +12 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.app.IActivityManager; import android.app.KeyguardManager; import android.content.Context; import android.content.Intent; import android.content.IntentSender; import android.content.pm.UserInfo; import android.os.Flags; import android.os.RemoteException; Loading Loading @@ -241,6 +242,17 @@ public class PrivateSpaceMaintainer { return false; } /** * Checks if private space exists and requests to disable quiet mode. * * @param intentSender target to start when the user is unlocked */ public synchronized void unlockPrivateSpace(IntentSender intentSender) { if (mUserHandle != null) { mUserManager.requestQuietModeEnabled(false, mUserHandle, intentSender); } } /** Returns true if private space exists and is running, otherwise returns false */ @VisibleForTesting synchronized boolean isPrivateProfileRunning() { Loading