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:
@@ -6576,6 +6576,12 @@
|
|||||||
<!-- [CHAR LIMIT=100] Notification Importance: blocked importance level description -->
|
<!-- [CHAR LIMIT=100] Notification Importance: blocked importance level description -->
|
||||||
<string name="notification_importance_blocked">Never show notifications</string>
|
<string name="notification_importance_blocked">Never show notifications</string>
|
||||||
|
|
||||||
|
<!-- [CHAR LIMIT=100] Notification Importance template for the channel importance summary -->
|
||||||
|
<string name="notification_importance_divider" translatable="false"><xliff:g id="importance_title">%1$s</xliff:g>: <xliff:g id="importance_summary">%2$s</xliff:g></string>
|
||||||
|
|
||||||
|
<!-- Importance title strings for the Importance page. Also the second part of the importance
|
||||||
|
summary on the channel page-->
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=100] Notification Importance: min importance level description -->
|
<!-- [CHAR LIMIT=100] Notification Importance: min importance level description -->
|
||||||
<string name="notification_importance_min">No sound or visual interruption</string>
|
<string name="notification_importance_min">No sound or visual interruption</string>
|
||||||
|
|
||||||
@@ -6588,6 +6594,9 @@
|
|||||||
<!-- [CHAR LIMIT=100] Notification Importance: high importance level description -->
|
<!-- [CHAR LIMIT=100] Notification Importance: high importance level description -->
|
||||||
<string name="notification_importance_high">Make sound and pop on screen</string>
|
<string name="notification_importance_high">Make sound and pop on screen</string>
|
||||||
|
|
||||||
|
<!-- Importance title strings for the Importance page. Also the first part of the importance
|
||||||
|
summary on the channel page-->
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=100] Notification Importance title: min importance level title -->
|
<!-- [CHAR LIMIT=100] Notification Importance title: min importance level title -->
|
||||||
<string name="notification_importance_min_title">Low</string>
|
<string name="notification_importance_min_title">Low</string>
|
||||||
|
|
||||||
|
@@ -17,6 +17,12 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" >
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" >
|
||||||
|
|
||||||
|
<!-- Show badge -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="badge"
|
||||||
|
android:title="@string/notification_badge_title"
|
||||||
|
settings:useAdditionalSummary="true"
|
||||||
|
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
|
||||||
|
|
||||||
<!-- Importance toggle -->
|
<!-- Importance toggle -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
20
res/xml/notification_settings.xml
Normal file
20
res/xml/notification_settings.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2014 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">
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Copyright (C) 2014 The Android Open Source Project
|
<!-- Copyright (C) 2017 The Android Open Source Project
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -15,9 +15,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
||||||
android:title="@string/app_notifications_title"
|
|
||||||
android:key="app_notification_settings">
|
|
||||||
|
|
||||||
<!-- Show badge -->
|
<!-- Show badge -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
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_LOW;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
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 String TAG = "AppNotificationSettings";
|
||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
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<NotificationChannelGroup> mChannelGroupList;
|
||||||
private List<PreferenceCategory> mChannelGroups = new ArrayList();
|
private List<PreferenceCategory> mChannelGroups = new ArrayList();
|
||||||
private RestrictedSwitchPreference mImportanceToggle;
|
|
||||||
private LayoutPreference mBlockBar;
|
|
||||||
private FooterPreference mDeletedChannels;
|
private FooterPreference mDeletedChannels;
|
||||||
private SwitchBar mSwitchBar;
|
|
||||||
|
|
||||||
private boolean mShowLegacyChannelConfig = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
@@ -92,21 +87,25 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
if (getPreferenceScreen() != null) {
|
if (getPreferenceScreen() != null) {
|
||||||
getPreferenceScreen().removeAll();
|
getPreferenceScreen().removeAll();
|
||||||
mChannelGroups.clear();
|
mChannelGroups.clear();
|
||||||
|
mDeletedChannels = null;
|
||||||
mShowLegacyChannelConfig = false;
|
mShowLegacyChannelConfig = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.app_notification_settings);
|
addPreferencesFromResource(R.xml.notification_settings);
|
||||||
getPreferenceScreen().setOrderingAsAdded(true);
|
getPreferenceScreen().setOrderingAsAdded(true);
|
||||||
|
|
||||||
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
|
|
||||||
mBlockedDesc = (FooterPreference) getPreferenceScreen().findPreference(KEY_BLOCKED_DESC);
|
|
||||||
|
|
||||||
setupBlock();
|
setupBlock();
|
||||||
|
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();
|
setupBadge();
|
||||||
// load settings intent
|
// Load channel settings
|
||||||
ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
|
|
||||||
rows.put(mAppRow.pkg, mAppRow);
|
|
||||||
collectConfigActivities(rows);
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... unused) {
|
protected Void doInBackground(Void... unused) {
|
||||||
@@ -123,7 +122,15 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
populateChannelList();
|
populateChannelList();
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDependents(mAppRow.banned);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addHeaderPref() {
|
||||||
|
ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
|
||||||
|
rows.put(mAppRow.pkg, mAppRow);
|
||||||
|
collectConfigActivities(rows);
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
final Preference pref = FeatureFactory.getFactory(activity)
|
final Preference pref = FeatureFactory.getFactory(activity)
|
||||||
.getApplicationFeatureProvider(activity)
|
.getApplicationFeatureProvider(activity)
|
||||||
@@ -135,15 +142,15 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
|
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
|
||||||
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
|
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
|
||||||
.done(activity, getPrefContext());
|
.done(activity, getPrefContext());
|
||||||
|
pref.setKey(KEY_HEADER);
|
||||||
getPreferenceScreen().addPreference(pref);
|
getPreferenceScreen().addPreference(pref);
|
||||||
|
|
||||||
updateDependents(mAppRow.banned);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateChannelList() {
|
private void populateChannelList() {
|
||||||
if (mChannelGroupList.isEmpty()) {
|
if (mChannelGroupList.isEmpty()) {
|
||||||
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
||||||
groupCategory.setTitle(R.string.notification_channels);
|
groupCategory.setTitle(R.string.notification_channels);
|
||||||
|
groupCategory.setKey(KEY_GENERAL_CATEGORY);
|
||||||
getPreferenceScreen().addPreference(groupCategory);
|
getPreferenceScreen().addPreference(groupCategory);
|
||||||
mChannelGroups.add(groupCategory);
|
mChannelGroups.add(groupCategory);
|
||||||
|
|
||||||
@@ -151,15 +158,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
empty.setTitle(R.string.no_channels);
|
empty.setTitle(R.string.no_channels);
|
||||||
empty.setEnabled(false);
|
empty.setEnabled(false);
|
||||||
groupCategory.addPreference(empty);
|
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 {
|
} else {
|
||||||
for (NotificationChannelGroup group : mChannelGroupList) {
|
for (NotificationChannelGroup group : mChannelGroupList) {
|
||||||
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
||||||
@@ -167,10 +165,11 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
groupCategory.setTitle(mChannelGroupList.size() > 1
|
groupCategory.setTitle(mChannelGroupList.size() > 1
|
||||||
? R.string.notification_channels_other
|
? R.string.notification_channels_other
|
||||||
: R.string.notification_channels);
|
: R.string.notification_channels);
|
||||||
|
groupCategory.setKey(KEY_GENERAL_CATEGORY);
|
||||||
} else {
|
} else {
|
||||||
groupCategory.setTitle(group.getName());
|
groupCategory.setTitle(group.getName());
|
||||||
}
|
|
||||||
groupCategory.setKey(group.getId());
|
groupCategory.setKey(group.getId());
|
||||||
|
}
|
||||||
groupCategory.setOrderingAsAdded(true);
|
groupCategory.setOrderingAsAdded(true);
|
||||||
getPreferenceScreen().addPreference(groupCategory);
|
getPreferenceScreen().addPreference(groupCategory);
|
||||||
mChannelGroups.add(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);
|
int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
|
||||||
if (deletedChannelCount > 0) {
|
if (deletedChannelCount > 0) {
|
||||||
mDeletedChannels = new FooterPreference(getPrefContext());
|
mDeletedChannels = new FooterPreference(getPrefContext());
|
||||||
@@ -198,9 +190,12 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
mDeletedChannels.setTitle(getResources().getQuantityString(
|
mDeletedChannels.setTitle(getResources().getQuantityString(
|
||||||
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
|
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
|
||||||
mDeletedChannels.setEnabled(false);
|
mDeletedChannels.setEnabled(false);
|
||||||
|
mDeletedChannels.setKey(KEY_DELETED);
|
||||||
|
mDeletedChannels.setOrder(ORDER_LAST);
|
||||||
getPreferenceScreen().addPreference(mDeletedChannels);
|
getPreferenceScreen().addPreference(mDeletedChannels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDependents(mAppRow.banned);
|
updateDependents(mAppRow.banned);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +207,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
channelPref.setKey(channel.getId());
|
channelPref.setKey(channel.getId());
|
||||||
channelPref.setTitle(channel.getName());
|
channelPref.setTitle(channel.getName());
|
||||||
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
|
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
|
||||||
channelPref.setSummary(getImportanceSummary(channel.getImportance()));
|
channelPref.setSummary(getImportanceSummary(channel));
|
||||||
Bundle channelArgs = new Bundle();
|
Bundle channelArgs = new Bundle();
|
||||||
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
||||||
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
||||||
@@ -234,7 +229,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
channel.setImportance(importance);
|
channel.setImportance(importance);
|
||||||
channel.lockFields(
|
channel.lockFields(
|
||||||
NotificationChannel.USER_LOCKED_IMPORTANCE);
|
NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||||
channelPref.setSummary(getImportanceSummary(channel.getImportance()));
|
channelPref.setSummary(getImportanceSummary(channel));
|
||||||
mBackend.updateChannel(mPkg, mUid, channel);
|
mBackend.updateChannel(mPkg, mUid, channel);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -243,36 +238,25 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
groupCategory.addPreference(channelPref);
|
groupCategory.addPreference(channelPref);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateDefaultChannelPrefs() {
|
void setupBadge() {
|
||||||
addPreferencesFromResource(R.xml.legacy_channel_notification_settings);
|
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
|
||||||
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
mVisibilityOverride =
|
if (mChannel == null) {
|
||||||
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
|
mBadge.setChecked(mAppRow.showBadge);
|
||||||
mImportanceToggle = (RestrictedSwitchPreference) findPreference(KEY_IMPORTANCE);
|
} else {
|
||||||
|
mBadge.setChecked(mChannel.canShowBadge());
|
||||||
if (mPkgInfo != null && mChannel != null) {
|
|
||||||
setupPriorityPref(mChannel.canBypassDnd());
|
|
||||||
setupVisOverridePref(mChannel.getLockscreenVisibility());
|
|
||||||
setupImportanceToggle();
|
|
||||||
}
|
}
|
||||||
mSwitchBar.setChecked(!mAppRow.banned
|
mBadge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
&& 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() {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final int importance =
|
final boolean value = (Boolean) newValue;
|
||||||
((Boolean) newValue ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_LOW);
|
if (mChannel == null) {
|
||||||
mChannel.setImportance(importance);
|
mBackend.setShowBadge(mPkg, mUid, value);
|
||||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
} else {
|
||||||
|
mChannel.setShowBadge(value);
|
||||||
|
mChannel.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
|
||||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -296,12 +280,13 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||||
}
|
}
|
||||||
mBackend.setNotificationsEnabledForPackage(mPkgInfo.packageName, mUid, isChecked);
|
mBackend.setNotificationsEnabledForPackage(mPkgInfo.packageName, mUid, isChecked);
|
||||||
|
mAppRow.banned = true;
|
||||||
updateDependents(!isChecked);
|
updateDependents(!isChecked);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
|
mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
|
||||||
mBlockBar.setOrder(-500);
|
mBlockBar.setOrder(ORDER_FIRST);
|
||||||
mBlockBar.setKey(KEY_BLOCK);
|
mBlockBar.setKey(KEY_BLOCK);
|
||||||
getPreferenceScreen().addPreference(mBlockBar);
|
getPreferenceScreen().addPreference(mBlockBar);
|
||||||
|
|
||||||
@@ -312,20 +297,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
setupBlockDesc(R.string.app_notifications_off_desc);
|
setupBlockDesc(R.string.app_notifications_off_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupBadge() {
|
protected void updateDependents(boolean banned) {
|
||||||
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) {
|
|
||||||
for (PreferenceCategory category : mChannelGroups) {
|
for (PreferenceCategory category : mChannelGroups) {
|
||||||
setVisible(category, !banned);
|
setVisible(category, !banned);
|
||||||
}
|
}
|
||||||
@@ -336,17 +308,42 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
setVisible(mBadge, !banned);
|
setVisible(mBadge, !banned);
|
||||||
if (mShowLegacyChannelConfig) {
|
if (mShowLegacyChannelConfig) {
|
||||||
setVisible(mImportanceToggle, !banned);
|
setVisible(mImportanceToggle, !banned);
|
||||||
setVisible(mPriority, !banned);
|
setVisible(mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
|
||||||
setVisible(mVisibilityOverride, !banned);
|
|| (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
|
||||||
|
&& mDndVisualEffectsSuppressed));
|
||||||
|
setVisible(mVisibilityOverride, !banned &&
|
||||||
|
checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure());
|
||||||
|
}
|
||||||
|
if (mAppLink != null) {
|
||||||
|
setVisible(mAppLink, !banned);
|
||||||
}
|
}
|
||||||
if (mAppRow.systemApp && !mAppRow.banned) {
|
if (mAppRow.systemApp && !mAppRow.banned) {
|
||||||
setVisible(mBlockBar, false);
|
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 =
|
private Comparator<NotificationChannel> mChannelComparator =
|
||||||
new Comparator<NotificationChannel>() {
|
new Comparator<NotificationChannel>() {
|
||||||
private final Collator sCollator = Collator.getInstance();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(NotificationChannel left, NotificationChannel right) {
|
public int compare(NotificationChannel left, NotificationChannel right) {
|
||||||
@@ -359,7 +356,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
|
|
||||||
private Comparator<NotificationChannelGroup> mChannelGroupComparator =
|
private Comparator<NotificationChannelGroup> mChannelGroupComparator =
|
||||||
new Comparator<NotificationChannelGroup>() {
|
new Comparator<NotificationChannelGroup>() {
|
||||||
private final Collator sCollator = Collator.getInstance();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(NotificationChannelGroup left, NotificationChannelGroup right) {
|
public int compare(NotificationChannelGroup left, NotificationChannelGroup right) {
|
||||||
|
@@ -66,6 +66,12 @@ public class ChannelImportanceSettings extends NotificationSettingsBase
|
|||||||
createPreferenceHierarchy();
|
createPreferenceHierarchy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void setupBadge() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void updateDependents(boolean banned) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification;
|
|||||||
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||||
|
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
@@ -53,16 +54,16 @@ import com.android.settingslib.RestrictedSwitchPreference;
|
|||||||
public class ChannelNotificationSettings extends NotificationSettingsBase {
|
public class ChannelNotificationSettings extends NotificationSettingsBase {
|
||||||
private static final String TAG = "ChannelSettings";
|
private static final String TAG = "ChannelSettings";
|
||||||
|
|
||||||
protected static final String KEY_LIGHTS = "lights";
|
private static final String KEY_LIGHTS = "lights";
|
||||||
protected static final String KEY_VIBRATE = "vibrate";
|
private static final String KEY_VIBRATE = "vibrate";
|
||||||
protected static final String KEY_RINGTONE = "ringtone";
|
private static final String KEY_RINGTONE = "ringtone";
|
||||||
|
private static final String KEY_IMPORTANCE = "importance";
|
||||||
|
|
||||||
protected Preference mImportance;
|
private Preference mImportance;
|
||||||
protected RestrictedSwitchPreference mLights;
|
private RestrictedSwitchPreference mLights;
|
||||||
protected RestrictedSwitchPreference mVibrate;
|
private RestrictedSwitchPreference mVibrate;
|
||||||
protected NotificationSoundPreference mRingtone;
|
private NotificationSoundPreference mRingtone;
|
||||||
|
private FooterPreference mFooter;
|
||||||
protected LayoutPreference mBlockBar;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
@@ -81,34 +82,37 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
if (getPreferenceScreen() != null) {
|
if (getPreferenceScreen() != null) {
|
||||||
getPreferenceScreen().removeAll();
|
getPreferenceScreen().removeAll();
|
||||||
}
|
}
|
||||||
addPreferencesFromResource(R.xml.channel_notification_settings);
|
addPreferencesFromResource(R.xml.notification_settings);
|
||||||
|
setupBlock();
|
||||||
|
addHeaderPref();
|
||||||
|
addAppLinkPref();
|
||||||
|
addFooterPref();
|
||||||
|
|
||||||
// load settings intent
|
if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
|
||||||
ArrayMap<String, NotificationBackend.AppRow> rows = new ArrayMap<String, NotificationBackend.AppRow>();
|
populateDefaultChannelPrefs();
|
||||||
rows.put(mAppRow.pkg, mAppRow);
|
mShowLegacyChannelConfig = true;
|
||||||
collectConfigActivities(rows);
|
} else {
|
||||||
|
populateUpgradedChannelPrefs();
|
||||||
mBlockedDesc = (FooterPreference) getPreferenceScreen().findPreference(KEY_BLOCKED_DESC);
|
}
|
||||||
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
|
|
||||||
mImportance = findPreference(KEY_IMPORTANCE);
|
|
||||||
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
|
||||||
mVisibilityOverride =
|
|
||||||
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
|
|
||||||
mLights = (RestrictedSwitchPreference) findPreference(KEY_LIGHTS);
|
|
||||||
mVibrate = (RestrictedSwitchPreference) findPreference(KEY_VIBRATE);
|
|
||||||
mRingtone = (NotificationSoundPreference) findPreference(KEY_RINGTONE);
|
|
||||||
|
|
||||||
|
updateDependents(mChannel.getImportance() == IMPORTANCE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateUpgradedChannelPrefs() {
|
||||||
|
addPreferencesFromResource(R.xml.upgraded_channel_notification_settings);
|
||||||
|
setupBadge();
|
||||||
setupPriorityPref(mChannel.canBypassDnd());
|
setupPriorityPref(mChannel.canBypassDnd());
|
||||||
setupVisOverridePref(mChannel.getLockscreenVisibility());
|
setupVisOverridePref(mChannel.getLockscreenVisibility());
|
||||||
setupLights();
|
setupLights();
|
||||||
setupVibrate();
|
setupVibrate();
|
||||||
setupRingtone();
|
setupRingtone();
|
||||||
setupBadge();
|
|
||||||
setupBlock();
|
|
||||||
setupImportance();
|
setupImportance();
|
||||||
updateDependents();
|
}
|
||||||
|
|
||||||
|
private void addHeaderPref() {
|
||||||
|
ArrayMap<String, NotificationBackend.AppRow> rows = new ArrayMap<String, NotificationBackend.AppRow>();
|
||||||
|
rows.put(mAppRow.pkg, mAppRow);
|
||||||
|
collectConfigActivities(rows);
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
final Preference pref = FeatureFactory.getFactory(activity)
|
final Preference pref = FeatureFactory.getFactory(activity)
|
||||||
.getApplicationFeatureProvider(activity)
|
.getApplicationFeatureProvider(activity)
|
||||||
@@ -122,25 +126,38 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
|
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
|
||||||
.done(activity, getPrefContext());
|
.done(activity, getPrefContext());
|
||||||
getPreferenceScreen().addPreference(pref);
|
getPreferenceScreen().addPreference(pref);
|
||||||
|
|
||||||
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 addFooterPref() {
|
||||||
if (!TextUtils.isEmpty(mChannel.getDescription())) {
|
if (!TextUtils.isEmpty(mChannel.getDescription())) {
|
||||||
FooterPreference descPref = new FooterPreference(getPrefContext());
|
FooterPreference descPref = new FooterPreference(getPrefContext());
|
||||||
|
descPref.setOrder(ORDER_LAST);
|
||||||
descPref.setSelectable(false);
|
descPref.setSelectable(false);
|
||||||
descPref.setSummary(mChannel.getDescription());
|
descPref.setTitle(mChannel.getDescription());
|
||||||
descPref.setEnabled(false);
|
|
||||||
getPreferenceScreen().addPreference(descPref);
|
getPreferenceScreen().addPreference(descPref);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupBadge() {
|
||||||
|
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
|
||||||
|
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
|
mBadge.setEnabled(mAppRow.showBadge);
|
||||||
|
mBadge.setChecked(mChannel.canShowBadge());
|
||||||
|
|
||||||
|
mBadge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
final boolean value = (Boolean) newValue;
|
||||||
|
mChannel.setShowBadge(value);
|
||||||
|
mChannel.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
|
||||||
|
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLights() {
|
private void setupLights() {
|
||||||
|
mLights = (RestrictedSwitchPreference) findPreference(KEY_LIGHTS);
|
||||||
mLights.setDisabledByAdmin(mSuspendedAppsAdmin);
|
mLights.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
mLights.setChecked(mChannel.shouldShowLights());
|
mLights.setChecked(mChannel.shouldShowLights());
|
||||||
mLights.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
mLights.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@@ -156,6 +173,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupVibrate() {
|
private void setupVibrate() {
|
||||||
|
mVibrate = (RestrictedSwitchPreference) findPreference(KEY_VIBRATE);
|
||||||
mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin);
|
mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
mVibrate.setChecked(mChannel.shouldVibrate());
|
mVibrate.setChecked(mChannel.shouldVibrate());
|
||||||
mVibrate.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
mVibrate.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@@ -171,6 +189,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupRingtone() {
|
private void setupRingtone() {
|
||||||
|
mRingtone = (NotificationSoundPreference) findPreference(KEY_RINGTONE);
|
||||||
mRingtone.setRingtone(mChannel.getSound());
|
mRingtone.setRingtone(mChannel.getSound());
|
||||||
mRingtone.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
mRingtone.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -183,27 +202,33 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupBlock() {
|
private void setupBlock() {
|
||||||
View switchBarContainer = LayoutInflater.from(
|
View switchBarContainer = LayoutInflater.from(
|
||||||
getPrefContext()).inflate(R.layout.styled_switch_bar, null);
|
getPrefContext()).inflate(R.layout.styled_switch_bar, null);
|
||||||
SwitchBar switchBar = switchBarContainer.findViewById(R.id.switch_bar);
|
mSwitchBar = switchBarContainer.findViewById(R.id.switch_bar);
|
||||||
switchBar.show();
|
mSwitchBar.show();
|
||||||
switchBar.setDisabledByAdmin(mSuspendedAppsAdmin);
|
mSwitchBar.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
switchBar.setChecked(mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
mSwitchBar.setChecked(mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
||||||
switchBar.addOnSwitchChangeListener(new SwitchBar.OnSwitchChangeListener() {
|
mSwitchBar.addOnSwitchChangeListener(new SwitchBar.OnSwitchChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
int importance = isChecked ? IMPORTANCE_LOW : IMPORTANCE_NONE;
|
int importance = 0;
|
||||||
|
if (mShowLegacyChannelConfig) {
|
||||||
|
importance = isChecked ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_NONE;
|
||||||
|
mImportanceToggle.setChecked(importance == IMPORTANCE_UNSPECIFIED);
|
||||||
|
} else {
|
||||||
|
importance = isChecked ? IMPORTANCE_LOW : IMPORTANCE_NONE;
|
||||||
mImportance.setSummary(getImportanceSummary(importance));
|
mImportance.setSummary(getImportanceSummary(importance));
|
||||||
|
}
|
||||||
mChannel.setImportance(importance);
|
mChannel.setImportance(importance);
|
||||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||||
updateDependents();
|
updateDependents(mChannel.getImportance() == IMPORTANCE_NONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
|
mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
|
||||||
mBlockBar.setOrder(-500);
|
mBlockBar.setOrder(ORDER_FIRST);
|
||||||
mBlockBar.setKey(KEY_BLOCK);
|
mBlockBar.setKey(KEY_BLOCK);
|
||||||
getPreferenceScreen().addPreference(mBlockBar);
|
getPreferenceScreen().addPreference(mBlockBar);
|
||||||
|
|
||||||
@@ -214,23 +239,8 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
setupBlockDesc(R.string.channel_notifications_off_desc);
|
setupBlockDesc(R.string.channel_notifications_off_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupBadge() {
|
private void setupImportance() {
|
||||||
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
|
mImportance = findPreference(KEY_IMPORTANCE);
|
||||||
mBadge.setEnabled(mAppRow.showBadge);
|
|
||||||
mBadge.setChecked(mChannel.canShowBadge());
|
|
||||||
mBadge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
final boolean value = (Boolean) newValue;
|
|
||||||
mChannel.setShowBadge(value);
|
|
||||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
|
|
||||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setupImportance() {
|
|
||||||
Bundle channelArgs = new Bundle();
|
Bundle channelArgs = new Bundle();
|
||||||
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
||||||
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
||||||
@@ -245,23 +255,43 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
mImportance.setSummary(getImportanceSummary(mChannel.getImportance()));
|
mImportance.setSummary(getImportanceSummary(mChannel.getImportance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLockScreenSecure() {
|
private String getImportanceSummary(int importance) {
|
||||||
LockPatternUtils utils = new LockPatternUtils(getActivity());
|
String title;
|
||||||
boolean lockscreenSecure = utils.isSecure(UserHandle.myUserId());
|
String summary = null;
|
||||||
UserInfo parentUser = mUm.getProfileParent(UserHandle.myUserId());
|
switch (importance) {
|
||||||
if (parentUser != null){
|
case IMPORTANCE_UNSPECIFIED:
|
||||||
lockscreenSecure |= utils.isSecure(parentUser.id);
|
title = getContext().getString(R.string.notification_importance_unspecified);
|
||||||
|
break;
|
||||||
|
case NotificationManager.IMPORTANCE_MIN:
|
||||||
|
title = getContext().getString(R.string.notification_importance_min_title);
|
||||||
|
summary = getContext().getString(R.string.notification_importance_min);
|
||||||
|
break;
|
||||||
|
case NotificationManager.IMPORTANCE_LOW:
|
||||||
|
title = getContext().getString(R.string.notification_importance_low_title);
|
||||||
|
summary = getContext().getString(R.string.notification_importance_low);
|
||||||
|
break;
|
||||||
|
case NotificationManager.IMPORTANCE_DEFAULT:
|
||||||
|
title = getContext().getString(R.string.notification_importance_default_title);
|
||||||
|
if (hasValidSound()) {
|
||||||
|
summary = getContext().getString(R.string.notification_importance_default);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NotificationManager.IMPORTANCE_HIGH:
|
||||||
|
case NotificationManager.IMPORTANCE_MAX:
|
||||||
|
title = getContext().getString(R.string.notification_importance_high_title);
|
||||||
|
if (hasValidSound()) {
|
||||||
|
summary = getContext().getString(R.string.notification_importance_high);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return lockscreenSecure;
|
if (summary != null) {
|
||||||
|
return getContext().getString(R.string.notification_importance_divider, title, summary);
|
||||||
|
} else {
|
||||||
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean checkCanBeVisible(int minImportanceVisible) {
|
|
||||||
int importance = mChannel.getImportance();
|
|
||||||
if (importance == NotificationManager.IMPORTANCE_UNSPECIFIED) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return importance >= minImportanceVisible;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -279,9 +309,10 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
if (mRingtone != null) {
|
if (mRingtone != null) {
|
||||||
mRingtone.onActivityResult(requestCode, resultCode, data);
|
mRingtone.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
mImportance.setSummary(getImportanceSummary(mChannel.getImportance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canPulseLight() {
|
boolean canPulseLight() {
|
||||||
if (!getResources()
|
if (!getResources()
|
||||||
.getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
|
.getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -290,18 +321,32 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1;
|
Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDependents() {
|
boolean hasValidSound() {
|
||||||
setVisible(mBlockedDesc, mChannel.getImportance() == IMPORTANCE_NONE);
|
return mChannel.getSound() != null && !Uri.EMPTY.equals(mChannel.getSound());
|
||||||
setVisible(mBadge, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
|
}
|
||||||
|
|
||||||
|
void updateDependents(boolean banned) {
|
||||||
|
if (mShowLegacyChannelConfig) {
|
||||||
|
setVisible(mImportanceToggle, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
|
||||||
|
} else {
|
||||||
setVisible(mImportance, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
|
setVisible(mImportance, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
|
||||||
setVisible(mLights, checkCanBeVisible(
|
setVisible(mLights, checkCanBeVisible(
|
||||||
NotificationManager.IMPORTANCE_LOW) && canPulseLight());
|
NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight());
|
||||||
setVisible(mVibrate, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
|
setVisible(mVibrate, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
|
||||||
setVisible(mRingtone, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
|
setVisible(mRingtone, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
|
||||||
|
}
|
||||||
|
setVisible(mBadge, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
|
||||||
setVisible(mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
|
setVisible(mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
|
||||||
|| (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
|
|| (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
|
||||||
&& mDndVisualEffectsSuppressed));
|
&& mDndVisualEffectsSuppressed));
|
||||||
setVisible(mVisibilityOverride, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN)
|
setVisible(mVisibilityOverride, checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
|
||||||
&& isLockScreenSecure());
|
&& isLockScreenSecure());
|
||||||
|
setVisible(mBlockedDesc, mChannel.getImportance() == IMPORTANCE_NONE);
|
||||||
|
if (mAppLink != null) {
|
||||||
|
setVisible(mAppLink, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
|
||||||
|
}
|
||||||
|
if (mFooter !=null) {
|
||||||
|
setVisible(mFooter, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -148,6 +148,15 @@ public class NotificationBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean onlyHasDefaultChannel(String pkg, int uid) {
|
||||||
|
try {
|
||||||
|
return sINM.onlyHasDefaultChannel(pkg, uid);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, "Error calling NoMan", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class Row {
|
static class Row {
|
||||||
public String section;
|
public String section;
|
||||||
}
|
}
|
||||||
|
@@ -16,10 +16,18 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
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;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.applications.AppInfoBase;
|
import com.android.settings.applications.AppInfoBase;
|
||||||
|
import com.android.settings.applications.LayoutPreference;
|
||||||
import com.android.settings.widget.FooterPreference;
|
import com.android.settings.widget.FooterPreference;
|
||||||
|
import com.android.settings.widget.SwitchBar;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
@@ -35,6 +43,7 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
@@ -60,16 +69,23 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
= new Intent(Intent.ACTION_MAIN)
|
= new Intent(Intent.ACTION_MAIN)
|
||||||
.addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);
|
.addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);
|
||||||
|
|
||||||
|
protected static final int ORDER_FIRST = -500;
|
||||||
|
protected static final int ORDER_LAST = 1000;
|
||||||
|
|
||||||
|
protected static final String KEY_APP_LINK = "app_link";
|
||||||
|
protected static final String KEY_HEADER = "header";
|
||||||
protected static final String KEY_BLOCK = "block";
|
protected static final String KEY_BLOCK = "block";
|
||||||
protected static final String KEY_BADGE = "badge";
|
protected static final String KEY_BADGE = "badge";
|
||||||
protected static final String KEY_BYPASS_DND = "bypass_dnd";
|
protected static final String KEY_BYPASS_DND = "bypass_dnd";
|
||||||
protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
|
protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
|
||||||
protected static final String KEY_IMPORTANCE = "importance";
|
|
||||||
protected static final String KEY_BLOCKED_DESC = "block_desc";
|
protected static final String KEY_BLOCKED_DESC = "block_desc";
|
||||||
|
protected static final String KEY_ALLOW_SOUND = "allow_sound";
|
||||||
|
|
||||||
protected PackageManager mPm;
|
protected PackageManager mPm;
|
||||||
protected UserManager mUm;
|
protected UserManager mUm;
|
||||||
protected final NotificationBackend mBackend = new NotificationBackend();
|
protected NotificationBackend mBackend = new NotificationBackend();
|
||||||
|
protected LockPatternUtils mLockPatternUtils;
|
||||||
|
protected NotificationManager mNm;
|
||||||
protected Context mContext;
|
protected Context mContext;
|
||||||
protected boolean mCreated;
|
protected boolean mCreated;
|
||||||
protected int mUid;
|
protected int mUid;
|
||||||
@@ -79,13 +95,18 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
protected RestrictedSwitchPreference mBadge;
|
protected RestrictedSwitchPreference mBadge;
|
||||||
protected RestrictedSwitchPreference mPriority;
|
protected RestrictedSwitchPreference mPriority;
|
||||||
protected RestrictedDropDownPreference mVisibilityOverride;
|
protected RestrictedDropDownPreference mVisibilityOverride;
|
||||||
|
protected RestrictedSwitchPreference mImportanceToggle;
|
||||||
|
protected LayoutPreference mBlockBar;
|
||||||
|
protected SwitchBar mSwitchBar;
|
||||||
protected FooterPreference mBlockedDesc;
|
protected FooterPreference mBlockedDesc;
|
||||||
|
protected Preference mAppLink;
|
||||||
|
|
||||||
protected EnforcedAdmin mSuspendedAppsAdmin;
|
protected EnforcedAdmin mSuspendedAppsAdmin;
|
||||||
protected boolean mDndVisualEffectsSuppressed;
|
protected boolean mDndVisualEffectsSuppressed;
|
||||||
|
|
||||||
protected NotificationChannel mChannel;
|
protected NotificationChannel mChannel;
|
||||||
protected NotificationBackend.AppRow mAppRow;
|
protected NotificationBackend.AppRow mAppRow;
|
||||||
|
protected boolean mShowLegacyChannelConfig = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
@@ -113,6 +134,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
|
|
||||||
mPm = getPackageManager();
|
mPm = getPackageManager();
|
||||||
mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||||
|
mNm = NotificationManager.from(mContext);
|
||||||
|
|
||||||
mPkg = args != null && args.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
|
mPkg = args != null && args.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
|
||||||
? args.getString(AppInfoBase.ARG_PACKAGE_NAME)
|
? args.getString(AppInfoBase.ARG_PACKAGE_NAME)
|
||||||
@@ -154,8 +176,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
|
|
||||||
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
|
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
|
||||||
mContext, mPkg, mUserId);
|
mContext, mPkg, mUserId);
|
||||||
NotificationManager.Policy policy =
|
NotificationManager.Policy policy = mNm.getNotificationPolicy();
|
||||||
NotificationManager.from(mContext).getNotificationPolicy();
|
|
||||||
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
|
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
|
||||||
|
|
||||||
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
|
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
|
||||||
@@ -241,26 +262,56 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getImportanceSummary(int importance) {
|
protected void addAppLinkPref() {
|
||||||
switch (importance) {
|
if (mAppRow.settingsIntent != null) {
|
||||||
case NotificationManager.IMPORTANCE_UNSPECIFIED:
|
mAppLink = new Preference(getPrefContext());
|
||||||
return getContext().getString(R.string.notification_importance_unspecified);
|
mAppLink.setKey(KEY_APP_LINK);
|
||||||
case NotificationManager.IMPORTANCE_NONE:
|
mAppLink.setOrder(500);
|
||||||
return getContext().getString(R.string.notification_importance_blocked);
|
mAppLink.setIntent(mAppRow.settingsIntent);
|
||||||
case NotificationManager.IMPORTANCE_MIN:
|
mAppLink.setTitle(mContext.getString(R.string.app_settings_link));
|
||||||
return getContext().getString(R.string.notification_importance_min);
|
getPreferenceScreen().addPreference(mAppLink);
|
||||||
case NotificationManager.IMPORTANCE_LOW:
|
|
||||||
return getContext().getString(R.string.notification_importance_low);
|
|
||||||
case NotificationManager.IMPORTANCE_DEFAULT:
|
|
||||||
return getContext().getString(R.string.notification_importance_default);
|
|
||||||
case NotificationManager.IMPORTANCE_HIGH:
|
|
||||||
case NotificationManager.IMPORTANCE_MAX:
|
|
||||||
default:
|
|
||||||
return getContext().getString(R.string.notification_importance_high);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void populateDefaultChannelPrefs() {
|
||||||
|
if (mPkgInfo != null && mChannel != null) {
|
||||||
|
addPreferencesFromResource(R.xml.legacy_channel_notification_settings);
|
||||||
|
setupPriorityPref(mChannel.canBypassDnd());
|
||||||
|
setupVisOverridePref(mChannel.getLockscreenVisibility());
|
||||||
|
setupImportanceToggle();
|
||||||
|
setupBadge();
|
||||||
|
}
|
||||||
|
mSwitchBar.setChecked(!mAppRow.banned
|
||||||
|
&& mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract void setupBadge();
|
||||||
|
|
||||||
|
abstract void updateDependents(boolean banned);
|
||||||
|
|
||||||
|
// 'allow sound'
|
||||||
|
private void setupImportanceToggle() {
|
||||||
|
mImportanceToggle = (RestrictedSwitchPreference) findPreference(KEY_ALLOW_SOUND);
|
||||||
|
mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
|
mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
|
||||||
|
|| mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
|
||||||
|
mImportanceToggle.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);
|
||||||
|
updateDependents(mChannel.getImportance() == IMPORTANCE_NONE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected void setupPriorityPref(boolean priority) {
|
protected void setupPriorityPref(boolean priority) {
|
||||||
|
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||||
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
|
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
mPriority.setChecked(priority);
|
mPriority.setChecked(priority);
|
||||||
mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@@ -276,6 +327,8 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setupVisOverridePref(int sensitive) {
|
protected void setupVisOverridePref(int sensitive) {
|
||||||
|
mVisibilityOverride =
|
||||||
|
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
|
||||||
ArrayList<CharSequence> entries = new ArrayList<>();
|
ArrayList<CharSequence> entries = new ArrayList<>();
|
||||||
ArrayList<CharSequence> values = new ArrayList<>();
|
ArrayList<CharSequence> values = new ArrayList<>();
|
||||||
|
|
||||||
@@ -328,6 +381,8 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setupBlockDesc(int summaryResId) {
|
protected void setupBlockDesc(int summaryResId) {
|
||||||
|
mBlockedDesc = (FooterPreference) getPreferenceScreen().findPreference(
|
||||||
|
KEY_BLOCKED_DESC);
|
||||||
mBlockedDesc = new FooterPreference(getPrefContext());
|
mBlockedDesc = new FooterPreference(getPrefContext());
|
||||||
mBlockedDesc.setSelectable(false);
|
mBlockedDesc.setSelectable(false);
|
||||||
mBlockedDesc.setTitle(summaryResId);
|
mBlockedDesc.setTitle(summaryResId);
|
||||||
@@ -336,6 +391,13 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
getPreferenceScreen().addPreference(mBlockedDesc);
|
getPreferenceScreen().addPreference(mBlockedDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean checkCanBeVisible(int minImportanceVisible) {
|
||||||
|
int importance = mChannel.getImportance();
|
||||||
|
if (importance == NotificationManager.IMPORTANCE_UNSPECIFIED) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return importance >= minImportanceVisible;
|
||||||
|
}
|
||||||
|
|
||||||
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
|
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
|
||||||
CharSequence entryValue, int keyguardNotificationFeatures) {
|
CharSequence entryValue, int keyguardNotificationFeatures) {
|
||||||
@@ -359,7 +421,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
return globalVis;
|
return globalVis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean getLockscreenNotificationsEnabled() {
|
private boolean getLockscreenNotificationsEnabled() {
|
||||||
return Settings.Secure.getInt(getContentResolver(),
|
return Settings.Secure.getInt(getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
||||||
@@ -369,4 +430,17 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
return Settings.Secure.getInt(getContentResolver(),
|
return Settings.Secure.getInt(getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
|
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isLockScreenSecure() {
|
||||||
|
if (mLockPatternUtils == null) {
|
||||||
|
mLockPatternUtils = new LockPatternUtils(getActivity());
|
||||||
|
}
|
||||||
|
boolean lockscreenSecure = mLockPatternUtils.isSecure(UserHandle.myUserId());
|
||||||
|
UserInfo parentUser = mUm.getProfileParent(UserHandle.myUserId());
|
||||||
|
if (parentUser != null){
|
||||||
|
lockscreenSecure |= mLockPatternUtils.isSecure(parentUser.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lockscreenSecure;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user