From cb160f318b26a2eb1fbeed717dacb14551b2af1f Mon Sep 17 00:00:00 2001 From: Beverly Date: Tue, 8 Nov 2022 23:19:46 +0000 Subject: [PATCH] Setup callbacks for ChipBar for ActiveUnlock In the KUM callback for trustGranted, send the trustGranted message along with the flags so that listeners can appropriately decide whether to show the provided message if the keyguard will dismiss. Bug: 240196500 Test: atest SystemUITests SystemUIGoogleTests Test: "Unlocked by Smart Lock" message shows when SmartLock is enabled Change-Id: I975bfef0bf86672fae5f38f94938f1f2a90d0ef4 --- .../keyguard/KeyguardHostViewController.java | 2 +- .../keyguard/KeyguardUpdateMonitor.java | 32 +++++++------------ .../KeyguardUpdateMonitorCallback.java | 12 +++---- .../KeyguardIndicationController.java | 19 +++++++---- .../keyguard/KeyguardUpdateMonitorTest.java | 5 ++- .../KeyguardIndicationControllerTest.java | 8 ++--- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java index db64f05ccbea7..8fa7b11e26645 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java @@ -68,7 +68,7 @@ public class KeyguardHostViewController extends ViewController private final KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { @Override - public void onTrustGrantedWithFlags(int flags, int userId) { + public void onTrustGrantedWithFlags(int flags, int userId, String message) { if (userId != KeyguardUpdateMonitor.getCurrentUser()) return; boolean bouncerVisible = mView.isVisibleToUser(); boolean temporaryAndRenewable = diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 47ea8784aae85..c8bcbbdb68835 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -486,19 +486,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab FACE_AUTH_TRIGGERED_TRUST_DISABLED); } - 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); - if (enabled && flags != 0) { - cb.onTrustGrantedWithFlags(flags, userId); - } - } - } - + String message = null; if (KeyguardUpdateMonitor.getCurrentUser() == userId) { - CharSequence message = null; final boolean userHasTrust = getUserHasTrust(userId); if (userHasTrust && trustGrantedMessages != null) { for (String msg : trustGrantedMessages) { @@ -508,14 +497,17 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } } } - - 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.showTrustGrantedMessage(message); + } + 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); } } } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java index c06e1dcf08c25..c5142f309a461 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java @@ -174,14 +174,12 @@ public class KeyguardUpdateMonitorCallback { public void onTrustManagedChanged(int userId) { } /** - * Called after trust was granted with non-zero flags. + * Called after trust was granted. + * @param userId of the user that has been granted trust + * @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) { } - - /** - * Called when setting the trust granted message. - */ - public void showTrustGrantedMessage(@Nullable CharSequence message) { } + public void onTrustGrantedWithFlags(int flags, int userId, @Nullable String message) { } /** * Called when a biometric has been acquired. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index 0deb47d73460f..15f4b12ba10e5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -1179,16 +1179,14 @@ public class KeyguardIndicationController { @Override public void onTrustChanged(int userId) { - if (getCurrentUser() != userId) { - return; - } + if (!isCurrentUser(userId)) return; updateDeviceEntryIndication(false); } @Override - public void showTrustGrantedMessage(CharSequence message) { - mTrustGrantedIndication = message; - updateDeviceEntryIndication(false); + public void onTrustGrantedWithFlags(int flags, int userId, @Nullable String message) { + if (!isCurrentUser(userId)) return; + showTrustGrantedMessage(flags, message); } @Override @@ -1248,6 +1246,15 @@ public class KeyguardIndicationController { } } + private boolean isCurrentUser(int userId) { + return getCurrentUser() == userId; + } + + void showTrustGrantedMessage(int flags, @Nullable CharSequence message) { + mTrustGrantedIndication = message; + updateDeviceEntryIndication(false); + } + private void handleFaceLockoutError(String errString) { int followupMsgId = canUnlockWithFingerprint() ? R.string.keyguard_suggest_fingerprint : R.string.keyguard_unlock; diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index c6200daca6f66..a3a089f4647fb 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -1314,7 +1314,10 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { Arrays.asList("Unlocked by wearable")); // THEN the showTrustGrantedMessage should be called with the first message - verify(mTestCallback).showTrustGrantedMessage("Unlocked by wearable"); + verify(mTestCallback).onTrustGrantedWithFlags( + eq(0), + eq(KeyguardUpdateMonitor.getCurrentUser()), + eq("Unlocked by wearable")); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java index 797256f91022c..1598dbb7d29ea 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java @@ -1064,7 +1064,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { // GIVEN a trust granted message but trust isn't granted final String trustGrantedMsg = "testing trust granted message"; - mController.getKeyguardCallback().showTrustGrantedMessage(trustGrantedMsg); + mController.getKeyguardCallback().onTrustGrantedWithFlags(0, 0, trustGrantedMsg); verifyHideIndication(INDICATION_TYPE_TRUST); @@ -1088,7 +1088,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { // WHEN the showTrustGranted method is called final String trustGrantedMsg = "testing trust granted message"; - mController.getKeyguardCallback().showTrustGrantedMessage(trustGrantedMsg); + mController.getKeyguardCallback().onTrustGrantedWithFlags(0, 0, trustGrantedMsg); // THEN verify the trust granted message shows verifyIndicationMessage( @@ -1105,7 +1105,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); // WHEN the showTrustGranted method is called with a null message - mController.getKeyguardCallback().showTrustGrantedMessage(null); + mController.getKeyguardCallback().onTrustGrantedWithFlags(0, 0, null); // THEN verify the default trust granted message shows verifyIndicationMessage( @@ -1122,7 +1122,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); // WHEN the showTrustGranted method is called with an EMPTY string - mController.getKeyguardCallback().showTrustGrantedMessage(""); + mController.getKeyguardCallback().onTrustGrantedWithFlags(0, 0, ""); // THEN verify NO trust message is shown verifyNoMessage(INDICATION_TYPE_TRUST);