Notification channel settings updates

- Show a deleted count instead of individual deleted channels
- Make the link to app settings more prominent
- Reload settings onresume

Change-Id: I4f493181194943310ba536eb2bca270cec7cafce
Fixes: 36119790
Fixes: 36191444
Test: manual
This commit is contained in:
Julia Reynolds
2017-03-15 11:32:54 -04:00
parent 2194f3db37
commit 8973e2786d
6 changed files with 136 additions and 129 deletions

View File

@@ -6473,8 +6473,14 @@
<!-- [CHAR LIMIT=NONE] App notification settings: no channels --> <!-- [CHAR LIMIT=NONE] App notification settings: no channels -->
<string name="no_channels">This app has not posted any notifications</string> <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=NONE] App notification settings: link to app notification settings-->
<string name="deleted_channel_name"><xliff:g id="channel_name" example="Promotions">%1$s</xliff:g> (deleted)</string> <string name="app_settings_link">Additional settings in the app</string>
<!-- [CHAR LIMIT=NONE] Footer listing a count of deleted channels. -->
<plurals name="deleted_channels">
<item quantity="one">%d category deleted</item>
<item quantity="other">%d categories deleted</item>
</plurals>
<!-- [CHAR LIMIT=NONE] App notification settings: Block option title --> <!-- [CHAR LIMIT=NONE] App notification settings: Block option title -->
<string name="app_notification_block_title">Block all</string> <string name="app_notification_block_title">Block all</string>

View File

