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:
Julia Reynolds
2017-05-09 10:15:51 -04:00
parent f1730bee90
commit 2f0547c783
10 changed files with 373 additions and 210 deletions

View File

@@ -16,10 +16,18 @@
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.SettingsPreferenceFragment;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.widget.FooterPreference;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -35,6 +43,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
@@ -60,16 +69,23 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
= new Intent(Intent.ACTION_MAIN)
.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_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 static final String KEY_BLOCKED_DESC = "block_desc";
protected static final String KEY_ALLOW_SOUND = "allow_sound";
protected PackageManager mPm;
protected UserManager mUm;
protected final NotificationBackend mBackend = new NotificationBackend();
protected NotificationBackend mBackend = new NotificationBackend();
protected LockPatternUtils mLockPatternUtils;
protected NotificationManager mNm;
protected Context mContext;
protected boolean mCreated;
protected int mUid;
@@ -79,13 +95,18 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
protected RestrictedSwitchPreference mBadge;
protected RestrictedSwitchPreference mPriority;
protected RestrictedDropDownPreference mVisibilityOverride;
protected RestrictedSwitchPreference mImportanceToggle;
protected LayoutPreference mBlockBar;
protected SwitchBar mSwitchBar;
protected FooterPreference mBlockedDesc;
protected Preference mAppLink;
protected EnforcedAdmin mSuspendedAppsAdmin;
protected boolean mDndVisualEffectsSuppressed;
protected NotificationChannel mChannel;
protected NotificationBackend.AppRow mAppRow;
protected boolean mShowLegacyChannelConfig = false;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
@@ -113,6 +134,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
mPm = getPackageManager();
mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
mNm = NotificationManager.from(mContext);
mPkg = args != null && args.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
? args.getString(AppInfoBase.ARG_PACKAGE_NAME)
@@ -154,8 +176,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
mContext, mPkg, mUserId);
NotificationManager.Policy policy =
NotificationManager.from(mContext).getNotificationPolicy();
NotificationManager.Policy policy = mNm.getNotificationPolicy();
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
@@ -241,26 +262,56 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
return null;
}
protected String getImportanceSummary(int importance) {
switch (importance) {
case NotificationManager.IMPORTANCE_UNSPECIFIED:
return getContext().getString(R.string.notification_importance_unspecified);
case NotificationManager.IMPORTANCE_NONE:
return getContext().getString(R.string.notification_importance_blocked);
case NotificationManager.IMPORTANCE_MIN:
return getContext().getString(R.string.notification_importance_min);
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 addAppLinkPref() {
if (mAppRow.settingsIntent != null) {
mAppLink = new Preference(getPrefContext());
mAppLink.setKey(KEY_APP_LINK);
mAppLink.setOrder(500);
mAppLink.setIntent(mAppRow.settingsIntent);
mAppLink.setTitle(mContext.getString(R.string.app_settings_link));
getPreferenceScreen().addPreference(mAppLink);
}
}
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) {
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
mPriority.setChecked(priority);
mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -276,6 +327,8 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
}
protected void setupVisOverridePref(int sensitive) {
mVisibilityOverride =
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
ArrayList<CharSequence> entries = new ArrayList<>();
ArrayList<CharSequence> values = new ArrayList<>();
@@ -328,6 +381,8 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
}
protected void setupBlockDesc(int summaryResId) {
mBlockedDesc = (FooterPreference) getPreferenceScreen().findPreference(
KEY_BLOCKED_DESC);
mBlockedDesc = new FooterPreference(getPrefContext());
mBlockedDesc.setSelectable(false);
mBlockedDesc.setTitle(summaryResId);
@@ -336,6 +391,13 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
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,
CharSequence entryValue, int keyguardNotificationFeatures) {
@@ -359,7 +421,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
return globalVis;
}
private boolean getLockscreenNotificationsEnabled() {
return Settings.Secure.getInt(getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
@@ -369,4 +430,17 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
return Settings.Secure.getInt(getContentResolver(),
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;
}
}