DO NOT MERGE Don't re-animate duplicate biometric msgs am: 170fa31f93

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17013660

Change-Id: Ie2daf3219b568486fcc3653d4d19b918ab4946b7
This commit is contained in:
Beverly
2022-03-02 13:37:44 +00:00
committed by Automerger Merge Worker
2 changed files with 145 additions and 109 deletions

View File

@@ -50,6 +50,7 @@ import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle; import android.os.UserHandle;
@@ -122,7 +123,7 @@ public class KeyguardIndicationController {
private final Context mContext; private final Context mContext;
private final BroadcastDispatcher mBroadcastDispatcher; private final BroadcastDispatcher mBroadcastDispatcher;
private final KeyguardStateController mKeyguardStateController; private final KeyguardStateController mKeyguardStateController;
private final StatusBarStateController mStatusBarStateController; protected final StatusBarStateController mStatusBarStateController;
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private ViewGroup mIndicationArea; private ViewGroup mIndicationArea;
private KeyguardIndicationTextView mTopIndicationView; private KeyguardIndicationTextView mTopIndicationView;
@@ -138,6 +139,7 @@ public class KeyguardIndicationController {
private final IActivityManager mIActivityManager; private final IActivityManager mIActivityManager;
private final FalsingManager mFalsingManager; private final FalsingManager mFalsingManager;
private final KeyguardBypassController mKeyguardBypassController; private final KeyguardBypassController mKeyguardBypassController;
private final Handler mHandler;
protected KeyguardIndicationRotateTextViewController mRotateTextViewController; protected KeyguardIndicationRotateTextViewController mRotateTextViewController;
private BroadcastReceiver mBroadcastReceiver; private BroadcastReceiver mBroadcastReceiver;
@@ -194,7 +196,9 @@ public class KeyguardIndicationController {
* Creates a new KeyguardIndicationController and registers callbacks. * Creates a new KeyguardIndicationController and registers callbacks.
*/ */
@Inject @Inject
public KeyguardIndicationController(Context context, public KeyguardIndicationController(
Context context,
@Main Looper mainLooper,
WakeLock.Builder wakeLockBuilder, WakeLock.Builder wakeLockBuilder,
KeyguardStateController keyguardStateController, KeyguardStateController keyguardStateController,
StatusBarStateController statusBarStateController, StatusBarStateController statusBarStateController,
@@ -230,6 +234,19 @@ public class KeyguardIndicationController {
mKeyguardBypassController = keyguardBypassController; mKeyguardBypassController = keyguardBypassController;
mScreenLifecycle = screenLifecycle; mScreenLifecycle = screenLifecycle;
mScreenLifecycle.addObserver(mScreenObserver); mScreenLifecycle.addObserver(mScreenObserver);
mHandler = new Handler(mainLooper) {
@Override
public void handleMessage(Message msg) {
if (msg.what == MSG_HIDE_TRANSIENT) {
hideTransientIndication();
} else if (msg.what == MSG_SHOW_ACTION_TO_UNLOCK) {
showActionToUnlock();
} else if (msg.what == MSG_HIDE_BIOMETRIC_MESSAGE) {
hideBiometricMessage();
}
}
};
} }
/** Call this after construction to finish setting up the instance. */ /** Call this after construction to finish setting up the instance. */
@@ -242,7 +259,6 @@ public class KeyguardIndicationController {
mDockManager.addAlignmentStateListener( mDockManager.addAlignmentStateListener(
alignState -> mHandler.post(() -> handleAlignStateChanged(alignState))); alignState -> mHandler.post(() -> handleAlignStateChanged(alignState)));
mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback()); mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback());
mKeyguardUpdateMonitor.registerCallback(mTickReceiver);
mStatusBarStateController.addCallback(mStatusBarStateListener); mStatusBarStateController.addCallback(mStatusBarStateListener);
mKeyguardStateController.addCallback(mKeyguardStateCallback); mKeyguardStateController.addCallback(mKeyguardStateCallback);
@@ -260,7 +276,7 @@ public class KeyguardIndicationController {
mLockScreenIndicationView, mLockScreenIndicationView,
mExecutor, mExecutor,
mStatusBarStateController); mStatusBarStateController);
updateIndication(false /* animate */); updateDeviceEntryIndication(false /* animate */);
updateOrganizedOwnedDevice(); updateOrganizedOwnedDevice();
if (mBroadcastReceiver == null) { if (mBroadcastReceiver == null) {
// Update the disclosure proactively to avoid IPC on the critical path. // Update the disclosure proactively to avoid IPC on the critical path.
@@ -288,7 +304,7 @@ public class KeyguardIndicationController {
} }
if (!alignmentIndication.equals(mAlignmentIndication)) { if (!alignmentIndication.equals(mAlignmentIndication)) {
mAlignmentIndication = alignmentIndication; mAlignmentIndication = alignmentIndication;
updateIndication(false); updateDeviceEntryIndication(false);
} }
} }
@@ -309,28 +325,30 @@ public class KeyguardIndicationController {
return mUpdateMonitorCallback; return mUpdateMonitorCallback;
} }
/** private void updateLockScreenIndications(boolean animate, int userId) {
* This method also doesn't update transient messages like biometrics since those messages // update transient messages:
* are also updated separately. updateBiometricMessage();
*/ updateTransient();
private void updatePersistentIndications(boolean animate, int userId) {
updateDisclosure(); // Update persistent messages. The following methods should only be called if we're on the
updateOwnerInfo(); // lock screen:
updateBattery(animate); updateLockScreenDisclosureMsg();
updateUserLocked(userId); updateLockScreenOwnerInfo();
updateTrust(userId, getTrustGrantedIndication(), getTrustManagedIndication()); updateLockScreenBatteryMsg(animate);
updateAlignment(); updateLockScreenUserLockedMsg(userId);
updateLogoutView(); updateLockScreenTrustMsg(userId, getTrustGrantedIndication(), getTrustManagedIndication());
updateResting(); updateLockScreenAlignmentMsg();
updateLockScreenLogoutView();
updateLockScreenRestingMsg();
} }
private void updateOrganizedOwnedDevice() { private void updateOrganizedOwnedDevice() {
// avoid calling this method since it has an IPC // avoid calling this method since it has an IPC
mOrganizationOwnedDevice = whitelistIpcs(this::isOrganizationOwnedDevice); mOrganizationOwnedDevice = whitelistIpcs(this::isOrganizationOwnedDevice);
updatePersistentIndications(false, KeyguardUpdateMonitor.getCurrentUser()); updateDeviceEntryIndication(false);
} }
private void updateDisclosure() { private void updateLockScreenDisclosureMsg() {
if (mOrganizationOwnedDevice) { if (mOrganizationOwnedDevice) {
mBackgroundExecutor.execute(() -> { mBackgroundExecutor.execute(() -> {
final CharSequence organizationName = getOrganizationOwnedDeviceOrganizationName(); final CharSequence organizationName = getOrganizationOwnedDeviceOrganizationName();
@@ -374,7 +392,7 @@ public class KeyguardIndicationController {
} }
} }
private void updateOwnerInfo() { private void updateLockScreenOwnerInfo() {
// Check device owner info on a bg thread. // Check device owner info on a bg thread.
// It makes multiple IPCs that could block the thread it's run on. // It makes multiple IPCs that could block the thread it's run on.
mBackgroundExecutor.execute(() -> { mBackgroundExecutor.execute(() -> {
@@ -406,7 +424,7 @@ public class KeyguardIndicationController {
}); });
} }
private void updateBattery(boolean animate) { private void updateLockScreenBatteryMsg(boolean animate) {
if (mPowerPluggedIn || mEnableBatteryDefender) { if (mPowerPluggedIn || mEnableBatteryDefender) {
String powerIndication = computePowerIndication(); String powerIndication = computePowerIndication();
if (DEBUG_CHARGING_SPEED) { if (DEBUG_CHARGING_SPEED) {
@@ -426,7 +444,7 @@ public class KeyguardIndicationController {
} }
} }
private void updateUserLocked(int userId) { private void updateLockScreenUserLockedMsg(int userId) {
if (!mKeyguardUpdateMonitor.isUserUnlocked(userId)) { if (!mKeyguardUpdateMonitor.isUserUnlocked(userId)) {
mRotateTextViewController.updateIndication( mRotateTextViewController.updateIndication(
INDICATION_TYPE_USER_LOCKED, INDICATION_TYPE_USER_LOCKED,
@@ -442,6 +460,11 @@ public class KeyguardIndicationController {
} }
private void updateBiometricMessage() { private void updateBiometricMessage() {
if (mDozing) {
updateDeviceEntryIndication(false);
return;
}
if (!TextUtils.isEmpty(mBiometricMessage)) { if (!TextUtils.isEmpty(mBiometricMessage)) {
mRotateTextViewController.updateIndication( mRotateTextViewController.updateIndication(
INDICATION_TYPE_BIOMETRIC_MESSAGE, INDICATION_TYPE_BIOMETRIC_MESSAGE,
@@ -455,25 +478,22 @@ public class KeyguardIndicationController {
} else { } else {
mRotateTextViewController.hideIndication(INDICATION_TYPE_BIOMETRIC_MESSAGE); mRotateTextViewController.hideIndication(INDICATION_TYPE_BIOMETRIC_MESSAGE);
} }
if (mDozing) {
updateIndication(false);
}
} }
private void updateTransient() { private void updateTransient() {
if (mDozing) {
updateDeviceEntryIndication(false);
return;
}
if (!TextUtils.isEmpty(mTransientIndication)) { if (!TextUtils.isEmpty(mTransientIndication)) {
mRotateTextViewController.showTransient(mTransientIndication); mRotateTextViewController.showTransient(mTransientIndication);
} else { } else {
mRotateTextViewController.hideTransient(); mRotateTextViewController.hideTransient();
} }
if (mDozing) {
updateIndication(false);
}
} }
private void updateTrust(int userId, CharSequence trustGrantedIndication, private void updateLockScreenTrustMsg(int userId, CharSequence trustGrantedIndication,
CharSequence trustManagedIndication) { CharSequence trustManagedIndication) {
if (!TextUtils.isEmpty(trustGrantedIndication) if (!TextUtils.isEmpty(trustGrantedIndication)
&& mKeyguardUpdateMonitor.getUserHasTrust(userId)) { && mKeyguardUpdateMonitor.getUserHasTrust(userId)) {
@@ -499,7 +519,7 @@ public class KeyguardIndicationController {
} }
} }
private void updateAlignment() { private void updateLockScreenAlignmentMsg() {
if (!TextUtils.isEmpty(mAlignmentIndication)) { if (!TextUtils.isEmpty(mAlignmentIndication)) {
mRotateTextViewController.updateIndication( mRotateTextViewController.updateIndication(
INDICATION_TYPE_ALIGNMENT, INDICATION_TYPE_ALIGNMENT,
@@ -514,7 +534,7 @@ public class KeyguardIndicationController {
} }
} }
private void updateResting() { private void updateLockScreenRestingMsg() {
if (!TextUtils.isEmpty(mRestingIndication) if (!TextUtils.isEmpty(mRestingIndication)
&& !mRotateTextViewController.hasIndications()) { && !mRotateTextViewController.hasIndications()) {
mRotateTextViewController.updateIndication( mRotateTextViewController.updateIndication(
@@ -529,7 +549,7 @@ public class KeyguardIndicationController {
} }
} }
private void updateLogoutView() { private void updateLockScreenLogoutView() {
final boolean shouldShowLogout = mKeyguardUpdateMonitor.isLogoutEnabled() final boolean shouldShowLogout = mKeyguardUpdateMonitor.isLogoutEnabled()
&& KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM; && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM;
if (shouldShowLogout) { if (shouldShowLogout) {
@@ -608,7 +628,7 @@ public class KeyguardIndicationController {
if (!mHandler.hasMessages(MSG_HIDE_TRANSIENT)) { if (!mHandler.hasMessages(MSG_HIDE_TRANSIENT)) {
hideTransientIndication(); hideTransientIndication();
} }
updateIndication(false); updateDeviceEntryIndication(false);
} else if (!visible) { } else if (!visible) {
// If we unlock and return to keyguard quickly, previous error should not be shown // If we unlock and return to keyguard quickly, previous error should not be shown
hideTransientIndication(); hideTransientIndication();
@@ -620,7 +640,7 @@ public class KeyguardIndicationController {
*/ */
public void setRestingIndication(String restingIndication) { public void setRestingIndication(String restingIndication) {
mRestingIndication = restingIndication; mRestingIndication = restingIndication;
updateIndication(false); updateDeviceEntryIndication(false);
} }
/** /**
@@ -697,6 +717,10 @@ public class KeyguardIndicationController {
* Shows {@param biometricMessage} until it is hidden by {@link #hideBiometricMessage}. * Shows {@param biometricMessage} until it is hidden by {@link #hideBiometricMessage}.
*/ */
private void showBiometricMessage(CharSequence biometricMessage) { private void showBiometricMessage(CharSequence biometricMessage) {
if (TextUtils.equals(biometricMessage, mBiometricMessage)) {
return;
}
mBiometricMessage = biometricMessage; mBiometricMessage = biometricMessage;
mHandler.removeMessages(MSG_SHOW_ACTION_TO_UNLOCK); mHandler.removeMessages(MSG_SHOW_ACTION_TO_UNLOCK);
@@ -725,7 +749,12 @@ public class KeyguardIndicationController {
} }
} }
protected final void updateIndication(boolean animate) { /**
* Updates message shown to the user. If the device is dozing, a single message with the highest
* precedence is shown. If the device is not dozing (on the lock screen), then several messages
* may continuously be cycled through.
*/
protected final void updateDeviceEntryIndication(boolean animate) {
if (!mVisible) { if (!mVisible) {
return; return;
} }
@@ -734,44 +763,37 @@ public class KeyguardIndicationController {
mIndicationArea.setVisibility(VISIBLE); mIndicationArea.setVisibility(VISIBLE);
// Walk down a precedence-ordered list of what indication // Walk down a precedence-ordered list of what indication
// should be shown based on user or device state // should be shown based on device state
// AoD
if (mDozing) { if (mDozing) {
mLockScreenIndicationView.setVisibility(View.GONE); mLockScreenIndicationView.setVisibility(View.GONE);
mTopIndicationView.setVisibility(VISIBLE); mTopIndicationView.setVisibility(VISIBLE);
// When dozing we ignore any text color and use white instead, because // When dozing we ignore any text color and use white instead, because
// colors can be hard to read in low brightness. // colors can be hard to read in low brightness.
mTopIndicationView.setTextColor(Color.WHITE); mTopIndicationView.setTextColor(Color.WHITE);
CharSequence newIndication = null;
if (!TextUtils.isEmpty(mBiometricMessage)) { if (!TextUtils.isEmpty(mBiometricMessage)) {
mWakeLock.setAcquired(true); newIndication = mBiometricMessage;
mTopIndicationView.switchIndication(mBiometricMessage, null,
true, () -> mWakeLock.setAcquired(false));
} else if (!TextUtils.isEmpty(mTransientIndication)) { } else if (!TextUtils.isEmpty(mTransientIndication)) {
mWakeLock.setAcquired(true); newIndication = mTransientIndication;
mTopIndicationView.switchIndication(mTransientIndication, null,
true, () -> mWakeLock.setAcquired(false));
} else if (!mBatteryPresent) { } else if (!mBatteryPresent) {
// If there is no battery detected, hide the indication and bail // If there is no battery detected, hide the indication and bail
mIndicationArea.setVisibility(GONE); mIndicationArea.setVisibility(GONE);
return;
} else if (!TextUtils.isEmpty(mAlignmentIndication)) { } else if (!TextUtils.isEmpty(mAlignmentIndication)) {
mTopIndicationView.switchIndication(mAlignmentIndication, null, newIndication = mAlignmentIndication;
false /* animate */, null /* onAnimationEndCallback */);
mTopIndicationView.setTextColor(mContext.getColor(R.color.misalignment_text_color)); mTopIndicationView.setTextColor(mContext.getColor(R.color.misalignment_text_color));
} else if (mPowerPluggedIn || mEnableBatteryDefender) { } else if (mPowerPluggedIn || mEnableBatteryDefender) {
String indication = computePowerIndication(); newIndication = computePowerIndication();
if (animate) {
mWakeLock.setAcquired(true);
mTopIndicationView.switchIndication(indication, null, true /* animate */,
() -> mWakeLock.setAcquired(false));
} else {
mTopIndicationView.switchIndication(indication, null, false /* animate */,
null /* onAnimationEndCallback */);
}
} else { } else {
String percentage = NumberFormat.getPercentInstance() newIndication = NumberFormat.getPercentInstance()
.format(mBatteryLevel / 100f); .format(mBatteryLevel / 100f);
mTopIndicationView.switchIndication(percentage, null /* indication */, }
false /* animate */, null /* onAnimationEnd*/);
if (!TextUtils.equals(mTopIndicationView.getText(), newIndication)) {
mWakeLock.setAcquired(true);
mTopIndicationView.switchIndication(newIndication, null,
true, () -> mWakeLock.setAcquired(false));
} }
return; return;
} }
@@ -780,7 +802,7 @@ public class KeyguardIndicationController {
mTopIndicationView.setVisibility(GONE); mTopIndicationView.setVisibility(GONE);
mTopIndicationView.setText(null); mTopIndicationView.setText(null);
mLockScreenIndicationView.setVisibility(View.VISIBLE); mLockScreenIndicationView.setVisibility(View.VISIBLE);
updatePersistentIndications(animate, KeyguardUpdateMonitor.getCurrentUser()); updateLockScreenIndications(animate, KeyguardUpdateMonitor.getCurrentUser());
} }
protected String computePowerIndication() { protected String computePowerIndication() {
@@ -842,29 +864,6 @@ public class KeyguardIndicationController {
mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
} }
private final KeyguardUpdateMonitorCallback mTickReceiver =
new KeyguardUpdateMonitorCallback() {
@Override
public void onTimeChanged() {
if (mVisible) {
updateIndication(false /* animate */);
}
}
};
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == MSG_HIDE_TRANSIENT) {
hideTransientIndication();
} else if (msg.what == MSG_SHOW_ACTION_TO_UNLOCK) {
showActionToUnlock();
} else if (msg.what == MSG_HIDE_BIOMETRIC_MESSAGE) {
hideBiometricMessage();
}
}
};
/** /**
* Show message on the keyguard for how the user can unlock/enter their device. * Show message on the keyguard for how the user can unlock/enter their device.
*/ */
@@ -929,7 +928,7 @@ public class KeyguardIndicationController {
pw.println(" mBiometricMessage: " + mBiometricMessage); pw.println(" mBiometricMessage: " + mBiometricMessage);
pw.println(" mBatteryLevel: " + mBatteryLevel); pw.println(" mBatteryLevel: " + mBatteryLevel);
pw.println(" mBatteryPresent: " + mBatteryPresent); pw.println(" mBatteryPresent: " + mBatteryPresent);
pw.println(" mTextView.getText(): " + ( pw.println(" AOD text: " + (
mTopIndicationView == null ? null : mTopIndicationView.getText())); mTopIndicationView == null ? null : mTopIndicationView.getText()));
pw.println(" computePowerIndication(): " + computePowerIndication()); pw.println(" computePowerIndication(): " + computePowerIndication());
pw.println(" trustGrantedIndication: " + getTrustGrantedIndication()); pw.println(" trustGrantedIndication: " + getTrustGrantedIndication());
@@ -939,6 +938,13 @@ public class KeyguardIndicationController {
protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback { protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback {
public static final int HIDE_DELAY_MS = 5000; public static final int HIDE_DELAY_MS = 5000;
@Override
public void onTimeChanged() {
if (mVisible) {
updateDeviceEntryIndication(false /* animate */);
}
}
@Override @Override
public void onRefreshBatteryInfo(BatteryStatus status) { public void onRefreshBatteryInfo(BatteryStatus status) {
boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING
@@ -962,7 +968,7 @@ public class KeyguardIndicationController {
Log.e(TAG, "Error calling IBatteryStats: ", e); Log.e(TAG, "Error calling IBatteryStats: ", e);
mChargingTimeRemaining = -1; mChargingTimeRemaining = -1;
} }
updateIndication(!wasPluggedIn && mPowerPluggedInWired); updateDeviceEntryIndication(!wasPluggedIn && mPowerPluggedInWired);
if (mDozing) { if (mDozing) {
if (!wasPluggedIn && mPowerPluggedIn) { if (!wasPluggedIn && mPowerPluggedIn) {
showTransientIndication(computePowerIndication()); showTransientIndication(computePowerIndication());
@@ -1084,14 +1090,13 @@ public class KeyguardIndicationController {
if (KeyguardUpdateMonitor.getCurrentUser() != userId) { if (KeyguardUpdateMonitor.getCurrentUser() != userId) {
return; return;
} }
updateTrust(userId, getTrustGrantedIndication(), getTrustManagedIndication()); updateDeviceEntryIndication(false);
} }
@Override @Override
public void showTrustGrantedMessage(CharSequence message) { public void showTrustGrantedMessage(CharSequence message) {
mTrustGrantedIndication = message; mTrustGrantedIndication = message;
updateTrust(KeyguardUpdateMonitor.getCurrentUser(), getTrustGrantedIndication(), updateDeviceEntryIndication(false);
getTrustManagedIndication());
} }
@Override @Override
@@ -1125,21 +1130,21 @@ public class KeyguardIndicationController {
@Override @Override
public void onUserSwitchComplete(int userId) { public void onUserSwitchComplete(int userId) {
if (mVisible) { if (mVisible) {
updateIndication(false); updateDeviceEntryIndication(false);
} }
} }
@Override @Override
public void onUserUnlocked() { public void onUserUnlocked() {
if (mVisible) { if (mVisible) {
updateIndication(false); updateDeviceEntryIndication(false);
} }
} }
@Override @Override
public void onLogoutEnabledChanged() { public void onLogoutEnabledChanged() {
if (mVisible) { if (mVisible) {
updateIndication(false); updateDeviceEntryIndication(false);
} }
} }
@@ -1167,7 +1172,7 @@ public class KeyguardIndicationController {
if (mDozing) { if (mDozing) {
hideBiometricMessage(); hideBiometricMessage();
} }
updateIndication(false); updateDeviceEntryIndication(false);
} }
}; };
@@ -1175,7 +1180,7 @@ public class KeyguardIndicationController {
new KeyguardStateController.Callback() { new KeyguardStateController.Callback() {
@Override @Override
public void onUnlockedChanged() { public void onUnlockedChanged() {
updateIndication(false); updateDeviceEntryIndication(false);
} }
@Override @Override
@@ -1185,7 +1190,7 @@ public class KeyguardIndicationController {
mTopIndicationView.clearMessages(); mTopIndicationView.clearMessages();
mRotateTextViewController.clearMessages(); mRotateTextViewController.clearMessages();
} else { } else {
updatePersistentIndications(false, KeyguardUpdateMonitor.getCurrentUser()); updateDeviceEntryIndication(false);
} }
} }
}; };

View File

@@ -45,7 +45,6 @@ import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset; import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -66,15 +65,17 @@ import android.os.BatteryManager;
import android.os.Looper; import android.os.Looper;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserManager; import android.os.UserManager;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.test.InstrumentationRegistry; import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.app.IBatteryStats; import com.android.internal.app.IBatteryStats;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.settingslib.fuelgauge.BatteryStatus; import com.android.settingslib.fuelgauge.BatteryStatus;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
@@ -106,7 +107,8 @@ import java.text.NumberFormat;
import java.util.Collections; import java.util.Collections;
@SmallTest @SmallTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class KeyguardIndicationControllerTest extends SysuiTestCase { public class KeyguardIndicationControllerTest extends SysuiTestCase {
private static final String ORGANIZATION_NAME = "organization"; private static final String ORGANIZATION_NAME = "organization";
@@ -164,11 +166,15 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Captor @Captor
private ArgumentCaptor<KeyguardIndication> mKeyguardIndicationCaptor; private ArgumentCaptor<KeyguardIndication> mKeyguardIndicationCaptor;
@Captor @Captor
private ArgumentCaptor<KeyguardUpdateMonitorCallback> mKeyguardUpdateMonitorCallbackCaptor;
@Captor
private ArgumentCaptor<KeyguardStateController.Callback> mKeyguardStateControllerCallbackCaptor; private ArgumentCaptor<KeyguardStateController.Callback> mKeyguardStateControllerCallbackCaptor;
private KeyguardStateController.Callback mKeyguardStateControllerCallback; private KeyguardStateController.Callback mKeyguardStateControllerCallback;
private KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback;
private StatusBarStateController.StateListener mStatusBarStateListener; private StatusBarStateController.StateListener mStatusBarStateListener;
private BroadcastReceiver mBroadcastReceiver; private BroadcastReceiver mBroadcastReceiver;
private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock()); private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
private TestableLooper mTestableLooper;
private KeyguardIndicationTextView mTextView; // AOD text private KeyguardIndicationTextView mTextView; // AOD text
@@ -181,6 +187,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mInstrumentation = InstrumentationRegistry.getInstrumentation(); mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTestableLooper = TestableLooper.get(this);
mTextView = new KeyguardIndicationTextView(mContext); mTextView = new KeyguardIndicationTextView(mContext);
mTextView.setAnimationsEnabled(false); mTextView.setAnimationsEnabled(false);
@@ -226,7 +233,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
Looper.prepare(); Looper.prepare();
} }
mController = new KeyguardIndicationController(mContext, mWakeLockBuilder, mController = new KeyguardIndicationController(
mContext,
mTestableLooper.getLooper(),
mWakeLockBuilder,
mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor, mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor,
mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats, mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats,
mUserManager, mExecutor, mExecutor, mFalsingManager, mLockPatternUtils, mUserManager, mExecutor, mExecutor, mFalsingManager, mLockPatternUtils,
@@ -245,6 +255,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mKeyguardStateControllerCallbackCaptor.capture()); mKeyguardStateControllerCallbackCaptor.capture());
mKeyguardStateControllerCallback = mKeyguardStateControllerCallbackCaptor.getValue(); mKeyguardStateControllerCallback = mKeyguardStateControllerCallbackCaptor.getValue();
verify(mKeyguardUpdateMonitor).registerCallback(
mKeyguardUpdateMonitorCallbackCaptor.capture());
mKeyguardUpdateMonitorCallback = mKeyguardUpdateMonitorCallbackCaptor.getValue();
mExecutor.runAllReady(); mExecutor.runAllReady();
reset(mRotateTextViewController); reset(mRotateTextViewController);
} }
@@ -267,7 +281,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR); mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
}); });
mInstrumentation.waitForIdleSync(); mInstrumentation.waitForIdleSync();
mTestableLooper.processAllMessages();
verifyIndicationMessage(INDICATION_TYPE_ALIGNMENT, verifyIndicationMessage(INDICATION_TYPE_ALIGNMENT,
mContext.getResources().getString(R.string.dock_alignment_slow_charging)); mContext.getResources().getString(R.string.dock_alignment_slow_charging));
@@ -285,6 +299,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE); mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
}); });
mInstrumentation.waitForIdleSync(); mInstrumentation.waitForIdleSync();
mTestableLooper.processAllMessages();
verifyIndicationMessage(INDICATION_TYPE_ALIGNMENT, verifyIndicationMessage(INDICATION_TYPE_ALIGNMENT,
mContext.getResources().getString(R.string.dock_alignment_not_charging)); mContext.getResources().getString(R.string.dock_alignment_not_charging));
@@ -303,6 +318,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR); mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
}); });
mInstrumentation.waitForIdleSync(); mInstrumentation.waitForIdleSync();
mTestableLooper.processAllMessages();
assertThat(mTextView.getText()).isEqualTo( assertThat(mTextView.getText()).isEqualTo(
mContext.getResources().getString(R.string.dock_alignment_slow_charging)); mContext.getResources().getString(R.string.dock_alignment_slow_charging));
@@ -321,6 +337,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE); mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
}); });
mInstrumentation.waitForIdleSync(); mInstrumentation.waitForIdleSync();
mTestableLooper.processAllMessages();
assertThat(mTextView.getText()).isEqualTo( assertThat(mTextView.getText()).isEqualTo(
mContext.getResources().getString(R.string.dock_alignment_not_charging)); mContext.getResources().getString(R.string.dock_alignment_not_charging));
@@ -331,9 +348,12 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void disclosure_unmanaged() { public void disclosure_unmanaged() {
createController(); createController();
mController.setVisible(true);
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false); when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false); when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false);
reset(mRotateTextViewController);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
mExecutor.runAllReady(); mExecutor.runAllReady();
@@ -347,6 +367,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null); when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
mController.setVisible(true);
mExecutor.runAllReady(); mExecutor.runAllReady();
verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureGeneric); verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureGeneric);
@@ -355,6 +376,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void disclosure_orgOwnedDeviceWithManagedProfile_noOrganizationName() { public void disclosure_orgOwnedDeviceWithManagedProfile_noOrganizationName() {
createController(); createController();
mController.setVisible(true);
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true); when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true);
when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList( when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList(
@@ -369,6 +391,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void disclosure_deviceOwner_withOrganizationName() { public void disclosure_deviceOwner_withOrganizationName() {
createController(); createController();
mController.setVisible(true);
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME); when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
@@ -381,6 +404,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void disclosure_orgOwnedDeviceWithManagedProfile_withOrganizationName() { public void disclosure_orgOwnedDeviceWithManagedProfile_withOrganizationName() {
createController(); createController();
mController.setVisible(true);
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true); when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true);
when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList( when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList(
@@ -397,6 +421,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false); when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
createController(); createController();
mController.setVisible(true);
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null); when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
@@ -424,7 +449,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void disclosure_deviceOwner_financedDeviceWithOrganizationName() { public void disclosure_deviceOwner_financedDeviceWithOrganizationName() {
createController(); createController();
mController.setVisible(true);
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME); when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
@@ -432,6 +457,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
.thenReturn(DEVICE_OWNER_TYPE_FINANCED); .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
sendUpdateDisclosureBroadcast(); sendUpdateDisclosureBroadcast();
mExecutor.runAllReady(); mExecutor.runAllReady();
mController.setVisible(true);
verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mFinancedDisclosureWithOrganization); verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mFinancedDisclosureWithOrganization);
} }
@@ -469,10 +495,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void transientIndication_visibleWhenDozing() { public void transientIndication_visibleWhenDozing() {
createController(); createController();
mController.setVisible(true); mController.setVisible(true);
mController.showTransientIndication(TEST_STRING_RES);
mStatusBarStateListener.onDozingChanged(true); mStatusBarStateListener.onDozingChanged(true);
mController.showTransientIndication(TEST_STRING_RES);
assertThat(mTextView.getText()).isEqualTo( assertThat(mTextView.getText()).isEqualTo(
mContext.getResources().getString(TEST_STRING_RES)); mContext.getResources().getString(TEST_STRING_RES));
@@ -493,7 +519,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
reset(mRotateTextViewController); reset(mRotateTextViewController);
mStatusBarStateListener.onDozingChanged(true); mStatusBarStateListener.onDozingChanged(true);
verifyHideIndication(INDICATION_TYPE_BIOMETRIC_MESSAGE); assertThat(mTextView.getText()).isNotEqualTo(message);
} }
@Test @Test
@@ -604,10 +630,9 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
} }
@Test @Test
public void updateMonitor_listener() { public void registersKeyguardStateCallback() {
createController(); createController();
verify(mKeyguardStateController).addCallback(any()); verify(mKeyguardStateController).addCallback(any());
verify(mKeyguardUpdateMonitor, times(2)).registerCallback(any());
} }
@Test @Test
@@ -695,13 +720,13 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void onRefreshBatteryInfo_dozing_dischargingWithOverheat_presentBatteryPercentage() { public void onRefreshBatteryInfo_dozing_dischargingWithOverheat_presentBatteryPercentage() {
createController(); createController();
mController.setVisible(true);
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,
0 /* maxChargingWattage */, true /* present */); 0 /* maxChargingWattage */, true /* present */);
mController.getKeyguardCallback().onRefreshBatteryInfo(status); mController.getKeyguardCallback().onRefreshBatteryInfo(status);
mStatusBarStateListener.onDozingChanged(true); mStatusBarStateListener.onDozingChanged(true);
mController.setVisible(true);
String percentage = NumberFormat.getPercentInstance().format(90 / 100f); String percentage = NumberFormat.getPercentInstance().format(90 / 100f);
assertThat(mTextView.getText()).isEqualTo(percentage); assertThat(mTextView.getText()).isEqualTo(percentage);
@@ -710,9 +735,9 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void onRequireUnlockForNfc_showsRequireUnlockForNfcIndication() { public void onRequireUnlockForNfc_showsRequireUnlockForNfcIndication() {
createController(); createController();
mController.setVisible(true);
String message = mContext.getString(R.string.require_unlock_for_nfc); String message = mContext.getString(R.string.require_unlock_for_nfc);
mController.getKeyguardCallback().onRequireUnlockForNfc(); mController.getKeyguardCallback().onRequireUnlockForNfc();
mController.setVisible(true);
verifyTransientMessage(message); verifyTransientMessage(message);
} }
@@ -778,6 +803,9 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void testOnKeyguardShowingChanged_showing_updatesPersistentMessages() { public void testOnKeyguardShowingChanged_showing_updatesPersistentMessages() {
createController(); createController();
mController.setVisible(true);
mExecutor.runAllReady();
reset(mRotateTextViewController);
// GIVEN keyguard is showing // GIVEN keyguard is showing
when(mKeyguardStateController.isShowing()).thenReturn(true); when(mKeyguardStateController.isShowing()).thenReturn(true);
@@ -799,6 +827,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void onTrustGrantedMessageDoesNotShowUntilTrustGranted() { public void onTrustGrantedMessageDoesNotShowUntilTrustGranted() {
createController(); createController();
mController.setVisible(true);
reset(mRotateTextViewController);
// GIVEN a trust granted message but trust isn't granted // GIVEN a trust granted message but trust isn't granted
final String trustGrantedMsg = "testing trust granted message"; final String trustGrantedMsg = "testing trust granted message";
@@ -808,7 +838,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
// WHEN trust is granted // WHEN trust is granted
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
mController.setVisible(true); mKeyguardUpdateMonitorCallback.onTrustChanged(KeyguardUpdateMonitor.getCurrentUser());
// THEN verify the trust granted message shows // THEN verify the trust granted message shows
verifyIndicationMessage( verifyIndicationMessage(
@@ -819,6 +849,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void onTrustGrantedMessageDoesShowsOnTrustGranted() { public void onTrustGrantedMessageDoesShowsOnTrustGranted() {
createController(); createController();
mController.setVisible(true);
// GIVEN trust is granted // GIVEN trust is granted
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);