Notification settings, importance and pre-O apps
- Show pre-O settings for the misc channel, should the app still have it (versus the full channel settings) - Fix the importance summmary text in various places - Update the color of the blocked description text - Fix what fields appear/disappear based on blocked status and importance Fixes: 38177887 Bug: 38120923 Fixes: 38012300 Fixes: 37923612 Test: manual, with an O app, a pre O app that has channels, and a pre-O app with no channels Change-Id: I42965b81b795e8fb427f857c7766fe5480a99f2e
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||
@@ -63,16 +62,12 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
private static final String TAG = "AppNotificationSettings";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private static final String KEY_IMPORTANCE = "allow_sound";
|
||||
private static String KEY_GENERAL_CATEGORY = "categories";
|
||||
private static String KEY_DELETED = "deleted";
|
||||
|
||||
private List<NotificationChannelGroup> mChannelGroupList;
|
||||
private List<PreferenceCategory> mChannelGroups = new ArrayList();
|
||||
private RestrictedSwitchPreference mImportanceToggle;
|
||||
private LayoutPreference mBlockBar;
|
||||
private FooterPreference mDeletedChannels;
|
||||
private SwitchBar mSwitchBar;
|
||||
|
||||
private boolean mShowLegacyChannelConfig = false;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
@@ -92,38 +87,50 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
if (getPreferenceScreen() != null) {
|
||||
getPreferenceScreen().removeAll();
|
||||
mChannelGroups.clear();
|
||||
mDeletedChannels = null;
|
||||
mShowLegacyChannelConfig = false;
|
||||
}
|
||||
|
||||
addPreferencesFromResource(R.xml.app_notification_settings);
|
||||
addPreferencesFromResource(R.xml.notification_settings);
|
||||
getPreferenceScreen().setOrderingAsAdded(true);
|
||||
|
||||
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
|
||||
mBlockedDesc = (FooterPreference) getPreferenceScreen().findPreference(KEY_BLOCKED_DESC);
|
||||
|
||||
setupBlock();
|
||||
setupBadge();
|
||||
// load settings intent
|
||||
addHeaderPref();
|
||||
addAppLinkPref();
|
||||
|
||||
mShowLegacyChannelConfig = mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid);
|
||||
if (mShowLegacyChannelConfig) {
|
||||
mChannel = mBackend.getChannel(
|
||||
mAppRow.pkg, mAppRow.uid, NotificationChannel.DEFAULT_CHANNEL_ID);
|
||||
populateDefaultChannelPrefs();
|
||||
} else {
|
||||
addPreferencesFromResource(R.xml.upgraded_app_notification_settings);
|
||||
setupBadge();
|
||||
// Load channel settings
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... unused) {
|
||||
mChannelGroupList = mBackend.getChannelGroups(mPkg, mUid).getList();
|
||||
Collections.sort(mChannelGroupList, mChannelGroupComparator);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void unused) {
|
||||
if (getHost() == null) {
|
||||
return;
|
||||
}
|
||||
populateChannelList();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
updateDependents(mAppRow.banned);
|
||||
}
|
||||
|
||||
private void addHeaderPref() {
|
||||
ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
|
||||
rows.put(mAppRow.pkg, mAppRow);
|
||||
collectConfigActivities(rows);
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... unused) {
|
||||
mChannelGroupList = mBackend.getChannelGroups(mPkg, mUid).getList();
|
||||
Collections.sort(mChannelGroupList, mChannelGroupComparator);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void unused) {
|
||||
if (getHost() == null) {
|
||||
return;
|
||||
}
|
||||
populateChannelList();
|
||||
}
|
||||
}.execute();
|
||||
|
||||
final Activity activity = getActivity();
|
||||
final Preference pref = FeatureFactory.getFactory(activity)
|
||||
.getApplicationFeatureProvider(activity)
|
||||
@@ -135,15 +142,15 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
|
||||
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
|
||||
.done(activity, getPrefContext());
|
||||
pref.setKey(KEY_HEADER);
|
||||
getPreferenceScreen().addPreference(pref);
|
||||
|
||||
updateDependents(mAppRow.banned);
|
||||
}
|
||||
|
||||
private void populateChannelList() {
|
||||
if (mChannelGroupList.isEmpty()) {
|
||||
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
||||
groupCategory.setTitle(R.string.notification_channels);
|
||||
groupCategory.setKey(KEY_GENERAL_CATEGORY);
|
||||
getPreferenceScreen().addPreference(groupCategory);
|
||||
mChannelGroups.add(groupCategory);
|
||||
|
||||
@@ -151,15 +158,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
empty.setTitle(R.string.no_channels);
|
||||
empty.setEnabled(false);
|
||||
groupCategory.addPreference(empty);
|
||||
|
||||
} else if (mChannelGroupList.size() == 1 &&
|
||||
mChannelGroupList.get(0).getChannels().get(0).getId()
|
||||
.equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
|
||||
// Legacy app using only default channel. Hoist default channel settings to main panel.
|
||||
mShowLegacyChannelConfig = true;
|
||||
mChannel = mChannelGroupList.get(0).getChannels().get(0);
|
||||
populateDefaultChannelPrefs();
|
||||
|
||||
} else {
|
||||
for (NotificationChannelGroup group : mChannelGroupList) {
|
||||
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
||||
@@ -167,10 +165,11 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
groupCategory.setTitle(mChannelGroupList.size() > 1
|
||||
? R.string.notification_channels_other
|
||||
: R.string.notification_channels);
|
||||
groupCategory.setKey(KEY_GENERAL_CATEGORY);
|
||||
} else {
|
||||
groupCategory.setTitle(group.getName());
|
||||
groupCategory.setKey(group.getId());
|
||||
}
|
||||
groupCategory.setKey(group.getId());
|
||||
groupCategory.setOrderingAsAdded(true);
|
||||
getPreferenceScreen().addPreference(groupCategory);
|
||||
mChannelGroups.add(groupCategory);
|
||||
@@ -184,13 +183,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
}
|
||||
}
|
||||
|
||||
if (mAppRow.settingsIntent != null) {
|
||||
Preference intentPref = new Preference(getPrefContext());
|
||||
intentPref.setIntent(mAppRow.settingsIntent);
|
||||
intentPref.setTitle(mContext.getString(R.string.app_settings_link));
|
||||
getPreferenceScreen().addPreference(intentPref);
|
||||
}
|
||||
|
||||
int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
|
||||
if (deletedChannelCount > 0) {
|
||||
mDeletedChannels = new FooterPreference(getPrefContext());
|
||||
@@ -198,9 +190,12 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
mDeletedChannels.setTitle(getResources().getQuantityString(
|
||||
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
|
||||
mDeletedChannels.setEnabled(false);
|
||||
mDeletedChannels.setKey(KEY_DELETED);
|
||||
mDeletedChannels.setOrder(ORDER_LAST);
|
||||
getPreferenceScreen().addPreference(mDeletedChannels);
|
||||
}
|
||||
}
|
||||
|
||||
updateDependents(mAppRow.banned);
|
||||
}
|
||||
|
||||
@@ -212,7 +207,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
channelPref.setKey(channel.getId());
|
||||
channelPref.setTitle(channel.getName());
|
||||
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
|
||||
channelPref.setSummary(getImportanceSummary(channel.getImportance()));
|
||||
channelPref.setSummary(getImportanceSummary(channel));
|
||||
Bundle channelArgs = new Bundle();
|
||||
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
||||
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
||||
@@ -234,7 +229,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
channel.setImportance(importance);
|
||||
channel.lockFields(
|
||||
NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||
channelPref.setSummary(getImportanceSummary(channel.getImportance()));
|
||||
channelPref.setSummary(getImportanceSummary(channel));
|
||||
mBackend.updateChannel(mPkg, mUid, channel);
|
||||
|
||||
return true;
|
||||
@@ -243,36 +238,25 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
groupCategory.addPreference(channelPref);
|
||||
}
|
||||
|
||||
private void populateDefaultChannelPrefs() {
|
||||
addPreferencesFromResource(R.xml.legacy_channel_notification_settings);
|
||||
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||
mVisibilityOverride =
|
||||
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
|
||||
mImportanceToggle = (RestrictedSwitchPreference) findPreference(KEY_IMPORTANCE);
|
||||
|
||||
if (mPkgInfo != null && mChannel != null) {
|
||||
setupPriorityPref(mChannel.canBypassDnd());
|
||||
setupVisOverridePref(mChannel.getLockscreenVisibility());
|
||||
setupImportanceToggle();
|
||||
void setupBadge() {
|
||||
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
|
||||
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
if (mChannel == null) {
|
||||
mBadge.setChecked(mAppRow.showBadge);
|
||||
} else {
|
||||
mBadge.setChecked(mChannel.canShowBadge());
|
||||
}
|
||||
mSwitchBar.setChecked(!mAppRow.banned
|
||||
&& mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
||||
}
|
||||
|
||||
// 'allow sound'
|
||||
private void setupImportanceToggle() {
|
||||
mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
|
||||
|| mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
|
||||
mImportanceToggle.setOnPreferenceChangeListener(
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
mBadge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final int importance =
|
||||
((Boolean) newValue ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_LOW);
|
||||
mChannel.setImportance(importance);
|
||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||
final boolean value = (Boolean) newValue;
|
||||
if (mChannel == null) {
|
||||
mBackend.setShowBadge(mPkg, mUid, value);
|
||||
} else {
|
||||
mChannel.setShowBadge(value);
|
||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
|
||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -296,12 +280,13 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||
}
|
||||
mBackend.setNotificationsEnabledForPackage(mPkgInfo.packageName, mUid, isChecked);
|
||||
mAppRow.banned = true;
|
||||
updateDependents(!isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
|
||||
mBlockBar.setOrder(-500);
|
||||
mBlockBar.setOrder(ORDER_FIRST);
|
||||
mBlockBar.setKey(KEY_BLOCK);
|
||||
getPreferenceScreen().addPreference(mBlockBar);
|
||||
|
||||
@@ -312,20 +297,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
setupBlockDesc(R.string.app_notifications_off_desc);
|
||||
}
|
||||
|
||||
private void setupBadge() {
|
||||
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mBadge.setChecked(mAppRow.showBadge);
|
||||
mBadge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean value = (Boolean) newValue;
|
||||
mBackend.setShowBadge(mPkg, mUid, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateDependents(boolean banned) {
|
||||
protected void updateDependents(boolean banned) {
|
||||
for (PreferenceCategory category : mChannelGroups) {
|
||||
setVisible(category, !banned);
|
||||
}
|
||||
@@ -336,17 +308,42 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
setVisible(mBadge, !banned);
|
||||
if (mShowLegacyChannelConfig) {
|
||||
setVisible(mImportanceToggle, !banned);
|
||||
setVisible(mPriority, !banned);
|
||||
setVisible(mVisibilityOverride, !banned);
|
||||
setVisible(mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
|
||||
|| (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
|
||||
&& mDndVisualEffectsSuppressed));
|
||||
setVisible(mVisibilityOverride, !banned &&
|
||||
checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure());
|
||||
}
|
||||
if (mAppLink != null) {
|
||||
setVisible(mAppLink, !banned);
|
||||
}
|
||||
if (mAppRow.systemApp && !mAppRow.banned) {
|
||||
setVisible(mBlockBar, false);
|
||||
}
|
||||
}
|
||||
|
||||
private String getImportanceSummary(NotificationChannel channel) {
|
||||
switch (channel.getImportance()) {
|
||||
case NotificationManager.IMPORTANCE_UNSPECIFIED:
|
||||
return getContext().getString(R.string.notification_importance_unspecified);
|
||||
case NotificationManager.IMPORTANCE_NONE:
|
||||
return getContext().getString(R.string.notification_toggle_off);
|
||||
case NotificationManager.IMPORTANCE_MIN:
|
||||
return getContext().getString(R.string.notification_importance_min_title);
|
||||
case NotificationManager.IMPORTANCE_LOW:
|
||||
return getContext().getString(R.string.notification_importance_low_title);
|
||||
case NotificationManager.IMPORTANCE_DEFAULT:
|
||||
return getContext().getString(R.string.notification_importance_default_title);
|
||||
case NotificationManager.IMPORTANCE_HIGH:
|
||||
case NotificationManager.IMPORTANCE_MAX:
|
||||
default:
|
||||
return getContext().getString(R.string.notification_importance_high_title);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Comparator<NotificationChannel> mChannelComparator =
|
||||
new Comparator<NotificationChannel>() {
|
||||
private final Collator sCollator = Collator.getInstance();
|
||||
|
||||
@Override
|
||||
public int compare(NotificationChannel left, NotificationChannel right) {
|
||||
@@ -359,7 +356,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
|
||||
private Comparator<NotificationChannelGroup> mChannelGroupComparator =
|
||||
new Comparator<NotificationChannelGroup>() {
|
||||
private final Collator sCollator = Collator.getInstance();
|
||||
|
||||
@Override
|
||||
public int compare(NotificationChannelGroup left, NotificationChannelGroup right) {
|
||||
|
Reference in New Issue
Block a user