Convert from Handlers to Executors in NotificationLockscreenUserManager
Removal of TestableLooper also means these tests can now run deviceless, so I've made that conversion as well.
Fixes: 315363596
Test: atest NotificationLockscreenUserManagerTest
Test: atest NotificationLockscreenUserManagerMainThreadTest
Test: atest SystemUiRoboTests
Flag: NA
Change-Id: Ie0adfcb9766593b2745791f040d8e3dbbd3e2240
diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp
index d3a89f4..d61ae7e 100644
--- a/packages/SystemUI/Android.bp
+++ b/packages/SystemUI/Android.bp
@@ -438,6 +438,7 @@
"androidx.core_core-animation-testing",
"androidx.test.ext.junit",
"inline-mockito-robolectric-prebuilt",
+ "platform-parametric-runner-lib",
],
libs: [
"android.test.runner",
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java
similarity index 97%
rename from packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java
rename to packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java
index 01fe40f..d0e05fa 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java
@@ -42,19 +42,15 @@
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.net.Uri;
-import android.os.Handler;
-import android.os.Looper;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
-import android.testing.AndroidTestingRunner;
-import android.testing.TestableLooper;
import android.util.SparseArray;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import com.android.internal.widget.LockPatternUtils;
-import com.android.systemui.Dependency;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dump.DumpManager;
@@ -86,8 +82,7 @@
import java.util.concurrent.Executor;
@SmallTest
-@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper
+@RunWith(AndroidJUnit4.class)
public class NotificationLockscreenUserManagerMainThreadTest extends SysuiTestCase {
@Mock
private NotificationPresenter mPresenter;
@@ -128,6 +123,7 @@
private NotificationEntry mSecondaryUserNotif;
private NotificationEntry mWorkProfileNotif;
private final FakeFeatureFlagsClassic mFakeFeatureFlags = new FakeFeatureFlagsClassic();
+ private Executor mMainExecutor = Runnable::run; // Direct executor
private Executor mBackgroundExecutor = Runnable::run; // Direct executor
@Before
@@ -156,8 +152,6 @@
mSecondaryUser));
when(mUserManager.getProfilesIncludingCommunal(mSecondaryUser.id)).thenReturn(
Lists.newArrayList(mSecondaryUser, mCommunalUser));
- mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
- Handler.createAsync(Looper.myLooper()));
Notification notifWithPrivateVisibility = new Notification();
notifWithPrivateVisibility.visibility = Notification.VISIBILITY_PRIVATE;
@@ -378,28 +372,24 @@
// first call explicitly sets user 0 to not public; notifies
mLockscreenUserManager.updatePublicMode();
- TestableLooper.get(this).processAllMessages();
assertFalse(mLockscreenUserManager.isLockscreenPublicMode(0));
verify(listener).onNotificationStateChanged();
clearInvocations(listener);
// calling again has no changes; does not notify
mLockscreenUserManager.updatePublicMode();
- TestableLooper.get(this).processAllMessages();
assertFalse(mLockscreenUserManager.isLockscreenPublicMode(0));
verify(listener, never()).onNotificationStateChanged();
// Calling again with keyguard now showing makes user 0 public; notifies
when(mKeyguardStateController.isShowing()).thenReturn(true);
mLockscreenUserManager.updatePublicMode();
- TestableLooper.get(this).processAllMessages();
assertTrue(mLockscreenUserManager.isLockscreenPublicMode(0));
verify(listener).onNotificationStateChanged();
clearInvocations(listener);
// calling again has no changes; does not notify
mLockscreenUserManager.updatePublicMode();
- TestableLooper.get(this).processAllMessages();
assertTrue(mLockscreenUserManager.isLockscreenPublicMode(0));
verify(listener, never()).onNotificationStateChanged();
}
@@ -595,8 +585,7 @@
(() -> mOverviewProxyService),
NotificationLockscreenUserManagerMainThreadTest.this.mKeyguardManager,
mStatusBarStateController,
- Handler.createAsync(Looper.myLooper()),
- Handler.createAsync(Looper.myLooper()),
+ mMainExecutor,
mBackgroundExecutor,
mDeviceProvisionedController,
mKeyguardStateController,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
similarity index 98%
rename from packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
rename to packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
index 757f16c..bcc0710 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
@@ -29,10 +29,11 @@
import static android.os.UserHandle.USER_ALL;
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS;
-import static com.android.systemui.util.concurrency.MockExecutorHandlerKt.mockExecutorHandler;
+
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -62,13 +63,11 @@
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.FlagsParameterization;
import android.provider.Settings;
-import android.testing.TestableLooper;
import android.util.SparseArray;
import androidx.test.filters.SmallTest;
import com.android.internal.widget.LockPatternUtils;
-import com.android.systemui.Dependency;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dump.DumpManager;
@@ -88,6 +87,7 @@
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.settings.FakeSettings;
import com.android.systemui.util.time.FakeSystemClock;
+
import com.google.android.collect.Lists;
import org.junit.After;
@@ -109,7 +109,6 @@
@SmallTest
@RunWith(ParameterizedAndroidJunit4.class)
-@TestableLooper.RunWithLooper
public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Parameters(name = "{0}")
@@ -197,8 +196,6 @@
mSecondaryUser));
when(mUserManager.getProfilesIncludingCommunal(mSecondaryUser.id)).thenReturn(
Lists.newArrayList(mSecondaryUser, mCommunalUser));
- mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
- mockExecutorHandler(mMainExecutor));
Notification notifWithPrivateVisibility = new Notification();
notifWithPrivateVisibility.visibility = VISIBILITY_PRIVATE;
@@ -949,8 +946,7 @@
(() -> mOverviewProxyService),
NotificationLockscreenUserManagerTest.this.mKeyguardManager,
mStatusBarStateController,
- mockExecutorHandler(mMainExecutor),
- mockExecutorHandler(mBackgroundExecutor),
+ mMainExecutor,
mBackgroundExecutor,
mDeviceProvisionedController,
mKeyguardStateController,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
index 9b8dd0b..24ac70e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
@@ -15,17 +15,17 @@
*/
package com.android.systemui.statusbar;
+import static android.app.Flags.keyguardPrivateNotifications;
import static android.app.StatusBarManager.ACTION_KEYGUARD_PRIVATE_NOTIFICATIONS_CHANGED;
import static android.app.StatusBarManager.EXTRA_KM_PRIVATE_NOTIFS_ALLOWED;
import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
+import static android.os.Flags.allowPrivateProfile;
import static android.os.UserHandle.USER_ALL;
import static android.os.UserHandle.USER_NULL;
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS;
-import static android.app.Flags.keyguardPrivateNotifications;
-import static android.os.Flags.allowPrivateProfile;
import static com.android.systemui.DejankUtils.whitelistIpcs;
@@ -42,9 +42,8 @@
import android.content.IntentSender;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
+import android.database.ExecutorContentObserver;
import android.net.Uri;
-import android.os.Handler;
-import android.os.HandlerExecutor;
import android.os.Looper;
import android.os.UserHandle;
import android.os.UserManager;
@@ -79,17 +78,17 @@
import com.android.systemui.util.ListenerSet;
import com.android.systemui.util.settings.SecureSettings;
+import dagger.Lazy;
+
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.concurrent.Executor;
import java.util.Objects;
+import java.util.concurrent.Executor;
import javax.inject.Inject;
-import dagger.Lazy;
-
/**
* Handles keeping track of the current user, profiles, and various things related to hiding
* contents, redacting notifications, and the lockscreen.
@@ -228,7 +227,7 @@
updateCurrentProfilesCache();
if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
- mBackgroundHandler.post(() -> {
+ mBackgroundExecutor.execute(() -> {
initValuesForUser(userId);
});
}
@@ -289,8 +288,7 @@
};
protected final Context mContext;
- private final Handler mMainHandler;
- private final Handler mBackgroundHandler;
+ private final Executor mMainExecutor;
private final Executor mBackgroundExecutor;
/** The current user and its profiles (possibly including a communal profile). */
protected final SparseArray<UserInfo> mCurrentProfiles = new SparseArray<>();
@@ -313,8 +311,7 @@
Lazy<OverviewProxyService> overviewProxyServiceLazy,
KeyguardManager keyguardManager,
StatusBarStateController statusBarStateController,
- @Main Handler mainHandler,
- @Background Handler backgroundHandler,
+ @Main Executor mainExecutor,
@Background Executor backgroundExecutor,
DeviceProvisionedController deviceProvisionedController,
KeyguardStateController keyguardStateController,
@@ -323,8 +320,7 @@
LockPatternUtils lockPatternUtils,
FeatureFlagsClassic featureFlags) {
mContext = context;
- mMainHandler = mainHandler;
- mBackgroundHandler = backgroundHandler;
+ mMainExecutor = mainExecutor;
mBackgroundExecutor = backgroundExecutor;
mDevicePolicyManager = devicePolicyManager;
mUserManager = userManager;
@@ -362,10 +358,10 @@
}
private void init() {
- mLockscreenSettingsObserver = new ContentObserver(
+ mLockscreenSettingsObserver = new ExecutorContentObserver(
mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)
- ? mBackgroundHandler
- : mMainHandler) {
+ ? mBackgroundExecutor
+ : mMainExecutor) {
@Override
public void onChange(boolean selfChange, Collection<Uri> uris, int flags) {
@@ -412,7 +408,7 @@
}
};
- mSettingsObserver = new ContentObserver(mMainHandler) {
+ mSettingsObserver = new ExecutorContentObserver(mMainExecutor) {
@Override
public void onChange(boolean selfChange) {
updateLockscreenNotificationSetting();
@@ -468,14 +464,14 @@
mContext.registerReceiver(mBaseBroadcastReceiver, internalFilter, PERMISSION_SELF, null,
Context.RECEIVER_EXPORTED_UNAUDITED);
- mUserTracker.addCallback(mUserChangedCallback, new HandlerExecutor(mMainHandler));
+ mUserTracker.addCallback(mUserChangedCallback, mMainExecutor);
mCurrentUserId = mUserTracker.getUserId(); // in case we reg'd receiver too late
updateCurrentProfilesCache();
if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
// Set up
- mBackgroundHandler.post(() -> {
+ mBackgroundExecutor.execute(() -> {
@SuppressLint("MissingPermission") List<UserInfo> users = mUserManager.getUsers();
for (int i = users.size() - 1; i >= 0; i--) {
initValuesForUser(users.get(i).id);
@@ -796,7 +792,7 @@
}
}
}
- mMainHandler.post(() -> {
+ mMainExecutor.execute(() -> {
for (UserChangedListener listener : mListeners) {
listener.onCurrentProfilesChanged(mCurrentProfiles);
}
@@ -895,7 +891,7 @@
private void notifyNotificationStateChanged() {
if (!Looper.getMainLooper().isCurrentThread()) {
- mMainHandler.post(() -> {
+ mMainExecutor.execute(() -> {
for (NotificationStateChangedListener listener : mNotifStateChangedListeners) {
listener.onNotificationStateChanged();
}