Merge "Calling requestQuietMode with peindingIntent to match PS settings with PS state" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
ad8dbc37d2
@@ -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;
|
||||
@@ -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) {
|
||||
@@ -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 {
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,22 +130,54 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity {
|
||||
if (mKeyguardManager == null) {
|
||||
mKeyguardManager = getSystemService(KeyguardManager.class);
|
||||
}
|
||||
return mKeyguardManager;
|
||||
return mKeyguardManager;
|
||||
}
|
||||
|
||||
private void onSetDeviceLockResult(@Nullable ActivityResult result) {
|
||||
if (result != null) {
|
||||
if (getKeyguardManager().isDeviceSecure()) {
|
||||
onLockAuthentication(this);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
@@ -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() {
|
||||
|
Reference in New Issue
Block a user