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

Commit 27ca104e authored by Victor Chang's avatar Victor Chang
Browse files

Fix Work Challenge / personal confirm credential is shown on top of keyguard after rotation

ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED has been abused.
We should not set onfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED
for work challenge and most other cases.

It's temp fix for the rotation bug. Because it's inconsistent the activity is shown
on top of keyguard with/without rotation (or any config change). In long term,
SHOW_WHEN_LOCKED should be set only if it's truly on purpose, and remove
isKeyguardLocked checking.

Bug: 28878075
Change-Id: I19db913f5bcaf2644c8c46c25e9584103d7fee8a
parent dad7b893
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -18,19 +18,20 @@ package com.android.settings;

import android.app.Fragment;
import android.app.KeyguardManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.UserManager;
import android.view.MenuItem;
import android.view.WindowManager;

public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivity {

    private static final String STATE_IS_KEYGUARD_LOCKED = "STATE_IS_KEYGUARD_LOCKED";

    private boolean mRestoring;
    private boolean mDark;
    private boolean mEnterAnimationPending;
    private boolean mFirstTimeVisible = true;
    private boolean mIsKeyguardLocked = false;

    @Override
    protected void onCreate(Bundle savedState) {
@@ -44,8 +45,15 @@ public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivi
            mDark = true;
        }
        super.onCreate(savedState);
        boolean deviceLocked = getSystemService(KeyguardManager.class).isKeyguardLocked();
        if (deviceLocked && getIntent().getBooleanExtra(
        mIsKeyguardLocked = savedState == null
                ? getSystemService(KeyguardManager.class).isKeyguardLocked()
                : savedState.getBoolean(STATE_IS_KEYGUARD_LOCKED, false);
        // If the activity is launched, not due to config change, when keyguard is locked and the
        // flag is set, assume it's launched on top of keyguard on purpose.
        // TODO: Don't abuse SHOW_WHEN_LOCKED and don't check isKeyguardLocked.
        // Set extra SHOW_WHEN_LOCKED and WindowManager FLAG_SHOW_WHEN_LOCKED only if it's
        // truly on top of keyguard on purpose
        if (mIsKeyguardLocked && getIntent().getBooleanExtra(
                ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, false)) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        }
@@ -59,6 +67,12 @@ public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivi
        mRestoring = savedState != null;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean(STATE_IS_KEYGUARD_LOCKED, mIsKeyguardLocked);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {