Merge "Update KeyguardIndicationController" into sc-dev

This commit is contained in:
Beverly Tai
2021-04-12 17:36:02 +00:00
committed by Android (Google) Code Review
5 changed files with 123 additions and 203 deletions

View File

@@ -19,6 +19,7 @@ package com.android.systemui.keyguard;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color; import android.graphics.Color;
import android.text.TextUtils;
import android.view.View; import android.view.View;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
@@ -69,8 +70,7 @@ public class KeyguardIndicationRotateTextViewController extends
public KeyguardIndicationRotateTextViewController( public KeyguardIndicationRotateTextViewController(
KeyguardIndicationTextView view, KeyguardIndicationTextView view,
@Main DelayableExecutor executor, @Main DelayableExecutor executor,
StatusBarStateController statusBarStateController, StatusBarStateController statusBarStateController
int lockScreenMode
) { ) {
super(view); super(view);
mMaxAlpha = view.getAlpha(); mMaxAlpha = view.getAlpha();
@@ -78,7 +78,6 @@ public class KeyguardIndicationRotateTextViewController extends
mInitialTextColorState = mView != null mInitialTextColorState = mView != null
? mView.getTextColors() : ColorStateList.valueOf(Color.WHITE); ? mView.getTextColors() : ColorStateList.valueOf(Color.WHITE);
mStatusBarStateController = statusBarStateController; mStatusBarStateController = statusBarStateController;
mView.setLockScreenMode(lockScreenMode);
init(); init();
} }
@@ -102,7 +101,7 @@ public class KeyguardIndicationRotateTextViewController extends
* the IndicationQueue comes around. * the IndicationQueue comes around.
*/ */
public void updateIndication(@IndicationType int type, KeyguardIndication newIndication, public void updateIndication(@IndicationType int type, KeyguardIndication newIndication,
boolean showImmediately) { boolean updateImmediately) {
if (type == INDICATION_TYPE_NOW_PLAYING if (type == INDICATION_TYPE_NOW_PLAYING
|| type == INDICATION_TYPE_REVERSE_CHARGING) { || type == INDICATION_TYPE_REVERSE_CHARGING) {
// temporarily don't show here, instead use AmbientContainer b/181049781 // temporarily don't show here, instead use AmbientContainer b/181049781
@@ -125,7 +124,7 @@ public class KeyguardIndicationRotateTextViewController extends
return; return;
} }
final boolean showNow = showImmediately final boolean showNow = updateImmediately
|| mCurrIndicationType == INDICATION_TYPE_NONE || mCurrIndicationType == INDICATION_TYPE_NONE
|| mCurrIndicationType == type; || mCurrIndicationType == type;
if (hasNewIndication) { if (hasNewIndication) {
@@ -139,7 +138,7 @@ public class KeyguardIndicationRotateTextViewController extends
if (mCurrIndicationType == type if (mCurrIndicationType == type
&& !hasNewIndication && !hasNewIndication
&& showImmediately) { && updateImmediately) {
if (mShowNextIndicationRunnable != null) { if (mShowNextIndicationRunnable != null) {
mShowNextIndicationRunnable.runImmediately(); mShowNextIndicationRunnable.runImmediately();
} else { } else {
@@ -154,6 +153,10 @@ public class KeyguardIndicationRotateTextViewController extends
* If the current indication is of this type, immediately stops showing the message. * If the current indication is of this type, immediately stops showing the message.
*/ */
public void hideIndication(@IndicationType int type) { public void hideIndication(@IndicationType int type) {
if (!mIndicationMessages.containsKey(type)
|| TextUtils.isEmpty(mIndicationMessages.get(type).getMessage())) {
return;
}
updateIndication(type, null, true); updateIndication(type, null, true);
} }

View File

@@ -20,7 +20,6 @@ import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static com.android.keyguard.KeyguardUpdateMonitor.LOCK_SCREEN_MODE_LAYOUT_1;
import static com.android.systemui.DejankUtils.whitelistIpcs; import static com.android.systemui.DejankUtils.whitelistIpcs;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_ALIGNMENT; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_ALIGNMENT;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BATTERY; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BATTERY;
@@ -30,6 +29,7 @@ import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewCont
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_RESTING; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_RESTING;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_TRUST; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_TRUST;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_USER_LOCKED; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_USER_LOCKED;
import static com.android.systemui.plugins.FalsingManager.LOW_PENALTY;
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
@@ -77,6 +77,7 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dock.DockManager; import com.android.systemui.dock.DockManager;
import com.android.systemui.keyguard.KeyguardIndication; import com.android.systemui.keyguard.KeyguardIndication;
import com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController; import com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.phone.KeyguardIndicationTextView; import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
@@ -120,6 +121,7 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
private final @Main DelayableExecutor mExecutor; private final @Main DelayableExecutor mExecutor;
private final LockPatternUtils mLockPatternUtils; private final LockPatternUtils mLockPatternUtils;
private final IActivityManager mIActivityManager; private final IActivityManager mIActivityManager;
private final FalsingManager mFalsingManager;
protected KeyguardIndicationRotateTextViewController mRotateTextViewController; protected KeyguardIndicationRotateTextViewController mRotateTextViewController;
private BroadcastReceiver mBroadcastReceiver; private BroadcastReceiver mBroadcastReceiver;
@@ -171,7 +173,8 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
DevicePolicyManager devicePolicyManager, DevicePolicyManager devicePolicyManager,
IBatteryStats iBatteryStats, IBatteryStats iBatteryStats,
UserManager userManager, UserManager userManager,
@Main DelayableExecutor executor) { @Main DelayableExecutor executor,
FalsingManager falsingManager) {
mContext = context; mContext = context;
mBroadcastDispatcher = broadcastDispatcher; mBroadcastDispatcher = broadcastDispatcher;
mDevicePolicyManager = devicePolicyManager; mDevicePolicyManager = devicePolicyManager;
@@ -188,6 +191,7 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
mExecutor = executor; mExecutor = executor;
mLockPatternUtils = new LockPatternUtils(context); mLockPatternUtils = new LockPatternUtils(context);
mIActivityManager = ActivityManager.getService(); mIActivityManager = ActivityManager.getService();
mFalsingManager = falsingManager;
mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback()); mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback());
mKeyguardUpdateMonitor.registerCallback(mTickReceiver); mKeyguardUpdateMonitor.registerCallback(mTickReceiver);
@@ -203,8 +207,7 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
mRotateTextViewController = new KeyguardIndicationRotateTextViewController( mRotateTextViewController = new KeyguardIndicationRotateTextViewController(
indicationArea.findViewById(R.id.keyguard_indication_text_bottom), indicationArea.findViewById(R.id.keyguard_indication_text_bottom),
mExecutor, mExecutor,
mStatusBarStateController, mStatusBarStateController);
mLockScreenMode);
updateIndication(false /* animate */); updateIndication(false /* animate */);
updateDisclosure(); updateDisclosure();
if (mBroadcastReceiver == null) { if (mBroadcastReceiver == null) {
@@ -284,9 +287,7 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
mRotateTextViewController.hideIndication(INDICATION_TYPE_DISCLOSURE); mRotateTextViewController.hideIndication(INDICATION_TYPE_DISCLOSURE);
} }
if (isKeyguardLayoutEnabled()) { updateResting();
updateResting();
}
} }
private CharSequence getDisclosureText(@Nullable CharSequence organizationName) { private CharSequence getDisclosureText(@Nullable CharSequence organizationName) {
@@ -306,10 +307,6 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
} }
private void updateOwnerInfo() { private void updateOwnerInfo() {
if (!isKeyguardLayoutEnabled()) {
mRotateTextViewController.hideIndication(INDICATION_TYPE_OWNER_INFO);
return;
}
String info = mLockPatternUtils.getDeviceOwnerInfo(); String info = mLockPatternUtils.getDeviceOwnerInfo();
if (info == null) { if (info == null) {
// Use the current user owner information if enabled. // Use the current user owner information if enabled.
@@ -431,15 +428,7 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
} }
} }
protected boolean isKeyguardLayoutEnabled() {
return mLockScreenMode == LOCK_SCREEN_MODE_LAYOUT_1;
}
private void updateLogoutView() { private void updateLogoutView() {
if (!isKeyguardLayoutEnabled()) {
mRotateTextViewController.hideIndication(INDICATION_TYPE_LOGOUT);
return;
}
final boolean shouldShowLogout = mKeyguardUpdateMonitor.isLogoutEnabled() final boolean shouldShowLogout = mKeyguardUpdateMonitor.isLogoutEnabled()
&& KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM; && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM;
if (shouldShowLogout) { if (shouldShowLogout) {
@@ -452,6 +441,9 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
.setBackground(mContext.getDrawable( .setBackground(mContext.getDrawable(
com.android.systemui.R.drawable.logout_button_background)) com.android.systemui.R.drawable.logout_button_background))
.setClickListener((view) -> { .setClickListener((view) -> {
if (mFalsingManager.isFalseTap(LOW_PENALTY)) {
return;
}
int currentUserId = KeyguardUpdateMonitor.getCurrentUser(); int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
try { try {
mIActivityManager.switchUser(UserHandle.USER_SYSTEM); mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
@@ -651,76 +643,8 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
} }
// LOCK SCREEN // LOCK SCREEN
// Some cases here might need to hide the indication (if the battery is not present) mTopIndicationView.setVisibility(GONE);
int userId = KeyguardUpdateMonitor.getCurrentUser(); updateIndications(animate, KeyguardUpdateMonitor.getCurrentUser());
if (mLockScreenMode == LOCK_SCREEN_MODE_LAYOUT_1) {
mTopIndicationView.setVisibility(GONE);
updateIndications(animate, userId);
} else {
boolean hideIndication = false;
boolean isError = false;
String trustGrantedIndication = getTrustGrantedIndication();
String trustManagedIndication = getTrustManagedIndication();
String powerIndication = null;
if (mPowerPluggedIn || mEnableBatteryDefender) {
powerIndication = computePowerIndication();
}
if (!mKeyguardUpdateMonitor.isUserUnlocked(userId)) {
mTopIndicationView.switchIndication(
com.android.internal.R.string.lockscreen_storage_locked);
} else if (!TextUtils.isEmpty(mTransientIndication)) {
if (powerIndication != null && !mTransientIndication.equals(powerIndication)) {
String indication = mContext.getResources().getString(
R.string.keyguard_indication_trust_unlocked_plugged_in,
mTransientIndication, powerIndication);
mTopIndicationView.switchIndication(indication, null);
hideIndication = !mBatteryPresent;
} else {
mTopIndicationView.switchIndication(mTransientIndication, null);
}
isError = mTransientTextIsError;
} else if (!TextUtils.isEmpty(trustGrantedIndication)
&& mKeyguardUpdateMonitor.getUserHasTrust(userId)) {
if (powerIndication != null) {
String indication = mContext.getResources().getString(
R.string.keyguard_indication_trust_unlocked_plugged_in,
trustGrantedIndication, powerIndication);
mTopIndicationView.switchIndication(indication, null);
hideIndication = !mBatteryPresent;
} else {
mTopIndicationView.switchIndication(trustGrantedIndication, null);
}
} else if (!TextUtils.isEmpty(mAlignmentIndication)) {
mTopIndicationView.switchIndication(mAlignmentIndication, null);
isError = true;
hideIndication = !mBatteryPresent;
} else if (mPowerPluggedIn || mEnableBatteryDefender) {
if (DEBUG_CHARGING_SPEED) {
powerIndication += ", " + (mChargingWattage / 1000) + " mW";
}
if (animate) {
animateText(mTopIndicationView, powerIndication);
} else {
mTopIndicationView.switchIndication(powerIndication, null);
}
hideIndication = !mBatteryPresent;
} else if (!TextUtils.isEmpty(trustManagedIndication)
&& mKeyguardUpdateMonitor.getUserTrustIsManaged(userId)
&& !mKeyguardUpdateMonitor.getUserHasTrust(userId)) {
mTopIndicationView.switchIndication(trustManagedIndication, null);
} else {
mTopIndicationView.switchIndication(mRestingIndication, null);
}
mTopIndicationView.setTextColor(
isError ? Utils.getColorError(mContext) : mInitialTextColorState);
if (hideIndication) {
mIndicationArea.setVisibility(GONE);
}
}
} }
// animates textView - textView moves up and bounces down // animates textView - textView moves up and bounces down
@@ -883,7 +807,7 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
@Override @Override
public void onUnlockedChanged() { public void onUnlockedChanged() {
updateIndication(!mDozing); updateIndication(false);
} }
protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback { protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback {
@@ -1025,7 +949,7 @@ public class KeyguardIndicationController implements KeyguardStateController.Cal
@Override @Override
public void onBiometricRunningStateChanged(boolean running, public void onBiometricRunningStateChanged(boolean running,
BiometricSourceType biometricSourceType) { BiometricSourceType biometricSourceType) {
if (running) { if (running && biometricSourceType == BiometricSourceType.FACE) {
// Let's hide any previous messages when authentication starts, otherwise // Let's hide any previous messages when authentication starts, otherwise
// multiple auth attempts would overlap. // multiple auth attempts would overlap.
hideTransientIndication(); hideTransientIndication();

View File

@@ -16,8 +16,6 @@
package com.android.systemui.statusbar.phone; package com.android.systemui.statusbar.phone;
import static com.android.keyguard.KeyguardUpdateMonitor.LOCK_SCREEN_MODE_LAYOUT_1;
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet; import android.animation.AnimatorSet;
@@ -40,16 +38,12 @@ import java.util.LinkedList;
* A view to show hints on Keyguard ("Swipe up to unlock", "Tap again to open"). * A view to show hints on Keyguard ("Swipe up to unlock", "Tap again to open").
*/ */
public class KeyguardIndicationTextView extends TextView { public class KeyguardIndicationTextView extends TextView {
private static final int FADE_OUT_MILLIS = 200;
private static final int FADE_IN_MILLIS = 250;
private static final long MSG_DURATION_MILLIS = 600; private static final long MSG_DURATION_MILLIS = 600;
private long mNextAnimationTime = 0; private long mNextAnimationTime = 0;
private boolean mAnimationsEnabled = true; private boolean mAnimationsEnabled = true;
private LinkedList<CharSequence> mMessages = new LinkedList<>(); private LinkedList<CharSequence> mMessages = new LinkedList<>();
private LinkedList<KeyguardIndication> mKeyguardIndicationInfo = new LinkedList<>(); private LinkedList<KeyguardIndication> mKeyguardIndicationInfo = new LinkedList<>();
private boolean mUseNewAnimations = false;
public KeyguardIndicationTextView(Context context) { public KeyguardIndicationTextView(Context context) {
super(context); super(context);
} }
@@ -67,10 +61,6 @@ public class KeyguardIndicationTextView extends TextView {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
} }
public void setLockScreenMode(int lockScreenMode) {
mUseNewAnimations = lockScreenMode == LOCK_SCREEN_MODE_LAYOUT_1;
}
/** /**
* Changes the text with an animation and makes sure a single indication is shown long enough. * Changes the text with an animation and makes sure a single indication is shown long enough.
*/ */
@@ -148,15 +138,11 @@ public class KeyguardIndicationTextView extends TextView {
} }
}); });
if (mUseNewAnimations) { Animator yTranslate =
Animator yTranslate = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0, -getYTranslationPixels());
ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0, -getYTranslationPixels()); yTranslate.setDuration(getFadeOutDuration());
yTranslate.setDuration(getFadeOutDuration()); fadeOut.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN);
fadeOut.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN); animatorSet.playTogether(fadeOut, yTranslate);
animatorSet.playTogether(fadeOut, yTranslate);
} else {
animatorSet.play(fadeOut);
}
return animatorSet; return animatorSet;
} }
@@ -168,20 +154,16 @@ public class KeyguardIndicationTextView extends TextView {
fadeIn.setDuration(getFadeInDuration()); fadeIn.setDuration(getFadeInDuration());
fadeIn.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); fadeIn.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
if (mUseNewAnimations) { Animator yTranslate =
Animator yTranslate = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, getYTranslationPixels(), 0);
ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, getYTranslationPixels(), 0); yTranslate.setDuration(getYInDuration());
yTranslate.setDuration(getYInDuration()); yTranslate.addListener(new AnimatorListenerAdapter() {
yTranslate.addListener(new AnimatorListenerAdapter() { @Override
@Override public void onAnimationCancel(Animator animation) {
public void onAnimationCancel(Animator animation) { setTranslationY(0);
setTranslationY(0); }
} });
}); animatorSet.playTogether(yTranslate, fadeIn);
animatorSet.playTogether(yTranslate, fadeIn);
} else {
animatorSet.play(fadeIn);
}
return animatorSet; return animatorSet;
} }
@@ -193,26 +175,22 @@ public class KeyguardIndicationTextView extends TextView {
private long getFadeInDelay() { private long getFadeInDelay() {
if (!mAnimationsEnabled) return 0L; if (!mAnimationsEnabled) return 0L;
if (mUseNewAnimations) return 150L; return 150L;
return 0L;
} }
private long getFadeInDuration() { private long getFadeInDuration() {
if (!mAnimationsEnabled) return 0L; if (!mAnimationsEnabled) return 0L;
if (mUseNewAnimations) return 317L; return 317L;
return FADE_IN_MILLIS;
} }
private long getYInDuration() { private long getYInDuration() {
if (!mAnimationsEnabled) return 0L; if (!mAnimationsEnabled) return 0L;
if (mUseNewAnimations) return 600L; return 600L;
return 0L;
} }
private long getFadeOutDuration() { private long getFadeOutDuration() {
if (!mAnimationsEnabled) return 0L; if (!mAnimationsEnabled) return 0L;
if (mUseNewAnimations) return 167L; return 167L;
return FADE_OUT_MILLIS;
} }
private void setNextAnimationTime(long time) { private void setNextAnimationTime(long time) {

View File

@@ -17,7 +17,6 @@
package com.android.systemui.keyguard; package com.android.systemui.keyguard;
import static com.android.keyguard.KeyguardUpdateMonitor.LOCK_SCREEN_MODE_LAYOUT_1;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BATTERY; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BATTERY;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_DISCLOSURE; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_DISCLOSURE;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_OWNER_INFO; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_OWNER_INFO;
@@ -77,7 +76,7 @@ public class KeyguardIndicationRotateTextViewControllerTest extends SysuiTestCas
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
when(mView.getTextColors()).thenReturn(ColorStateList.valueOf(Color.WHITE)); when(mView.getTextColors()).thenReturn(ColorStateList.valueOf(Color.WHITE));
mController = new KeyguardIndicationRotateTextViewController(mView, mExecutor, mController = new KeyguardIndicationRotateTextViewController(mView, mExecutor,
mStatusBarStateController, LOCK_SCREEN_MODE_LAYOUT_1); mStatusBarStateController);
mController.onViewAttached(); mController.onViewAttached();
verify(mStatusBarStateController).addCallback(mStatusBarStateListenerCaptor.capture()); verify(mStatusBarStateController).addCallback(mStatusBarStateListenerCaptor.capture());

View File

@@ -20,7 +20,13 @@ import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED; import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE; import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_ALIGNMENT;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BATTERY;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_DISCLOSURE; import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_DISCLOSURE;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_RESTING;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_TRANSIENT;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_TRUST;
import static com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_USER_LOCKED;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -29,6 +35,8 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@@ -70,6 +78,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dock.DockManager; import com.android.systemui.dock.DockManager;
import com.android.systemui.keyguard.KeyguardIndication; import com.android.systemui.keyguard.KeyguardIndication;
import com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController; import com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.phone.KeyguardIndicationTextView; import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
import com.android.systemui.statusbar.phone.LockIcon; import com.android.systemui.statusbar.phone.LockIcon;
@@ -130,6 +139,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
private DockManager mDockManager; private DockManager mDockManager;
@Mock @Mock
private KeyguardIndicationRotateTextViewController mRotateTextViewController; private KeyguardIndicationRotateTextViewController mRotateTextViewController;
@Mock
private FalsingManager mFalsingManager;
@Captor @Captor
private ArgumentCaptor<DockManager.AlignmentStateListener> mAlignmentListener; private ArgumentCaptor<DockManager.AlignmentStateListener> mAlignmentListener;
@Captor @Captor
@@ -197,7 +208,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mController = new KeyguardIndicationController(mContext, mWakeLockBuilder, mController = new KeyguardIndicationController(mContext, mWakeLockBuilder,
mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor, mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor,
mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats, mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats,
mUserManager, mExecutor); mUserManager, mExecutor, mFalsingManager);
mController.setIndicationArea(mIndicationArea); mController.setIndicationArea(mIndicationArea);
verify(mStatusBarStateController).addCallback(mStatusBarStateListenerCaptor.capture()); verify(mStatusBarStateController).addCallback(mStatusBarStateListenerCaptor.capture());
mStatusBarStateListener = mStatusBarStateListenerCaptor.getValue(); mStatusBarStateListener = mStatusBarStateListenerCaptor.getValue();
@@ -227,10 +238,11 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
}); });
mInstrumentation.waitForIdleSync(); mInstrumentation.waitForIdleSync();
assertThat(mTextView.getText()).isEqualTo(
verifyIndicationMessage(INDICATION_TYPE_ALIGNMENT,
mContext.getResources().getString(R.string.dock_alignment_slow_charging)); mContext.getResources().getString(R.string.dock_alignment_slow_charging));
assertThat(mTextView.getCurrentTextColor()).isEqualTo( assertThat(mKeyguardIndicationCaptor.getValue().getTextColor())
Utils.getColorError(mContext).getDefaultColor()); .isEqualTo(Utils.getColorError(mContext));
} }
@Test @Test
@@ -244,10 +256,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
}); });
mInstrumentation.waitForIdleSync(); mInstrumentation.waitForIdleSync();
assertThat(mTextView.getText()).isEqualTo( verifyIndicationMessage(INDICATION_TYPE_ALIGNMENT,
mContext.getResources().getString(R.string.dock_alignment_not_charging)); mContext.getResources().getString(R.string.dock_alignment_not_charging));
assertThat(mTextView.getCurrentTextColor()).isEqualTo( assertThat(mKeyguardIndicationCaptor.getValue().getTextColor())
Utils.getColorError(mContext).getDefaultColor()); .isEqualTo(Utils.getColorError(mContext));
} }
@Test @Test
@@ -293,9 +305,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false); when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_DISCLOSURE); verifyHideIndication(INDICATION_TYPE_DISCLOSURE);
verify(mRotateTextViewController, never()).updateIndication(eq(INDICATION_TYPE_DISCLOSURE),
any(), anyBoolean());
} }
@Test @Test
@@ -305,10 +315,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null); when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).updateIndication(eq(INDICATION_TYPE_DISCLOSURE), verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureGeneric);
mKeyguardIndicationCaptor.capture(), eq(false));
assertThat(mKeyguardIndicationCaptor.getValue().getMessage())
.isEqualTo(mDisclosureGeneric);
} }
@Test @Test
@@ -320,10 +327,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mDevicePolicyManager.getOrganizationNameForUser(eq(10))).thenReturn(null); when(mDevicePolicyManager.getOrganizationNameForUser(eq(10))).thenReturn(null);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).updateIndication(eq(INDICATION_TYPE_DISCLOSURE), verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureGeneric);
mKeyguardIndicationCaptor.capture(), eq(false));
assertThat(mKeyguardIndicationCaptor.getValue().getMessage())
.isEqualTo(mDisclosureGeneric);
} }
@Test @Test
@@ -333,10 +337,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME); when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).updateIndication(eq(INDICATION_TYPE_DISCLOSURE), verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureWithOrganization);
mKeyguardIndicationCaptor.capture(), eq(false));
assertThat(mKeyguardIndicationCaptor.getValue().getMessage())
.isEqualTo(mDisclosureWithOrganization);
} }
@Test @Test
@@ -348,10 +349,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mDevicePolicyManager.getOrganizationNameForUser(eq(10))).thenReturn(ORGANIZATION_NAME); when(mDevicePolicyManager.getOrganizationNameForUser(eq(10))).thenReturn(ORGANIZATION_NAME);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).updateIndication(eq(INDICATION_TYPE_DISCLOSURE), verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureWithOrganization);
mKeyguardIndicationCaptor.capture(), eq(false));
assertThat(mKeyguardIndicationCaptor.getValue().getMessage())
.isEqualTo(mDisclosureWithOrganization);
} }
@Test @Test
@@ -363,26 +361,20 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null); when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).updateIndication(eq(INDICATION_TYPE_DISCLOSURE), verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureGeneric);
mKeyguardIndicationCaptor.capture(), eq(false));
assertThat(mKeyguardIndicationCaptor.getValue().getMessage())
.isEqualTo(mDisclosureGeneric);
reset(mRotateTextViewController); reset(mRotateTextViewController);
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME); when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).updateIndication(eq(INDICATION_TYPE_DISCLOSURE), verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureWithOrganization);
mKeyguardIndicationCaptor.capture(), eq(false));
assertThat(mKeyguardIndicationCaptor.getValue().getMessage())
.isEqualTo(mDisclosureWithOrganization);
reset(mRotateTextViewController); reset(mRotateTextViewController);
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false); when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).hideIndication(INDICATION_TYPE_DISCLOSURE); verifyHideIndication(INDICATION_TYPE_DISCLOSURE);
} }
@Test @Test
@@ -395,10 +387,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
.thenReturn(DEVICE_OWNER_TYPE_FINANCED); .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
verify(mRotateTextViewController).updateIndication(eq(INDICATION_TYPE_DISCLOSURE), verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mFinancedDisclosureWithOrganization);
mKeyguardIndicationCaptor.capture(), eq(false));
assertThat(mKeyguardIndicationCaptor.getValue().getMessage())
.isEqualTo(mFinancedDisclosureWithOrganization);
} }
@Test @Test
@@ -462,10 +451,11 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mController.getKeyguardCallback().onBiometricHelp( mController.getKeyguardCallback().onBiometricHelp(
KeyguardUpdateMonitor.BIOMETRIC_HELP_FACE_NOT_RECOGNIZED, message, KeyguardUpdateMonitor.BIOMETRIC_HELP_FACE_NOT_RECOGNIZED, message,
BiometricSourceType.FACE); BiometricSourceType.FACE);
assertThat(mTextView.getText()).isEqualTo(message); verifyTransientMessage(message);
reset(mRotateTextViewController);
mStatusBarStateListener.onDozingChanged(true); mStatusBarStateListener.onDozingChanged(true);
assertThat(mTextView.getText()).isNotEqualTo(message); verifyHideIndication(INDICATION_TYPE_TRANSIENT);
} }
@Test @Test
@@ -477,7 +467,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mController.getKeyguardCallback().onBiometricError(FaceManager.FACE_ERROR_TIMEOUT, mController.getKeyguardCallback().onBiometricError(FaceManager.FACE_ERROR_TIMEOUT,
"A message", BiometricSourceType.FACE); "A message", BiometricSourceType.FACE);
assertThat(mTextView.getText()).isEqualTo(message); verifyTransientMessage(message);
mStatusBarStateListener.onDozingChanged(true); mStatusBarStateListener.onDozingChanged(true);
assertThat(mTextView.getText()).isNotEqualTo(message); assertThat(mTextView.getText()).isNotEqualTo(message);
@@ -503,19 +493,22 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
reset(mKeyguardUpdateMonitor); reset(mKeyguardUpdateMonitor);
mController.setVisible(true); mController.setVisible(true);
assertThat(mTextView.getText()).isEqualTo( verifyIndicationMessage(INDICATION_TYPE_USER_LOCKED,
mContext.getString(com.android.internal.R.string.lockscreen_storage_locked)); mContext.getString(com.android.internal.R.string.lockscreen_storage_locked));
reset(mRotateTextViewController);
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true);
mController.setRestingIndication(restingIndication); mController.setRestingIndication(restingIndication);
assertThat(mTextView.getText()).isEqualTo(mController.getTrustGrantedIndication()); verifyHideIndication(INDICATION_TYPE_USER_LOCKED);
verifyIndicationMessage(INDICATION_TYPE_RESTING, restingIndication);
reset(mRotateTextViewController);
reset(mKeyguardUpdateMonitor); reset(mKeyguardUpdateMonitor);
when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true);
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(false); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(false);
mController.onUnlockedChanged(); mController.onUnlockedChanged();
assertThat(mTextView.getText()).isEqualTo(restingIndication); verifyIndicationMessage(INDICATION_TYPE_RESTING, restingIndication);
} }
@Test @Test
@@ -567,12 +560,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
mController.setPowerPluggedIn(true); mController.setPowerPluggedIn(true);
mController.setVisible(true); mController.setVisible(true);
String powerIndication = mController.computePowerIndication();
String pluggedIndication = mContext.getString(R.string.keyguard_indication_trust_unlocked); verifyIndicationMessage(
pluggedIndication = mContext.getString( INDICATION_TYPE_TRUST,
R.string.keyguard_indication_trust_unlocked_plugged_in, mContext.getString(R.string.keyguard_indication_trust_unlocked));
pluggedIndication, powerIndication);
assertThat(mTextView.getText()).isEqualTo(pluggedIndication);
} }
@Test @Test
@@ -586,10 +577,11 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mController.getKeyguardCallback().onRefreshBatteryInfo(status); mController.getKeyguardCallback().onRefreshBatteryInfo(status);
mController.setVisible(true); mController.setVisible(true);
String percentage = NumberFormat.getPercentInstance().format(80 / 100f); verifyIndicationMessage(
String pluggedIndication = mContext.getString( INDICATION_TYPE_BATTERY,
R.string.keyguard_plugged_in_charging_limited, percentage); mContext.getString(
assertThat(mTextView.getText()).isEqualTo(pluggedIndication); R.string.keyguard_plugged_in_charging_limited,
NumberFormat.getPercentInstance().format(80 / 100f)));
} }
@Test @Test
@@ -603,10 +595,11 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mController.getKeyguardCallback().onRefreshBatteryInfo(status); mController.getKeyguardCallback().onRefreshBatteryInfo(status);
mController.setVisible(true); mController.setVisible(true);
String percentage = NumberFormat.getPercentInstance().format(80 / 100f); verifyIndicationMessage(
String pluggedIndication = mContext.getString( INDICATION_TYPE_BATTERY,
R.string.keyguard_plugged_in_charging_limited, percentage); mContext.getString(
assertThat(mTextView.getText()).isEqualTo(pluggedIndication); R.string.keyguard_plugged_in_charging_limited,
NumberFormat.getPercentInstance().format(80 / 100f)));
} }
@Test @Test
@@ -620,12 +613,13 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mController.getKeyguardCallback().onRefreshBatteryInfo(status); mController.getKeyguardCallback().onRefreshBatteryInfo(status);
mController.setVisible(true); mController.setVisible(true);
String chargedIndication = mContext.getString(R.string.keyguard_charged); verifyIndicationMessage(
assertThat(mTextView.getText()).isEqualTo(chargedIndication); INDICATION_TYPE_BATTERY,
mContext.getString(R.string.keyguard_charged));
} }
@Test @Test
public void onRefreshBatteryInfo_dischargingWithOverheat_presentBatteryPercentage() { public void onRefreshBatteryInfo_dozing_dischargingWithOverheat_presentBatteryPercentage() {
createController(); createController();
BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_DISCHARGING, BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_DISCHARGING,
90 /* level */, 0 /* plugged */, BatteryManager.BATTERY_HEALTH_OVERHEAT, 90 /* level */, 0 /* plugged */, BatteryManager.BATTERY_HEALTH_OVERHEAT,
@@ -646,10 +640,32 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mController.getKeyguardCallback().onRequireUnlockForNfc(); mController.getKeyguardCallback().onRequireUnlockForNfc();
mController.setVisible(true); mController.setVisible(true);
assertThat(mTextView.getText()).isEqualTo(message); verifyTransientMessage(message);
} }
private void sendUpdateDisclosureBroadcast() { private void sendUpdateDisclosureBroadcast() {
mBroadcastReceiver.onReceive(mContext, new Intent()); mBroadcastReceiver.onReceive(mContext, new Intent());
} }
private void verifyIndicationMessage(int type, String message) {
verify(mRotateTextViewController).updateIndication(eq(type),
mKeyguardIndicationCaptor.capture(), anyBoolean());
assertThat(mKeyguardIndicationCaptor.getValue().getMessage())
.isEqualTo(message);
}
private void verifyHideIndication(int type) {
if (type == INDICATION_TYPE_TRANSIENT) {
verify(mRotateTextViewController).hideTransient();
verify(mRotateTextViewController, never()).showTransient(anyString(), anyBoolean());
} else {
verify(mRotateTextViewController).hideIndication(type);
verify(mRotateTextViewController, never()).updateIndication(eq(type),
anyObject(), anyBoolean());
}
}
private void verifyTransientMessage(String message) {
verify(mRotateTextViewController).showTransient(eq(message), anyBoolean());
}
} }