Prevent whitelisted apps from blocking and silencing

Change-Id: I34cb5c2c59d56b68ed1500c8c79cd65676c0af25
Fixes: 35841524
Test: manual
This commit is contained in:
Julia Reynolds
2017-03-06 15:24:35 -05:00
parent 6c2f9fe6d7
commit dcee38d02e
4 changed files with 49 additions and 32 deletions

View File

@@ -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<NotificationChannel> mChannelComparator =

View File

@@ -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<String> summaries = new ArrayList<>();
List<String> values = new ArrayList<>();;
List<String> 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) {

View File

@@ -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;
}

View File

@@ -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);
}