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.AlertDialog;
|
||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@@ -53,11 +54,12 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity {
|
|||||||
private KeyguardManager mKeyguardManager;
|
private KeyguardManager mKeyguardManager;
|
||||||
|
|
||||||
private final ActivityResultLauncher<Intent> mSetDeviceLock =
|
private final ActivityResultLauncher<Intent> mSetDeviceLock =
|
||||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
registerForActivityResult(
|
||||||
|
new ActivityResultContracts.StartActivityForResult(),
|
||||||
this::onSetDeviceLockResult);
|
this::onSetDeviceLockResult);
|
||||||
private final ActivityResultLauncher<Intent> mVerifyDeviceLock =
|
private final ActivityResultLauncher<Intent> mVerifyDeviceLock =
|
||||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
registerForActivityResult(
|
||||||
this::onVerifyDeviceLock);
|
new ActivityResultContracts.StartActivityForResult(), this::onVerifyDeviceLock);
|
||||||
|
|
||||||
static class Injector {
|
static class Injector {
|
||||||
PrivateSpaceMaintainer injectPrivateSpaceMaintainer(Context context) {
|
PrivateSpaceMaintainer injectPrivateSpaceMaintainer(Context context) {
|
||||||
@@ -71,17 +73,14 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity {
|
|||||||
|
|
||||||
if (Flags.allowPrivateProfile()) {
|
if (Flags.allowPrivateProfile()) {
|
||||||
ThemeHelper.trySetDynamicColor(this);
|
ThemeHelper.trySetDynamicColor(this);
|
||||||
mPrivateSpaceMaintainer = new Injector().injectPrivateSpaceMaintainer(
|
mPrivateSpaceMaintainer =
|
||||||
getApplicationContext());
|
new Injector().injectPrivateSpaceMaintainer(getApplicationContext());
|
||||||
if (getKeyguardManager().isDeviceSecure()) {
|
if (getKeyguardManager().isDeviceSecure()) {
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
Intent credentialIntent =
|
if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) {
|
||||||
mPrivateSpaceMaintainer.getPrivateProfileLockCredentialIntent();
|
unlockAndLaunchPrivateSpaceSettings(this);
|
||||||
if (credentialIntent != null) {
|
|
||||||
mVerifyDeviceLock.launch(credentialIntent);
|
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "verifyCredentialIntent is null even though device lock is set");
|
authenticatePrivateSpaceEntry();
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -96,14 +95,10 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void onLockAuthentication(Context context) {
|
public void onLockAuthentication(Context context) {
|
||||||
if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) {
|
if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) {
|
||||||
new SubSettingLauncher(context)
|
unlockAndLaunchPrivateSpaceSettings(context);
|
||||||
.setDestination(PrivateSpaceDashboardFragment.class.getName())
|
|
||||||
.setTransitionType(
|
|
||||||
SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
|
|
||||||
.setSourceMetricsCategory(SettingsEnums.PRIVATE_SPACE_SETTINGS)
|
|
||||||
.launch();
|
|
||||||
} else {
|
} else {
|
||||||
startActivity(new Intent(context, PrivateSpaceSetupActivity.class));
|
startActivity(new Intent(context, PrivateSpaceSetupActivity.class));
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,15 +137,47 @@ public class PrivateSpaceAuthenticationActivity extends FragmentActivity {
|
|||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (getKeyguardManager().isDeviceSecure()) {
|
if (getKeyguardManager().isDeviceSecure()) {
|
||||||
onLockAuthentication(this);
|
onLockAuthentication(this);
|
||||||
}
|
} else {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void onVerifyDeviceLock(@Nullable ActivityResult result) {
|
private void onVerifyDeviceLock(@Nullable ActivityResult result) {
|
||||||
if (result != null && result.getResultCode() == RESULT_OK) {
|
if (result != null && result.getResultCode() == RESULT_OK) {
|
||||||
onLockAuthentication(this);
|
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();
|
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.app.KeyguardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentSender;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.os.Flags;
|
import android.os.Flags;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
@@ -241,6 +242,17 @@ public class PrivateSpaceMaintainer {
|
|||||||
return false;
|
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 */
|
/** Returns true if private space exists and is running, otherwise returns false */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
synchronized boolean isPrivateProfileRunning() {
|
synchronized boolean isPrivateProfileRunning() {
|
||||||
|
Reference in New Issue
Block a user