diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index e5f6d3c90eb75..9ba3860f4fb80 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -95,6 +95,7 @@ import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.TaskStackChangeListener; import com.android.systemui.statusbar.phone.KeyguardBypassController; +import com.android.systemui.util.Assert; import com.google.android.collect.Lists; @@ -341,7 +342,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab @Override public void onTrustChanged(boolean enabled, int userId, int flags) { - checkIsHandlerThread(); + Assert.isMainThread(); mUserHasTrust.put(userId, enabled); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -360,7 +361,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleSimSubscriptionInfoChanged() { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG_SIM_STATES) { Log.v(TAG, "onSubscriptionInfoChanged()"); List sil = mSubscriptionManager @@ -403,7 +404,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void callbacksRefreshCarrierInfo() { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -466,7 +467,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab @Override public void onTrustManagedChanged(boolean managed, int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); mUserTrustIsManaged.put(userId, managed); mUserTrustIsUsuallyManaged.put(userId, mTrustManager.isTrustUsuallyManaged(userId)); for (int i = 0; i < mCallbacks.size(); i++) { @@ -523,7 +524,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab @VisibleForTesting protected void onFingerprintAuthenticated(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); Trace.beginSection("KeyGuardUpdateMonitor#onFingerPrintAuthenticated"); mUserFingerprintAuthenticated.put(userId, true); // Update/refresh trust state only if user can skip bouncer @@ -549,7 +550,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleFingerprintAuthFailed() { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -561,7 +562,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleFingerprintAcquired(int acquireInfo) { - checkIsHandlerThread(); + Assert.isMainThread(); if (acquireInfo != FingerprintManager.FINGERPRINT_ACQUIRED_GOOD) { return; } @@ -599,7 +600,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleFingerprintHelp(int msgId, String helpString) { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -618,7 +619,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab }; private void handleFingerprintError(int msgId, String errString) { - checkIsHandlerThread(); + Assert.isMainThread(); if (msgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED && mHandler.hasCallbacks( mCancelNotReceived)) { mHandler.removeCallbacks(mCancelNotReceived); @@ -671,7 +672,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void notifyFingerprintRunningStateChanged() { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -684,7 +685,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab @VisibleForTesting protected void onFaceAuthenticated(int userId) { Trace.beginSection("KeyGuardUpdateMonitor#onFaceAuthenticated"); - checkIsHandlerThread(); + Assert.isMainThread(); mUserFaceAuthenticated.put(userId, true); // Update/refresh trust state only if user can skip bouncer if (getUserCanSkipBouncer(userId)) { @@ -710,7 +711,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleFaceAuthFailed() { - checkIsHandlerThread(); + Assert.isMainThread(); setFaceRunningState(BIOMETRIC_STATE_STOPPED); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -723,7 +724,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleFaceAcquired(int acquireInfo) { - checkIsHandlerThread(); + Assert.isMainThread(); if (acquireInfo != FaceManager.FACE_ACQUIRED_GOOD) { return; } @@ -767,7 +768,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleFaceHelp(int msgId, String helpString) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG_FACE) Log.d(TAG, "Face help received: " + helpString); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -787,7 +788,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab }; private void handleFaceError(int msgId, String errString) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG_FACE) Log.d(TAG, "Face error received: " + errString); if (msgId == FaceManager.FACE_ERROR_CANCELED && mHandler.hasCallbacks(mCancelNotReceived)) { mHandler.removeCallbacks(mCancelNotReceived); @@ -842,7 +843,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void notifyFaceRunningStateChanged() { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -853,7 +854,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleFaceUnlockStateChanged(boolean running, int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); mUserFaceUnlockRunning.put(userId, running); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -965,7 +966,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Cached version of {@link TrustManager#isTrustUsuallyManaged(int)}. */ public boolean isTrustUsuallyManaged(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); return mUserTrustIsUsuallyManaged.get(userId); } @@ -996,7 +997,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void notifyStrongAuthStateChanged(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -1010,7 +1011,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void dispatchErrorMessage(CharSequence message) { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -1323,7 +1324,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab protected void handleStartedWakingUp() { Trace.beginSection("KeyguardUpdateMonitor#handleStartedWakingUp"); - checkIsHandlerThread(); + Assert.isMainThread(); updateBiometricListeningState(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -1335,7 +1336,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } protected void handleStartedGoingToSleep(int arg1) { - checkIsHandlerThread(); + Assert.isMainThread(); mLockIconPressed = false; clearBiometricRecognized(); for (int i = 0; i < mCallbacks.size(); i++) { @@ -1349,7 +1350,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } protected void handleFinishedGoingToSleep(int arg1) { - checkIsHandlerThread(); + Assert.isMainThread(); mGoingToSleep = false; for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -1361,7 +1362,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleScreenTurnedOn() { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -1373,7 +1374,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab private void handleScreenTurnedOff() { final String tag = "KeyguardUpdateMonitor#handleScreenTurnedOff"; DejankUtils.startDetectingBlockingIpcs(tag); - checkIsHandlerThread(); + Assert.isMainThread(); mHardwareFingerprintUnavailableRetryCount = 0; mHardwareFaceUnavailableRetryCount = 0; for (int i = 0; i < mCallbacks.size(); i++) { @@ -1386,7 +1387,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleDreamingStateChanged(int dreamStart) { - checkIsHandlerThread(); + Assert.isMainThread(); mIsDreaming = dreamStart == 1; for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -1398,7 +1399,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleUserInfoChanged(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -1408,7 +1409,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleUserUnlocked(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); mUserIsUnlocked.put(userId, true); mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); for (int i = 0; i < mCallbacks.size(); i++) { @@ -1420,20 +1421,22 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void handleUserStopped(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); mUserIsUnlocked.put(userId, mUserManager.isUserUnlocked(userId)); } @VisibleForTesting void handleUserRemoved(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); mUserIsUnlocked.delete(userId); mUserTrustIsUsuallyManaged.delete(userId); } @VisibleForTesting @Inject - protected KeyguardUpdateMonitor(Context context, @Main Looper mainLooper, + protected KeyguardUpdateMonitor( + Context context, + @Main Looper mainLooper, BroadcastDispatcher broadcastDispatcher, DumpController dumpController) { mContext = context; @@ -1962,7 +1965,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * @param hasLockscreenWallpaper Whether Keyguard has a lockscreen wallpaper. */ public void setHasLockscreenWallpaper(boolean hasLockscreenWallpaper) { - checkIsHandlerThread(); + Assert.isMainThread(); if (hasLockscreenWallpaper != mHasLockscreenWallpaper) { mHasLockscreenWallpaper = hasLockscreenWallpaper; for (int i = 0; i < mCallbacks.size(); i++) { @@ -1985,7 +1988,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_DPM_STATE_CHANGED} */ private void handleDevicePolicyManagerStateChanged(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); updateFingerprintListeningState(); updateSecondaryLockscreenRequirement(userId); for (int i = 0; i < mCallbacks.size(); i++) { @@ -2000,7 +2003,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_USER_SWITCHING} */ private void handleUserSwitching(int userId, IRemoteCallback reply) { - checkIsHandlerThread(); + Assert.isMainThread(); mUserTrustIsUsuallyManaged.put(userId, mTrustManager.isTrustUsuallyManaged(userId)); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -2018,7 +2021,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_USER_SWITCH_COMPLETE} */ private void handleUserSwitchComplete(int userId) { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -2031,7 +2034,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_DEVICE_PROVISIONED} */ private void handleDeviceProvisioned() { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -2049,7 +2052,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_PHONE_STATE_CHANGED} */ private void handlePhoneStateChanged(String newState) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG) Log.d(TAG, "handlePhoneStateChanged(" + newState + ")"); if (TelephonyManager.EXTRA_STATE_IDLE.equals(newState)) { mPhoneState = TelephonyManager.CALL_STATE_IDLE; @@ -2070,7 +2073,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_RINGER_MODE_CHANGED} */ private void handleRingerModeChange(int mode) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG) Log.d(TAG, "handleRingerModeChange(" + mode + ")"); mRingMode = mode; for (int i = 0; i < mCallbacks.size(); i++) { @@ -2085,7 +2088,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_TIME_UPDATE} */ private void handleTimeUpdate() { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG) Log.d(TAG, "handleTimeUpdate"); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -2099,7 +2102,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle (@line #MSG_TIMEZONE_UPDATE} */ private void handleTimeZoneUpdate(String timeZone) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG) Log.d(TAG, "handleTimeZoneUpdate"); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -2115,7 +2118,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_BATTERY_UPDATE} */ private void handleBatteryUpdate(BatteryStatus status) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG) Log.d(TAG, "handleBatteryUpdate"); final boolean batteryUpdateInteresting = isBatteryUpdateInteresting(mBatteryStatus, status); mBatteryStatus = status; @@ -2134,7 +2137,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab */ @VisibleForTesting void updateTelephonyCapable(boolean capable) { - checkIsHandlerThread(); + Assert.isMainThread(); if (capable == mTelephonyCapable) { return; } @@ -2152,7 +2155,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab */ @VisibleForTesting void handleSimStateChange(int subId, int slotId, int state) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG_SIM_STATES) { Log.d(TAG, "handleSimStateChange(subId=" + subId + ", slotId=" + slotId + ", state=" + state + ")"); @@ -2236,7 +2239,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab *

Needs to be called from the main thread. */ public void onKeyguardVisibilityChanged(boolean showing) { - checkIsHandlerThread(); + Assert.isMainThread(); Log.d(TAG, "onKeyguardVisibilityChanged(" + showing + ")"); mKeyguardIsVisible = showing; @@ -2279,7 +2282,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * @see #sendKeyguardBouncerChanged(boolean) */ private void handleKeyguardBouncerChanged(int bouncer) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG) Log.d(TAG, "handleKeyguardBouncerChanged(" + bouncer + ")"); boolean isBouncer = (bouncer == 1); mBouncer = isBouncer; @@ -2305,7 +2308,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * Handle {@link #MSG_REPORT_EMERGENCY_CALL_ACTION} */ private void handleReportEmergencyCallAction() { - checkIsHandlerThread(); + Assert.isMainThread(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -2344,7 +2347,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * @param callback The callback to remove */ public void removeCallback(KeyguardUpdateMonitorCallback callback) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG) { Log.v(TAG, "*** unregister callback for " + callback); } @@ -2359,7 +2362,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * @param callback The callback to register */ public void registerCallback(KeyguardUpdateMonitorCallback callback) { - checkIsHandlerThread(); + Assert.isMainThread(); if (DEBUG) Log.v(TAG, "*** register callback for " + callback); // Prevent adding duplicate callbacks @@ -2448,7 +2451,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab if (!bypassHandler) { mHandler.obtainMessage(MSG_REPORT_EMERGENCY_CALL_ACTION).sendToTarget(); } else { - checkIsHandlerThread(); + Assert.isMainThread(); handleReportEmergencyCallAction(); } } @@ -2466,7 +2469,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } public void clearBiometricRecognized() { - checkIsHandlerThread(); + Assert.isMainThread(); mUserFingerprintAuthenticated.clear(); mUserFaceAuthenticated.clear(); mTrustManager.clearAllBiometricRecognized(BiometricSourceType.FINGERPRINT); @@ -2653,7 +2656,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private void updateLogoutEnabled() { - checkIsHandlerThread(); + Assert.isMainThread(); boolean logoutEnabled = mDevicePolicyManager.isLogoutEnabled(); if (mLogoutEnabled != logoutEnabled) { mLogoutEnabled = logoutEnabled; @@ -2667,13 +2670,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } } - private void checkIsHandlerThread() { - if (!mHandler.getLooper().isCurrentThread()) { - Log.wtfStack(TAG, "must call on mHandler's thread " - + mHandler.getLooper().getThread() + ", not " + Thread.currentThread()); - } - } - @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("KeyguardUpdateMonitor state:"); diff --git a/packages/SystemUI/src/com/android/systemui/util/Assert.java b/packages/SystemUI/src/com/android/systemui/util/Assert.java index f6e921e628ba7..3f05657ed09ec 100644 --- a/packages/SystemUI/src/com/android/systemui/util/Assert.java +++ b/packages/SystemUI/src/com/android/systemui/util/Assert.java @@ -24,12 +24,17 @@ import androidx.annotation.VisibleForTesting; * Helper providing common assertions. */ public class Assert { + private static final Looper sMainLooper = Looper.getMainLooper(); + private static Looper sTestLooper = null; @VisibleForTesting - public static Looper sMainLooper = Looper.getMainLooper(); + public static void setTestableLooper(Looper testLooper) { + sTestLooper = testLooper; + } public static void isMainThread() { - if (!sMainLooper.isCurrentThread()) { + if (!sMainLooper.isCurrentThread() + && (sTestLooper == null || !sTestLooper.isCurrentThread())) { throw new IllegalStateException("should be called from the main thread." + " sMainLooper.threadName=" + sMainLooper.getThread().getName() + " Thread.currentThread()=" + Thread.currentThread().getName()); @@ -37,7 +42,8 @@ public class Assert { } public static void isNotMainThread() { - if (sMainLooper.isCurrentThread()) { + if (sMainLooper.isCurrentThread() + && (sTestLooper == null || sTestLooper.isCurrentThread())) { throw new IllegalStateException("should not be called from the main thread."); } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java index 082782d3092a0..b6ca8d8e4afb4 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPresentationTest.java @@ -37,7 +37,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(); + allowTestableLooperAsMainThread(); InjectionInflationController inflationController = new InjectionInflationController( SystemUIFactory.getInstance().getRootComponent()); Context context = getContext(); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java index 116f8fc7d3eb2..462b0421e1edd 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java @@ -19,7 +19,6 @@ import android.graphics.Color; import android.net.Uri; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.LayoutInflater; @@ -51,7 +50,7 @@ public class KeyguardSliceViewTest extends SysuiTestCase { @Before public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); InjectionInflationController inflationController = new InjectionInflationController( SystemUIFactory.getInstance().getRootComponent()); LayoutInflater layoutInflater = inflationController diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java index e4b83ccc5125d..bc3c3d995ce68 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java @@ -20,14 +20,12 @@ import static org.mockito.Mockito.verify; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.LayoutInflater; import com.android.systemui.R; import com.android.systemui.SystemUIFactory; import com.android.systemui.SysuiTestCase; -import com.android.systemui.util.Assert; import com.android.systemui.util.InjectionInflationController; import org.junit.Before; @@ -50,7 +48,7 @@ public class KeyguardStatusViewTest extends SysuiTestCase { @Before public void setUp() { - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mDependency.injectMockDependency(KeyguardUpdateMonitor.class); InjectionInflationController inflationController = new InjectionInflationController( SystemUIFactory.getInstance().getRootComponent()); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index 7e4ba92301aa3..befe3e12b64e6 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -147,6 +147,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { context.addMockSystemService(SubscriptionManager.class, mSubscriptionManager); mTestableLooper = TestableLooper.get(this); + allowTestableLooperAsMainThread(); mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(context); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java index ffe8c285b4f1d..471149c936e46 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.when; import android.animation.ObjectAnimator; import android.content.Context; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import androidx.test.annotation.UiThreadTest; @@ -33,7 +32,6 @@ import com.android.keyguard.KeyguardUpdateMonitor; import com.android.systemui.statusbar.NotificationMediaManager; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.NotificationTestHelper; -import com.android.systemui.util.Assert; import org.junit.Before; import org.junit.Test; @@ -52,7 +50,7 @@ public class ExpandHelperTest extends SysuiTestCase { public void setUp() throws Exception { mDependency.injectMockDependency(KeyguardUpdateMonitor.class); mDependency.injectMockDependency(NotificationMediaManager.class); - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); Context context = getContext(); mRow = new NotificationTestHelper(context, mDependency).createRow(); mCallback = mock(ExpandHelper.Callback.class); diff --git a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java index 8d11b54dacb27..c912b678ac095 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java @@ -35,7 +35,6 @@ import android.app.Notification; import android.app.NotificationManager; import android.os.Bundle; import android.os.Handler; -import android.os.Looper; import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.testing.AndroidTestingRunner; @@ -75,8 +74,8 @@ public class ForegroundServiceControllerTest extends SysuiTestCase { @Before public void setUp() throws Exception { - // assume the TestLooper is the main looper for these tests - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + // allow the TestLooper to be asserted as the main thread these tests + allowTestableLooperAsMainThread(); MockitoAnnotations.initMocks(this); mFsc = new ForegroundServiceController(mEntryManager, mAppOpsController, mMainHandler); @@ -93,7 +92,7 @@ public class ForegroundServiceControllerTest extends SysuiTestCase { public void testAppOpsChangedCalledFromBgThread() { try { // WHEN onAppOpChanged is called from a different thread than the MainLooper - com.android.systemui.util.Assert.sMainLooper = Looper.getMainLooper(); + disallowTestableLooperAsMainThread(); NotificationEntry entry = createFgEntry(); mFsc.onAppOpChanged( AppOpsManager.OP_CAMERA, diff --git a/packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java b/packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java index fc331d6adccc6..689eed9e2a61a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java @@ -77,7 +77,7 @@ public class ImageWallpaperTest extends SysuiTestCase { @Before public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); MockitoAnnotations.initMocks(this); mEventCountdown = new CountDownLatch(1); diff --git a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java index c85d600e84478..7ac5443d67d04 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java +++ b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java @@ -25,6 +25,7 @@ import android.os.MessageQueue; import android.os.ParcelFileDescriptor; import android.testing.DexmakerShareClassLoaderRule; import android.testing.LeakCheck; +import android.testing.TestableLooper; import android.util.Log; import androidx.test.InstrumentationRegistry; @@ -32,7 +33,6 @@ 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; import org.junit.Before; @@ -86,11 +86,24 @@ public abstract class SysuiTestCase { public void SysuiTeardown() { InstrumentationRegistry.registerInstance(mRealInstrumentation, InstrumentationRegistry.getArguments()); - // Reset the assert's main looper. - Assert.sMainLooper = Looper.getMainLooper(); + // Reset the assert's testable looper to null. + disallowTestableLooperAsMainThread(); SystemUIFactory.cleanup(); } + /** + * Tests are run on the TestableLooper; however, there are parts of SystemUI that assert that + * the code is run from the main looper. Therefore, we allow the TestableLooper to pass these + * assertions since in a test, the TestableLooper is essentially the MainLooper. + */ + protected void allowTestableLooperAsMainThread() { + com.android.systemui.util.Assert.setTestableLooper(TestableLooper.get(this).getLooper()); + } + + protected void disallowTestableLooperAsMainThread() { + com.android.systemui.util.Assert.setTestableLooper(null); + } + protected LeakCheck getLeakCheck() { return null; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java index 60163f26bb2b4..8e87e0a802ef4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java @@ -54,7 +54,6 @@ import com.android.systemui.statusbar.notification.stack.ForegroundServiceSectio import com.android.systemui.statusbar.notification.stack.NotificationListContainer; import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.phone.NotificationGroupManager; -import com.android.systemui.util.Assert; import com.google.android.collect.Lists; @@ -90,7 +89,7 @@ public class NotificationViewHierarchyManagerTest extends SysuiTestCase { public void setUp() { MockitoAnnotations.initMocks(this); mTestableLooper = TestableLooper.get(this); - Assert.sMainLooper = mTestableLooper.getLooper(); + allowTestableLooperAsMainThread(); mHandler = Handler.createAsync(mTestableLooper.getLooper()); mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java index 9d667a9a91c82..0a38f163cfba5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java @@ -21,7 +21,6 @@ import static org.mockito.Mockito.verify; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.widget.FrameLayout; @@ -46,7 +45,7 @@ public class AboveShelfObserverTest extends SysuiTestCase { @Before public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mNotificationTestHelper = new NotificationTestHelper(getContext(), mDependency); mHostLayout = new FrameLayout(getContext()); mObserver = new AboveShelfObserver(mHostLayout); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java index f1fba792a882d..0b17d1cf84bf1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java @@ -98,7 +98,6 @@ import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.phone.NotificationGroupManager; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.HeadsUpManager; -import com.android.systemui.util.Assert; import com.android.systemui.util.leak.LeakDetector; import com.android.systemui.util.time.FakeSystemClock; @@ -205,7 +204,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase { mCountDownLatch = new CountDownLatch(1); - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mDependency.injectTestDependency(Dependency.MAIN_HANDLER, Handler.createAsync(TestableLooper.get(this).getLooper())); when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationFilterTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationFilterTest.java index 1116a333125ef..97e0a3199e17b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationFilterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationFilterTest.java @@ -32,7 +32,6 @@ import android.content.pm.PackageManager; import android.os.Bundle; import android.service.notification.StatusBarNotification; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import androidx.test.annotation.UiThreadTest; @@ -79,7 +78,7 @@ public class NotificationFilterTest extends SysuiTestCase { @Before public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); MockitoAnnotations.initMocks(this); when(mMockStatusBarNotification.getUid()).thenReturn(UID_NORMAL); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java index 12e9d31fdd0c1..605b59ef3974e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java @@ -77,7 +77,6 @@ import com.android.systemui.statusbar.notification.collection.notifcollection.No import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionLogger; import com.android.systemui.statusbar.notification.collection.notifcollection.NotifDismissInterceptor; import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender; -import com.android.systemui.util.Assert; import org.junit.Before; import org.junit.Test; @@ -129,7 +128,7 @@ public class NotifCollectionTest extends SysuiTestCase { @Before public void setUp() { MockitoAnnotations.initMocks(this); - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); when(mFeatureFlags.isNewNotifPipelineRenderingEnabled()).thenReturn(true); when(mFeatureFlags.isNewNotifPipelineEnabled()).thenReturn(true); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java index 27ca18cd80339..e570ab8d7f417 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java @@ -51,7 +51,6 @@ import com.android.systemui.statusbar.notification.collection.listbuilder.plugga import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifPromoter; import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSection; import com.android.systemui.statusbar.notification.collection.notifcollection.CollectionReadyForBuildListener; -import com.android.systemui.util.Assert; import com.android.systemui.util.time.FakeSystemClock; import org.junit.Before; @@ -101,7 +100,7 @@ public class ShadeListBuilderTest extends SysuiTestCase { @Before public void setUp() { MockitoAnnotations.initMocks(this); - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mListBuilder = new ShadeListBuilder(mSystemClock, mLogger, mock(DumpController.class)); mListBuilder.setOnRenderListListener(mOnRenderListListener); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ForegroundCoordinatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ForegroundCoordinatorTest.java index eb1af7c82324d..67b1aad94f518 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ForegroundCoordinatorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ForegroundCoordinatorTest.java @@ -44,7 +44,6 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter; import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender; -import com.android.systemui.util.Assert; import com.android.systemui.util.concurrency.FakeExecutor; import com.android.systemui.util.time.FakeSystemClock; @@ -84,7 +83,7 @@ public class ForegroundCoordinatorTest extends SysuiTestCase { @Before public void setup() { MockitoAnnotations.initMocks(this); - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mForegroundCoordinator = new ForegroundCoordinator( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java index a8918103c4a21..e960185ebe3a2 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java @@ -39,7 +39,6 @@ import static org.mockito.Mockito.when; import android.app.AppOpsManager; import android.app.NotificationChannel; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.util.ArraySet; import android.view.NotificationHeaderView; @@ -79,7 +78,7 @@ public class ExpandableNotificationRowTest extends SysuiTestCase { @Before public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mNotificationTestHelper = new NotificationTestHelper(mContext, mDependency); mGroupRow = mNotificationTestHelper.createGroup(); mGroupRow.setHeadsUpAnimatingAwayListener( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java index a8c438a390ef5..481bac2c19c66 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java @@ -49,7 +49,6 @@ import com.android.systemui.SysuiTestCase; import com.android.systemui.bubbles.BubbleController; import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; import com.android.systemui.statusbar.notification.NotificationEntryManager; -import com.android.systemui.util.Assert; import org.junit.Before; import org.junit.Test; @@ -75,7 +74,7 @@ public class NotificationBlockingHelperManagerTest extends SysuiTestCase { @Before public void setUp() { - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); MockitoAnnotations.initMocks(this); mDependency.injectMockDependency(BubbleController.class); when(mGutsManager.openGuts( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java index bbb6723135a61..54c0bde134087 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java @@ -74,7 +74,6 @@ import com.android.systemui.statusbar.notification.row.NotificationGutsManager.O import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.policy.DeviceProvisionedController; -import com.android.systemui.util.Assert; import org.junit.Before; import org.junit.Ignore; @@ -118,7 +117,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase { @Before public void setUp() { mTestableLooper = TestableLooper.get(this); - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mDependency.injectTestDependency(DeviceProvisionedController.class, mDeviceProvisionedController); mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java index 0790cb7ca6c48..b661b28c42fc5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java @@ -17,7 +17,6 @@ package com.android.systemui.statusbar.notification.row.wrapper; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.View; import android.widget.RemoteViews; @@ -43,7 +42,7 @@ public class NotificationCustomViewWrapperTest extends SysuiTestCase { @Before public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mRow = new NotificationTestHelper(mContext, mDependency).createRow(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapperTest.java index 038eff7fa5dcc..69e4f2205c35e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationMediaTemplateViewWrapperTest.java @@ -26,7 +26,6 @@ import android.media.MediaMetadata; import android.media.session.MediaSession; import android.media.session.PlaybackState; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.View; import android.widget.RemoteViews; @@ -64,7 +63,7 @@ public class NotificationMediaTemplateViewWrapperTest extends SysuiTestCase { @Before public void setUp() { MockitoAnnotations.initMocks(this); - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapperTest.java index 9567f3386dda2..830e8d93196c7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapperTest.java @@ -20,7 +20,6 @@ import static org.mockito.Mockito.mock; import android.content.Context; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.View; import android.widget.LinearLayout; @@ -31,7 +30,6 @@ import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.NotificationTestHelper; -import com.android.systemui.util.Assert; import org.junit.Before; import org.junit.Test; @@ -48,7 +46,7 @@ public class NotificationViewWrapperTest extends SysuiTestCase { @Before public void setup() throws Exception { - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mView = mock(View.class); mRow = new NotificationTestHelper(getContext(), mDependency).createRow(); mNotificationViewWrapper = new TestableNotificationViewWrapper(mContext, mView, mRow); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java index 1773175450ff8..a2029c76bb55a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java @@ -17,7 +17,6 @@ package com.android.systemui.statusbar.notification.stack; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.NotificationHeaderView; import android.view.View; @@ -44,7 +43,7 @@ public class NotificationChildrenContainerTest extends SysuiTestCase { @Before public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mNotificationTestHelper = new NotificationTestHelper(mContext, mDependency); mGroup = mNotificationTestHelper.createGroup(); mChildrenContainer = mGroup.getChildrenContainer(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java index 2d1bc7890aeda..ba2b94677814a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java @@ -24,7 +24,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import androidx.test.filters.SmallTest; @@ -66,7 +65,7 @@ public class NotificationRoundnessManagerTest extends SysuiTestCase { mRoundnessManager = new NotificationRoundnessManager( mBypassController, new NotificationSectionsFeatureManager(new DeviceConfigProxy(), mContext)); - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); NotificationTestHelper testHelper = new NotificationTestHelper(getContext(), mDependency); mFirst = testHelper.createRow(); mFirst.setHeadsUpAnimatingAwayListener(animatingAway diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java index 9ccee75a3d095..d768bc30175f4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java @@ -144,7 +144,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { @Before @UiThreadTest public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); mOriginalInterruptionModelSetting = Settings.Secure.getInt(mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 0); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java index f71d0fc4b43e3..a74657e561aa1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.view.View; import android.widget.TextView; @@ -69,7 +68,7 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { @Before public void setUp() throws Exception { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); NotificationTestHelper testHelper = new NotificationTestHelper(getContext(), mDependency); mFirst = testHelper.createRow(); mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher); 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 67b8e07f2bec1..35971bd4037c2 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 @@ -96,7 +96,7 @@ public class KeyguardBouncerTest extends SysuiTestCase { @Before public void setup() { - com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); MockitoAnnotations.initMocks(this); mDependency.injectTestDependency(KeyguardUpdateMonitor.class, mKeyguardUpdateMonitor); mDependency.injectTestDependency(KeyguardSecurityModel.class, mKeyguardSecurityModel); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java index df622542e22cb..86add98ab929d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java @@ -43,7 +43,6 @@ import com.android.systemui.statusbar.RemoteInputController; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.NotificationTestHelper; import com.android.systemui.statusbar.phone.LightBarController; -import com.android.systemui.util.Assert; import org.junit.After; import org.junit.Before; @@ -74,7 +73,7 @@ public class RemoteInputViewTest extends SysuiTestCase { @Before public void setUp() throws Exception { - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); MockitoAnnotations.initMocks(this); mDependency.injectTestDependency(RemoteInputQuickSettingsDisabler.class, diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java index 20dcbb73c2121..1ff9548486ab5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java @@ -21,14 +21,12 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import android.animation.Animator; -import android.os.Looper; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; -import com.android.systemui.util.Assert; import org.junit.Before; import org.junit.Test; @@ -45,7 +43,7 @@ public class KeepAwakeAnimationListenerTest extends SysuiTestCase { @Before public void setup() { - Assert.sMainLooper = TestableLooper.get(this).getLooper(); + allowTestableLooperAsMainThread(); MockitoAnnotations.initMocks(this); KeepAwakeAnimationListener.sWakeLock = mWakeLock; mKeepAwakeAnimationListener = new KeepAwakeAnimationListener(getContext()); @@ -63,7 +61,10 @@ public class KeepAwakeAnimationListenerTest extends SysuiTestCase { @Test(expected = IllegalStateException.class) public void initThrows_onNonMainThread() { - Assert.sMainLooper = Looper.getMainLooper(); + disallowTestableLooperAsMainThread(); + + // we are creating the KeepAwakeAnimationListener from the TestableLooper, not the main + // looper, so we expect an IllegalStateException: new KeepAwakeAnimationListener(getContext()); } }