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

Commit 574fbd14 authored by Beverly Tai's avatar Beverly Tai Committed by Automerger Merge Worker
Browse files

Merge "Inject LockPatternUtils into KeyguardUpdateMonitor" into rvc-dev am: 3fb4151b

Change-Id: Ic4225ac0d4cbbdbfd6ca0c048302a74f9715b896
parents c98b63b6 3fb4151b
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -1369,7 +1369,7 @@ public class LockPatternUtils {

    public void registerStrongAuthTracker(final StrongAuthTracker strongAuthTracker) {
        try {
            getLockSettings().registerStrongAuthTracker(strongAuthTracker.mStub);
            getLockSettings().registerStrongAuthTracker(strongAuthTracker.getStub());
        } catch (RemoteException e) {
            throw new RuntimeException("Could not register StrongAuthTracker");
        }
@@ -1377,7 +1377,7 @@ public class LockPatternUtils {

    public void unregisterStrongAuthTracker(final StrongAuthTracker strongAuthTracker) {
        try {
            getLockSettings().unregisterStrongAuthTracker(strongAuthTracker.mStub);
            getLockSettings().unregisterStrongAuthTracker(strongAuthTracker.getStub());
        } catch (RemoteException e) {
            Log.e(TAG, "Could not unregister StrongAuthTracker", e);
        }
@@ -1740,7 +1740,7 @@ public class LockPatternUtils {
            }
        }

        protected final IStrongAuthTracker.Stub mStub = new IStrongAuthTracker.Stub() {
        private final IStrongAuthTracker.Stub mStub = new IStrongAuthTracker.Stub() {
            @Override
            public void onStrongAuthRequiredChanged(@StrongAuthFlags int strongAuthFlags,
                    int userId) {
@@ -1755,6 +1755,10 @@ public class LockPatternUtils {
            }
        };

        public IStrongAuthTracker.Stub getStub() {
            return mStub;
        }

        private class H extends Handler {
            static final int MSG_ON_STRONG_AUTH_REQUIRED_CHANGED = 1;
            static final int MSG_ON_IS_NON_STRONG_BIOMETRIC_ALLOWED_CHANGED = 2;
+20 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static com.android.systemui.DejankUtils.whitelistIpcs;

import android.annotation.AnyThread;
import android.annotation.MainThread;
import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.AlarmManager;
@@ -247,8 +248,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    // Battery status
    private BatteryStatus mBatteryStatus;

    @VisibleForTesting
    protected StrongAuthTracker mStrongAuthTracker;
    private StrongAuthTracker mStrongAuthTracker;

    private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>>
            mCallbacks = Lists.newArrayList();
@@ -1512,6 +1512,16 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        mUserTrustIsUsuallyManaged.delete(userId);
    }

    @VisibleForTesting
    protected void setStrongAuthTracker(@NonNull StrongAuthTracker tracker) {
        if (mStrongAuthTracker != null) {
            mLockPatternUtils.unregisterStrongAuthTracker(mStrongAuthTracker);
        }

        mStrongAuthTracker = tracker;
        mLockPatternUtils.registerStrongAuthTracker(mStrongAuthTracker);
    }

    private void registerRingerTracker() {
        mRingerModeTracker.getRingerMode().observeForever(mRingerModeObserver);
    }
@@ -1525,7 +1535,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            DumpManager dumpManager,
            RingerModeTracker ringerModeTracker,
            @Background Executor backgroundExecutor,
            StatusBarStateController statusBarStateController) {
            StatusBarStateController statusBarStateController,
            LockPatternUtils lockPatternUtils) {
        mContext = context;
        mSubscriptionManager = SubscriptionManager.from(context);
        mDeviceProvisioned = isDeviceProvisionedInSettingsDb();
@@ -1534,6 +1545,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        mBroadcastDispatcher = broadcastDispatcher;
        mRingerModeTracker = ringerModeTracker;
        mStatusBarStateController = statusBarStateController;
        mLockPatternUtils = lockPatternUtils;
        dumpManager.registerDumpable(getClass().getName(), this);

        mHandler = new Handler(mainLooper) {
@@ -1702,8 +1714,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

        mTrustManager = context.getSystemService(TrustManager.class);
        mTrustManager.registerTrustListener(this);
        mLockPatternUtils = new LockPatternUtils(context);
        mLockPatternUtils.registerStrongAuthTracker(mStrongAuthTracker);

        setStrongAuthTracker(mStrongAuthTracker);

        mDreamManager = IDreamManager.Stub.asInterface(
                ServiceManager.getService(DreamService.DREAM_SERVICE));
@@ -2847,6 +2859,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        mBroadcastDispatcher.unregisterReceiver(mBroadcastAllReceiver);
        mRingerModeTracker.getRingerMode().removeObserver(mRingerModeObserver);

        mLockPatternUtils.unregisterStrongAuthTracker(mStrongAuthTracker);
        mTrustManager.unregisterTrustListener(this);

        mHandler.removeCallbacksAndMessages(null);
    }

+12 −3
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.when;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.app.trust.IStrongAuthTracker;
import android.app.trust.TrustManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -72,6 +73,8 @@ import androidx.lifecycle.Observer;

import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.widget.ILockSettings;
import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardUpdateMonitor.BiometricAuthenticated;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
@@ -120,6 +123,10 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
    @Mock
    private TrustManager mTrustManager;
    @Mock
    private LockPatternUtils mLockPatternUtils;
    @Mock
    private ILockSettings mLockSettings;
    @Mock
    private FingerprintManager mFingerprintManager;
    @Mock
    private FaceManager mFaceManager;
@@ -169,12 +176,13 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
        when(mUserManager.isUserUnlocked(anyInt())).thenReturn(true);
        when(mUserManager.isPrimaryUser()).thenReturn(true);
        when(mStrongAuthTracker.getStub()).thenReturn(mock(IStrongAuthTracker.Stub.class));
        when(mStrongAuthTracker
                .isUnlockingWithBiometricAllowed(anyBoolean() /* isStrongBiometric */))
                .thenReturn(true);

        when(mTelephonyManager.getServiceStateForSubscriber(anyInt()))
                .thenReturn(new ServiceState());
        when(mLockPatternUtils.getLockSettings()).thenReturn(mLockSettings);
        mSpiedContext.addMockSystemService(TrustManager.class, mTrustManager);
        mSpiedContext.addMockSystemService(FingerprintManager.class, mFingerprintManager);
        mSpiedContext.addMockSystemService(BiometricManager.class, mBiometricManager);
@@ -729,8 +737,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
            super(context,
                    TestableLooper.get(KeyguardUpdateMonitorTest.this).getLooper(),
                    mBroadcastDispatcher, mDumpManager,
                    mRingerModeTracker, mBackgroundExecutor, mStatusBarStateController);
            mStrongAuthTracker = KeyguardUpdateMonitorTest.this.mStrongAuthTracker;
                    mRingerModeTracker, mBackgroundExecutor,
                    mStatusBarStateController, mLockPatternUtils);
            setStrongAuthTracker(KeyguardUpdateMonitorTest.this.mStrongAuthTracker);
        }

        public boolean hasSimStateJustChanged() {
+1 −1
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ public class LockSettingsService extends ILockSettings.Stub {
        }

        void register(LockSettingsStrongAuth strongAuth) {
            strongAuth.registerStrongAuthTracker(this.mStub);
            strongAuth.registerStrongAuthTracker(getStub());
        }
    }