Extract the not-strictly-modes-related parts of ZenModesBackend
So that when it's moved to SettingsLib, it doesn't need to carry that baggage. Bug: 346519570 Test: atest com.android.settings.notification.modes Flag: android.app.modes_ui Change-Id: I7911a521d96f5dbac2c2395171d324b7b54b8b07
This commit is contained in:
@@ -357,19 +357,6 @@ public class NotificationBackend {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of a user's packages that have at least one channel that will bypass DND
|
||||
*/
|
||||
public List<String> getPackagesBypassingDnd(int userId,
|
||||
boolean includeConversationChannels) {
|
||||
try {
|
||||
return sINM.getPackagesBypassingDnd(userId, includeConversationChannels);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateChannel(String pkg, int uid, NotificationChannel channel) {
|
||||
try {
|
||||
sINM.updateNotificationChannelForPackage(pkg, uid, channel);
|
||||
|
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.modes;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.INotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
import android.database.Cursor;
|
||||
import android.os.ServiceManager;
|
||||
import android.provider.ContactsContract;
|
||||
import android.service.notification.ConversationChannelWrapper;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class used for Settings-system_server interactions that are not <em>directly</em> related to
|
||||
* Mode management, but still used in the UI of its Settings pages (such as listing priority
|
||||
* conversations, contacts, etc).
|
||||
*/
|
||||
class ZenHelperBackend {
|
||||
|
||||
private static final String TAG = "ZenHelperBackend";
|
||||
|
||||
@Nullable // Until first usage
|
||||
private static ZenHelperBackend sInstance;
|
||||
|
||||
private final Context mContext;
|
||||
private final INotificationManager mInm;
|
||||
|
||||
static ZenHelperBackend getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ZenHelperBackend(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
ZenHelperBackend(Context context) {
|
||||
mContext = context;
|
||||
mInm = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of a user's packages that have at least one channel that will bypass DND
|
||||
*/
|
||||
List<String> getPackagesBypassingDnd(int userId,
|
||||
boolean includeConversationChannels) {
|
||||
try {
|
||||
return mInm.getPackagesBypassingDnd(userId, includeConversationChannels);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ParceledListSlice<ConversationChannelWrapper> getConversations(boolean onlyImportant) {
|
||||
try {
|
||||
return mInm.getConversations(onlyImportant);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
return ParceledListSlice.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
List<String> getStarredContacts() {
|
||||
try (Cursor cursor = queryStarredContactsData()) {
|
||||
return getStarredContacts(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
List<String> getStarredContacts(Cursor cursor) {
|
||||
List<String> starredContacts = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
String contact = cursor.getString(0);
|
||||
starredContacts.add(contact != null ? contact :
|
||||
mContext.getString(R.string.zen_mode_starred_contacts_empty_name));
|
||||
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
return starredContacts;
|
||||
}
|
||||
|
||||
private Cursor queryStarredContactsData() {
|
||||
return mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
|
||||
new String[]{ContactsContract.Contacts.DISPLAY_NAME_PRIMARY},
|
||||
ContactsContract.Data.STARRED + "=1", null,
|
||||
ContactsContract.Data.TIMES_CONTACTED);
|
||||
}
|
||||
|
||||
Cursor queryAllContactsData() {
|
||||
return mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
|
||||
new String[]{ContactsContract.Contacts.DISPLAY_NAME_PRIMARY},
|
||||
null, null, null);
|
||||
}
|
||||
}
|
@@ -29,7 +29,6 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -47,14 +46,16 @@ class ZenModeAppsLinkPreferenceController extends AbstractZenModePreferenceContr
|
||||
|
||||
private final ZenModeSummaryHelper mSummaryHelper;
|
||||
private ApplicationsState.Session mAppSession;
|
||||
private NotificationBackend mNotificationBackend = new NotificationBackend();
|
||||
private final ZenHelperBackend mHelperBackend;
|
||||
private ZenMode mZenMode;
|
||||
private Preference mPreference;
|
||||
|
||||
ZenModeAppsLinkPreferenceController(Context context, String key, Fragment host,
|
||||
ApplicationsState applicationsState, ZenModesBackend backend) {
|
||||
ApplicationsState applicationsState, ZenModesBackend backend,
|
||||
ZenHelperBackend helperBackend) {
|
||||
super(context, key, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(mContext, mBackend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(mContext, helperBackend);
|
||||
mHelperBackend = helperBackend;
|
||||
if (applicationsState != null && host != null) {
|
||||
mAppSession = applicationsState.newSession(mAppSessionCallbacks, host.getLifecycle());
|
||||
}
|
||||
@@ -105,7 +106,7 @@ class ZenModeAppsLinkPreferenceController extends AbstractZenModePreferenceContr
|
||||
pkgLabelMap.put(entry.info.packageName, entry.label);
|
||||
}
|
||||
}
|
||||
for (String pkg : mNotificationBackend.getPackagesBypassingDnd(mContext.getUserId(),
|
||||
for (String pkg : mHelperBackend.getPackagesBypassingDnd(mContext.getUserId(),
|
||||
/* includeConversationChannels= */ false)) {
|
||||
// Settings may hide some packages from the user, so if they're not present here
|
||||
// we skip displaying them, even if they bypass dnd.
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification.modes;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -34,7 +35,7 @@ public class ZenModeCallsFragment extends ZenModeFragmentBase {
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModePrioritySendersPreferenceController(context,
|
||||
"zen_mode_settings_category_calls", false, mBackend));
|
||||
"zen_mode_settings_category_calls", false, mBackend, mHelperBackend));
|
||||
controllers.add(new ZenModeRepeatCallersPreferenceController(context,
|
||||
"zen_mode_repeat_callers", mBackend,
|
||||
context.getResources().getInteger(com.android.internal.R.integer
|
||||
|
@@ -31,9 +31,9 @@ class ZenModeCallsLinkPreferenceController extends AbstractZenModePreferenceCont
|
||||
private final ZenModeSummaryHelper mSummaryHelper;
|
||||
|
||||
public ZenModeCallsLinkPreferenceController(Context context, String key,
|
||||
ZenModesBackend backend) {
|
||||
ZenModesBackend backend, ZenHelperBackend helperBackend) {
|
||||
super(context, key, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(context, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(context, helperBackend);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification.modes;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -34,7 +35,7 @@ public class ZenModeDisplayFragment extends ZenModeFragmentBase {
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
List<AbstractPreferenceController> prefControllers = new ArrayList<>();
|
||||
prefControllers.add(new ZenModeNotifVisLinkPreferenceController(
|
||||
context, "notification_visibility", mBackend));
|
||||
context, "notification_visibility", mBackend, mHelperBackend));
|
||||
prefControllers.add(new ZenModeDisplayEffectPreferenceController(
|
||||
context, "effect_greyscale", mBackend));
|
||||
prefControllers.add(new ZenModeDisplayEffectPreferenceController(
|
||||
|
@@ -31,9 +31,9 @@ class ZenModeDisplayLinkPreferenceController extends AbstractZenModePreferenceCo
|
||||
private final ZenModeSummaryHelper mSummaryHelper;
|
||||
|
||||
public ZenModeDisplayLinkPreferenceController(Context context, String key,
|
||||
ZenModesBackend backend) {
|
||||
ZenModesBackend backend, ZenHelperBackend helperBackend) {
|
||||
super(context, key, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(context, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(context, helperBackend);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -42,15 +42,15 @@ public class ZenModeFragment extends ZenModeFragmentBase {
|
||||
prefControllers.add(new ZenModeButtonPreferenceController(context, "activate", mBackend));
|
||||
prefControllers.add(new ZenModeActionsPreferenceController(context, "actions", mBackend));
|
||||
prefControllers.add(new ZenModePeopleLinkPreferenceController(
|
||||
context, "zen_mode_people", mBackend));
|
||||
context, "zen_mode_people", mBackend, mHelperBackend));
|
||||
prefControllers.add(new ZenModeAppsLinkPreferenceController(
|
||||
context, "zen_mode_apps", this,
|
||||
ApplicationsState.getInstance((Application) context.getApplicationContext()),
|
||||
mBackend));
|
||||
mBackend, mHelperBackend));
|
||||
prefControllers.add(new ZenModeOtherLinkPreferenceController(
|
||||
context, "zen_other_settings", mBackend));
|
||||
context, "zen_other_settings", mBackend, mHelperBackend));
|
||||
prefControllers.add(new ZenModeDisplayLinkPreferenceController(
|
||||
context, "mode_display_settings", mBackend));
|
||||
context, "mode_display_settings", mBackend, mHelperBackend));
|
||||
prefControllers.add(new ZenModeSetTriggerLinkPreferenceController(context,
|
||||
"zen_automatic_trigger_category", mBackend));
|
||||
return prefControllers;
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification.modes;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -34,7 +35,7 @@ public class ZenModeMessagesFragment extends ZenModeFragmentBase {
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModePrioritySendersPreferenceController(context,
|
||||
"zen_mode_settings_category_messages", true, mBackend));
|
||||
"zen_mode_settings_category_messages", true, mBackend, mHelperBackend));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -30,9 +30,9 @@ class ZenModeMessagesLinkPreferenceController extends AbstractZenModePreferenceC
|
||||
private final ZenModeSummaryHelper mSummaryHelper;
|
||||
|
||||
public ZenModeMessagesLinkPreferenceController(Context context, String key,
|
||||
ZenModesBackend backend) {
|
||||
ZenModesBackend backend, ZenHelperBackend helperBackend) {
|
||||
super(context, key, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(context, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(context, helperBackend);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -31,9 +31,9 @@ class ZenModeNotifVisLinkPreferenceController extends AbstractZenModePreferenceC
|
||||
private final ZenModeSummaryHelper mSummaryBuilder;
|
||||
|
||||
public ZenModeNotifVisLinkPreferenceController(Context context, String key,
|
||||
ZenModesBackend backend) {
|
||||
ZenModesBackend backend, ZenHelperBackend helperBackend) {
|
||||
super(context, key, backend);
|
||||
mSummaryBuilder = new ZenModeSummaryHelper(context, backend);
|
||||
mSummaryBuilder = new ZenModeSummaryHelper(context, helperBackend);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -34,9 +34,9 @@ class ZenModeOtherLinkPreferenceController extends AbstractZenModePreferenceCont
|
||||
private final ZenModeSummaryHelper mSummaryHelper;
|
||||
|
||||
public ZenModeOtherLinkPreferenceController(Context context, String key,
|
||||
ZenModesBackend backend) {
|
||||
ZenModesBackend backend, ZenHelperBackend helperBackend) {
|
||||
super(context, key, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(mContext, mBackend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(mContext, helperBackend);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification.modes;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -34,9 +35,9 @@ public class ZenModePeopleFragment extends ZenModeFragmentBase {
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
List<AbstractPreferenceController> prefControllers = new ArrayList<>();
|
||||
prefControllers.add(new ZenModeCallsLinkPreferenceController(
|
||||
context, "zen_mode_people_calls", mBackend));
|
||||
context, "zen_mode_people_calls", mBackend, mHelperBackend));
|
||||
prefControllers.add(new ZenModeMessagesLinkPreferenceController(
|
||||
context, "zen_mode_people_messages", mBackend));
|
||||
context, "zen_mode_people_messages", mBackend, mHelperBackend));
|
||||
return prefControllers;
|
||||
}
|
||||
|
||||
|
@@ -34,9 +34,9 @@ class ZenModePeopleLinkPreferenceController extends AbstractZenModePreferenceCon
|
||||
private final ZenModeSummaryHelper mSummaryHelper;
|
||||
|
||||
public ZenModePeopleLinkPreferenceController(Context context, String key,
|
||||
ZenModesBackend backend) {
|
||||
ZenModesBackend backend, ZenHelperBackend helperBackend) {
|
||||
super(context, key, backend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(mContext, mBackend);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(mContext, helperBackend);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -83,6 +83,7 @@ class ZenModePrioritySendersPreferenceController
|
||||
private static final Intent FALLBACK_INTENT = new Intent(Intent.ACTION_MAIN)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
|
||||
private final ZenHelperBackend mHelperBackend;
|
||||
private final PackageManager mPackageManager;
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
private List<SelectorWithWidgetPreference> mSelectorPreferences = new ArrayList<>();
|
||||
@@ -90,9 +91,10 @@ class ZenModePrioritySendersPreferenceController
|
||||
private final ZenModeSummaryHelper mZenModeSummaryHelper;
|
||||
|
||||
public ZenModePrioritySendersPreferenceController(Context context, String key,
|
||||
boolean isMessages, ZenModesBackend backend) {
|
||||
boolean isMessages, ZenModesBackend backend, ZenHelperBackend helperBackend) {
|
||||
super(context, key, backend);
|
||||
mIsMessages = isMessages;
|
||||
mHelperBackend = helperBackend;
|
||||
|
||||
String contactsPackage = context.getString(R.string.config_contacts_package_name);
|
||||
ALL_CONTACTS_INTENT.setPackage(contactsPackage);
|
||||
@@ -103,7 +105,7 @@ class ZenModePrioritySendersPreferenceController
|
||||
if (!FALLBACK_INTENT.hasCategory(Intent.CATEGORY_APP_CONTACTS)) {
|
||||
FALLBACK_INTENT.addCategory(Intent.CATEGORY_APP_CONTACTS);
|
||||
}
|
||||
mZenModeSummaryHelper = new ZenModeSummaryHelper(mContext, mBackend);
|
||||
mZenModeSummaryHelper = new ZenModeSummaryHelper(mContext, mHelperBackend);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,7 +166,7 @@ class ZenModePrioritySendersPreferenceController
|
||||
|
||||
private void updateChannelCounts() {
|
||||
ParceledListSlice<ConversationChannelWrapper> impConversations =
|
||||
mBackend.getConversations(true);
|
||||
mHelperBackend.getConversations(true);
|
||||
int numImportantConversations = 0;
|
||||
if (impConversations != null) {
|
||||
for (ConversationChannelWrapper conversation : impConversations.getList()) {
|
||||
|
@@ -60,9 +60,9 @@ import java.util.function.Predicate;
|
||||
class ZenModeSummaryHelper {
|
||||
|
||||
private final Context mContext;
|
||||
private final ZenModesBackend mBackend;
|
||||
private final ZenHelperBackend mBackend;
|
||||
|
||||
public ZenModeSummaryHelper(Context context, ZenModesBackend backend) {
|
||||
ZenModeSummaryHelper(Context context, ZenHelperBackend backend) {
|
||||
mContext = context;
|
||||
mBackend = backend;
|
||||
}
|
||||
|
@@ -19,24 +19,15 @@ package com.android.settings.notification.modes;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.INotificationManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.ServiceManager;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.Condition;
|
||||
import android.service.notification.ConversationChannelWrapper;
|
||||
import android.service.notification.SystemZenRules;
|
||||
import android.service.notification.ZenAdapters;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -58,8 +49,6 @@ class ZenModesBackend {
|
||||
private static ZenModesBackend sInstance;
|
||||
|
||||
private final NotificationManager mNotificationManager;
|
||||
static INotificationManager sINM = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
@@ -113,54 +102,6 @@ class ZenModesBackend {
|
||||
}
|
||||
}
|
||||
|
||||
public ParceledListSlice<ConversationChannelWrapper> getConversations(boolean onlyImportant) {
|
||||
try {
|
||||
return sINM.getConversations(onlyImportant);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
return ParceledListSlice.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getStarredContacts() {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = queryStarredContactsData();
|
||||
return getStarredContacts(cursor);
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
List<String> getStarredContacts(Cursor cursor) {
|
||||
List<String> starredContacts = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
String contact = cursor.getString(0);
|
||||
starredContacts.add(contact != null ? contact :
|
||||
mContext.getString(R.string.zen_mode_starred_contacts_empty_name));
|
||||
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
return starredContacts;
|
||||
}
|
||||
|
||||
private Cursor queryStarredContactsData() {
|
||||
return mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
|
||||
new String[]{ContactsContract.Contacts.DISPLAY_NAME_PRIMARY},
|
||||
ContactsContract.Data.STARRED + "=1", null,
|
||||
ContactsContract.Data.TIMES_CONTACTED);
|
||||
}
|
||||
|
||||
Cursor queryAllContactsData() {
|
||||
return mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
|
||||
new String[]{ContactsContract.Contacts.DISPLAY_NAME_PRIMARY},
|
||||
null, null, null);
|
||||
}
|
||||
|
||||
private ZenMode getManualDndMode(ZenModeConfig config) {
|
||||
ZenModeConfig.ZenRule manualRule = config.manualRule;
|
||||
// TODO: b/333682392 - Replace with final strings for name & trigger description
|
||||
|
@@ -41,6 +41,7 @@ abstract class ZenModesFragmentBase extends RestrictedDashboardFragment {
|
||||
protected Context mContext;
|
||||
|
||||
protected ZenModesBackend mBackend;
|
||||
protected ZenHelperBackend mHelperBackend;
|
||||
|
||||
// Individual pages must implement this method based on what they should do when
|
||||
// the device's zen mode state changes.
|
||||
@@ -59,6 +60,7 @@ abstract class ZenModesFragmentBase extends RestrictedDashboardFragment {
|
||||
public void onAttach(@NonNull Context context) {
|
||||
mContext = context;
|
||||
mBackend = ZenModesBackend.getInstance(context);
|
||||
mHelperBackend = ZenHelperBackend.getInstance(context);
|
||||
super.onAttach(context);
|
||||
mSettingsObserver.register();
|
||||
}
|
||||
|
@@ -43,7 +43,6 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
@@ -57,7 +56,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -73,7 +71,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
private ZenModesBackend mZenModesBackend;
|
||||
|
||||
@Mock
|
||||
private NotificationBackend mNotificationBackend;
|
||||
private ZenHelperBackend mHelperBackend;
|
||||
|
||||
@Mock
|
||||
private ApplicationsState mApplicationsState;
|
||||
@@ -90,8 +88,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
when(mApplicationsState.newSession(any(), any())).thenReturn(mSession);
|
||||
mController = new ZenModeAppsLinkPreferenceController(
|
||||
mContext, "controller_key", mock(Fragment.class), mApplicationsState,
|
||||
mZenModesBackend);
|
||||
ReflectionHelpers.setField(mController, "mNotificationBackend", mNotificationBackend);
|
||||
mZenModesBackend, mHelperBackend);
|
||||
}
|
||||
|
||||
private ApplicationsState.AppEntry createAppEntry(String packageName, String label) {
|
||||
@@ -149,7 +146,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
ApplicationsState.AppEntry entryConv = createAppEntry("test_conv", "test_convLabel");
|
||||
List<ApplicationsState.AppEntry> appEntries = List.of(entry, entryConv);
|
||||
|
||||
when(mNotificationBackend.getPackagesBypassingDnd(mContext.getUserId(),
|
||||
when(mHelperBackend.getPackagesBypassingDnd(mContext.getUserId(),
|
||||
false)).thenReturn(List.of("test"));
|
||||
|
||||
assertThat(mController.getAppsBypassingDnd(appEntries)).containsExactly("testLabel");
|
||||
@@ -167,7 +164,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
new ArrayList<ApplicationsState.AppEntry>();
|
||||
appEntries.add(createAppEntry("test", "pkgLabel"));
|
||||
|
||||
when(mNotificationBackend.getPackagesBypassingDnd(
|
||||
when(mHelperBackend.getPackagesBypassingDnd(
|
||||
mContext.getUserId(), false))
|
||||
.thenReturn(List.of("test"));
|
||||
|
||||
|
@@ -17,7 +17,7 @@
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -29,7 +29,9 @@ import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -38,8 +40,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class ZenModeCallsLinkPreferenceControllerTest {
|
||||
@@ -49,10 +49,9 @@ public final class ZenModeCallsLinkPreferenceControllerTest {
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
@Mock private ZenModesBackend mBackend;
|
||||
@Mock private ZenHelperBackend mHelperBackend;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -61,7 +60,7 @@ public final class ZenModeCallsLinkPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeCallsLinkPreferenceController(
|
||||
mContext, "something", mBackend);
|
||||
mContext, "something", mBackend, mHelperBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -28,7 +29,9 @@ import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -47,8 +50,8 @@ public final class ZenModeDisplayLinkPreferenceControllerTest {
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
@Mock private ZenModesBackend mBackend;
|
||||
@Mock private ZenHelperBackend mHelperBackend;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -57,7 +60,7 @@ public final class ZenModeDisplayLinkPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeDisplayLinkPreferenceController(
|
||||
mContext, "something", mBackend);
|
||||
mContext, "something", mBackend, mHelperBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -17,7 +17,7 @@
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -29,7 +29,9 @@ import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -48,8 +50,8 @@ public final class ZenModeMessagesLinkPreferenceControllerTest {
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
@Mock private ZenModesBackend mBackend;
|
||||
@Mock private ZenHelperBackend mHelperBackend;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -58,7 +60,7 @@ public final class ZenModeMessagesLinkPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeMessagesLinkPreferenceController(
|
||||
mContext, "something", mBackend);
|
||||
mContext, "something", mBackend, mHelperBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -28,7 +29,9 @@ import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -47,8 +50,8 @@ public final class ZenModeNotifVisLinkPreferenceControllerTest {
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
@Mock private ZenModesBackend mBackend;
|
||||
@Mock private ZenHelperBackend mHelperBackend;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -57,7 +60,7 @@ public final class ZenModeNotifVisLinkPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeNotifVisLinkPreferenceController(
|
||||
mContext, "something", mBackend);
|
||||
mContext, "something", mBackend, mHelperBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -28,7 +29,9 @@ import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -48,8 +51,8 @@ public final class ZenModeOtherLinkPreferenceControllerTest {
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
@Mock private ZenModesBackend mBackend;
|
||||
@Mock private ZenHelperBackend mHelperBackend;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -58,7 +61,7 @@ public final class ZenModeOtherLinkPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeOtherLinkPreferenceController(
|
||||
mContext, "something", mBackend);
|
||||
mContext, "something", mBackend, mHelperBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -19,7 +19,9 @@ package com.android.settings.notification.modes;
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static android.service.notification.ZenPolicy.STATE_ALLOW;
|
||||
import static android.service.notification.ZenPolicy.STATE_UNSET;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -30,7 +32,9 @@ import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -29,7 +29,9 @@ import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -50,6 +52,8 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
@Mock
|
||||
private ZenHelperBackend mHelperBackend;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -58,7 +62,7 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModePeopleLinkPreferenceController(
|
||||
mContext, "something", mBackend);
|
||||
mContext, "something", mBackend, mHelperBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -77,8 +77,8 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
@Mock private ZenModesBackend mBackend;
|
||||
@Mock private ZenHelperBackend mHelperBackend;
|
||||
|
||||
private PreferenceCategory mMessagesPrefCategory, mCallsPrefCategory;
|
||||
|
||||
@@ -90,10 +90,11 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mMessagesController = new ZenModePrioritySendersPreferenceController(
|
||||
mContext, "messages", true, mBackend);
|
||||
mCallsController = new ZenModePrioritySendersPreferenceController(
|
||||
mContext, "calls", false, mBackend);
|
||||
mMessagesController = new ZenModePrioritySendersPreferenceController(mContext, "messages",
|
||||
true, mBackend, mHelperBackend);
|
||||
mCallsController = new ZenModePrioritySendersPreferenceController(mContext, "calls", false,
|
||||
mBackend, mHelperBackend);
|
||||
|
||||
mMessagesPrefCategory = new PreferenceCategory(mContext);
|
||||
mMessagesPrefCategory.setKey(mMessagesController.getPreferenceKey());
|
||||
mCallsPrefCategory = new PreferenceCategory(mContext);
|
||||
@@ -106,7 +107,7 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
||||
|
||||
Cursor cursor = mock(Cursor.class);
|
||||
when(cursor.getCount()).thenReturn(1);
|
||||
when(mBackend.queryAllContactsData()).thenReturn(cursor);
|
||||
when(mHelperBackend.queryAllContactsData()).thenReturn(cursor);
|
||||
}
|
||||
|
||||
// Makes a preference with the provided key and whether it's a checkbox with
|
||||
|
@@ -44,7 +44,7 @@ import java.util.Set;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ZenModesSummaryHelperTest {
|
||||
private Context mContext;
|
||||
private ZenModesBackend mBackend;
|
||||
private ZenHelperBackend mBackend;
|
||||
|
||||
private ZenModeSummaryHelper mSummaryHelper;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ZenModesSummaryHelperTest {
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mBackend = new ZenModesBackend(mContext);
|
||||
mBackend = new ZenHelperBackend(mContext);
|
||||
mSummaryHelper = new ZenModeSummaryHelper(mContext, mBackend);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user