From 778db3306af7eec2a30c3e8fc99f3e7dc36ee6eb Mon Sep 17 00:00:00 2001 From: Scott Warner Date: Tue, 21 Jan 2020 09:45:56 -0500 Subject: [PATCH] Show charging status in addition to trust granted If the device is kept unlocked, it displays 'Kept unlocked by TrustAgent' and will not show charging state. This adds the charging state below the unlocked message Test: m, atest KeyguardIndicationControllerTest, check keyguard Fixes: 150780409 Change-Id: I6b3515167c990c27fa89b3742d72db98657768b0 --- packages/SystemUI/res/values/strings.xml | 3 ++ .../KeyguardIndicationController.java | 42 +++++++++++++++---- .../KeyguardIndicationControllerTest.java | 14 +++++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 496ab439bdc02..ecbe59872a21f 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1425,6 +1425,9 @@ Device will stay locked until you manually unlock + + %1$s\n%2$s + Get notifications faster diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index 4f8e6cfdf767e..9af90d6979478 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -284,6 +284,14 @@ public class KeyguardIndicationController implements StateListener, return mContext.getString(R.string.keyguard_indication_trust_unlocked); } + /** + * Sets if the device is plugged in + */ + @VisibleForTesting + void setPowerPluggedIn(boolean plugged) { + mPowerPluggedIn = plugged; + } + /** * Returns the indication text indicating that trust is currently being managed. * @@ -382,29 +390,48 @@ public class KeyguardIndicationController implements StateListener, int userId = KeyguardUpdateMonitor.getCurrentUser(); String trustGrantedIndication = getTrustGrantedIndication(); String trustManagedIndication = getTrustManagedIndication(); + + String powerIndication = null; + if (mPowerPluggedIn) { + powerIndication = computePowerIndication(); + } + if (!mKeyguardUpdateMonitor.isUserUnlocked(userId)) { mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked); mTextView.setTextColor(mInitialTextColorState); } else if (!TextUtils.isEmpty(mTransientIndication)) { - mTextView.switchIndication(mTransientIndication); + if (powerIndication != null) { + String indication = mContext.getResources().getString( + R.string.keyguard_indication_trust_unlocked_plugged_in, + mTransientIndication, powerIndication); + mTextView.switchIndication(indication); + } else { + mTextView.switchIndication(mTransientIndication); + } mTextView.setTextColor(mTransientTextColorState); } else if (!TextUtils.isEmpty(trustGrantedIndication) && mKeyguardUpdateMonitor.getUserHasTrust(userId)) { - mTextView.switchIndication(trustGrantedIndication); + if (powerIndication != null) { + String indication = mContext.getResources().getString( + R.string.keyguard_indication_trust_unlocked_plugged_in, + trustGrantedIndication, powerIndication); + mTextView.switchIndication(indication); + } else { + mTextView.switchIndication(trustGrantedIndication); + } mTextView.setTextColor(mInitialTextColorState); } else if (!TextUtils.isEmpty(mAlignmentIndication)) { mTextView.switchIndication(mAlignmentIndication); mTextView.setTextColor(Utils.getColorError(mContext)); } else if (mPowerPluggedIn) { - String indication = computePowerIndication(); if (DEBUG_CHARGING_SPEED) { - indication += ", " + (mChargingWattage / 1000) + " mW"; + powerIndication += ", " + (mChargingWattage / 1000) + " mW"; } mTextView.setTextColor(mInitialTextColorState); if (animate) { - animateText(mTextView, indication); + animateText(mTextView, powerIndication); } else { - mTextView.switchIndication(indication); + mTextView.switchIndication(powerIndication); } } else if (!TextUtils.isEmpty(trustManagedIndication) && mKeyguardUpdateMonitor.getUserTrustIsManaged(userId) @@ -469,7 +496,8 @@ public class KeyguardIndicationController implements StateListener, }); } - private String computePowerIndication() { + @VisibleForTesting + String computePowerIndication() { if (mPowerCharged) { return mContext.getResources().getString(R.string.keyguard_charged); } 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 581d795af3df0..f72b18cbd8a58 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java @@ -403,4 +403,18 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { verify(mStatusBarStateController).addCallback(eq(mController)); verify(mKeyguardUpdateMonitor, times(2)).registerCallback(any()); } + + @Test + public void unlockMethodCache_listenerUpdatesPluggedIndication() { + createController(); + when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); + mController.setPowerPluggedIn(true); + mController.setVisible(true); + String powerIndication = mController.computePowerIndication(); + String pluggedIndication = mContext.getString(R.string.keyguard_indication_trust_unlocked); + pluggedIndication = mContext.getString( + R.string.keyguard_indication_trust_unlocked_plugged_in, + pluggedIndication, powerIndication); + assertThat(mTextView.getText()).isEqualTo(pluggedIndication); + } }