Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16c32a5e authored by josephpv's avatar josephpv
Browse files

Calling requestQuietMode with peindingIntent to match PS settings with

PS state

Bug: 314910049, 312399293
Test: Manually verified

Change-Id: Iebdd09d4c6f319d50b8c0f118de0ddb2eaeb95d6
parent 0bdf8e9c
Loading
Loading
Loading
Loading
+46 −19
Original line number Diff line number Diff line
@@ -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();
        }
    }

@@ -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();
        }
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -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() {