Do not register for broadcasts within NoMan test.
Fixes potential flake when broadcasts come in after Looper has terminated. Change-Id: Id63d27970b1ffacccfa8f1b074f744b6547ffcf9 Fixes: 63797731 Test: runtest systemui-notification
This commit is contained in:
@@ -1160,7 +1160,7 @@ public class NotificationManagerService extends SystemService {
|
||||
mUsageStats = us;
|
||||
}
|
||||
|
||||
// TODO: Tests should call onStart instead once the methods above are removed.
|
||||
// TODO: All tests should use this init instead of the one-off setters above.
|
||||
@VisibleForTesting
|
||||
void init(Looper looper, IPackageManager packageManager,
|
||||
PackageManager packageManagerClient,
|
||||
@@ -1265,6 +1265,46 @@ public class NotificationManagerService extends SystemService {
|
||||
mUserProfiles.updateCache(getContext());
|
||||
listenForCallState();
|
||||
|
||||
mSettingsObserver = new SettingsObserver(mHandler);
|
||||
|
||||
mArchive = new Archive(resources.getInteger(
|
||||
R.integer.config_notificationServiceArchiveSize));
|
||||
|
||||
mIsTelevision = mPackageManagerClient.hasSystemFeature(FEATURE_LEANBACK)
|
||||
|| mPackageManagerClient.hasSystemFeature(FEATURE_TELEVISION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
SnoozeHelper snoozeHelper = new SnoozeHelper(getContext(), new SnoozeHelper.Callback() {
|
||||
@Override
|
||||
public void repost(int userId, NotificationRecord r) {
|
||||
try {
|
||||
if (DBG) {
|
||||
Slog.d(TAG, "Reposting " + r.getKey());
|
||||
}
|
||||
enqueueNotificationInternal(r.sbn.getPackageName(), r.sbn.getOpPkg(),
|
||||
r.sbn.getUid(), r.sbn.getInitialPid(), r.sbn.getTag(), r.sbn.getId(),
|
||||
r.sbn.getNotification(), userId);
|
||||
} catch (Exception e) {
|
||||
Slog.e(TAG, "Cannot un-snooze notification", e);
|
||||
}
|
||||
}
|
||||
}, mUserProfiles);
|
||||
|
||||
final File systemDir = new File(Environment.getDataDirectory(), "system");
|
||||
|
||||
init(Looper.myLooper(),
|
||||
AppGlobals.getPackageManager(), getContext().getPackageManager(),
|
||||
getLocalService(LightsManager.class),
|
||||
new NotificationListeners(AppGlobals.getPackageManager()),
|
||||
new NotificationAssistants(AppGlobals.getPackageManager()),
|
||||
new ConditionProviders(getContext(), mUserProfiles, AppGlobals.getPackageManager()),
|
||||
null, snoozeHelper, new NotificationUsageStats(getContext()),
|
||||
new AtomicFile(new File(systemDir, "notification_policy.xml")),
|
||||
(ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE),
|
||||
getGroupHelper());
|
||||
|
||||
// register for various Intents
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
@@ -1305,45 +1345,6 @@ public class NotificationManagerService extends SystemService {
|
||||
IntentFilter settingsRestoredFilter = new IntentFilter(Intent.ACTION_SETTING_RESTORED);
|
||||
getContext().registerReceiver(mRestoreReceiver, settingsRestoredFilter);
|
||||
|
||||
mSettingsObserver = new SettingsObserver(mHandler);
|
||||
|
||||
mArchive = new Archive(resources.getInteger(
|
||||
R.integer.config_notificationServiceArchiveSize));
|
||||
|
||||
mIsTelevision = mPackageManagerClient.hasSystemFeature(FEATURE_LEANBACK)
|
||||
|| mPackageManagerClient.hasSystemFeature(FEATURE_TELEVISION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
SnoozeHelper snoozeHelper = new SnoozeHelper(getContext(), new SnoozeHelper.Callback() {
|
||||
@Override
|
||||
public void repost(int userId, NotificationRecord r) {
|
||||
try {
|
||||
if (DBG) {
|
||||
Slog.d(TAG, "Reposting " + r.getKey());
|
||||
}
|
||||
enqueueNotificationInternal(r.sbn.getPackageName(), r.sbn.getOpPkg(),
|
||||
r.sbn.getUid(), r.sbn.getInitialPid(), r.sbn.getTag(), r.sbn.getId(),
|
||||
r.sbn.getNotification(), userId);
|
||||
} catch (Exception e) {
|
||||
Slog.e(TAG, "Cannot un-snooze notification", e);
|
||||
}
|
||||
}
|
||||
}, mUserProfiles);
|
||||
|
||||
final File systemDir = new File(Environment.getDataDirectory(), "system");
|
||||
|
||||
init(Looper.myLooper(),
|
||||
AppGlobals.getPackageManager(), getContext().getPackageManager(),
|
||||
getLocalService(LightsManager.class),
|
||||
new NotificationListeners(AppGlobals.getPackageManager()),
|
||||
new NotificationAssistants(AppGlobals.getPackageManager()),
|
||||
new ConditionProviders(getContext(), mUserProfiles, AppGlobals.getPackageManager()),
|
||||
null, snoozeHelper, new NotificationUsageStats(getContext()),
|
||||
new AtomicFile(new File(systemDir, "notification_policy.xml")),
|
||||
(ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE),
|
||||
getGroupHelper());
|
||||
publishBinderService(Context.NOTIFICATION_SERVICE, mService);
|
||||
publishLocalService(NotificationManagerInternal.class, mInternalService);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user