Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a41c272 authored by Yuri Lin's avatar Yuri Lin
Browse files

Skip invalidating caches in NotificationManagerServiceTest

The IpcDataCaches used in NotificationManager and invalidated in PreferencesHelper cannot be invalidated in test processes unless the caches are set to test mode. Since this test is not intending to test caching behavior, make sure the component PreferencesHelper doesn't try to invalidate real caches when the test is running.

Most tests in NMSTest use the mock PreferencesHelper anyway, but some do go through the "real" PreferencesHelper object created in TestableNotificationManagerService.init().

Flag: android.app.nm_binder_perf_cache_channels
Bug: 381131846
Test: this
Change-Id: I2f1922b2c5e038b256572add3b7d8514e11562c6
parent efc34112
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.app.ActivityManagerInternal.ServiceNotificationPolicy.NOT_
import static android.app.ActivityManagerInternal.ServiceNotificationPolicy.SHOW_IMMEDIATELY;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.app.Flags.FLAG_KEYGUARD_PRIVATE_NOTIFICATIONS;
import static android.app.Flags.FLAG_NM_BINDER_PERF_CACHE_CHANNELS;
import static android.app.Flags.FLAG_REDACT_SENSITIVE_CONTENT_NOTIFICATIONS_ON_LOCKSCREEN;
import static android.app.Flags.FLAG_SORT_SECTION_BY_TIME;
import static android.app.Notification.EXTRA_ALLOW_DURING_SETUP;
@@ -604,7 +605,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Parameters(name = "{0}")
    public static List<FlagsParameterization> getParams() {
        return FlagsParameterization.allCombinationsOf(
            FLAG_NOTIFICATION_CLASSIFICATION);
            FLAG_NOTIFICATION_CLASSIFICATION, FLAG_NM_BINDER_PERF_CACHE_CHANNELS);
    }
    public NotificationManagerServiceTest(FlagsParameterization flags) {
@@ -826,6 +827,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mService.setAttentionHelper(mAttentionHelper);
        mService.setLockPatternUtils(mock(LockPatternUtils.class));
        // make sure PreferencesHelper doesn't try to interact with any real caches
        PreferencesHelper prefHelper = spy(mService.mPreferencesHelper);
        doNothing().when(prefHelper).invalidateNotificationChannelCache();
        mService.setPreferencesHelper(prefHelper);
        // Return first true for RoleObserver main-thread check
        when(mMainLooper.isCurrentThread()).thenReturn(true).thenReturn(false);
        ModuleInfo moduleInfo = new ModuleInfo();