Reduce usages of main looper in sysui tests
Push over to a standard testable looper, and a testable looper +
setAsMain when needed.
Also make tests more synchronous and single threaded as possible.
This will make them more deterministic and speeds them up noticeably.
Test: runtest systemui
Bug: 79550837
Change-Id: Iab0eb794329d7b1de95aef904ec08ecae7dadc98
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java
index 0143d01..1303057 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java
@@ -137,9 +137,15 @@
return;
}
StatusBarNotification sbn = mRow.getEntry().notification;
- new AsyncInflationTask(sbn, reInflateFlags, mRow, mIsLowPriority,
+ AsyncInflationTask task = new AsyncInflationTask(sbn, reInflateFlags, mRow,
+ mIsLowPriority,
mIsChildInGroup, mUsesIncreasedHeight, mUsesIncreasedHeadsUpHeight, mRedactAmbient,
- mCallback, mRemoteViewClickHandler).execute();
+ mCallback, mRemoteViewClickHandler);
+ if (mCallback != null && mCallback.doInflateSynchronous()) {
+ task.onPostExecute(task.doInBackground());
+ } else {
+ task.execute();
+ }
}
@VisibleForTesting
@@ -331,6 +337,30 @@
final HashMap<Integer, CancellationSignal> runningInflations,
ApplyCallback applyCallback) {
RemoteViews newContentView = applyCallback.getRemoteView();
+ if (callback != null && callback.doInflateSynchronous()) {
+ try {
+ if (isNewView) {
+ View v = newContentView.apply(
+ result.packageContext,
+ parentLayout,
+ remoteViewClickHandler);
+ v.setIsRootNamespace(true);
+ applyCallback.setResultView(v);
+ } else {
+ newContentView.reapply(
+ result.packageContext,
+ existingView,
+ remoteViewClickHandler);
+ existingWrapper.onReinflated();
+ }
+ } catch (Exception e) {
+ handleInflationError(runningInflations, e, entry.notification, callback);
+ // Add a running inflation to make sure we don't trigger callbacks.
+ // Safe to do because only happens in tests.
+ runningInflations.put(inflationId, new CancellationSignal());
+ }
+ return;
+ }
RemoteViews.OnViewAppliedListener listener
= new RemoteViews.OnViewAppliedListener() {
@@ -515,6 +545,13 @@
public interface InflationCallback {
void handleInflationException(StatusBarNotification notification, Exception e);
void onAsyncInflationFinished(NotificationData.Entry entry);
+
+ /**
+ * Used to disable async-ness for tests. Should only be used for tests.
+ */
+ default boolean doInflateSynchronous() {
+ return false;
+ }
}
public void onDensityOrFontScaleChanged() {
@@ -646,6 +683,11 @@
mRow.onNotificationUpdated();
mCallback.onAsyncInflationFinished(mRow.getEntry());
}
+
+ @Override
+ public boolean doInflateSynchronous() {
+ return mCallback != null && mCallback.doInflateSynchronous();
+ }
}
@VisibleForTesting
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardMessageAreaTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardMessageAreaTest.java
index f3be945..f8ca262 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardMessageAreaTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardMessageAreaTest.java
@@ -20,10 +20,9 @@
import static org.mockito.Mockito.mock;
-import android.os.Handler;
-import android.os.Looper;
-import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import com.android.systemui.SysuiTestCase;
@@ -32,33 +31,25 @@
import org.junit.runner.RunWith;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper
public class KeyguardMessageAreaTest extends SysuiTestCase {
- private Handler mHandler = new Handler(Looper.getMainLooper());
private KeyguardMessageArea mMessageArea;
@Before
public void setUp() throws Exception {
KeyguardUpdateMonitor monitor = mock(KeyguardUpdateMonitor.class);
- mHandler.post(()-> mMessageArea = new KeyguardMessageArea(mContext, null, monitor));
+ mMessageArea = new KeyguardMessageArea(mContext, null, monitor);
waitForIdleSync();
}
@Test
public void clearFollowedByMessage_keepsMessage() {
- mHandler.post(()-> {
- mMessageArea.setMessage("");
- mMessageArea.setMessage("test");
- });
-
- waitForIdleSync();
+ mMessageArea.setMessage("");
+ mMessageArea.setMessage("test");
CharSequence[] messageText = new CharSequence[1];
- mHandler.post(()-> {
- messageText[0] = mMessageArea.getText();
- });
-
- waitForIdleSync();
+ messageText[0] = mMessageArea.getText();
assertEquals("test", messageText[0]);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
index aa840989..08c4235 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
@@ -22,6 +22,8 @@
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;
@@ -35,7 +37,8 @@
import static org.mockito.Mockito.when;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class ExpandHelperTest extends SysuiTestCase {
private ExpandableNotificationRow mRow;
@@ -47,9 +50,7 @@
Context context = getContext();
mRow = new NotificationTestHelper(context).createRow();
mCallback = mock(ExpandHelper.Callback.class);
- InstrumentationRegistry.getInstrumentation().runOnMainSync(
- () -> mExpandHelper = new ExpandHelper(context, mCallback, 10, 100));
-
+ mExpandHelper = new ExpandHelper(context, mCallback, 10, 100);
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
index a8ea1c0..c2da7f5 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
@@ -29,7 +29,8 @@
import android.os.Looper;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.systemui.SysuiTestCase;
@@ -46,7 +47,8 @@
@SmallTest
@Ignore("failing")
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class DozeTriggersTest extends SysuiTestCase {
private DozeTriggers mTriggers;
private DozeMachine mMachine;
@@ -54,7 +56,6 @@
private AmbientDisplayConfiguration mConfig;
private DozeParameters mParameters;
private FakeSensorManager mSensors;
- private Handler mHandler;
private WakeLock mWakeLock;
private Instrumentation mInstrumentation;
private AlarmManager mAlarmManager;
@@ -74,40 +75,29 @@
mConfig = DozeConfigurationUtil.createMockConfig();
mParameters = DozeConfigurationUtil.createMockParameters();
mSensors = new FakeSensorManager(mContext);
- mHandler = new Handler(Looper.getMainLooper());
mWakeLock = new WakeLockFake();
- mInstrumentation.runOnMainSync(() -> {
- mTriggers = new DozeTriggers(mContext, mMachine, mHost, mAlarmManager,
- mConfig, mParameters, mSensors, mHandler, mWakeLock, true);
- });
+ mTriggers = new DozeTriggers(mContext, mMachine, mHost, mAlarmManager, mConfig, mParameters,
+ mSensors, Handler.createAsync(Looper.myLooper()), mWakeLock, true);
}
@Test
public void testOnNotification_stillWorksAfterOneFailedProxCheck() throws Exception {
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
- mInstrumentation.runOnMainSync(()->{
- mTriggers.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
- mTriggers.transitionTo(DozeMachine.State.INITIALIZED, DozeMachine.State.DOZE);
+ mTriggers.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
+ mTriggers.transitionTo(DozeMachine.State.INITIALIZED, DozeMachine.State.DOZE);
- mHost.callback.onNotificationHeadsUp();
- });
+ mHost.callback.onNotificationHeadsUp();
- mInstrumentation.runOnMainSync(() -> {
- mSensors.getMockProximitySensor().sendProximityResult(false); /* Near */
- });
+ mSensors.getMockProximitySensor().sendProximityResult(false); /* Near */
verify(mMachine, never()).requestState(any());
verify(mMachine, never()).requestPulse(anyInt());
- mInstrumentation.runOnMainSync(()->{
- mHost.callback.onNotificationHeadsUp();
- });
+ mHost.callback.onNotificationHeadsUp();
- mInstrumentation.runOnMainSync(() -> {
- mSensors.getMockProximitySensor().sendProximityResult(true); /* Far */
- });
+ mSensors.getMockProximitySensor().sendProximityResult(true); /* Far */
verify(mMachine).requestPulse(anyInt());
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/pip/phone/PipTouchStateTest.java b/packages/SystemUI/tests/src/com/android/systemui/pip/phone/PipTouchStateTest.java
index b8c946d..b7c1e8e 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/pip/phone/PipTouchStateTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/pip/phone/PipTouchStateTest.java
@@ -24,43 +24,36 @@
import static org.junit.Assert.assertTrue;
import android.os.Handler;
-import android.os.HandlerThread;
import android.os.Looper;
import android.os.SystemClock;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.testing.TestableLooper.RunWithLooper;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.pip.phone.PipTouchState;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
@SmallTest
+@RunWithLooper
public class PipTouchStateTest extends SysuiTestCase {
- private Handler mHandler;
- private HandlerThread mHandlerThread;
private PipTouchState mTouchState;
private CountDownLatch mDoubleTapCallbackTriggeredLatch;
@Before
public void setUp() throws Exception {
- mHandlerThread = new HandlerThread("PipTouchStateTestThread");
- mHandlerThread.start();
- mHandler = new Handler(mHandlerThread.getLooper());
-
mDoubleTapCallbackTriggeredLatch = new CountDownLatch(1);
mTouchState = new PipTouchState(ViewConfiguration.get(getContext()),
- mHandler, () -> {
+ Handler.createAsync(Looper.myLooper()), () -> {
mDoubleTapCallbackTriggeredLatch.countDown();
});
assertFalse(mTouchState.isDoubleTap());
@@ -91,7 +84,10 @@
assertTrue(mTouchState.getDoubleTapTimeoutCallbackDelay() == 10);
mTouchState.scheduleDoubleTapTimeoutCallback();
- mDoubleTapCallbackTriggeredLatch.await(1, TimeUnit.SECONDS);
+
+ // TODO: Remove this sleep. Its only being added because it speeds up this test a bit.
+ Thread.sleep(15);
+ TestableLooper.get(this).processAllMessages();
assertTrue(mDoubleTapCallbackTriggeredLatch.getCount() == 0);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
index 4f98836..33b347a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
@@ -22,12 +22,15 @@
import android.content.Context;
import android.content.pm.UserInfo;
-import android.os.Handler;
import android.os.Looper;
import android.os.UserManager;
import android.provider.Settings;
-import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.LayoutInflaterBuilder;
+import android.testing.TestableImageView;
+import android.testing.TestableLooper;
+import android.testing.TestableLooper.RunWithLooper;
import android.text.SpannableStringBuilder;
import android.view.LayoutInflater;
import android.view.View;
@@ -38,8 +41,6 @@
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.policy.SecurityController;
-import android.testing.LayoutInflaterBuilder;
-import android.testing.TestableImageView;
import org.junit.Before;
import org.junit.Test;
@@ -56,7 +57,8 @@
*/
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class QSSecurityFooterTest extends SysuiTestCase {
private final String MANAGING_ORGANIZATION = "organization";
@@ -81,12 +83,10 @@
.build());
mUserManager = Mockito.mock(UserManager.class);
mContext.addMockSystemService(Context.USER_SERVICE, mUserManager);
- Handler h = new Handler(Looper.getMainLooper());
- h.post(() -> mFooter = new QSSecurityFooter(null, mContext));
- waitForIdleSync(h);
+ mFooter = new QSSecurityFooter(null, mContext);
mRootView = (ViewGroup) mFooter.getView();
- mFooterText = (TextView) mRootView.findViewById(R.id.footer_text);
- mFooterIcon = (TestableImageView) mRootView.findViewById(R.id.footer_icon);
+ mFooterText = mRootView.findViewById(R.id.footer_text);
+ mFooterIcon = mRootView.findViewById(R.id.footer_icon);
mFooter.setHostEnvironment(null);
}
@@ -95,7 +95,7 @@
when(mSecurityController.isDeviceManaged()).thenReturn(false);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(View.GONE, mRootView.getVisibility());
}
@@ -105,7 +105,7 @@
when(mSecurityController.getDeviceOwnerOrganizationName()).thenReturn(null);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management),
mFooterText.getText());
assertEquals(View.VISIBLE, mRootView.getVisibility());
@@ -121,7 +121,7 @@
.thenReturn(MANAGING_ORGANIZATION);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_management,
MANAGING_ORGANIZATION),
mFooterText.getText());
@@ -142,7 +142,7 @@
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(View.GONE, mRootView.getVisibility());
}
@@ -152,7 +152,7 @@
when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
mFooterText.getText());
assertEquals(View.VISIBLE, mFooterIcon.getVisibility());
@@ -164,7 +164,7 @@
.thenReturn(MANAGING_ORGANIZATION);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(
R.string.quick_settings_disclosure_named_management_monitoring,
MANAGING_ORGANIZATION),
@@ -177,7 +177,7 @@
when(mSecurityController.hasCACertInCurrentUser()).thenReturn(true);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
mFooterText.getText());
}
@@ -189,7 +189,7 @@
when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_named_vpn,
VPN_PACKAGE),
mFooterText.getText());
@@ -201,7 +201,7 @@
.thenReturn(MANAGING_ORGANIZATION);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(
R.string.quick_settings_disclosure_named_management_named_vpn,
MANAGING_ORGANIZATION, VPN_PACKAGE),
@@ -216,7 +216,7 @@
when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_vpns),
mFooterText.getText());
assertEquals(View.VISIBLE, mFooterIcon.getVisibility());
@@ -227,7 +227,7 @@
.thenReturn(MANAGING_ORGANIZATION);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_management_vpns,
MANAGING_ORGANIZATION),
mFooterText.getText());
@@ -241,7 +241,7 @@
when(mSecurityController.getPrimaryVpnName()).thenReturn("VPN Test App");
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(View.VISIBLE, mFooterIcon.getVisibility());
assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource());
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
@@ -254,7 +254,7 @@
when(mSecurityController.hasCACertInWorkProfile()).thenReturn(true);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
// -1 == never set.
assertEquals(-1, mFooterIcon.getLastImageResource());
assertEquals(mContext.getString(
@@ -266,7 +266,7 @@
.thenReturn(MANAGING_ORGANIZATION);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(
R.string.quick_settings_disclosure_named_managed_profile_monitoring,
MANAGING_ORGANIZATION),
@@ -279,7 +279,7 @@
when(mSecurityController.hasCACertInCurrentUser()).thenReturn(true);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
// -1 == never set.
assertEquals(-1, mFooterIcon.getLastImageResource());
assertEquals(mContext.getString(R.string.quick_settings_disclosure_monitoring),
@@ -293,7 +293,7 @@
when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource());
assertEquals(mContext.getString(R.string.quick_settings_disclosure_vpns),
mFooterText.getText());
@@ -305,7 +305,7 @@
when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource());
assertEquals(mContext.getString(
R.string.quick_settings_disclosure_managed_profile_named_vpn,
@@ -319,7 +319,7 @@
when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource());
assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_vpn,
VPN_PACKAGE),
@@ -328,7 +328,7 @@
when(mSecurityController.hasWorkProfile()).thenReturn(true);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(mContext.getString(
R.string.quick_settings_disclosure_personal_profile_named_vpn,
VPN_PACKAGE),
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java
index 66ec7dd..e5e8ae3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java
@@ -81,7 +81,7 @@
mUser = new UserHandle(UserHandle.myUserId());
mThread = new HandlerThread("TestThread");
mThread.start();
- mHandler = new Handler(mThread.getLooper());
+ mHandler = Handler.createAsync(mThread.getLooper());
mStateManager = new TileLifecycleManager(mHandler, mContext,
Mockito.mock(IQSService.class), new Tile(),
mTileServiceIntent,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServiceManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServiceManagerTest.java
index c2237c9..cc743245 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServiceManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServiceManagerTest.java
@@ -46,7 +46,7 @@
public void setUp() throws Exception {
mThread = new HandlerThread("TestThread");
mThread.start();
- mHandler = new Handler(mThread.getLooper());
+ mHandler = Handler.createAsync(mThread.getLooper());
mTileServices = Mockito.mock(TileServices.class);
Mockito.when(mTileServices.getContext()).thenReturn(mContext);
mTileLifecycle = Mockito.mock(TileLifecycleManager.class);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/AppOpsListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/AppOpsListenerTest.java
index dc0e2b0..0feaa5a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/AppOpsListenerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/AppOpsListenerTest.java
@@ -16,8 +16,6 @@
package com.android.systemui.statusbar;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -53,7 +51,6 @@
@Mock private ForegroundServiceController mFsc;
private AppOpsListener mListener;
- private Handler mHandler;
@Before
public void setUp() {
@@ -61,8 +58,7 @@
mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
mDependency.injectTestDependency(ForegroundServiceController.class, mFsc);
getContext().addMockSystemService(AppOpsManager.class, mAppOpsManager);
- mHandler = new Handler(Looper.getMainLooper());
- when(mPresenter.getHandler()).thenReturn(mHandler);
+ when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
mListener = new AppOpsListener(mContext);
}
@@ -85,7 +81,7 @@
mListener.setUpWithPresenter(mPresenter, mEntryManager);
mListener.onOpActiveChanged(
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
verify(mEntryManager, times(1)).updateNotificationsForAppOp(
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
}
@@ -95,7 +91,7 @@
mListener.setUpWithPresenter(mPresenter, mEntryManager);
mListener.onOpActiveChanged(
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
verify(mFsc, times(1)).onAppOpChanged(
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/ExpandableNotificationRowTest.java
index 2a4a5ad..ff12c53 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/ExpandableNotificationRowTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/ExpandableNotificationRowTest.java
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -33,7 +34,8 @@
import android.app.AppOpsManager;
import android.app.NotificationChannel;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.util.ArraySet;
import android.view.NotificationHeaderView;
import android.view.View;
@@ -49,15 +51,14 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
-import java.util.function.Consumer;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class ExpandableNotificationRowTest extends SysuiTestCase {
private ExpandableNotificationRow mGroupRow;
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 1204dda..2af0c3e 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java
@@ -55,13 +55,10 @@
@Mock private NotificationGutsManager.OnSettingsClickListener mOnClickListener;
@Mock private NotificationRemoteInputManager.Callback mRemoteInputManagerCallback;
- private Handler mHandler;
-
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mHandler = new Handler(Looper.getMainLooper());
- when(mPresenter.getHandler()).thenReturn(mHandler);
+ when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java
index a6d87af..9638541 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java
@@ -52,7 +52,7 @@
@SmallTest
@FlakyTest
@org.junit.runner.RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
private NotificationBlockingHelperManager mBlockingHelperManager;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationCustomViewWrapperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationCustomViewWrapperTest.java
index 2ff86c3..a34588d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationCustomViewWrapperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationCustomViewWrapperTest.java
@@ -16,9 +16,9 @@
package com.android.systemui.statusbar;
-import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import android.widget.RemoteViews;
@@ -33,7 +33,8 @@
import org.junit.runner.RunWith;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class NotificationCustomViewWrapperTest extends SysuiTestCase {
private ExpandableNotificationRow mRow;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java
index 8bdaff9..609e032 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java
@@ -47,6 +47,8 @@
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.util.ArraySet;
import com.android.systemui.ForegroundServiceController;
@@ -61,7 +63,8 @@
import org.mockito.MockitoAnnotations;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class NotificationDataTest extends SysuiTestCase {
private static final int UID_NORMAL = 123;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryManagerTest.java
index 8172626..f05cf6b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryManagerTest.java
@@ -100,7 +100,6 @@
private NotificationData.Entry mEntry;
private StatusBarNotification mSbn;
- private Handler mHandler;
private TestableNotificationEntryManager mEntryManager;
private CountDownLatch mCountDownLatch;
@@ -160,10 +159,9 @@
mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager);
mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
- mHandler = new Handler(Looper.getMainLooper());
mCountDownLatch = new CountDownLatch(1);
- when(mPresenter.getHandler()).thenReturn(mHandler);
+ when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
when(mPresenter.getNotificationLockscreenUserManager()).thenReturn(mLockscreenUserManager);
when(mPresenter.getGroupManager()).thenReturn(mGroupManager);
when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
@@ -188,6 +186,7 @@
@Test
public void testAddNotification() throws Exception {
com.android.systemui.util.Assert.isNotMainThread();
+ TestableLooper.get(this).processAllMessages();
doAnswer(invocation -> {
mCountDownLatch.countDown();
@@ -196,12 +195,10 @@
// Post on main thread, otherwise we will be stuck waiting here for the inflation finished
// callback forever, since it won't execute until the tests ends.
- mHandler.post(() -> {
- mEntryManager.addNotification(mSbn, mRankingMap);
- });
- assertTrue(mCountDownLatch.await(1, TimeUnit.MINUTES));
- assertTrue(mEntryManager.getCountDownLatch().await(1, TimeUnit.MINUTES));
- waitForIdleSync(mHandler);
+ mEntryManager.addNotification(mSbn, mRankingMap);
+ TestableLooper.get(this).processMessages(1);
+ assertTrue(mCountDownLatch.await(10, TimeUnit.SECONDS));
+ assertTrue(mEntryManager.getCountDownLatch().await(10, TimeUnit.SECONDS));
// Check that no inflation error occurred.
verify(mBarService, never()).onNotificationError(any(), any(), anyInt(), anyInt(), anyInt(),
@@ -228,17 +225,16 @@
@Test
public void testUpdateNotification() throws Exception {
com.android.systemui.util.Assert.isNotMainThread();
+ TestableLooper.get(this).processAllMessages();
mEntryManager.getNotificationData().add(mEntry);
setUserSentiment(mEntry.key, NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE);
- mHandler.post(() -> {
- mEntryManager.updateNotification(mSbn, mRankingMap);
- });
+ mEntryManager.updateNotification(mSbn, mRankingMap);
+ TestableLooper.get(this).processMessages(1);
// Wait for content update.
- mEntryManager.getCountDownLatch().await(1, TimeUnit.MINUTES);
- waitForIdleSync(mHandler);
+ assertTrue(mEntryManager.getCountDownLatch().await(10, TimeUnit.SECONDS));
verify(mBarService, never()).onNotificationError(any(), any(), anyInt(), anyInt(), anyInt(),
any(), anyInt());
@@ -259,10 +255,7 @@
mEntry.row = mRow;
mEntryManager.getNotificationData().add(mEntry);
- mHandler.post(() -> {
- mEntryManager.removeNotification(mSbn.getKey(), mRankingMap);
- });
- waitForIdleSync(mHandler);
+ mEntryManager.removeNotification(mSbn.getKey(), mRankingMap);
verify(mBarService, never()).onNotificationError(any(), any(), anyInt(), anyInt(), anyInt(),
any(), anyInt());
@@ -287,12 +280,9 @@
mEntry.row = mRow;
mEntryManager.getNotificationData().add(mEntry);
- mHandler.post(() -> {
- mEntryManager.updateNotificationsForAppOp(
- AppOpsManager.OP_CAMERA, mEntry.notification.getUid(),
- mEntry.notification.getPackageName(), true);
- });
- waitForIdleSync(mHandler);
+ mEntryManager.updateNotificationsForAppOp(
+ AppOpsManager.OP_CAMERA, mEntry.notification.getUid(),
+ mEntry.notification.getPackageName(), true);
verify(mPresenter, times(1)).updateNotificationViews();
assertTrue(mEntryManager.getNotificationData().get(mEntry.key).mActiveAppOps.contains(
@@ -305,10 +295,7 @@
when(mForegroundServiceController.getStandardLayoutKey(anyInt(), anyString()))
.thenReturn(null);
- mHandler.post(() -> {
- mEntryManager.updateNotificationsForAppOp(AppOpsManager.OP_CAMERA, 1000, "pkg", true);
- });
- waitForIdleSync(mHandler);
+ mEntryManager.updateNotificationsForAppOp(AppOpsManager.OP_CAMERA, 1000, "pkg", true);
verify(mPresenter, never()).updateNotificationViews();
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java
index 0ef2d051..cba1b54 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java
@@ -74,7 +74,7 @@
*/
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class NotificationGutsManagerTest extends SysuiTestCase {
private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
@@ -95,7 +95,7 @@
@Before
public void setUp() {
mTestableLooper = TestableLooper.get(this);
- mHandler = new Handler(mTestableLooper.getLooper());
+ mHandler = Handler.createAsync(mTestableLooper.getLooper());
mHelper = new NotificationTestHelper(mContext);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java
index ef5f071..c6397e6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java
@@ -59,7 +59,6 @@
@Mock private NotificationRemoteInputManager mRemoteInputManager;
private NotificationListener mListener;
- private Handler mHandler;
private StatusBarNotification mSbn;
private Set<String> mKeysKeptForRemoteInput;
@@ -70,10 +69,9 @@
mDependency.injectTestDependency(NotificationRemoteInputManager.class,
mRemoteInputManager);
- mHandler = new Handler(Looper.getMainLooper());
mKeysKeptForRemoteInput = new HashSet<>();
- when(mPresenter.getHandler()).thenReturn(mHandler);
+ when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
when(mEntryManager.getNotificationData()).thenReturn(mNotificationData);
when(mRemoteInputManager.getKeysKeptForRemoteInput()).thenReturn(mKeysKeptForRemoteInput);
@@ -87,7 +85,7 @@
@Test
public void testNotificationAddCallsAddNotification() {
mListener.onNotificationPosted(mSbn, mRanking);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
verify(mEntryManager).addNotification(mSbn, mRanking);
}
@@ -95,7 +93,7 @@
public void testPostNotificationRemovesKeyKeptForRemoteInput() {
mKeysKeptForRemoteInput.add(mSbn.getKey());
mListener.onNotificationPosted(mSbn, mRanking);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
assertTrue(mKeysKeptForRemoteInput.isEmpty());
}
@@ -103,21 +101,21 @@
public void testNotificationUpdateCallsUpdateNotification() {
when(mNotificationData.get(mSbn.getKey())).thenReturn(new NotificationData.Entry(mSbn));
mListener.onNotificationPosted(mSbn, mRanking);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
verify(mEntryManager).updateNotification(mSbn, mRanking);
}
@Test
public void testNotificationRemovalCallsRemoveNotification() {
mListener.onNotificationRemoved(mSbn, mRanking);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
verify(mEntryManager).removeNotification(mSbn.getKey(), mRanking);
}
@Test
public void testRankingUpdateCallsNotificationRankingUpdate() {
mListener.onNotificationRankingUpdate(mRanking);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
// RankingMap may be modified by plugins.
verify(mEntryManager).updateNotificationRanking(any());
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
index cb8f7ce..2401519 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
@@ -63,7 +63,6 @@
@Mock private DeviceProvisionedController mDeviceProvisionedController;
private int mCurrentUserId;
- private Handler mHandler;
private TestNotificationLockscreenUserManager mLockscreenUserManager;
@Before
@@ -73,13 +72,12 @@
mDependency.injectTestDependency(DeviceProvisionedController.class,
mDeviceProvisionedController);
- mHandler = new Handler(Looper.getMainLooper());
mContext.addMockSystemService(UserManager.class, mUserManager);
mCurrentUserId = ActivityManager.getCurrentUser();
when(mUserManager.getProfiles(mCurrentUserId)).thenReturn(Lists.newArrayList(
new UserInfo(mCurrentUserId, "", 0), new UserInfo(mCurrentUserId + 1, "", 0)));
- when(mPresenter.getHandler()).thenReturn(mHandler);
+ when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
mLockscreenUserManager = new TestNotificationLockscreenUserManager(mContext);
mLockscreenUserManager.setUpWithPresenter(mPresenter, mEntryManager);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLoggerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLoggerTest.java
index 14fada5..bbb03d7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLoggerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLoggerTest.java
@@ -26,7 +26,6 @@
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
-import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
@@ -35,7 +34,6 @@
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.UiOffloadThread;
import com.google.android.collect.Lists;
@@ -48,7 +46,7 @@
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class NotificationLoggerTest extends SysuiTestCase {
private static final String TEST_PACKAGE_NAME = "test";
private static final int TEST_UID = 0;
@@ -89,7 +87,7 @@
when(mListContainer.isInVisibleLocation(any())).thenReturn(true);
when(mNotificationData.getActiveNotifications()).thenReturn(Lists.newArrayList(mEntry));
mLogger.getChildLocationsChangedListenerForTest().onChildLocationsChanged();
- waitForIdleSync(mLogger.getHandlerForTest());
+ TestableLooper.get(this).processAllMessages();
waitForUiOffloadThread();
NotificationVisibility[] newlyVisibleKeys = {
@@ -101,7 +99,7 @@
// |mEntry| won't change visibility, so it shouldn't be reported again:
Mockito.reset(mBarService);
mLogger.getChildLocationsChangedListenerForTest().onChildLocationsChanged();
- waitForIdleSync(mLogger.getHandlerForTest());
+ TestableLooper.get(this).processAllMessages();
waitForUiOffloadThread();
verify(mBarService, never()).onNotificationVisibilityChanged(any(), any());
@@ -113,7 +111,7 @@
when(mListContainer.isInVisibleLocation(any())).thenReturn(true);
when(mNotificationData.getActiveNotifications()).thenReturn(Lists.newArrayList(mEntry));
mLogger.getChildLocationsChangedListenerForTest().onChildLocationsChanged();
- waitForIdleSync(mLogger.getHandlerForTest());
+ TestableLooper.get(this).processAllMessages();
waitForUiOffloadThread();
Mockito.reset(mBarService);
@@ -128,8 +126,8 @@
public TestableNotificationLogger(IStatusBarService barService) {
mBarService = barService;
- // Make this on the main thread so we can wait for it during tests.
- mHandler = new Handler(Looper.getMainLooper());
+ // Make this on the current thread so we can wait for it during tests.
+ mHandler = Handler.createAsync(Looper.myLooper());
}
public OnChildLocationsChangedListener
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java
index 4829cb2..8b2f6cd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java
@@ -45,7 +45,6 @@
@Mock private NotificationEntryManager mEntryManager;
@Mock private NotificationLockscreenUserManager mLockscreenUserManager;
- private Handler mHandler;
private TestableNotificationRemoteInputManager mRemoteInputManager;
private StatusBarNotification mSbn;
private NotificationData.Entry mEntry;
@@ -56,9 +55,8 @@
mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
mDependency.injectTestDependency(NotificationLockscreenUserManager.class,
mLockscreenUserManager);
- mHandler = new Handler(Looper.getMainLooper());
- when(mPresenter.getHandler()).thenReturn(mHandler);
+ when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
when(mEntryManager.getLatestRankingMap()).thenReturn(mRanking);
mRemoteInputManager = new TestableNotificationRemoteInputManager(mContext);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java
index de2e6bf..2b0c6bf 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java
@@ -143,12 +143,10 @@
throws Exception {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
mContext.LAYOUT_INFLATER_SERVICE);
- mInstrumentation.runOnMainSync(() ->
- mRow = (ExpandableNotificationRow) inflater.inflate(
- R.layout.status_bar_notification_row,
- null /* root */,
- false /* attachToRoot */)
- );
+ mRow = (ExpandableNotificationRow) inflater.inflate(
+ R.layout.status_bar_notification_row,
+ null /* root */,
+ false /* attachToRoot */);
ExpandableNotificationRow row = mRow;
row.setGroupManager(mGroupManager);
row.setHeadsUpManager(mHeadsUpManager);
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 76ed452..0d0d1f86 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java
@@ -50,7 +50,7 @@
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class NotificationViewHierarchyManagerTest extends SysuiTestCase {
@Mock private NotificationPresenter mPresenter;
@Mock private NotificationData mNotificationData;
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 1ee9b32..00e9995 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,6 +21,8 @@
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.widget.FrameLayout;
import com.android.systemui.SysuiTestCase;
@@ -33,7 +35,8 @@
import org.junit.runner.RunWith;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class AboveShelfObserverTest extends SysuiTestCase {
private AboveShelfObserver mObserver;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java
index 83a2883..aa8a08c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationInflaterTest.java
@@ -18,6 +18,7 @@
import static com.android.systemui.statusbar.notification.NotificationInflater.FLAG_REINFLATE_ALL;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -28,10 +29,9 @@
import android.os.Handler;
import android.os.Looper;
import android.service.notification.StatusBarNotification;
-import android.support.test.annotation.UiThreadTest;
-import android.support.test.filters.FlakyTest;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RemoteViews;
@@ -52,9 +52,11 @@
import java.util.HashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
+import java.util.concurrent.TimeUnit;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class NotificationInflaterTest extends SysuiTestCase {
private NotificationInflater mNotificationInflater;
@@ -85,7 +87,6 @@
}
@Test
- @UiThreadTest
public void testIncreasedHeadsUpBeingUsed() {
mNotificationInflater.setUsesIncreasedHeadsUpHeight(true);
Notification.Builder builder = spy(mBuilder);
@@ -94,7 +95,6 @@
}
@Test
- @UiThreadTest
public void testIncreasedHeightBeingUsed() {
mNotificationInflater.setUsesIncreasedHeight(true);
Notification.Builder builder = spy(mBuilder);
@@ -115,8 +115,8 @@
mRow.getEntry().cachedBigContentView = null;
runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(
NotificationInflater.FLAG_REINFLATE_EXPANDED_VIEW), mNotificationInflater);
- Assert.assertTrue(mRow.getPrivateLayout().getChildCount() == 1);
- Assert.assertTrue(mRow.getPrivateLayout().getChildAt(0)
+ assertTrue(mRow.getPrivateLayout().getChildCount() == 1);
+ assertTrue(mRow.getPrivateLayout().getChildAt(0)
== mRow.getPrivateLayout().getExpandedChild());
verify(mRow).onNotificationUpdated();
}
@@ -128,7 +128,7 @@
= new RemoteViews(mContext.getPackageName(), R.layout.status_bar);
runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(),
true /* expectingException */, mNotificationInflater);
- Assert.assertTrue(mRow.getPrivateLayout().getChildCount() == 0);
+ assertTrue(mRow.getPrivateLayout().getChildCount() == 0);
verify(mRow, times(0)).onNotificationUpdated();
}
@@ -181,12 +181,11 @@
R.layout.custom_view_dark);
}
});
- countDownLatch.await();
+ assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS));
}
/* Cancelling requires us to be on the UI thread otherwise we might have a race */
@Test
- @UiThreadTest
public void testSupersedesExistingTask() throws Exception {
mNotificationInflater.inflateNotificationViews();
mNotificationInflater.setIsLowPriority(true);
@@ -219,7 +218,6 @@
private static void runThenWaitForInflation(Runnable block, boolean expectingException,
NotificationInflater inflater) throws Exception {
- com.android.systemui.util.Assert.isNotMainThread();
CountDownLatch countDownLatch = new CountDownLatch(1);
final ExceptionHolder exceptionHolder = new ExceptionHolder();
inflater.setInflationCallback(new NotificationInflater.InflationCallback() {
@@ -240,9 +238,14 @@
}
countDownLatch.countDown();
}
+
+ @Override
+ public boolean doInflateSynchronous() {
+ return true;
+ }
});
block.run();
- countDownLatch.await();
+ assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS));
if (exceptionHolder.mException != null) {
throw exceptionHolder.mException;
}
@@ -257,7 +260,7 @@
}
private class AsyncFailRemoteView extends RemoteViews {
- Handler mHandler = new Handler(Looper.getMainLooper());
+ Handler mHandler = Handler.createAsync(Looper.getMainLooper());
public AsyncFailRemoteView(String packageName, int layoutId) {
super(packageName, layoutId);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java
index 9da28a0..7e2e505 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java
@@ -20,6 +20,8 @@
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import com.android.systemui.SysuiTestCase;
@@ -30,8 +32,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
@SmallTest
+@RunWithLooper(setAsMainLooper = true)
public class NotificationViewWrapperTest extends SysuiTestCase {
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
index 36fd499..23365a4 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
@@ -51,7 +51,7 @@
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mAutoTileManager = new AutoTileManager(mContext, mAutoAddTracker, mQsTileHost,
- new Handler(TestableLooper.get(this).getLooper()));
+ Handler.createAsync(TestableLooper.get(this).getLooper()));
}
@Test
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 7a61bfe..537bfd4 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
@@ -26,6 +26,8 @@
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import android.widget.TextView;
@@ -47,7 +49,8 @@
import java.util.HashSet;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
private final NotificationStackScrollLayout mStackScroller =
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
index 37e0005..0a412b9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
@@ -48,6 +48,7 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IPowerManager;
+import android.os.Looper;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -173,10 +174,8 @@
mNotificationLogger = new NotificationLogger();
IPowerManager powerManagerService = mock(IPowerManager.class);
- HandlerThread handlerThread = new HandlerThread("TestThread");
- handlerThread.start();
mPowerManager = new PowerManager(mContext, powerManagerService,
- new Handler(handlerThread.getLooper()));
+ Handler.createAsync(Looper.myLooper()));
CommandQueue commandQueue = mock(CommandQueue.class);
when(commandQueue.asBinder()).thenReturn(new Binder());
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 7e1aba5..938dfca 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
@@ -21,6 +21,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ShortcutManager;
+import android.os.Handler;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -28,6 +29,7 @@
import android.widget.EditText;
import android.widget.ImageButton;
+import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.ExpandableNotificationRow;
@@ -42,7 +44,7 @@
import org.mockito.MockitoAnnotations;
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
@SmallTest
public class RemoteInputViewTest extends SysuiTestCase {
@@ -60,7 +62,8 @@
MockitoAnnotations.initMocks(this);
mReceiver = new BlockingQueueIntentReceiver();
- mContext.registerReceiver(mReceiver, new IntentFilter(TEST_ACTION));
+ mContext.registerReceiver(mReceiver, new IntentFilter(TEST_ACTION), null,
+ Handler.createAsync(Dependency.get(Dependency.BG_LOOPER)));
// Avoid SecurityException RemoteInputView#sendRemoteInput().
mContext.addMockSystemService(ShortcutManager.class, mShortcutManager);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyConstantsTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyConstantsTest.java
index aca7c9c..2266b47 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyConstantsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyConstantsTest.java
@@ -51,7 +51,7 @@
resources.addOverride(R.bool.config_smart_replies_in_notifications_enabled, true);
resources.addOverride(
R.integer.config_smart_replies_in_notifications_max_squeeze_remeasure_attempts, 7);
- mConstants = new SmartReplyConstants(new Handler(Looper.getMainLooper()), mContext);
+ mConstants = new SmartReplyConstants(Handler.createAsync(Looper.myLooper()), mContext);
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/ZenModeControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/ZenModeControllerImplTest.java
index ff65587..7437e834 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/ZenModeControllerImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/ZenModeControllerImplTest.java
@@ -24,6 +24,7 @@
import android.app.NotificationManager;
import android.os.Handler;
+import android.os.Looper;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.support.test.filters.SmallTest;
@@ -58,7 +59,7 @@
mContext.addMockSystemService(NotificationManager.class, mNm);
when(mNm.getZenModeConfig()).thenReturn(mConfig);
- mController = new ZenModeControllerImpl(mContext, new Handler());
+ mController = new ZenModeControllerImpl(mContext, Handler.createAsync(Looper.myLooper()));
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/stack/NotificationChildrenContainerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/stack/NotificationChildrenContainerTest.java
index 5ac965c..8a74019 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/stack/NotificationChildrenContainerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/stack/NotificationChildrenContainerTest.java
@@ -18,6 +18,8 @@
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.view.NotificationHeaderView;
import android.view.View;
@@ -31,7 +33,8 @@
import org.junit.runner.RunWith;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class NotificationChildrenContainerTest extends SysuiTestCase {
private ExpandableNotificationRow mGroup;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/stack/NotificationRoundnessManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/stack/NotificationRoundnessManagerTest.java
index 28d1aff..16e69f4 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/stack/NotificationRoundnessManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/stack/NotificationRoundnessManagerTest.java
@@ -16,29 +16,18 @@
package com.android.systemui.statusbar.stack;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyFloat;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.statusbar.ActivatableNotificationView;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;
-import com.android.systemui.statusbar.StatusBarState;
-import com.android.systemui.statusbar.phone.ScrimController;
-import com.android.systemui.statusbar.phone.StatusBar;
import org.junit.Assert;
import org.junit.Before;
@@ -46,10 +35,10 @@
import org.junit.runner.RunWith;
import java.util.HashSet;
-import java.util.function.Consumer;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class NotificationRoundnessManagerTest extends SysuiTestCase {
private NotificationRoundnessManager mRoundnessManager = new NotificationRoundnessManager();