diff --git a/res/values/strings.xml b/res/values/strings.xml index 4ab6585aeba..b7a8726fec7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -6473,8 +6473,14 @@ This app has not posted any notifications - - %1$s (deleted) + + Additional settings in the app + + + + %d category deleted + %d categories deleted + Block all diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml index 4af9fe8e668..fde1bfa6004 100644 --- a/res/xml/channel_notification_settings.xml +++ b/res/xml/channel_notification_settings.xml @@ -23,29 +23,25 @@ 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" /> + android:title="@string/notification_importance_title" /> @@ -53,7 +49,6 @@ android:key="badge" android:title="@string/notification_badge_title" android:summary="@string/notification_badge_summary" - android:order="5" settings:useAdditionalSummary="true" settings:restrictedSwitchSummary="@string/enabled_by_admin" /> @@ -61,21 +56,18 @@ + android:title="@string/app_notification_visibility_override_title" /> diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index 88d0a4714bd..24405b349df 100644 --- a/src/com/android/settings/notification/AppNotificationSettings.java +++ b/src/com/android/settings/notification/AppNotificationSettings.java @@ -34,6 +34,7 @@ import android.util.Log; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.AppHeader; +import com.android.settings.DimmableIconPreference; import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.applications.AppHeaderController; @@ -66,14 +67,18 @@ public class AppNotificationSettings extends NotificationSettingsBase { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onResume() { + super.onResume(); + if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) { Log.w(TAG, "Missing package or uid or packageinfo"); - toastAndFinish(); + finish(); return; } - final Activity activity = getActivity(); + + if (getPreferenceScreen() != null) { + getPreferenceScreen().removeAll(); + } addPreferencesFromResource(R.xml.app_notification_settings); getPreferenceScreen().setOrderingAsAdded(true); @@ -81,44 +86,38 @@ public class AppNotificationSettings extends NotificationSettingsBase { mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK); mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE); - if (mPkgInfo != null) { - setupBlock(); - setupBadge(); - // load settings intent - ArrayMap rows = new ArrayMap(); - rows.put(mAppRow.pkg, mAppRow); - collectConfigActivities(rows); - new AsyncTask() { - @Override - protected Void doInBackground(Void... unused) { - mChannelGroupList = mBackend.getChannelGroups(mPkg, mUid).getList(); - Collections.sort(mChannelGroupList, mChannelGroupComparator); - return null; - } + setupBlock(); + setupBadge(); + // load settings intent + ArrayMap rows = new ArrayMap(); + rows.put(mAppRow.pkg, mAppRow); + collectConfigActivities(rows); + new AsyncTask() { + @Override + protected Void doInBackground(Void... unused) { + mChannelGroupList = mBackend.getChannelGroups(mPkg, mUid).getList(); + Collections.sort(mChannelGroupList, mChannelGroupComparator); + return null; + } - @Override - protected void onPostExecute(Void unused) { - populateChannelList(); - } - }.execute(); - } - final Preference pref = FeatureFactory.getFactory(activity) - .getApplicationFeatureProvider(activity) - .newAppHeaderController(this /* fragment */, null /* appHeader */) - .setIcon(mAppRow.icon) - .setLabel(mAppRow.label) - .setPackageName(mAppRow.pkg) - .setUid(mAppRow.uid) - .setAppNotifPrefIntent(mAppRow.settingsIntent) - .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO, - AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE) - .done(getPrefContext()); + @Override + protected void onPostExecute(Void unused) { + populateChannelList(); + } + }.execute(); + + final Preference pref = FeatureFactory.getFactory(getActivity()) + .getApplicationFeatureProvider(getActivity()) + .newAppHeaderController(this /* fragment */, null /* appHeader */) + .setIcon(mAppRow.icon) + .setLabel(mAppRow.label) + .setPackageName(mAppRow.pkg) + .setUid(mAppRow.uid) + .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO, + AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE) + .done(getPrefContext()); getPreferenceScreen().addPreference(pref); - } - @Override - public void onResume() { - super.onResume(); if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) { Log.w(TAG, "Missing package or uid or packageinfo"); finish(); @@ -164,42 +163,52 @@ public class AppNotificationSettings extends NotificationSettingsBase { channelPref.setTitle(channel.getName()); channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE); 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.setTitle(getString(R.string.deleted_channel_name, - channel.getName())); - channelPref.setEnabled(false); - } else { - 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); + channelPref.setOnPreferenceChangeListener( + 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); - channelPref.setOnPreferenceChangeListener( - 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; - } - }); - } + return true; + } + }); 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); } diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java index 9ca1d865bab..7f7aa081447 100644 --- a/src/com/android/settings/notification/ChannelNotificationSettings.java +++ b/src/com/android/settings/notification/ChannelNotificationSettings.java @@ -73,19 +73,22 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onResume() { + super.onResume(); if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) { Log.w(TAG, "Missing package or uid or packageinfo or channel"); - toastAndFinish(); + finish(); return; } - final Activity activity = getActivity(); + + if (getPreferenceScreen() != null) { + getPreferenceScreen().removeAll(); + } addPreferencesFromResource(R.xml.channel_notification_settings); + getPreferenceScreen().setOrderingAsAdded(true); // load settings intent - ArrayMap - rows = new ArrayMap(); + ArrayMap rows = new ArrayMap(); rows.put(mAppRow.pkg, mAppRow); collectConfigActivities(rows); @@ -109,36 +112,25 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { setupBlockAndImportance(); updateDependents(); } - final Preference pref = FeatureFactory.getFactory(activity) - .getApplicationFeatureProvider(activity) - .newAppHeaderController(this /* fragment */, null /* appHeader */) - .setIcon(mAppRow.icon) - .setLabel(mChannel.getName()) - .setSummary(mAppRow.label) - .setPackageName(mAppRow.pkg) - .setUid(mAppRow.uid) - .setAppNotifPrefIntent(mAppRow.settingsIntent) - .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO, - AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE) - .done(getPrefContext()); + final Preference pref = FeatureFactory.getFactory(getActivity()) + .getApplicationFeatureProvider(getActivity()) + .newAppHeaderController(this /* fragment */, null /* appHeader */) + .setIcon(mAppRow.icon) + .setLabel(mChannel.getName()) + .setSummary(mAppRow.label) + .setPackageName(mAppRow.pkg) + .setUid(mAppRow.uid) + .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO, + AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE) + .done(getPrefContext()); getPreferenceScreen().addPreference(pref); - } - @Override - public void onResume() { - super.onResume(); - if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) { - Log.w(TAG, "Missing package or uid or packageinfo or channel"); - finish(); - return; + 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); } - mLights.setDisabledByAdmin(mSuspendedAppsAdmin); - mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin); - if (mImportance.isEnabled()) { - mImportance.setDisabledByAdmin(mSuspendedAppsAdmin); - } - mPriority.setDisabledByAdmin(mSuspendedAppsAdmin); - mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin); } private void setupLights() { @@ -321,6 +313,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { return true; } }); + mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin); } private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry, diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java index 0881eb76553..c1ef018fe04 100644 --- a/src/com/android/settings/notification/NotificationBackend.java +++ b/src/com/android/settings/notification/NotificationBackend.java @@ -124,7 +124,7 @@ public class NotificationBackend { public ParceledListSlice getChannelGroups(String pkg, int uid) { try { - return sINM.getNotificationChannelGroupsForPackage(pkg, uid, true); + return sINM.getNotificationChannelGroupsForPackage(pkg, uid, false); } catch (Exception e) { Log.w(TAG, "Error calling NoMan", e); 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 { public String section; } diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java index c666b72bd33..960c3b83286 100644 --- a/src/com/android/settings/notification/NotificationSettingsBase.java +++ b/src/com/android/settings/notification/NotificationSettingsBase.java @@ -127,15 +127,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen } 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 @@ -146,12 +137,19 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen finish(); 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( mContext, mPkg, mUserId); - if (mBlock.isEnabled()) { - mBlock.setDisabledByAdmin(mSuspendedAppsAdmin); - } - mBadge.setDisabledByAdmin(mSuspendedAppsAdmin); } protected void setVisible(Preference p, boolean visible) {