Config notifs page updates

- Remove unused settings
- Regroup and combine lockscreen settings. The original
lockscreen controller is used in other places (SUW and privacy)
and so it's left untouched for those uses for now.

Test: atest
Bug: 132971502
Change-Id: Ic82817ff98cab27ca35b9488ae2e0eb6922a18e8
This commit is contained in:
Julia Reynolds
2019-05-21 10:21:21 -04:00
parent 6cb224b38b
commit 4fe79c266e
9 changed files with 895 additions and 120 deletions

View File

@@ -57,17 +57,9 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
OnActivityResultListener {
private static final String TAG = "ConfigNotiSettings";
@VisibleForTesting
static final String KEY_LOCKSCREEN = "lock_screen_notifications";
@VisibleForTesting
static final String KEY_LOCKSCREEN_WORK_PROFILE_HEADER =
"lock_screen_notifications_profile_header";
@VisibleForTesting
static final String KEY_LOCKSCREEN_WORK_PROFILE = "lock_screen_notifications_profile";
@VisibleForTesting
static final String KEY_SWIPE_DOWN = "gesture_swipe_down_fingerprint_notifications";
@VisibleForTesting
static final String KEY_NOTIFICATION_ASSISTANT = "notification_assistant";
static final String KEY_LOCKSCREEN = "lock_screen_notifications";
private static final String KEY_NOTI_DEFAULT_RINGTONE = "notification_default_ringtone";
private static final int REQUEST_CODE = 200;
@@ -100,25 +92,18 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
} else {
app = null;
}
return buildPreferenceControllers(context, getSettingsLifecycle(), app, this);
return buildPreferenceControllers(context, app, this);
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, Application app, Fragment host) {
Application app, Fragment host) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final LockScreenNotificationPreferenceController lockScreenNotificationController =
new LockScreenNotificationPreferenceController(context,
KEY_LOCKSCREEN,
KEY_LOCKSCREEN_WORK_PROFILE_HEADER,
KEY_LOCKSCREEN_WORK_PROFILE);
if (lifecycle != null) {
lifecycle.addObserver(lockScreenNotificationController);
}
controllers.add(new RecentNotifyingAppsPreferenceController(
context, new NotificationBackend(), IUsageStatsManager.Stub.asInterface(
ServiceManager.getService(Context.USAGE_STATS_SERVICE)),
context.getSystemService(UserManager.class), app, host));
controllers.add(lockScreenNotificationController);
controllers.add(new ShowOnLockScreenNotificationPreferenceController(
context, KEY_LOCKSCREEN));
controllers.add(new NotificationRingtonePreferenceController(context) {
@Override
public String getPreferenceKey() {
@@ -245,7 +230,7 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null, null, null);
return buildPreferenceControllers(context, null, null);
}
@Override

View File

@@ -71,7 +71,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
static final String KEY_DIVIDER = "all_notifications_divider";
@VisibleForTesting
static final String KEY_SEE_ALL = "all_notifications";
private static final int SHOW_RECENT_APP_COUNT = 5;
private static final int SHOW_RECENT_APP_COUNT = 3;
private static final int DAYS = 3;
private static final Set<String> SKIP_SYSTEM_PACKAGES = new ArraySet<>();

View File

@@ -0,0 +1,130 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.Utils;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.overlay.FeatureFactory;
public class RedactNotificationPreferenceController extends TogglePreferenceController {
private static final String TAG = "LockScreenNotifPref";
static final String KEY_LOCKSCREEN_REDACT = "lock_screen_redact";
static final String KEY_LOCKSCREEN_WORK_PROFILE_REDACT = "lock_screen_work_redact";
private DevicePolicyManager mDpm;
private UserManager mUm;
private KeyguardManager mKm;
private final int mProfileUserId;
public RedactNotificationPreferenceController(Context context, String settingKey) {
super(context, settingKey);
mUm = context.getSystemService(UserManager.class);
mDpm = context.getSystemService(DevicePolicyManager.class);
mKm = context.getSystemService(KeyguardManager.class);
mProfileUserId = Utils.getManagedProfileId(mUm, UserHandle.myUserId());
}
@Override
public boolean isChecked() {
int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
? UserHandle.myUserId() : mProfileUserId;
return getAllowPrivateNotifications(userId);
}
@Override
public boolean setChecked(boolean isChecked) {
int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
? UserHandle.myUserId() : mProfileUserId;
Settings.Secure.putIntForUser(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, isChecked ? 1 : 0, userId);
return true;
}
@Override
public int getAvailabilityStatus() {
// hide work profile setting if no work profile
if (KEY_LOCKSCREEN_WORK_PROFILE_REDACT.equals(getPreferenceKey())
&& mProfileUserId == UserHandle.USER_NULL) {
return CONDITIONALLY_UNAVAILABLE;
}
int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
? UserHandle.myUserId() : mProfileUserId;
// hide if lockscreen isn't secure for this user
final LockPatternUtils utils = FeatureFactory.getFactory(mContext)
.getSecurityFeatureProvider()
.getLockPatternUtils(mContext);
if (!utils.isSecure(userId)) {
return CONDITIONALLY_UNAVAILABLE;
}
// all notifs hidden? admin doesn't allow notifs or redacted notifs? disabled
if (!getLockscreenNotificationsEnabled(userId)
|| !adminAllowsNotifications(userId)
|| !adminAllowsUnredactedNotifications(userId)) {
return DISABLED_DEPENDENT_SETTING;
}
// specifically the work profile setting requires the work profile to be unlocked
if (KEY_LOCKSCREEN_WORK_PROFILE_REDACT.equals(getPreferenceKey())) {
if (mKm.isDeviceLocked(mProfileUserId)) {
return DISABLED_DEPENDENT_SETTING;
}
}
return AVAILABLE;
}
private boolean adminAllowsNotifications(int userId) {
final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */, userId);
return (dpmFlags & KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0;
}
private boolean adminAllowsUnredactedNotifications(int userId) {
final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */, userId);
return (dpmFlags & KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) == 0;
}
private boolean getAllowPrivateNotifications(int userId) {
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, userId) != 0;
}
private boolean getLockscreenNotificationsEnabled(int userId) {
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, userId) != 0;
}
}

