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

Change-Id: Ia9bb44b6d0b9bdc955f06648f7a2b5e6cd921a1c
This commit is contained in:
Beverly Tai
2020-05-12 22:58:20 +00:00
committed by Automerger Merge Worker
4 changed files with 40 additions and 12 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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() {

View File

@@ -312,7 +312,7 @@ public class LockSettingsService extends ILockSettings.Stub {
}
void register(LockSettingsStrongAuth strongAuth) {
strongAuth.registerStrongAuthTracker(this.mStub);
strongAuth.registerStrongAuthTracker(getStub());
}
}