summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jan Tomljanovic <jtomljanovic@google.com> 2020-12-09 20:17:42 +0000
committer Jan Tomljanovic <jtomljanovic@google.com> 2020-12-10 11:31:45 +0000
commit6129cfa7aff92e8d76f1f36f6e272d388a32f863 (patch)
tree61f96bcdeb90ae3c1d4f8d277caa07b08a7b8fc2
parent7bd311cf7a957729c5d6f95975654358bcedc4b7 (diff)
Fix the bug where inner lock in MultiRateLimiter is null.
The bug would occur when Mockito stopped mocking methods when the test is done, but the mocked object still exists, and is then accessed as a scheduled message triggers it. Test: atest NotificationManagerServiceTest Bug: 174997218 Change-Id: I3c76456927bb0c27945b137187011b5eb3c7102c
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 849477c924bb..dcb6ee702ecb 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -305,6 +305,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
@Mock
StatusBarManagerInternal mStatusBar;
+ private NotificationManagerService.WorkerHandler mWorkerHandler;
+
// Use a Testable subclass so we can simulate calls from the system without failing.
private static class TestableNotificationManagerService extends NotificationManagerService {
int countSystemChecks = 0;
@@ -482,14 +484,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mAssistants.isAdjustmentAllowed(anyString())).thenReturn(true);
- mService.init(mService.new WorkerHandler(mTestableLooper.getLooper()),
- mRankingHandler, mPackageManager, mPackageManagerClient, mockLightsManager,
- mListeners, mAssistants, mConditionProviders,
- mCompanionMgr, mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager,
- mGroupHelper, mAm, mAtm, mAppUsageStats,
- mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal,
- mAppOpsManager, mUm, mHistoryManager, mStatsManager,
- mock(TelephonyManager.class), mAmi, mToastRateLimiter);
+ mWorkerHandler = mService.new WorkerHandler(mTestableLooper.getLooper());
+ mService.init(mWorkerHandler, mRankingHandler, mPackageManager, mPackageManagerClient,
+ mockLightsManager, mListeners, mAssistants, mConditionProviders, mCompanionMgr,
+ mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager, mGroupHelper, mAm, mAtm,
+ mAppUsageStats, mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal,
+ mAppOpsManager, mUm, mHistoryManager, mStatsManager, mock(TelephonyManager.class),
+ mAmi, mToastRateLimiter);
mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
mService.setAudioManager(mAudioManager);
@@ -575,6 +576,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
InstrumentationRegistry.getInstrumentation()
.getUiAutomation().dropShellPermissionIdentity();
+ // Remove scheduled messages that would be processed when the test is already done, and
+ // could cause issues, for example, messages that remove/cancel shown toasts (this causes
+ // problematic interactions with mocks when they're no longer working as expected).
+ mWorkerHandler.removeCallbacksAndMessages(null);
}
private void simulatePackageSuspendBroadcast(boolean suspend, String pkg,