Loading res/xml/legacy_channel_notification_settings.xml 0 → 100644 +38 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" > <!-- Importance toggle --> <com.android.settingslib.RestrictedSwitchPreference android:key="allow_sound" android:title="@string/allow_sound" /> <!-- Visibility Override --> <com.android.settings.notification.RestrictedDropDownPreference android:key="visibility_override" android:title="@string/app_notification_visibility_override_title" /> <!-- Bypass DND --> <com.android.settingslib.RestrictedSwitchPreference android:key="bypass_dnd" android:title="@string/app_notification_override_dnd_title" android:summary="@string/app_notification_override_dnd_summary" settings:useAdditionalSummary="true" /> </PreferenceScreen> src/com/android/settings/notification/AppNotificationSettings.java +88 −33 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ 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; Loading Loading @@ -56,9 +57,13 @@ public class AppNotificationSettings extends NotificationSettingsBase { private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final String KEY_BLOCK = "block"; private static final String KEY_IMPORTANCE = "allow_sound"; private List<NotificationChannelGroup> mChannelGroupList; private List<PreferenceCategory> mChannelGroups = new ArrayList(); private RestrictedSwitchPreference mImportanceToggle; private boolean mShowLegacyChannelConfig = false; @Override public int getMetricsCategory() { Loading Loading @@ -139,6 +144,15 @@ 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()); Loading @@ -159,6 +173,32 @@ public class AppNotificationSettings extends NotificationSettingsBase { int N = channels.size(); for (int i = 0; i < N; i++) { final NotificationChannel channel = channels.get(i); populateSingleChannelPrefs(groupCategory, channel); } } 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.setSelectable(false); deletedPref.setTitle(getResources().getQuantityString( R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount)); deletedPref.setIcon(R.drawable.ic_info); getPreferenceScreen().addPreference(deletedPref); } } updateDependents(mAppRow.banned); } private void populateSingleChannelPrefs(PreferenceCategory groupCategory, final NotificationChannel channel) { MasterSwitchPreference channelPref = new MasterSwitchPreference( getPrefContext()); channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null && !mAppRow.systemApp); Loading Loading @@ -193,26 +233,36 @@ public class AppNotificationSettings extends NotificationSettingsBase { }); 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); 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(); } int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid); if (deletedChannelCount > 0) { DimmableIconPreference deletedPref = new DimmableIconPreference(getPrefContext()); deletedPref.setSelectable(false); deletedPref.setTitle(getResources().getQuantityString( R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount)); deletedPref.setIcon(R.drawable.ic_info); getPreferenceScreen().addPreference(deletedPref); } private void setupImportanceToggle() { mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin); mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT); mImportanceToggle.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final int importance = ((Boolean) newValue ? IMPORTANCE_DEFAULT : IMPORTANCE_LOW); mChannel.setImportance(importance); mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } updateDependents(mAppRow.banned); }); } private void setupBadge() { Loading Loading @@ -254,6 +304,11 @@ public class AppNotificationSettings extends NotificationSettingsBase { setVisible(category, !banned); } setVisible(mBadge, !banned); if (mShowLegacyChannelConfig) { setVisible(mImportanceToggle, !banned); setVisible(mPriority, !banned); setVisible(mVisibilityOverride, !banned); } if (mAppRow.systemApp && !mAppRow.banned) { setVisible(mBlock, false); } Loading src/com/android/settings/notification/ChannelNotificationSettings.java +1 −110 Original line number Diff line number Diff line Loading @@ -22,16 +22,13 @@ import static android.app.NotificationManager.IMPORTANCE_MIN; import static android.app.NotificationManager.IMPORTANCE_NONE; import android.app.Activity; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.admin.DevicePolicyManager; import android.content.Intent; import android.content.pm.UserInfo; import android.net.Uri; import android.os.UserHandle; import android.provider.Settings; import android.service.notification.NotificationListenerService.Ranking; import android.support.v7.preference.Preference; import android.text.TextUtils; import android.util.ArrayMap; Loading @@ -44,7 +41,6 @@ import com.android.settings.R; import com.android.settings.RingtonePreference; import com.android.settings.applications.AppHeaderController; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedSwitchPreference; import java.util.ArrayList; Loading @@ -53,9 +49,6 @@ import java.util.List; public class ChannelNotificationSettings extends NotificationSettingsBase { private static final String TAG = "ChannelSettings"; protected static final String KEY_BYPASS_DND = "bypass_dnd"; protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override"; protected static final String KEY_IMPORTANCE = "importance"; protected static final String KEY_LIGHTS = "lights"; protected static final String KEY_VIBRATE = "vibrate"; protected static final String KEY_RINGTONE = "ringtone"; Loading @@ -63,9 +56,6 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { protected RestrictedSwitchPreference mLights; protected RestrictedSwitchPreference mVibrate; protected NotificationSoundPreference mRingtone; protected RestrictedDropDownPreference mImportance; protected RestrictedSwitchPreference mPriority; protected RestrictedDropDownPreference mVisibilityOverride; @Override public int getMetricsCategory() { Loading Loading @@ -224,7 +214,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { final int numImportances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1; List<String> summaries = new ArrayList<>(); List<String> values = new ArrayList<>(); ; for (int i = 0; i < numImportances; i++) { int importance = i + 1; summaries.add(getImportanceSummary(importance)); Loading Loading @@ -256,105 +246,6 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { } } protected void setupPriorityPref(boolean priority) { mPriority.setDisabledByAdmin(mSuspendedAppsAdmin); mPriority.setChecked(priority); mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean bypassZenMode = (Boolean) newValue; mChannel.setBypassDnd(bypassZenMode); mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } }); } protected void setupVisOverridePref(int sensitive) { ArrayList<CharSequence> entries = new ArrayList<>(); ArrayList<CharSequence> values = new ArrayList<>(); mVisibilityOverride.clearRestrictedItems(); if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) { final String summaryShowEntry = getString(R.string.lock_screen_notifications_summary_show); final String summaryShowEntryValue = Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE); entries.add(summaryShowEntry); values.add(summaryShowEntryValue); setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue, DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); } final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide); final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE); entries.add(summaryHideEntry); values.add(summaryHideEntryValue); setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue, DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); entries.add(getString(R.string.lock_screen_notifications_summary_disable)); values.add(Integer.toString(Notification.VISIBILITY_SECRET)); mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()])); mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()])); if (sensitive == Ranking.VISIBILITY_NO_OVERRIDE) { mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility())); } else { mVisibilityOverride.setValue(Integer.toString(sensitive)); } mVisibilityOverride.setSummary("%s"); mVisibilityOverride.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int sensitive = Integer.parseInt((String) newValue); if (sensitive == getGlobalVisibility()) { sensitive = Ranking.VISIBILITY_NO_OVERRIDE; } mChannel.setLockscreenVisibility(sensitive); mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } }); mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin); } private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) { RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( mContext, keyguardNotificationFeatures, mUserId); if (admin != null) { RestrictedDropDownPreference.RestrictedItem item = new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin); mVisibilityOverride.addRestrictedItem(item); } } private int getGlobalVisibility() { int globalVis = Ranking.VISIBILITY_NO_OVERRIDE; if (!getLockscreenNotificationsEnabled()) { globalVis = Notification.VISIBILITY_SECRET; } else if (!getLockscreenAllowPrivateNotifications()) { globalVis = Notification.VISIBILITY_PRIVATE; } return globalVis; } private boolean getLockscreenNotificationsEnabled() { return Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; } private boolean getLockscreenAllowPrivateNotifications() { return Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0; } private boolean isLockScreenSecure() { LockPatternUtils utils = new LockPatternUtils(getActivity()); boolean lockscreenSecure = utils.isSecure(UserHandle.myUserId()); Loading src/com/android/settings/notification/NotificationSettingsBase.java +111 −2 Original line number Diff line number Diff line Loading @@ -18,15 +18,14 @@ package com.android.settings.notification; import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.Utils; import com.android.settings.applications.AppInfoBase; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedSwitchPreference; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; Loading @@ -39,6 +38,7 @@ import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.support.v7.preference.Preference; import android.text.TextUtils; import android.util.ArrayMap; Loading @@ -47,6 +47,7 @@ import android.widget.Toast; import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import java.util.ArrayList; import java.util.List; abstract public class NotificationSettingsBase extends SettingsPreferenceFragment { Loading @@ -59,6 +60,9 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen protected static final String KEY_BLOCK = "block"; protected static final String KEY_BADGE = "badge"; protected static final String KEY_BYPASS_DND = "bypass_dnd"; protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override"; protected static final String KEY_IMPORTANCE = "importance"; protected PackageManager mPm; protected UserManager mUm; Loading @@ -71,6 +75,10 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen protected PackageInfo mPkgInfo; protected RestrictedSwitchPreference mBlock; protected RestrictedSwitchPreference mBadge; protected RestrictedDropDownPreference mImportance; protected RestrictedSwitchPreference mPriority; protected RestrictedDropDownPreference mVisibilityOverride; protected EnforcedAdmin mSuspendedAppsAdmin; protected boolean mDndVisualEffectsSuppressed; Loading Loading @@ -249,4 +257,105 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen return getContext().getString(R.string.notification_importance_high); } } protected void setupPriorityPref(boolean priority) { mPriority.setDisabledByAdmin(mSuspendedAppsAdmin); mPriority.setChecked(priority); mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean bypassZenMode = (Boolean) newValue; mChannel.setBypassDnd(bypassZenMode); mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } }); } protected void setupVisOverridePref(int sensitive) { ArrayList<CharSequence> entries = new ArrayList<>(); ArrayList<CharSequence> values = new ArrayList<>(); mVisibilityOverride.clearRestrictedItems(); if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) { final String summaryShowEntry = getString(R.string.lock_screen_notifications_summary_show); final String summaryShowEntryValue = Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE); entries.add(summaryShowEntry); values.add(summaryShowEntryValue); setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue, DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); } final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide); final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE); entries.add(summaryHideEntry); values.add(summaryHideEntryValue); setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue, DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); entries.add(getString(R.string.lock_screen_notifications_summary_disable)); values.add(Integer.toString(Notification.VISIBILITY_SECRET)); mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()])); mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()])); if (sensitive == NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE) { mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility())); } else { mVisibilityOverride.setValue(Integer.toString(sensitive)); } mVisibilityOverride.setSummary("%s"); mVisibilityOverride.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int sensitive = Integer.parseInt((String) newValue); if (sensitive == getGlobalVisibility()) { sensitive = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE; } mChannel.setLockscreenVisibility(sensitive); mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } }); mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin); } private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) { RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( mContext, keyguardNotificationFeatures, mUserId); if (admin != null) { RestrictedDropDownPreference.RestrictedItem item = new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin); mVisibilityOverride.addRestrictedItem(item); } } private int getGlobalVisibility() { int globalVis = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE; if (!getLockscreenNotificationsEnabled()) { globalVis = Notification.VISIBILITY_SECRET; } else if (!getLockscreenAllowPrivateNotifications()) { globalVis = Notification.VISIBILITY_PRIVATE; } return globalVis; } private boolean getLockscreenNotificationsEnabled() { return Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; } private boolean getLockscreenAllowPrivateNotifications() { return Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0; } } Loading
res/xml/legacy_channel_notification_settings.xml 0 → 100644 +38 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" > <!-- Importance toggle --> <com.android.settingslib.RestrictedSwitchPreference android:key="allow_sound" android:title="@string/allow_sound" /> <!-- Visibility Override --> <com.android.settings.notification.RestrictedDropDownPreference android:key="visibility_override" android:title="@string/app_notification_visibility_override_title" /> <!-- Bypass DND --> <com.android.settingslib.RestrictedSwitchPreference android:key="bypass_dnd" android:title="@string/app_notification_override_dnd_title" android:summary="@string/app_notification_override_dnd_summary" settings:useAdditionalSummary="true" /> </PreferenceScreen>
src/com/android/settings/notification/AppNotificationSettings.java +88 −33 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ 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; Loading Loading @@ -56,9 +57,13 @@ public class AppNotificationSettings extends NotificationSettingsBase { private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final String KEY_BLOCK = "block"; private static final String KEY_IMPORTANCE = "allow_sound"; private List<NotificationChannelGroup> mChannelGroupList; private List<PreferenceCategory> mChannelGroups = new ArrayList(); private RestrictedSwitchPreference mImportanceToggle; private boolean mShowLegacyChannelConfig = false; @Override public int getMetricsCategory() { Loading Loading @@ -139,6 +144,15 @@ 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()); Loading @@ -159,6 +173,32 @@ public class AppNotificationSettings extends NotificationSettingsBase { int N = channels.size(); for (int i = 0; i < N; i++) { final NotificationChannel channel = channels.get(i); populateSingleChannelPrefs(groupCategory, channel); } } 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.setSelectable(false); deletedPref.setTitle(getResources().getQuantityString( R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount)); deletedPref.setIcon(R.drawable.ic_info); getPreferenceScreen().addPreference(deletedPref); } } updateDependents(mAppRow.banned); } private void populateSingleChannelPrefs(PreferenceCategory groupCategory, final NotificationChannel channel) { MasterSwitchPreference channelPref = new MasterSwitchPreference( getPrefContext()); channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null && !mAppRow.systemApp); Loading Loading @@ -193,26 +233,36 @@ public class AppNotificationSettings extends NotificationSettingsBase { }); 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); 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(); } int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid); if (deletedChannelCount > 0) { DimmableIconPreference deletedPref = new DimmableIconPreference(getPrefContext()); deletedPref.setSelectable(false); deletedPref.setTitle(getResources().getQuantityString( R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount)); deletedPref.setIcon(R.drawable.ic_info); getPreferenceScreen().addPreference(deletedPref); } private void setupImportanceToggle() { mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin); mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT); mImportanceToggle.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final int importance = ((Boolean) newValue ? IMPORTANCE_DEFAULT : IMPORTANCE_LOW); mChannel.setImportance(importance); mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } updateDependents(mAppRow.banned); }); } private void setupBadge() { Loading Loading @@ -254,6 +304,11 @@ public class AppNotificationSettings extends NotificationSettingsBase { setVisible(category, !banned); } setVisible(mBadge, !banned); if (mShowLegacyChannelConfig) { setVisible(mImportanceToggle, !banned); setVisible(mPriority, !banned); setVisible(mVisibilityOverride, !banned); } if (mAppRow.systemApp && !mAppRow.banned) { setVisible(mBlock, false); } Loading
src/com/android/settings/notification/ChannelNotificationSettings.java +1 −110 Original line number Diff line number Diff line Loading @@ -22,16 +22,13 @@ import static android.app.NotificationManager.IMPORTANCE_MIN; import static android.app.NotificationManager.IMPORTANCE_NONE; import android.app.Activity; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.admin.DevicePolicyManager; import android.content.Intent; import android.content.pm.UserInfo; import android.net.Uri; import android.os.UserHandle; import android.provider.Settings; import android.service.notification.NotificationListenerService.Ranking; import android.support.v7.preference.Preference; import android.text.TextUtils; import android.util.ArrayMap; Loading @@ -44,7 +41,6 @@ import com.android.settings.R; import com.android.settings.RingtonePreference; import com.android.settings.applications.AppHeaderController; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedSwitchPreference; import java.util.ArrayList; Loading @@ -53,9 +49,6 @@ import java.util.List; public class ChannelNotificationSettings extends NotificationSettingsBase { private static final String TAG = "ChannelSettings"; protected static final String KEY_BYPASS_DND = "bypass_dnd"; protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override"; protected static final String KEY_IMPORTANCE = "importance"; protected static final String KEY_LIGHTS = "lights"; protected static final String KEY_VIBRATE = "vibrate"; protected static final String KEY_RINGTONE = "ringtone"; Loading @@ -63,9 +56,6 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { protected RestrictedSwitchPreference mLights; protected RestrictedSwitchPreference mVibrate; protected NotificationSoundPreference mRingtone; protected RestrictedDropDownPreference mImportance; protected RestrictedSwitchPreference mPriority; protected RestrictedDropDownPreference mVisibilityOverride; @Override public int getMetricsCategory() { Loading Loading @@ -224,7 +214,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { final int numImportances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1; List<String> summaries = new ArrayList<>(); List<String> values = new ArrayList<>(); ; for (int i = 0; i < numImportances; i++) { int importance = i + 1; summaries.add(getImportanceSummary(importance)); Loading Loading @@ -256,105 +246,6 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { } } protected void setupPriorityPref(boolean priority) { mPriority.setDisabledByAdmin(mSuspendedAppsAdmin); mPriority.setChecked(priority); mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean bypassZenMode = (Boolean) newValue; mChannel.setBypassDnd(bypassZenMode); mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } }); } protected void setupVisOverridePref(int sensitive) { ArrayList<CharSequence> entries = new ArrayList<>(); ArrayList<CharSequence> values = new ArrayList<>(); mVisibilityOverride.clearRestrictedItems(); if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) { final String summaryShowEntry = getString(R.string.lock_screen_notifications_summary_show); final String summaryShowEntryValue = Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE); entries.add(summaryShowEntry); values.add(summaryShowEntryValue); setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue, DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); } final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide); final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE); entries.add(summaryHideEntry); values.add(summaryHideEntryValue); setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue, DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); entries.add(getString(R.string.lock_screen_notifications_summary_disable)); values.add(Integer.toString(Notification.VISIBILITY_SECRET)); mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()])); mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()])); if (sensitive == Ranking.VISIBILITY_NO_OVERRIDE) { mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility())); } else { mVisibilityOverride.setValue(Integer.toString(sensitive)); } mVisibilityOverride.setSummary("%s"); mVisibilityOverride.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int sensitive = Integer.parseInt((String) newValue); if (sensitive == getGlobalVisibility()) { sensitive = Ranking.VISIBILITY_NO_OVERRIDE; } mChannel.setLockscreenVisibility(sensitive); mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } }); mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin); } private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) { RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( mContext, keyguardNotificationFeatures, mUserId); if (admin != null) { RestrictedDropDownPreference.RestrictedItem item = new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin); mVisibilityOverride.addRestrictedItem(item); } } private int getGlobalVisibility() { int globalVis = Ranking.VISIBILITY_NO_OVERRIDE; if (!getLockscreenNotificationsEnabled()) { globalVis = Notification.VISIBILITY_SECRET; } else if (!getLockscreenAllowPrivateNotifications()) { globalVis = Notification.VISIBILITY_PRIVATE; } return globalVis; } private boolean getLockscreenNotificationsEnabled() { return Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; } private boolean getLockscreenAllowPrivateNotifications() { return Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0; } private boolean isLockScreenSecure() { LockPatternUtils utils = new LockPatternUtils(getActivity()); boolean lockscreenSecure = utils.isSecure(UserHandle.myUserId()); Loading
src/com/android/settings/notification/NotificationSettingsBase.java +111 −2 Original line number Diff line number Diff line Loading @@ -18,15 +18,14 @@ package com.android.settings.notification; import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.Utils; import com.android.settings.applications.AppInfoBase; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedSwitchPreference; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; Loading @@ -39,6 +38,7 @@ import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.support.v7.preference.Preference; import android.text.TextUtils; import android.util.ArrayMap; Loading @@ -47,6 +47,7 @@ import android.widget.Toast; import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import java.util.ArrayList; import java.util.List; abstract public class NotificationSettingsBase extends SettingsPreferenceFragment { Loading @@ -59,6 +60,9 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen protected static final String KEY_BLOCK = "block"; protected static final String KEY_BADGE = "badge"; protected static final String KEY_BYPASS_DND = "bypass_dnd"; protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override"; protected static final String KEY_IMPORTANCE = "importance"; protected PackageManager mPm; protected UserManager mUm; Loading @@ -71,6 +75,10 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen protected PackageInfo mPkgInfo; protected RestrictedSwitchPreference mBlock; protected RestrictedSwitchPreference mBadge; protected RestrictedDropDownPreference mImportance; protected RestrictedSwitchPreference mPriority; protected RestrictedDropDownPreference mVisibilityOverride; protected EnforcedAdmin mSuspendedAppsAdmin; protected boolean mDndVisualEffectsSuppressed; Loading Loading @@ -249,4 +257,105 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen return getContext().getString(R.string.notification_importance_high); } } protected void setupPriorityPref(boolean priority) { mPriority.setDisabledByAdmin(mSuspendedAppsAdmin); mPriority.setChecked(priority); mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean bypassZenMode = (Boolean) newValue; mChannel.setBypassDnd(bypassZenMode); mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } }); } protected void setupVisOverridePref(int sensitive) { ArrayList<CharSequence> entries = new ArrayList<>(); ArrayList<CharSequence> values = new ArrayList<>(); mVisibilityOverride.clearRestrictedItems(); if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) { final String summaryShowEntry = getString(R.string.lock_screen_notifications_summary_show); final String summaryShowEntryValue = Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE); entries.add(summaryShowEntry); values.add(summaryShowEntryValue); setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue, DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); } final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide); final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE); entries.add(summaryHideEntry); values.add(summaryHideEntryValue); setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue, DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); entries.add(getString(R.string.lock_screen_notifications_summary_disable)); values.add(Integer.toString(Notification.VISIBILITY_SECRET)); mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()])); mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()])); if (sensitive == NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE) { mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility())); } else { mVisibilityOverride.setValue(Integer.toString(sensitive)); } mVisibilityOverride.setSummary("%s"); mVisibilityOverride.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int sensitive = Integer.parseInt((String) newValue); if (sensitive == getGlobalVisibility()) { sensitive = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE; } mChannel.setLockscreenVisibility(sensitive); mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY); mBackend.updateChannel(mPkg, mUid, mChannel); return true; } }); mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin); } private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) { RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( mContext, keyguardNotificationFeatures, mUserId); if (admin != null) { RestrictedDropDownPreference.RestrictedItem item = new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin); mVisibilityOverride.addRestrictedItem(item); } } private int getGlobalVisibility() { int globalVis = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE; if (!getLockscreenNotificationsEnabled()) { globalVis = Notification.VISIBILITY_SECRET; } else if (!getLockscreenAllowPrivateNotifications()) { globalVis = Notification.VISIBILITY_PRIVATE; } return globalVis; } private boolean getLockscreenNotificationsEnabled() { return Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; } private boolean getLockscreenAllowPrivateNotifications() { return Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0; } }