PreferenceControllers are the way of the future.
Migrates Notification settings (app level, group level, and channel level) into PreferenceControllers (and most importantly: PreferenceControllerTest) Note: this removes the 'Advanced' preference group, but does not yet use the standard system 'Advanced' grouping as it does not currently support our use case (where we don't know how many fields to show outside of 'Advanced' until onResume() and also where we need fields to show below the 'Advanced' group). Test: make RunSettingsRoboTests Change-Id: Iddd1b4771922db322e5f73562e9d63ed077c5396
This commit is contained in:
@@ -27,10 +27,15 @@ import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
import android.app.Notification;
|
||||
@@ -53,10 +58,12 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
@@ -68,66 +75,30 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
abstract public class NotificationSettingsBase extends SettingsPreferenceFragment {
|
||||
abstract public class NotificationSettingsBase extends DashboardFragment {
|
||||
private static final String TAG = "NotifiSettingsBase";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private static final Intent APP_NOTIFICATION_PREFS_CATEGORY_INTENT
|
||||
= new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);
|
||||
|
||||
protected static final int ORDER_FIRST = -500;
|
||||
protected static final int ORDER_LAST = 1000;
|
||||
|
||||
protected static final String KEY_APP_LINK = "app_link";
|
||||
protected static final String KEY_HEADER = "header";
|
||||
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_BLOCKED_DESC = "block_desc";
|
||||
protected static final String KEY_ALLOW_SOUND = "allow_sound";
|
||||
|
||||
protected PackageManager mPm;
|
||||
protected UserManager mUm;
|
||||
protected NotificationBackend mBackend = new NotificationBackend();
|
||||
protected LockPatternUtils mLockPatternUtils;
|
||||
protected NotificationManager mNm;
|
||||
protected Context mContext;
|
||||
protected boolean mCreated;
|
||||
|
||||
protected int mUid;
|
||||
protected int mUserId;
|
||||
protected String mPkg;
|
||||
protected PackageInfo mPkgInfo;
|
||||
protected RestrictedSwitchPreference mBadge;
|
||||
protected RestrictedSwitchPreference mPriority;
|
||||
protected RestrictedDropDownPreference mVisibilityOverride;
|
||||
protected RestrictedSwitchPreference mImportanceToggle;
|
||||
protected LayoutPreference mBlockBar;
|
||||
protected SwitchBar mSwitchBar;
|
||||
protected FooterPreference mBlockedDesc;
|
||||
protected Preference mAppLink;
|
||||
|
||||
protected EnforcedAdmin mSuspendedAppsAdmin;
|
||||
protected boolean mDndVisualEffectsSuppressed;
|
||||
|
||||
protected NotificationChannelGroup mChannelGroup;
|
||||
protected NotificationChannelGroupWrapper mChannelGroup;
|
||||
protected NotificationChannel mChannel;
|
||||
protected NotificationBackend.AppRow mAppRow;
|
||||
protected boolean mShowLegacyChannelConfig = false;
|
||||
|
||||
protected boolean mShowLegacyChannelConfig = false;
|
||||
protected boolean mListeningToPackageRemove;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
if (DEBUG) Log.d(TAG, "onActivityCreated mCreated=" + mCreated);
|
||||
if (mCreated) {
|
||||
Log.w(TAG, "onActivityCreated: ignoring duplicate call");
|
||||
return;
|
||||
}
|
||||
mCreated = true;
|
||||
}
|
||||
protected List<NotificationPreferenceController> mControllers = new ArrayList<>();
|
||||
protected List<Preference> mDynamicPreferences = new ArrayList<>();
|
||||
protected ImportanceListener mImportanceListener = new ImportanceListener();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -143,7 +114,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
}
|
||||
|
||||
mPm = getPackageManager();
|
||||
mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
mNm = NotificationManager.from(mContext);
|
||||
|
||||
mPkg = args != null && args.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
|
||||
@@ -187,35 +157,41 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
return;
|
||||
}
|
||||
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
|
||||
if (mAppRow == null) {
|
||||
Log.w(TAG, "Can't load package");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
collectConfigActivities();
|
||||
Bundle args = getArguments();
|
||||
mChannel = (args != null && args.containsKey(Settings.EXTRA_CHANNEL_ID)) ?
|
||||
mBackend.getChannel(mPkg, mUid, args.getString(Settings.EXTRA_CHANNEL_ID)) : null;
|
||||
|
||||
mChannelGroup = (args != null && args.containsKey(Settings.EXTRA_CHANNEL_GROUP_ID)) ?
|
||||
mBackend.getGroupWithChannels(mPkg, mUid,
|
||||
NotificationChannelGroup group =
|
||||
(args != null && args.containsKey(Settings.EXTRA_CHANNEL_GROUP_ID))
|
||||
? mBackend.getGroupWithChannels(mPkg, mUid,
|
||||
args.getString(Settings.EXTRA_CHANNEL_GROUP_ID))
|
||||
: null;
|
||||
: null;
|
||||
if (group != null) {
|
||||
mChannelGroup = new NotificationChannelGroupWrapper(group);
|
||||
}
|
||||
|
||||
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
|
||||
mContext, mPkg, mUserId);
|
||||
NotificationManager.Policy policy = mNm.getNotificationPolicy();
|
||||
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
|
||||
|
||||
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
|
||||
mContext, mPkg, mUserId);
|
||||
}
|
||||
mShowLegacyChannelConfig = mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|
||||
|| (mChannel != null
|
||||
&& NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()));
|
||||
|
||||
protected void setVisible(Preference p, boolean visible) {
|
||||
setVisible(getPreferenceScreen(), p, visible);
|
||||
}
|
||||
|
||||
protected void setVisible(PreferenceGroup parent, Preference p, boolean visible) {
|
||||
final boolean isVisible = parent.findPreference(p.getKey()) != null;
|
||||
if (isVisible == visible) return;
|
||||
if (visible) {
|
||||
parent.addPreference(p);
|
||||
} else {
|
||||
parent.removePreference(p);
|
||||
if (mShowLegacyChannelConfig) {
|
||||
mChannel = mBackend.getChannel(
|
||||
mAppRow.pkg, mAppRow.uid, NotificationChannel.DEFAULT_CHANNEL_ID);
|
||||
}
|
||||
if (mChannel != null && !TextUtils.isEmpty(mChannel.getGroup())) {
|
||||
group = mBackend.getGroup(mPkg, mUid, mChannel.getGroup());
|
||||
if (group != null) {
|
||||
mChannelGroup = new NotificationChannelGroupWrapper(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,49 +200,34 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
private List<ResolveInfo> queryNotificationConfigActivities() {
|
||||
if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
|
||||
+ APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
|
||||
protected void collectConfigActivities() {
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES)
|
||||
.setPackage(mAppRow.pkg);
|
||||
final List<ResolveInfo> resolveInfos = mPm.queryIntentActivities(
|
||||
APP_NOTIFICATION_PREFS_CATEGORY_INTENT,
|
||||
intent,
|
||||
0 //PackageManager.MATCH_DEFAULT_ONLY
|
||||
);
|
||||
return resolveInfos;
|
||||
}
|
||||
|
||||
protected void collectConfigActivities(ArrayMap<String, NotificationBackend.AppRow> rows) {
|
||||
final List<ResolveInfo> resolveInfos = queryNotificationConfigActivities();
|
||||
applyConfigActivities(rows, resolveInfos);
|
||||
}
|
||||
|
||||
private void applyConfigActivities(ArrayMap<String, NotificationBackend.AppRow> rows,
|
||||
List<ResolveInfo> resolveInfos) {
|
||||
if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities"
|
||||
+ (resolveInfos.size() == 0 ? " ;_;" : ""));
|
||||
for (ResolveInfo ri : resolveInfos) {
|
||||
final ActivityInfo activityInfo = ri.activityInfo;
|
||||
final ApplicationInfo appInfo = activityInfo.applicationInfo;
|
||||
final NotificationBackend.AppRow row = rows.get(appInfo.packageName);
|
||||
if (row == null) {
|
||||
if (DEBUG) Log.v(TAG, "Ignoring notification preference activity ("
|
||||
+ activityInfo.name + ") for unknown package "
|
||||
+ activityInfo.packageName);
|
||||
continue;
|
||||
}
|
||||
if (row.settingsIntent != null) {
|
||||
if (mAppRow.settingsIntent != null) {
|
||||
if (DEBUG) Log.v(TAG, "Ignoring duplicate notification preference activity ("
|
||||
+ activityInfo.name + ") for package "
|
||||
+ activityInfo.packageName);
|
||||
continue;
|
||||
}
|
||||
row.settingsIntent = new Intent(APP_NOTIFICATION_PREFS_CATEGORY_INTENT)
|
||||
mAppRow.settingsIntent = intent
|
||||
.setPackage(null)
|
||||
.setClassName(activityInfo.packageName, activityInfo.name);
|
||||
if (mChannel != null) {
|
||||
row.settingsIntent.putExtra(Notification.EXTRA_CHANNEL_ID, mChannel.getId());
|
||||
mAppRow.settingsIntent.putExtra(Notification.EXTRA_CHANNEL_ID, mChannel.getId());
|
||||
}
|
||||
if (mChannelGroup != null) {
|
||||
row.settingsIntent.putExtra(
|
||||
Notification.EXTRA_CHANNEL_GROUP_ID, mChannelGroup.getId());
|
||||
mAppRow.settingsIntent.putExtra(
|
||||
Notification.EXTRA_CHANNEL_GROUP_ID, mChannelGroup.getGroup().getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -292,134 +253,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void addAppLinkPref() {
|
||||
if (mAppRow.settingsIntent != null && mAppLink == null) {
|
||||
addPreferencesFromResource(R.xml.inapp_notification_settings);
|
||||
mAppLink = findPreference(KEY_APP_LINK);
|
||||
mAppLink.setIntent(mAppRow.settingsIntent);
|
||||
}
|
||||
}
|
||||
|
||||
protected void populateDefaultChannelPrefs() {
|
||||
if (mPkgInfo != null && mChannel != null) {
|
||||
addPreferencesFromResource(R.xml.legacy_channel_notification_settings);
|
||||
setupPriorityPref(mChannel.canBypassDnd());
|
||||
setupVisOverridePref(mChannel.getLockscreenVisibility());
|
||||
setupImportanceToggle();
|
||||
setupBadge();
|
||||
}
|
||||
mSwitchBar.setChecked(!mAppRow.banned
|
||||
&& mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
||||
}
|
||||
|
||||
abstract void setupBadge();
|
||||
|
||||
abstract void updateDependents(boolean banned);
|
||||
|
||||
// 'allow sound'
|
||||
private void setupImportanceToggle() {
|
||||
mImportanceToggle = (RestrictedSwitchPreference) findPreference(KEY_ALLOW_SOUND);
|
||||
mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mImportanceToggle.setEnabled(isChannelConfigurable(mChannel)
|
||||
&& !mImportanceToggle.isDisabledByAdmin());
|
||||
mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
|
||||
|| mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
|
||||
mImportanceToggle.setOnPreferenceChangeListener(
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final int importance =
|
||||
((Boolean) newValue ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_LOW);
|
||||
mChannel.setImportance(importance);
|
||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||
updateDependents(mChannel.getImportance() == IMPORTANCE_NONE);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void setupPriorityPref(boolean priority) {
|
||||
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mPriority.setEnabled(isChannelConfigurable(mChannel) && !mPriority.isDisabledByAdmin());
|
||||
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) {
|
||||
mVisibilityOverride =
|
||||
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
|
||||
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);
|
||||
}
|
||||
|
||||
protected void setupBlockDesc(int summaryResId) {
|
||||
mBlockedDesc = new FooterPreference(getPrefContext());
|
||||
mBlockedDesc.setSelectable(false);
|
||||
mBlockedDesc.setTitle(summaryResId);
|
||||
mBlockedDesc.setEnabled(false);
|
||||
mBlockedDesc.setOrder(50);
|
||||
mBlockedDesc.setKey(KEY_BLOCKED_DESC);
|
||||
getPreferenceScreen().addPreference(mBlockedDesc);
|
||||
}
|
||||
|
||||
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
|
||||
final NotificationChannel channel, String summary) {
|
||||
MasterSwitchPreference channelPref = new MasterSwitchPreference(
|
||||
@@ -461,105 +294,48 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
return channelPref;
|
||||
}
|
||||
|
||||
protected boolean checkCanBeVisible(int minImportanceVisible) {
|
||||
int importance = mChannel.getImportance();
|
||||
if (importance == NotificationManager.IMPORTANCE_UNSPECIFIED) {
|
||||
return true;
|
||||
}
|
||||
return importance >= minImportanceVisible;
|
||||
}
|
||||
|
||||
protected String getImportanceSummary(NotificationChannel channel) {
|
||||
switch (channel.getImportance()) {
|
||||
case NotificationManager.IMPORTANCE_UNSPECIFIED:
|
||||
return getContext().getString(R.string.notification_importance_unspecified);
|
||||
case NotificationManager.IMPORTANCE_NONE:
|
||||
return getContext().getString(R.string.notification_toggle_off);
|
||||
case NotificationManager.IMPORTANCE_MIN:
|
||||
return getContext().getString(R.string.notification_importance_min);
|
||||
case NotificationManager.IMPORTANCE_LOW:
|
||||
return getContext().getString(R.string.notification_importance_low);
|
||||
case NotificationManager.IMPORTANCE_DEFAULT:
|
||||
if (hasValidSound(channel)) {
|
||||
return getContext().getString(R.string.notification_importance_default);
|
||||
} else { // Silent
|
||||
return getContext().getString(R.string.notification_importance_low);
|
||||
}
|
||||
case NotificationManager.IMPORTANCE_HIGH:
|
||||
case NotificationManager.IMPORTANCE_MAX:
|
||||
default:
|
||||
if (hasValidSound(channel)) {
|
||||
return getContext().getString(R.string.notification_importance_high);
|
||||
} else { // Silent
|
||||
return getContext().getString(R.string.notification_importance_high_silent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected boolean isLockScreenSecure() {
|
||||
if (mLockPatternUtils == null) {
|
||||
mLockPatternUtils = new LockPatternUtils(getActivity());
|
||||
}
|
||||
boolean lockscreenSecure = mLockPatternUtils.isSecure(UserHandle.myUserId());
|
||||
UserInfo parentUser = mUm.getProfileParent(UserHandle.myUserId());
|
||||
if (parentUser != null){
|
||||
lockscreenSecure |= mLockPatternUtils.isSecure(parentUser.id);
|
||||
}
|
||||
|
||||
return lockscreenSecure;
|
||||
}
|
||||
|
||||
protected boolean isChannelConfigurable(NotificationChannel channel) {
|
||||
return !channel.getId().equals(mAppRow.lockedChannelId);
|
||||
if (channel != null && mAppRow != null) {
|
||||
return !channel.getId().equals(mAppRow.lockedChannelId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isChannelBlockable(NotificationChannel channel) {
|
||||
if (!mAppRow.systemApp) {
|
||||
return true;
|
||||
}
|
||||
if (channel != null && mAppRow != null) {
|
||||
if (!mAppRow.systemApp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return channel.isBlockableSystem()
|
||||
|| channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
|
||||
return channel.isBlockableSystem()
|
||||
|| channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isChannelGroupBlockable(NotificationChannelGroup group) {
|
||||
if (!mAppRow.systemApp) {
|
||||
return true;
|
||||
}
|
||||
if (group != null && mAppRow != null) {
|
||||
if (!mAppRow.systemApp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return group.isBlocked();
|
||||
return group.isBlocked();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void setVisible(Preference p, boolean visible) {
|
||||
setVisible(getPreferenceScreen(), p, visible);
|
||||
}
|
||||
|
||||
protected void setVisible(PreferenceGroup parent, Preference p, boolean visible) {
|
||||
final boolean isVisible = parent.findPreference(p.getKey()) != null;
|
||||
if (isVisible == visible) return;
|
||||
if (visible) {
|
||||
parent.addPreference(p);
|
||||
} else {
|
||||
parent.removePreference(p);
|
||||
}
|
||||
}
|
||||
|
||||
protected void startListeningToPackageRemove() {
|
||||
@@ -604,7 +380,45 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
return left.getId().compareTo(right.getId());
|
||||
};
|
||||
|
||||
boolean hasValidSound(NotificationChannel channel) {
|
||||
return channel.getSound() != null && !Uri.EMPTY.equals(channel.getSound());
|
||||
/**
|
||||
* These screens aren't searchable - they only make sense in the context of an app, so
|
||||
* surfacing a generic version would be impossible.
|
||||
*/
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
return getPreferenceControllers(context);
|
||||
}
|
||||
};
|
||||
|
||||
protected class ImportanceListener {
|
||||
protected void onImportanceChanged() {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
for (NotificationPreferenceController controller : mControllers) {
|
||||
controller.displayPreference(screen);
|
||||
}
|
||||
updatePreferenceStates();
|
||||
|
||||
boolean hideDynamicFields = false;
|
||||
if (mAppRow == null || mAppRow.banned) {
|
||||
hideDynamicFields = true;
|
||||
} else {
|
||||
if (mChannel != null) {
|
||||
hideDynamicFields = mChannel.getImportance() == IMPORTANCE_NONE;
|
||||
} else if (mChannelGroup != null) {
|
||||
hideDynamicFields = mChannelGroup.isBlocked();
|
||||
}
|
||||
}
|
||||
for (Preference preference : mDynamicPreferences) {
|
||||
setVisible(getPreferenceScreen(), preference, !hideDynamicFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user