diff options
| author | 2023-12-21 19:21:03 +0000 | |
|---|---|---|
| committer | 2024-01-10 14:13:49 +0000 | |
| commit | 52c6a8bb12b2a4c42ed874dd1b08a0dd9d75fa1c (patch) | |
| tree | 5178b6cb927cb80a8a75a4feff834833daf35c60 | |
| parent | 79dd61236e51a31d5f6557af37fdbd34e5771345 (diff) | |
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
| -rw-r--r-- | packages/SystemUI/Android.bp | 1 | ||||
| -rw-r--r-- | packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java (renamed from packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java) | 19 | ||||
| -rw-r--r-- | packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java (renamed from packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java) | 12 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java | 40 | 
4 files changed, 27 insertions, 45 deletions
diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp index d3a89f447d1f..d61ae7eccc42 100644 --- a/packages/SystemUI/Android.bp +++ b/packages/SystemUI/Android.bp @@ -438,6 +438,7 @@ android_robolectric_test {          "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 index 01fe40f6dff6..d0e05fa60114 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.Intent;  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.Collection;  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 @@ public class NotificationLockscreenUserManagerMainThreadTest extends SysuiTestCa      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 @@ public class NotificationLockscreenUserManagerMainThreadTest extends SysuiTestCa                  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 @@ public class NotificationLockscreenUserManagerMainThreadTest extends SysuiTestCa          // 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 @@ public class NotificationLockscreenUserManagerMainThreadTest extends SysuiTestCa                      (() -> 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 index 757f16cac227..bcc0710359cc 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.Flags.FLAG_ALLOW_PRIVATE_PROFILE;  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.DisableFlags;  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.statusbar.policy.KeyguardStateController;  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 @@ import platform.test.runner.parameterized.Parameters;  @SmallTest  @RunWith(ParameterizedAndroidJunit4.class) -@TestableLooper.RunWithLooper  public class NotificationLockscreenUserManagerTest extends SysuiTestCase {      @Parameters(name = "{0}") @@ -197,8 +196,6 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {                  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 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {                      (() -> 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 9b8dd0b75a24..24ac70e63e46 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.IntentFilter;  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.statusbar.policy.KeyguardStateController;  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 @@ public class NotificationLockscreenUserManagerImpl implements                  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 @@ public class NotificationLockscreenUserManagerImpl implements              };      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 @@ public class NotificationLockscreenUserManagerImpl implements              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 @@ public class NotificationLockscreenUserManagerImpl implements              LockPatternUtils lockPatternUtils,              FeatureFlagsClassic featureFlags) {          mContext = context; -        mMainHandler = mainHandler; -        mBackgroundHandler = backgroundHandler; +        mMainExecutor = mainExecutor;          mBackgroundExecutor = backgroundExecutor;          mDevicePolicyManager = devicePolicyManager;          mUserManager = userManager; @@ -362,10 +358,10 @@ public class NotificationLockscreenUserManagerImpl implements      }      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 @@ public class NotificationLockscreenUserManagerImpl implements              }          }; -        mSettingsObserver = new ContentObserver(mMainHandler) { +        mSettingsObserver = new ExecutorContentObserver(mMainExecutor) {              @Override              public void onChange(boolean selfChange) {                  updateLockscreenNotificationSetting(); @@ -468,14 +464,14 @@ public class NotificationLockscreenUserManagerImpl implements          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 @@ public class NotificationLockscreenUserManagerImpl implements                  }              }          } -        mMainHandler.post(() -> { +        mMainExecutor.execute(() -> {              for (UserChangedListener listener : mListeners) {                  listener.onCurrentProfilesChanged(mCurrentProfiles);              } @@ -895,7 +891,7 @@ public class NotificationLockscreenUserManagerImpl implements      private void notifyNotificationStateChanged() {          if (!Looper.getMainLooper().isCurrentThread()) { -            mMainHandler.post(() -> { +            mMainExecutor.execute(() -> {                  for (NotificationStateChangedListener listener : mNotifStateChangedListeners) {                      listener.onNotificationStateChanged();                  }  |