In apps with no channels, provide settings for misc channel in top level.
Test: robolectric tests pass, plus manual verification Bug: 36561295 Change-Id: I58872a41fab562787d85bade0552c7735d716e5b
This commit is contained in:
@@ -18,15 +18,14 @@ package com.android.settings.notification;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
@@ -39,6 +38,7 @@ import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
@@ -47,6 +47,7 @@ import android.widget.Toast;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
abstract public class NotificationSettingsBase extends SettingsPreferenceFragment {
|
||||
@@ -59,6 +60,9 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
|
||||
protected static final String KEY_BLOCK = "block";
|
||||
protected static final String KEY_BADGE = "badge";
|
||||
protected static final String KEY_BYPASS_DND = "bypass_dnd";
|
||||
protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
|
||||
protected static final String KEY_IMPORTANCE = "importance";
|
||||
|
||||
protected PackageManager mPm;
|
||||
protected UserManager mUm;
|
||||
@@ -71,6 +75,10 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
protected PackageInfo mPkgInfo;
|
||||
protected RestrictedSwitchPreference mBlock;
|
||||
protected RestrictedSwitchPreference mBadge;
|
||||
protected RestrictedDropDownPreference mImportance;
|
||||
protected RestrictedSwitchPreference mPriority;
|
||||
protected RestrictedDropDownPreference mVisibilityOverride;
|
||||
|
||||
protected EnforcedAdmin mSuspendedAppsAdmin;
|
||||
protected boolean mDndVisualEffectsSuppressed;
|
||||
|
||||
@@ -249,4 +257,105 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
return getContext().getString(R.string.notification_importance_high);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setupPriorityPref(boolean priority) {
|
||||
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mPriority.setChecked(priority);
|
||||
mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean bypassZenMode = (Boolean) newValue;
|
||||
mChannel.setBypassDnd(bypassZenMode);
|
||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
|
||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void setupVisOverridePref(int sensitive) {
|
||||
ArrayList<CharSequence> entries = new ArrayList<>();
|
||||
ArrayList<CharSequence> values = new ArrayList<>();
|
||||
|
||||
mVisibilityOverride.clearRestrictedItems();
|
||||
if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) {
|
||||
final String summaryShowEntry =
|
||||
getString(R.string.lock_screen_notifications_summary_show);
|
||||
final String summaryShowEntryValue =
|
||||
Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE);
|
||||
entries.add(summaryShowEntry);
|
||||
values.add(summaryShowEntryValue);
|
||||
setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue,
|
||||
DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS
|
||||
| DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
|
||||
}
|
||||
|
||||
final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide);
|
||||
final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE);
|
||||
entries.add(summaryHideEntry);
|
||||
values.add(summaryHideEntryValue);
|
||||
setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue,
|
||||
DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
|
||||
entries.add(getString(R.string.lock_screen_notifications_summary_disable));
|
||||
values.add(Integer.toString(Notification.VISIBILITY_SECRET));
|
||||
mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
||||
mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()]));
|
||||
|
||||
if (sensitive == NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE) {
|
||||
mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility()));
|
||||
} else {
|
||||
mVisibilityOverride.setValue(Integer.toString(sensitive));
|
||||
}
|
||||
mVisibilityOverride.setSummary("%s");
|
||||
|
||||
mVisibilityOverride.setOnPreferenceChangeListener(
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int sensitive = Integer.parseInt((String) newValue);
|
||||
if (sensitive == getGlobalVisibility()) {
|
||||
sensitive = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
|
||||
}
|
||||
mChannel.setLockscreenVisibility(sensitive);
|
||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
|
||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
}
|
||||
|
||||
|
||||
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
|
||||
CharSequence entryValue, int keyguardNotificationFeatures) {
|
||||
RestrictedLockUtils.EnforcedAdmin admin =
|
||||
RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
||||
mContext, keyguardNotificationFeatures, mUserId);
|
||||
if (admin != null) {
|
||||
RestrictedDropDownPreference.RestrictedItem item =
|
||||
new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin);
|
||||
mVisibilityOverride.addRestrictedItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
private int getGlobalVisibility() {
|
||||
int globalVis = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
|
||||
if (!getLockscreenNotificationsEnabled()) {
|
||||
globalVis = Notification.VISIBILITY_SECRET;
|
||||
} else if (!getLockscreenAllowPrivateNotifications()) {
|
||||
globalVis = Notification.VISIBILITY_PRIVATE;
|
||||
}
|
||||
return globalVis;
|
||||
}
|
||||
|
||||
|
||||
private boolean getLockscreenNotificationsEnabled() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
||||
}
|
||||
|
||||
private boolean getLockscreenAllowPrivateNotifications() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user