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
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() {
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() {
mRow.onNotificationUpdated();
mCallback.onAsyncInflationFinished(mRow.getEntry());
}
+
+ @Override
+ public boolean doInflateSynchronous() {
+ return mCallback != null && mCallback.doInflateSynchronous();
+ }
}
@VisibleForTesting
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;
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]);
}
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;
import static org.mockito.Mockito.when;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class ExpandHelperTest extends SysuiTestCase {
private ExpandableNotificationRow mRow;
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
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;
@SmallTest
@Ignore("failing")
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class DozeTriggersTest extends SysuiTestCase {
private DozeTriggers mTriggers;
private DozeMachine mMachine;
private AmbientDisplayConfiguration mConfig;
private DozeParameters mParameters;
private FakeSensorManager mSensors;
- private Handler mHandler;
private WakeLock mWakeLock;
private Instrumentation mInstrumentation;
private AlarmManager mAlarmManager;
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());
}
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());
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);
}
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;
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;
*/
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class QSSecurityFooterTest extends SysuiTestCase {
private final String MANAGING_ORGANIZATION = "organization";
.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);
}
when(mSecurityController.isDeviceManaged()).thenReturn(false);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(View.GONE, mRootView.getVisibility());
}
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());
.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());
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
assertEquals(View.GONE, mRootView.getVisibility());
}
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());
.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),
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());
}
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());
.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),
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());
.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());
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),
when(mSecurityController.hasCACertInWorkProfile()).thenReturn(true);
mFooter.refreshState();
- waitForIdleSync(mFooter.mHandler);
+ TestableLooper.get(this).processAllMessages();
// -1 == never set.
assertEquals(-1, mFooterIcon.getLastImageResource());
assertEquals(mContext.getString(
.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),
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),
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());
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,
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),
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),
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,
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);
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;
@Mock private ForegroundServiceController mFsc;
private AppOpsListener mListener;
- private Handler mHandler;
@Before
public void setUp() {
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);
}
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);
}
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);
}
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;
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;
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;
@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
@SmallTest
@FlakyTest
@org.junit.runner.RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
private NotificationBlockingHelperManager mBlockingHelperManager;
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;
import org.junit.runner.RunWith;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class NotificationCustomViewWrapperTest extends SysuiTestCase {
private ExpandableNotificationRow mRow;
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;
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;
private NotificationData.Entry mEntry;
private StatusBarNotification mSbn;
- private Handler mHandler;
private TestableNotificationEntryManager mEntryManager;
private CountDownLatch mCountDownLatch;
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);
@Test
public void testAddNotification() throws Exception {
com.android.systemui.util.Assert.isNotMainThread();
+ TestableLooper.get(this).processAllMessages();
doAnswer(invocation -> {
mCountDownLatch.countDown();
// 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(),
@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());
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());
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(
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();
}
*/
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class NotificationGutsManagerTest extends SysuiTestCase {
private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
@Before
public void setUp() {
mTestableLooper = TestableLooper.get(this);
- mHandler = new Handler(mTestableLooper.getLooper());
+ mHandler = Handler.createAsync(mTestableLooper.getLooper());
mHelper = new NotificationTestHelper(mContext);
@Mock private NotificationRemoteInputManager mRemoteInputManager;
private NotificationListener mListener;
- private Handler mHandler;
private StatusBarNotification mSbn;
private Set<String> mKeysKeptForRemoteInput;
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);
@Test
public void testNotificationAddCallsAddNotification() {
mListener.onNotificationPosted(mSbn, mRanking);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
verify(mEntryManager).addNotification(mSbn, mRanking);
}
public void testPostNotificationRemovesKeyKeptForRemoteInput() {
mKeysKeptForRemoteInput.add(mSbn.getKey());
mListener.onNotificationPosted(mSbn, mRanking);
- waitForIdleSync(mHandler);
+ TestableLooper.get(this).processAllMessages();
assertTrue(mKeysKeptForRemoteInput.isEmpty());
}
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());
}
@Mock private DeviceProvisionedController mDeviceProvisionedController;
private int mCurrentUserId;
- private Handler mHandler;
private TestNotificationLockscreenUserManager mLockscreenUserManager;
@Before
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);
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;
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;
@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;
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 = {
// |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());
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);
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
@Mock private NotificationEntryManager mEntryManager;
@Mock private NotificationLockscreenUserManager mLockscreenUserManager;
- private Handler mHandler;
private TestableNotificationRemoteInputManager mRemoteInputManager;
private StatusBarNotification mSbn;
private NotificationData.Entry mEntry;
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);
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);
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class NotificationViewHierarchyManagerTest extends SysuiTestCase {
@Mock private NotificationPresenter mPresenter;
@Mock private NotificationData mNotificationData;
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;
import org.junit.runner.RunWith;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class AboveShelfObserverTest extends SysuiTestCase {
private AboveShelfObserver mObserver;
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;
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;
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;
}
@Test
- @UiThreadTest
public void testIncreasedHeadsUpBeingUsed() {
mNotificationInflater.setUsesIncreasedHeadsUpHeight(true);
Notification.Builder builder = spy(mBuilder);
}
@Test
- @UiThreadTest
public void testIncreasedHeightBeingUsed() {
mNotificationInflater.setUsesIncreasedHeight(true);
Notification.Builder builder = spy(mBuilder);
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();
}
= 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();
}
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);
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() {
}
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;
}
}
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);
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;
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
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
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;
import java.util.HashSet;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
private final NotificationStackScrollLayout mStackScroller =
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;
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());
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;
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;
import org.mockito.MockitoAnnotations;
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@TestableLooper.RunWithLooper(setAsMainLooper = true)
@SmallTest
public class RemoteInputViewTest extends SysuiTestCase {
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);
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
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;
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
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;
import org.junit.runner.RunWith;
@SmallTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper(setAsMainLooper = true)
public class NotificationChildrenContainerTest extends SysuiTestCase {
private ExpandableNotificationRow mGroup;
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;
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();