Merge "Updates main page for Do Not Disturb" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4d4c55ad72
@@ -1,19 +1,53 @@
|
||||
package com.android.settings.notification.zen;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.NotificationChannel;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.core.text.BidiFormatter;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class ZenModeBypassingAppsPreferenceController extends AbstractZenModePreferenceController {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controls the summary for preference found at:
|
||||
* Settings > Sound > Do Not Disturb > Apps
|
||||
*/
|
||||
public class ZenModeBypassingAppsPreferenceController extends AbstractZenModePreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
protected static final String KEY = "zen_mode_behavior_apps";
|
||||
|
||||
@VisibleForTesting protected Preference mPreference;
|
||||
private ApplicationsState.Session mAppSession;
|
||||
private NotificationBackend mNotificationBackend = new NotificationBackend();
|
||||
|
||||
public ZenModeBypassingAppsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
private String mSummary;
|
||||
|
||||
public ZenModeBypassingAppsPreferenceController(Context context, Application app,
|
||||
Fragment host, Lifecycle lifecycle) {
|
||||
this(context, app == null ? null : ApplicationsState.getInstance(app), host, lifecycle);
|
||||
}
|
||||
|
||||
private ZenModeBypassingAppsPreferenceController(Context context, ApplicationsState appState,
|
||||
Fragment host, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
if (appState != null && host != null) {
|
||||
mAppSession = appState.newSession(mAppSessionCallbacks, host.getLifecycle());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,13 +56,125 @@ public class ZenModeBypassingAppsPreferenceController extends AbstractZenModePre
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary() {
|
||||
final int channelsBypassing =
|
||||
mNotificationBackend.getNumAppsBypassingDnd(UserHandle.getCallingUserId());
|
||||
if (channelsBypassing == 0) {
|
||||
return mContext.getResources().getString(R.string.zen_mode_bypassing_apps_subtext_none);
|
||||
}
|
||||
return mContext.getResources().getQuantityString(R.plurals.zen_mode_bypassing_apps_subtext,
|
||||
channelsBypassing, channelsBypassing);
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
mPreference = screen.findPreference(KEY);
|
||||
updateAppsBypassingDndSummaryText();
|
||||
super.displayPreference(screen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary() {
|
||||
return mSummary;
|
||||
}
|
||||
|
||||
private void updateAppsBypassingDndSummaryText() {
|
||||
if (mAppSession == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationsState.AppFilter filter = ApplicationsState.FILTER_ALL_ENABLED;
|
||||
List<ApplicationsState.AppEntry> apps = mAppSession.rebuild(filter,
|
||||
ApplicationsState.ALPHA_COMPARATOR);
|
||||
updateAppsBypassingDndSummaryText(apps);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateAppsBypassingDndSummaryText(List<ApplicationsState.AppEntry> apps) {
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
// users cannot change their DND settings when an app puts the device total
|
||||
// silence or alarms only (both deprecated) modes
|
||||
mPreference.setEnabled(false);
|
||||
mSummary = mContext.getResources().getString(
|
||||
R.string.zen_mode_bypassing_apps_subtext_none);
|
||||
return;
|
||||
default:
|
||||
mPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
if (apps == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> appsBypassingDnd = new ArrayList<>();
|
||||
for (ApplicationsState.AppEntry entry : apps) {
|
||||
String pkg = entry.info.packageName;
|
||||
for (NotificationChannel channel : mNotificationBackend
|
||||
.getNotificationChannelsBypassingDnd(pkg, entry.info.uid).getList()) {
|
||||
if (!TextUtils.isEmpty(channel.getConversationId())) {
|
||||
// conversation channels that bypass dnd will be shown on the People page
|
||||
continue;
|
||||
}
|
||||
appsBypassingDnd.add(BidiFormatter.getInstance().unicodeWrap(entry.label));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (appsBypassingDnd.size() == 0) {
|
||||
mSummary = mContext.getResources().getString(
|
||||
R.string.zen_mode_bypassing_apps_subtext_none);
|
||||
refreshSummary(mPreference);
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> displayAppsBypassing = new ArrayList<>();
|
||||
if (appsBypassingDnd.size() <= 2) {
|
||||
displayAppsBypassing = appsBypassingDnd;
|
||||
} else {
|
||||
displayAppsBypassing.add(appsBypassingDnd.get(0));
|
||||
displayAppsBypassing.add(appsBypassingDnd.get(1));
|
||||
displayAppsBypassing.add(mContext.getResources().getString(
|
||||
R.string.zen_mode_apps_bypassing_list_count,
|
||||
appsBypassingDnd.size() - 2));
|
||||
}
|
||||
mSummary = mContext.getResources().getQuantityString(
|
||||
R.plurals.zen_mode_bypassing_apps_subtext,
|
||||
appsBypassingDnd.size(),
|
||||
ListFormatter.getInstance().format(displayAppsBypassing));
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
|
||||
private final ApplicationsState.Callbacks mAppSessionCallbacks =
|
||||
new ApplicationsState.Callbacks() {
|
||||
|
||||
@Override
|
||||
public void onRunningStateChanged(boolean running) {
|
||||
updateAppsBypassingDndSummaryText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageListChanged() {
|
||||
updateAppsBypassingDndSummaryText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRebuildComplete(ArrayList<ApplicationsState.AppEntry> apps) {
|
||||
updateAppsBypassingDndSummaryText(apps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageIconChanged() { }
|
||||
|
||||
@Override
|
||||
public void onPackageSizeChanged(String packageName) {
|
||||
updateAppsBypassingDndSummaryText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAllSizesComputed() { }
|
||||
|
||||
@Override
|
||||
public void onLauncherInfoChanged() { }
|
||||
|
||||
@Override
|
||||
public void onLoadEntriesCompleted() {
|
||||
updateAppsBypassingDndSummaryText();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -16,25 +16,33 @@
|
||||
|
||||
package com.android.settings.notification.zen;
|
||||
|
||||
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE;
|
||||
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_NONE;
|
||||
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS;
|
||||
import static android.app.NotificationManager.Policy.PRIORITY_SENDERS_ANY;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
/**
|
||||
* Controls the summary for preference found at:
|
||||
* Settings > Sound > Do Not Disturb > People
|
||||
*/
|
||||
public class ZenModePeoplePreferenceController extends
|
||||
AbstractZenModePreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
private final String KEY;
|
||||
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModePeoplePreferenceController(Context context, Lifecycle lifecycle, String key) {
|
||||
super(context, key, lifecycle);
|
||||
KEY = key;
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,8 +68,28 @@ public class ZenModePeoplePreferenceController extends
|
||||
break;
|
||||
default:
|
||||
preference.setEnabled(true);
|
||||
// TODO: How do all of the people options roll up into the summary?
|
||||
//preference.setSummary(mSummaryBuilder.getMessagesSettingSummary(getPolicy()));
|
||||
preference.setSummary(getPeopleSummary());
|
||||
}
|
||||
}
|
||||
|
||||
private String getPeopleSummary() {
|
||||
final int callersAllowed = mBackend.getPriorityCallSenders();
|
||||
final int messagesAllowed = mBackend.getPriorityMessageSenders();
|
||||
final int conversationsAllowed = mBackend.getPriorityConversationSenders();
|
||||
final boolean areRepeatCallersAllowed =
|
||||
mBackend.isPriorityCategoryEnabled(PRIORITY_CATEGORY_REPEAT_CALLERS);
|
||||
|
||||
if (callersAllowed == PRIORITY_SENDERS_ANY
|
||||
&& messagesAllowed == PRIORITY_SENDERS_ANY
|
||||
&& conversationsAllowed == CONVERSATION_SENDERS_ANYONE) {
|
||||
return mContext.getResources().getString(R.string.zen_mode_people_all);
|
||||
} else if (callersAllowed == ZenModeBackend.SOURCE_NONE
|
||||
&& messagesAllowed == ZenModeBackend.SOURCE_NONE
|
||||
&& conversationsAllowed == CONVERSATION_SENDERS_NONE
|
||||
&& !areRepeatCallersAllowed) {
|
||||
return mContext.getResources().getString(R.string.zen_mode_people_none);
|
||||
} else {
|
||||
return mContext.getResources().getString(R.string.zen_mode_people_some);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,15 +25,19 @@ import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS
|
||||
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS;
|
||||
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.NotificationManager.Policy;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -67,7 +71,9 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, getSettingsLifecycle(), getFragmentManager());
|
||||
final Activity activity = getActivity();
|
||||
return buildPreferenceControllers(context, getSettingsLifecycle(), getFragmentManager(),
|
||||
activity != null ? activity.getApplication() : null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,15 +82,19 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle, FragmentManager fragmentManager) {
|
||||
Lifecycle lifecycle, FragmentManager fragmentManager, Application app,
|
||||
Fragment fragment) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager));
|
||||
controllers.add(new ZenModePeoplePreferenceController(context, lifecycle,
|
||||
"zen_mode_behavior_people"));
|
||||
controllers.add(new ZenModeBypassingAppsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBypassingAppsPreferenceController(context, app,
|
||||
fragment, lifecycle));
|
||||
controllers.add(new ZenModeSoundVibrationPreferenceController(context, lifecycle,
|
||||
"zen_sound_vibration_settings"));
|
||||
controllers.add(new ZenModeAutomationPreferenceController(context));
|
||||
controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager));
|
||||
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle,
|
||||
fragmentManager));
|
||||
return controllers;
|
||||
@@ -110,29 +120,34 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
PRIORITY_CATEGORY_REPEAT_CALLERS,
|
||||
};
|
||||
|
||||
String getSoundSettingSummary(Policy policy) {
|
||||
List<String> enabledCategories = getEnabledCategories(policy,
|
||||
String getOtherSoundCategoriesSummary(Policy policy) {
|
||||
List<String> enabledCategories = getEnabledCategories(
|
||||
policy,
|
||||
category -> PRIORITY_CATEGORY_ALARMS == category
|
||||
|| PRIORITY_CATEGORY_MEDIA == category
|
||||
|| PRIORITY_CATEGORY_SYSTEM == category, false);
|
||||
|| PRIORITY_CATEGORY_SYSTEM == category
|
||||
|| PRIORITY_CATEGORY_REMINDERS == category
|
||||
|| PRIORITY_CATEGORY_EVENTS == category,
|
||||
true);
|
||||
int numCategories = enabledCategories.size();
|
||||
if (numCategories == 0) {
|
||||
return mContext.getString(R.string.zen_sound_all_muted);
|
||||
} else if (numCategories == 1) {
|
||||
return mContext.getString(R.string.zen_sound_one_allowed,
|
||||
enabledCategories.get(0));
|
||||
} else if (numCategories == 2) {
|
||||
return mContext.getString(R.string.zen_sound_two_allowed,
|
||||
enabledCategories.get(0),
|
||||
enabledCategories.get(1));
|
||||
} else if (numCategories == 3) {
|
||||
return mContext.getString(R.string.zen_sound_three_allowed,
|
||||
enabledCategories.get(0),
|
||||
enabledCategories.get(1),
|
||||
enabledCategories.get(2));
|
||||
} else {
|
||||
return mContext.getString(R.string.zen_sound_none_muted);
|
||||
return mContext.getResources().getString(R.string.zen_mode_other_sounds_none);
|
||||
}
|
||||
|
||||
List<String> displayCategories = new ArrayList<>();
|
||||
if (numCategories <= 2) {
|
||||
displayCategories = enabledCategories;
|
||||
} else {
|
||||
displayCategories.add(enabledCategories.get(0));
|
||||
displayCategories.add(enabledCategories.get(1));
|
||||
displayCategories.add(mContext.getString(R.string.zen_mode_other_sounds_list_count,
|
||||
numCategories - 2));
|
||||
}
|
||||
|
||||
return mContext.getResources().getQuantityString(
|
||||
R.plurals.zen_mode_other_sounds_summary,
|
||||
numCategories /* quantity */,
|
||||
ListFormatter.getInstance().format(displayCategories));
|
||||
}
|
||||
|
||||
String getCallsSettingSummary(Policy policy) {
|
||||
@@ -322,7 +337,8 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(Context
|
||||
context) {
|
||||
return buildPreferenceControllers(context, null, null);
|
||||
return buildPreferenceControllers(context, null, null,
|
||||
null, null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.zen;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
/**
|
||||
* Controls the summary for preference found at:
|
||||
* Settings > Sound > Do Not Disturb > Alarms & other interruptions
|
||||
*/
|
||||
public class ZenModeSoundVibrationPreferenceController extends
|
||||
AbstractZenModePreferenceController implements PreferenceControllerMixin {
|
||||
private final String mKey;
|
||||
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModeSoundVibrationPreferenceController(Context context, Lifecycle lifecycle,
|
||||
String key) {
|
||||
super(context, key, lifecycle);
|
||||
mKey = key;
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return mKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
preference.setEnabled(false);
|
||||
preference.setSummary(mContext.getString(R.string.zen_mode_other_sounds_none));
|
||||
break;
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
preference.setEnabled(false);
|
||||
preference.setSummary(mContext.getString(R.string.zen_mode_behavior_alarms_only));
|
||||
break;
|
||||
default:
|
||||
preference.setEnabled(true);
|
||||
preference.setSummary(mSummaryBuilder.getOtherSoundCategoriesSummary(getPolicy()));
|
||||
}
|
||||
}
|
||||
}
|
@@ -21,14 +21,17 @@ import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Settings > Sound > Do Not Disturb > Alarms & Other Interruptions
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implements Indexable {
|
||||
|
||||
@@ -40,10 +43,6 @@ public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implement
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle,
|
||||
"zen_mode_calls_settings"));
|
||||
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle,
|
||||
"zen_mode_messages_settings"));
|
||||
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle,
|
||||
"zen_mode_alarms"));
|
||||
controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
|
||||
@@ -52,7 +51,6 @@ public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implement
|
||||
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
|
||||
R.string.zen_sound_footer));
|
||||
controllers.add(new ZenModeBypassingAppsPreferenceController(context, lifecycle));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user