View File

@@ -0,0 +1,160 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.RestrictedListPreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.core.AbstractPreferenceController;
import com.google.common.annotations.VisibleForTesting;
import java.util.ArrayList;
import androidx.preference.Preference;
public class ShowOnLockScreenNotificationPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
private static final String TAG = "LockScreenNotifPref";
private final String mSettingKey;
private DevicePolicyManager mDpm;
public ShowOnLockScreenNotificationPreferenceController(Context context, String settingKey) {
super(context);
mSettingKey = settingKey;
mDpm = context.getSystemService(DevicePolicyManager.class);
}
@VisibleForTesting
void setDpm(DevicePolicyManager dpm) {
mDpm = dpm;
}
@Override
public String getPreferenceKey() {
return mSettingKey;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void updateState(Preference preference) {
RestrictedListPreference pref = (RestrictedListPreference) preference;
pref.clearRestrictedItems();
ArrayList<CharSequence> entries = new ArrayList<>();
ArrayList<CharSequence> values = new ArrayList<>();
String showAllEntry =
mContext.getString(R.string.lock_screen_notifs_show_all);
String showAllEntryValue =
Integer.toString(R.string.lock_screen_notifs_show_all);
entries.add(showAllEntry);
values.add(showAllEntryValue);
setRestrictedIfNotificationFeaturesDisabled(pref, showAllEntry, showAllEntryValue,
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
String alertingEntry = mContext.getString(R.string.lock_screen_notifs_show_alerting);
String alertingEntryValue = Integer.toString(R.string.lock_screen_notifs_show_alerting);
entries.add(alertingEntry);
values.add(alertingEntryValue);
setRestrictedIfNotificationFeaturesDisabled(pref, alertingEntry, alertingEntryValue,
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
entries.add(mContext.getString(R.string.lock_screen_notifs_show_none));
values.add(Integer.toString(R.string.lock_screen_notifs_show_none));
pref.setEntries(entries.toArray(new CharSequence[entries.size()]));
pref.setEntryValues(values.toArray(new CharSequence[values.size()]));
if (!adminAllowsNotifications() || !getLockscreenNotificationsEnabled()) {
pref.setValue(Integer.toString(R.string.lock_screen_notifs_show_none));
} else if (!getLockscreenSilentNotificationsEnabled()) {
pref.setValue(Integer.toString(R.string.lock_screen_notifs_show_alerting));
} else {
pref.setValue(Integer.toString(R.string.lock_screen_notifs_show_all));
}
pref.setOnPreferenceChangeListener(this);
refreshSummary(preference);
}
@Override
public CharSequence getSummary() {
if (!adminAllowsNotifications() || !getLockscreenNotificationsEnabled()) {
return mContext.getString(R.string.lock_screen_notifs_show_none);
} else if (!getLockscreenSilentNotificationsEnabled()) {
return mContext.getString(R.string.lock_screen_notifs_show_alerting);
} else {
return mContext.getString(R.string.lock_screen_notifs_show_all);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final int val = Integer.parseInt((String) newValue);
final boolean enabled = val != R.string.lock_screen_notifs_show_none;
final boolean show = val == R.string.lock_screen_notifs_show_all;
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, show ? 1 : 0);
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
refreshSummary(preference);
return true;
}
private void setRestrictedIfNotificationFeaturesDisabled(RestrictedListPreference pref,
CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) {
RestrictedLockUtils.EnforcedAdmin admin =
RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
mContext, keyguardNotificationFeatures, UserHandle.myUserId());
if (admin != null && pref != null) {
RestrictedListPreference.RestrictedItem item =
new RestrictedListPreference.RestrictedItem(entry, entryValue, admin);
pref.addRestrictedItem(item);
}
}
private boolean adminAllowsNotifications() {
final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */);
return (dpmFlags & KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0;
}
private boolean getLockscreenNotificationsEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
}
private boolean getLockscreenSilentNotificationsEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0) != 0;
}
}