@@ -23,29 +23,25 @@
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" />
<!-- Importance --> <!-- Importance -->
<com.android.settings.notification.RestrictedDropDownPreference <com.android.settings.notification.RestrictedDropDownPreference
android:key="importance" android:key="importance"
android:title="@string/notification_importance_title" android:title="@string/notification_importance_title" />
android:order="2"/>
<!-- Default ringtone --> <!-- Default ringtone -->
<com.android.settings.notification.DefaultNotificationTonePreference <com.android.settings.notification.DefaultNotificationTonePreference
android:key="ringtone" android:key="ringtone"
android:title="@string/notification_ringtone_title" android:title="@string/notification_ringtone_title"
android:dialogTitle="@string/notification_ringtone_title" android:dialogTitle="@string/notification_ringtone_title"
android:order="3"
android:ringtoneType="notification" /> android:ringtoneType="notification" />
<!-- Vibration --> <!-- Vibration -->
<com.android.settingslib.RestrictedSwitchPreference <com.android.settingslib.RestrictedSwitchPreference
android:key="vibrate" android:key="vibrate"
android:title="@string/notification_vibrate_title" android:title="@string/notification_vibrate_title"
android:order="4"
settings:useAdditionalSummary="true" /> settings:useAdditionalSummary="true" />
<!-- Show badge --> <!-- Show badge -->
@@ -53,7 +49,6 @@
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="5"
settings:useAdditionalSummary="true" settings:useAdditionalSummary="true"
settings:restrictedSwitchSummary="@string/enabled_by_admin" /> settings:restrictedSwitchSummary="@string/enabled_by_admin" />
@@ -61,21 +56,18 @@
<com.android.settingslib.RestrictedSwitchPreference <com.android.settingslib.RestrictedSwitchPreference
android:key="lights" android:key="lights"
android:title="@string/notification_show_lights_title" android:title="@string/notification_show_lights_title"
android:order="6"
settings:useAdditionalSummary="true" /> settings:useAdditionalSummary="true" />
<!-- Visibility Override --> <!-- Visibility Override -->
<com.android.settings.notification.RestrictedDropDownPreference <com.android.settings.notification.RestrictedDropDownPreference
android:key="visibility_override" android:key="visibility_override"
android:title="@string/app_notification_visibility_override_title" android:title="@string/app_notification_visibility_override_title" />
android:order="7" />
<!-- Bypass DND --> <!-- Bypass DND -->
<com.android.settingslib.RestrictedSwitchPreference <com.android.settingslib.RestrictedSwitchPreference
android:key="bypass_dnd" android:key="bypass_dnd"
android:title="@string/app_notification_override_dnd_title" android:title="@string/app_notification_override_dnd_title"
android:summary="@string/app_notification_override_dnd_summary" android:summary="@string/app_notification_override_dnd_summary"
android:order="8"
settings:useAdditionalSummary="true" /> settings:useAdditionalSummary="true" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -34,6 +34,7 @@ import android.util.Log;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.AppHeader; import com.android.settings.AppHeader;
import com.android.settings.DimmableIconPreference;
import com.android.settings.R; 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;
@@ -66,14 +67,18 @@ public class AppNotificationSettings extends NotificationSettingsBase {
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onResume() {
super.onCreate(savedInstanceState); super.onResume();
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) { if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
Log.w(TAG, "Missing package or uid or packageinfo"); Log.w(TAG, "Missing package or uid or packageinfo");
toastAndFinish(); finish();
return; return;
} }
final Activity activity = getActivity();
if (getPreferenceScreen() != null) {
getPreferenceScreen().removeAll();
}
addPreferencesFromResource(R.xml.app_notification_settings); addPreferencesFromResource(R.xml.app_notification_settings);
getPreferenceScreen().setOrderingAsAdded(true); getPreferenceScreen().setOrderingAsAdded(true);
@@ -81,44 +86,38 @@ public class AppNotificationSettings extends NotificationSettingsBase {
mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK); mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE); mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
if (mPkgInfo != null) { setupBlock();
setupBlock(); setupBadge();
setupBadge(); // load settings intent
// load settings intent 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); new AsyncTask<Void, Void, Void>() {
new AsyncTask<Void, Void, Void>() { @Override
@Override protected Void doInBackground(Void... unused) {
protected Void doInBackground(Void... unused) { mChannelGroupList = mBackend.getChannelGroups(mPkg, mUid).getList();
mChannelGroupList = mBackend.getChannelGroups(mPkg, mUid).getList(); Collections.sort(mChannelGroupList, mChannelGroupComparator);
Collections.sort(mChannelGroupList, mChannelGroupComparator); return null;
return null; }
}
@Override @Override
protected void onPostExecute(Void unused) { protected void onPostExecute(Void unused) {
populateChannelList(); populateChannelList();
} }
}.execute(); }.execute();
}
final Preference pref = FeatureFactory.getFactory(activity) final Preference pref = FeatureFactory.getFactory(getActivity())
.getApplicationFeatureProvider(activity) .getApplicationFeatureProvider(getActivity())
.newAppHeaderController(this /* fragment */, null /* appHeader */) .newAppHeaderController(this /* fragment */, null /* appHeader */)
.setIcon(mAppRow.icon) .setIcon(mAppRow.icon)
.setLabel(mAppRow.label) .setLabel(mAppRow.label)
.setPackageName(mAppRow.pkg) .setPackageName(mAppRow.pkg)
.setUid(mAppRow.uid) .setUid(mAppRow.uid)
.setAppNotifPrefIntent(mAppRow.settingsIntent) .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO, AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE) .done(getPrefContext());
.done(getPrefContext());
getPreferenceScreen().addPreference(pref); getPreferenceScreen().addPreference(pref);
}
@Override
public void onResume() {
super.onResume();
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) { if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
Log.w(TAG, "Missing package or uid or packageinfo"); Log.w(TAG, "Missing package or uid or packageinfo");
finish(); finish();
@@ -164,42 +163,52 @@ public class AppNotificationSettings extends NotificationSettingsBase {
channelPref.setTitle(channel.getName()); channelPref.setTitle(channel.getName());
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE); channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
channelPref.setMultiLine(true); channelPref.setMultiLine(true);
channelPref.setSummary(getImportanceSummary(channel.getImportance()));
Bundle channelArgs = new Bundle();
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
ChannelNotificationSettings.class.getName(),
channelArgs, null, 0, null, false, getMetricsCategory());
channelPref.setIntent(channelIntent);
if (channel.isDeleted()) { channelPref.setOnPreferenceChangeListener(
channelPref.setTitle(getString(R.string.deleted_channel_name, new Preference.OnPreferenceChangeListener() {
channel.getName())); @Override
channelPref.setEnabled(false); public boolean onPreferenceChange(Preference preference,
} else { Object o) {
channelPref.setSummary(getImportanceSummary(channel.getImportance())); boolean value = (Boolean) o;
Bundle channelArgs = new Bundle(); int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid); channel.setImportance(importance);
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true); channel.lockFields(
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg); NotificationChannel.USER_LOCKED_IMPORTANCE);
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId()); mBackend.updateChannel(mPkg, mUid, channel);
Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
ChannelNotificationSettings.class.getName(),
channelArgs, null, 0, null, false, getMetricsCategory());
channelPref.setIntent(channelIntent);
channelPref.setOnPreferenceChangeListener( return true;
new Preference.OnPreferenceChangeListener() { }
@Override });
public boolean onPreferenceChange(Preference preference,
Object o) {
boolean value = (Boolean) o;
int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
channel.setImportance(importance);
channel.lockFields(
NotificationChannel.USER_LOCKED_IMPORTANCE);
mBackend.updateChannel(mPkg, mUid, channel);
return true;
}
});
}
groupCategory.addPreference(channelPref); groupCategory.addPreference(channelPref);
} }
} }
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) {
DimmableIconPreference deletedPref = new DimmableIconPreference(getPrefContext());
deletedPref.setEnabled(false);
deletedPref.setTitle(getResources().getQuantityString(
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
deletedPref.setIcon(R.drawable.ic_info);
getPreferenceScreen().addPreference(deletedPref);
}
} }
updateDependents(mAppRow.banned); updateDependents(mAppRow.banned);
} }

View File

