From 21f78c2df08bd174c23e577619bf88cf949168a4 Mon Sep 17 00:00:00 2001 From: Beverly Date: Fri, 14 Jan 2022 09:54:48 -0500 Subject: [PATCH] Update all persistent kg messages when kg is shown We only want to remove all transient messages from being shown the next time the keyguard shows. Cleanup so unused code. Fixes: 214551067 Test: atest KeyguardIndicationControllerTest KeyguardIndicationRotateTextViewControllerTest Change-Id: I0a7c1dfafa49f6f3967d62e1d233a5cedf7f2497 --- ...ardIndicationRotateTextViewController.java | 12 +-- .../KeyguardIndicationController.java | 79 ++++--------------- .../KeyguardIndicationControllerTest.java | 39 ++++++++- 3 files changed, 56 insertions(+), 74 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java index d73d9cdb7d40f..0ad2807bed559 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardIndicationRotateTextViewController.java @@ -119,14 +119,13 @@ public class KeyguardIndicationRotateTextViewController extends return; } long minShowDuration = getMinVisibilityMillis(mIndicationMessages.get(mCurrIndicationType)); - final boolean hasPreviousIndication = mIndicationMessages.get(type) != null - && !TextUtils.isEmpty(mIndicationMessages.get(type).getMessage()); - final boolean hasNewIndication = newIndication != null; + final boolean hasNewIndication = newIndication != null + && !TextUtils.isEmpty(newIndication.getMessage()); if (!hasNewIndication) { mIndicationMessages.remove(type); mIndicationQueue.removeIf(x -> x == type); } else { - if (!hasPreviousIndication) { + if (!mIndicationQueue.contains(type)) { mIndicationQueue.add(type); } @@ -230,6 +229,7 @@ public class KeyguardIndicationRotateTextViewController extends public void clearMessages() { mCurrIndicationType = INDICATION_TYPE_NONE; mIndicationQueue.clear(); + mIndicationMessages.clear(); mView.clearMessages(); } @@ -310,7 +310,7 @@ public class KeyguardIndicationRotateTextViewController extends if (mIsDozing) { showIndication(INDICATION_TYPE_NONE); } else if (mIndicationQueue.size() > 0) { - showIndication(mIndicationQueue.remove(0)); + showIndication(mIndicationQueue.get(0)); } } }; @@ -327,7 +327,7 @@ public class KeyguardIndicationRotateTextViewController extends ShowNextIndication(long delay) { mShowIndicationRunnable = () -> { int type = mIndicationQueue.size() == 0 - ? INDICATION_TYPE_NONE : mIndicationQueue.remove(0); + ? INDICATION_TYPE_NONE : mIndicationQueue.get(0); showIndication(type); }; mCancelDelayedRunnable = mExecutor.executeDelayed(mShowIndicationRunnable, delay); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index cd4b74514937e..963a0d709dac6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -34,8 +34,6 @@ import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewCont import static com.android.systemui.keyguard.ScreenLifecycle.SCREEN_ON; import static com.android.systemui.plugins.FalsingManager.LOW_PENALTY; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; import android.app.IActivityManager; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; @@ -72,7 +70,6 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.settingslib.Utils; import com.android.settingslib.fuelgauge.BatteryStatus; import com.android.systemui.R; -import com.android.systemui.animation.Interpolators; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.qualifiers.Main; @@ -149,6 +146,7 @@ public class KeyguardIndicationController { private CharSequence mBiometricMessage; protected ColorStateList mInitialTextColorState; private boolean mVisible; + private boolean mOrganizationOwnedDevice; private boolean mPowerPluggedIn; private boolean mPowerPluggedInWired; @@ -256,13 +254,13 @@ public class KeyguardIndicationController { mExecutor, mStatusBarStateController); updateIndication(false /* animate */); - updateDisclosure(); + updateOrganizedOwnedDevice(); if (mBroadcastReceiver == null) { // Update the disclosure proactively to avoid IPC on the critical path. mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - updateDisclosure(); + updateOrganizedOwnedDevice(); } }; IntentFilter intentFilter = new IntentFilter(); @@ -305,12 +303,11 @@ public class KeyguardIndicationController { } /** - * Doesn't include disclosure (also a persistent indication) which gets triggered separately. - * * This method also doesn't update transient messages like biometrics since those messages * are also updated separately. */ private void updatePersistentIndications(boolean animate, int userId) { + updateDisclosure(); updateOwnerInfo(); updateBattery(animate); updateUserLocked(userId); @@ -320,9 +317,14 @@ public class KeyguardIndicationController { updateResting(); } - private void updateDisclosure() { + private void updateOrganizedOwnedDevice() { // avoid calling this method since it has an IPC - if (whitelistIpcs(this::isOrganizationOwnedDevice)) { + mOrganizationOwnedDevice = whitelistIpcs(this::isOrganizationOwnedDevice); + updatePersistentIndications(false, KeyguardUpdateMonitor.getCurrentUser()); + } + + private void updateDisclosure() { + if (mOrganizationOwnedDevice) { final CharSequence organizationName = getOrganizationOwnedDeviceOrganizationName(); final CharSequence disclosure = getDisclosureText(organizationName); mRotateTextViewController.updateIndication( @@ -335,8 +337,6 @@ public class KeyguardIndicationController { } else { mRotateTextViewController.hideIndication(INDICATION_TYPE_DISCLOSURE); } - - updateResting(); } private CharSequence getDisclosureText(@Nullable CharSequence organizationName) { @@ -753,60 +753,6 @@ public class KeyguardIndicationController { updatePersistentIndications(animate, KeyguardUpdateMonitor.getCurrentUser()); } - // animates textView - textView moves up and bounces down - private void animateText(KeyguardIndicationTextView textView, String indication) { - int yTranslation = mContext.getResources().getInteger( - R.integer.wired_charging_keyguard_text_animation_distance); - int animateUpDuration = mContext.getResources().getInteger( - R.integer.wired_charging_keyguard_text_animation_duration_up); - int animateDownDuration = mContext.getResources().getInteger( - R.integer.wired_charging_keyguard_text_animation_duration_down); - textView.animate().cancel(); - ViewClippingUtil.setClippingDeactivated(textView, true, mClippingParams); - textView.animate() - .translationYBy(yTranslation) - .setInterpolator(Interpolators.LINEAR) - .setDuration(animateUpDuration) - .setListener(new AnimatorListenerAdapter() { - private boolean mCancelled; - - @Override - public void onAnimationStart(Animator animation) { - textView.switchIndication(indication, null); - } - - @Override - public void onAnimationCancel(Animator animation) { - textView.setTranslationY(BOUNCE_ANIMATION_FINAL_Y); - mCancelled = true; - } - - @Override - public void onAnimationEnd(Animator animation) { - if (mCancelled) { - ViewClippingUtil.setClippingDeactivated(textView, false, - mClippingParams); - return; - } - textView.animate() - .setDuration(animateDownDuration) - .setInterpolator(Interpolators.BOUNCE) - .translationY(BOUNCE_ANIMATION_FINAL_Y) - .setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - textView.setTranslationY(BOUNCE_ANIMATION_FINAL_Y); - ViewClippingUtil.setClippingDeactivated(textView, false, - mClippingParams); - // Unset the listener, otherwise this may persist for - // another view property animation - textView.animate().setListener(null); - } - }); - } - }); - } - protected String computePowerIndication() { int chargingId; if (mBatteryOverheated) { @@ -1182,9 +1128,12 @@ public class KeyguardIndicationController { @Override public void onKeyguardShowingChanged() { + // All transient messages are gone the next time keyguard is shown if (!mKeyguardStateController.isShowing()) { mTopIndicationView.clearMessages(); mRotateTextViewController.clearMessages(); + } else { + updatePersistentIndications(false, KeyguardUpdateMonitor.getCurrentUser()); } } }; 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 7f357324bed08..cf1a36af24ba7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java @@ -24,6 +24,7 @@ import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewCont import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BATTERY; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BIOMETRIC_MESSAGE; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_DISCLOSURE; +import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_LOGOUT; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_OWNER_INFO; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_RESTING; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_TRANSIENT; @@ -86,7 +87,6 @@ import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.phone.KeyguardIndicationTextView; -import com.android.systemui.statusbar.phone.LockIcon; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.concurrency.FakeExecutor; @@ -132,8 +132,6 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { @Mock private BroadcastDispatcher mBroadcastDispatcher; @Mock - private LockIcon mLockIcon; - @Mock private StatusBarStateController mStatusBarStateController; @Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor; @@ -738,6 +736,41 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { verifyHideIndication(INDICATION_TYPE_OWNER_INFO); } + @Test + public void testOnKeyguardShowingChanged_notShowing_resetsMessages() { + createController(); + + // GIVEN keyguard isn't showing + when(mKeyguardStateController.isShowing()).thenReturn(false); + + // WHEN keyguard showing changed called + mKeyguardStateControllerCallback.onKeyguardShowingChanged(); + + // THEN messages are reset + verify(mRotateTextViewController).clearMessages(); + assertThat(mTextView.getText()).isEqualTo(""); + } + + @Test + public void testOnKeyguardShowingChanged_showing_updatesPersistentMessages() { + createController(); + + // GIVEN keyguard is showing + when(mKeyguardStateController.isShowing()).thenReturn(true); + + // WHEN keyguard showing changed called + mKeyguardStateControllerCallback.onKeyguardShowingChanged(); + + // THEN persistent messages are updated (in this case, most messages are hidden since + // no info is provided) - verify that this happens + verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_DISCLOSURE); + verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_OWNER_INFO); + verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_BATTERY); + verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_TRUST); + verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_ALIGNMENT); + verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_LOGOUT); + } + private void sendUpdateDisclosureBroadcast() { mBroadcastReceiver.onReceive(mContext, new Intent()); }