Fix the looper that KeyguardUpdateMonitor is using.
Bug: 139051615
Test: atest SystemUITests && atest SystemUIGoogleTests
Change-Id: Ic4dd5978001c208504c137cee41f363d7e70b1b5
diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
index 7ea83f5..b0ab5b4 100644
--- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
+++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
@@ -948,8 +948,8 @@
pw.print(" mNavigationBarView=");
pw.println(mNavigationBarView);
- if (KeyguardUpdateMonitor.getInstance(mContext) != null) {
- KeyguardUpdateMonitor.getInstance(mContext).dump(fd, pw, args);
+ if (Dependency.get(KeyguardUpdateMonitor.class) != null) {
+ Dependency.get(KeyguardUpdateMonitor.class).dump(fd, pw, args);
}
Dependency.get(FalsingManager.class).dump(pw);
diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierText.java b/packages/SystemUI/src/com/android/keyguard/CarrierText.java
index adcb7a1..7592a8d 100644
--- a/packages/SystemUI/src/com/android/keyguard/CarrierText.java
+++ b/packages/SystemUI/src/com/android/keyguard/CarrierText.java
@@ -24,6 +24,8 @@
import android.view.View;
import android.widget.TextView;
+import com.android.systemui.Dependency;
+
import java.util.Locale;
public class CarrierText extends TextView {
@@ -83,7 +85,7 @@
com.android.internal.R.string.kg_text_message_separator);
mCarrierTextController = new CarrierTextController(mContext, mSeparator, mShowAirplaneMode,
mShowMissingSim);
- mShouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
+ mShouldMarquee = Dependency.get(KeyguardUpdateMonitor.class).isDeviceInteractive();
setSelected(mShouldMarquee); // Allow marquee to work.
}
diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
index 107d5cc..cdabbd7 100644
--- a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
+++ b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
@@ -225,7 +225,7 @@
// TODO(b/140034799)
if (whitelistIpcs(() -> ConnectivityManager.from(mContext).isNetworkSupported(
ConnectivityManager.TYPE_MOBILE))) {
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mKeyguardUpdateMonitor.registerCallback(mCallback);
mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
telephonyManager.listen(mPhoneStateListener,
@@ -487,7 +487,7 @@
}
final boolean missingAndNotProvisioned =
- !KeyguardUpdateMonitor.getInstance(mContext).isDeviceProvisioned()
+ !Dependency.get(KeyguardUpdateMonitor.class).isDeviceProvisioned()
&& (simState == IccCardConstants.State.ABSENT
|| simState == IccCardConstants.State.PERM_DISABLED);
diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
index 979f3dc..1c30762 100644
--- a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
+++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
@@ -40,6 +40,7 @@
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.util.EmergencyAffordanceManager;
import com.android.internal.widget.LockPatternUtils;
+import com.android.systemui.Dependency;
import com.android.systemui.util.EmergencyDialerConstants;
/**
@@ -104,13 +105,13 @@
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mInfoCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mInfoCallback);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mInfoCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mInfoCallback);
}
@Override
@@ -186,7 +187,7 @@
mEmergencyButtonCallback.onEmergencyButtonClickedWhenInCall();
}
} else {
- KeyguardUpdateMonitor.getInstance(mContext).reportEmergencyCallAction(
+ Dependency.get(KeyguardUpdateMonitor.class).reportEmergencyCallAction(
true /* bypassHandler */);
getContext().startActivityAsUser(INTENT_EMERGENCY_DIAL,
ActivityOptions.makeCustomAnimation(getContext(), 0, 0).toBundle(),
@@ -201,7 +202,7 @@
if (isInCall()) {
visible = true; // always show "return to call" if phone is off-hook
} else {
- final boolean simLocked = KeyguardUpdateMonitor.getInstance(mContext)
+ final boolean simLocked = Dependency.get(KeyguardUpdateMonitor.class)
.isSimPinVoiceSecure();
if (simLocked) {
// Some countries can't handle emergency calls while SIM is locked.
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardHostView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardHostView.java
index 14ead04..97e435d 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardHostView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardHostView.java
@@ -35,6 +35,7 @@
import com.android.keyguard.KeyguardSecurityContainer.SecurityCallback;
import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
import com.android.settingslib.Utils;
+import com.android.systemui.Dependency;
import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
import java.io.File;
@@ -106,7 +107,7 @@
public KeyguardHostView(Context context, AttributeSet attrs) {
super(context, attrs);
- KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mUpdateCallback);
}
@Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardMessageArea.java b/packages/SystemUI/src/com/android/keyguard/KeyguardMessageArea.java
index 037a8d3..811b458 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardMessageArea.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardMessageArea.java
@@ -31,6 +31,7 @@
import android.view.View;
import android.widget.TextView;
+import com.android.systemui.Dependency;
import com.android.systemui.statusbar.policy.ConfigurationController;
import java.lang.ref.WeakReference;
@@ -85,7 +86,7 @@
@Inject
public KeyguardMessageArea(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs,
ConfigurationController configurationController) {
- this(context, attrs, KeyguardUpdateMonitor.getInstance(context), configurationController);
+ this(context, attrs, Dependency.get(KeyguardUpdateMonitor.class), configurationController);
}
public KeyguardMessageArea(Context context, AttributeSet attrs, KeyguardUpdateMonitor monitor,
@@ -177,7 +178,7 @@
@Override
protected void onFinishInflate() {
- boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
+ boolean shouldMarquee = Dependency.get(KeyguardUpdateMonitor.class).isDeviceInteractive();
setSelected(shouldMarquee); // This is required to ensure marquee works
}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java
index 6808c0f..299e72b 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java
@@ -24,6 +24,7 @@
import com.android.settingslib.animation.AppearAnimationUtils;
import com.android.settingslib.animation.DisappearAnimationUtils;
+import com.android.systemui.Dependency;
/**
* Displays a PIN pad for unlocking.
@@ -61,7 +62,7 @@
mContext, android.R.interpolator.fast_out_linear_in));
mDisappearYTranslation = getResources().getDimensionPixelSize(
R.dimen.disappear_y_translation);
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
}
@Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java
index 56b38f7..11a70b6 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java
@@ -42,6 +42,7 @@
import com.android.settingslib.animation.AppearAnimationCreator;
import com.android.settingslib.animation.AppearAnimationUtils;
import com.android.settingslib.animation.DisappearAnimationUtils;
+import com.android.systemui.Dependency;
import java.util.List;
@@ -116,7 +117,7 @@
public KeyguardPatternView(Context context, AttributeSet attrs) {
super(context, attrs);
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mAppearAnimationUtils = new AppearAnimationUtils(context,
AppearAnimationUtils.DEFAULT_APPEAR_DURATION, 1.5f /* translationScale */,
2.0f /* delayScale */, AnimationUtils.loadInterpolator(
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
index 454f446..878c9c4 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
@@ -129,7 +129,7 @@
super(context, attrs, defStyle);
mSecurityModel = new KeyguardSecurityModel(context);
mLockPatternUtils = new LockPatternUtils(context);
- mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mSpringAnimation = new SpringAnimation(this, DynamicAnimation.Y);
mInjectionInflationController = new InjectionInflationController(
SystemUIFactory.getInstance().getRootComponent());
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java
index 16e9ffc..bb89959 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java
@@ -23,6 +23,7 @@
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.widget.LockPatternUtils;
+import com.android.systemui.Dependency;
public class KeyguardSecurityModel {
@@ -57,7 +58,7 @@
}
SecurityMode getSecurityMode(int userId) {
- KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
+ KeyguardUpdateMonitor monitor = Dependency.get(KeyguardUpdateMonitor.class);
if (mIsPukScreenAvailable && SubscriptionManager.isValidSubscriptionId(
monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED))) {
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinView.java
index 69da990..b93e28b 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinView.java
@@ -41,6 +41,7 @@
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.telephony.PhoneConstants;
+import com.android.systemui.Dependency;
/**
* Displays a PIN pad for unlocking.
@@ -111,8 +112,8 @@
if (count < 2) {
msg = rez.getString(R.string.kg_sim_pin_instructions);
} else {
- SubscriptionInfo info = KeyguardUpdateMonitor.getInstance(mContext).
- getSubscriptionInfoForSubId(mSubId);
+ SubscriptionInfo info = Dependency.get(KeyguardUpdateMonitor.class)
+ .getSubscriptionInfoForSubId(mSubId);
CharSequence displayName = info != null ? info.getDisplayName() : ""; // don't crash
msg = rez.getString(R.string.kg_sim_pin_instructions_multi, displayName);
if (info != null) {
@@ -149,7 +150,7 @@
}
private void handleSubInfoChangeIfNeeded() {
- KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
+ KeyguardUpdateMonitor monitor = Dependency.get(KeyguardUpdateMonitor.class);
int subId = monitor.getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED);
if (subId != mSubId && SubscriptionManager.isValidSubscriptionId(subId)) {
mSubId = subId;
@@ -222,7 +223,7 @@
@Override
public void onResume(int reason) {
super.onResume(reason);
- KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mUpdateMonitorCallback);
resetState();
}
@@ -233,7 +234,7 @@
mSimUnlockProgressDialog.dismiss();
mSimUnlockProgressDialog = null;
}
- KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mUpdateMonitorCallback);
}
/**
@@ -337,7 +338,7 @@
resetPasswordText(true /* animate */,
result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
- KeyguardUpdateMonitor.getInstance(getContext())
+ Dependency.get(KeyguardUpdateMonitor.class)
.reportSimUnlocked(mSubId);
mRemainingAttempts = -1;
mShowDefaultMessage = true;
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java
index 27f71d1..44cd2ef 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java
@@ -40,6 +40,7 @@
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.telephony.PhoneConstants;
+import com.android.systemui.Dependency;
/**
@@ -171,8 +172,8 @@
if (count < 2) {
msg = rez.getString(R.string.kg_puk_enter_puk_hint);
} else {
- SubscriptionInfo info = KeyguardUpdateMonitor.getInstance(mContext).
- getSubscriptionInfoForSubId(mSubId);
+ SubscriptionInfo info = Dependency.get(KeyguardUpdateMonitor.class)
+ .getSubscriptionInfoForSubId(mSubId);
CharSequence displayName = info != null ? info.getDisplayName() : "";
msg = rez.getString(R.string.kg_puk_enter_puk_hint_multi, displayName);
if (info != null) {
@@ -202,7 +203,7 @@
}
private void handleSubInfoChangeIfNeeded() {
- KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
+ KeyguardUpdateMonitor monitor = Dependency.get(KeyguardUpdateMonitor.class);
int subId = monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED);
if (subId != mSubId && SubscriptionManager.isValidSubscriptionId(subId)) {
mSubId = subId;
@@ -271,14 +272,14 @@
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mUpdateMonitorCallback);
resetState();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mUpdateMonitorCallback);
}
@Override
@@ -408,7 +409,7 @@
resetPasswordText(true /* animate */,
result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
- KeyguardUpdateMonitor.getInstance(getContext())
+ Dependency.get(KeyguardUpdateMonitor.class)
.reportSimUnlocked(mSubId);
mRemainingAttempts = -1;
mShowDefaultMessage = true;
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
index 37e89c0..0cbe43b 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
@@ -198,7 +198,7 @@
mKeyguardSlice.setContentChangeListener(this::onSliceContentChanged);
onSliceContentChanged();
- boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
+ boolean shouldMarquee = Dependency.get(KeyguardUpdateMonitor.class).isDeviceInteractive();
setEnableMarquee(shouldMarquee);
refreshFormat();
updateOwnerInfo();
@@ -314,14 +314,14 @@
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mInfoCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mInfoCallback);
Dependency.get(ConfigurationController.class).addCallback(this);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mInfoCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mInfoCallback);
Dependency.get(ConfigurationController.class).removeCallback(this);
}
@@ -441,7 +441,7 @@
}
private boolean shouldShowLogout() {
- return KeyguardUpdateMonitor.getInstance(mContext).isLogoutEnabled()
+ return Dependency.get(KeyguardUpdateMonitor.class).isLogoutEnabled()
&& KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM;
}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
index aa1d8b4..81a6576 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
@@ -39,13 +39,13 @@
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT;
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
import static com.android.systemui.DejankUtils.whitelistIpcs;
+import static com.android.systemui.Dependency.MAIN_LOOPER_NAME;
import android.annotation.AnyThread;
import android.annotation.MainThread;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.AlarmManager;
-import android.app.Instrumentation;
import android.app.PendingIntent;
import android.app.UserSwitchObserver;
import android.app.admin.DevicePolicyManager;
@@ -96,7 +96,6 @@
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
-import com.android.internal.util.Preconditions;
import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.WirelessUtils;
import com.android.systemui.shared.system.ActivityManagerWrapper;
@@ -115,6 +114,9 @@
import java.util.TimeZone;
import java.util.function.Consumer;
+import javax.inject.Inject;
+import javax.inject.Named;
+
/**
* Watches for updates that may be interesting to the keyguard, and provides
* the up to date information as well as a registration for callbacks that care
@@ -292,119 +294,7 @@
}
};
- private final Handler mHandler = new Handler(Looper.getMainLooper()) {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_TIME_UPDATE:
- handleTimeUpdate();
- break;
- case MSG_TIMEZONE_UPDATE:
- handleTimeZoneUpdate((String) msg.obj);
- break;
- case MSG_BATTERY_UPDATE:
- handleBatteryUpdate((BatteryStatus) msg.obj);
- break;
- case MSG_SIM_STATE_CHANGE:
- handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj);
- break;
- case MSG_RINGER_MODE_CHANGED:
- handleRingerModeChange(msg.arg1);
- break;
- case MSG_PHONE_STATE_CHANGED:
- handlePhoneStateChanged((String) msg.obj);
- break;
- case MSG_DEVICE_PROVISIONED:
- handleDeviceProvisioned();
- break;
- case MSG_DPM_STATE_CHANGED:
- handleDevicePolicyManagerStateChanged();
- break;
- case MSG_USER_SWITCHING:
- handleUserSwitching(msg.arg1, (IRemoteCallback) msg.obj);
- break;
- case MSG_USER_SWITCH_COMPLETE:
- handleUserSwitchComplete(msg.arg1);
- break;
- case MSG_KEYGUARD_RESET:
- handleKeyguardReset();
- break;
- case MSG_KEYGUARD_BOUNCER_CHANGED:
- handleKeyguardBouncerChanged(msg.arg1);
- break;
- case MSG_BOOT_COMPLETED:
- handleBootCompleted();
- break;
- case MSG_USER_INFO_CHANGED:
- handleUserInfoChanged(msg.arg1);
- break;
- case MSG_REPORT_EMERGENCY_CALL_ACTION:
- handleReportEmergencyCallAction();
- break;
- case MSG_STARTED_GOING_TO_SLEEP:
- handleStartedGoingToSleep(msg.arg1);
- break;
- case MSG_FINISHED_GOING_TO_SLEEP:
- handleFinishedGoingToSleep(msg.arg1);
- break;
- case MSG_STARTED_WAKING_UP:
- Trace.beginSection("KeyguardUpdateMonitor#handler MSG_STARTED_WAKING_UP");
- handleStartedWakingUp();
- Trace.endSection();
- break;
- case MSG_FACE_UNLOCK_STATE_CHANGED:
- Trace.beginSection(
- "KeyguardUpdateMonitor#handler MSG_FACE_UNLOCK_STATE_CHANGED");
- handleFaceUnlockStateChanged(msg.arg1 != 0, msg.arg2);
- Trace.endSection();
- break;
- case MSG_SIM_SUBSCRIPTION_INFO_CHANGED:
- handleSimSubscriptionInfoChanged();
- break;
- case MSG_AIRPLANE_MODE_CHANGED:
- handleAirplaneModeChanged();
- break;
- case MSG_SERVICE_STATE_CHANGE:
- handleServiceStateChange(msg.arg1, (ServiceState) msg.obj);
- break;
- case MSG_SCREEN_TURNED_ON:
- handleScreenTurnedOn();
- break;
- case MSG_SCREEN_TURNED_OFF:
- Trace.beginSection("KeyguardUpdateMonitor#handler MSG_SCREEN_TURNED_ON");
- handleScreenTurnedOff();
- Trace.endSection();
- break;
- case MSG_DREAMING_STATE_CHANGED:
- handleDreamingStateChanged(msg.arg1);
- break;
- case MSG_USER_UNLOCKED:
- handleUserUnlocked(msg.arg1);
- break;
- case MSG_USER_STOPPED:
- handleUserStopped(msg.arg1);
- break;
- case MSG_USER_REMOVED:
- handleUserRemoved(msg.arg1);
- break;
- case MSG_ASSISTANT_STACK_CHANGED:
- setAssistantVisible((boolean) msg.obj);
- break;
- case MSG_BIOMETRIC_AUTHENTICATION_CONTINUE:
- updateBiometricListeningState();
- break;
- case MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED:
- updateLogoutEnabled();
- break;
- case MSG_TELEPHONY_CAPABLE:
- updateTelephonyCapable((boolean) msg.obj);
- break;
- default:
- super.handleMessage(msg);
- break;
- }
- }
- };
+ private final Handler mHandler;
private SparseBooleanArray mFaceSettingEnabledForUser = new SparseBooleanArray();
private BiometricManager mBiometricManager;
@@ -446,7 +336,6 @@
private static int sCurrentUser;
private Runnable mUpdateBiometricListeningState = this::updateBiometricListeningState;
- private static boolean sDisableHandlerCheckForTesting;
public synchronized static void setCurrentUser(int currentUser) {
sCurrentUser = currentUser;
@@ -1486,13 +1375,6 @@
}
}
- public static KeyguardUpdateMonitor getInstance(Context context) {
- if (sInstance == null) {
- sInstance = new KeyguardUpdateMonitor(context);
- }
- return sInstance;
- }
-
protected void handleStartedWakingUp() {
Trace.beginSection("KeyguardUpdateMonitor#handleStartedWakingUp");
checkIsHandlerThread();
@@ -1599,12 +1481,127 @@
}
@VisibleForTesting
- protected KeyguardUpdateMonitor(Context context) {
+ @Inject
+ protected KeyguardUpdateMonitor(Context context, @Named(MAIN_LOOPER_NAME) Looper mainLooper) {
mContext = context;
mSubscriptionManager = SubscriptionManager.from(context);
mDeviceProvisioned = isDeviceProvisionedInSettingsDb();
mStrongAuthTracker = new StrongAuthTracker(context, this::notifyStrongAuthStateChanged);
+ mHandler = new Handler(mainLooper) {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_TIME_UPDATE:
+ handleTimeUpdate();
+ break;
+ case MSG_TIMEZONE_UPDATE:
+ handleTimeZoneUpdate((String) msg.obj);
+ break;
+ case MSG_BATTERY_UPDATE:
+ handleBatteryUpdate((BatteryStatus) msg.obj);
+ break;
+ case MSG_SIM_STATE_CHANGE:
+ handleSimStateChange(msg.arg1, msg.arg2, (State) msg.obj);
+ break;
+ case MSG_RINGER_MODE_CHANGED:
+ handleRingerModeChange(msg.arg1);
+ break;
+ case MSG_PHONE_STATE_CHANGED:
+ handlePhoneStateChanged((String) msg.obj);
+ break;
+ case MSG_DEVICE_PROVISIONED:
+ handleDeviceProvisioned();
+ break;
+ case MSG_DPM_STATE_CHANGED:
+ handleDevicePolicyManagerStateChanged();
+ break;
+ case MSG_USER_SWITCHING:
+ handleUserSwitching(msg.arg1, (IRemoteCallback) msg.obj);
+ break;
+ case MSG_USER_SWITCH_COMPLETE:
+ handleUserSwitchComplete(msg.arg1);
+ break;
+ case MSG_KEYGUARD_RESET:
+ handleKeyguardReset();
+ break;
+ case MSG_KEYGUARD_BOUNCER_CHANGED:
+ handleKeyguardBouncerChanged(msg.arg1);
+ break;
+ case MSG_BOOT_COMPLETED:
+ handleBootCompleted();
+ break;
+ case MSG_USER_INFO_CHANGED:
+ handleUserInfoChanged(msg.arg1);
+ break;
+ case MSG_REPORT_EMERGENCY_CALL_ACTION:
+ handleReportEmergencyCallAction();
+ break;
+ case MSG_STARTED_GOING_TO_SLEEP:
+ handleStartedGoingToSleep(msg.arg1);
+ break;
+ case MSG_FINISHED_GOING_TO_SLEEP:
+ handleFinishedGoingToSleep(msg.arg1);
+ break;
+ case MSG_STARTED_WAKING_UP:
+ Trace.beginSection("KeyguardUpdateMonitor#handler MSG_STARTED_WAKING_UP");
+ handleStartedWakingUp();
+ Trace.endSection();
+ break;
+ case MSG_FACE_UNLOCK_STATE_CHANGED:
+ Trace.beginSection(
+ "KeyguardUpdateMonitor#handler MSG_FACE_UNLOCK_STATE_CHANGED");
+ handleFaceUnlockStateChanged(msg.arg1 != 0, msg.arg2);
+ Trace.endSection();
+ break;
+ case MSG_SIM_SUBSCRIPTION_INFO_CHANGED:
+ handleSimSubscriptionInfoChanged();
+ break;
+ case MSG_AIRPLANE_MODE_CHANGED:
+ handleAirplaneModeChanged();
+ break;
+ case MSG_SERVICE_STATE_CHANGE:
+ handleServiceStateChange(msg.arg1, (ServiceState) msg.obj);
+ break;
+ case MSG_SCREEN_TURNED_ON:
+ handleScreenTurnedOn();
+ break;
+ case MSG_SCREEN_TURNED_OFF:
+ Trace.beginSection("KeyguardUpdateMonitor#handler MSG_SCREEN_TURNED_ON");
+ handleScreenTurnedOff();
+ Trace.endSection();
+ break;
+ case MSG_DREAMING_STATE_CHANGED:
+ handleDreamingStateChanged(msg.arg1);
+ break;
+ case MSG_USER_UNLOCKED:
+ handleUserUnlocked(msg.arg1);
+ break;
+ case MSG_USER_STOPPED:
+ handleUserStopped(msg.arg1);
+ break;
+ case MSG_USER_REMOVED:
+ handleUserRemoved(msg.arg1);
+ break;
+ case MSG_ASSISTANT_STACK_CHANGED:
+ setAssistantVisible((boolean) msg.obj);
+ break;
+ case MSG_BIOMETRIC_AUTHENTICATION_CONTINUE:
+ updateBiometricListeningState();
+ break;
+ case MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED:
+ updateLogoutEnabled();
+ break;
+ case MSG_TELEPHONY_CAPABLE:
+ updateTelephonyCapable((boolean) msg.obj);
+ break;
+ default:
+ super.handleMessage(msg);
+ break;
+ }
+ }
+ };
+
// Since device can't be un-provisioned, we only need to register a content observer
// to update mDeviceProvisioned when we are...
if (!mDeviceProvisioned) {
@@ -2752,35 +2749,12 @@
}
private void checkIsHandlerThread() {
- if (sDisableHandlerCheckForTesting) {
- return;
- }
if (!mHandler.getLooper().isCurrentThread()) {
Log.wtf(TAG, "must call on mHandler's thread "
+ mHandler.getLooper().getThread() + ", not " + Thread.currentThread());
}
}
- /**
- * Turn off the handler check for testing.
- *
- * This is necessary because currently tests are not too careful about which thread they call
- * into this class on.
- *
- * Note that this must be called before scheduling any work involving KeyguardUpdateMonitor
- * instances.
- *
- * TODO: fix the tests and remove this.
- */
- @VisibleForTesting
- public static void disableHandlerCheckForTesting(Instrumentation instrumentation) {
- Preconditions.checkNotNull(instrumentation, "Must only call this method in tests!");
- // Don't need synchronization here *if* the callers follow the contract and call this only
- // before scheduling work for KeyguardUpdateMonitor on other threads, because the scheduling
- // of that work forces a happens-before relationship.
- sDisableHandlerCheckForTesting = true;
- }
-
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("KeyguardUpdateMonitor state:");
pw.println(" SIM States:");
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index f9452e2..d8f039c 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -30,6 +30,7 @@
import com.android.internal.logging.MetricsLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.Preconditions;
+import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.clock.ClockManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.systemui.appops.AppOpsController;
@@ -145,6 +146,11 @@
private static final String TAG = "Dependency";
/**
+ * Key for getting a the main looper.
+ */
+ public static final String MAIN_LOOPER_NAME = "main_looper";
+
+ /**
* Key for getting a background Looper for background work.
*/
public static final String BG_LOOPER_NAME = "background_looper";
@@ -177,6 +183,10 @@
*/
public static final DependencyKey<Looper> BG_LOOPER = new DependencyKey<>(BG_LOOPER_NAME);
/**
+ * Key for getting a mainer Looper.
+ */
+ public static final DependencyKey<Looper> MAIN_LOOPER = new DependencyKey<>(MAIN_LOOPER_NAME);
+ /**
* Key for getting a background Handler for background work.
*/
public static final DependencyKey<Handler> BG_HANDLER = new DependencyKey<>(BG_HANDLER_NAME);
@@ -215,6 +225,7 @@
@Inject Lazy<UserSwitcherController> mUserSwitcherController;
@Inject Lazy<UserInfoController> mUserInfoController;
@Inject Lazy<KeyguardMonitor> mKeyguardMonitor;
+ @Inject Lazy<KeyguardUpdateMonitor> mKeyguardUpdateMonitor;
@Inject Lazy<BatteryController> mBatteryController;
@Inject Lazy<NightDisplayListener> mNightDisplayListener;
@Inject Lazy<ManagedProfileController> mManagedProfileController;
@@ -291,6 +302,7 @@
@Inject Lazy<PrivacyItemController> mPrivacyItemController;
@Inject @Named(BG_LOOPER_NAME) Lazy<Looper> mBgLooper;
@Inject @Named(BG_HANDLER_NAME) Lazy<Handler> mBgHandler;
+ @Inject @Named(MAIN_LOOPER_NAME) Lazy<Looper> mMainLooper;
@Inject @Named(MAIN_HANDLER_NAME) Lazy<Handler> mMainHandler;
@Inject @Named(TIME_TICK_HANDLER_NAME) Lazy<Handler> mTimeTickHandler;
@Nullable
@@ -318,6 +330,7 @@
mProviders.put(TIME_TICK_HANDLER, mTimeTickHandler::get);
mProviders.put(BG_LOOPER, mBgLooper::get);
mProviders.put(BG_HANDLER, mBgHandler::get);
+ mProviders.put(MAIN_LOOPER, mMainLooper::get);
mProviders.put(MAIN_HANDLER, mMainHandler::get);
mProviders.put(ActivityStarter.class, mActivityStarter::get);
mProviders.put(ActivityStarterDelegate.class, mActivityStarterDelegate::get);
@@ -344,6 +357,8 @@
mProviders.put(KeyguardMonitor.class, mKeyguardMonitor::get);
+ mProviders.put(KeyguardUpdateMonitor.class, mKeyguardUpdateMonitor::get);
+
mProviders.put(UserSwitcherController.class, mUserSwitcherController::get);
mProviders.put(UserInfoController.class, mUserInfoController::get);
diff --git a/packages/SystemUI/src/com/android/systemui/DependencyProvider.java b/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
index 3e2010e..d46a86c 100644
--- a/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
@@ -19,6 +19,7 @@
import static com.android.systemui.Dependency.BG_HANDLER_NAME;
import static com.android.systemui.Dependency.BG_LOOPER_NAME;
import static com.android.systemui.Dependency.MAIN_HANDLER_NAME;
+import static com.android.systemui.Dependency.MAIN_LOOPER_NAME;
import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME;
import android.annotation.Nullable;
@@ -87,6 +88,14 @@
return thread.getLooper();
}
+ /** Main Looper */
+ @Singleton
+ @Provides
+ @Named(MAIN_LOOPER_NAME)
+ public Looper provideMainLooper() {
+ return Looper.getMainLooper();
+ }
+
@Singleton
@Provides
@Named(BG_HANDLER_NAME)
@@ -97,8 +106,8 @@
@Singleton
@Provides
@Named(MAIN_HANDLER_NAME)
- public Handler provideMainHandler() {
- return new Handler(Looper.getMainLooper());
+ public Handler provideMainHandler(@Named(MAIN_LOOPER_NAME) Looper mainLooper) {
+ return new Handler(mainLooper);
}
@Singleton
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactory.java
index 6a59fa1..0f99674 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIAppComponentFactory.java
@@ -51,8 +51,8 @@
@NonNull ClassLoader cl, @NonNull String className)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
Application app = super.instantiateApplicationCompat(cl, className);
- if (app instanceof ContextProvider) {
- ((ContextProvider) app).setContextAvailableCallback(
+ if (app instanceof ContextInitializer) {
+ ((ContextInitializer) app).setContextAvailableCallback(
context -> {
SystemUIFactory.createFromConfig(context);
SystemUIFactory.getInstance().getRootComponent().inject(
@@ -71,8 +71,8 @@
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
ContentProvider contentProvider = super.instantiateProviderCompat(cl, className);
- if (contentProvider instanceof ContextProvider) {
- ((ContextProvider) contentProvider).setContextAvailableCallback(
+ if (contentProvider instanceof ContextInitializer) {
+ ((ContextInitializer) contentProvider).setContextAvailableCallback(
context -> {
SystemUIFactory.createFromConfig(context);
SystemUIFactory.getInstance().getRootComponent().inject(
@@ -96,11 +96,17 @@
return super.instantiateServiceCompat(cl, className, intent);
}
- interface ContextAvailableCallback {
+ /**
+ * A callback that receives a Context when one is ready.
+ */
+ public interface ContextAvailableCallback {
void onContextAvailable(Context context);
}
- interface ContextProvider {
+ /**
+ * Implemented in classes that get started by the system before a context is available.
+ */
+ public interface ContextInitializer {
void setContextAvailableCallback(ContextAvailableCallback callback);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
index aafc67e..351ca42 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -49,7 +49,7 @@
* Application class for SystemUI.
*/
public class SystemUIApplication extends Application implements SysUiServiceProvider,
- SystemUIAppComponentFactory.ContextProvider {
+ SystemUIAppComponentFactory.ContextInitializer {
public static final String TAG = "SystemUIService";
private static final boolean DEBUG = false;
@@ -182,7 +182,7 @@
o = ((SystemUI.Injector) o).apply(this);
}
mServices[i] = (SystemUI) o;
- } catch(ClassNotFoundException ex){
+ } catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
} catch (IllegalAccessException ex) {
throw new RuntimeException(ex);
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
index 45142b0..0e5bdaf 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
@@ -136,7 +136,7 @@
return new KeyguardBouncer(context, callback, lockPatternUtils, container,
dismissCallbackRegistry, falsingManager,
expansionCallback, UnlockMethodCache.getInstance(context),
- KeyguardUpdateMonitor.getInstance(context), bypassController,
+ Dependency.get(KeyguardUpdateMonitor.class), bypassController,
new Handler(Looper.getMainLooper()));
}
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/SystemUIModule.java
index 5d103eb..3395014 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIModule.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIModule.java
@@ -46,7 +46,7 @@
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE)) {
return null;
}
- return new KeyguardLiftController(context, statusBarStateController, asyncSensorManager);
+ return new KeyguardLiftController(statusBarStateController, asyncSensorManager);
}
diff --git a/packages/SystemUI/src/com/android/systemui/classifier/FalsingManagerImpl.java b/packages/SystemUI/src/com/android/systemui/classifier/FalsingManagerImpl.java
index fba0d50..c2b0fe4 100644
--- a/packages/SystemUI/src/com/android/systemui/classifier/FalsingManagerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/classifier/FalsingManagerImpl.java
@@ -154,7 +154,7 @@
updateConfiguration();
Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener);
- KeyguardUpdateMonitor.getInstance(context).registerCallback(mKeyguardUpdateCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mKeyguardUpdateCallback);
}
private void updateConfiguration() {
@@ -556,7 +556,7 @@
mSensorManager.unregisterListener(mSensorEventListener);
mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
Dependency.get(StatusBarStateController.class).removeCallback(mStatusBarStateListener);
- KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mKeyguardUpdateCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mKeyguardUpdateCallback);
}
public Uri reportRejectedTouch() {
diff --git a/packages/SystemUI/src/com/android/systemui/classifier/FalsingManagerProxy.java b/packages/SystemUI/src/com/android/systemui/classifier/FalsingManagerProxy.java
index efac147..c9f5b79 100644
--- a/packages/SystemUI/src/com/android/systemui/classifier/FalsingManagerProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/classifier/FalsingManagerProxy.java
@@ -114,7 +114,7 @@
mInternalFalsingManager = new BrightLineFalsingManager(
new FalsingDataProvider(context.getResources().getDisplayMetrics()),
Dependency.get(AsyncSensorManager.class),
- KeyguardUpdateMonitor.getInstance(context),
+ Dependency.get(KeyguardUpdateMonitor.class),
mDeviceConfig
);
}
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeAuthRemover.java b/packages/SystemUI/src/com/android/systemui/doze/DozeAuthRemover.java
index e5a54b8..abd41d4 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeAuthRemover.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeAuthRemover.java
@@ -19,6 +19,7 @@
import android.content.Context;
import com.android.keyguard.KeyguardUpdateMonitor;
+import com.android.systemui.Dependency;
/**
* Controls removing Keyguard authorization when the phone goes to sleep.
@@ -28,7 +29,7 @@
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
public DozeAuthRemover(Context context) {
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java b/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java
index 86d4a48..c367286 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java
@@ -29,8 +29,8 @@
import com.android.systemui.R;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.dock.DockManager;
-import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.keyguard.WakefulnessLifecycle;
+import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.statusbar.phone.BiometricUnlockController;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.util.AsyncSensorManager;
@@ -104,7 +104,7 @@
DozeMachine machine, Handler handler, AlarmManager alarmManager,
DozeParameters params) {
return new DozeUi(context, alarmManager, machine, wakeLock, host, handler, params,
- KeyguardUpdateMonitor.getInstance(context));
+ Dependency.get(KeyguardUpdateMonitor.class));
}
public static DozeHost getHost(DozeService service) {
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
index c09e284..8fe9f92 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
@@ -23,6 +23,7 @@
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
+import com.android.systemui.Dependency;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
@@ -112,7 +113,7 @@
}
log("init");
if (sRegisterKeyguardCallback) {
- KeyguardUpdateMonitor.getInstance(context).registerCallback(sKeyguardCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(sKeyguardCallback);
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsImpl.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsImpl.java
index 1f3403b..6f8665a 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsImpl.java
@@ -82,7 +82,7 @@
mGlobalActions.showDialog(mKeyguardMonitor.isShowing(),
mDeviceProvisionedController.isDeviceProvisioned(),
mPanelExtension.get());
- KeyguardUpdateMonitor.getInstance(mContext).requestFaceAuth();
+ Dependency.get(KeyguardUpdateMonitor.class).requestFaceAuth();
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
index 48f32cf..abfcbc1 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java
@@ -49,7 +49,9 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
+import com.android.systemui.Dependency;
import com.android.systemui.R;
+import com.android.systemui.SystemUIAppComponentFactory;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.StatusBarState;
@@ -72,7 +74,8 @@
*/
public class KeyguardSliceProvider extends SliceProvider implements
NextAlarmController.NextAlarmChangeCallback, ZenModeController.Callback,
- NotificationMediaManager.MediaListener, StatusBarStateController.StateListener {
+ NotificationMediaManager.MediaListener, StatusBarStateController.StateListener,
+ SystemUIAppComponentFactory.ContextInitializer {
private static final StyleSpan BOLD_STYLE = new StyleSpan(Typeface.BOLD);
public static final String KEYGUARD_SLICE_URI = "content://com.android.systemui.keyguard/main";
@@ -93,6 +96,7 @@
@VisibleForTesting
static final int ALARM_VISIBILITY_HOURS = 12;
+ private static final Object sInstanceLock = new Object();
private static KeyguardSliceProvider sInstance;
protected final Uri mSliceUri;
@@ -130,6 +134,7 @@
protected boolean mDozing;
private int mStatusBarState;
private boolean mMediaIsVisible;
+ private SystemUIAppComponentFactory.ContextAvailableCallback mContextAvailableCallback;
/**
* Receiver responsible for time ticking and updating the date format.
@@ -310,7 +315,11 @@
@Override
public boolean onCreateSliceProvider() {
- synchronized (this) {
+ if (mContextAvailableCallback != null) {
+ mContextAvailableCallback.onContextAvailable(getContext());
+ Dependency.initDependencies(getContext());
+ }
+ synchronized (KeyguardSliceProvider.sInstanceLock) {
KeyguardSliceProvider oldInstance = KeyguardSliceProvider.sInstance;
if (oldInstance != null) {
oldInstance.onDestroy();
@@ -335,7 +344,7 @@
@VisibleForTesting
protected void onDestroy() {
- synchronized (this) {
+ synchronized (KeyguardSliceProvider.sInstanceLock) {
mNextAlarmController.removeCallback(this);
mZenModeController.removeCallback(this);
mMediaWakeLock.setAcquired(false);
@@ -345,6 +354,7 @@
getKeyguardUpdateMonitor().removeCallback(mKeyguardUpdateMonitorCallback);
getContext().unregisterReceiver(mIntentReceiver);
}
+ KeyguardSliceProvider.sInstance = null;
}
}
@@ -449,9 +459,8 @@
updateNextAlarm();
}
- @VisibleForTesting
- protected KeyguardUpdateMonitor getKeyguardUpdateMonitor() {
- return KeyguardUpdateMonitor.getInstance(getContext());
+ private KeyguardUpdateMonitor getKeyguardUpdateMonitor() {
+ return Dependency.get(KeyguardUpdateMonitor.class);
}
/**
@@ -530,4 +539,10 @@
notifyChange();
}
}
+
+ @Override
+ public void setContextAvailableCallback(
+ SystemUIAppComponentFactory.ContextAvailableCallback callback) {
+ mContextAvailableCallback = callback;
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 4016b59..dc026e7 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -710,7 +710,7 @@
mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
- mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mLockPatternUtils = new LockPatternUtils(mContext);
KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
@@ -846,7 +846,7 @@
playSounds(true);
}
}
- KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
+ mUpdateMonitor.dispatchStartedGoingToSleep(why);
notifyStartedGoingToSleep();
}
@@ -891,7 +891,7 @@
}
}
- KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
+ mUpdateMonitor.dispatchFinishedGoingToSleep(why);
}
private long getLockTimeout(int userId) {
@@ -1004,7 +1004,7 @@
if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
notifyStartedWakingUp();
}
- KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
+ mUpdateMonitor.dispatchStartedWakingUp();
maybeSendUserPresentBroadcast();
Trace.endSection();
}
@@ -1047,7 +1047,7 @@
* if there is a secure lock pattern.
*/
public void onDreamingStarted() {
- KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
+ mUpdateMonitor.dispatchDreamingStarted();
synchronized (this) {
if (mDeviceInteractive
&& mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
@@ -1060,7 +1060,7 @@
* A dream stopped.
*/
public void onDreamingStopped() {
- KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
+ mUpdateMonitor.dispatchDreamingStopped();
synchronized (this) {
if (mDeviceInteractive) {
cancelDoKeyguardLaterLocked();
@@ -1456,11 +1456,11 @@
public boolean isSecure(int userId) {
return mLockPatternUtils.isSecure(userId)
- || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
+ || mUpdateMonitor.isSimPinSecure();
}
public void setSwitchingUser(boolean switching) {
- KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
+ mUpdateMonitor.setSwitchingUser(switching);
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
index 9178fda..6556ed0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
@@ -142,7 +142,7 @@
Dependency.get(AccessibilityController.class),
UnlockMethodCache.getInstance(context),
Dependency.get(StatusBarStateController.class),
- KeyguardUpdateMonitor.getInstance(context));
+ Dependency.get(KeyguardUpdateMonitor.class));
}
/**
@@ -649,7 +649,7 @@
@Override
public void onBiometricHelp(int msgId, String helpString,
BiometricSourceType biometricSourceType) {
- KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ KeyguardUpdateMonitor updateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
if (!updateMonitor.isUnlockingWithBiometricAllowed()) {
return;
}
@@ -674,7 +674,7 @@
@Override
public void onBiometricError(int msgId, String errString,
BiometricSourceType biometricSourceType) {
- KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ KeyguardUpdateMonitor updateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
if (shouldSuppressBiometricError(msgId, biometricSourceType, updateMonitor)) {
return;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
index 107b24c..289277e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
@@ -281,7 +281,7 @@
if (userId == UserHandle.USER_ALL) {
userId = mCurrentUserId;
}
- return KeyguardUpdateMonitor.getInstance(mContext).isUserInLockdown(userId);
+ return Dependency.get(KeyguardUpdateMonitor.class).isUserInLockdown(userId);
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java b/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java
index 2a5ccdb..843c37f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java
@@ -70,7 +70,7 @@
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mKeyguardUpdateMonitor.registerCallback(mCallback);
Dependency.get(DarkIconDispatcher.class).addDarkReceiver(this);
Dependency.get(NetworkController.class).addCallback(this);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
index ab9162a..b6f82a1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
@@ -278,7 +278,7 @@
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
getContext().registerReceiverAsUser(mDevicePolicyReceiver,
UserHandle.ALL, filter, null, null);
- KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mUpdateMonitorCallback);
mUnlockMethodCache.addListener(this);
}
@@ -290,7 +290,7 @@
mRightExtension.destroy();
mLeftExtension.destroy();
getContext().unregisterReceiver(mDevicePolicyReceiver);
- KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mUpdateMonitorCallback);
}
private void initAccessibility() {
@@ -817,7 +817,7 @@
@Override
public Intent getIntent() {
- KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ KeyguardUpdateMonitor updateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
boolean canSkipBouncer = updateMonitor.getUserCanSkipBouncer(
KeyguardUpdateMonitor.getCurrentUser());
boolean secure = mUnlockMethodCache.isMethodSecure();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardLiftController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardLiftController.kt
index f4635d1..f7bb97b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardLiftController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardLiftController.kt
@@ -16,23 +16,22 @@
package com.android.systemui.statusbar.phone
-import android.content.Context
import android.hardware.Sensor
import android.hardware.TriggerEvent
import android.hardware.TriggerEventListener
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
+import com.android.systemui.Dependency
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.util.Assert
import com.android.systemui.util.AsyncSensorManager
class KeyguardLiftController constructor(
- context: Context,
private val statusBarStateController: StatusBarStateController,
private val asyncSensorManager: AsyncSensorManager
) : StatusBarStateController.StateListener, KeyguardUpdateMonitorCallback() {
- private val keyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context)
+ private val keyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor::class.java)
private val pickupSensor = asyncSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE)
private var isListening = false
private var bouncerVisible = false
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java
index ecfc45b..62d855d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java
@@ -42,6 +42,7 @@
import com.android.internal.telephony.IccCardConstants;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
+import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.dock.DockManager;
@@ -182,7 +183,7 @@
super(context, attrs);
mContext = context;
mUnlockMethodCache = UnlockMethodCache.getInstance(context);
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mAccessibilityController = accessibilityController;
mConfigurationController = configurationController;
mStatusBarStateController = statusBarStateController;
@@ -509,7 +510,7 @@
}
private int getState() {
- KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ KeyguardUpdateMonitor updateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
if ((mUnlockMethodCache.canSkipBouncer() || !mKeyguardShowing
|| mKeyguardMonitor.isKeyguardGoingAway()) && !mSimLocked) {
return STATE_LOCK_OPEN;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
index dcb349b..e34c639 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
@@ -75,7 +75,7 @@
mH = h;
mWallpaperManager = (WallpaperManager) ctx.getSystemService(Context.WALLPAPER_SERVICE);
mCurrentUserId = ActivityManager.getCurrentUser();
- mUpdateMonitor = KeyguardUpdateMonitor.getInstance(ctx);
+ mUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
IWallpaperManager service = IWallpaperManager.Stub.asInterface(
ServiceManager.getService(Context.WALLPAPER_SERVICE));
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index 248bc75..a58ba85 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -421,7 +421,7 @@
});
mThemeResId = context.getThemeResId();
mKeyguardBypassController = bypassController;
- mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
dynamicPrivacyController.addListener(this);
mBottomAreaShadeAlphaAnimator = ValueAnimator.ofFloat(1f, 0);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
index 5733d4b..8c95b84 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
@@ -198,7 +198,7 @@
mContext = scrimBehind.getContext();
mUnlockMethodCache = UnlockMethodCache.getInstance(mContext);
mDarkenWhileDragging = !mUnlockMethodCache.canSkipBouncer();
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mKeyguardVisibilityCallback = new KeyguardVisibilityCallback();
mKeyguardUpdateMonitor.registerCallback(mKeyguardVisibilityCallback);
mScrimBehindAlphaResValue = mContext.getResources().getFloat(R.dimen.scrim_behind_alpha);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index 1c85724..fe96ef7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -701,7 +701,7 @@
mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mKeyguardUpdateMonitor.setKeyguardBypassController(mKeyguardBypassController);
mBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService(Context.STATUS_BAR_SERVICE));
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
index ccb85fa..50c3561 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
@@ -193,7 +193,7 @@
mViewMediatorCallback = callback;
mLockPatternUtils = lockPatternUtils;
mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);
- KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateMonitorCallback);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mUpdateMonitorCallback);
mStatusBarStateController.addCallback(this);
Dependency.get(ConfigurationController.class).addCallback(this);
mGesturalNav = QuickStepContract.isGesturalMode(
@@ -395,7 +395,7 @@
} else {
showBouncerOrKeyguard(hideBouncerWhenShowing);
}
- KeyguardUpdateMonitor.getInstance(mContext).sendKeyguardReset();
+ Dependency.get(KeyguardUpdateMonitor.class).sendKeyguardReset();
updateStates();
}
}
@@ -533,7 +533,7 @@
mShowing, mKeyguardMonitor.isSecure(), mKeyguardMonitor.isOccluded());
launchPendingWakeupAction();
- if (KeyguardUpdateMonitor.getInstance(mContext).needsSlowUnlockTransition()) {
+ if (Dependency.get(KeyguardUpdateMonitor.class).needsSlowUnlockTransition()) {
fadeoutDuration = KEYGUARD_DISMISS_DURATION_LOCKED;
}
long uptimeMillis = SystemClock.uptimeMillis();
@@ -785,7 +785,7 @@
updateLockIcon();
}
- KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ KeyguardUpdateMonitor updateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
if ((showing && !occluded) != (mLastShowing && !mLastOccluded) || mFirstUpdate) {
updateMonitor.onKeyguardVisibilityChanged(showing && !occluded);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
index a870590..d8b2239 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
@@ -240,7 +240,7 @@
public void onDensityOrFontScaleChanged() {
MessagingMessage.dropCache();
MessagingGroup.dropCache();
- if (!KeyguardUpdateMonitor.getInstance(mContext).isSwitchingUser()) {
+ if (!Dependency.get(KeyguardUpdateMonitor.class).isSwitchingUser()) {
updateNotificationsOnDensityOrFontScaleChanged();
} else {
mReinflateNotificationsOnUserSwitched = true;
@@ -249,7 +249,7 @@
@Override
public void onUiModeChanged() {
- if (!KeyguardUpdateMonitor.getInstance(mContext).isSwitchingUser()) {
+ if (!Dependency.get(KeyguardUpdateMonitor.class).isSwitchingUser()) {
updateNotificationOnUiModeChanged();
} else {
mDispatchUiModeChangeOnUserSwitched = true;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java
index 24ecd14..c76f93e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java
@@ -28,6 +28,7 @@
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.DejankUtils;
+import com.android.systemui.Dependency;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -57,8 +58,8 @@
private UnlockMethodCache(Context ctx) {
mLockPatternUtils = new LockPatternUtils(ctx);
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(ctx);
- KeyguardUpdateMonitor.getInstance(ctx).registerCallback(mCallback);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
+ Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mCallback);
update(true /* updateAlways */);
if (Build.IS_DEBUGGABLE && DEBUG_AUTH_WITH_ADB) {
// Watch for interesting updates
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java
index f2c0434..353d6a4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java
@@ -32,6 +32,7 @@
import com.android.internal.telephony.TelephonyIntents;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
+import com.android.systemui.Dependency;
import java.util.List;
@@ -66,7 +67,7 @@
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mKeyguardUpdateMonitor.registerCallback(mCallback);
getContext().registerReceiver(mReceiver,
new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitorImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitorImpl.java
index 87ed14a..a950626 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitorImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitorImpl.java
@@ -23,6 +23,7 @@
import com.android.internal.util.Preconditions;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
+import com.android.systemui.Dependency;
import com.android.systemui.settings.CurrentUserTracker;
import java.util.ArrayList;
@@ -61,7 +62,7 @@
@Inject
public KeyguardMonitorImpl(Context context) {
mContext = context;
- mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
+ mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
mUserTracker = new CurrentUserTracker(mContext) {
@Override
public void onUserSwitched(int newUserId) {
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java
index 1ae1b97..21f6b67 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java
@@ -111,6 +111,7 @@
mDependency.injectMockDependency(WakefulnessLifecycle.class);
mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
new Handler(mTestableLooper.getLooper()));
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("",
new CharSequence[]{}, false, new int[]{});
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewTest.java
index a69fd56..25f279b 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewTest.java
@@ -39,6 +39,7 @@
@Before
public void setup() {
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
mKeyguardHostView = new KeyguardHostView(getContext());
}
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewTest.kt
index 5f03bdb..22e10206 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewTest.kt
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewTest.kt
@@ -41,6 +41,7 @@
@Before
fun setup() {
val inflater = LayoutInflater.from(context)
+ mDependency.injectMockDependency(KeyguardUpdateMonitor::class.java)
mKeyguardPatternView = inflater.inflate(R.layout.keyguard_pattern_view, null)
as KeyguardPatternView
mSecurityMessage = KeyguardMessageArea(mContext, null,
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java
index eadb1b6..b2a4281 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java
@@ -52,6 +52,7 @@
@Before
public void setup() {
LayoutInflater inflater = LayoutInflater.from(getContext());
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
mKeyguardPinView =
(KeyguardPinBasedInputView) inflater.inflate(R.layout.keyguard_pin_view, null);
MockitoAnnotations.initMocks(this);
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java
index 8138420..082782d 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java
@@ -36,6 +36,7 @@
public class KeyguardPresentationTest extends SysuiTestCase {
@Test
public void testInflation_doesntCrash() {
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
InjectionInflationController inflationController = new InjectionInflationController(
SystemUIFactory.getInstance().getRootComponent());
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
index 31ea39c..8da5306 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
@@ -50,6 +50,7 @@
@Before
public void setUp() {
Assert.sMainLooper = TestableLooper.get(this).getLooper();
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
InjectionInflationController inflationController = new InjectionInflationController(
SystemUIFactory.getInstance().getRootComponent());
LayoutInflater layoutInflater = inflationController
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
index fce79c3..ad7bba1 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
@@ -51,7 +51,6 @@
import android.testing.AndroidTestingRunner;
import android.testing.TestableContext;
import android.testing.TestableLooper;
-import android.testing.TestableLooper.RunWithLooper;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.PhoneConstants;
@@ -72,12 +71,7 @@
@SmallTest
@RunWith(AndroidTestingRunner.class)
-// We must run on the main looper because KeyguardUpdateMonitor#mHandler is initialized with
-// new Handler(Looper.getMainLooper()).
-//
-// Using the main looper should be avoided whenever possible, please don't copy this over to
-// new tests.
-@RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class KeyguardUpdateMonitorTest extends SysuiTestCase {
private static final String TEST_CARRIER = "TEST_CARRIER";
private static final String TEST_CARRIER_2 = "TEST_CARRIER_2";
@@ -501,7 +495,7 @@
AtomicBoolean mSimStateChanged = new AtomicBoolean(false);
protected TestableKeyguardUpdateMonitor(Context context) {
- super(context);
+ super(context, TestableLooper.get(KeyguardUpdateMonitorTest.this).getLooper());
context.unregisterReceiver(mBroadcastReceiver);
context.unregisterReceiver(mBroadcastAllReceiver);
mStrongAuthTracker = KeyguardUpdateMonitorTest.this.mStrongAuthTracker;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
index e07d17f..a07f25a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
@@ -29,6 +29,7 @@
import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.SmallTest;
+import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.statusbar.NotificationTestHelper;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.util.Assert;
@@ -48,6 +49,7 @@
@Before
public void setUp() throws Exception {
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
Assert.sMainLooper = TestableLooper.get(this).getLooper();
Context context = getContext();
mRow = new NotificationTestHelper(context).createRow();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java
index e4f33e2..94ca9e9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java
@@ -29,7 +29,8 @@
import androidx.test.InstrumentationRegistry;
-import com.android.keyguard.KeyguardUpdateMonitor;
+import com.android.systemui.classifier.FalsingManagerFake;
+import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.util.Assert;
import org.junit.After;
@@ -74,7 +75,9 @@
"SysUI Tests should use SysuiTestCase#getContext or SysuiTestCase#mContext");
});
InstrumentationRegistry.registerInstance(inst, InstrumentationRegistry.getArguments());
- KeyguardUpdateMonitor.disableHandlerCheckForTesting(inst);
+ // A lot of tests get the FalsingManager, often via several layers of indirection.
+ // None of them actually need it.
+ mDependency.injectTestDependency(FalsingManager.class, new FalsingManagerFake());
}
@After
diff --git a/packages/SystemUI/tests/src/com/android/systemui/assist/AssistHandleBehaviorControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/assist/AssistHandleBehaviorControllerTest.java
index a583b1c..6db5ef9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/assist/AssistHandleBehaviorControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/assist/AssistHandleBehaviorControllerTest.java
@@ -37,6 +37,7 @@
import com.android.internal.app.AssistUtils;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
+import com.android.systemui.DumpController;
import com.android.systemui.ScreenDecorations;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
@@ -70,6 +71,7 @@
MockitoAnnotations.initMocks(this);
mDependency.injectMockDependency(StatusBarStateController.class);
mDependency.injectMockDependency(OverviewProxyService.class);
+ mDependency.injectMockDependency(DumpController.class);
doAnswer(answerVoid(Runnable::run)).when(mMockHandler).post(any(Runnable.class));
doAnswer(answerVoid(Runnable::run)).when(mMockHandler)
.postDelayed(any(Runnable.class), anyLong());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/classifier/FalsingManagerProxyTest.java b/packages/SystemUI/tests/src/com/android/systemui/classifier/FalsingManagerProxyTest.java
index 2073ae1..e1457ef 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/classifier/FalsingManagerProxyTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/classifier/FalsingManagerProxyTest.java
@@ -28,6 +28,7 @@
import androidx.test.filters.SmallTest;
+import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.classifier.brightline.BrightLineFalsingManager;
import com.android.systemui.shared.plugins.PluginManager;
@@ -55,6 +56,7 @@
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
mTestableLooper = TestableLooper.get(this);
mHandler = new Handler(mTestableLooper.getLooper());
mDeviceConfig = new DeviceConfigProxyFake();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
index 9576cb2..c9b6790 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
@@ -54,6 +54,7 @@
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.util.wakelock.SettableWakeLock;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -85,15 +86,15 @@
@Mock
private SettableWakeLock mMediaWakeLock;
@Mock
- private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
- @Mock
private DozeParameters mDozeParameters;
+ private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private TestableKeyguardSliceProvider mProvider;
private boolean mIsZenMode;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
+ mKeyguardUpdateMonitor = mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
mIsZenMode = false;
mProvider = new TestableKeyguardSliceProvider();
mProvider.attachInfo(getContext(), null);
@@ -102,6 +103,11 @@
SliceProvider.setSpecs(new HashSet<>(Arrays.asList(SliceSpecs.LIST)));
}
+ @After
+ public void tearDown() {
+ mProvider.onDestroy();
+ }
+
@Test
public void registersClockUpdate() {
Assert.assertTrue("registerClockUpdate should have been called during initialization.",
@@ -269,11 +275,6 @@
}
@Override
- public KeyguardUpdateMonitor getKeyguardUpdateMonitor() {
- return mKeyguardUpdateMonitor;
- }
-
- @Override
protected String getFormattedDateLocked() {
return super.getFormattedDateLocked() + mCounter++;
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java
index 690133a..a0a410d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java
@@ -24,6 +24,7 @@
import androidx.test.filters.SmallTest;
+import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.Dependency;
import com.android.systemui.InitController;
import com.android.systemui.SysuiTestCase;
@@ -66,6 +67,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
new Handler(TestableLooper.get(this).getLooper()));
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
index cd60e47..c51263f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
@@ -95,6 +95,7 @@
public void setup() {
com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
MockitoAnnotations.initMocks(this);
+ mDependency.injectTestDependency(KeyguardUpdateMonitor.class, mKeyguardUpdateMonitor);
DejankUtils.setImmediate(true);
final ViewGroup container = new FrameLayout(getContext());
when(mKeyguardHostView.getViewTreeObserver()).thenReturn(mViewTreeObserver);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
index c5d4019..2623b46 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
@@ -45,6 +45,7 @@
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.util.function.TriConsumer;
+import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
@@ -91,6 +92,7 @@
mAlwaysOnEnabled = true;
mDozeParamenters = mock(DozeParameters.class);
mLooper = TestableLooper.get(this);
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
when(mDozeParamenters.getAlwaysOn()).thenAnswer(invocation -> mAlwaysOnEnabled);
when(mDozeParamenters.getDisplayNeedsBlanking()).thenReturn(true);
mScrimController = new SynchronousScrimController(mScrimBehind, mScrimInFront,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
index 63f653b..3c445c8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
@@ -37,6 +37,7 @@
import androidx.test.filters.SmallTest;
import com.android.internal.widget.LockPatternUtils;
+import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.ViewMediatorCallback;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.classifier.FalsingManagerFake;
@@ -87,6 +88,7 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mDependency.injectMockDependency(StatusBarWindowController.class);
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
mDependency.injectTestDependency(StatusBarStateController.class, mStatusBarStateController);
when(mLockIconContainer.getParent()).thenReturn(mock(ViewGroup.class));
when(mLockIconContainer.animate()).thenReturn(mock(ViewPropertyAnimator.class,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
index b59bac1..8e3e2db 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
@@ -48,6 +48,7 @@
import androidx.test.filters.SmallTest;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.ActivityStarter;
@@ -112,6 +113,7 @@
mDependency.get(KeyguardDismissUtil.class).setDismissHandler((action, unused) -> {
action.onDismiss();
});
+ mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
mDependency.injectMockDependency(ShadeController.class);
mDependency.injectTestDependency(ActivityStarter.class, mActivityStarter);
mDependency.injectTestDependency(SmartReplyConstants.class, mConstants);