From d95d2e7369a641edc89819cd0dd0264be2ee384a Mon Sep 17 00:00:00 2001 From: Beverly Date: Tue, 8 Feb 2022 13:13:21 +0000 Subject: [PATCH] Display grant trust messages on the lock screen Before, nothing was registered for the trust granted message callback and we were always showing the default trust granted message. Test: locally/manually add FLAG_DISPLAY_GRANT_TRUST_MESSAGE to all messages in TrustAgentWrapper. Observe messages are shown on the lock screen. Test: atest KeyguardIndicationControlerTest Fixes: 213911325 Change-Id: I239b71dcd14d7edde7d99a54cfbee43a211badc2 --- .../KeyguardIndicationController.java | 22 ++++++++++- .../KeyguardIndicationControllerTest.java | 37 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index a3f0a6dbf1daf..eccf27ee88413 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -143,6 +143,7 @@ public class KeyguardIndicationController { private String mRestingIndication; private String mAlignmentIndication; + private CharSequence mTrustGrantedIndication; private CharSequence mTransientIndication; private CharSequence mBiometricMessage; protected ColorStateList mInitialTextColorState; @@ -609,7 +610,9 @@ public class KeyguardIndicationController { */ @VisibleForTesting String getTrustGrantedIndication() { - return mContext.getString(R.string.keyguard_indication_trust_unlocked); + return TextUtils.isEmpty(mTrustGrantedIndication) + ? mContext.getString(R.string.keyguard_indication_trust_unlocked) + : mTrustGrantedIndication.toString(); } /** @@ -909,6 +912,7 @@ public class KeyguardIndicationController { pw.println(" mTextView.getText(): " + ( mTopIndicationView == null ? null : mTopIndicationView.getText())); pw.println(" computePowerIndication(): " + computePowerIndication()); + pw.println(" trustGrantedIndication: " + getTrustGrantedIndication()); mRotateTextViewController.dump(fd, pw, args); } @@ -1054,6 +1058,22 @@ public class KeyguardIndicationController { || msgId == FaceManager.FACE_ERROR_CANCELED); } + + @Override + public void onTrustChanged(int userId) { + if (KeyguardUpdateMonitor.getCurrentUser() != userId) { + return; + } + updateTrust(userId, getTrustGrantedIndication(), getTrustManagedIndication()); + } + + @Override + public void showTrustGrantedMessage(CharSequence message) { + mTrustGrantedIndication = message; + updateTrust(KeyguardUpdateMonitor.getCurrentUser(), getTrustGrantedIndication(), + getTrustManagedIndication()); + } + @Override public void onTrustAgentErrorMessage(CharSequence message) { showBiometricMessage(message); 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 529f6b47cf9e6..98e285743706d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java @@ -774,6 +774,43 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_LOGOUT); } + @Test + public void onTrustGrantedMessageDoesNotShowUntilTrustGranted() { + createController(); + + // GIVEN a trust granted message but trust isn't granted + final String trustGrantedMsg = "testing trust granted message"; + mController.getKeyguardCallback().showTrustGrantedMessage(trustGrantedMsg); + + verifyHideIndication(INDICATION_TYPE_TRUST); + + // WHEN trust is granted + when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); + mController.setVisible(true); + + // THEN verify the trust granted message shows + verifyIndicationMessage( + INDICATION_TYPE_TRUST, + trustGrantedMsg); + } + + @Test + public void onTrustGrantedMessageDoesShowsOnTrustGranted() { + createController(); + + // GIVEN trust is granted + when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); + + // WHEN the showTrustGranted message is called + final String trustGrantedMsg = "testing trust granted message"; + mController.getKeyguardCallback().showTrustGrantedMessage(trustGrantedMsg); + + // THEN verify the trust granted message shows + verifyIndicationMessage( + INDICATION_TYPE_TRUST, + trustGrantedMsg); + } + private void sendUpdateDisclosureBroadcast() { mBroadcastReceiver.onReceive(mContext, new Intent()); }