From 77b1f525744350f8416c96f78145f8d3aaae5afb Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 12 Sep 2016 10:11:24 -0400 Subject: [PATCH] Non-blockable notification packages can't be blocked. Bug: 31404047 Change-Id: Icbe7e5e57983d281f6fe21e9b4715c822784d43c --- .../settings/notification/NotificationBackend.java | 10 +++++++ .../notification/NotificationSettingsBase.java | 32 +++++++++++----------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java index 944a1f2cfc..1229b9e3ce 100644 --- a/src/com/android/settings/notification/NotificationBackend.java +++ b/src/com/android/settings/notification/NotificationBackend.java @@ -60,6 +60,16 @@ public class NotificationBackend { public AppRow loadAppRow(Context context, PackageManager pm, PackageInfo app) { final AppRow row = loadAppRow(context, pm, app.applicationInfo); row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app); + final String[] nonBlockablePkgs = context.getResources().getStringArray( + com.android.internal.R.array.config_nonBlockableNotificationPackages); + if (nonBlockablePkgs != null) { + int N = nonBlockablePkgs.length; + for (int i = 0; i < N; i++) { + if (app.packageName.equals(nonBlockablePkgs[i])) { + row.systemApp = true; + } + } + } return row; } diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java index bce42eba91..3469cc0a26 100644 --- a/src/com/android/settings/notification/NotificationSettingsBase.java +++ b/src/com/android/settings/notification/NotificationSettingsBase.java @@ -154,13 +154,13 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen } } - protected void setupImportancePrefs(boolean isSystemApp, int importance, boolean banned) { + protected void setupImportancePrefs(boolean notBlockable, int importance, boolean banned) { if (mShowSlider) { setVisible(mBlock, false); setVisible(mSilent, false); mImportance.setDisabledByAdmin(mSuspendedAppsAdmin); mImportance.setMinimumProgress( - isSystemApp ? Ranking.IMPORTANCE_MIN : Ranking.IMPORTANCE_NONE); + notBlockable ? Ranking.IMPORTANCE_MIN : Ranking.IMPORTANCE_NONE); mImportance.setMax(Ranking.IMPORTANCE_MAX); mImportance.setProgress(importance); mImportance.setAutoOn(importance == Ranking.IMPORTANCE_UNSPECIFIED); @@ -175,7 +175,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen }); } else { setVisible(mImportance, false); - if (isSystemApp) { + if (notBlockable) { setVisible(mBlock, false); } else { boolean blocked = importance == Ranking.IMPORTANCE_NONE || banned; @@ -191,20 +191,20 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen return true; } }); - - mSilent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - final boolean silenced = (Boolean) newValue; - final int importance = - silenced ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_UNSPECIFIED; - mBackend.setImportance(mPkgInfo.packageName, mUid, importance); - updateDependents(importance); - return true; - } - }); - updateDependents(banned ? Ranking.IMPORTANCE_NONE : importance); } + mSilent.setChecked(importance == Ranking.IMPORTANCE_LOW); + mSilent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean silenced = (Boolean) newValue; + final int importance = + silenced ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_UNSPECIFIED; + mBackend.setImportance(mPkgInfo.packageName, mUid, importance); + updateDependents(importance); + return true; + } + }); + updateDependents(banned ? Ranking.IMPORTANCE_NONE : importance); } } -- 2.11.0