Show new visual effects options in dnd settings

Bug: 74075050
Test: make -j20 RunSettingsRoboTests
Change-Id: Ia629007d1c80b657aaf756d0f6d2edfd89a7f6b4
This commit is contained in:
Julia Reynolds
2018-03-02 15:51:14 -05:00
parent 9a9b8cad39
commit d640a97ce8
18 changed files with 601 additions and 336 deletions

View File

@@ -100,6 +100,7 @@ public class Settings extends SettingsActivity {
public static class PrintJobSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeBehaviorSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeBlockedEffectsSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeAutomationSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ }

View File

@@ -88,6 +88,10 @@ public class ZenModeBackend {
return mZenMode;
}
protected boolean isVisualEffectSuppressed(int visualEffect) {
return (mPolicy.suppressedVisualEffects & visualEffect) != 0;
}
protected boolean isPriorityCategoryEnabled(int categoryType) {
return (mPolicy.priorityCategories & categoryType) != 0;
}
@@ -117,8 +121,8 @@ public class ZenModeBackend {
return SOURCE_NONE;
}
protected void saveVisualEffectsPolicy(int category, boolean canBypass) {
int suppressedEffects = getNewSuppressedEffects(!canBypass, category);
protected void saveVisualEffectsPolicy(int category, boolean suppress) {
int suppressedEffects = getNewSuppressedEffects(suppress, category);
savePolicy(mPolicy.priorityCategories, mPolicy.priorityCallSenders,
mPolicy.priorityMessageSenders, suppressedEffects);
}

View File

@@ -49,8 +49,6 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
context.getResources().getInteger(com.android.internal.R.integer
.config_zen_repeat_callers_threshold)));
controllers.add(new ZenModeScreenOnPreferenceController(context, lifecycle));
controllers.add(new ZenModeScreenOffPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
return controllers;
}
@@ -85,15 +83,6 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
keys.add(ZenModeAlarmsPreferenceController.KEY);
keys.add(ZenModeMediaPreferenceController.KEY);
keys.add(ZenModeEventsPreferenceController.KEY);
keys.add(ZenModeRemindersPreferenceController.KEY);
keys.add(ZenModeMessagesPreferenceController.KEY);
keys.add(ZenModeCallsPreferenceController.KEY);
keys.add(ZenModeRepeatCallersPreferenceController.KEY);
keys.add(ZenModeScreenOnPreferenceController.KEY);
keys.add(ZenModeScreenOffPreferenceController.KEY);
return keys;
}

View File

