Eval dismissKeyguard in KeyguardUpdateMonitor
And pass the dismissKeyguard evaluation through to the onTrustGrant KeyguardUpdateMonitor callback. We do this so that multiple classes will receive the same source of truth of whether the keyguard should be dismissed when a trust agent grants trust. Add ic_watch drawable. Test: manually test the SmartLock message shows on the lockscreen Test: atest SystemUITests Test: atest KeyguardUpdateMonitorTest Bug: 240196500 Bug: 256513609 Change-Id: I92abca021eda1bb0c8640d589c0e52007d4ddf00
This commit is contained in:
29
packages/SystemUI/res/drawable/ic_watch.xml
Normal file
29
packages/SystemUI/res/drawable/ic_watch.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2022 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M16,0L8,0l-0.95,5.73C5.19,7.19 4,9.45 4,12s1.19,4.81 3.05,6.27L8,24
|
||||
h8l0.96,-5.73C18.81,16.81 20,14.54 20,12s-1.19,-4.81 -3.04,-6.27L16,0z
|
||||
M12,18c-3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6 6,2.69 6,6 -2.69,6 -6,6z"/>
|
||||
</vector>
|
||||
@@ -21,7 +21,6 @@ import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.media.AudioManager;
|
||||
import android.os.SystemClock;
|
||||
import android.service.trust.TrustAgentService;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
import android.util.MathUtils;
|
||||
@@ -68,30 +67,24 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
|
||||
private final KeyguardUpdateMonitorCallback mUpdateCallback =
|
||||
new KeyguardUpdateMonitorCallback() {
|
||||
@Override
|
||||
public void onTrustGrantedWithFlags(int flags, int userId, String message) {
|
||||
if (userId != KeyguardUpdateMonitor.getCurrentUser()) return;
|
||||
boolean bouncerVisible = mView.isVisibleToUser();
|
||||
boolean temporaryAndRenewable =
|
||||
(flags & TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE)
|
||||
!= 0;
|
||||
boolean initiatedByUser =
|
||||
(flags & TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER) != 0;
|
||||
boolean dismissKeyguard =
|
||||
(flags & TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD) != 0;
|
||||
|
||||
if (initiatedByUser || dismissKeyguard) {
|
||||
if ((mViewMediatorCallback.isScreenOn() || temporaryAndRenewable)
|
||||
&& (bouncerVisible || dismissKeyguard)) {
|
||||
if (!bouncerVisible) {
|
||||
// The trust agent dismissed the keyguard without the user proving
|
||||
// that they are present (by swiping up to show the bouncer). That's
|
||||
// fine if the user proved presence via some other way to the trust
|
||||
//agent.
|
||||
Log.i(TAG, "TrustAgent dismissed Keyguard.");
|
||||
}
|
||||
mSecurityCallback.dismiss(false /* authenticated */, userId,
|
||||
/* bypassSecondaryLockScreen */ false, SecurityMode.Invalid);
|
||||
} else {
|
||||
public void onTrustGrantedForCurrentUser(boolean dismissKeyguard,
|
||||
TrustGrantFlags flags, String message) {
|
||||
if (dismissKeyguard) {
|
||||
if (!mView.isVisibleToUser()) {
|
||||
// The trust agent dismissed the keyguard without the user proving
|
||||
// that they are present (by swiping up to show the bouncer). That's
|
||||
// fine if the user proved presence via some other way to the trust
|
||||
// agent.
|
||||
Log.i(TAG, "TrustAgent dismissed Keyguard.");
|
||||
}
|
||||
mSecurityCallback.dismiss(
|
||||
false /* authenticated */,
|
||||
KeyguardUpdateMonitor.getCurrentUser(),
|
||||
/* bypassSecondaryLockScreen */ false,
|
||||
SecurityMode.Invalid
|
||||
);
|
||||
} else {
|
||||
if (flags.isInitiatedByUser() || flags.dismissKeyguardRequested()) {
|
||||
mViewMediatorCallback.playTrustedSound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,10 +486,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|
||||
FACE_AUTH_TRIGGERED_TRUST_DISABLED);
|
||||
}
|
||||
|
||||
String message = null;
|
||||
if (KeyguardUpdateMonitor.getCurrentUser() == userId) {
|
||||
final boolean userHasTrust = getUserHasTrust(userId);
|
||||
if (userHasTrust && trustGrantedMessages != null) {
|
||||
if (enabled) {
|
||||
String message = null;
|
||||
if (KeyguardUpdateMonitor.getCurrentUser() == userId
|
||||
&& trustGrantedMessages != null) {
|
||||
// Show the first non-empty string provided by a trust agent OR intentionally pass
|
||||
// an empty string through (to prevent the default trust agent string from showing)
|
||||
for (String msg : trustGrantedMessages) {
|
||||
message = msg;
|
||||
if (!TextUtils.isEmpty(message)) {
|
||||
@@ -497,21 +499,39 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mLogger.logTrustChanged(wasTrusted, enabled, userId);
|
||||
if (message != null) {
|
||||
mLogger.logShowTrustGrantedMessage(message.toString());
|
||||
}
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
|
||||
if (cb != null) {
|
||||
cb.onTrustChanged(userId);
|
||||
if (enabled) {
|
||||
cb.onTrustGrantedWithFlags(flags, userId, message);
|
||||
|
||||
mLogger.logTrustGrantedWithFlags(flags, userId, message);
|
||||
if (userId == getCurrentUser()) {
|
||||
final TrustGrantFlags trustGrantFlags = new TrustGrantFlags(flags);
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
|
||||
if (cb != null) {
|
||||
cb.onTrustGrantedForCurrentUser(
|
||||
shouldDismissKeyguardOnTrustGrantedWithCurrentUser(trustGrantFlags),
|
||||
trustGrantFlags, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mLogger.logTrustChanged(wasTrusted, enabled, userId);
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
|
||||
if (cb != null) {
|
||||
cb.onTrustChanged(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the trust granted call with its passed flags should dismiss keyguard.
|
||||
* It's assumed that the trust was granted for the current user.
|
||||
*/
|
||||
private boolean shouldDismissKeyguardOnTrustGrantedWithCurrentUser(TrustGrantFlags flags) {
|
||||
final boolean isBouncerShowing = mPrimaryBouncerIsOrWillBeShowing || mUdfpsBouncerShowing;
|
||||
return (flags.isInitiatedByUser() || flags.dismissKeyguardRequested())
|
||||
&& (mDeviceInteractive || flags.temporaryAndRenewable())
|
||||
&& (isBouncerShowing || flags.dismissKeyguardRequested());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ import android.hardware.biometrics.BiometricSourceType;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.view.WindowManagerPolicyConstants;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settingslib.fuelgauge.BatteryStatus;
|
||||
@@ -175,11 +176,13 @@ public class KeyguardUpdateMonitorCallback {
|
||||
|
||||
/**
|
||||
* Called after trust was granted.
|
||||
* @param userId of the user that has been granted trust
|
||||
* @param dismissKeyguard whether the keyguard should be dismissed as a result of the
|
||||
* trustGranted
|
||||
* @param message optional message the trust agent has provided to show that should indicate
|
||||
* why trust was granted.
|
||||
*/
|
||||
public void onTrustGrantedWithFlags(int flags, int userId, @Nullable String message) { }
|
||||
public void onTrustGrantedForCurrentUser(boolean dismissKeyguard,
|
||||
@NonNull TrustGrantFlags flags, @Nullable String message) { }
|
||||
|
||||
/**
|
||||
* Called when a biometric has been acquired.
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.keyguard;
|
||||
|
||||
import android.service.trust.TrustAgentService;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Translating {@link android.service.trust.TrustAgentService.GrantTrustFlags} to a more
|
||||
* parsable object. These flags are requested by a TrustAgent.
|
||||
*/
|
||||
public class TrustGrantFlags {
|
||||
final int mFlags;
|
||||
|
||||
public TrustGrantFlags(int flags) {
|
||||
this.mFlags = flags;
|
||||
}
|
||||
|
||||
/** {@link TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER} */
|
||||
public boolean isInitiatedByUser() {
|
||||
return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trust agent is requesting to dismiss the keyguard.
|
||||
* See {@link TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD}.
|
||||
*
|
||||
* This does not guarantee that the keyguard is dismissed.
|
||||
* KeyguardUpdateMonitor makes the final determination whether the keyguard should be dismissed.
|
||||
* {@link KeyguardUpdateMonitorCallback#onTrustGrantedForCurrentUser(
|
||||
* boolean, TrustGrantFlags, String).
|
||||
*/
|
||||
public boolean dismissKeyguardRequested() {
|
||||
return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD) != 0;
|
||||
}
|
||||
|
||||
/** {@link TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE} */
|
||||
public boolean temporaryAndRenewable() {
|
||||
return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) != 0;
|
||||
}
|
||||
|
||||
/** {@link TrustAgentService.FLAG_GRANT_TRUST_DISPLAY_MESSAGE} */
|
||||
public boolean displayMessage() {
|
||||
return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_DISPLAY_MESSAGE) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof TrustGrantFlags)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((TrustGrantFlags) o).mFlags == this.mFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("[");
|
||||
sb.append(mFlags);
|
||||
sb.append("]=");
|
||||
|
||||
if (isInitiatedByUser()) {
|
||||
sb.append("initiatedByUser|");
|
||||
}
|
||||
if (dismissKeyguardRequested()) {
|
||||
sb.append("dismissKeyguard|");
|
||||
}
|
||||
if (temporaryAndRenewable()) {
|
||||
sb.append("temporaryAndRenewable|");
|
||||
}
|
||||
if (displayMessage()) {
|
||||
sb.append("displayMessage|");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.android.keyguard.ActiveUnlockConfig
|
||||
import com.android.keyguard.FaceAuthUiEvent
|
||||
import com.android.keyguard.KeyguardListenModel
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback
|
||||
import com.android.keyguard.TrustGrantFlags
|
||||
import com.android.systemui.plugins.log.LogBuffer
|
||||
import com.android.systemui.plugins.log.LogLevel
|
||||
import com.android.systemui.plugins.log.LogLevel.DEBUG
|
||||
@@ -368,12 +369,16 @@ class KeyguardUpdateMonitorLogger @Inject constructor(
|
||||
}, { "reportUserRequestedUnlock origin=$str1 reason=$str2 dismissKeyguard=$bool1" })
|
||||
}
|
||||
|
||||
fun logShowTrustGrantedMessage(
|
||||
fun logTrustGrantedWithFlags(
|
||||
flags: Int,
|
||||
userId: Int,
|
||||
message: String?
|
||||
) {
|
||||
logBuffer.log(TAG, DEBUG, {
|
||||
int1 = flags
|
||||
int2 = userId
|
||||
str1 = message
|
||||
}, { "showTrustGrantedMessage message$str1" })
|
||||
}, { "trustGrantedWithFlags[user=$int2] flags=${TrustGrantFlags(int1)} message=$str1" })
|
||||
}
|
||||
|
||||
fun logTrustChanged(
|
||||
|
||||
@@ -67,6 +67,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
@@ -74,6 +75,7 @@ import com.android.internal.app.IBatteryStats;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback;
|
||||
import com.android.keyguard.TrustGrantFlags;
|
||||
import com.android.keyguard.logging.KeyguardLogger;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.fuelgauge.BatteryStatus;
|
||||
@@ -154,7 +156,8 @@ public class KeyguardIndicationController {
|
||||
private final AccessibilityManager mAccessibilityManager;
|
||||
private final Handler mHandler;
|
||||
|
||||
protected KeyguardIndicationRotateTextViewController mRotateTextViewController;
|
||||
@VisibleForTesting
|
||||
public KeyguardIndicationRotateTextViewController mRotateTextViewController;
|
||||
private BroadcastReceiver mBroadcastReceiver;
|
||||
private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
|
||||
|
||||
@@ -1188,9 +1191,9 @@ public class KeyguardIndicationController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrustGrantedWithFlags(int flags, int userId, @Nullable String message) {
|
||||
if (!isCurrentUser(userId)) return;
|
||||
showTrustGrantedMessage(flags, message);
|
||||
public void onTrustGrantedForCurrentUser(boolean dismissKeyguard,
|
||||
@NonNull TrustGrantFlags flags, @Nullable String message) {
|
||||
showTrustGrantedMessage(dismissKeyguard, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1254,7 +1257,7 @@ public class KeyguardIndicationController {
|
||||
return getCurrentUser() == userId;
|
||||
}
|
||||
|
||||
void showTrustGrantedMessage(int flags, @Nullable CharSequence message) {
|
||||
protected void showTrustGrantedMessage(boolean dismissKeyguard, @Nullable String message) {
|
||||
mTrustGrantedIndication = message;
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOM
|
||||
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT;
|
||||
import static com.android.keyguard.FaceAuthApiRequestReason.NOTIFICATION_PANEL_CLICKED;
|
||||
import static com.android.keyguard.KeyguardUpdateMonitor.DEFAULT_CANCEL_SIGNAL_TIMEOUT;
|
||||
import static com.android.keyguard.KeyguardUpdateMonitor.getCurrentUser;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -35,6 +36,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyObject;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
@@ -88,6 +90,7 @@ import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.service.dreams.IDreamManager;
|
||||
import android.service.trust.TrustAgentService;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
@@ -351,7 +354,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mMockitoSession.finishMocking();
|
||||
if (mMockitoSession != null) {
|
||||
mMockitoSession.finishMocking();
|
||||
}
|
||||
cleanupKeyguardUpdateMonitor();
|
||||
}
|
||||
|
||||
@@ -1314,9 +1319,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
|
||||
Arrays.asList("Unlocked by wearable"));
|
||||
|
||||
// THEN the showTrustGrantedMessage should be called with the first message
|
||||
verify(mTestCallback).onTrustGrantedWithFlags(
|
||||
eq(0),
|
||||
eq(KeyguardUpdateMonitor.getCurrentUser()),
|
||||
verify(mTestCallback).onTrustGrantedForCurrentUser(
|
||||
anyBoolean(),
|
||||
eq(new TrustGrantFlags(0)),
|
||||
eq("Unlocked by wearable"));
|
||||
}
|
||||
|
||||
@@ -1727,6 +1732,155 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
|
||||
verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOnTrustGrantedForCurrentUser_dismissKeyguardRequested_deviceInteractive() {
|
||||
// GIVEN device is interactive
|
||||
deviceIsInteractive();
|
||||
|
||||
// GIVEN callback is registered
|
||||
KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);
|
||||
mKeyguardUpdateMonitor.registerCallback(callback);
|
||||
|
||||
// WHEN onTrustChanged with TRUST_DISMISS_KEYGUARD flag
|
||||
mKeyguardUpdateMonitor.onTrustChanged(
|
||||
true /* enabled */,
|
||||
getCurrentUser() /* userId */,
|
||||
TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD /* flags */,
|
||||
null /* trustGrantedMessages */);
|
||||
|
||||
// THEN onTrustGrantedForCurrentUser callback called
|
||||
verify(callback).onTrustGrantedForCurrentUser(
|
||||
eq(true) /* dismissKeyguard */,
|
||||
eq(new TrustGrantFlags(TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD)),
|
||||
eq(null) /* message */
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnTrustGrantedForCurrentUser_dismissKeyguardRequested_doesNotDismiss() {
|
||||
// GIVEN device is NOT interactive
|
||||
|
||||
// GIVEN callback is registered
|
||||
KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);
|
||||
mKeyguardUpdateMonitor.registerCallback(callback);
|
||||
|
||||
// WHEN onTrustChanged with TRUST_DISMISS_KEYGUARD flag
|
||||
mKeyguardUpdateMonitor.onTrustChanged(
|
||||
true /* enabled */,
|
||||
getCurrentUser() /* userId */,
|
||||
TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD /* flags */,
|
||||
null /* trustGrantedMessages */);
|
||||
|
||||
// THEN onTrustGrantedForCurrentUser callback called
|
||||
verify(callback).onTrustGrantedForCurrentUser(
|
||||
eq(false) /* dismissKeyguard */,
|
||||
eq(new TrustGrantFlags(TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD)),
|
||||
eq(null) /* message */
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnTrustGrantedForCurrentUser_dismissKeyguardRequested_temporaryAndRenewable() {
|
||||
// GIVEN device is interactive
|
||||
deviceIsInteractive();
|
||||
|
||||
// GIVEN callback is registered
|
||||
KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);
|
||||
mKeyguardUpdateMonitor.registerCallback(callback);
|
||||
|
||||
// WHEN onTrustChanged for a different user
|
||||
mKeyguardUpdateMonitor.onTrustChanged(
|
||||
true /* enabled */,
|
||||
546 /* userId, not the current userId */,
|
||||
0 /* flags */,
|
||||
null /* trustGrantedMessages */);
|
||||
|
||||
// THEN onTrustGrantedForCurrentUser callback called
|
||||
verify(callback, never()).onTrustGrantedForCurrentUser(
|
||||
anyBoolean() /* dismissKeyguard */,
|
||||
anyObject() /* flags */,
|
||||
anyString() /* message */
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnTrustGranted_differentUser_noCallback() {
|
||||
// GIVEN device is interactive
|
||||
|
||||
// GIVEN callback is registered
|
||||
KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);
|
||||
mKeyguardUpdateMonitor.registerCallback(callback);
|
||||
|
||||
// WHEN onTrustChanged with TRUST_DISMISS_KEYGUARD AND TRUST_TEMPORARY_AND_RENEWABLE
|
||||
// flags (temporary & rewable is active unlock)
|
||||
mKeyguardUpdateMonitor.onTrustChanged(
|
||||
true /* enabled */,
|
||||
getCurrentUser() /* userId */,
|
||||
TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD
|
||||
| TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE /* flags */,
|
||||
null /* trustGrantedMessages */);
|
||||
|
||||
// THEN onTrustGrantedForCurrentUser callback called
|
||||
verify(callback).onTrustGrantedForCurrentUser(
|
||||
eq(true) /* dismissKeyguard */,
|
||||
eq(new TrustGrantFlags(TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD
|
||||
| TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE)),
|
||||
eq(null) /* message */
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnTrustGrantedForCurrentUser_bouncerShowing_initiatedByUser() {
|
||||
// GIVEN device is interactive & bouncer is showing
|
||||
deviceIsInteractive();
|
||||
bouncerFullyVisible();
|
||||
|
||||
// GIVEN callback is registered
|
||||
KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);
|
||||
mKeyguardUpdateMonitor.registerCallback(callback);
|
||||
|
||||
// WHEN onTrustChanged with INITIATED_BY_USER flag
|
||||
mKeyguardUpdateMonitor.onTrustChanged(
|
||||
true /* enabled */,
|
||||
getCurrentUser() /* userId, not the current userId */,
|
||||
TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER /* flags */,
|
||||
null /* trustGrantedMessages */);
|
||||
|
||||
// THEN onTrustGrantedForCurrentUser callback called
|
||||
verify(callback, never()).onTrustGrantedForCurrentUser(
|
||||
eq(true) /* dismissKeyguard */,
|
||||
eq(new TrustGrantFlags(TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER)),
|
||||
anyString() /* message */
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnTrustGrantedForCurrentUser_bouncerShowing_temporaryRenewable() {
|
||||
// GIVEN device is NOT interactive & bouncer is showing
|
||||
bouncerFullyVisible();
|
||||
|
||||
// GIVEN callback is registered
|
||||
KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);
|
||||
mKeyguardUpdateMonitor.registerCallback(callback);
|
||||
|
||||
// WHEN onTrustChanged with INITIATED_BY_USER flag
|
||||
mKeyguardUpdateMonitor.onTrustChanged(
|
||||
true /* enabled */,
|
||||
getCurrentUser() /* userId, not the current userId */,
|
||||
TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER
|
||||
| TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE /* flags */,
|
||||
null /* trustGrantedMessages */);
|
||||
|
||||
// THEN onTrustGrantedForCurrentUser callback called
|
||||
verify(callback, never()).onTrustGrantedForCurrentUser(
|
||||
eq(true) /* dismissKeyguard */,
|
||||
eq(new TrustGrantFlags(TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER
|
||||
| TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE)),
|
||||
anyString() /* message */
|
||||
);
|
||||
}
|
||||
|
||||
private void cleanupKeyguardUpdateMonitor() {
|
||||
if (mKeyguardUpdateMonitor != null) {
|
||||
mKeyguardUpdateMonitor.removeCallback(mTestCallback);
|
||||
|
||||
@@ -87,6 +87,7 @@ import com.android.internal.app.IBatteryStats;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback;
|
||||
import com.android.keyguard.TrustGrantFlags;
|
||||
import com.android.keyguard.logging.KeyguardLogger;
|
||||
import com.android.settingslib.fuelgauge.BatteryStatus;
|
||||
import com.android.systemui.R;
|
||||
@@ -1065,7 +1066,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
|
||||
// GIVEN a trust granted message but trust isn't granted
|
||||
final String trustGrantedMsg = "testing trust granted message";
|
||||
mController.getKeyguardCallback().onTrustGrantedWithFlags(0, 0, trustGrantedMsg);
|
||||
mController.getKeyguardCallback().onTrustGrantedForCurrentUser(
|
||||
false, new TrustGrantFlags(0), trustGrantedMsg);
|
||||
|
||||
verifyHideIndication(INDICATION_TYPE_TRUST);
|
||||
|
||||
@@ -1089,7 +1091,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
|
||||
// WHEN the showTrustGranted method is called
|
||||
final String trustGrantedMsg = "testing trust granted message";
|
||||
mController.getKeyguardCallback().onTrustGrantedWithFlags(0, 0, trustGrantedMsg);
|
||||
mController.getKeyguardCallback().onTrustGrantedForCurrentUser(
|
||||
false, new TrustGrantFlags(0), trustGrantedMsg);
|
||||
|
||||
// THEN verify the trust granted message shows
|
||||
verifyIndicationMessage(
|
||||
@@ -1106,7 +1109,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
|
||||
|
||||
// WHEN the showTrustGranted method is called with a null message
|
||||
mController.getKeyguardCallback().onTrustGrantedWithFlags(0, 0, null);
|
||||
mController.getKeyguardCallback().onTrustGrantedForCurrentUser(
|
||||
false, new TrustGrantFlags(0), null);
|
||||
|
||||
// THEN verify the default trust granted message shows
|
||||
verifyIndicationMessage(
|
||||
@@ -1123,7 +1127,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
|
||||
|
||||
// WHEN the showTrustGranted method is called with an EMPTY string
|
||||
mController.getKeyguardCallback().onTrustGrantedWithFlags(0, 0, "");
|
||||
mController.getKeyguardCallback().onTrustGrantedForCurrentUser(
|
||||
false, new TrustGrantFlags(0), "");
|
||||
|
||||
// THEN verify NO trust message is shown
|
||||
verifyNoMessage(INDICATION_TYPE_TRUST);
|
||||
|
||||
Reference in New Issue
Block a user