Suppress notif block/silence settings for essential packages.

Companion to change I6b8fa374.

Bug: 31360343
Test: Manual. With config_nonBlockableNotificationPackages
      set to include com.android.dialer, examine Dialer's
      notification settings. Be sure to test with advanced
      notification controls enabled in System UI Tuner.
Change-Id: Ifbe13acf4cb02d6642f5c80e000f5b558f289920
This commit is contained in:
Dan Sandler
2016-10-04 15:24:23 -04:00
committed by Daniel Sandler
parent 0d424ef9bd
commit acf763e996
3 changed files with 25 additions and 18 deletions

View File

@@ -90,7 +90,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
rows.put(mAppRow.pkg, mAppRow); rows.put(mAppRow.pkg, mAppRow);
collectConfigActivities(rows); collectConfigActivities(rows);
setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance, mAppRow.banned); setupImportancePrefs(mAppRow.cantBlock, mAppRow.cantSilence,
mAppRow.appImportance, mAppRow.banned);
setupPriorityPref(mAppRow.appBypassDnd); setupPriorityPref(mAppRow.appBypassDnd);
setupVisOverridePref(mAppRow.appVisOverride); setupVisOverridePref(mAppRow.appVisOverride);
updateDependents(mAppRow.appImportance); updateDependents(mAppRow.appImportance);

View File

@@ -59,14 +59,14 @@ public class NotificationBackend {
public AppRow loadAppRow(Context context, PackageManager pm, PackageInfo app) { public AppRow loadAppRow(Context context, PackageManager pm, PackageInfo app) {
final AppRow row = loadAppRow(context, pm, app.applicationInfo); final AppRow row = loadAppRow(context, pm, app.applicationInfo);
row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app); row.cantBlock = Utils.isSystemPackage(context.getResources(), pm, app);
final String[] nonBlockablePkgs = context.getResources().getStringArray( final String[] nonBlockablePkgs = context.getResources().getStringArray(
com.android.internal.R.array.config_nonBlockableNotificationPackages); com.android.internal.R.array.config_nonBlockableNotificationPackages);
if (nonBlockablePkgs != null) { if (nonBlockablePkgs != null) {
int N = nonBlockablePkgs.length; int N = nonBlockablePkgs.length;
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
if (app.packageName.equals(nonBlockablePkgs[i])) { if (app.packageName.equals(nonBlockablePkgs[i])) {
row.systemApp = true; row.cantBlock = row.cantSilence = true;
} }
} }
} }
@@ -153,7 +153,8 @@ public class NotificationBackend {
public Intent settingsIntent; public Intent settingsIntent;
public boolean banned; public boolean banned;
public boolean first; // first app in section public boolean first; // first app in section
public boolean systemApp; public boolean cantBlock;
public boolean cantSilence;
public int appImportance; public int appImportance;
public boolean appBypassDnd; public boolean appBypassDnd;
public int appVisOverride; public int appVisOverride;

View File

@@ -154,8 +154,9 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
} }
} }
protected void setupImportancePrefs(boolean notBlockable, int importance, boolean banned) { protected void setupImportancePrefs(boolean notBlockable, boolean notSilenceable,
if (mShowSlider) { int importance, boolean banned) {
if (mShowSlider && !notSilenceable) {
setVisible(mBlock, false); setVisible(mBlock, false);
setVisible(mSilent, false); setVisible(mSilent, false);
mImportance.setDisabledByAdmin(mSuspendedAppsAdmin); mImportance.setDisabledByAdmin(mSuspendedAppsAdmin);
@@ -192,18 +193,22 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
} }
}); });
} }
mSilent.setChecked(importance == Ranking.IMPORTANCE_LOW); if (notSilenceable) {
mSilent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { setVisible(mSilent, false);
@Override } else {
public boolean onPreferenceChange(Preference preference, Object newValue) { mSilent.setChecked(importance == Ranking.IMPORTANCE_LOW);
final boolean silenced = (Boolean) newValue; mSilent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
final int importance = @Override
silenced ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_UNSPECIFIED; public boolean onPreferenceChange(Preference preference, Object newValue) {
mBackend.setImportance(mPkgInfo.packageName, mUid, importance); final boolean silenced = (Boolean) newValue;
updateDependents(importance); final int importance =
return true; silenced ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_UNSPECIFIED;
} mBackend.setImportance(mPkgInfo.packageName, mUid, importance);
}); updateDependents(importance);
return true;
}
});
}
updateDependents(banned ? Ranking.IMPORTANCE_NONE : importance); updateDependents(banned ? Ranking.IMPORTANCE_NONE : importance);
} }
} }