diff options
author | Rohan Shah <shahrk@google.com> | 2018-04-10 12:30:33 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-04-10 12:30:33 -0700 |
commit | 02adb97ec2eccb84f7ad5f0b16b8f091c3e3641a (patch) | |
tree | 97d6c76b7b304f2e81044bcdbd20cb8ded227257 | |
parent | 9444ab876989ec20ef543c497384214237fc6e37 (diff) | |
parent | cef38b383c76b8a1f1a52f971fc6939747c37879 (diff) |
Merge "[Notif] Show block message for notif with multiple channels" into pi-dev am: a4dab5d1ea
am: cef38b383c
Change-Id: I86a0cf579f6c6d7e2a486c80c90aaa611627547c
4 files changed, 166 insertions, 47 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 58bc4dd1e8e6..87e6608a576a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -436,19 +436,13 @@ public class ExpandableNotificationRow extends ActivatableNotificationView } /** - * Returns whether this row is considered non-blockable (e.g. it's a non-blockable system notif, - * covers multiple channels, or is in a whitelist). + * Returns whether this row is considered non-blockable (i.e. it's a non-blockable system notif + * or is in a whitelist). */ public boolean getIsNonblockable() { boolean isNonblockable = Dependency.get(NotificationBlockingHelperManager.class) .isNonblockablePackage(mStatusBarNotification.getPackageName()); - // Only bother with going through the children if the row is still blockable based on the - // number of unique channels. - if (!isNonblockable) { - isNonblockable = getNumUniqueChannels() > 1; - } - // If the SystemNotifAsyncTask hasn't finished running or retrieved a value, we'll try once // again, but in-place on the main thread this time. This should rarely ever get called. if (mIsSystemNotification == null) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java index 6238526a521f..81dd9e8c3d87 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java @@ -23,6 +23,7 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; +import android.annotation.Nullable; import android.app.INotificationManager; import android.app.Notification; import android.app.NotificationChannel; @@ -34,10 +35,12 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.drawable.Drawable; +import android.os.Handler; import android.os.RemoteException; import android.service.notification.StatusBarNotification; import android.text.TextUtils; import android.util.AttributeSet; +import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; @@ -63,10 +66,10 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G private INotificationManager mINotificationManager; private PackageManager mPm; - private String mPkg; + private String mPackageName; private String mAppName; private int mAppUid; - private int mNumNotificationChannels; + private int mNumUniqueChannelsInRow; private NotificationChannel mSingleNotificationChannel; private int mStartingUserImportance; private int mChosenImportance; @@ -87,7 +90,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G private OnClickListener mOnKeepShowing = this::closeControls; - private OnClickListener mOnStopMinNotifications = v -> { + private OnClickListener mOnStopOrMinimizeNotifications = v -> { swapContent(false); }; @@ -120,16 +123,16 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G final INotificationManager iNotificationManager, final String pkg, final NotificationChannel notificationChannel, - final int numChannels, + final int numUniqueChannelsInRow, final StatusBarNotification sbn, final CheckSaveListener checkSaveListener, final OnSettingsClickListener onSettingsClick, final OnAppSettingsClickListener onAppSettingsClick, boolean isNonblockable) throws RemoteException { - bindNotification(pm, iNotificationManager, pkg, notificationChannel, numChannels, sbn, - checkSaveListener, onSettingsClick, onAppSettingsClick, isNonblockable, - false /* isBlockingHelper */, + bindNotification(pm, iNotificationManager, pkg, notificationChannel, + numUniqueChannelsInRow, sbn, checkSaveListener, onSettingsClick, + onAppSettingsClick, isNonblockable, false /* isBlockingHelper */, false /* isUserSentimentNegative */); } @@ -138,7 +141,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G INotificationManager iNotificationManager, String pkg, NotificationChannel notificationChannel, - int numChannels, + int numUniqueChannelsInRow, StatusBarNotification sbn, CheckSaveListener checkSaveListener, OnSettingsClickListener onSettingsClick, @@ -148,12 +151,12 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G boolean isUserSentimentNegative) throws RemoteException { mINotificationManager = iNotificationManager; - mPkg = pkg; - mNumNotificationChannels = numChannels; + mPackageName = pkg; + mNumUniqueChannelsInRow = numUniqueChannelsInRow; mSbn = sbn; mPm = pm; mAppSettingsClickListener = onAppSettingsClick; - mAppName = mPkg; + mAppName = mPackageName; mCheckSaveListener = checkSaveListener; mOnSettingsClickListener = onSettingsClick; mSingleNotificationChannel = notificationChannel; @@ -167,11 +170,11 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage( pkg, mAppUid, false /* includeDeleted */); - if (mNumNotificationChannels == 0) { + if (mNumUniqueChannelsInRow == 0) { throw new IllegalArgumentException("bindNotification requires at least one channel"); } else { // Special behavior for the Default channel if no other channels have been defined. - mIsSingleDefaultChannel = mNumNotificationChannels == 1 + mIsSingleDefaultChannel = mNumUniqueChannelsInRow == 1 && mSingleNotificationChannel.getId().equals( NotificationChannel.DEFAULT_CHANNEL_ID) && numTotalChannels == 1; @@ -187,7 +190,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G Drawable pkgicon = null; ApplicationInfo info; try { - info = mPm.getApplicationInfo(mPkg, + info = mPm.getApplicationInfo( + mPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.MATCH_DIRECT_BOOT_UNAWARE @@ -208,7 +212,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) { final NotificationChannelGroup notificationChannelGroup = mINotificationManager.getNotificationChannelGroupForPackage( - mSingleNotificationChannel.getGroup(), mPkg, mAppUid); + mSingleNotificationChannel.getGroup(), mPackageName, mAppUid); if (notificationChannelGroup != null) { groupName = notificationChannelGroup.getName(); } @@ -232,7 +236,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G settingsButton.setOnClickListener( (View view) -> { mOnSettingsClickListener.onClick(view, - mNumNotificationChannels > 1 ? null : mSingleNotificationChannel, + mNumUniqueChannelsInRow > 1 ? null : mSingleNotificationChannel, appUidF); }); } else { @@ -248,7 +252,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G } else { if (mNegativeUserSentiment) { blockPrompt.setText(R.string.inline_blocking_helper); - } else if (mIsSingleDefaultChannel || mNumNotificationChannels > 1) { + } else if (mIsSingleDefaultChannel || mNumUniqueChannelsInRow > 1) { blockPrompt.setText(R.string.inline_keep_showing_app); } else { blockPrompt.setText(R.string.inline_keep_showing); @@ -258,7 +262,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G private void bindName() { final TextView channelName = findViewById(R.id.channel_name); - if (mIsSingleDefaultChannel || mNumNotificationChannels > 1) { + if (mIsSingleDefaultChannel || mNumUniqueChannelsInRow > 1) { channelName.setVisibility(View.GONE); } else { channelName.setText(mSingleNotificationChannel.getName()); @@ -270,19 +274,26 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G } private void saveImportance() { - if (mIsNonblockable) { - return; + if (!mIsNonblockable) { + if (mCheckSaveListener != null) { + mCheckSaveListener.checkSave(this::updateImportance, mSbn); + } else { + updateImportance(); + } } + } + + /** + * Commits the updated importance values on the background thread. + */ + private void updateImportance() { MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE, mChosenImportance - mStartingUserImportance); - mSingleNotificationChannel.setImportance(mChosenImportance); - mSingleNotificationChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); - try { - mINotificationManager.updateNotificationChannelForPackage( - mPkg, mAppUid, mSingleNotificationChannel); - } catch (RemoteException e) { - // :( - } + + Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER)); + bgHandler.post(new UpdateImportanceRunnable(mINotificationManager, mPackageName, mAppUid, + mNumUniqueChannelsInRow == 1 ? mSingleNotificationChannel : null, + mStartingUserImportance, mChosenImportance)); } private void bindButtons() { @@ -292,9 +303,9 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G View minimize = findViewById(R.id.minimize); findViewById(R.id.undo).setOnClickListener(mOnUndo); - block.setOnClickListener(mOnStopMinNotifications); + block.setOnClickListener(mOnStopOrMinimizeNotifications); keep.setOnClickListener(mOnKeepShowing); - minimize.setOnClickListener(mOnStopMinNotifications); + minimize.setOnClickListener(mOnStopOrMinimizeNotifications); if (mIsNonblockable) { keep.setText(R.string.notification_done); @@ -310,7 +321,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G // Set up app settings link (i.e. Customize) TextView settingsLinkView = findViewById(R.id.app_settings); - Intent settingsIntent = getAppSettingsIntent(mPm, mPkg, mSingleNotificationChannel, + Intent settingsIntent = getAppSettingsIntent(mPm, mPackageName, mSingleNotificationChannel, mSbn.getId(), mSbn.getTag()); if (!mIsForBlockingHelper && settingsIntent != null @@ -415,12 +426,25 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G return intent; } + /** + * Closes the controls and commits the updated importance values (indirectly). If this view is + * being used to show the blocking helper, this will immediately dismiss the blocking helper and + * commit the updated importance. + * + * <p><b>Note,</b> this will only get called once the view is dismissing. This means that the + * user does not have the ability to undo the action anymore. See {@link #swapContent(boolean)} + * for where undo is handled. + */ @VisibleForTesting void closeControls(View v) { if (mIsForBlockingHelper) { NotificationBlockingHelperManager manager = Dependency.get(NotificationBlockingHelperManager.class); manager.dismissCurrentBlockingHelper(); + + // Since this won't get a callback via gutsContainer.closeControls, save the new + // importance values immediately. + saveImportance(); } else { int[] parentLoc = new int[2]; int[] targetLoc = new int[2]; @@ -454,11 +478,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G // Save regardless of the importance so we can lock the importance field if the user wants // to keep getting notifications if (save) { - if (mCheckSaveListener != null) { - mCheckSaveListener.checkSave(this::saveImportance, mSbn); - } else { - saveImportance(); - } + saveImportance(); } return false; } @@ -467,4 +487,48 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G public int getActualHeight() { return getHeight(); } + + /** + * Runnable to either update the given channel (with a new importance value) or, if no channel + * is provided, update notifications enabled state for the package. + */ + private static class UpdateImportanceRunnable implements Runnable { + private final INotificationManager mINotificationManager; + private final String mPackageName; + private final int mAppUid; + private final @Nullable NotificationChannel mChannelToUpdate; + private final int mCurrentImportance; + private final int mNewImportance; + + + public UpdateImportanceRunnable(INotificationManager notificationManager, + String packageName, int appUid, @Nullable NotificationChannel channelToUpdate, + int currentImportance, int newImportance) { + mINotificationManager = notificationManager; + mPackageName = packageName; + mAppUid = appUid; + mChannelToUpdate = channelToUpdate; + mCurrentImportance = currentImportance; + mNewImportance = newImportance; + } + + @Override + public void run() { + try { + if (mChannelToUpdate != null) { + mChannelToUpdate.setImportance(mNewImportance); + mChannelToUpdate.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); + mINotificationManager.updateNotificationChannelForPackage( + mPackageName, mAppUid, mChannelToUpdate); + } else { + // For notifications with more than one channel, update notification enabled + // state. If the importance was lowered, we disable notifications. + mINotificationManager.setNotificationsEnabledForPackage( + mPackageName, mAppUid, mNewImportance >= mCurrentImportance); + } + } catch (RemoteException e) { + Log.e(TAG, "Unable to update notification importance", e); + } + } + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java index 658ac73153ab..3cbe27430d47 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java @@ -52,17 +52,20 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.drawable.Drawable; +import android.os.Looper; import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.PollingCheck; +import android.testing.TestableLooper; import android.testing.UiThreadTest; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; @@ -81,7 +84,7 @@ import java.util.concurrent.CountDownLatch; @SmallTest @RunWith(AndroidTestingRunner.class) -@UiThreadTest +@TestableLooper.RunWithLooper public class NotificationInfoTest extends SysuiTestCase { private static final String TEST_PACKAGE_NAME = "test_package"; private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; @@ -90,12 +93,14 @@ public class NotificationInfoTest extends SysuiTestCase { private static final String TEST_CHANNEL = "test_channel"; private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; + private TestableLooper mTestableLooper; private NotificationInfo mNotificationInfo; private NotificationChannel mNotificationChannel; private NotificationChannel mDefaultNotificationChannel; private StatusBarNotification mSbn; @Rule public MockitoRule mockito = MockitoJUnit.rule(); + private Looper mLooper; @Mock private INotificationManager mMockINotificationManager; @Mock private PackageManager mMockPackageManager; @Mock private NotificationBlockingHelperManager mBlockingHelperManager; @@ -105,7 +110,8 @@ public class NotificationInfoTest extends SysuiTestCase { mDependency.injectTestDependency( NotificationBlockingHelperManager.class, mBlockingHelperManager); - + mTestableLooper = TestableLooper.get(this); + mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper()); // Inflate the layout final LayoutInflater layoutInflater = LayoutInflater.from(mContext); mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, @@ -355,6 +361,7 @@ public class NotificationInfoTest extends SysuiTestCase { public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), eq(TEST_UID), any()); } @@ -366,6 +373,7 @@ public class NotificationInfoTest extends SysuiTestCase { TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); mNotificationInfo.findViewById(R.id.block).performClick(); + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), eq(TEST_UID), any()); } @@ -378,6 +386,7 @@ public class NotificationInfoTest extends SysuiTestCase { TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); mNotificationInfo.findViewById(R.id.minimize).performClick(); + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), eq(TEST_UID), any()); } @@ -390,6 +399,7 @@ public class NotificationInfoTest extends SysuiTestCase { TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); mNotificationInfo.handleCloseControls(true, false); + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( anyString(), eq(TEST_UID), any()); assertEquals(originalImportance, mNotificationChannel.getImportance()); @@ -403,6 +413,8 @@ public class NotificationInfoTest extends SysuiTestCase { TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); mNotificationInfo.handleCloseControls(true, false); + + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( anyString(), eq(TEST_UID), any()); assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance()); @@ -436,6 +448,8 @@ public class NotificationInfoTest extends SysuiTestCase { TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); mNotificationInfo.findViewById(R.id.block).performClick(); waitForUndoButton(); + + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), eq(TEST_UID), any()); } @@ -450,6 +464,7 @@ public class NotificationInfoTest extends SysuiTestCase { waitForUndoButton(); mNotificationInfo.handleCloseControls(true, false); + mTestableLooper.processAllMessages(); ArgumentCaptor<NotificationChannel> updated = ArgumentCaptor.forClass(NotificationChannel.class); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( @@ -460,12 +475,46 @@ public class NotificationInfoTest extends SysuiTestCase { } @Test + public void testBlockChangedCallsUpdateNotificationChannel_blockingHelper() throws Exception { + mNotificationChannel.setImportance(IMPORTANCE_LOW); + mNotificationInfo.bindNotification( + mMockPackageManager, + mMockINotificationManager, + TEST_PACKAGE_NAME, + mNotificationChannel, + 1 /* numChannels */, + mSbn, + null /* checkSaveListener */, + null /* onSettingsClick */, + null /* onAppSettingsClick */, + false /* isNonblockable */, + true /* isForBlockingHelper */, + true /* isUserSentimentNegative */); + + mNotificationInfo.findViewById(R.id.block).performClick(); + waitForUndoButton(); + mNotificationInfo.handleCloseControls(true, false); + + mTestableLooper.processAllMessages(); + ArgumentCaptor<NotificationChannel> updated = + ArgumentCaptor.forClass(NotificationChannel.class); + verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( + anyString(), eq(TEST_UID), updated.capture()); + assertTrue((updated.getValue().getUserLockedFields() + & USER_LOCKED_IMPORTANCE) != 0); + assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance()); + } + + + @Test public void testNonBlockableAppDoesNotBecomeMin() throws Exception { mNotificationChannel.setImportance(IMPORTANCE_LOW); mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); mNotificationInfo.findViewById(R.id.minimize).performClick(); waitForUndoButton(); + + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), eq(TEST_UID), any()); } @@ -481,6 +530,7 @@ public class NotificationInfoTest extends SysuiTestCase { waitForUndoButton(); mNotificationInfo.handleCloseControls(true, false); + mTestableLooper.processAllMessages(); ArgumentCaptor<NotificationChannel> updated = ArgumentCaptor.forClass(NotificationChannel.class); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( @@ -498,6 +548,7 @@ public class NotificationInfoTest extends SysuiTestCase { mNotificationInfo.handleCloseControls(true, false); + mTestableLooper.processAllMessages(); ArgumentCaptor<NotificationChannel> updated = ArgumentCaptor.forClass(NotificationChannel.class); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( @@ -518,6 +569,7 @@ public class NotificationInfoTest extends SysuiTestCase { waitForStopButton(); mNotificationInfo.handleCloseControls(true, false); + mTestableLooper.processAllMessages(); ArgumentCaptor<NotificationChannel> updated = ArgumentCaptor.forClass(NotificationChannel.class); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( @@ -538,6 +590,7 @@ public class NotificationInfoTest extends SysuiTestCase { waitForStopButton(); mNotificationInfo.handleCloseControls(true, false); + mTestableLooper.processAllMessages(); ArgumentCaptor<NotificationChannel> updated = ArgumentCaptor.forClass(NotificationChannel.class); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( @@ -555,6 +608,8 @@ public class NotificationInfoTest extends SysuiTestCase { mNotificationInfo.findViewById(R.id.minimize).performClick(); waitForUndoButton(); mNotificationInfo.handleCloseControls(false, false); + + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); } @@ -568,6 +623,8 @@ public class NotificationInfoTest extends SysuiTestCase { mNotificationInfo.findViewById(R.id.block).performClick(); waitForUndoButton(); mNotificationInfo.handleCloseControls(false, false); + + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); } @@ -583,6 +640,8 @@ public class NotificationInfoTest extends SysuiTestCase { mNotificationInfo.findViewById(R.id.block).performClick(); waitForUndoButton(); mNotificationInfo.handleCloseControls(true, false); + + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); } @@ -599,6 +658,8 @@ public class NotificationInfoTest extends SysuiTestCase { mNotificationInfo.findViewById(R.id.block).performClick(); waitForUndoButton(); mNotificationInfo.handleCloseControls(true, false); + + mTestableLooper.processAllMessages(); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 7813e70e86a7..7e04d3337e68 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2066,7 +2066,7 @@ public class NotificationManagerService extends SystemService { @Override public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) { - checkCallerIsSystem(); + enforceSystemOrSystemUI("setNotificationsEnabledForPackage"); mRankingHelper.setEnabled(pkg, uid, enabled); // Now, cancel any outstanding notifications that are part of a just-disabled app |