System gets its own dnd toggle
Test: make ROBOTEST_FILTER=ZenModeSystemPreferenceControllerTest RunSettingsRoboTests -j40 Bug: 73362490 Change-Id: Id5212665da8c820fc070676ff034dbe67510ea5d
This commit is contained in:
@@ -40,7 +40,8 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
|
||||
Lifecycle lifecycle) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeMediaSystemOtherPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
|
||||
@@ -85,7 +86,7 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> keys = super.getNonIndexableKeys(context);
|
||||
keys.add(ZenModeAlarmsPreferenceController.KEY);
|
||||
keys.add(ZenModeMediaSystemOtherPreferenceController.KEY);
|
||||
keys.add(ZenModeMediaPreferenceController.KEY);
|
||||
keys.add(ZenModeEventsPreferenceController.KEY);
|
||||
keys.add(ZenModeRemindersPreferenceController.KEY);
|
||||
keys.add(ZenModeMessagesPreferenceController.KEY);
|
||||
|
@@ -25,13 +25,13 @@ import android.util.Log;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class ZenModeMediaSystemOtherPreferenceController extends AbstractZenModePreferenceController
|
||||
public class ZenModeMediaPreferenceController extends AbstractZenModePreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
protected static final String KEY = "zen_mode_media";
|
||||
private final ZenModeBackend mBackend;
|
||||
|
||||
public ZenModeMediaSystemOtherPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
public ZenModeMediaPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
mBackend = ZenModeBackend.getInstance(context);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class ZenModeMediaSystemOtherPreferenceController extends AbstractZenMode
|
||||
default:
|
||||
pref.setEnabled(true);
|
||||
pref.setChecked(mBackend.isPriorityCategoryEnabled(
|
||||
Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER));
|
||||
Policy.PRIORITY_CATEGORY_MEDIA));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ public class ZenModeMediaSystemOtherPreferenceController extends AbstractZenMode
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean allowMedia = (Boolean) newValue;
|
||||
if (ZenModeSettingsBase.DEBUG) {
|
||||
Log.d(TAG, "onPrefChange allowMediaSystemOther=" + allowMedia);
|
||||
Log.d(TAG, "onPrefChange allowMedia=" + allowMedia);
|
||||
}
|
||||
mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER, allowMedia);
|
||||
mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_MEDIA, allowMedia);
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -77,9 +77,11 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
// these should match NotificationManager.Policy#ALL_PRIORITY_CATEGORIES
|
||||
private static final int[] ALL_PRIORITY_CATEGORIES = {
|
||||
Policy.PRIORITY_CATEGORY_ALARMS,
|
||||
Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
|
||||
Policy.PRIORITY_CATEGORY_MEDIA,
|
||||
Policy.PRIORITY_CATEGORY_SYSTEM,
|
||||
Policy.PRIORITY_CATEGORY_REMINDERS,
|
||||
Policy.PRIORITY_CATEGORY_EVENTS,
|
||||
Policy.PRIORITY_CATEGORY_MESSAGES,
|
||||
@@ -104,10 +106,10 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
return mContext.getString(R.string.zen_mode_behavior_total_silence);
|
||||
}
|
||||
|
||||
// only alarms and media/system can bypass dnd
|
||||
// only alarms and media can bypass dnd
|
||||
if (numCategories == 2 &&
|
||||
isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_ALARMS) &&
|
||||
isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER)) {
|
||||
isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MEDIA)) {
|
||||
return mContext.getString(R.string.zen_mode_behavior_alarms_only);
|
||||
}
|
||||
|
||||
@@ -164,9 +166,12 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
if (isCategoryEnabled(policy, category)) {
|
||||
if (category == Policy.PRIORITY_CATEGORY_ALARMS) {
|
||||
enabledCategories.add(mContext.getString(R.string.zen_mode_alarms));
|
||||
} else if (category == Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER) {
|
||||
} else if (category == Policy.PRIORITY_CATEGORY_MEDIA) {
|
||||
enabledCategories.add(mContext.getString(
|
||||
R.string.zen_mode_media_system_other));
|
||||
R.string.zen_mode_media));
|
||||
} else if (category == Policy.PRIORITY_CATEGORY_SYSTEM) {
|
||||
enabledCategories.add(mContext.getString(
|
||||
R.string.zen_mode_system));
|
||||
} else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
|
||||
enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
|
||||
} else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
|
||||
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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 android.app.NotificationManager.Policy;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class ZenModeSystemPreferenceController extends
|
||||
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
protected static final String KEY = "zen_mode_system";
|
||||
|
||||
public ZenModeSystemPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
SwitchPreference pref = (SwitchPreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
pref.setEnabled(false);
|
||||
pref.setChecked(false);
|
||||
break;
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
pref.setEnabled(false);
|
||||
pref.setChecked(false);
|
||||
break;
|
||||
default:
|
||||
pref.setEnabled(true);
|
||||
pref.setChecked(mBackend.isPriorityCategoryEnabled(
|
||||
Policy.PRIORITY_CATEGORY_SYSTEM));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean allowSystem = (Boolean) newValue;
|
||||
if (ZenModeSettingsBase.DEBUG) {
|
||||
Log.d(TAG, "onPrefChange allowSystem=" + allowSystem);
|
||||
}
|
||||
|
||||
mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_SYSTEM,
|
||||
allowSystem);
|
||||
mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_SYSTEM, allowSystem);
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user