From dcee38d02e5599d487ba43c3732cb038eba35455 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 6 Mar 2017 15:24:35 -0500 Subject: [PATCH] Prevent whitelisted apps from blocking and silencing Change-Id: I34cb5c2c59d56b68ed1500c8c79cd65676c0af25 Fixes: 35841524 Test: manual --- .../notification/AppNotificationSettings.java | 5 +- .../ChannelNotificationSettings.java | 69 +++++++++++-------- .../notification/NotificationBackend.java | 3 +- .../NotificationSettingsBase.java | 4 +- 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index a451786da4a..d12842c32d3 100644 --- a/src/com/android/settings/notification/AppNotificationSettings.java +++ b/src/com/android/settings/notification/AppNotificationSettings.java @@ -218,7 +218,7 @@ public class AppNotificationSettings extends NotificationSettingsBase { } private void setupBlock() { - if (mAppRow.systemApp) { + if (mAppRow.systemApp && !mAppRow.banned) { setVisible(mBlock, false); } else { mBlock.setDisabledByAdmin(mSuspendedAppsAdmin); @@ -243,6 +243,9 @@ public class AppNotificationSettings extends NotificationSettingsBase { setVisible(category, !banned); } setVisible(mBadge, !banned); + if (mAppRow.systemApp && !mAppRow.banned) { + setVisible(mBlock, false); + } } private Comparator mChannelComparator = diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java index 1cb2154560d..18e00f831e4 100644 --- a/src/com/android/settings/notification/ChannelNotificationSettings.java +++ b/src/com/android/settings/notification/ChannelNotificationSettings.java @@ -134,7 +134,9 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { } mLights.setDisabledByAdmin(mSuspendedAppsAdmin); mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin); - mImportance.setDisabledByAdmin(mSuspendedAppsAdmin); + if (mImportance.isEnabled()) { + mImportance.setDisabledByAdmin(mSuspendedAppsAdmin); + } mPriority.setDisabledByAdmin(mSuspendedAppsAdmin); mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin); } @@ -185,21 +187,26 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { } protected void setupBlockAndImportance() { - mBlock.setDisabledByAdmin(mSuspendedAppsAdmin); - mBlock.setChecked(mChannel.getImportance() == NotificationManager.IMPORTANCE_NONE); - mBlock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - final boolean value = (Boolean) newValue; - int importance = value ? IMPORTANCE_NONE : IMPORTANCE_LOW; - mImportance.setValue(String.valueOf(importance)); - mChannel.setImportance(importance); - mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); - mBackend.updateChannel(mPkg, mUid, mChannel); - updateDependents(); - return true; - } - }); + if (mAppRow.systemApp && mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE) { + setVisible(mBlock, false); + } else { + mBlock.setEnabled(mAppRow.systemApp); + mBlock.setDisabledByAdmin(mSuspendedAppsAdmin); + mBlock.setChecked(mChannel.getImportance() == NotificationManager.IMPORTANCE_NONE); + mBlock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean value = (Boolean) newValue; + int importance = value ? IMPORTANCE_NONE : IMPORTANCE_LOW; + mImportance.setValue(String.valueOf(importance)); + mChannel.setImportance(importance); + mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); + mBackend.updateChannel(mPkg, mUid, mChannel); + updateDependents(); + return true; + } + }); + } mBadge.setDisabledByAdmin(mSuspendedAppsAdmin); mBadge.setEnabled(mAppRow.showBadge); mBadge.setChecked(mChannel.canShowBadge()); @@ -217,7 +224,8 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { mImportance.setDisabledByAdmin(mSuspendedAppsAdmin); final int numImportances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1; List summaries = new ArrayList<>(); - List values = new ArrayList<>();; + List values = new ArrayList<>(); + ; for (int i = 0; i < numImportances; i++) { int importance = i + 1; summaries.add(getImportanceSummary(importance)); @@ -232,18 +240,21 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { mImportance.setEntries(summaries.toArray(new String[0])); mImportance.setValue(String.valueOf(mChannel.getImportance())); mImportance.setSummary("%s"); - - mImportance.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - int importance = Integer.parseInt((String) newValue); - mChannel.setImportance(importance); - mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); - mBackend.updateChannel(mPkg, mUid, mChannel); - updateDependents(); - return true; - } - }); + if (mAppRow.lockedImportance) { + mImportance.setEnabled(false); + } else { + mImportance.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + int importance = Integer.parseInt((String) newValue); + mChannel.setImportance(importance); + mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); + mBackend.updateChannel(mPkg, mUid, mChannel); + updateDependents(); + return true; + } + }); + } } protected void setupPriorityPref(boolean priority) { diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java index d201d60ca09..0881eb76553 100644 --- a/src/com/android/settings/notification/NotificationBackend.java +++ b/src/com/android/settings/notification/NotificationBackend.java @@ -64,7 +64,7 @@ public class NotificationBackend { int N = nonBlockablePkgs.length; for (int i = 0; i < N; i++) { if (app.packageName.equals(nonBlockablePkgs[i])) { - row.systemApp = true; + row.systemApp = row.lockedImportance = true; } } } @@ -152,6 +152,7 @@ public class NotificationBackend { public boolean banned; public boolean first; // first app in section public boolean systemApp; + public boolean lockedImportance; public boolean showBadge; public int userId; } diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java index 38de27eee91..6a40ea59e74 100644 --- a/src/com/android/settings/notification/NotificationSettingsBase.java +++ b/src/com/android/settings/notification/NotificationSettingsBase.java @@ -148,7 +148,9 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen } mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended( mContext, mPkg, mUserId); - mBlock.setDisabledByAdmin(mSuspendedAppsAdmin); + if (mBlock.isEnabled()) { + mBlock.setDisabledByAdmin(mSuspendedAppsAdmin); + } mBadge.setDisabledByAdmin(mSuspendedAppsAdmin); }