diff options
author | 2023-09-26 19:50:28 +0000 | |
---|---|---|
committer | 2023-09-26 19:50:28 +0000 | |
commit | cab681542a0710c0308415d78686b7e31edefb64 (patch) | |
tree | 85d9a7e83de3ca44a75692e38dbec549fc905105 | |
parent | e4988b458ea088aeb479c17e3611dbb98925f121 (diff) | |
parent | e5e74e731cb4aa4816792b4daf7be045121889cc (diff) |
Merge "Updates to notif channel blocking UI" into main
19 files changed, 227 insertions, 362 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 7f38b27c12c8..ec5effd0963d 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -98,6 +98,7 @@ interface INotificationManager ParceledListSlice getNotificationChannelGroupsForPackage(String pkg, int uid, boolean includeDeleted); NotificationChannelGroup getNotificationChannelGroupForPackage(String groupId, String pkg, int uid); NotificationChannelGroup getPopulatedNotificationChannelGroupForPackage(String pkg, int uid, String groupId, boolean includeDeleted); + ParceledListSlice getRecentBlockedNotificationChannelGroupsForPackage(String pkg, int uid); void updateNotificationChannelGroupForPackage(String pkg, int uid, in NotificationChannelGroup group); void updateNotificationChannelForPackage(String pkg, int uid, in NotificationChannel channel); void unlockNotificationChannel(String pkg, int uid, String channelId); diff --git a/packages/SystemUI/res/layout/notif_half_shelf.xml b/packages/SystemUI/res/layout/notif_half_shelf.xml index 37b8ae0f40c4..c70f8e2b1c07 100644 --- a/packages/SystemUI/res/layout/notif_half_shelf.xml +++ b/packages/SystemUI/res/layout/notif_half_shelf.xml @@ -22,8 +22,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal|bottom" android:paddingStart="4dp" - android:paddingEnd="4dp" -> + android:paddingEnd="4dp"> <LinearLayout android:id="@+id/half_shelf" @@ -82,11 +81,21 @@ android:theme="@style/MainSwitch.Settingslib"/> </com.android.systemui.statusbar.notification.row.AppControlView> - <!-- ChannelRows get added dynamically --> - + <ScrollView + android:layout_width="match_parent" + android:layout_height="@dimen/notification_blocker_channel_list_height" + android:clipToPadding="false"> + <LinearLayout + android:id="@+id/scrollView" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + <!-- ChannelRows get added dynamically --> + </LinearLayout> + </ScrollView> </com.android.systemui.statusbar.notification.row.ChannelEditorListView> - <RelativeLayout + <LinearLayout android:id="@+id/bottom_actions" android:layout_width="match_parent" android:layout_height="wrap_content" @@ -98,25 +107,23 @@ android:text="@string/see_more_title" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentStart="true" - android:layout_centerVertical="true" - android:gravity="start|center_vertical" android:minWidth="@dimen/notification_importance_toggle_size" android:minHeight="@dimen/notification_importance_toggle_size" android:maxWidth="200dp" style="@style/Widget.Dialog.Button"/> + <Space + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" /> <TextView android:id="@+id/done_button" android:text="@string/inline_ok_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerVertical="true" - android:gravity="end|center_vertical" android:maxWidth="125dp" android:minWidth="@dimen/notification_importance_toggle_size" android:minHeight="@dimen/notification_importance_toggle_size" - android:layout_alignParentEnd="true" style="@style/Widget.Dialog.Button"/> - </RelativeLayout> + </LinearLayout> </LinearLayout> </FrameLayout> diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml index 259b9adf0209..cfb40171cfc1 100644 --- a/packages/SystemUI/res/values-land/dimens.xml +++ b/packages/SystemUI/res/values-land/dimens.xml @@ -89,6 +89,9 @@ <dimen name="global_actions_button_size">72dp</dimen> <dimen name="global_actions_button_padding">26dp</dimen> + <!-- scroll view the size of 2 channel rows --> + <dimen name="notification_blocker_channel_list_height">128dp</dimen> + <dimen name="keyguard_indication_margin_bottom">8dp</dimen> <dimen name="lock_icon_margin_bottom">24dp</dimen> </resources> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index d5658dcf0f8e..0ee5da22a31b 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -313,6 +313,8 @@ <!-- The space around a notification menu item --> <dimen name="notification_menu_icon_padding">20dp</dimen> + <!-- scroll view the size of 3 channel rows --> + <dimen name="notification_blocker_channel_list_height">192dp</dimen> <!-- The vertical space around the buttons in the inline settings --> <dimen name="notification_guts_button_spacing">12dp</dimen> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogController.kt index 4114eb2a7896..a8d59d83d1e9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogController.kt @@ -71,15 +71,15 @@ class ChannelEditorDialogController @Inject constructor( private var appUid: Int? = null private var packageName: String? = null private var appName: String? = null + private var channel: NotificationChannel? = null private var onSettingsClickListener: NotificationInfo.OnSettingsClickListener? = null // Caller should set this if they care about when we dismiss var onFinishListener: OnChannelEditorDialogFinishedListener? = null - @VisibleForTesting - internal val paddedChannels = mutableListOf<NotificationChannel>() // Channels handed to us from NotificationInfo - private val providedChannels = mutableListOf<NotificationChannel>() + @VisibleForTesting + internal val channelList = mutableListOf<NotificationChannel>() // Map from NotificationChannel to importance private val edits = mutableMapOf<NotificationChannel, Int>() @@ -93,14 +93,14 @@ class ChannelEditorDialogController @Inject constructor( private val channelGroupList = mutableListOf<NotificationChannelGroup>() /** - * Give the controller all of the information it needs to present the dialog + * Give the controller all the information it needs to present the dialog * for a given app. Does a bunch of querying of NoMan, but won't present anything yet */ fun prepareDialogForApp( appName: String, packageName: String, uid: Int, - channels: Set<NotificationChannel>, + channel: NotificationChannel, appIcon: Drawable, onSettingsClickListener: NotificationInfo.OnSettingsClickListener? ) { @@ -110,6 +110,7 @@ class ChannelEditorDialogController @Inject constructor( this.appIcon = appIcon this.appNotificationsEnabled = checkAreAppNotificationsOn() this.onSettingsClickListener = onSettingsClickListener + this.channel = channel // These will always start out the same appNotificationsCurrentlyEnabled = appNotificationsEnabled @@ -117,9 +118,7 @@ class ChannelEditorDialogController @Inject constructor( channelGroupList.clear() channelGroupList.addAll(fetchNotificationChannelGroups()) buildGroupNameLookup() - providedChannels.clear() - providedChannels.addAll(channels) - padToFourChannels(channels) + populateChannelList() initDialog() prepared = true @@ -133,36 +132,26 @@ class ChannelEditorDialogController @Inject constructor( } } - private fun padToFourChannels(channels: Set<NotificationChannel>) { - paddedChannels.clear() - // First, add all of the given channels - paddedChannels.addAll(channels.asSequence().take(4)) - - // Then pad to 4 if we haven't been given that many - paddedChannels.addAll(getDisplayableChannels(channelGroupList.asSequence()) - .filterNot { paddedChannels.contains(it) } - .distinct() - .take(4 - paddedChannels.size)) - - // If we only got one channel and it has the default miscellaneous tag, then we actually - // are looking at an app with a targetSdk <= O, and it doesn't make much sense to show the - // channel - if (paddedChannels.size == 1 && DEFAULT_CHANNEL_ID == paddedChannels[0].id) { - paddedChannels.clear() + private fun populateChannelList() { + channelList.clear() + if (DEFAULT_CHANNEL_ID != channel!!.id) { + channelList.add(0, channel!!) + channelList.addAll(getDisplayableChannels(channelGroupList.asSequence()) + .filterNot { it.id == channel!!.id } + .distinct()) } } private fun getDisplayableChannels( groupList: Sequence<NotificationChannelGroup> ): Sequence<NotificationChannel> { - - // TODO (b/194833441): remove channel level settings when we move to a permission val channels = groupList .flatMap { group -> - group.channels.asSequence().filterNot { channel -> - channel.importance == IMPORTANCE_NONE || + group.channels.asSequence() + .sortedWith(compareBy {group.name?.toString() ?: group.id}) + .filterNot { channel -> channel.isImportanceLockedByCriticalDeviceFunction - } + } } // TODO: sort these by avgSentWeekly, but for now let's just do alphabetical (why not) @@ -196,8 +185,7 @@ class ChannelEditorDialogController @Inject constructor( appNotificationsCurrentlyEnabled = null edits.clear() - paddedChannels.clear() - providedChannels.clear() + channelList.clear() groupNameLookup.clear() } @@ -231,7 +219,7 @@ class ChannelEditorDialogController @Inject constructor( @Suppress("unchecked_cast") private fun fetchNotificationChannelGroups(): List<NotificationChannelGroup> { return try { - noMan.getNotificationChannelGroupsForPackage(packageName!!, appUid!!, false) + noMan.getRecentBlockedNotificationChannelGroupsForPackage(packageName!!, appUid!!) .list as? List<NotificationChannelGroup> ?: listOf() } catch (e: Exception) { Log.e(TAG, "Error fetching channel groups", e) @@ -280,7 +268,6 @@ class ChannelEditorDialogController @Inject constructor( @VisibleForTesting fun launchSettings(sender: View) { - val channel = if (providedChannels.size == 1) providedChannels[0] else null onSettingsClickListener?.onClick(sender, channel, appUid!!) } @@ -301,14 +288,12 @@ class ChannelEditorDialogController @Inject constructor( controller = this@ChannelEditorDialogController appIcon = this@ChannelEditorDialogController.appIcon appName = this@ChannelEditorDialogController.appName - channels = paddedChannels + channels = channelList } setOnShowListener { - // play a highlight animation for the given channels - for (channel in providedChannels) { - listView?.highlightChannel(channel) - } + // play a highlight animation for the given channel + listView?.highlightChannel(channel!!) } findViewById<TextView>(R.id.done_button)?.setOnClickListener { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorListView.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorListView.kt index 2cfd075a17a9..10e67a40ebc9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorListView.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorListView.kt @@ -20,6 +20,7 @@ import android.animation.ArgbEvaluator import android.animation.ValueAnimator import android.app.NotificationChannel import android.app.NotificationManager.IMPORTANCE_DEFAULT +import android.app.NotificationManager.IMPORTANCE_LOW import android.app.NotificationManager.IMPORTANCE_NONE import android.app.NotificationManager.IMPORTANCE_UNSPECIFIED import android.content.Context @@ -55,12 +56,14 @@ class ChannelEditorListView(c: Context, attrs: AttributeSet) : LinearLayout(c, a // The first row is for the entire app private lateinit var appControlRow: AppControlView + private lateinit var channelListView: LinearLayout private val channelRows = mutableListOf<ChannelRow>() override fun onFinishInflate() { super.onFinishInflate() appControlRow = requireViewById(R.id.app_control) + channelListView = requireViewById(R.id.scrollView) } /** @@ -102,7 +105,7 @@ class ChannelEditorListView(c: Context, attrs: AttributeSet) : LinearLayout(c, a // Remove any rows for (row in channelRows) { - removeView(row) + channelListView.removeView(row) } channelRows.clear() @@ -122,7 +125,7 @@ class ChannelEditorListView(c: Context, attrs: AttributeSet) : LinearLayout(c, a row.channel = channel channelRows.add(row) - addView(row) + channelListView.addView(row) } private fun updateAppControlRow(enabled: Boolean) { @@ -179,7 +182,9 @@ class ChannelRow(c: Context, attrs: AttributeSet) : LinearLayout(c, attrs) { switch = requireViewById(R.id.toggle) switch.setOnCheckedChangeListener { _, b -> channel?.let { - controller.proposeEditForChannel(it, if (b) it.importance else IMPORTANCE_NONE) + controller.proposeEditForChannel(it, + if (b) it.originalImportance.coerceAtLeast(IMPORTANCE_LOW) + else IMPORTANCE_NONE) } } setOnClickListener { switch.toggle() } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java index fb8024c88191..d18f9919604d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java @@ -2658,42 +2658,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView } /** - * Returns the number of channels covered by the notification row (including its children if - * it's a summary notification). - */ - public int getNumUniqueChannels() { - return getUniqueChannels().size(); - } - - /** - * Returns the channels covered by the notification row (including its children if - * it's a summary notification). - */ - public ArraySet<NotificationChannel> getUniqueChannels() { - ArraySet<NotificationChannel> channels = new ArraySet<>(); - - channels.add(mEntry.getChannel()); - - // If this is a summary, then add in the children notification channels for the - // same user and pkg. - if (mIsSummaryWithChildren) { - final List<ExpandableNotificationRow> childrenRows = getAttachedChildren(); - final int numChildren = childrenRows.size(); - for (int i = 0; i < numChildren; i++) { - final ExpandableNotificationRow childRow = childrenRows.get(i); - final NotificationChannel childChannel = childRow.getEntry().getChannel(); - final StatusBarNotification childSbn = childRow.getEntry().getSbn(); - if (childSbn.getUser().equals(mEntry.getSbn().getUser()) - && childSbn.getPackageName().equals(mEntry.getSbn().getPackageName())) { - channels.add(childChannel); - } - } - } - - return channels; - } - - /** * If this is a group, update the appearance of the children. */ public void updateChildrenAppearance() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java index 1dd3739d0e84..6d6566058aed 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java @@ -403,7 +403,6 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta mChannelEditorDialogController, packageName, row.getEntry().getChannel(), - row.getUniqueChannels(), row.getEntry(), onSettingsClick, onAppSettingsClick, @@ -449,7 +448,6 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta mChannelEditorDialogController, packageName, row.getEntry().getChannel(), - row.getUniqueChannels(), row.getEntry(), onSettingsClick, mDeviceProvisionedController.isDeviceProvisioned(), diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java index d8f31d4fb8a2..d8ebd4209c7d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java @@ -104,8 +104,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G private String mAppName; private int mAppUid; private String mDelegatePkg; - private int mNumUniqueChannelsInRow; - private Set<NotificationChannel> mUniqueChannelsInRow; private NotificationChannel mSingleNotificationChannel; private int mStartingChannelImportance; private boolean mWasShownHighPriority; @@ -196,7 +194,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G ChannelEditorDialogController channelEditorDialogController, String pkg, NotificationChannel notificationChannel, - Set<NotificationChannel> uniqueChannelsInRow, NotificationEntry entry, OnSettingsClickListener onSettingsClick, OnAppSettingsClickListener onAppSettingsClick, @@ -213,8 +210,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G mChannelEditorDialogController = channelEditorDialogController; mAssistantFeedbackController = assistantFeedbackController; mPackageName = pkg; - mUniqueChannelsInRow = uniqueChannelsInRow; - mNumUniqueChannelsInRow = uniqueChannelsInRow.size(); mEntry = entry; mSbn = entry.getSbn(); mPm = pm; @@ -236,15 +231,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage( pkg, mAppUid, false /* includeDeleted */); - 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 = mNumUniqueChannelsInRow == 1 - && mSingleNotificationChannel.getId().equals( - NotificationChannel.DEFAULT_CHANNEL_ID) - && numTotalChannels == 1; - } + mIsSingleDefaultChannel = mSingleNotificationChannel.getId().equals( + NotificationChannel.DEFAULT_CHANNEL_ID) && numTotalChannels == 1; mIsAutomaticChosen = getAlertingBehavior() == BEHAVIOR_AUTOMATIC; bindHeader(); @@ -271,11 +259,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G findViewById(R.id.interruptiveness_settings).setVisibility(GONE); ((TextView) findViewById(R.id.done)).setText(R.string.inline_done_button); findViewById(R.id.turn_off_notifications).setVisibility(GONE); - } else if (mNumUniqueChannelsInRow > 1) { - findViewById(R.id.non_configurable_call_text).setVisibility(GONE); - findViewById(R.id.non_configurable_text).setVisibility(GONE); - findViewById(R.id.interruptiveness_settings).setVisibility(GONE); - findViewById(R.id.non_configurable_multichannel_text).setVisibility(VISIBLE); } else { findViewById(R.id.non_configurable_call_text).setVisibility(GONE); findViewById(R.id.non_configurable_text).setVisibility(GONE); @@ -361,9 +344,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G if (mAppUid >= 0 && mOnSettingsClickListener != null && mIsDeviceProvisioned) { final int appUidF = mAppUid; return ((View view) -> { - mOnSettingsClickListener.onClick(view, - mNumUniqueChannelsInRow > 1 ? null : mSingleNotificationChannel, - appUidF); + mOnSettingsClickListener.onClick(view, mSingleNotificationChannel, appUidF); }); } return null; @@ -375,7 +356,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G mPresentingChannelEditorDialog = true; mChannelEditorDialogController.prepareDialogForApp(mAppName, mPackageName, mAppUid, - mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener); + mSingleNotificationChannel, mPkgIcon, mOnSettingsClickListener); mChannelEditorDialogController.setOnFinishListener(() -> { mPresentingChannelEditorDialog = false; mGutsContainer.closeControls(this, false); @@ -392,7 +373,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G private void bindName() { final TextView channelName = findViewById(R.id.channel_name); - if (mIsSingleDefaultChannel || mNumUniqueChannelsInRow > 1) { + if (mIsSingleDefaultChannel) { channelName.setVisibility(View.GONE); } else { channelName.setText(mSingleNotificationChannel.getName()); @@ -459,7 +440,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER)); bgHandler.post( new UpdateImportanceRunnable(mINotificationManager, mPackageName, mAppUid, - mNumUniqueChannelsInRow == 1 ? mSingleNotificationChannel : null, + mSingleNotificationChannel, mStartingChannelImportance, newImportance, mIsAutomaticChosen)); mOnUserInteractionCallback.onImportanceChanged(mEntry); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java index 06c3b7951db3..53f7d4bde70f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java @@ -57,7 +57,6 @@ public class PartialConversationInfo extends LinearLayout implements private StatusBarNotification mSbn; private boolean mIsDeviceProvisioned; private boolean mIsNonBlockable; - private Set<NotificationChannel> mUniqueChannelsInRow; private Drawable mPkgIcon; private boolean mPresentingChannelEditorDialog = false; @@ -83,7 +82,6 @@ public class PartialConversationInfo extends LinearLayout implements ChannelEditorDialogController channelEditorDialogController, String pkg, NotificationChannel notificationChannel, - Set<NotificationChannel> uniqueChannelsInRow, NotificationEntry entry, NotificationInfo.OnSettingsClickListener onSettingsClick, boolean isDeviceProvisioned, @@ -100,7 +98,6 @@ public class PartialConversationInfo extends LinearLayout implements mIsDeviceProvisioned = isDeviceProvisioned; mIsNonBlockable = isNonBlockable; mChannelEditorDialogController = channelEditorDialogController; - mUniqueChannelsInRow = uniqueChannelsInRow; bindHeader(); bindActions(); @@ -149,7 +146,7 @@ public class PartialConversationInfo extends LinearLayout implements mPresentingChannelEditorDialog = true; mChannelEditorDialogController.prepareDialogForApp(mAppName, mPackageName, mAppUid, - mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener); + mNotificationChannel, mPkgIcon, mOnSettingsClickListener); mChannelEditorDialogController.setOnFinishListener(() -> { mPresentingChannelEditorDialog = false; mGutsContainer.closeControls(this, false); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogControllerTest.kt index 64d025628754..7dcbd8084594 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogControllerTest.kt @@ -73,14 +73,14 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { controller = ChannelEditorDialogController(mContext, mockNoMan, dialogBuilder) channel1 = NotificationChannel(TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_DEFAULT) - channel2 = NotificationChannel(TEST_CHANNEL2, TEST_CHANNEL_NAME2, IMPORTANCE_DEFAULT) + channel2 = NotificationChannel(TEST_CHANNEL2, TEST_CHANNEL_NAME2, IMPORTANCE_NONE) channelDefault = NotificationChannel( NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, IMPORTANCE_DEFAULT) group = NotificationChannelGroup(TEST_GROUP_ID, TEST_GROUP_NAME) - `when`(mockNoMan.getNotificationChannelGroupsForPackage( - eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())) + `when`(mockNoMan.getRecentBlockedNotificationChannelGroupsForPackage( + eq(TEST_PACKAGE_NAME), eq(TEST_UID))) .thenReturn(ParceledListSlice(listOf(group))) `when`(mockNoMan.areNotificationsEnabledForPackage(eq(TEST_PACKAGE_NAME), eq(TEST_UID))) @@ -89,11 +89,13 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { @Test fun testPrepareDialogForApp_noExtraChannels() { + channel1.group = group.id + channel2.group = group.id group.channels = listOf(channel1, channel2) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channel1, channel2), appIcon, clickListener) + channel1, appIcon, clickListener) - assertEquals(2, controller.paddedChannels.size) + assertEquals(2, controller.channelList.size) } @Test @@ -101,39 +103,41 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { group.addChannel(channelDefault) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channelDefault), appIcon, clickListener) + channelDefault, appIcon, clickListener) assertEquals("No channels should be shown when there is only the miscellaneous channel", - 0, controller.paddedChannels.size) + 0, controller.channelList.size) } @Test - fun testPrepareDialogForApp_noProvidedChannels_noException() { - group.channels = listOf() - - controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(), appIcon, clickListener) - } - - @Test - fun testPrepareDialogForApp_retrievesUpTo4Channels() { + fun testPrepareDialogForApp_AddsAllChannelsAllGroups() { + val group2 = NotificationChannelGroup("two", "group two") val channel3 = NotificationChannel("test_channel_3", "Test channel 3", IMPORTANCE_DEFAULT) + channel3.group = group2.id val channel4 = NotificationChannel("test_channel_4", "Test channel 4", IMPORTANCE_DEFAULT) + channel4.group = group.id + val channel5 = NotificationChannel("test_channel_5", "Test channel 5", IMPORTANCE_DEFAULT) + channel5.group = group.id - group.channels = listOf(channel1, channel2, channel3, channel4) + `when`(mockNoMan.getRecentBlockedNotificationChannelGroupsForPackage( + eq(TEST_PACKAGE_NAME), eq(TEST_UID))) + .thenReturn(ParceledListSlice(listOf(group, group2))) + + group.channels = listOf(channel1, channel2, channel4, channel5) + group2.channels = listOf(channel3) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channel1), appIcon, clickListener) + channel1, appIcon, clickListener) - assertEquals("ChannelEditorDialog should fetch enough channels to show 4", - 4, controller.paddedChannels.size) + assertEquals("ChannelEditorDialog should show all channels", + 5, controller.channelList.size) } @Test fun testApply_demoteChannel() { group.channels = listOf(channel1, channel2) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channel1, channel2), appIcon, clickListener) + channel1, appIcon, clickListener) // propose an adjustment of channel1 controller.proposeEditForChannel(channel1, IMPORTANCE_NONE) @@ -145,14 +149,33 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { // Channel 2 shouldn't have changed assertEquals("Proposed edits should take effect after apply", + IMPORTANCE_NONE, channel2.importance) + } + + @Test + fun testApply_promoteChannel() { + group.channels = listOf(channel1, channel2) + controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, + channel1, appIcon, clickListener) + + // propose an adjustment of channel1 + controller.proposeEditForChannel(channel2, IMPORTANCE_DEFAULT) + + controller.apply() + + assertEquals("Proposed edits should take effect after apply", IMPORTANCE_DEFAULT, channel2.importance) + + // Channel 1 shouldn't have changed + assertEquals("Proposed edits should take effect after apply", + IMPORTANCE_DEFAULT, channel1.importance) } @Test fun testApply_demoteApp() { group.channels = listOf(channel1, channel2) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channel1, channel2), appIcon, clickListener) + channel1, appIcon, clickListener) controller.proposeSetAppNotificationsEnabled(false) controller.apply() @@ -168,7 +191,7 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { .thenReturn(false) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channel1, channel2), appIcon, clickListener) + channel1, appIcon, clickListener) controller.proposeSetAppNotificationsEnabled(true) controller.apply() @@ -181,7 +204,7 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { // GIVEN editor dialog group.channels = listOf(channel1, channel2) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channel1, channel2), appIcon, null) + channel1, appIcon, null) // WHEN user taps settings // Pass in any old view, it should never actually be used @@ -197,7 +220,7 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { group.channels = listOf(channel1, channel2) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channel1, channel2), appIcon, null) + channel1, appIcon, null) // WHEN the user proposes a change controller.proposeEditForChannel(channel1, IMPORTANCE_NONE) @@ -214,7 +237,7 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { group.channels = listOf(channel1, channel2) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, - setOf(channel1, channel2), appIcon, null) + channel1, appIcon, null) // WHEN the user proposes a change controller.proposeEditForChannel(channel1, IMPORTANCE_NONE) @@ -236,7 +259,6 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { const val TEST_PACKAGE_NAME = "test_package" const val TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME const val TEST_UID = 1 - const val MULTIPLE_CHANNEL_COUNT = 2 const val TEST_CHANNEL = "test_channel" const val TEST_CHANNEL_NAME = "Test Channel Name" const val TEST_CHANNEL2 = "test_channel2" diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java index ac8b42afd4b2..e37314301e28 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java @@ -481,33 +481,6 @@ public class ExpandableNotificationRowTest extends SysuiTestCase { } @Test - public void testGetNumUniqueChildren_defaultChannel() throws Exception { - ExpandableNotificationRow groupRow = mNotificationTestHelper.createGroup(); - - assertEquals(1, groupRow.getNumUniqueChannels()); - } - - @Test - public void testGetNumUniqueChildren_multiChannel() throws Exception { - ExpandableNotificationRow group = mNotificationTestHelper.createGroup(); - - List<ExpandableNotificationRow> childRows = - group.getChildrenContainer().getAttachedChildren(); - // Give each child a unique channel id/name. - int i = 0; - for (ExpandableNotificationRow childRow : childRows) { - modifyRanking(childRow.getEntry()) - .setChannel( - new NotificationChannel( - "id" + i, "dinnertime" + i, IMPORTANCE_DEFAULT)) - .build(); - i++; - } - - assertEquals(3, group.getNumUniqueChannels()); - } - - @Test public void testIconScrollXAfterTranslationAndReset() throws Exception { ExpandableNotificationRow group = mNotificationTestHelper.createGroup(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java index 9e0f83c9fc53..0f1e63f4c0df 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java @@ -462,7 +462,6 @@ public class NotificationGutsManagerTest extends SysuiTestCase { eq(mChannelEditorDialogController), eq(statusBarNotification.getPackageName()), any(NotificationChannel.class), - anySet(), eq(entry), any(NotificationInfo.OnSettingsClickListener.class), any(NotificationInfo.OnAppSettingsClickListener.class), @@ -496,7 +495,6 @@ public class NotificationGutsManagerTest extends SysuiTestCase { eq(mChannelEditorDialogController), eq(statusBarNotification.getPackageName()), any(NotificationChannel.class), - anySet(), eq(entry), any(NotificationInfo.OnSettingsClickListener.class), any(NotificationInfo.OnAppSettingsClickListener.class), @@ -528,7 +526,6 @@ public class NotificationGutsManagerTest extends SysuiTestCase { eq(mChannelEditorDialogController), eq(statusBarNotification.getPackageName()), any(NotificationChannel.class), - anySet(), eq(entry), any(NotificationInfo.OnSettingsClickListener.class), any(NotificationInfo.OnAppSettingsClickListener.class), diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java index f0b4dd46654a..b59385cd5261 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java @@ -92,7 +92,6 @@ 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; private static final int TEST_UID = 1; - private static final int MULTIPLE_CHANNEL_COUNT = 2; private static final String TEST_CHANNEL = "test_channel"; private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; @@ -100,8 +99,6 @@ public class NotificationInfoTest extends SysuiTestCase { private NotificationInfo mNotificationInfo; private NotificationChannel mNotificationChannel; private NotificationChannel mDefaultNotificationChannel; - private Set<NotificationChannel> mNotificationChannelSet = new HashSet<>(); - private Set<NotificationChannel> mDefaultNotificationChannelSet = new HashSet<>(); private StatusBarNotification mSbn; private NotificationEntry mEntry; private UiEventLoggerFake mUiEventLogger = new UiEventLoggerFake(); @@ -162,11 +159,9 @@ public class NotificationInfoTest extends SysuiTestCase { // Some test channels. mNotificationChannel = new NotificationChannel( TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); - mNotificationChannelSet.add(mNotificationChannel); mDefaultNotificationChannel = new NotificationChannel( NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, IMPORTANCE_LOW); - mDefaultNotificationChannelSet.add(mDefaultNotificationChannel); mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0, new Notification(), UserHandle.getUserHandleForUid(TEST_UID), null, 0); mEntry = new NotificationEntryBuilder().setSbn(mSbn).build(); @@ -185,7 +180,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -212,7 +206,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -235,7 +228,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -267,7 +259,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, entry, null, null, @@ -291,7 +282,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -320,7 +310,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -344,7 +333,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -367,7 +355,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mDefaultNotificationChannel, - mDefaultNotificationChannelSet, mEntry, null, null, @@ -394,7 +381,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mDefaultNotificationChannel, - mDefaultNotificationChannelSet, mEntry, null, null, @@ -417,7 +403,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -441,7 +426,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, (View v, NotificationChannel c, int appUid) -> { assertEquals(mNotificationChannel, c); @@ -470,7 +454,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -494,7 +477,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, (View v, NotificationChannel c, int appUid) -> { assertEquals(mNotificationChannel, c); @@ -519,7 +501,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -536,7 +517,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, (View v, NotificationChannel c, int appUid) -> { }, null, @@ -551,86 +531,6 @@ public class NotificationInfoTest extends SysuiTestCase { } @Test - public void testOnClickListenerPassesNullChannelForBundle() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - mNotificationInfo.bindNotification( - mMockPackageManager, - mMockINotificationManager, - mOnUserInteractionCallback, - mChannelEditorDialogController, - TEST_PACKAGE_NAME, mNotificationChannel, - createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), - mEntry, - (View v, NotificationChannel c, int appUid) -> { - assertEquals(null, c); - latch.countDown(); - }, - null, - mUiEventLogger, - true, - true, - true, - mAssistantFeedbackController, - mMetricsLogger); - - mNotificationInfo.findViewById(R.id.info).performClick(); - // Verify that listener was triggered. - assertEquals(0, latch.getCount()); - } - - @Test - @UiThreadTest - public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels() - throws Exception { - mNotificationInfo.bindNotification( - mMockPackageManager, - mMockINotificationManager, - mOnUserInteractionCallback, - mChannelEditorDialogController, - TEST_PACKAGE_NAME, - mNotificationChannel, - createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), - mEntry, - null, - null, - mUiEventLogger, - true, - false, - true, - mAssistantFeedbackController, - mMetricsLogger); - final TextView channelNameView = - mNotificationInfo.findViewById(R.id.channel_name); - assertEquals(GONE, channelNameView.getVisibility()); - } - - @Test - @UiThreadTest - public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception { - mNotificationInfo.bindNotification( - mMockPackageManager, - mMockINotificationManager, - mOnUserInteractionCallback, - mChannelEditorDialogController, - TEST_PACKAGE_NAME, - mNotificationChannel, - createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), - mEntry, - null, - null, - mUiEventLogger, - true, - false, - true, - mAssistantFeedbackController, - mMetricsLogger); - assertEquals(GONE, mNotificationInfo.findViewById( - R.id.interruptiveness_settings).getVisibility()); - assertEquals(VISIBLE, mNotificationInfo.findViewById( - R.id.non_configurable_multichannel_text).getVisibility()); - } - - @Test public void testBindNotification_whenAppUnblockable() throws Exception { mNotificationInfo.bindNotification( mMockPackageManager, @@ -639,7 +539,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -683,7 +582,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -727,7 +625,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -755,7 +652,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -778,7 +674,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -803,7 +698,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -825,7 +719,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -847,7 +740,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -869,7 +761,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -893,7 +784,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -918,7 +808,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -946,7 +835,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -974,7 +862,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1003,7 +890,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1031,7 +917,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1067,7 +952,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1096,7 +980,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1138,7 +1021,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1176,7 +1058,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1209,7 +1090,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1246,7 +1126,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1285,7 +1164,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1317,7 +1195,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1356,7 +1233,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1386,7 +1262,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1418,7 +1293,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1454,7 +1328,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1488,7 +1361,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1522,7 +1394,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1549,7 +1420,6 @@ public class NotificationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, null, @@ -1562,21 +1432,4 @@ public class NotificationInfoTest extends SysuiTestCase { assertFalse(mNotificationInfo.willBeRemoved()); } - - private Set<NotificationChannel> createMultipleChannelSet(int howMany) { - Set<NotificationChannel> multiChannelSet = new HashSet<>(); - for (int i = 0; i < howMany; i++) { - if (i == 0) { - multiChannelSet.add(mNotificationChannel); - continue; - } - - NotificationChannel channel = new NotificationChannel( - TEST_CHANNEL, TEST_CHANNEL_NAME + i, IMPORTANCE_LOW); - - multiChannelSet.add(channel); - } - - return multiChannelSet; - } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java index e42ce2789e0b..ccedd364ef67 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java @@ -83,8 +83,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { private PartialConversationInfo mInfo; private NotificationChannel mNotificationChannel; private NotificationChannel mDefaultNotificationChannel; - private Set<NotificationChannel> mNotificationChannelSet = new HashSet<>(); - private Set<NotificationChannel> mDefaultNotificationChannelSet = new HashSet<>(); private StatusBarNotification mSbn; private NotificationEntry mEntry; @@ -144,11 +142,9 @@ public class PartialConversationInfoTest extends SysuiTestCase { // Some test channels. mNotificationChannel = new NotificationChannel( TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); - mNotificationChannelSet.add(mNotificationChannel); mDefaultNotificationChannel = new NotificationChannel( NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, IMPORTANCE_LOW); - mDefaultNotificationChannelSet.add(mDefaultNotificationChannel); Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) .setContentTitle(new SpannableString("title")) .build(); @@ -166,7 +162,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, true, @@ -185,7 +180,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, true, @@ -202,7 +196,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, true, @@ -228,7 +221,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, entry, null, true, @@ -247,7 +239,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, (View v, NotificationChannel c, int appUid) -> { assertEquals(mNotificationChannel, c); @@ -271,7 +262,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, (View v, NotificationChannel c, int appUid) -> { assertEquals(mNotificationChannel, c); @@ -294,7 +284,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, true, @@ -311,7 +300,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, (View v, NotificationChannel c, int appUid) -> { assertEquals(mNotificationChannel, c); @@ -330,7 +318,6 @@ public class PartialConversationInfoTest extends SysuiTestCase { mChannelEditorDialogController, TEST_PACKAGE_NAME, mNotificationChannel, - mNotificationChannelSet, mEntry, null, true, diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 802dfb182297..a3c71c2e0218 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -177,6 +177,7 @@ import android.app.compat.CompatChanges; import android.app.role.OnRoleHoldersChangedListener; import android.app.role.RoleManager; import android.app.usage.UsageEvents; +import android.app.usage.UsageStatsManager; import android.app.usage.UsageStatsManagerInternal; import android.companion.ICompanionDeviceManager; import android.compat.annotation.ChangeId; @@ -263,6 +264,7 @@ import android.telecom.TelecomManager; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.text.TextUtils; +import android.text.format.DateUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.AtomicFile; @@ -4159,7 +4161,7 @@ public class NotificationManagerService extends SystemService { String pkg) { checkCallerIsSystemOrSameApp(pkg); return mPreferencesHelper.getNotificationChannelGroups( - pkg, Binder.getCallingUid(), false, false, true); + pkg, Binder.getCallingUid(), false, false, true, true, null); } @Override @@ -4280,7 +4282,36 @@ public class NotificationManagerService extends SystemService { String pkg, int uid, boolean includeDeleted) { enforceSystemOrSystemUI("getNotificationChannelGroupsForPackage"); return mPreferencesHelper.getNotificationChannelGroups( - pkg, uid, includeDeleted, true, false); + pkg, uid, includeDeleted, true, false, true, null); + } + + @Override + public ParceledListSlice<NotificationChannelGroup> + getRecentBlockedNotificationChannelGroupsForPackage(String pkg, int uid) { + enforceSystemOrSystemUI("getRecentBlockedNotificationChannelGroupsForPackage"); + Set<String> recentlySentChannels = new HashSet<>(); + long now = System.currentTimeMillis(); + long startTime = now - (DateUtils.DAY_IN_MILLIS * 14); + UsageEvents events = mUsageStatsManagerInternal.queryEventsForUser( + UserHandle.getUserId(uid), startTime, now, UsageEvents.SHOW_ALL_EVENT_DATA); + // get all channelids that sent notifs in the past 2 weeks + if (events != null) { + UsageEvents.Event event = new UsageEvents.Event(); + while (events.hasNextEvent()) { + events.getNextEvent(event); + if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) { + if (pkg.equals(event.mPackage)) { + String channelId = event.mNotificationChannelId; + if (channelId != null) { + recentlySentChannels.add(channelId); + } + } + } + } + } + + return mPreferencesHelper.getNotificationChannelGroups( + pkg, uid, false, true, false, true, recentlySentChannels); } @Override diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index b132a23b575b..de698d916cce 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -1459,9 +1459,9 @@ public class PreferencesHelper implements RankingConfig { } } - @Override public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, - int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) { + int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty, + boolean includeBlocked, Set<String> activeChannelFilter) { Objects.requireNonNull(pkg); Map<String, NotificationChannelGroup> groups = new ArrayMap<>(); synchronized (mPackagePreferences) { @@ -1473,7 +1473,11 @@ public class PreferencesHelper implements RankingConfig { int N = r.channels.size(); for (int i = 0; i < N; i++) { final NotificationChannel nc = r.channels.valueAt(i); - if (includeDeleted || !nc.isDeleted()) { + boolean includeChannel = (includeDeleted || !nc.isDeleted()) + && (activeChannelFilter == null + || (includeBlocked && nc.getImportance() == IMPORTANCE_NONE) + || activeChannelFilter.contains(nc.getId())); + if (includeChannel) { if (nc.getGroup() != null) { if (r.groups.get(nc.getGroup()) != null) { NotificationChannelGroup ncg = groups.get(nc.getGroup()); @@ -1481,7 +1485,6 @@ public class PreferencesHelper implements RankingConfig { ncg = r.groups.get(nc.getGroup()).clone(); ncg.setChannels(new ArrayList<>()); groups.put(nc.getGroup(), ncg); - } ncg.addChannel(nc); } diff --git a/services/core/java/com/android/server/notification/RankingConfig.java b/services/core/java/com/android/server/notification/RankingConfig.java index fec359198e88..8df24c9911a6 100644 --- a/services/core/java/com/android/server/notification/RankingConfig.java +++ b/services/core/java/com/android/server/notification/RankingConfig.java @@ -40,8 +40,6 @@ public interface RankingConfig { int uid); void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group, boolean fromTargetApp, int callingUid, boolean isSystemOrSystemUi); - ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, - int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty); boolean createNotificationChannel(String pkg, int uid, NotificationChannel channel, boolean fromTargetApp, boolean hasDndAccess, int callingUid, boolean isSystemOrSystemUi); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index 020afdbce987..8d7b5cb984b4 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -141,6 +141,7 @@ import com.android.server.UiServiceTestCase; import com.android.server.notification.PermissionHelper.PackagePermission; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.protobuf.InvalidProtocolBufferException; import org.json.JSONArray; @@ -563,7 +564,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel2.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups( - PKG_N_MR1, UID_N_MR1, false, true, false).getList(); + PKG_N_MR1, UID_N_MR1, false, true, false, true, null).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { @@ -647,7 +648,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups( - PKG_N_MR1, UID_N_MR1, false, true, false).getList(); + PKG_N_MR1, UID_N_MR1, false, true, false, true, null).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { @@ -2620,6 +2621,16 @@ public class PreferencesHelperTest extends UiServiceTestCase { } @Test + public void testOnlyHasDefaultChannel() throws Exception { + assertTrue(mHelper.onlyHasDefaultChannel(PKG_N_MR1, UID_N_MR1)); + assertFalse(mHelper.onlyHasDefaultChannel(PKG_O, UID_O)); + + mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, getChannel(), true, false, + UID_N_MR1, false); + assertFalse(mHelper.onlyHasDefaultChannel(PKG_N_MR1, UID_N_MR1)); + } + + @Test public void testCreateDeletedChannel() throws Exception { long[] vibration = new long[]{100, 67, 145, 156}; NotificationChannel channel = @@ -2644,16 +2655,6 @@ public class PreferencesHelperTest extends UiServiceTestCase { } @Test - public void testOnlyHasDefaultChannel() throws Exception { - assertTrue(mHelper.onlyHasDefaultChannel(PKG_N_MR1, UID_N_MR1)); - assertFalse(mHelper.onlyHasDefaultChannel(PKG_O, UID_O)); - - mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, getChannel(), true, false, - UID_N_MR1, false); - assertFalse(mHelper.onlyHasDefaultChannel(PKG_N_MR1, UID_N_MR1)); - } - - @Test public void testCreateChannel_defaultChannelId() throws Exception { try { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel( @@ -2884,7 +2885,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { UID_N_MR1}); assertEquals(0, mHelper.getNotificationChannelGroups( - PKG_N_MR1, UID_N_MR1, true, true, false).getList().size()); + PKG_N_MR1, UID_N_MR1, true, true, false, true, null).getList().size()); } @Test @@ -3022,7 +3023,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { UID_N_MR1, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( - PKG_N_MR1, UID_N_MR1, true, true, false).getList(); + PKG_N_MR1, UID_N_MR1, true, true, false, true, null).getList(); assertEquals(3, actual.size()); for (NotificationChannelGroup group : actual) { if (group.getId() == null) { @@ -3056,14 +3057,15 @@ public class PreferencesHelperTest extends UiServiceTestCase { channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1, true, false, UID_N_MR1, false); - mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true, false).getList(); + mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true, false, true, null) + .getList(); channel1.setImportance(IMPORTANCE_LOW); mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1, true, UID_N_MR1, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( - PKG_N_MR1, UID_N_MR1, true, true, false).getList(); + PKG_N_MR1, UID_N_MR1, true, true, false, true, null).getList(); assertEquals(2, actual.size()); for (NotificationChannelGroup group : actual) { @@ -3089,7 +3091,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { UID_N_MR1, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( - PKG_N_MR1, UID_N_MR1, false, false, true).getList(); + PKG_N_MR1, UID_N_MR1, false, false, true, true, null).getList(); assertEquals(2, actual.size()); for (NotificationChannelGroup group : actual) { @@ -5786,6 +5788,62 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertFalse(isUserSet); } + @Test + public void testGetNotificationChannelGroups_withChannelFilter_includeBlocked() { + NotificationChannel channel = + new NotificationChannel("id2", "name1", NotificationManager.IMPORTANCE_HIGH); + mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel, true, false, + UID_N_MR1, false); + // modifying same object, don't need to call updateNotificationChannel + channel.setImportance(IMPORTANCE_NONE); + + NotificationChannel channel2 = + new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_HIGH); + mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel2, true, false, + UID_N_MR1, false); + + NotificationChannel channel3 = + new NotificationChannel("id3", "name3", NotificationManager.IMPORTANCE_HIGH); + mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3, true, false, + UID_N_MR1, false); + + Set<String> filter = ImmutableSet.of("id3"); + + NotificationChannelGroup actual = mHelper.getNotificationChannelGroups( + PKG_N_MR1, UID_N_MR1, false, true, false, true, filter).getList().get(0); + assertEquals(2, actual.getChannels().size()); + assertEquals(1, actual.getChannels().stream().filter(c -> c.getId().equals("id3")).count()); + assertEquals(1, actual.getChannels().stream().filter(c -> c.getId().equals("id2")).count()); + } + + @Test + public void testGetNotificationChannelGroups_withChannelFilter_doNotIncludeBlocked() { + NotificationChannel channel = + new NotificationChannel("id2", "name1", NotificationManager.IMPORTANCE_HIGH); + mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel, true, false, + UID_N_MR1, false); + // modifying same object, don't need to call updateNotificationChannel + channel.setImportance(IMPORTANCE_NONE); + + NotificationChannel channel2 = + new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_HIGH); + mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel2, true, false, + UID_N_MR1, false); + + NotificationChannel channel3 = + new NotificationChannel("id3", "name3", NotificationManager.IMPORTANCE_HIGH); + mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3, true, false, + UID_N_MR1, false); + + Set<String> filter = ImmutableSet.of("id3"); + + NotificationChannelGroup actual = mHelper.getNotificationChannelGroups( + PKG_N_MR1, UID_N_MR1, false, true, false, false, filter).getList().get(0); + assertEquals(1, actual.getChannels().size()); + assertEquals(1, actual.getChannels().stream().filter(c -> c.getId().equals("id3")).count()); + assertEquals(0, actual.getChannels().stream().filter(c -> c.getId().equals("id2")).count()); + } + private static NotificationChannel cloneChannel(NotificationChannel original) { Parcel parcel = Parcel.obtain(); try { |