@@ -0,0 +1,51 @@
/*
* 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.content.Context;
import android.support.v7.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBlockedEffectsPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
protected static final String KEY = "zen_mode_block_effects_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
public ZenModeBlockedEffectsPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public CharSequence getSummary() {
return mSummaryBuilder.getBlockedEffectsSummary(getPolicy());
}
}

View File

@@ -0,0 +1,123 @@
/*
* 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 static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
import android.content.Context;
import android.provider.SearchIndexableResource;
import android.support.v7.preference.CheckBoxPreference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.List;
public class ZenModeBlockedEffectsSettings extends ZenModeSettingsBase implements Indexable {
@Override
public void onResume() {
super.onResume();
CheckBoxPreference soundPreference =
(CheckBoxPreference) getPreferenceScreen().findPreference("zen_effect_sound");
if (soundPreference != null) {
soundPreference.setChecked(true);
}
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
"zen_effect_intent", SUPPRESSED_EFFECT_FULL_SCREEN_INTENT,
MetricsEvent.ACTION_ZEN_BLOCK_FULL_SCREEN_INTENTS, null));
controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
"zen_effect_light", SUPPRESSED_EFFECT_LIGHTS,
MetricsEvent.ACTION_ZEN_BLOCK_LIGHT, null));
controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
"zen_effect_peek", SUPPRESSED_EFFECT_PEEK,
MetricsEvent.ACTION_ZEN_BLOCK_PEEK, null));
controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
"zen_effect_status", SUPPRESSED_EFFECT_STATUS_BAR,
MetricsEvent.ACTION_ZEN_BLOCK_STATUS,
new int[] {SUPPRESSED_EFFECT_NOTIFICATION_LIST}));
controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
"zen_effect_badge", SUPPRESSED_EFFECT_BADGE,
MetricsEvent.ACTION_ZEN_BLOCK_BADGE, null));
controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
"zen_effect_ambient", SUPPRESSED_EFFECT_AMBIENT,
MetricsEvent.ACTION_ZEN_BLOCK_AMBIENT, null));
controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
"zen_effect_list", SUPPRESSED_EFFECT_NOTIFICATION_LIST,
MetricsEvent.ACTION_ZEN_BLOCK_NOTIFICATION_LIST, null));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_block_settings;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.ZEN_WHAT_TO_BLOCK;
}
/**
* For Search.
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.zen_mode_block_settings;
result.add(sir);
return result;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
return keys;
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, null);
}
};
}

View File

@@ -1,66 +0,0 @@
/*
* Copyright (C) 2017 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.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 ZenModeScreenOffPreferenceController extends
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_screen_off";
public ZenModeScreenOffPreferenceController(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;
pref.setChecked(mBackend.isEffectAllowed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF));
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean bypass = (Boolean) newValue;
if (ZenModeSettingsBase.DEBUG) {
Log.d(TAG, "onPrefChange allowWhenScreenOff=" + bypass);
}
mMetricsFeatureProvider.action(mContext,
MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_OFF, bypass);
mBackend.saveVisualEffectsPolicy(Policy.SUPPRESSED_EFFECT_SCREEN_OFF, bypass);
return true;
}
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright (C) 2017 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.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 ZenModeScreenOnPreferenceController extends
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_screen_on";
public ZenModeScreenOnPreferenceController(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;
pref.setChecked(mBackend.isEffectAllowed(Policy.SUPPRESSED_EFFECT_SCREEN_ON));
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean bypass = (Boolean) newValue;
if (ZenModeSettingsBase.DEBUG) Log.d(TAG, "onPrefChange allowWhenScreenOn="
+ bypass);
mMetricsFeatureProvider.action(mContext,
MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_ON, bypass);
mBackend.saveVisualEffectsPolicy(Policy.SUPPRESSED_EFFECT_SCREEN_ON, bypass);
return true;
}
}

View File

@@ -63,6 +63,7 @@ public class ZenModeSettings extends ZenModeSettingsBase {
Lifecycle lifecycle, FragmentManager fragmentManager) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle));
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
controllers.add(new ZenModeAutomationPreferenceController(context));
controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager));
controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle));
@@ -137,6 +138,18 @@ public class ZenModeSettings extends ZenModeSettingsBase {
}
}
String getBlockedEffectsSummary(Policy policy) {
if (policy.suppressedVisualEffects == 0) {
return mContext.getResources().getString(
R.string.zen_mode_block_effect_summary_sound);
} else if (Policy.areAllVisualEffectsSuppressed(policy.suppressedVisualEffects)) {
return mContext.getResources().getString(
R.string.zen_mode_block_effect_summary_all);
}
return mContext.getResources().getString(
R.string.zen_mode_block_effect_summary_some);
}
String getAutomaticRulesSummary() {
final int count = getEnabledAutomaticRulesCount();
return count == 0 ? mContext.getString(R.string.zen_mode_settings_summary_off)

View File

@@ -0,0 +1,91 @@
/*
* 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.content.Context;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeVisEffectPreferenceController
extends AbstractZenModePreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
protected final String mKey;
protected final int mEffect;
protected final int mMetricsCategory;
// if any of these effects are suppressed, this effect must be too
protected final int[] mParentSuppressedEffects;
private PreferenceScreen mScreen;
public ZenModeVisEffectPreferenceController(Context context, Lifecycle lifecycle, String key,
int visualEffect, int metricsCategory, int[] parentSuppressedEffects) {
super(context, key, lifecycle);
mKey = key;
mEffect = visualEffect;
mMetricsCategory = metricsCategory;
mParentSuppressedEffects = parentSuppressedEffects;
}
@Override
public String getPreferenceKey() {
return mKey;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void displayPreference(PreferenceScreen screen) {
mScreen = screen;
super.displayPreference(screen);
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
boolean suppressed = mBackend.isVisualEffectSuppressed(mEffect);
boolean parentSuppressed = false;
if (mParentSuppressedEffects != null) {
for (int parentEffect : mParentSuppressedEffects) {
parentSuppressed |= mBackend.isVisualEffectSuppressed(parentEffect);
}
}
if (parentSuppressed) {
((CheckBoxPreference) preference).setChecked(parentSuppressed);
onPreferenceChange(preference, parentSuppressed);
preference.setEnabled(false);
} else {
preference.setEnabled(true);
((CheckBoxPreference) preference).setChecked(suppressed);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean suppressEffect = (Boolean) newValue;
mMetricsFeatureProvider.action(mContext, mMetricsCategory, suppressEffect);
mBackend.saveVisualEffectsPolicy(mEffect, suppressEffect);
return true;
}
}

View File

@@ -74,6 +74,7 @@ import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
import com.android.settings.notification.ZenModeBehaviorSettings;
import com.android.settings.notification.ZenModeBlockedEffectsSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.security.EncryptionAndCredential;
@@ -175,6 +176,7 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources {
addIndex(UsbDetailsFragment.class);
addIndex(WifiDisplaySettings.class);
addIndex(ZenModeBehaviorSettings.class);
addIndex(ZenModeBlockedEffectsSettings.class);
addIndex(ZenModeAutomationSettings.class);
addIndex(NightDisplaySettings.class);
addIndex(SmartBatterySettings.class);