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