Loading res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -6370,6 +6370,9 @@ <!-- [CHAR LIMIT=NONE] App notification settings: channels title --> <string name="notification_channels">Channels</string> <!-- [CHAR LIMIT=NONE] App notification settings: no channels --> <string name="no_channels">This app has not posted any notifications</string> <!-- [CHAR LIMIT=60] App notification settings: Text to display for deleted channels --> <string name="deleted_channel_name"><xliff:g id="channel_name" example="Promotions">%1$s</xliff:g> (deleted)</string> Loading res/xml/app_notification_settings.xml +1 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ android:key="block" android:title="@string/app_notification_block_title" android:summary="@string/app_notification_block_summary" android:order="1" settings:useAdditionalSummary="true" settings:restrictedSwitchSummary="@string/enabled_by_admin" /> Loading @@ -32,13 +31,11 @@ android:key="badge" android:title="@string/notification_badge_title" android:summary="@string/notification_badge_summary" android:order="2" settings:useAdditionalSummary="true" settings:restrictedSwitchSummary="@string/enabled_by_admin" /> <PreferenceCategory android:key="channels" android:title="@string/notification_channels" android:order="3" /> android:title="@string/notification_channels" /> </PreferenceScreen> src/com/android/settings/notification/AppNotificationSettings.java +72 −31 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package com.android.settings.notification; import android.app.Activity; import android.app.Notification; import android.app.NotificationChannel; import android.content.Context; import android.app.NotificationChannelGroup; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; Loading @@ -38,13 +38,11 @@ import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.applications.AppHeaderController; import com.android.settings.applications.AppInfoBase; import com.android.settings.core.PreferenceController; import com.android.settings.dashboard.DashboardFeatureProvider; import com.android.settings.notification.NotificationBackend.AppRow; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.RestrictedPreference; import com.android.settingslib.RestrictedSwitchPreference; import com.android.settingslib.drawer.CategoryKey; import java.text.Collator; import java.util.Collections; Loading @@ -66,7 +64,7 @@ public class AppNotificationSettings extends NotificationSettingsBase { private DashboardFeatureProvider mDashboardFeatureProvider; private PreferenceCategory mChannels; private List<NotificationChannel> mChannelList; private List<NotificationChannelGroup> mChannelGroupList; @Override public void onActivityCreated(Bundle savedInstanceState) { Loading Loading @@ -96,6 +94,7 @@ public class AppNotificationSettings extends NotificationSettingsBase { FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity); addPreferencesFromResource(R.xml.app_notification_settings); getPreferenceScreen().setOrderingAsAdded(true); mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK); mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE); Loading @@ -108,16 +107,32 @@ public class AppNotificationSettings extends NotificationSettingsBase { ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>(); rows.put(mAppRow.pkg, mAppRow); collectConfigActivities(rows); mChannelList = mBackend.getChannels(mPkg, mUid).getList(); Collections.sort(mChannelList, mChannelComparator); // TODO: load channels in asynctask? mChannelGroupList = mBackend.getChannelGroups(mPkg, mUid).getList(); Collections.sort(mChannelGroupList, mChannelGroupComparator); if (mChannelList.isEmpty()) { setVisible(mChannels, false); if (mChannelGroupList.isEmpty()) { Preference empty = new Preference(getPrefContext()); empty.setTitle(R.string.no_channels); empty.setEnabled(false); mChannels.addPreference(empty); } else { int N = mChannelList.size(); for (NotificationChannelGroup group : mChannelGroupList) { PreferenceCategory groupCategory = null; if (group.getId() != null && group.getName() != null) { groupCategory = new PreferenceCategory(getPrefContext()); groupCategory.setTitle(group.getName()); groupCategory.setKey(group.getId()); groupCategory.setOrderingAsAdded(true); getPreferenceScreen().addPreference(groupCategory); } final List<NotificationChannel> channels = group.getChannels(); Collections.sort(channels, mChannelComparator); int N = channels.size(); for (int i = 0; i < N; i++) { final NotificationChannel channel = mChannelList.get(i); RestrictedPreference channelPref = new RestrictedPreference(getPrefContext()); final NotificationChannel channel = channels.get(i); RestrictedPreference channelPref = new RestrictedPreference( getPrefContext()); channelPref.setDisabledByAdmin(mSuspendedAppsAdmin); channelPref.setKey(channel.getId()); channelPref.setTitle(channel.getName()); Loading @@ -137,9 +152,14 @@ public class AppNotificationSettings extends NotificationSettingsBase { channelArgs, null, 0, null, false); channelPref.setIntent(channelIntent); } if (groupCategory != null) { groupCategory.addPreference(channelPref); } else { mChannels.addPreference(channelPref); } } } } updateDependents(mAppRow.banned); } if (mDashboardFeatureProvider.isEnabled()) { Loading Loading @@ -203,7 +223,7 @@ public class AppNotificationSettings extends NotificationSettingsBase { } private void updateDependents(boolean banned) { setVisible(mChannels, !(mChannelList.isEmpty() || banned)); setVisible(mChannels, !banned); setVisible(mBadge, !banned); } Loading Loading @@ -262,4 +282,25 @@ public class AppNotificationSettings extends NotificationSettingsBase { return left.getId().compareTo(right.getId()); } }; private Comparator<NotificationChannelGroup> mChannelGroupComparator = new Comparator<NotificationChannelGroup>() { private final Collator sCollator = Collator.getInstance(); @Override public int compare(NotificationChannelGroup left, NotificationChannelGroup right) { // Non-groups channels (in placeholder group with a null id) come first if (left.getId() == null && right.getId() != null) { return 1; } else if (right.getId() == null && left.getId() != null) { return -1; } // sort rest of the groups by name if (!Objects.equals(left.getName(), right.getName())) { return sCollator.compare(left.getName().toString(), right.getName().toString()); } return left.getId().compareTo(right.getId()); } }; } src/com/android/settings/notification/NotificationBackend.java +3 −2 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.notification; import android.app.INotificationManager; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; Loading Loading @@ -121,9 +122,9 @@ public class NotificationBackend { } } public ParceledListSlice<NotificationChannel> getChannels(String pkg, int uid) { public ParceledListSlice<NotificationChannelGroup> getChannelGroups(String pkg, int uid) { try { return sINM.getNotificationChannelsForPackage(pkg, uid, true); return sINM.getNotificationChannelGroupsForPackage(pkg, uid, true); } catch (Exception e) { Log.w(TAG, "Error calling NoMan", e); return ParceledListSlice.emptyList(); Loading Loading
res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -6370,6 +6370,9 @@ <!-- [CHAR LIMIT=NONE] App notification settings: channels title --> <string name="notification_channels">Channels</string> <!-- [CHAR LIMIT=NONE] App notification settings: no channels --> <string name="no_channels">This app has not posted any notifications</string> <!-- [CHAR LIMIT=60] App notification settings: Text to display for deleted channels --> <string name="deleted_channel_name"><xliff:g id="channel_name" example="Promotions">%1$s</xliff:g> (deleted)</string> Loading
res/xml/app_notification_settings.xml +1 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ android:key="block" android:title="@string/app_notification_block_title" android:summary="@string/app_notification_block_summary" android:order="1" settings:useAdditionalSummary="true" settings:restrictedSwitchSummary="@string/enabled_by_admin" /> Loading @@ -32,13 +31,11 @@ android:key="badge" android:title="@string/notification_badge_title" android:summary="@string/notification_badge_summary" android:order="2" settings:useAdditionalSummary="true" settings:restrictedSwitchSummary="@string/enabled_by_admin" /> <PreferenceCategory android:key="channels" android:title="@string/notification_channels" android:order="3" /> android:title="@string/notification_channels" /> </PreferenceScreen>
src/com/android/settings/notification/AppNotificationSettings.java +72 −31 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package com.android.settings.notification; import android.app.Activity; import android.app.Notification; import android.app.NotificationChannel; import android.content.Context; import android.app.NotificationChannelGroup; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; Loading @@ -38,13 +38,11 @@ import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.applications.AppHeaderController; import com.android.settings.applications.AppInfoBase; import com.android.settings.core.PreferenceController; import com.android.settings.dashboard.DashboardFeatureProvider; import com.android.settings.notification.NotificationBackend.AppRow; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.RestrictedPreference; import com.android.settingslib.RestrictedSwitchPreference; import com.android.settingslib.drawer.CategoryKey; import java.text.Collator; import java.util.Collections; Loading @@ -66,7 +64,7 @@ public class AppNotificationSettings extends NotificationSettingsBase { private DashboardFeatureProvider mDashboardFeatureProvider; private PreferenceCategory mChannels; private List<NotificationChannel> mChannelList; private List<NotificationChannelGroup> mChannelGroupList; @Override public void onActivityCreated(Bundle savedInstanceState) { Loading Loading @@ -96,6 +94,7 @@ public class AppNotificationSettings extends NotificationSettingsBase { FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity); addPreferencesFromResource(R.xml.app_notification_settings); getPreferenceScreen().setOrderingAsAdded(true); mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK); mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE); Loading @@ -108,16 +107,32 @@ public class AppNotificationSettings extends NotificationSettingsBase { ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>(); rows.put(mAppRow.pkg, mAppRow); collectConfigActivities(rows); mChannelList = mBackend.getChannels(mPkg, mUid).getList(); Collections.sort(mChannelList, mChannelComparator); // TODO: load channels in asynctask? mChannelGroupList = mBackend.getChannelGroups(mPkg, mUid).getList(); Collections.sort(mChannelGroupList, mChannelGroupComparator); if (mChannelList.isEmpty()) { setVisible(mChannels, false); if (mChannelGroupList.isEmpty()) { Preference empty = new Preference(getPrefContext()); empty.setTitle(R.string.no_channels); empty.setEnabled(false); mChannels.addPreference(empty); } else { int N = mChannelList.size(); for (NotificationChannelGroup group : mChannelGroupList) { PreferenceCategory groupCategory = null; if (group.getId() != null && group.getName() != null) { groupCategory = new PreferenceCategory(getPrefContext()); groupCategory.setTitle(group.getName()); groupCategory.setKey(group.getId()); groupCategory.setOrderingAsAdded(true); getPreferenceScreen().addPreference(groupCategory); } final List<NotificationChannel> channels = group.getChannels(); Collections.sort(channels, mChannelComparator); int N = channels.size(); for (int i = 0; i < N; i++) { final NotificationChannel channel = mChannelList.get(i); RestrictedPreference channelPref = new RestrictedPreference(getPrefContext()); final NotificationChannel channel = channels.get(i); RestrictedPreference channelPref = new RestrictedPreference( getPrefContext()); channelPref.setDisabledByAdmin(mSuspendedAppsAdmin); channelPref.setKey(channel.getId()); channelPref.setTitle(channel.getName()); Loading @@ -137,9 +152,14 @@ public class AppNotificationSettings extends NotificationSettingsBase { channelArgs, null, 0, null, false); channelPref.setIntent(channelIntent); } if (groupCategory != null) { groupCategory.addPreference(channelPref); } else { mChannels.addPreference(channelPref); } } } } updateDependents(mAppRow.banned); } if (mDashboardFeatureProvider.isEnabled()) { Loading Loading @@ -203,7 +223,7 @@ public class AppNotificationSettings extends NotificationSettingsBase { } private void updateDependents(boolean banned) { setVisible(mChannels, !(mChannelList.isEmpty() || banned)); setVisible(mChannels, !banned); setVisible(mBadge, !banned); } Loading Loading @@ -262,4 +282,25 @@ public class AppNotificationSettings extends NotificationSettingsBase { return left.getId().compareTo(right.getId()); } }; private Comparator<NotificationChannelGroup> mChannelGroupComparator = new Comparator<NotificationChannelGroup>() { private final Collator sCollator = Collator.getInstance(); @Override public int compare(NotificationChannelGroup left, NotificationChannelGroup right) { // Non-groups channels (in placeholder group with a null id) come first if (left.getId() == null && right.getId() != null) { return 1; } else if (right.getId() == null && left.getId() != null) { return -1; } // sort rest of the groups by name if (!Objects.equals(left.getName(), right.getName())) { return sCollator.compare(left.getName().toString(), right.getName().toString()); } return left.getId().compareTo(right.getId()); } }; }
src/com/android/settings/notification/NotificationBackend.java +3 −2 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.notification; import android.app.INotificationManager; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; Loading Loading @@ -121,9 +122,9 @@ public class NotificationBackend { } } public ParceledListSlice<NotificationChannel> getChannels(String pkg, int uid) { public ParceledListSlice<NotificationChannelGroup> getChannelGroups(String pkg, int uid) { try { return sINM.getNotificationChannelsForPackage(pkg, uid, true); return sINM.getNotificationChannelGroupsForPackage(pkg, uid, true); } catch (Exception e) { Log.w(TAG, "Error calling NoMan", e); return ParceledListSlice.emptyList(); Loading