Merge "DO NOT MERGE Don't re-animate duplicate biometric msgs" into tm-dev
This commit is contained in:
@@ -50,6 +50,7 @@ import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
@@ -122,7 +123,7 @@ public class KeyguardIndicationController {
|
||||
private final Context mContext;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final KeyguardStateController mKeyguardStateController;
|
||||
private final StatusBarStateController mStatusBarStateController;
|
||||
protected final StatusBarStateController mStatusBarStateController;
|
||||
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
private ViewGroup mIndicationArea;
|
||||
private KeyguardIndicationTextView mTopIndicationView;
|
||||
@@ -138,6 +139,7 @@ public class KeyguardIndicationController {
|
||||
private final IActivityManager mIActivityManager;
|
||||
private final FalsingManager mFalsingManager;
|
||||
private final KeyguardBypassController mKeyguardBypassController;
|
||||
private final Handler mHandler;
|
||||
|
||||
protected KeyguardIndicationRotateTextViewController mRotateTextViewController;
|
||||
private BroadcastReceiver mBroadcastReceiver;
|
||||
@@ -194,7 +196,9 @@ public class KeyguardIndicationController {
|
||||
* Creates a new KeyguardIndicationController and registers callbacks.
|
||||
*/
|
||||
@Inject
|
||||
public KeyguardIndicationController(Context context,
|
||||
public KeyguardIndicationController(
|
||||
Context context,
|
||||
@Main Looper mainLooper,
|
||||
WakeLock.Builder wakeLockBuilder,
|
||||
KeyguardStateController keyguardStateController,
|
||||
StatusBarStateController statusBarStateController,
|
||||
@@ -230,6 +234,19 @@ public class KeyguardIndicationController {
|
||||
mKeyguardBypassController = keyguardBypassController;
|
||||
mScreenLifecycle = screenLifecycle;
|
||||
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. */
|
||||
@@ -242,7 +259,6 @@ public class KeyguardIndicationController {
|
||||
mDockManager.addAlignmentStateListener(
|
||||
alignState -> mHandler.post(() -> handleAlignStateChanged(alignState)));
|
||||
mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback());
|
||||
mKeyguardUpdateMonitor.registerCallback(mTickReceiver);
|
||||
mStatusBarStateController.addCallback(mStatusBarStateListener);
|
||||
mKeyguardStateController.addCallback(mKeyguardStateCallback);
|
||||
|
||||
@@ -260,7 +276,7 @@ public class KeyguardIndicationController {
|
||||
mLockScreenIndicationView,
|
||||
mExecutor,
|
||||
mStatusBarStateController);
|
||||
updateIndication(false /* animate */);
|
||||
updateDeviceEntryIndication(false /* animate */);
|
||||
updateOrganizedOwnedDevice();
|
||||
if (mBroadcastReceiver == null) {
|
||||
// Update the disclosure proactively to avoid IPC on the critical path.
|
||||
@@ -288,7 +304,7 @@ public class KeyguardIndicationController {
|
||||
}
|
||||
if (!alignmentIndication.equals(mAlignmentIndication)) {
|
||||
mAlignmentIndication = alignmentIndication;
|
||||
updateIndication(false);
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,28 +325,30 @@ public class KeyguardIndicationController {
|
||||
return mUpdateMonitorCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
updateTrust(userId, getTrustGrantedIndication(), getTrustManagedIndication());
|
||||
updateAlignment();
|
||||
updateLogoutView();
|
||||
updateResting();
|
||||
private void updateLockScreenIndications(boolean animate, int userId) {
|
||||
// update transient messages:
|
||||
updateBiometricMessage();
|
||||
updateTransient();
|
||||
|
||||
// Update persistent messages. The following methods should only be called if we're on the
|
||||
// lock screen:
|
||||
updateLockScreenDisclosureMsg();
|
||||
updateLockScreenOwnerInfo();
|
||||
updateLockScreenBatteryMsg(animate);
|
||||
updateLockScreenUserLockedMsg(userId);
|
||||
updateLockScreenTrustMsg(userId, getTrustGrantedIndication(), getTrustManagedIndication());
|
||||
updateLockScreenAlignmentMsg();
|
||||
updateLockScreenLogoutView();
|
||||
updateLockScreenRestingMsg();
|
||||
}
|
||||
|
||||
private void updateOrganizedOwnedDevice() {
|
||||
// avoid calling this method since it has an IPC
|
||||
mOrganizationOwnedDevice = whitelistIpcs(this::isOrganizationOwnedDevice);
|
||||
updatePersistentIndications(false, KeyguardUpdateMonitor.getCurrentUser());
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
|
||||
private void updateDisclosure() {
|
||||
private void updateLockScreenDisclosureMsg() {
|
||||
if (mOrganizationOwnedDevice) {
|
||||
mBackgroundExecutor.execute(() -> {
|
||||
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.
|
||||
// It makes multiple IPCs that could block the thread it's run on.
|
||||
mBackgroundExecutor.execute(() -> {
|
||||
@@ -406,7 +424,7 @@ public class KeyguardIndicationController {
|
||||
});
|
||||
}
|
||||
|
||||
private void updateBattery(boolean animate) {
|
||||
private void updateLockScreenBatteryMsg(boolean animate) {
|
||||
if (mPowerPluggedIn || mEnableBatteryDefender) {
|
||||
String powerIndication = computePowerIndication();
|
||||
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)) {
|
||||
mRotateTextViewController.updateIndication(
|
||||
INDICATION_TYPE_USER_LOCKED,
|
||||
@@ -442,6 +460,11 @@ public class KeyguardIndicationController {
|
||||
}
|
||||
|
||||
private void updateBiometricMessage() {
|
||||
if (mDozing) {
|
||||
updateDeviceEntryIndication(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(mBiometricMessage)) {
|
||||
mRotateTextViewController.updateIndication(
|
||||
INDICATION_TYPE_BIOMETRIC_MESSAGE,
|
||||
@@ -455,25 +478,22 @@ public class KeyguardIndicationController {
|
||||
} else {
|
||||
mRotateTextViewController.hideIndication(INDICATION_TYPE_BIOMETRIC_MESSAGE);
|
||||
}
|
||||
|
||||
if (mDozing) {
|
||||
updateIndication(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTransient() {
|
||||
if (mDozing) {
|
||||
updateDeviceEntryIndication(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(mTransientIndication)) {
|
||||
mRotateTextViewController.showTransient(mTransientIndication);
|
||||
} else {
|
||||
mRotateTextViewController.hideTransient();
|
||||
}
|
||||
|
||||
if (mDozing) {
|
||||
updateIndication(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTrust(int userId, CharSequence trustGrantedIndication,
|
||||
private void updateLockScreenTrustMsg(int userId, CharSequence trustGrantedIndication,
|
||||
CharSequence trustManagedIndication) {
|
||||
if (!TextUtils.isEmpty(trustGrantedIndication)
|
||||
&& mKeyguardUpdateMonitor.getUserHasTrust(userId)) {
|
||||
@@ -499,7 +519,7 @@ public class KeyguardIndicationController {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAlignment() {
|
||||
private void updateLockScreenAlignmentMsg() {
|
||||
if (!TextUtils.isEmpty(mAlignmentIndication)) {
|
||||
mRotateTextViewController.updateIndication(
|
||||
INDICATION_TYPE_ALIGNMENT,
|
||||
@@ -514,7 +534,7 @@ public class KeyguardIndicationController {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateResting() {
|
||||
private void updateLockScreenRestingMsg() {
|
||||
if (!TextUtils.isEmpty(mRestingIndication)
|
||||
&& !mRotateTextViewController.hasIndications()) {
|
||||
mRotateTextViewController.updateIndication(
|
||||
@@ -529,7 +549,7 @@ public class KeyguardIndicationController {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLogoutView() {
|
||||
private void updateLockScreenLogoutView() {
|
||||
final boolean shouldShowLogout = mKeyguardUpdateMonitor.isLogoutEnabled()
|
||||
&& KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM;
|
||||
if (shouldShowLogout) {
|
||||
@@ -608,7 +628,7 @@ public class KeyguardIndicationController {
|
||||
if (!mHandler.hasMessages(MSG_HIDE_TRANSIENT)) {
|
||||
hideTransientIndication();
|
||||
}
|
||||
updateIndication(false);
|
||||
updateDeviceEntryIndication(false);
|
||||
} else if (!visible) {
|
||||
// If we unlock and return to keyguard quickly, previous error should not be shown
|
||||
hideTransientIndication();
|
||||
@@ -620,7 +640,7 @@ public class KeyguardIndicationController {
|
||||
*/
|
||||
public void setRestingIndication(String restingIndication) {
|
||||
mRestingIndication = restingIndication;
|
||||
updateIndication(false);
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -697,6 +717,10 @@ public class KeyguardIndicationController {
|
||||
* Shows {@param biometricMessage} until it is hidden by {@link #hideBiometricMessage}.
|
||||
*/
|
||||
private void showBiometricMessage(CharSequence biometricMessage) {
|
||||
if (TextUtils.equals(biometricMessage, mBiometricMessage)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mBiometricMessage = biometricMessage;
|
||||
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@@ -734,44 +763,37 @@ public class KeyguardIndicationController {
|
||||
mIndicationArea.setVisibility(VISIBLE);
|
||||
|
||||
// Walk down a precedence-ordered list of what indication
|
||||
// should be shown based on user or device state
|
||||
// AoD
|
||||
// should be shown based on device state
|
||||
if (mDozing) {
|
||||
mLockScreenIndicationView.setVisibility(View.GONE);
|
||||
mTopIndicationView.setVisibility(VISIBLE);
|
||||
// When dozing we ignore any text color and use white instead, because
|
||||
// colors can be hard to read in low brightness.
|
||||
mTopIndicationView.setTextColor(Color.WHITE);
|
||||
|
||||
CharSequence newIndication = null;
|
||||
if (!TextUtils.isEmpty(mBiometricMessage)) {
|
||||
mWakeLock.setAcquired(true);
|
||||
mTopIndicationView.switchIndication(mBiometricMessage, null,
|
||||
true, () -> mWakeLock.setAcquired(false));
|
||||
newIndication = mBiometricMessage;
|
||||
} else if (!TextUtils.isEmpty(mTransientIndication)) {
|
||||
mWakeLock.setAcquired(true);
|
||||
mTopIndicationView.switchIndication(mTransientIndication, null,
|
||||
true, () -> mWakeLock.setAcquired(false));
|
||||
newIndication = mTransientIndication;
|
||||
} else if (!mBatteryPresent) {
|
||||
// If there is no battery detected, hide the indication and bail
|
||||
mIndicationArea.setVisibility(GONE);
|
||||
return;
|
||||
} else if (!TextUtils.isEmpty(mAlignmentIndication)) {
|
||||
mTopIndicationView.switchIndication(mAlignmentIndication, null,
|
||||
false /* animate */, null /* onAnimationEndCallback */);
|
||||
newIndication = mAlignmentIndication;
|
||||
mTopIndicationView.setTextColor(mContext.getColor(R.color.misalignment_text_color));
|
||||
} else if (mPowerPluggedIn || mEnableBatteryDefender) {
|
||||
String indication = computePowerIndication();
|
||||
if (animate) {
|
||||
mWakeLock.setAcquired(true);
|
||||
mTopIndicationView.switchIndication(indication, null, true /* animate */,
|
||||
() -> mWakeLock.setAcquired(false));
|
||||
} else {
|
||||
mTopIndicationView.switchIndication(indication, null, false /* animate */,
|
||||
null /* onAnimationEndCallback */);
|
||||
}
|
||||
newIndication = computePowerIndication();
|
||||
} else {
|
||||
String percentage = NumberFormat.getPercentInstance()
|
||||
newIndication = NumberFormat.getPercentInstance()
|
||||
.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;
|
||||
}
|
||||
@@ -780,7 +802,7 @@ public class KeyguardIndicationController {
|
||||
mTopIndicationView.setVisibility(GONE);
|
||||
mTopIndicationView.setText(null);
|
||||
mLockScreenIndicationView.setVisibility(View.VISIBLE);
|
||||
updatePersistentIndications(animate, KeyguardUpdateMonitor.getCurrentUser());
|
||||
updateLockScreenIndications(animate, KeyguardUpdateMonitor.getCurrentUser());
|
||||
}
|
||||
|
||||
protected String computePowerIndication() {
|
||||
@@ -842,29 +864,6 @@ public class KeyguardIndicationController {
|
||||
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.
|
||||
*/
|
||||
@@ -929,7 +928,7 @@ public class KeyguardIndicationController {
|
||||
pw.println(" mBiometricMessage: " + mBiometricMessage);
|
||||
pw.println(" mBatteryLevel: " + mBatteryLevel);
|
||||
pw.println(" mBatteryPresent: " + mBatteryPresent);
|
||||
pw.println(" mTextView.getText(): " + (
|
||||
pw.println(" AOD text: " + (
|
||||
mTopIndicationView == null ? null : mTopIndicationView.getText()));
|
||||
pw.println(" computePowerIndication(): " + computePowerIndication());
|
||||
pw.println(" trustGrantedIndication: " + getTrustGrantedIndication());
|
||||
@@ -939,6 +938,13 @@ public class KeyguardIndicationController {
|
||||
protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback {
|
||||
public static final int HIDE_DELAY_MS = 5000;
|
||||
|
||||
@Override
|
||||
public void onTimeChanged() {
|
||||
if (mVisible) {
|
||||
updateDeviceEntryIndication(false /* animate */);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefreshBatteryInfo(BatteryStatus status) {
|
||||
boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING
|
||||
@@ -962,7 +968,7 @@ public class KeyguardIndicationController {
|
||||
Log.e(TAG, "Error calling IBatteryStats: ", e);
|
||||
mChargingTimeRemaining = -1;
|
||||
}
|
||||
updateIndication(!wasPluggedIn && mPowerPluggedInWired);
|
||||
updateDeviceEntryIndication(!wasPluggedIn && mPowerPluggedInWired);
|
||||
if (mDozing) {
|
||||
if (!wasPluggedIn && mPowerPluggedIn) {
|
||||
showTransientIndication(computePowerIndication());
|
||||
@@ -1084,14 +1090,13 @@ public class KeyguardIndicationController {
|
||||
if (KeyguardUpdateMonitor.getCurrentUser() != userId) {
|
||||
return;
|
||||
}
|
||||
updateTrust(userId, getTrustGrantedIndication(), getTrustManagedIndication());
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showTrustGrantedMessage(CharSequence message) {
|
||||
mTrustGrantedIndication = message;
|
||||
updateTrust(KeyguardUpdateMonitor.getCurrentUser(), getTrustGrantedIndication(),
|
||||
getTrustManagedIndication());
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1125,21 +1130,21 @@ public class KeyguardIndicationController {
|
||||
@Override
|
||||
public void onUserSwitchComplete(int userId) {
|
||||
if (mVisible) {
|
||||
updateIndication(false);
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserUnlocked() {
|
||||
if (mVisible) {
|
||||
updateIndication(false);
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogoutEnabledChanged() {
|
||||
if (mVisible) {
|
||||
updateIndication(false);
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1167,7 +1172,7 @@ public class KeyguardIndicationController {
|
||||
if (mDozing) {
|
||||
hideBiometricMessage();
|
||||
}
|
||||
updateIndication(false);
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1175,7 +1180,7 @@ public class KeyguardIndicationController {
|
||||
new KeyguardStateController.Callback() {
|
||||
@Override
|
||||
public void onUnlockedChanged() {
|
||||
updateIndication(false);
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1185,7 +1190,7 @@ public class KeyguardIndicationController {
|
||||
mTopIndicationView.clearMessages();
|
||||
mRotateTextViewController.clearMessages();
|
||||
} else {
|
||||
updatePersistentIndications(false, KeyguardUpdateMonitor.getCurrentUser());
|
||||
updateDeviceEntryIndication(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,7 +45,6 @@ import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -66,15 +65,17 @@ import android.os.BatteryManager;
|
||||
import android.os.Looper;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserManager;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.app.IBatteryStats;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback;
|
||||
import com.android.settingslib.fuelgauge.BatteryStatus;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
@@ -106,7 +107,8 @@ import java.text.NumberFormat;
|
||||
import java.util.Collections;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper
|
||||
public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
|
||||
private static final String ORGANIZATION_NAME = "organization";
|
||||
@@ -164,11 +166,15 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Captor
|
||||
private ArgumentCaptor<KeyguardIndication> mKeyguardIndicationCaptor;
|
||||
@Captor
|
||||
private ArgumentCaptor<KeyguardUpdateMonitorCallback> mKeyguardUpdateMonitorCallbackCaptor;
|
||||
@Captor
|
||||
private ArgumentCaptor<KeyguardStateController.Callback> mKeyguardStateControllerCallbackCaptor;
|
||||
private KeyguardStateController.Callback mKeyguardStateControllerCallback;
|
||||
private KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback;
|
||||
private StatusBarStateController.StateListener mStatusBarStateListener;
|
||||
private BroadcastReceiver mBroadcastReceiver;
|
||||
private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
|
||||
private TestableLooper mTestableLooper;
|
||||
|
||||
private KeyguardIndicationTextView mTextView; // AOD text
|
||||
|
||||
@@ -181,6 +187,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mTestableLooper = TestableLooper.get(this);
|
||||
mTextView = new KeyguardIndicationTextView(mContext);
|
||||
mTextView.setAnimationsEnabled(false);
|
||||
|
||||
@@ -226,7 +233,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
mController = new KeyguardIndicationController(mContext, mWakeLockBuilder,
|
||||
mController = new KeyguardIndicationController(
|
||||
mContext,
|
||||
mTestableLooper.getLooper(),
|
||||
mWakeLockBuilder,
|
||||
mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor,
|
||||
mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats,
|
||||
mUserManager, mExecutor, mExecutor, mFalsingManager, mLockPatternUtils,
|
||||
@@ -245,6 +255,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
mKeyguardStateControllerCallbackCaptor.capture());
|
||||
mKeyguardStateControllerCallback = mKeyguardStateControllerCallbackCaptor.getValue();
|
||||
|
||||
verify(mKeyguardUpdateMonitor).registerCallback(
|
||||
mKeyguardUpdateMonitorCallbackCaptor.capture());
|
||||
mKeyguardUpdateMonitorCallback = mKeyguardUpdateMonitorCallbackCaptor.getValue();
|
||||
|
||||
mExecutor.runAllReady();
|
||||
reset(mRotateTextViewController);
|
||||
}
|
||||
@@ -267,7 +281,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
|
||||
});
|
||||
mInstrumentation.waitForIdleSync();
|
||||
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
verifyIndicationMessage(INDICATION_TYPE_ALIGNMENT,
|
||||
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);
|
||||
});
|
||||
mInstrumentation.waitForIdleSync();
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
verifyIndicationMessage(INDICATION_TYPE_ALIGNMENT,
|
||||
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);
|
||||
});
|
||||
mInstrumentation.waitForIdleSync();
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
assertThat(mTextView.getText()).isEqualTo(
|
||||
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);
|
||||
});
|
||||
mInstrumentation.waitForIdleSync();
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
assertThat(mTextView.getText()).isEqualTo(
|
||||
mContext.getResources().getString(R.string.dock_alignment_not_charging));
|
||||
@@ -331,9 +348,12 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void disclosure_unmanaged() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
when(mKeyguardStateController.isShowing()).thenReturn(true);
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
|
||||
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false);
|
||||
reset(mRotateTextViewController);
|
||||
|
||||
sendUpdateDisclosureBroadcast();
|
||||
mExecutor.runAllReady();
|
||||
|
||||
@@ -347,6 +367,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||
sendUpdateDisclosureBroadcast();
|
||||
mController.setVisible(true);
|
||||
mExecutor.runAllReady();
|
||||
|
||||
verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mDisclosureGeneric);
|
||||
@@ -355,6 +376,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void disclosure_orgOwnedDeviceWithManagedProfile_noOrganizationName() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
when(mKeyguardStateController.isShowing()).thenReturn(true);
|
||||
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true);
|
||||
when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList(
|
||||
@@ -369,6 +391,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void disclosure_deviceOwner_withOrganizationName() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
when(mKeyguardStateController.isShowing()).thenReturn(true);
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
|
||||
@@ -381,6 +404,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void disclosure_orgOwnedDeviceWithManagedProfile_withOrganizationName() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
when(mKeyguardStateController.isShowing()).thenReturn(true);
|
||||
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true);
|
||||
when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList(
|
||||
@@ -397,6 +421,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
when(mKeyguardStateController.isShowing()).thenReturn(true);
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||
@@ -424,7 +449,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void disclosure_deviceOwner_financedDeviceWithOrganizationName() {
|
||||
createController();
|
||||
|
||||
mController.setVisible(true);
|
||||
when(mKeyguardStateController.isShowing()).thenReturn(true);
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
|
||||
@@ -432,6 +457,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
.thenReturn(DEVICE_OWNER_TYPE_FINANCED);
|
||||
sendUpdateDisclosureBroadcast();
|
||||
mExecutor.runAllReady();
|
||||
mController.setVisible(true);
|
||||
|
||||
verifyIndicationMessage(INDICATION_TYPE_DISCLOSURE, mFinancedDisclosureWithOrganization);
|
||||
}
|
||||
@@ -469,10 +495,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void transientIndication_visibleWhenDozing() {
|
||||
createController();
|
||||
|
||||
mController.setVisible(true);
|
||||
mController.showTransientIndication(TEST_STRING_RES);
|
||||
|
||||
mStatusBarStateListener.onDozingChanged(true);
|
||||
mController.showTransientIndication(TEST_STRING_RES);
|
||||
|
||||
assertThat(mTextView.getText()).isEqualTo(
|
||||
mContext.getResources().getString(TEST_STRING_RES));
|
||||
@@ -493,7 +519,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
reset(mRotateTextViewController);
|
||||
mStatusBarStateListener.onDozingChanged(true);
|
||||
|
||||
verifyHideIndication(INDICATION_TYPE_BIOMETRIC_MESSAGE);
|
||||
assertThat(mTextView.getText()).isNotEqualTo(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -604,10 +630,9 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateMonitor_listener() {
|
||||
public void registersKeyguardStateCallback() {
|
||||
createController();
|
||||
verify(mKeyguardStateController).addCallback(any());
|
||||
verify(mKeyguardUpdateMonitor, times(2)).registerCallback(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -695,13 +720,13 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void onRefreshBatteryInfo_dozing_dischargingWithOverheat_presentBatteryPercentage() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_DISCHARGING,
|
||||
90 /* level */, 0 /* plugged */, BatteryManager.BATTERY_HEALTH_OVERHEAT,
|
||||
0 /* maxChargingWattage */, true /* present */);
|
||||
|
||||
mController.getKeyguardCallback().onRefreshBatteryInfo(status);
|
||||
mStatusBarStateListener.onDozingChanged(true);
|
||||
mController.setVisible(true);
|
||||
|
||||
String percentage = NumberFormat.getPercentInstance().format(90 / 100f);
|
||||
assertThat(mTextView.getText()).isEqualTo(percentage);
|
||||
@@ -710,9 +735,9 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void onRequireUnlockForNfc_showsRequireUnlockForNfcIndication() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
String message = mContext.getString(R.string.require_unlock_for_nfc);
|
||||
mController.getKeyguardCallback().onRequireUnlockForNfc();
|
||||
mController.setVisible(true);
|
||||
|
||||
verifyTransientMessage(message);
|
||||
}
|
||||
@@ -778,6 +803,9 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testOnKeyguardShowingChanged_showing_updatesPersistentMessages() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
mExecutor.runAllReady();
|
||||
reset(mRotateTextViewController);
|
||||
|
||||
// GIVEN keyguard is showing
|
||||
when(mKeyguardStateController.isShowing()).thenReturn(true);
|
||||
@@ -799,6 +827,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void onTrustGrantedMessageDoesNotShowUntilTrustGranted() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
reset(mRotateTextViewController);
|
||||
|
||||
// GIVEN a trust granted message but trust isn't granted
|
||||
final String trustGrantedMsg = "testing trust granted message";
|
||||
@@ -808,7 +838,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
|
||||
// WHEN trust is granted
|
||||
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
|
||||
mController.setVisible(true);
|
||||
mKeyguardUpdateMonitorCallback.onTrustChanged(KeyguardUpdateMonitor.getCurrentUser());
|
||||
|
||||
// THEN verify the trust granted message shows
|
||||
verifyIndicationMessage(
|
||||
@@ -819,6 +849,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void onTrustGrantedMessageDoesShowsOnTrustGranted() {
|
||||
createController();
|
||||
mController.setVisible(true);
|
||||
|
||||
// GIVEN trust is granted
|
||||
when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
|
||||
|
||||
Reference in New Issue
Block a user