@@ -73,19 +73,22 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onResume() {
super.onCreate(savedInstanceState); super.onResume();
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) { if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) {
Log.w(TAG, "Missing package or uid or packageinfo or channel"); Log.w(TAG, "Missing package or uid or packageinfo or channel");
toastAndFinish(); finish();
return; return;
} }
final Activity activity = getActivity();
if (getPreferenceScreen() != null) {
getPreferenceScreen().removeAll();
}
addPreferencesFromResource(R.xml.channel_notification_settings); addPreferencesFromResource(R.xml.channel_notification_settings);
getPreferenceScreen().setOrderingAsAdded(true);
// load settings intent // load settings intent
ArrayMap<String, NotificationBackend.AppRow> ArrayMap<String, NotificationBackend.AppRow> rows = new ArrayMap<String, NotificationBackend.AppRow>();
rows = new ArrayMap<String, NotificationBackend.AppRow>();
rows.put(mAppRow.pkg, mAppRow); rows.put(mAppRow.pkg, mAppRow);
collectConfigActivities(rows); collectConfigActivities(rows);
@@ -109,36 +112,25 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
setupBlockAndImportance(); setupBlockAndImportance();
updateDependents(); updateDependents();
} }
final Preference pref = FeatureFactory.getFactory(activity) final Preference pref = FeatureFactory.getFactory(getActivity())
.getApplicationFeatureProvider(activity) .getApplicationFeatureProvider(getActivity())
.newAppHeaderController(this /* fragment */, null /* appHeader */) .newAppHeaderController(this /* fragment */, null /* appHeader */)
.setIcon(mAppRow.icon) .setIcon(mAppRow.icon)
.setLabel(mChannel.getName()) .setLabel(mChannel.getName())
.setSummary(mAppRow.label) .setSummary(mAppRow.label)
.setPackageName(mAppRow.pkg) .setPackageName(mAppRow.pkg)
.setUid(mAppRow.uid) .setUid(mAppRow.uid)
.setAppNotifPrefIntent(mAppRow.settingsIntent) .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO, AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE) .done(getPrefContext());
.done(getPrefContext());
getPreferenceScreen().addPreference(pref); getPreferenceScreen().addPreference(pref);
}
@Override if (mAppRow.settingsIntent != null) {
public void onResume() { Preference intentPref = new Preference(getPrefContext());
super.onResume(); intentPref.setIntent(mAppRow.settingsIntent);
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) { intentPref.setTitle(mContext.getString(R.string.app_settings_link));
Log.w(TAG, "Missing package or uid or packageinfo or channel"); getPreferenceScreen().addPreference(intentPref);
finish();
return;
} }
mLights.setDisabledByAdmin(mSuspendedAppsAdmin);
mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin);
if (mImportance.isEnabled()) {
mImportance.setDisabledByAdmin(mSuspendedAppsAdmin);
}
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin);
} }
private void setupLights() { private void setupLights() {
@@ -321,6 +313,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
return true; return true;
} }
}); });
mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin);
} }
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry, private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,

View File

@@ -124,7 +124,7 @@ public class NotificationBackend {
public ParceledListSlice<NotificationChannelGroup> getChannelGroups(String pkg, int uid) { public ParceledListSlice<NotificationChannelGroup> getChannelGroups(String pkg, int uid) {
try { try {
return sINM.getNotificationChannelGroupsForPackage(pkg, uid, true); return sINM.getNotificationChannelGroupsForPackage(pkg, uid, false);
} 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();
@@ -139,6 +139,15 @@ public class NotificationBackend {
} }
} }
public int getDeletedChannelCount(String pkg, int uid) {
try {
return sINM.getDeletedChannelCount(pkg, uid);
} catch (Exception e) {
Log.w(TAG, "Error calling NoMan", e);
return 0;
}
}
static class Row { static class Row {
public String section; public String section;
} }

View File

@@ -127,15 +127,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
} }
mUserId = UserHandle.getUserId(mUid); mUserId = UserHandle.getUserId(mUid);
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
mChannel = (args != null && args.containsKey(Settings.EXTRA_CHANNEL_ID)) ?
mBackend.getChannel(mPkg, mUid, args.getString(Settings.EXTRA_CHANNEL_ID)) : null;
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
mContext, mPkg, mUserId);
NotificationManager.Policy policy =
NotificationManager.from(mContext).getNotificationPolicy();
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
} }
@Override @Override
@@ -146,12 +137,19 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
finish(); finish();
return; return;
} }
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
Bundle args = getArguments();
mChannel = (args != null && args.containsKey(Settings.EXTRA_CHANNEL_ID)) ?
mBackend.getChannel(mPkg, mUid, args.getString(Settings.EXTRA_CHANNEL_ID)) : null;
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
mContext, mPkg, mUserId);
NotificationManager.Policy policy =
NotificationManager.from(mContext).getNotificationPolicy();
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended( mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
mContext, mPkg, mUserId); mContext, mPkg, mUserId);
if (mBlock.isEnabled()) {
mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
}
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
} }
protected void setVisible(Preference p, boolean visible) { protected void setVisible(Preference p, boolean visible) {