Limit unconfigurability to specified channels.
am: 80fa6b5833
Change-Id: I63c40ae241f6891fa1e6b85a78dc78d2b918ca6d
This commit is contained in:
@@ -211,7 +211,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
MasterSwitchPreference channelPref = new MasterSwitchPreference(
|
||||
getPrefContext());
|
||||
channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
|
||||
&& isChannelBlockable(mAppRow.systemApp, channel));
|
||||
&& isChannelBlockable(mAppRow.systemApp, channel)
|
||||
&& isChannelConfigurable(channel));
|
||||
channelPref.setKey(channel.getId());
|
||||
channelPref.setTitle(channel.getName());
|
||||
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
|
||||
|
@@ -213,7 +213,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
||||
private void setupVibrate() {
|
||||
mVibrate = (RestrictedSwitchPreference) findPreference(KEY_VIBRATE);
|
||||
mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mVibrate.setEnabled(!(mAppRow.lockedImportance || mVibrate.isDisabledByAdmin()));
|
||||
mVibrate.setEnabled(!mVibrate.isDisabledByAdmin() && isChannelConfigurable(mChannel));
|
||||
mVibrate.setChecked(mChannel.shouldVibrate());
|
||||
mVibrate.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
@@ -230,7 +230,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
||||
private void setupRingtone() {
|
||||
mRingtone = (NotificationSoundPreference) findPreference(KEY_RINGTONE);
|
||||
mRingtone.setRingtone(mChannel.getSound());
|
||||
mRingtone.setEnabled(!(mAppRow.lockedImportance));
|
||||
mRingtone.setEnabled(isChannelConfigurable(mChannel));
|
||||
mRingtone.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
@@ -286,7 +286,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
||||
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
||||
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
|
||||
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
|
||||
mImportance.setEnabled(mSuspendedAppsAdmin == null && !mAppRow.lockedImportance);
|
||||
mImportance.setEnabled(mSuspendedAppsAdmin == null && isChannelConfigurable(mChannel));
|
||||
// Set up intent to show importance selection only if this setting is enabled.
|
||||
if (mImportance.isEnabled()) {
|
||||
Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
|
||||
|
@@ -30,6 +30,7 @@ import android.os.UserHandle;
|
||||
import android.util.IconDrawableFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
public class NotificationBackend {
|
||||
@@ -60,15 +61,28 @@ public class NotificationBackend {
|
||||
row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app);
|
||||
final String[] nonBlockablePkgs = context.getResources().getStringArray(
|
||||
com.android.internal.R.array.config_nonBlockableNotificationPackages);
|
||||
markAppRowWithBlockables(nonBlockablePkgs, row, app.packageName);
|
||||
return row;
|
||||
}
|
||||
|
||||
@VisibleForTesting static void markAppRowWithBlockables(String[] nonBlockablePkgs, AppRow row,
|
||||
String packageName) {
|
||||
if (nonBlockablePkgs != null) {
|
||||
int N = nonBlockablePkgs.length;
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (app.packageName.equals(nonBlockablePkgs[i])) {
|
||||
String pkg = nonBlockablePkgs[i];
|
||||
if (pkg == null) {
|
||||
continue;
|
||||
} else if (pkg.contains(":")) {
|
||||
// Interpret as channel; lock only this channel for this app.
|
||||
if (packageName.equals(pkg.split(":", 2)[0])) {
|
||||
row.lockedChannelId = pkg.split(":", 2 )[1];
|
||||
}
|
||||
} else if (packageName.equals(nonBlockablePkgs[i])) {
|
||||
row.systemApp = row.lockedImportance = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
public boolean getNotificationsBanned(String pkg, int uid) {
|
||||
@@ -184,6 +198,7 @@ public class NotificationBackend {
|
||||
public boolean first; // first app in section
|
||||
public boolean systemApp;
|
||||
public boolean lockedImportance;
|
||||
public String lockedChannelId;
|
||||
public boolean showBadge;
|
||||
public int userId;
|
||||
}
|
||||
|
@@ -293,8 +293,8 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
private void setupImportanceToggle() {
|
||||
mImportanceToggle = (RestrictedSwitchPreference) findPreference(KEY_ALLOW_SOUND);
|
||||
mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mImportanceToggle.setEnabled(!(mAppRow.lockedImportance
|
||||
|| mImportanceToggle.isDisabledByAdmin()));
|
||||
mImportanceToggle.setEnabled(isChannelConfigurable(mChannel)
|
||||
&& !mImportanceToggle.isDisabledByAdmin());
|
||||
mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
|
||||
|| mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
|
||||
mImportanceToggle.setOnPreferenceChangeListener(
|
||||
@@ -315,7 +315,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
protected void setupPriorityPref(boolean priority) {
|
||||
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mPriority.setEnabled(!(mAppRow.lockedImportance || mPriority.isDisabledByAdmin()));
|
||||
mPriority.setEnabled(isChannelConfigurable(mChannel) && !mPriority.isDisabledByAdmin());
|
||||
mPriority.setChecked(priority);
|
||||
mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
@@ -447,10 +447,15 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
return lockscreenSecure;
|
||||
}
|
||||
|
||||
protected boolean isChannelConfigurable(NotificationChannel channel) {
|
||||
return !channel.getId().equals(mAppRow.lockedChannelId);
|
||||
}
|
||||
|
||||
protected boolean isChannelBlockable(boolean systemApp, NotificationChannel channel) {
|
||||
if (!mAppRow.systemApp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return channel.isBlockableSystem()
|
||||
|| channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user