Merge "Check for available rotation resolver service and camera permission before showing setting for face based auto-rotation" into sc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3bd4815..cfda9b7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -517,12 +517,12 @@
<activity android:name=".network.telephony.ToggleSubscriptionDialogActivity"
android:exported="false"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
- android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight" />
+ android:theme="@style/Theme.AlertDialog" />
<activity android:name=".network.telephony.DeleteEuiccSubscriptionDialogActivity"
android:exported="false"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
- android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight" />
+ android:theme="@style/Theme.AlertDialog" />
<activity
android:name="Settings$TetherSettingsActivity"
@@ -3688,14 +3688,14 @@
android:exported="false"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
android:launchMode="singleInstance"
- android:theme="@style/Transparent" />
+ android:theme="@style/Theme.AlertDialog" />
<activity
android:name=".sim.DsdsDialogActivity"
android:exported="false"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
android:launchMode="singleInstance"
- android:theme="@style/Transparent" />
+ android:theme="@style/Theme.AlertDialog" />
<service android:name=".sim.SimNotificationService"
android:permission="android.permission.BIND_JOB_SERVICE" />
diff --git a/res/layout/manage_applications_apps_v2.xml b/res/layout/manage_applications_apps_v2.xml
new file mode 100644
index 0000000..ecc764a
--- /dev/null
+++ b/res/layout/manage_applications_apps_v2.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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.
+-->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <FrameLayout
+ android:id="@+id/pinned_header"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:elevation="2dp"/>
+
+ <FrameLayout
+ android:id="@+id/list_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone">
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/apps_list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:clipToPadding="false"
+ android:scrollbars="none"
+ settings:fastScrollEnabled="true"
+ settings:fastScrollHorizontalThumbDrawable="@drawable/thumb_drawable"
+ settings:fastScrollHorizontalTrackDrawable="@drawable/line_drawable"
+ settings:fastScrollVerticalThumbDrawable="@drawable/thumb_drawable"
+ settings:fastScrollVerticalTrackDrawable="@drawable/line_drawable"/>
+
+ <TextView
+ android:id="@android:id/empty"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:layout_gravity="center"
+ android:text="@string/no_applications"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:visibility="invisible"/>
+
+ </FrameLayout>
+
+ <include layout="@layout/loading_container"/>
+
+</FrameLayout>
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9e99251..90aad1b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -12192,6 +12192,8 @@
<!-- Strings for SIM push notifications -->
<!-- Category name of the notifications related to SIM setup. [CHAR LIMIT=NONE] -->
<string name="sim_setup_channel_id">Network activation</string>
+ <!-- Title on a push notification indicating that the user's device is in the middle of switching between mobile networks. [CHAR LIMIT=NONE] -->
+ <string name="sim_switch_channel_id">Carrier switching</string>
<!-- The title of post DSDS reboot notification. The title includes carrier's name. [CHAR LIMIT=NONE] -->
<string name="post_dsds_reboot_notification_title_with_carrier"><xliff:g id="carrier_name" example="Google Fi">%1$s</xliff:g> is active</string>
<!-- The body text of post DSDS reboot notification. [CHAR LIMIT=NONE] -->
@@ -12778,4 +12780,7 @@
<string name="smart_forwarding_missing_mdn_text">Phone number is missing.</string>
<!-- Alert Dialog text when user didn't input the phone number [CHAR LIMIT=50]-->
<string name="smart_forwarding_missing_alert_dialog_text">OK</string>
+
+ <!-- Enable 2G: Title for if user wants to enable 2G [CHAR LIMIT=40] -->
+ <string name="enable_2g_title">Allow 2G</string>
</resources>
diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml
index 44a21ac..707cae9 100644
--- a/res/xml/channel_notification_settings.xml
+++ b/res/xml/channel_notification_settings.xml
@@ -65,11 +65,6 @@
android:summary="@string/promote_conversation_summary"
settings:allowDividerAbove="true"/>
- <PreferenceCategory
- android:key="channel_advanced"
- android:order="50"
- settings:initialExpandedChildrenCount="0">
-
<!-- Default ringtone -->
<com.android.settings.notification.app.NotificationSoundPreference
android:key="ringtone"
@@ -120,7 +115,6 @@
android:order="18"
android:title="@string/app_settings_link"
settings:allowDividerAbove="true"/>
- </PreferenceCategory>
<com.android.settings.notification.app.NotificationFooterPreference
android:key="desc"
diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml
index fb03f4c..162dc38 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -22,16 +22,10 @@
settings:keywords="@string/keywords_location">
<PreferenceCategory
- android:key="recent_location_requests"
- android:title="@string/location_category_recent_location_requests"
- settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/>
-
- <Preference
- android:key="recent_location_requests_see_all_button"
- android:title="@string/location_recent_location_requests_see_all"
- android:icon="@drawable/ic_chevron_right_24dp"
- android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
- settings:searchable="false"/>
+ android:key="recent_location_access"
+ android:title="@string/location_category_recent_location_access"
+ settings:controller=
+ "com.android.settings.location.RecentLocationAccessPreferenceController"/>
<PreferenceCategory
android:key="location_advanced_settings"
diff --git a/res/xml/location_settings_personal.xml b/res/xml/location_settings_personal.xml
index de8ed81..e2a2f15 100644
--- a/res/xml/location_settings_personal.xml
+++ b/res/xml/location_settings_personal.xml
@@ -25,14 +25,8 @@
<PreferenceCategory
android:key="recent_location_requests"
android:title="@string/location_category_recent_location_requests"
- settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/>
-
- <Preference
- android:key="recent_location_requests_see_all_button"
- android:title="@string/location_recent_location_requests_see_all"
- android:icon="@drawable/ic_chevron_right_24dp"
- android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
- settings:searchable="false"/>
+ settings:controller=
+ "com.android.settings.location.RecentLocationAccessPreferenceController"/>
<!-- This preference category gets removed if new_recent_location_ui is disabled -->
<Preference
diff --git a/res/xml/location_settings_workprofile.xml b/res/xml/location_settings_workprofile.xml
index f15c8d8..f6f2d96 100644
--- a/res/xml/location_settings_workprofile.xml
+++ b/res/xml/location_settings_workprofile.xml
@@ -25,16 +25,8 @@
<PreferenceCategory
android:key="recent_location_requests"
android:title="@string/location_category_recent_location_requests"
- settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/>
-
- <Preference
- android:key="recent_location_requests_see_all_button"
- android:title="@string/location_recent_location_requests_see_all"
- android:icon="@drawable/ic_chevron_right_24dp"
- android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
- settings:controller="com.android.settings.core.WorkPreferenceController"
- settings:forWork="true"
- settings:searchable="false"/>
+ settings:controller=
+ "com.android.settings.location.RecentLocationAccessPreferenceController"/>
<com.android.settingslib.RestrictedSwitchPreference
android:key="managed_profile_location_switch"
diff --git a/res/xml/mobile_network_settings.xml b/res/xml/mobile_network_settings.xml
index a100d6b..86f5a83 100644
--- a/res/xml/mobile_network_settings.xml
+++ b/res/xml/mobile_network_settings.xml
@@ -255,4 +255,8 @@
settings:searchable="false"
settings:controller="com.android.settings.network.telephony.NrDisabledInDsdsFooterPreferenceController"/>
+ <SwitchPreference
+ android:key="enable_2g"
+ android:title="@string/enable_2g_title"
+ settings:controller="com.android.settings.network.telephony.Enable2gPreferenceController" />
</PreferenceScreen>
diff --git a/src/com/android/settings/accessibility/ShortcutsSettingsFragment.java b/src/com/android/settings/accessibility/ShortcutsSettingsFragment.java
index 91e16f6..8426834 100644
--- a/src/com/android/settings/accessibility/ShortcutsSettingsFragment.java
+++ b/src/com/android/settings/accessibility/ShortcutsSettingsFragment.java
@@ -21,8 +21,10 @@
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
/** Accessibility settings for accessibility shortcuts. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class ShortcutsSettingsFragment extends DashboardFragment {
private static final String TAG = "ShortcutsSettingsFragment";
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index c699425..707e6f4 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -398,7 +398,11 @@
return mRootView;
}
- mRootView = inflater.inflate(R.layout.manage_applications_apps, null);
+ if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.SILKY_HOME)) {
+ mRootView = inflater.inflate(R.layout.manage_applications_apps_v2, null);
+ } else {
+ mRootView = inflater.inflate(R.layout.manage_applications_apps, null);
+ }
mLoadingContainer = mRootView.findViewById(R.id.loading_container);
mListContainer = mRootView.findViewById(R.id.list_container);
if (mListContainer != null) {
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingRequest.java b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
index 0e4ed74..d7dad88 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
@@ -37,20 +37,26 @@
if (action == null || !action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
return;
}
- PowerManager powerManager =
- (PowerManager)context.getSystemService(Context.POWER_SERVICE);
+ PowerManager powerManager = context.getSystemService(PowerManager.class);
BluetoothDevice device =
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ int pairingVariant = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
+ BluetoothDevice.ERROR);
String deviceAddress = device != null ? device.getAddress() : null;
String deviceName = device != null ? device.getName() : null;
boolean shouldShowDialog = LocalBluetoothPreferences.shouldShowDialogInForeground(
context, deviceAddress, deviceName);
- if (powerManager.isInteractive() && shouldShowDialog) {
+
+ // Skips consent pairing dialog if the device was recently associated with CDM
+ if (pairingVariant == BluetoothDevice.PAIRING_VARIANT_CONSENT
+ && device.canBondWithoutDialog()) {
+ device.setPairingConfirmation(true);
+ } else if (powerManager.isInteractive() && shouldShowDialog) {
// Since the screen is on and the BT-related activity is in the foreground,
// just open the dialog
// convert broadcast intent into activity intent (same action string)
Intent pairingIntent = BluetoothPairingService.getPairingDialogIntent(context, intent,
- BluetoothDevice.EXTRA_PAIRING_INITIATOR_FOREGROUND);
+ BluetoothDevice.EXTRA_PAIRING_INITIATOR_FOREGROUND);
context.startActivityAsUser(pairingIntent, UserHandle.CURRENT);
} else {
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
index 62f15b9..7d28d82 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
@@ -85,11 +85,6 @@
boolean isAlwaysOnVpnSetInManagedProfile();
/**
- * Returns whether the Device Owner set a recommended global HTTP proxy.
- */
- boolean isGlobalHttpProxySet();
-
- /**
* Returns the number of failed login attempts that the Device Owner or Profile Owner allows
* before the current user is wiped, or zero if no such limit is set.
*/
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index 7a5b489..f461fe1 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -25,6 +25,7 @@
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.net.ConnectivityManager;
+import android.net.VpnManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -48,18 +49,20 @@
private final PackageManager mPm;
private final UserManager mUm;
private final ConnectivityManager mCm;
+ private final VpnManager mVm;
private final Resources mResources;
private static final int MY_USER_ID = UserHandle.myUserId();
public EnterprisePrivacyFeatureProviderImpl(Context context, DevicePolicyManager dpm,
- PackageManager pm, UserManager um, ConnectivityManager cm,
+ PackageManager pm, UserManager um, ConnectivityManager cm, VpnManager vm,
Resources resources) {
mContext = context.getApplicationContext();
mDpm = dpm;
mPm = pm;
mUm = um;
mCm = cm;
+ mVm = vm;
mResources = resources;
}
@@ -133,19 +136,14 @@
@Override
public boolean isAlwaysOnVpnSetInCurrentUser() {
- return VpnUtils.isAlwaysOnVpnSet(mCm, MY_USER_ID);
+ return VpnUtils.isAlwaysOnVpnSet(mVm, MY_USER_ID);
}
@Override
public boolean isAlwaysOnVpnSetInManagedProfile() {
final int managedProfileUserId = getManagedProfileUserId();
return managedProfileUserId != UserHandle.USER_NULL &&
- VpnUtils.isAlwaysOnVpnSet(mCm, managedProfileUserId);
- }
-
- @Override
- public boolean isGlobalHttpProxySet() {
- return mCm.getGlobalProxy() != null;
+ VpnUtils.isAlwaysOnVpnSet(mVm, managedProfileUserId);
}
@Override
diff --git a/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceController.java b/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceController.java
index 04e63aa..6de6cde 100644
--- a/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceController.java
+++ b/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceController.java
@@ -14,26 +14,25 @@
package com.android.settings.enterprise;
import android.content.Context;
+import android.net.ConnectivityManager;
import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController;
public class GlobalHttpProxyPreferenceController extends AbstractPreferenceController implements
PreferenceControllerMixin {
private static final String KEY_GLOBAL_HTTP_PROXY = "global_http_proxy";
- private final EnterprisePrivacyFeatureProvider mFeatureProvider;
+ private final ConnectivityManager mCm;
public GlobalHttpProxyPreferenceController(Context context) {
super(context);
- mFeatureProvider = FeatureFactory.getFactory(context)
- .getEnterprisePrivacyFeatureProvider(context);
+ mCm = context.getSystemService(ConnectivityManager.class);
}
@Override
public boolean isAvailable() {
- return mFeatureProvider.isGlobalHttpProxySet();
+ return mCm.getGlobalProxy() != null;
}
@Override
diff --git a/src/com/android/settings/fuelgauge/OWNERS b/src/com/android/settings/fuelgauge/OWNERS
index 4e5ee0e..ab3da89 100644
--- a/src/com/android/settings/fuelgauge/OWNERS
+++ b/src/com/android/settings/fuelgauge/OWNERS
@@ -1,3 +1,4 @@
# Default reviewers for this and subdirectories.
-millchen@google.com
-tmfang@google.com
+tifn@google.com
+wesleycwwang@google.com
+ykhung@google.com
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index b4f0f1f..0bc7fc7 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -82,7 +82,7 @@
super.onAttach(context);
use(AppLocationPermissionPreferenceController.class).init(this);
- use(RecentLocationRequestPreferenceController.class).init(this);
+ use(RecentLocationAccessPreferenceController.class).init(this);
use(LocationServicePreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this);
use(LocationForWorkPreferenceController.class).init(this);
diff --git a/src/com/android/settings/location/LocationWorkProfileSettings.java b/src/com/android/settings/location/LocationWorkProfileSettings.java
index 2bf5f98..c312714 100644
--- a/src/com/android/settings/location/LocationWorkProfileSettings.java
+++ b/src/com/android/settings/location/LocationWorkProfileSettings.java
@@ -21,7 +21,6 @@
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
/**
* Location Setting page for managed profile.
@@ -54,11 +53,9 @@
use(LocationFooterPreferenceController.class).init(this);
use(LocationForWorkPreferenceController.class).init(this);
- final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
- final RecentLocationRequestPreferenceController controller = use(
- RecentLocationRequestPreferenceController.class);
+ final RecentLocationAccessPreferenceController controller =
+ use(RecentLocationAccessPreferenceController.class);
controller.init(this);
- controller.setProfileType(profileType);
}
@Override
diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
index c835a51..245118d 100644
--- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
@@ -13,114 +13,141 @@
*/
package com.android.settings.location;
-import static java.util.concurrent.TimeUnit.DAYS;
+import static android.Manifest.permission_group.LOCATION;
-import android.Manifest;
import android.content.Context;
import android.content.Intent;
-import android.icu.text.RelativeDateTimeFormatter;
-import android.provider.DeviceConfig;
-import android.view.View;
+import android.os.UserHandle;
+import android.os.UserManager;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.Utils;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settingslib.location.RecentLocationAccesses;
-import com.android.settingslib.utils.StringUtil;
-import com.android.settingslib.widget.AppEntitiesHeaderController;
-import com.android.settingslib.widget.AppEntityInfo;
-import com.android.settingslib.widget.LayoutPreference;
+import com.android.settingslib.widget.AppPreference;
+import java.util.ArrayList;
import java.util.List;
-public class RecentLocationAccessPreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin {
- /** Key for the recent location apps dashboard */
- private static final String KEY_APPS_DASHBOARD = "apps_dashboard";
- private final RecentLocationAccesses mRecentLocationAccesses;
- private AppEntitiesHeaderController mController;
- private static final int MAXIMUM_APP_COUNT = 3;
+/**
+ * Preference controller that handles the display of apps that access locations.
+ */
+public class RecentLocationAccessPreferenceController extends LocationBasePreferenceController {
+ @VisibleForTesting
+ RecentLocationAccesses mRecentLocationApps;
+ private PreferenceCategory mCategoryRecentLocationRequests;
+ private int mType = ProfileSelectFragment.ProfileType.ALL;
- public RecentLocationAccessPreferenceController(Context context) {
- this(context, new RecentLocationAccesses(context));
+ private static class PackageEntryClickedListener implements
+ Preference.OnPreferenceClickListener {
+ private final Context mContext;
+ private final String mPackage;
+ private final UserHandle mUserHandle;
+
+ PackageEntryClickedListener(Context context, String packageName,
+ UserHandle userHandle) {
+ mContext = context;
+ mPackage = packageName;
+ mUserHandle = userHandle;
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION);
+ intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, LOCATION);
+ intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mPackage);
+ intent.putExtra(Intent.EXTRA_USER, mUserHandle);
+ mContext.startActivity(intent);
+ return true;
+ }
+ }
+
+ public RecentLocationAccessPreferenceController(Context context, String key) {
+ this(context, key, new RecentLocationAccesses(context));
}
@VisibleForTesting
- RecentLocationAccessPreferenceController(Context context,
- RecentLocationAccesses recentAccesses) {
- super(context);
- mRecentLocationAccesses = recentAccesses;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_APPS_DASHBOARD;
- }
-
- @Override
- public boolean isAvailable() {
- return Boolean.parseBoolean(
- DeviceConfig.getProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED));
+ public RecentLocationAccessPreferenceController(Context context, String key,
+ RecentLocationAccesses recentLocationApps) {
+ super(context, key);
+ mRecentLocationApps = recentLocationApps;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- final LayoutPreference preference = screen.findPreference(KEY_APPS_DASHBOARD);
- final View view = preference.findViewById(R.id.app_entities_header);
- mController = AppEntitiesHeaderController.newInstance(mContext, view)
- .setHeaderTitleRes(R.string.location_category_recent_location_access)
- .setHeaderDetailsRes(R.string.location_recent_location_access_view_details)
- .setHeaderEmptyRes(R.string.location_no_recent_accesses)
- .setHeaderDetailsClickListener((View v) -> {
- final Intent intent = new Intent(Intent.ACTION_REVIEW_PERMISSION_USAGE);
- intent.putExtra(Intent.EXTRA_PERMISSION_NAME,
- Manifest.permission.ACCESS_FINE_LOCATION);
- intent.putExtra(Intent.EXTRA_DURATION_MILLIS, DAYS.toMillis(1));
- mContext.startActivity(intent);
- });
+ mCategoryRecentLocationRequests = screen.findPreference(getPreferenceKey());
+ final Context prefContext = mCategoryRecentLocationRequests.getContext();
+ final List<RecentLocationAccesses.Access> recentLocationAccesses = new ArrayList<>();
+ final UserManager userManager = UserManager.get(mContext);
+ for (RecentLocationAccesses.Access access : mRecentLocationApps.getAppListSorted()) {
+ if (isRequestMatchesProfileType(userManager, access, mType)) {
+ recentLocationAccesses.add(access);
+ }
+ }
+
+ if (recentLocationAccesses.size() > 0) {
+ // Add preferences to container in original order (already sorted by recency).
+ for (RecentLocationAccesses.Access access : recentLocationAccesses) {
+ mCategoryRecentLocationRequests.addPreference(
+ createAppPreference(prefContext, access, mFragment));
+ }
+ } else {
+ // If there's no item to display, add a "No recent apps" item.
+ final Preference banner = new AppPreference(prefContext);
+ banner.setTitle(R.string.location_no_recent_accesses);
+ banner.setSelectable(false);
+ mCategoryRecentLocationRequests.addPreference(banner);
+ }
}
@Override
- public void updateState(Preference preference) {
- updateRecentApps();
+ public void onLocationModeChanged(int mode, boolean restricted) {
+ mCategoryRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode));
}
- private void updateRecentApps() {
- final List<RecentLocationAccesses.Access> recentLocationAccesses =
- mRecentLocationAccesses.getAppListSorted();
- if (recentLocationAccesses.size() > 0) {
- // Display the top 3 preferences to container in original order.
- int i = 0;
- for (; i < Math.min(recentLocationAccesses.size(), MAXIMUM_APP_COUNT); i++) {
- final RecentLocationAccesses.Access access = recentLocationAccesses.get(i);
- final AppEntityInfo appEntityInfo = new AppEntityInfo.Builder()
- .setIcon(access.icon)
- .setTitle(access.label)
- .setSummary(StringUtil.formatRelativeTime(mContext,
- System.currentTimeMillis() - access.accessFinishTime, false,
- RelativeDateTimeFormatter.Style.SHORT))
- .setOnClickListener((v) -> {
- final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION);
- intent.putExtra(Intent.EXTRA_PERMISSION_NAME,
- Manifest.permission.ACCESS_FINE_LOCATION);
- intent.putExtra(Intent.EXTRA_PACKAGE_NAME, access.packageName);
- intent.putExtra(Intent.EXTRA_USER, access.userHandle);
- mContext.startActivity(intent);
- })
- .build();
- mController.setAppEntity(i, appEntityInfo);
- }
- for (; i < MAXIMUM_APP_COUNT; i++) {
- mController.removeAppEntity(i);
- }
+ /**
+ * Initialize {@link ProfileSelectFragment.ProfileType} of the controller
+ *
+ * @param type {@link ProfileSelectFragment.ProfileType} of the controller.
+ */
+ public void setProfileType(@ProfileSelectFragment.ProfileType int type) {
+ mType = type;
+ }
+
+ /**
+ * Create a {@link AppPreference}
+ */
+ public static AppPreference createAppPreference(Context prefContext,
+ RecentLocationAccesses.Access access, DashboardFragment fragment) {
+ final AppPreference pref = new AppPreference(prefContext);
+ pref.setIcon(access.icon);
+ pref.setTitle(access.label);
+ pref.setOnPreferenceClickListener(new PackageEntryClickedListener(
+ fragment.getContext(), access.packageName, access.userHandle));
+ return pref;
+ }
+
+ /**
+ * Return if the {@link RecentLocationAccesses.Access} matches current UI
+ * {@ProfileSelectFragment.ProfileType}
+ */
+ public static boolean isRequestMatchesProfileType(UserManager userManager,
+ RecentLocationAccesses.Access access, @ProfileSelectFragment.ProfileType int type) {
+
+ final boolean isWorkProfile = userManager.isManagedProfile(
+ access.userHandle.getIdentifier());
+ if (isWorkProfile && (type & ProfileSelectFragment.ProfileType.WORK) != 0) {
+ return true;
}
- mController.apply();
+ if (!isWorkProfile && (type & ProfileSelectFragment.ProfileType.PERSONAL) != 0) {
+ return true;
+ }
+ return false;
}
}
diff --git a/src/com/android/settings/network/telephony/Enable2gPreferenceController.java b/src/com/android/settings/network/telephony/Enable2gPreferenceController.java
new file mode 100644
index 0000000..1fa4300
--- /dev/null
+++ b/src/com/android/settings/network/telephony/Enable2gPreferenceController.java
@@ -0,0 +1,102 @@
+/*
+ * 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.network.telephony;
+
+import android.content.Context;
+import android.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+
+/**
+ * Preference controller for "Enable 2G"
+ */
+public class Enable2gPreferenceController extends TelephonyTogglePreferenceController {
+
+ private static final String LOG_TAG = "Enable2gPreferenceController";
+ private static final long BITMASK_2G = TelephonyManager.NETWORK_TYPE_BITMASK_GSM
+ | TelephonyManager.NETWORK_TYPE_BITMASK_GPRS
+ | TelephonyManager.NETWORK_TYPE_BITMASK_EDGE
+ | TelephonyManager.NETWORK_TYPE_BITMASK_CDMA;
+
+ private CarrierConfigManager mCarrierConfigManager;
+ private TelephonyManager mTelephonyManager;
+
+ /**
+ * Class constructor of "Enable 2G" toggle.
+ *
+ * @param context of settings
+ * @param key assigned within UI entry of XML file
+ */
+ public Enable2gPreferenceController(Context context, String key) {
+ super(context, key);
+ mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
+ }
+
+ /**
+ * Initialization based on a given subscription id.
+ *
+ * @param subId is the subscription id
+ * @return this instance after initialization
+ */
+ public Enable2gPreferenceController init(int subId) {
+ mSubId = subId;
+ mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
+ .createForSubscriptionId(mSubId);
+ return this;
+ }
+
+ @Override
+ public int getAvailabilityStatus(int subId) {
+ final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
+ boolean visible =
+ subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
+ && carrierConfig != null
+ && !carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G)
+ && mTelephonyManager.isRadioInterfaceCapabilitySupported(
+ mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ long currentlyAllowedNetworkTypes = mTelephonyManager.getAllowedNetworkTypesForReason(
+ mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G);
+ return (currentlyAllowedNetworkTypes & BITMASK_2G) != 0;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ long currentlyAllowedNetworkTypes = mTelephonyManager.getAllowedNetworkTypesForReason(
+ mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G);
+ boolean enabled = (currentlyAllowedNetworkTypes & BITMASK_2G) != 0;
+ if (enabled == isChecked) {
+ return false;
+ }
+ long newAllowedNetworkTypes = currentlyAllowedNetworkTypes;
+ if (isChecked) {
+ newAllowedNetworkTypes = currentlyAllowedNetworkTypes | BITMASK_2G;
+ Log.i(LOG_TAG, "Enabling 2g. Allowed network types: " + newAllowedNetworkTypes);
+ } else {
+ newAllowedNetworkTypes = currentlyAllowedNetworkTypes & ~BITMASK_2G;
+ Log.i(LOG_TAG, "Disabling 2g. Allowed network types: " + newAllowedNetworkTypes);
+ }
+ mTelephonyManager.setAllowedNetworkTypesForReason(
+ mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G, newAllowedNetworkTypes);
+ return true;
+ }
+}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index 0d842ef..9a4cb40 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -158,6 +158,7 @@
use(PreferredNetworkModePreferenceController.class).init(mSubId);
use(EnabledNetworkModePreferenceController.class).init(getLifecycle(), mSubId);
use(DataServiceSetupPreferenceController.class).init(mSubId);
+ use(Enable2gPreferenceController.class).init(mSubId);
final WifiCallingPreferenceController wifiCallingPreferenceController =
use(WifiCallingPreferenceController.class).init(mSubId);
diff --git a/src/com/android/settings/notification/AppBubbleListPreferenceController.java b/src/com/android/settings/notification/AppBubbleListPreferenceController.java
index 31f185b..bf7fcc0 100644
--- a/src/com/android/settings/notification/AppBubbleListPreferenceController.java
+++ b/src/com/android/settings/notification/AppBubbleListPreferenceController.java
@@ -32,7 +32,6 @@
import android.widget.ImageView;
import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
@@ -67,8 +66,10 @@
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
Drawable conversationDrawable,
ShortcutInfo conversationInfo,
- RestrictedLockUtils.EnforcedAdmin admin) {
- super.onResume(appRow, channel, group, conversationDrawable, conversationInfo, admin);
+ RestrictedLockUtils.EnforcedAdmin admin,
+ List<String> preferenceFilter) {
+ super.onResume(appRow, channel, group, conversationDrawable, conversationInfo, admin,
+ preferenceFilter);
// In case something changed in the foreground (e.g. via bubble button on notification)
loadConversationsAndPopulate();
}
diff --git a/src/com/android/settings/notification/AssistantFeedbackPreferenceController.java b/src/com/android/settings/notification/AssistantFeedbackPreferenceController.java
deleted file mode 100644
index 491fd8b..0000000
--- a/src/com/android/settings/notification/AssistantFeedbackPreferenceController.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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;
-
-import static android.provider.Settings.Global.NOTIFICATION_FEEDBACK_ENABLED;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Handler;
-import android.provider.DeviceConfig;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.core.TogglePreferenceController;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnPause;
-import com.android.settingslib.core.lifecycle.events.OnResume;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public class AssistantFeedbackPreferenceController extends TogglePreferenceController
- implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
- LifecycleObserver, OnResume, OnPause {
-
- @VisibleForTesting
- static final int ON = 1;
- @VisibleForTesting
- static final int OFF = 0;
-
- private SettingObserver mSettingObserver;
-
- public AssistantFeedbackPreferenceController(Context context,
- String preferenceKey) {
- super(context, preferenceKey);
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- Preference preference = screen.findPreference(NOTIFICATION_FEEDBACK_ENABLED);
- if (preference != null) {
- mSettingObserver = new SettingObserver(preference);
- }
- }
-
- @Override
- public void onResume() {
- if (mSettingObserver != null) {
- mSettingObserver.register(mContext.getContentResolver(), true /* register */);
- }
- }
-
- @Override
- public void onPause() {
- if (mSettingObserver != null) {
- mSettingObserver.register(mContext.getContentResolver(), false /* register */);
- }
- }
-
- @Override
- public int getAvailabilityStatus() {
- return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
- SystemUiDeviceConfigFlags.ENABLE_NAS_FEEDBACK, false)
- ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
- }
-
- @Override
- public boolean isChecked() {
- return Settings.Global.getInt(mContext.getContentResolver(),
- NOTIFICATION_FEEDBACK_ENABLED, ON) == ON;
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- return Settings.Global.putInt(mContext.getContentResolver(),
- NOTIFICATION_FEEDBACK_ENABLED, isChecked ? ON : OFF);
- }
-
- class SettingObserver extends ContentObserver {
-
- private final Uri NOTIFICATION_URI =
- Settings.Global.getUriFor(NOTIFICATION_FEEDBACK_ENABLED);
-
- private final Preference mPreference;
-
- SettingObserver(Preference preference) {
- super(new Handler());
- mPreference = preference;
- }
-
- public void register(ContentResolver cr, boolean register) {
- if (register) {
- cr.registerContentObserver(NOTIFICATION_URI, false, this);
- } else {
- cr.unregisterContentObserver(this);
- }
- }
-
- @Override
- public void onChange(boolean selfChange, Uri uri) {
- super.onChange(selfChange, uri);
- if (NOTIFICATION_URI.equals(uri)) {
- updateState(mPreference);
- }
- }
- }
-}
diff --git a/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java b/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java
index 15b8388..e5afd9d 100644
--- a/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java
+++ b/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.notification.app;
+import android.app.NotificationChannel;
import android.content.Context;
import android.util.Slog;
@@ -48,6 +49,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_LAUNCHER);
+ }
+
+ @Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (KEY.equals(preference.getKey())) {
try {
diff --git a/src/com/android/settings/notification/app/AllowSoundPreferenceController.java b/src/com/android/settings/notification/app/AllowSoundPreferenceController.java
index cf6db87..0664c54 100644
--- a/src/com/android/settings/notification/app/AllowSoundPreferenceController.java
+++ b/src/com/android/settings/notification/app/AllowSoundPreferenceController.java
@@ -59,6 +59,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_SOUND);
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mChannel != null) {
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
diff --git a/src/com/android/settings/notification/app/AppBubbleNotificationSettings.java b/src/com/android/settings/notification/app/AppBubbleNotificationSettings.java
index 59fa440..3aeb73c 100644
--- a/src/com/android/settings/notification/app/AppBubbleNotificationSettings.java
+++ b/src/com/android/settings/notification/app/AppBubbleNotificationSettings.java
@@ -90,7 +90,7 @@
}
for (NotificationPreferenceController controller : mControllers) {
- controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin);
+ controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin, null);
controller.displayPreference(getPreferenceScreen());
}
updatePreferenceStates();
diff --git a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
index 297bfdb..5e12bbd 100644
--- a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
+++ b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
@@ -115,6 +115,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mAppRow != null) {
loadAppChannels();
diff --git a/src/com/android/settings/notification/app/AppChannelsBypassingDndSettings.java b/src/com/android/settings/notification/app/AppChannelsBypassingDndSettings.java
index 4dcbcfc..4fab7e2 100644
--- a/src/com/android/settings/notification/app/AppChannelsBypassingDndSettings.java
+++ b/src/com/android/settings/notification/app/AppChannelsBypassingDndSettings.java
@@ -53,7 +53,7 @@
}
for (NotificationPreferenceController controller : mControllers) {
- controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin);
+ controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin, null);
controller.displayPreference(getPreferenceScreen());
}
updatePreferenceStates();
diff --git a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java
index 2054a16..0e89be3 100644
--- a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java
+++ b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java
@@ -75,6 +75,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
+ @Override
public void updateState(Preference preference) {
mPreference = (PreferenceCategory) preference;
loadConversationsAndPopulate();
diff --git a/src/com/android/settings/notification/app/AppLinkPreferenceController.java b/src/com/android/settings/notification/app/AppLinkPreferenceController.java
index 23ccbf0..043ae69 100644
--- a/src/com/android/settings/notification/app/AppLinkPreferenceController.java
+++ b/src/com/android/settings/notification/app/AppLinkPreferenceController.java
@@ -48,6 +48,11 @@
return mAppRow.settingsIntent != null;
}
+ @Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
public void updateState(Preference preference) {
if (mAppRow != null) {
preference.setIntent(mAppRow.settingsIntent);
diff --git a/src/com/android/settings/notification/app/AppNotificationSettings.java b/src/com/android/settings/notification/app/AppNotificationSettings.java
index 58c18ba..d7694d7 100644
--- a/src/com/android/settings/notification/app/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/app/AppNotificationSettings.java
@@ -79,7 +79,8 @@
}
for (NotificationPreferenceController controller : mControllers) {
- controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin);
+ controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin,
+ null);
controller.displayPreference(getPreferenceScreen());
}
updatePreferenceStates();
diff --git a/src/com/android/settings/notification/app/BadgePreferenceController.java b/src/com/android/settings/notification/app/BadgePreferenceController.java
index 9f8608e..108fa1d 100644
--- a/src/com/android/settings/notification/app/BadgePreferenceController.java
+++ b/src/com/android/settings/notification/app/BadgePreferenceController.java
@@ -18,6 +18,7 @@
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
+import android.app.NotificationChannel;
import android.content.Context;
import android.provider.Settings;
@@ -67,6 +68,11 @@
return true;
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_LAUNCHER);
+ }
+
public void updateState(Preference preference) {
if (mAppRow != null) {
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
diff --git a/src/com/android/settings/notification/app/BlockPreferenceController.java b/src/com/android/settings/notification/app/BlockPreferenceController.java
index 4df3e28..d5d516e 100644
--- a/src/com/android/settings/notification/app/BlockPreferenceController.java
+++ b/src/com/android/settings/notification/app/BlockPreferenceController.java
@@ -20,6 +20,7 @@
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.widget.Switch;
@@ -55,9 +56,17 @@
if (mAppRow == null) {
return false;
}
+ if (mPreferenceFilter != null && !isIncludedInFilter()) {
+ return false;
+ }
return true;
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
+ }
+
public void updateState(Preference preference) {
SettingsMainSwitchPreference bar = (SettingsMainSwitchPreference) preference;
if (bar != null) {
diff --git a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java
index f8983ff..43f0baa 100644
--- a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java
+++ b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java
@@ -44,6 +44,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
+ @Override
public String getPreferenceKey() {
return KEY;
}
diff --git a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java
index ff27043..3439543 100644
--- a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java
+++ b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java
@@ -44,6 +44,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
+ @Override
public String getPreferenceKey() {
return KEY;
}
diff --git a/src/com/android/settings/notification/app/BubblePreferenceController.java b/src/com/android/settings/notification/app/BubblePreferenceController.java
index 8f452f7..6caa95e 100644
--- a/src/com/android/settings/notification/app/BubblePreferenceController.java
+++ b/src/com/android/settings/notification/app/BubblePreferenceController.java
@@ -21,6 +21,7 @@
import android.app.ActivityManager;
import android.annotation.Nullable;
+import android.app.NotificationChannel;
import android.content.Context;
import android.provider.Settings;
@@ -85,6 +86,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mIsAppPage && mAppRow != null) {
mHasSentInvalidMsg = mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
diff --git a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java
index 236e628..5b2a973 100644
--- a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java
+++ b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java
@@ -67,6 +67,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
+ @Override
public String getPreferenceKey() {
return KEY;
}
diff --git a/src/com/android/settings/notification/app/ChannelListPreferenceController.java b/src/com/android/settings/notification/app/ChannelListPreferenceController.java
index 5fd607f..b1109ec 100644
--- a/src/com/android/settings/notification/app/ChannelListPreferenceController.java
+++ b/src/com/android/settings/notification/app/ChannelListPreferenceController.java
@@ -85,6 +85,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
+ @Override
public void updateState(Preference preference) {
mPreference = (PreferenceCategory) preference;
// Load channel settings
diff --git a/src/com/android/settings/notification/app/ChannelNotificationSettings.java b/src/com/android/settings/notification/app/ChannelNotificationSettings.java
index 319c798..bdea30d 100644
--- a/src/com/android/settings/notification/app/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/app/ChannelNotificationSettings.java
@@ -79,7 +79,8 @@
}
for (NotificationPreferenceController controller : mControllers) {
- controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin);
+ controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin,
+ mPreferenceFilter);
controller.displayPreference(getPreferenceScreen());
}
updatePreferenceStates();
diff --git a/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java b/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java
index 6583a23..02f639c 100644
--- a/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.notification.app;
+import android.app.NotificationChannel;
import android.content.Context;
import android.text.TextUtils;
@@ -56,6 +57,11 @@
return !TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted();
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
+ }
+
public void updateState(Preference preference) {
preference.setEnabled(mAdmin == null);
}
diff --git a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
index 50a8b23..313b387 100644
--- a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
@@ -60,6 +60,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return true;
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mAppRow != null && mFragment != null) {
diff --git a/src/com/android/settings/notification/app/ConversationNotificationSettings.java b/src/com/android/settings/notification/app/ConversationNotificationSettings.java
index 902c81c..819ba83 100644
--- a/src/com/android/settings/notification/app/ConversationNotificationSettings.java
+++ b/src/com/android/settings/notification/app/ConversationNotificationSettings.java
@@ -49,7 +49,7 @@
for (NotificationPreferenceController controller : mControllers) {
controller.onResume(mAppRow, mChannel, mChannelGroup, mConversationDrawable,
- mConversationInfo, mSuspendedAppsAdmin);
+ mConversationInfo, mSuspendedAppsAdmin, null);
controller.displayPreference(getPreferenceScreen());
}
updatePreferenceStates();
diff --git a/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java b/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java
index e59f277..9730104 100644
--- a/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.notification.app;
+import android.app.NotificationChannel;
import android.content.Context;
import android.util.Pair;
@@ -53,6 +54,12 @@
return true;
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE)
+ || mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
+ }
+
public void updateState(Preference preference) {
if (mAppRow != null) {
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
diff --git a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
index 5a6fa51..24c3d2f 100644
--- a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.notification.app;
+import android.app.NotificationChannel;
import android.content.Context;
import android.text.TextUtils;
@@ -56,6 +57,11 @@
return !TextUtils.isEmpty(mChannel.getConversationId()) && mChannel.isDemoted();
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
+ }
+
public void updateState(Preference preference) {
preference.setEnabled(mAdmin == null);
}
diff --git a/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java b/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java
index 5a60f3f..77a692f 100644
--- a/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java
+++ b/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java
@@ -51,6 +51,11 @@
return mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0;
}
+ @Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
public void updateState(Preference preference) {
if (mAppRow != null) {
int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
diff --git a/src/com/android/settings/notification/app/DescriptionPreferenceController.java b/src/com/android/settings/notification/app/DescriptionPreferenceController.java
index f4ad6a3..0a5bb2f 100644
--- a/src/com/android/settings/notification/app/DescriptionPreferenceController.java
+++ b/src/com/android/settings/notification/app/DescriptionPreferenceController.java
@@ -54,6 +54,11 @@
return false;
}
+ @Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
public void updateState(Preference preference) {
if (mAppRow != null) {
if (mChannel != null) {
diff --git a/src/com/android/settings/notification/app/DndPreferenceController.java b/src/com/android/settings/notification/app/DndPreferenceController.java
index 90e6b25..b65928a 100644
--- a/src/com/android/settings/notification/app/DndPreferenceController.java
+++ b/src/com/android/settings/notification/app/DndPreferenceController.java
@@ -47,6 +47,11 @@
return true;
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_ZEN);
+ }
+
public void updateState(Preference preference) {
if (mChannel != null) {
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
diff --git a/src/com/android/settings/notification/app/HeaderPreferenceController.java b/src/com/android/settings/notification/app/HeaderPreferenceController.java
index 8098714..6482943 100644
--- a/src/com/android/settings/notification/app/HeaderPreferenceController.java
+++ b/src/com/android/settings/notification/app/HeaderPreferenceController.java
@@ -60,6 +60,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return true;
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mAppRow != null && mFragment != null) {
diff --git a/src/com/android/settings/notification/app/HighImportancePreferenceController.java b/src/com/android/settings/notification/app/HighImportancePreferenceController.java
index 3aecfa8..67fb2ff 100644
--- a/src/com/android/settings/notification/app/HighImportancePreferenceController.java
+++ b/src/com/android/settings/notification/app/HighImportancePreferenceController.java
@@ -22,12 +22,12 @@
import android.app.NotificationChannel;
import android.content.Context;
+import androidx.preference.Preference;
+
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedSwitchPreference;
-import androidx.preference.Preference;
-
public class HighImportancePreferenceController extends NotificationPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
@@ -61,6 +61,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mAppRow != null && mChannel != null) {
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
diff --git a/src/com/android/settings/notification/app/ImportancePreferenceController.java b/src/com/android/settings/notification/app/ImportancePreferenceController.java
index dc7f29b..ed3410c 100644
--- a/src/com/android/settings/notification/app/ImportancePreferenceController.java
+++ b/src/com/android/settings/notification/app/ImportancePreferenceController.java
@@ -59,6 +59,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mAppRow!= null && mChannel != null) {
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
diff --git a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java
index ade9653..b937e80 100644
--- a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java
+++ b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java
@@ -47,10 +47,18 @@
if (mAppRow.banned) {
return false;
}
+ if (mPreferenceFilter != null && !isIncludedInFilter()) {
+ return false;
+ }
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mAppRow == null) {
return;
diff --git a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java
index cf66474..5c502dc 100644
--- a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java
+++ b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java
@@ -47,10 +47,18 @@
if (mAppRow.banned) {
return false;
}
+ if (mPreferenceFilter != null && !isIncludedInFilter()) {
+ return false;
+ }
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mAppRow == null) {
return;
diff --git a/src/com/android/settings/notification/app/LightsPreferenceController.java b/src/com/android/settings/notification/app/LightsPreferenceController.java
index fc9f34c..d096922 100644
--- a/src/com/android/settings/notification/app/LightsPreferenceController.java
+++ b/src/com/android/settings/notification/app/LightsPreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.notification.app;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.provider.Settings;
@@ -53,6 +54,11 @@
&& !isDefaultChannel();
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_LOCKED_DEVICE);
+ }
+
public void updateState(Preference preference) {
if (mChannel != null) {
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
diff --git a/src/com/android/settings/notification/app/MinImportancePreferenceController.java b/src/com/android/settings/notification/app/MinImportancePreferenceController.java
index 69b7dc5..90f56b2 100644
--- a/src/com/android/settings/notification/app/MinImportancePreferenceController.java
+++ b/src/com/android/settings/notification/app/MinImportancePreferenceController.java
@@ -61,6 +61,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
+ }
+
+ @Override
public void updateState(Preference preference) {
if (mAppRow != null && mChannel != null) {
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
diff --git a/src/com/android/settings/notification/app/NotificationPreferenceController.java b/src/com/android/settings/notification/app/NotificationPreferenceController.java
index 14c98cf..e2eb453 100644
--- a/src/com/android/settings/notification/app/NotificationPreferenceController.java
+++ b/src/com/android/settings/notification/app/NotificationPreferenceController.java
@@ -36,6 +36,7 @@
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.Comparator;
+import java.util.List;
import java.util.Objects;
/**
@@ -60,6 +61,7 @@
protected Drawable mConversationDrawable;
@Nullable
protected ShortcutInfo mConversationInfo;
+ protected List<String> mPreferenceFilter;
public NotificationPreferenceController(Context context, NotificationBackend backend) {
super(context);
@@ -87,6 +89,9 @@
}
}
if (mChannel != null) {
+ if (mPreferenceFilter != null && !isIncludedInFilter()) {
+ return false;
+ }
return mChannel.getImportance() != IMPORTANCE_NONE;
}
return true;
@@ -96,15 +101,19 @@
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
Drawable conversationDrawable,
ShortcutInfo conversationInfo,
- RestrictedLockUtils.EnforcedAdmin admin) {
+ RestrictedLockUtils.EnforcedAdmin admin,
+ List<String> preferenceFilter) {
mAppRow = appRow;
mChannel = channel;
mChannelGroup = group;
mAdmin = admin;
mConversationDrawable = conversationDrawable;
mConversationInfo = conversationInfo;
+ mPreferenceFilter = preferenceFilter;
}
+ abstract boolean isIncludedInFilter();
+
protected boolean checkCanBeVisible(int minImportanceVisible) {
if (mChannel == null) {
Log.w(TAG, "No channel");
diff --git a/src/com/android/settings/notification/app/NotificationSettings.java b/src/com/android/settings/notification/app/NotificationSettings.java
index af1d9c1..44c735a 100644
--- a/src/com/android/settings/notification/app/NotificationSettings.java
+++ b/src/com/android/settings/notification/app/NotificationSettings.java
@@ -74,6 +74,7 @@
protected NotificationBackend.AppRow mAppRow;
protected Drawable mConversationDrawable;
protected ShortcutInfo mConversationInfo;
+ protected List<String> mPreferenceFilter;
protected boolean mShowLegacyChannelConfig = false;
protected boolean mListeningToPackageRemove;
@@ -119,6 +120,7 @@
loadChannel();
loadAppRow();
loadChannelGroup();
+ loadPreferencesFilter();
collectConfigActivities();
if (use(HeaderPreferenceController.class) != null) {
@@ -131,7 +133,7 @@
for (NotificationPreferenceController controller : mControllers) {
controller.onResume(mAppRow, mChannel, mChannelGroup, null, null,
- mSuspendedAppsAdmin);
+ mSuspendedAppsAdmin, mPreferenceFilter);
}
}
}
@@ -181,9 +183,17 @@
loadChannel();
loadConversation();
loadChannelGroup();
+ loadPreferencesFilter();
collectConfigActivities();
}
+ private void loadPreferencesFilter() {
+ Intent intent = getActivity().getIntent();
+ mPreferenceFilter = intent != null
+ ? intent.getStringArrayListExtra(Settings.EXTRA_CHANNEL_FILTER_LIST)
+ : null;
+ }
+
private void loadChannel() {
Intent intent = getActivity().getIntent();
String channelId = intent != null ? intent.getStringExtra(Settings.EXTRA_CHANNEL_ID) : null;
diff --git a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
index 0d998eb..0c7cd23 100644
--- a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
+++ b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.notification.app;
+import android.app.NotificationChannel;
import android.content.Context;
import androidx.preference.Preference;
@@ -42,11 +43,19 @@
if (mAppRow == null) {
return false;
}
+ if (mPreferenceFilter != null && !isIncludedInFilter()) {
+ return false;
+ }
// Available only when other controllers are unavailable - this UI replaces the UI that
// would give more detailed notification controls.
return !super.isAvailable();
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
+ }
+
public void updateState(Preference preference) {
if (mAppRow != null) {
if (mChannel != null) {
diff --git a/src/com/android/settings/notification/app/SoundPreferenceController.java b/src/com/android/settings/notification/app/SoundPreferenceController.java
index b3ac927..b23b4fc 100644
--- a/src/com/android/settings/notification/app/SoundPreferenceController.java
+++ b/src/com/android/settings/notification/app/SoundPreferenceController.java
@@ -69,6 +69,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_SOUND);
+ }
+
+ @Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
diff --git a/src/com/android/settings/notification/app/VibrationPreferenceController.java b/src/com/android/settings/notification/app/VibrationPreferenceController.java
index b22c477..bfbe768 100644
--- a/src/com/android/settings/notification/app/VibrationPreferenceController.java
+++ b/src/com/android/settings/notification/app/VibrationPreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.notification.app;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Vibrator;
@@ -54,6 +55,11 @@
&& mVibrator.hasVibrator();
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_VIBRATION);
+ }
+
public void updateState(Preference preference) {
if (mChannel != null) {
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
diff --git a/src/com/android/settings/notification/app/VisibilityPreferenceController.java b/src/com/android/settings/notification/app/VisibilityPreferenceController.java
index 74e42b0..a2a1d76 100644
--- a/src/com/android/settings/notification/app/VisibilityPreferenceController.java
+++ b/src/com/android/settings/notification/app/VisibilityPreferenceController.java
@@ -68,6 +68,11 @@
return checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure();
}
+ @Override
+ boolean isIncludedInFilter() {
+ return mPreferenceFilter.contains(NotificationChannel.EDIT_LOCKED_DEVICE);
+ }
+
public void updateState(Preference preference) {
if (mChannel != null && mAppRow != null) {
RestrictedListPreference pref = (RestrictedListPreference) preference;
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index ebbe87c..a1b70d9 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -20,6 +20,7 @@
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.net.ConnectivityManager;
+import android.net.VpnManager;
import android.os.UserManager;
import androidx.annotation.Keep;
@@ -172,7 +173,8 @@
Context.DEVICE_POLICY_SERVICE),
appContext.getPackageManager(),
UserManager.get(appContext),
- (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE),
+ appContext.getSystemService(ConnectivityManager.class),
+ appContext.getSystemService(VpnManager.class),
appContext.getResources());
}
return mEnterprisePrivacyFeatureProvider;
diff --git a/src/com/android/settings/sim/SimActivationNotifier.java b/src/com/android/settings/sim/SimActivationNotifier.java
index 735cb46..c90836e 100644
--- a/src/com/android/settings/sim/SimActivationNotifier.java
+++ b/src/com/android/settings/sim/SimActivationNotifier.java
@@ -88,6 +88,11 @@
SIM_SETUP_CHANNEL_ID,
mContext.getString(R.string.sim_setup_channel_id),
NotificationManager.IMPORTANCE_HIGH));
+ mNotificationManager.createNotificationChannel(
+ new NotificationChannel(
+ SWITCH_SLOT_CHANNEL_ID,
+ mContext.getString(R.string.sim_switch_channel_id),
+ NotificationManager.IMPORTANCE_HIGH));
}
/**
diff --git a/src/com/android/settings/vpn2/AppDialogFragment.java b/src/com/android/settings/vpn2/AppDialogFragment.java
index 45fb9bd..626a271 100644
--- a/src/com/android/settings/vpn2/AppDialogFragment.java
+++ b/src/com/android/settings/vpn2/AppDialogFragment.java
@@ -20,7 +20,6 @@
import android.app.settings.SettingsEnums;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
-import android.net.ConnectivityManager;
import android.net.VpnManager;
import android.os.Bundle;
import android.os.UserHandle;
@@ -48,7 +47,6 @@
private PackageInfo mPackageInfo;
private Listener mListener;
- private ConnectivityManager mConnectivityManager;
private UserManager mUserManager;
private VpnManager mVpnManager;
@@ -93,7 +91,6 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mConnectivityManager = getContext().getSystemService(ConnectivityManager.class);
mUserManager = UserManager.get(getContext());
mVpnManager = getContext().getSystemService(VpnManager.class);
}
@@ -158,8 +155,8 @@
}
final int userId = getUserId();
if (mPackageInfo.packageName.equals(VpnUtils.getConnectedPackage(mVpnManager, userId))) {
- mConnectivityManager.setAlwaysOnVpnPackageForUser(userId, null,
- /* lockdownEnabled */ false, /* lockdownAllowlist */ null);
+ mVpnManager.setAlwaysOnVpnPackageForUser(userId, null, /* lockdownEnabled */ false,
+ /* lockdownAllowlist */ null);
mVpnManager.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
}
}
diff --git a/src/com/android/settings/vpn2/AppManagementFragment.java b/src/com/android/settings/vpn2/AppManagementFragment.java
index 9422010..0543fee 100644
--- a/src/com/android/settings/vpn2/AppManagementFragment.java
+++ b/src/com/android/settings/vpn2/AppManagementFragment.java
@@ -28,7 +28,6 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
-import android.net.ConnectivityManager;
import android.net.VpnManager;
import android.os.Bundle;
import android.os.UserHandle;
@@ -69,7 +68,6 @@
private PackageManager mPackageManager;
private DevicePolicyManager mDevicePolicyManager;
- private ConnectivityManager mConnectivityManager;
private VpnManager mVpnManager;
// VPN app info
@@ -122,7 +120,6 @@
mPackageManager = getContext().getPackageManager();
mDevicePolicyManager = getContext().getSystemService(DevicePolicyManager.class);
- mConnectivityManager = getContext().getSystemService(ConnectivityManager.class);
mVpnManager = getContext().getSystemService(VpnManager.class);
mPreferenceVersion = findPreference(KEY_VERSION);
@@ -227,7 +224,7 @@
}
private boolean setAlwaysOnVpn(boolean isEnabled, boolean isLockdown) {
- return mConnectivityManager.setAlwaysOnVpnPackageForUser(mUserId,
+ return mVpnManager.setAlwaysOnVpnPackageForUser(mUserId,
isEnabled ? mPackageName : null, isLockdown, /* lockdownAllowlist */ null);
}
@@ -261,7 +258,7 @@
mPreferenceLockdown.setDisabledByAdmin(admin);
}
}
- if (mConnectivityManager.isAlwaysOnVpnPackageSupportedForUser(mUserId, mPackageName)) {
+ if (mVpnManager.isAlwaysOnVpnPackageSupportedForUser(mUserId, mPackageName)) {
// setSummary doesn't override the admin message when user restriction is applied
mPreferenceAlwaysOn.setSummary(R.string.vpn_always_on_summary);
// setEnabled is not required here, as checkRestrictionAndSetDisabled
@@ -275,7 +272,7 @@
}
private String getAlwaysOnVpnPackage() {
- return mConnectivityManager.getAlwaysOnVpnPackageForUser(mUserId);
+ return mVpnManager.getAlwaysOnVpnPackageForUser(mUserId);
}
private boolean isVpnAlwaysOn() {
diff --git a/src/com/android/settings/vpn2/ConfigDialogFragment.java b/src/com/android/settings/vpn2/ConfigDialogFragment.java
index e88e4ef..f339a69 100644
--- a/src/com/android/settings/vpn2/ConfigDialogFragment.java
+++ b/src/com/android/settings/vpn2/ConfigDialogFragment.java
@@ -20,7 +20,6 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
-import android.net.ConnectivityManager;
import android.net.VpnManager;
import android.os.Bundle;
import android.os.RemoteException;
@@ -177,8 +176,7 @@
return;
}
- final ConnectivityManager conn = ConnectivityManager.from(mContext);
- conn.setAlwaysOnVpnPackageForUser(UserHandle.myUserId(), null,
+ mService.setAlwaysOnVpnPackageForUser(UserHandle.myUserId(), null,
/* lockdownEnabled */ false, /* lockdownAllowlist */ null);
VpnUtils.setLockdownVpn(mContext, profile.key);
} else {
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index 79f6be3..0a3b2b0 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -490,7 +490,7 @@
Set<AppVpnInfo> result = new ArraySet<>();
for (UserHandle profile : mUserManager.getUserProfiles()) {
final int profileId = profile.getIdentifier();
- final String packageName = mConnectivityManager.getAlwaysOnVpnPackageForUser(profileId);
+ final String packageName = mVpnManager.getAlwaysOnVpnPackageForUser(profileId);
if (packageName != null) {
result.add(new AppVpnInfo(profileId, packageName));
}
diff --git a/src/com/android/settings/vpn2/VpnUtils.java b/src/com/android/settings/vpn2/VpnUtils.java
index c6b79b4..4c9338c 100644
--- a/src/com/android/settings/vpn2/VpnUtils.java
+++ b/src/com/android/settings/vpn2/VpnUtils.java
@@ -16,7 +16,6 @@
package com.android.settings.vpn2;
import android.content.Context;
-import android.net.ConnectivityManager;
import android.net.VpnManager;
import android.os.RemoteException;
import android.provider.Settings;
@@ -43,15 +42,15 @@
public static void clearLockdownVpn(Context context) {
KeyStore.getInstance().delete(Credentials.LOCKDOWN_VPN);
- // Always notify ConnectivityManager after keystore update
- getConnectivityManager(context).updateLockdownVpn();
+ // Always notify VpnManager after keystore update
+ getVpnManager(context).updateLockdownVpn();
}
public static void setLockdownVpn(Context context, String lockdownKey) {
KeyStore.getInstance().put(Credentials.LOCKDOWN_VPN, lockdownKey.getBytes(),
KeyStore.UID_SELF, /* flags */ 0);
- // Always notify ConnectivityManager after keystore update
- getConnectivityManager(context).updateLockdownVpn();
+ // Always notify VpnManager after keystore update
+ getVpnManager(context).updateLockdownVpn();
}
public static boolean isVpnLockdown(String key) {
@@ -63,7 +62,7 @@
if (getLockdownVpn() != null) {
return true;
}
- return getConnectivityManager(context).getAlwaysOnVpnPackageForUser(userId) != null
+ return getVpnManager(context).getAlwaysOnVpnPackageForUser(userId) != null
&& Settings.Secure.getIntForUser(context.getContentResolver(),
Settings.Secure.ALWAYS_ON_VPN_LOCKDOWN, /* default */ 0, userId) != 0;
}
@@ -77,16 +76,12 @@
return config != null ? config.user : null;
}
- private static ConnectivityManager getConnectivityManager(Context context) {
- return context.getSystemService(ConnectivityManager.class);
- }
-
private static VpnManager getVpnManager(Context context) {
return context.getSystemService(VpnManager.class);
}
- public static boolean isAlwaysOnVpnSet(ConnectivityManager cm, final int userId) {
- return cm.getAlwaysOnVpnPackageForUser(userId) != null;
+ public static boolean isAlwaysOnVpnSet(VpnManager vm, final int userId) {
+ return vm.getAlwaysOnVpnPackageForUser(userId) != null;
}
public static boolean disconnectLegacyVpn(Context context) {
diff --git a/src/com/android/settings/wifi/WifiSummaryUpdater.java b/src/com/android/settings/wifi/WifiSummaryUpdater.java
index 79bab36..19ef200 100644
--- a/src/com/android/settings/wifi/WifiSummaryUpdater.java
+++ b/src/com/android/settings/wifi/WifiSummaryUpdater.java
@@ -74,6 +74,7 @@
@Override
public void register(boolean register) {
if (register) {
+ mWifiTracker.fetchInitialState();
notifyChangeIfNeeded();
mContext.registerReceiver(mReceiver, INTENT_FILTER);
} else {
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index c28267b..28a7906 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -39,7 +39,7 @@
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.net.ConnectivityManager;
-import android.net.ProxyInfo;
+import android.net.VpnManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -91,6 +91,8 @@
private UserManager mUserManager;
@Mock
private ConnectivityManager mConnectivityManger;
+ @Mock
+ private VpnManager mVpnManager;
private Resources mResources;
private EnterprisePrivacyFeatureProvider mProvider;
@@ -106,7 +108,7 @@
mResources = RuntimeEnvironment.application.getResources();
mProvider = new EnterprisePrivacyFeatureProviderImpl(mContext, mDevicePolicyManager,
- mPackageManager, mUserManager, mConnectivityManger, mResources);
+ mPackageManager, mUserManager, mConnectivityManger, mVpnManager, mResources);
}
@Test
@@ -208,11 +210,10 @@
@Test
public void testIsAlwaysOnVpnSetInCurrentUser() {
- when(mConnectivityManger.getAlwaysOnVpnPackageForUser(mUserId)).thenReturn(null);
+ when(mVpnManager.getAlwaysOnVpnPackageForUser(mUserId)).thenReturn(null);
assertThat(mProvider.isAlwaysOnVpnSetInCurrentUser()).isFalse();
- when(mConnectivityManger.getAlwaysOnVpnPackageForUser(mUserId))
- .thenReturn(VPN_PACKAGE_ID);
+ when(mVpnManager.getAlwaysOnVpnPackageForUser(mUserId)).thenReturn(VPN_PACKAGE_ID);
assertThat(mProvider.isAlwaysOnVpnSetInCurrentUser()).isTrue();
}
@@ -222,26 +223,15 @@
mProfiles.add(new UserInfo(mManagedProfileUserId, "", "", UserInfo.FLAG_MANAGED_PROFILE));
- when(mConnectivityManger.getAlwaysOnVpnPackageForUser(mManagedProfileUserId))
- .thenReturn(null);
+ when(mVpnManager.getAlwaysOnVpnPackageForUser(mManagedProfileUserId)).thenReturn(null);
assertThat(mProvider.isAlwaysOnVpnSetInManagedProfile()).isFalse();
- when(mConnectivityManger.getAlwaysOnVpnPackageForUser(mManagedProfileUserId))
+ when(mVpnManager.getAlwaysOnVpnPackageForUser(mManagedProfileUserId))
.thenReturn(VPN_PACKAGE_ID);
assertThat(mProvider.isAlwaysOnVpnSetInManagedProfile()).isTrue();
}
@Test
- public void testIsGlobalHttpProxySet() {
- when(mConnectivityManger.getGlobalProxy()).thenReturn(null);
- assertThat(mProvider.isGlobalHttpProxySet()).isFalse();
-
- when(mConnectivityManger.getGlobalProxy())
- .thenReturn(ProxyInfo.buildDirectProxy("localhost", 123));
- assertThat(mProvider.isGlobalHttpProxySet()).isTrue();
- }
-
- @Test
public void testGetMaximumFailedPasswordsForWipeInCurrentUser() {
when(mDevicePolicyManager.getDeviceOwnerComponentOnCallingUser()).thenReturn(null);
when(mDevicePolicyManager.getProfileOwnerAsUser(mUserId)).thenReturn(null);
diff --git a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
index 05d1c64..11676a2 100644
--- a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
@@ -21,11 +21,11 @@
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.ProxyInfo;
import androidx.preference.Preference;
-import com.android.settings.testutils.FakeFeatureFactory;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,25 +41,23 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
- private FakeFeatureFactory mFeatureFactory;
+ @Mock
+ private ConnectivityManager mCm;
private GlobalHttpProxyPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mFeatureFactory = FakeFeatureFactory.setupForTest();
mController = new GlobalHttpProxyPreferenceController(mContext);
}
@Test
public void testIsAvailable() {
- when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
- .thenReturn(false);
+ when(mCm.getGlobalProxy()).thenReturn(null);
assertThat(mController.isAvailable()).isFalse();
- when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
- .thenReturn(true);
+ when(mCm.getGlobalProxy()).thenReturn(ProxyInfo.buildDirectProxy("localhost", 123));
assertThat(mController.isAvailable()).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
index 71a80de..5feee60 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
@@ -24,19 +24,17 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
-import android.provider.DeviceConfig;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.ImageView;
import android.widget.TextView;
+import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.Utils;
+import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import com.android.settingslib.location.RecentLocationAccesses;
-import com.android.settingslib.widget.LayoutPreference;
import org.junit.After;
import org.junit.Before;
@@ -55,11 +53,14 @@
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowDeviceConfig.class})
public class RecentLocationAccessPreferenceControllerTest {
+ private static final String PREFERENCE_KEY = "test_preference_key";
@Mock
- private LayoutPreference mLayoutPreference;
+ private PreferenceCategory mLayoutPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
+ private DashboardFragment mDashboardFragment;
+ @Mock
private RecentLocationAccesses mRecentLocationApps;
private Context mContext;
@@ -71,15 +72,16 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = spy(
- new RecentLocationAccessPreferenceController(mContext, mRecentLocationApps));
+ new RecentLocationAccessPreferenceController(mContext, PREFERENCE_KEY,
+ mRecentLocationApps));
+ mController.init(mDashboardFragment);
final String key = mController.getPreferenceKey();
mAppEntitiesHeaderView = LayoutInflater.from(mContext).inflate(
R.layout.app_entities_header, null /* root */);
when(mScreen.findPreference(key)).thenReturn(mLayoutPreference);
when(mLayoutPreference.getKey()).thenReturn(key);
when(mLayoutPreference.getContext()).thenReturn(mContext);
- when(mLayoutPreference.findViewById(R.id.app_entities_header)).thenReturn(
- mAppEntitiesHeaderView);
+ when(mDashboardFragment.getContext()).thenReturn(mContext);
}
@After
@@ -88,16 +90,7 @@
}
@Test
- public void isAvailable_permissionHubNotSet_shouldReturnFalse() {
- // We have not yet set the property to show the Permissions Hub.
- assertThat(mController.isAvailable()).isEqualTo(false);
- }
-
- @Test
- public void isAvailable_permissionHubEnabled_shouldReturnTrue() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
-
+ public void isAvailable_shouldReturnTrue() {
assertThat(mController.isAvailable()).isEqualTo(true);
}
@@ -118,39 +111,6 @@
assertThat(details.hasOnClickListeners()).isTrue();
}
- @Test
- public void updateState_whenAppListMoreThanThree_shouldDisplayTopThreeApps() {
- final List<RecentLocationAccesses.Access> accesses = createMockAccesses(6);
- doReturn(accesses).when(mRecentLocationApps).getAppListSorted();
- mController.displayPreference(mScreen);
- mController.updateState(mLayoutPreference);
-
- // The widget can display the top 3 apps from the list when there're more than 3.
- final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view);
- final ImageView appIconView1 = app1View.findViewById(R.id.app_icon);
- final TextView appTitle1 = app1View.findViewById(R.id.app_title);
-
- assertThat(app1View.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(appIconView1.getDrawable()).isNotNull();
- assertThat(appTitle1.getText()).isEqualTo("appTitle0");
-
- final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view);
- final ImageView appIconView2 = app2View.findViewById(R.id.app_icon);
- final TextView appTitle2 = app2View.findViewById(R.id.app_title);
-
- assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(appIconView2.getDrawable()).isNotNull();
- assertThat(appTitle2.getText()).isEqualTo("appTitle1");
-
- final View app3View = mAppEntitiesHeaderView.findViewById(R.id.app3_view);
- final ImageView appIconView3 = app3View.findViewById(R.id.app_icon);
- final TextView appTitle3 = app3View.findViewById(R.id.app_title);
-
- assertThat(app3View.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(appIconView3.getDrawable()).isNotNull();
- assertThat(appTitle3.getText()).isEqualTo("appTitle2");
- }
-
private List<RecentLocationAccesses.Access> createMockAccesses(int count) {
final List<RecentLocationAccesses.Access> accesses = new ArrayList<>();
for (int i = 0; i < count; i++) {
diff --git a/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
index 89d0465fa..fb66d29 100644
--- a/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
@@ -30,11 +30,9 @@
import android.content.Context;
import android.net.ConnectivityManager;
-import android.net.IConnectivityManager;
import android.net.NetworkRequest;
-import android.os.IBinder;
+import android.net.VpnManager;
import android.os.UserHandle;
-import android.os.ServiceManager;
import android.provider.SettingsSlicesContract;
import androidx.lifecycle.LifecycleOwner;
@@ -60,9 +58,7 @@
@Mock
private ConnectivityManager mConnectivityManager;
@Mock
- private IBinder mBinder;
- @Mock
- private IConnectivityManager mConnectivityManagerService;
+ private VpnManager mVpnManager;
@Mock
private PreferenceScreen mScreen;
@Mock
@@ -76,9 +72,7 @@
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
.thenReturn(mConnectivityManager);
- when(mBinder.queryLocalInterface("android.net.IConnectivityManager"))
- .thenReturn(mConnectivityManagerService);
- ServiceManager.addService(Context.CONNECTIVITY_SERVICE, mBinder);
+ when(mContext.getSystemService(VpnManager.class)).thenReturn(mVpnManager);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
mController = spy(new VpnPreferenceController(mContext));
diff --git a/tests/robotests/src/com/android/settings/notification/AssistantFeedbackPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AssistantFeedbackPreferenceControllerTest.java
deleted file mode 100644
index 9f172a6..0000000
--- a/tests/robotests/src/com/android/settings/notification/AssistantFeedbackPreferenceControllerTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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;
-
-import static android.provider.Settings.Global.NOTIFICATION_FEEDBACK_ENABLED;
-
-import static com.android.settings.notification.AssistantFeedbackPreferenceController.OFF;
-import static com.android.settings.notification.AssistantFeedbackPreferenceController.ON;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.provider.DeviceConfig;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.TwoStatePreference;
-
-import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.testutils.shadow.ShadowDeviceConfig;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-
-@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowDeviceConfig.class})
-public class AssistantFeedbackPreferenceControllerTest {
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private PreferenceScreen mScreen;
-
- private AssistantFeedbackPreferenceController mController;
- private Preference mPreference;
-
- private static final String KEY = "asst_feedback_indicator";
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mController = new AssistantFeedbackPreferenceController(mContext, KEY);
- mPreference = new Preference(RuntimeEnvironment.application);
- mPreference.setKey(mController.getPreferenceKey());
- when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
- }
-
- @After
- public void tearDown() {
- ShadowDeviceConfig.reset();
- }
-
- @Test
- public void testIsVisible_DeviceConfigOn() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
- SystemUiDeviceConfigFlags.ENABLE_NAS_FEEDBACK, "true", true);
- mController.displayPreference(mScreen);
-
- assertThat(mPreference.isVisible()).isTrue();
- }
-
- @Test
- public void testIsVisible_DeviceConfigOff() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
- SystemUiDeviceConfigFlags.ENABLE_NAS_FEEDBACK, "false", true);
- mController.displayPreference(mScreen);
-
- assertThat(mPreference.isVisible()).isFalse();
- }
-
- @Test
- public void getAvailabilityStatus_DeviceConfigOn_returnAvailable() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
- SystemUiDeviceConfigFlags.ENABLE_NAS_FEEDBACK, "true", true);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.AVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_DeviceConfigOff_returnUnavailable() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
- SystemUiDeviceConfigFlags.ENABLE_NAS_FEEDBACK, "false", true);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
- }
-
- @Test
- public void updateState_preferenceSetCheckedWhenSettingIsOn() {
- final TwoStatePreference preference = mock(TwoStatePreference.class);
- final Context context = RuntimeEnvironment.application;
- Settings.Global.putInt(context.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);
-
- mController = new AssistantFeedbackPreferenceController(context, KEY);
- mController.updateState(preference);
-
- verify(preference).setChecked(true);
- }
-
- @Test
- public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
- final TwoStatePreference preference = mock(TwoStatePreference.class);
- final Context context = RuntimeEnvironment.application;
- Settings.Global.putInt(context.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);
-
- mController = new AssistantFeedbackPreferenceController(context, KEY);
- mController.updateState(preference);
-
- verify(preference).setChecked(false);
- }
-
- @Test
- public void isChecked_settingIsOff_shouldReturnFalse() {
- Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);
-
- assertThat(mController.isChecked()).isFalse();
- }
-
- @Test
- public void isChecked_settingIsOn_shouldReturnTrue() {
- Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);
-
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void setChecked_setFalse_disablesSetting() {
- Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);
-
- mController.setChecked(false);
- int updatedValue = Settings.Global.getInt(mContext.getContentResolver(),
- NOTIFICATION_FEEDBACK_ENABLED, -1);
-
- assertThat(updatedValue).isEqualTo(OFF);
- }
-
- @Test
- public void setChecked_setTrue_enablesSetting() {
- Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);
-
- mController.setChecked(true);
- int updatedValue = Settings.Global.getInt(mContext.getContentResolver(),
- NOTIFICATION_FEEDBACK_ENABLED, -1);
-
- assertThat(updatedValue).isEqualTo(ON);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/notification/app/AddToHomeScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/AddToHomeScreenPreferenceControllerTest.java
index 342f3ad..b21991d 100644
--- a/tests/robotests/src/com/android/settings/notification/app/AddToHomeScreenPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/AddToHomeScreenPreferenceControllerTest.java
@@ -22,7 +22,9 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import android.app.NotificationChannel;
import android.content.Context;
import android.content.pm.ShortcutInfo;
@@ -30,6 +32,8 @@
import com.android.settings.notification.NotificationBackend;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,12 +42,16 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class AddToHomeScreenPreferenceControllerTest {
private Context mContext;
@Mock
private NotificationBackend mBackend;
+ @Mock
+ private NotificationChannel mNc;
private AddToHomeScreenPreferenceController mController;
@@ -52,6 +60,7 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new AddToHomeScreenPreferenceController(mContext, mBackend);
+ when(mNc.getImportance()).thenReturn(4);
}
@Test
@@ -62,21 +71,41 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable() {
ShortcutInfo si = mock(ShortcutInfo.class);
- mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null);
+ mController.onResume(mock(NotificationBackend.AppRow.class),
+ mNc, null, null, si, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ ShortcutInfo si = mock(ShortcutInfo.class);
+ mController.onResume(mock(NotificationBackend.AppRow.class),
+ mNc, null, null, si, null,
+ ImmutableList.of(NotificationChannel.EDIT_LAUNCHER));
+ assertTrue(mController.isAvailable());
+ }
+
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ ShortcutInfo si = mock(ShortcutInfo.class);
+ mController.onResume(mock(NotificationBackend.AppRow.class),
+ mNc, null, null, si, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testHandlePreferenceTreeClick() {
ShortcutInfo si = mock(ShortcutInfo.class);
- mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null);
+ mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null,
+ null);
Preference pref = new Preference(RuntimeEnvironment.application);
pref.setKey("add_to_home");
diff --git a/tests/robotests/src/com/android/settings/notification/app/AllowSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/AllowSoundPreferenceControllerTest.java
index 49d0a1d..be663d8 100644
--- a/tests/robotests/src/com/android/settings/notification/app/AllowSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/AllowSoundPreferenceControllerTest.java
@@ -44,6 +44,8 @@
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,6 +56,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class AllowSoundPreferenceControllerTest {
@@ -92,10 +96,11 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, mock(NotificationChannel.class), null, null, null, null);
+ mController.onResume(null, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
- mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null);
+ mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null,
+ null);
assertFalse(mController.isAvailable());
}
@@ -103,7 +108,7 @@
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +117,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something new");
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,16 +127,37 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
+ mController.onResume(appRow, channel, null, null, null, null, ImmutableList.of(
+ NotificationChannel.EDIT_SOUND));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -145,7 +171,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("");
when(channel.isImportanceLockedByOEM()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -158,7 +184,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -170,7 +196,8 @@
public void testUpdateState_checkedForHighImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -181,7 +208,8 @@
public void testUpdateState_checkedForUnspecifiedImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -192,7 +220,8 @@
public void testUpdateState_notCheckedForLowImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -203,7 +232,8 @@
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -220,7 +250,8 @@
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/AppBubbleListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/AppBubbleListPreferenceControllerTest.java
index d176827..53ef86c 100644
--- a/tests/robotests/src/com/android/settings/notification/app/AppBubbleListPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/AppBubbleListPreferenceControllerTest.java
@@ -104,7 +104,7 @@
public void isAvailable_BUBBLE_PREFERENCE_NONE_false() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertThat(mController.isAvailable()).isFalse();
}
@@ -113,7 +113,7 @@
public void isAvailable_BUBBLE_PREFERENCE_SELECTED_true() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -122,7 +122,7 @@
public void isAvailable_BUBBLE_PREFERENCE_ALL_true() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -131,7 +131,7 @@
public void filterAndSortConversations_BUBBLE_PREFERENCE_SELECTED_filtersAllowedBubbles() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
List<ConversationChannelWrapper> result =
mController.filterAndSortConversations(mConvoList.getList());
@@ -144,7 +144,7 @@
public void filterAndSortConversations_BUBBLE_PREFERENCE_ALL_filtersExcludedBubbles() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
List<ConversationChannelWrapper> result =
mController.filterAndSortConversations(mConvoList.getList());
@@ -158,7 +158,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
appRow.pkg = "PKG";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
mController.mPreference = new PreferenceCategory(mContext);
ConversationChannelWrapper ccw = mConvoList.getList().get(0);
diff --git a/tests/robotests/src/com/android/settings/notification/app/AppLinkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/AppLinkPreferenceControllerTest.java
index 41aeacb..2a23abd 100644
--- a/tests/robotests/src/com/android/settings/notification/app/AppLinkPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/AppLinkPreferenceControllerTest.java
@@ -75,7 +75,7 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -83,7 +83,7 @@
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -92,7 +92,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -102,7 +102,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -113,16 +113,21 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_alwaysFiltered() {
+ assertFalse(mController.isIncludedInFilter());
+ }
+
+ @Test
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
Intent intent = new Intent("action");
appRow.settingsIntent = intent;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/BadgePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/BadgePreferenceControllerTest.java
index 277e6b2..9cdf64d 100644
--- a/tests/robotests/src/com/android/settings/notification/app/BadgePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/BadgePreferenceControllerTest.java
@@ -47,6 +47,8 @@
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,6 +59,9 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+import java.util.List;
+
@RunWith(RobolectricTestRunner.class)
public class BadgePreferenceControllerTest {
@@ -93,7 +98,7 @@
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -102,7 +107,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +117,7 @@
appRow.showBadge = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,7 +127,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 0);
assertFalse(mController.isAvailable());
@@ -131,7 +136,7 @@
@Test
public void testIsAvailable_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -144,7 +149,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -156,7 +161,7 @@
appRow.showBadge = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -168,18 +173,43 @@
appRow.showBadge = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertFalse(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = true;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
+
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = true;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_LAUNCHER));
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
+
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
- null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
+ null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -193,7 +223,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("");
when(channel.isImportanceLockedByOEM()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -206,7 +236,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canShowBadge()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -214,7 +244,7 @@
assertTrue(pref.isChecked());
when(channel.canShowBadge()).thenReturn(false);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -224,14 +254,14 @@
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
assertTrue(pref.isChecked());
appRow.showBadge = false;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -244,7 +274,7 @@
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setShowBadge(false);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -263,7 +293,7 @@
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setShowBadge(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -279,7 +309,7 @@
public void testOnPreferenceChange_on_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = false;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -296,7 +326,7 @@
public void testOnPreferenceChange_off_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/BlockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/BlockPreferenceControllerTest.java
index 90c743a..d65f91d 100644
--- a/tests/robotests/src/com/android/settings/notification/app/BlockPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/BlockPreferenceControllerTest.java
@@ -59,6 +59,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class BlockPreferenceControllerTest {
@@ -102,7 +104,7 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +114,7 @@
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -122,7 +124,7 @@
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -132,7 +134,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -140,7 +142,8 @@
public void testIsAvailable_GroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
- mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
+ mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
+ null);
assertTrue(mController.isAvailable());
}
@@ -148,7 +151,7 @@
public void testIsAvailable_AppNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -158,17 +161,41 @@
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
- public void testIsAvailable_nonSystemApp() {
+ public void testIsAvailable_nonSystemApp_noFilter() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = false;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ ArrayList<String> filter = new ArrayList<>();
+ filter.add("no");
+ mController.onResume(appRow, channel, null, null, null, null, filter);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = false;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ ArrayList<String> filter = new ArrayList<>();
+ filter.add(NotificationChannel.EDIT_IMPORTANCE);
+ mController.onResume(appRow, channel, null, null, null, null, filter);
assertTrue(mController.isAvailable());
}
@@ -177,7 +204,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedImportance = true;
appRow.systemApp = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.getSwitchBar().isEnabled());
}
@@ -186,7 +213,8 @@
public void testIsEnabled_GroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
- mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
+ mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
+ null);
mController.updateState(mPreference);
assertFalse(mPreference.getSwitchBar().isEnabled());
}
@@ -195,7 +223,7 @@
public void testIsEnabled_systemAppNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.getSwitchBar().isEnabled());
}
@@ -206,7 +234,7 @@
appRow.systemApp = true;
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setBlockable(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mPreference.getSwitchBar().isEnabled());
}
@@ -217,7 +245,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
@@ -230,7 +258,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
@@ -242,7 +270,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
@@ -252,7 +280,7 @@
@Test
public void testIsEnabled_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
@@ -263,13 +291,13 @@
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = false;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mPreference.isChecked());
@@ -280,20 +308,20 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = true;
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
when(group.isBlocked()).thenReturn(true);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = false;
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
when(group.isBlocked()).thenReturn(false);
mController.updateState(mPreference);
@@ -304,21 +332,21 @@
public void testUpdateState_channelBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = true;
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mPreference.isChecked());
appRow.banned = false;
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mPreference.isChecked());
@@ -328,7 +356,7 @@
public void testUpdateState_noCrashIfCalledTwice() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
mController.updateState(mPreference);
}
@@ -337,7 +365,7 @@
public void testUpdateState_doesNotResetImportance() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
assertEquals(IMPORTANCE_LOW, channel.getImportance());
@@ -350,7 +378,7 @@
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_UNSPECIFIED);
when(mBackend.onlyHasDefaultChannel(anyString(), anyInt())).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
mController.onSwitchChanged(null, false);
@@ -372,7 +400,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
channel.setOriginalImportance(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
mController.onSwitchChanged(null, false);
diff --git a/tests/robotests/src/com/android/settings/notification/app/BubblePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/BubblePreferenceControllerTest.java
index ea963e3..f4f99c7 100644
--- a/tests/robotests/src/com/android/settings/notification/app/BubblePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/BubblePreferenceControllerTest.java
@@ -60,6 +60,8 @@
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -125,7 +127,7 @@
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -135,7 +137,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -146,7 +148,7 @@
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -154,7 +156,7 @@
@Test
public void isNotAvailable_ifOffGlobally_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -164,7 +166,7 @@
@Test
public void isNotAvailable_ifLowRam() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
@@ -178,7 +180,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -188,7 +190,7 @@
@Test
public void isAvailable_ifNotLowRam() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
final ShadowActivityManager activityManager =
@@ -200,7 +202,7 @@
@Test
public void isAvailable_app_evenIfOffGlobally() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -210,7 +212,7 @@
@Test
public void isAvailable_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -223,7 +225,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -235,18 +237,43 @@
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
}
@Test
+ public void isAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
+ Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
+
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
+
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void updateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
- null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
+ null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -261,7 +288,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
mAppPageController.onResume(appRow, channel, null,
- null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
+ null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
BubblePreference pref = new BubblePreference(mContext);
mAppPageController.updateState(pref);
@@ -276,7 +303,7 @@
appRow.pkg = "a";
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -291,7 +318,7 @@
appRow.pkg = "a";
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBubble()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -299,7 +326,7 @@
assertTrue(pref.isChecked());
when(channel.canBubble()).thenReturn(false);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -312,20 +339,20 @@
appRow.pkg = "a";
appRow.label = "App!";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
mAppPageController.updateState(pref);
assertEquals(BUBBLE_PREFERENCE_ALL, pref.getSelectedPreference());
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
mAppPageController.updateState(pref);
assertEquals(BUBBLE_PREFERENCE_NONE, pref.getSelectedPreference());
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
mAppPageController.updateState(pref);
assertEquals(BUBBLE_PREFERENCE_SELECTED, pref.getSelectedPreference());
@@ -339,7 +366,7 @@
appRow.pkg = "a";
appRow.label = "App!";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
mAppPageController.updateState(pref);
@@ -354,7 +381,7 @@
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -374,7 +401,7 @@
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -393,7 +420,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -413,7 +440,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -433,7 +460,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -452,7 +479,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -471,7 +498,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "a";
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mAppPageController.onResume(appRow, null, null, null, null, null);
+ mAppPageController.onResume(appRow, null, null, null, null, null, null);
BubblePreference pref = new BubblePreference(mContext);
mAppPageController.onPreferenceChange(pref, BUBBLE_PREFERENCE_NONE);
diff --git a/tests/robotests/src/com/android/settings/notification/app/BubbleSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/BubbleSummaryPreferenceControllerTest.java
index f851c96..911f9a2 100644
--- a/tests/robotests/src/com/android/settings/notification/app/BubbleSummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/BubbleSummaryPreferenceControllerTest.java
@@ -23,8 +23,6 @@
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
-import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_OFF;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_ON;
@@ -92,14 +90,14 @@
public void isAvailable_appBlocked_shouldReturnFalse() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_NOTIFICATION_BUBBLESisOn_shouldReturnTrue() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
- mController.onResume(mAppRow, null, null, null, null, null);
+ mController.onResume(mAppRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -107,7 +105,7 @@
@Test
public void isAvailable_NOTIFICATION_BUBBLESisOn_neverSentMsg_shouldReturnFalse() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
- mController.onResume(mAppRow, null, null, null, null, null);
+ mController.onResume(mAppRow, null, null, null, null, null, null);
when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(false);
assertFalse(mController.isAvailable());
@@ -117,7 +115,7 @@
public void isAvailable_NOTIFICATION_BUBBLESisOff_shouldReturnFalse() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
SYSTEM_WIDE_OFF);
- mController.onResume(mAppRow, null, null, null, null, null);
+ mController.onResume(mAppRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -128,7 +126,7 @@
SYSTEM_WIDE_OFF);
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(mAppRow, channel, null, null, null, null);
+ mController.onResume(mAppRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -139,7 +137,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(mAppRow, channel, null, null, null, null);
+ mController.onResume(mAppRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -147,7 +145,7 @@
@Test
public void isAvailable_lowRam_shouldReturnFalse() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
- mController.onResume(mAppRow, null, null, null, null, null);
+ mController.onResume(mAppRow, null, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
@@ -158,7 +156,7 @@
@Test
public void isAvailable_notLowRam_shouldReturnTrue() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
- mController.onResume(mAppRow, null, null, null, null, null);
+ mController.onResume(mAppRow, null, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
@@ -169,7 +167,7 @@
@Test
public void updateState_setsIntent() {
mAppRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mController.onResume(mAppRow, null, null, null, null, null);
+ mController.onResume(mAppRow, null, null, null, null, null, null);
Preference pref = new Preference(mContext);
mController.updateState(pref);
@@ -182,7 +180,7 @@
SYSTEM_WIDE_OFF);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
String noneString = mContext.getString(R.string.bubble_app_setting_none);
assertEquals(noneString, mController.getSummary());
@@ -195,7 +193,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
String noneString = mContext.getString(R.string.bubble_app_setting_none);
assertEquals(noneString, mController.getSummary());
@@ -208,7 +206,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
String allString = mContext.getString(R.string.bubble_app_setting_all);
assertEquals(allString, mController.getSummary());
@@ -221,7 +219,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
String selectedString = mContext.getString(R.string.bubble_app_setting_selected);
assertEquals(selectedString, mController.getSummary());
diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationDemotePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationDemotePreferenceControllerTest.java
index 89007f0..0591cf2 100644
--- a/tests/robotests/src/com/android/settings/notification/app/ConversationDemotePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/ConversationDemotePreferenceControllerTest.java
@@ -36,6 +36,8 @@
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.NotificationBackend;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,6 +48,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class ConversationDemotePreferenceControllerTest {
@@ -79,7 +83,7 @@
public void testIsAvailable_notConversation() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -89,7 +93,7 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -99,17 +103,38 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(false);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ channel.setConversationId("a", "a");
+ channel.setDemoted(false);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ channel.setConversationId("a", "a");
+ channel.setDemoted(false);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testHandlePreferenceClick() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(false);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("demote");
diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationHeaderPreferenceControllerTest.java
index 428a1a8..9b166ac 100644
--- a/tests/robotests/src/com/android/settings/notification/app/ConversationHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/ConversationHeaderPreferenceControllerTest.java
@@ -49,6 +49,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class ConversationHeaderPreferenceControllerTest {
@@ -88,7 +90,7 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -96,7 +98,15 @@
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_ignoresFilter() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
assertTrue(mController.isAvailable());
}
@@ -105,11 +115,11 @@
ShortcutInfo si = mock(ShortcutInfo.class);
when(si.getLabel()).thenReturn("hello");
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, si, null);
+ mController.onResume(appRow, null, null, null, si, null, null);
assertEquals(si.getLabel(), mController.getLabel());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertEquals(channel.getName(), mController.getLabel());
}
@@ -117,25 +127,25 @@
public void testGetSummary() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertEquals("", mController.getSummary());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertEquals(appRow.label, mController.getSummary());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
- mController.onResume(appRow, channel, group, null, null, null);
+ mController.onResume(appRow, channel, group, null, null, null, null);
assertTrue(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
- mController.onResume(appRow, defaultChannel, null, null, null, null);
+ mController.onResume(appRow, defaultChannel, null, null, null, null, null);
assertEquals("", mController.getSummary());
}
}
diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceControllerTest.java
index d74715c..692a4b1 100644
--- a/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceControllerTest.java
@@ -34,7 +34,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
@@ -47,6 +46,8 @@
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,6 +58,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class ConversationPriorityPreferenceControllerTest {
@@ -95,7 +98,7 @@
@Test
public void testIsAvailable_notChannelNull() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -103,16 +106,37 @@
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
+ assertTrue(mController.isAvailable());
+
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
@@ -126,7 +150,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
@@ -141,7 +165,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
@@ -156,7 +180,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
@@ -170,7 +194,7 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setImportantConversation(true);
channel.setOriginalImportance(IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
ConversationPriorityPreference pref = mock(ConversationPriorityPreference.class);
mController.updateState(pref);
@@ -185,7 +209,8 @@
public void testImportanceLowToImportant() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -203,7 +228,8 @@
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setAllowBubbles(false);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -222,7 +248,8 @@
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
channel.setAllowBubbles(false);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -241,7 +268,8 @@
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setAllowBubbles(true);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -261,7 +289,8 @@
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setAllowBubbles(true);
channel.setImportantConversation(true);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
index 80e2dd5..1c049be 100644
--- a/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
@@ -38,6 +38,8 @@
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.NotificationBackend;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -48,6 +50,9 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.sql.Array;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class ConversationPromotePreferenceControllerTest {
@@ -81,7 +86,7 @@
public void testIsAvailable_notConversation() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -90,7 +95,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -100,18 +105,39 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ channel.setConversationId("a", "a");
+ channel.setDemoted(true);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ channel.setConversationId("a", "a");
+ channel.setDemoted(true);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testHandlePreferenceClick() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
channel.setBypassDnd(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("convo_promote");
@@ -133,7 +159,7 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("wrong");
diff --git a/tests/robotests/src/com/android/settings/notification/app/DeletedChannelsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/DeletedChannelsPreferenceControllerTest.java
index 5515a55..5c9de7c 100644
--- a/tests/robotests/src/com/android/settings/notification/app/DeletedChannelsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/DeletedChannelsPreferenceControllerTest.java
@@ -46,6 +46,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class DeletedChannelsPreferenceControllerTest {
@@ -79,14 +81,15 @@
public void isAvailable_appScreen_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_groupScreen_never() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
+ mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
+ null);
assertFalse(mController.isAvailable());
}
@@ -94,28 +97,29 @@
public void isAvailable_channelScreen_never() {
mController.onResume(
new NotificationBackend.AppRow(), mock(NotificationChannel.class), null, null, null,
- null);
+ null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_appScreen_notIfNoDeletedChannels() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(0);
- mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_appScreen() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
- mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
+ mController.onResume(
+ new NotificationBackend.AppRow(), null, null, null, null, null, new ArrayList<>());
assertTrue(mController.isAvailable());
}
@Test
public void updateState() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
- mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null, null);
Preference pref = mock(Preference.class);
mController.updateState(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/DescriptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/DescriptionPreferenceControllerTest.java
index 3e37327..3ce67a2 100644
--- a/tests/robotests/src/com/android/settings/notification/app/DescriptionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/DescriptionPreferenceControllerTest.java
@@ -74,7 +74,7 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -82,7 +82,7 @@
public void testIsAvailable_notIfChannelGroupBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -91,7 +91,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -100,7 +100,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -108,7 +108,7 @@
public void testIsAvailable_notIfNoChannelGroupDesc() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -118,7 +118,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getDescription()).thenReturn("AAA");
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -128,17 +128,22 @@
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.getDescription()).thenReturn("something");
when(group.isBlocked()).thenReturn(false);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_alwaysFiltered() {
+ assertFalse(mController.isIncludedInFilter());
+ }
+
+ @Test
public void testUpdateState_channel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getDescription()).thenReturn("AAA");
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -153,7 +158,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.getDescription()).thenReturn("something");
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/DndPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/DndPreferenceControllerTest.java
index 4220bed..22a7b09 100644
--- a/tests/robotests/src/com/android/settings/notification/app/DndPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/DndPreferenceControllerTest.java
@@ -44,6 +44,8 @@
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,6 +56,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class DndPreferenceControllerTest {
@@ -83,7 +87,7 @@
public void testIsAvailable_app() {
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -93,16 +97,37 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_ZEN));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -115,7 +140,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -128,7 +153,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -140,7 +165,8 @@
public void testUpdateState_bypassDnd() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBypassDnd()).thenReturn(true);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -152,7 +178,8 @@
public void testUpdateState_noBypassDnd() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBypassDnd()).thenReturn(false);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -164,7 +191,8 @@
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -182,7 +210,8 @@
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
diff --git a/tests/robotests/src/com/android/settings/notification/app/HeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/HeaderPreferenceControllerTest.java
index c4e94a9..9f90a16 100644
--- a/tests/robotests/src/com/android/settings/notification/app/HeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/HeaderPreferenceControllerTest.java
@@ -48,6 +48,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class HeaderPreferenceControllerTest {
@@ -87,7 +89,7 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -95,7 +97,15 @@
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_ignoredFilter() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
assertTrue(mController.isAvailable());
}
@@ -103,20 +113,20 @@
public void testGetLabel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertEquals(appRow.label, mController.getLabel());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertEquals(group.getName(), mController.getLabel());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
- mController.onResume(appRow, channel, group, null, null, null);
+ mController.onResume(appRow, channel, group, null, null, null, null);
assertEquals(channel.getName(), mController.getLabel());
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
- mController.onResume(appRow, defaultChannel, null, null, null, null);
+ mController.onResume(appRow, defaultChannel, null, null, null, null, null);
assertEquals(appRow.label, mController.getLabel());
}
@@ -124,25 +134,25 @@
public void testGetSummary() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertEquals("", mController.getSummary());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertEquals(appRow.label, mController.getSummary());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
- mController.onResume(appRow, channel, group, null, null, null);
+ mController.onResume(appRow, channel, group, null, null, null, null);
assertTrue(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
- mController.onResume(appRow, defaultChannel, null, null, null, null);
+ mController.onResume(appRow, defaultChannel, null, null, null, null, null);
assertEquals("", mController.getSummary());
}
}
diff --git a/tests/robotests/src/com/android/settings/notification/app/HighImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/HighImportancePreferenceControllerTest.java
index 150fd2a..0db4678 100644
--- a/tests/robotests/src/com/android/settings/notification/app/HighImportancePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/HighImportancePreferenceControllerTest.java
@@ -52,6 +52,10 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.google.common.collect.ImmutableList;
+
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class HighImportancePreferenceControllerTest {
@@ -88,7 +92,7 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -96,7 +100,7 @@
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -105,7 +109,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -115,7 +119,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -124,16 +128,35 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -147,7 +170,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -162,7 +185,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -177,7 +200,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -189,7 +212,7 @@
public void testUpdateState_high() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -201,7 +224,7 @@
public void testUpdateState_default() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -213,7 +236,8 @@
public void onPreferenceChange() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/ImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ImportancePreferenceControllerTest.java
index 3de7e7c..223fa23 100644
--- a/tests/robotests/src/com/android/settings/notification/app/ImportancePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/ImportancePreferenceControllerTest.java
@@ -48,6 +48,8 @@
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,6 +60,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class ImportancePreferenceControllerTest {
@@ -94,7 +98,7 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -102,7 +106,7 @@
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -113,7 +117,7 @@
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
- mController.onResume(appRow, channel, group, null, null, null);
+ mController.onResume(appRow, channel, group, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,7 +126,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -132,7 +136,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -141,16 +145,35 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -164,7 +187,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -179,7 +202,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -194,7 +217,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -206,7 +229,7 @@
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
ImportancePreference pref = mock(ImportancePreference.class);
mController.updateState(pref);
@@ -221,7 +244,8 @@
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
ImportancePreference pref = new ImportancePreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -239,7 +263,8 @@
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
ImportancePreference pref = new ImportancePreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceControllerTest.java
index aa87539..eb80465 100644
--- a/tests/robotests/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceControllerTest.java
@@ -24,6 +24,7 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
@@ -34,6 +35,8 @@
import com.android.settings.notification.NotificationBackend;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.google.common.collect.ImmutableList;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -46,6 +49,8 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class InvalidConversationInfoPreferenceControllerTest {
@@ -90,7 +95,7 @@
appRow.pkg = "hi";
appRow.uid = 0;
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -100,7 +105,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -110,18 +115,39 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.pkg = "hi";
+ appRow.uid = 0;
+ mController.onResume(appRow, null, null, null, null, null, ImmutableList.of(
+ NotificationChannel.EDIT_CONVERSATION));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.pkg = "hi";
+ appRow.uid = 0;
+ mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState() {
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
appRow.label = "plum";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
Preference pref = new Preference(mContext);
mController.updateState(pref);
assertTrue(pref.getSummary().toString().contains(appRow.label));
diff --git a/tests/robotests/src/com/android/settings/notification/app/InvalidConversationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/InvalidConversationPreferenceControllerTest.java
index 4bfc1b4..965191c 100644
--- a/tests/robotests/src/com/android/settings/notification/app/InvalidConversationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/InvalidConversationPreferenceControllerTest.java
@@ -16,10 +16,6 @@
package com.android.settings.notification.app;
-import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
-import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
-import static android.app.NotificationManager.IMPORTANCE_HIGH;
-
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -45,6 +41,8 @@
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.google.common.collect.ImmutableList;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -57,6 +55,8 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class InvalidConversationPreferenceControllerTest {
@@ -102,7 +102,7 @@
appRow.pkg = "hi";
appRow.uid = 0;
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +112,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,17 +122,38 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.pkg = "hi";
+ appRow.uid = 0;
+ mController.onResume(appRow, null, null, null, null, null, ImmutableList.of(
+ NotificationChannel.EDIT_CONVERSATION));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.pkg = "hi";
+ appRow.uid = 0;
+ mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "hi";
appRow.uid = 0;
mController.onResume(appRow, null, null,
- null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
+ null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -144,7 +165,7 @@
public void testUpdateState_notChecked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "pkg";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
@@ -157,7 +178,7 @@
public void testUpdateState_checked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "pkg";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
@@ -170,7 +191,7 @@
public void testOnPreferenceChange_toggleEnabled() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "pkg";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
@@ -189,7 +210,7 @@
public void testOnPreferenceChange_toggleDisabled() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.pkg = "pkg";
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
diff --git a/tests/robotests/src/com/android/settings/notification/app/LightsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/LightsPreferenceControllerTest.java
index 4f3b496..e51a9e0 100644
--- a/tests/robotests/src/com/android/settings/notification/app/LightsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/LightsPreferenceControllerTest.java
@@ -46,6 +46,8 @@
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.google.common.collect.ImmutableList;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -58,6 +60,10 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
+import javax.annotation.concurrent.Immutable;
+
@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class LightsPreferenceControllerTest {
@@ -107,7 +113,7 @@
com.android.internal.R.bool.config_intrusiveNotificationLed, false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -116,7 +122,7 @@
Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -124,7 +130,7 @@
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -133,7 +139,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -141,16 +147,33 @@
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_LOCKED_DEVICE));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
- null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
+ null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -163,7 +186,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -175,7 +198,8 @@
public void testUpdateState_lightsOn() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldShowLights()).thenReturn(true);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -186,7 +210,8 @@
public void testUpdateState_lightsOff() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldShowLights()).thenReturn(false);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -197,7 +222,8 @@
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -214,7 +240,8 @@
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(mContext);
diff --git a/tests/robotests/src/com/android/settings/notification/app/MinImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/MinImportancePreferenceControllerTest.java
index f046820..3907db2 100644
--- a/tests/robotests/src/com/android/settings/notification/app/MinImportancePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/MinImportancePreferenceControllerTest.java
@@ -52,6 +52,10 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.google.common.collect.ImmutableList;
+
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class MinImportancePreferenceControllerTest {
@@ -88,7 +92,7 @@
@Test
public void testIsAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -96,7 +100,7 @@
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -105,7 +109,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -115,7 +119,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -124,16 +128,35 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -147,7 +170,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -162,7 +185,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -177,7 +200,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -189,7 +212,7 @@
public void testUpdateState_min() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -201,7 +224,7 @@
public void testUpdateState_low() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -213,7 +236,8 @@
public void onPreferenceChange() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java
index a9e4361..1fb9942 100644
--- a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java
@@ -54,6 +54,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class NotificationPreferenceControllerTest {
@@ -90,7 +92,7 @@
@Test
public void isAvailable_notIfNull() {
- mController.onResume(null, null, null, null, null, null);
+ mController.onResume(null, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -99,7 +101,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class),
- mock(NotificationChannelGroup.class), null, null, null);
+ mock(NotificationChannelGroup.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -111,7 +113,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, group, null, null, null);
+ mController.onResume(appRow, channel, group, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,12 +124,26 @@
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
- mController.onResume(appRow, channel, group, null, null, null);
+ mController.onResume(appRow, channel, group, null, null, null, null);
when(group.isBlocked()).thenReturn(true);
assertFalse(mController.isAvailable());
}
@Test
+ public void isAvailable_notIfFailsFilterCheck() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
+ NotificationChannelGroup group = mock(NotificationChannelGroup.class);
+ when(group.isBlocked()).thenReturn(false);
+ ArrayList<String> filter = new ArrayList<>();
+ filter.add("something");
+
+ mController.onResume(appRow, channel, group, null, null, null, filter);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void isAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
@@ -135,7 +151,7 @@
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
- mController.onResume(appRow, channel, group, null, null, null);
+ mController.onResume(appRow, channel, group, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -146,7 +162,7 @@
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
RestrictedLockUtils.EnforcedAdmin admin = mock(RestrictedLockUtils.EnforcedAdmin.class);
- mController.onResume(appRow, channel, group, null, null, admin);
+ mController.onResume(appRow, channel, group, null, null, admin, null);
assertEquals(appRow, mController.mAppRow);
assertEquals(channel, mController.mChannel);
@@ -160,7 +176,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
}
@@ -170,7 +186,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_LOW));
}
@@ -180,7 +196,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
}
@@ -190,7 +206,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.checkCanBeVisible(IMPORTANCE_DEFAULT));
}
@@ -200,7 +216,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
mController.saveChannel();
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
}
@@ -212,11 +228,11 @@
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
when(channel.isImportanceLockedByOEM()).thenReturn(false);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -227,7 +243,7 @@
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -238,7 +254,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isBlockable()).thenReturn(false);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -250,7 +266,7 @@
when(channel.isBlockable()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -261,7 +277,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isBlockable()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -273,7 +289,7 @@
when(channel.isBlockable()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -284,7 +300,7 @@
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertTrue(mController.isChannelGroupBlockable());
}
@@ -296,7 +312,7 @@
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -308,7 +324,7 @@
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -319,7 +335,7 @@
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertFalse(mController.isChannelGroupBlockable());
}
@@ -330,13 +346,14 @@
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertTrue(mController.isChannelGroupBlockable());
}
@Test
public void testIsDefaultChannel_noChannel() {
- mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null);
+ mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null,
+ null);
assertFalse(mController.isDefaultChannel());
}
@@ -344,7 +361,8 @@
@Test
public void testIsDefaultChannel_nonDefaultChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
- mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null, null);
+ mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null,
+ null, null);
assertFalse(mController.isDefaultChannel());
}
@@ -353,7 +371,8 @@
public void testIsDefaultChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(NotificationChannel.DEFAULT_CHANNEL_ID);
- mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null, null);
+ mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null,
+ null, null);
assertTrue(mController.isDefaultChannel());
}
@@ -365,6 +384,11 @@
}
@Override
+ boolean isIncludedInFilter() {
+ return false;
+ }
+
+ @Override
public String getPreferenceKey() {
return null;
}
diff --git a/tests/robotests/src/com/android/settings/notification/app/NotificationsOffPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/NotificationsOffPreferenceControllerTest.java
index cfbe5f7..34e94a0 100644
--- a/tests/robotests/src/com/android/settings/notification/app/NotificationsOffPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/NotificationsOffPreferenceControllerTest.java
@@ -34,6 +34,8 @@
import com.android.settings.notification.NotificationBackend;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,6 +45,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class NotificationsOffPreferenceControllerTest {
@@ -72,7 +76,7 @@
public void testIsAvailable_yesIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -81,7 +85,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -90,16 +94,35 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void testUpdateState_channel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -113,7 +136,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
- mController.onResume(appRow, null, group, null, null, null);
+ mController.onResume(appRow, null, group, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -126,7 +149,7 @@
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
diff --git a/tests/robotests/src/com/android/settings/notification/app/SoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/SoundPreferenceControllerTest.java
index 0d18c1f..c79b97d 100644
--- a/tests/robotests/src/com/android/settings/notification/app/SoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/SoundPreferenceControllerTest.java
@@ -53,6 +53,8 @@
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -65,6 +67,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class SoundPreferenceControllerTest {
@@ -108,7 +112,7 @@
@Test
public void testIsAvailable_notIfChannelNull() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
- mController.onResume(appRow, null, null, null, null, null);
+ mController.onResume(appRow, null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -116,7 +120,7 @@
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -125,7 +129,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -133,11 +137,28 @@
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_SOUND));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testDisplayPreference_savesPreference() {
NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -152,7 +173,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
@@ -166,7 +187,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
@@ -182,7 +203,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
when(channel.getSound()).thenReturn(sound);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref = new NotificationSoundPreference(mContext, attributeSet);
@@ -198,7 +219,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(sound, Notification.AUDIO_ATTRIBUTES_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -238,7 +259,7 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_ALARM).build());
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -259,7 +280,7 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build());
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -280,7 +301,7 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_UNKNOWN).build());
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
diff --git a/tests/robotests/src/com/android/settings/notification/app/VibrationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/VibrationPreferenceControllerTest.java
index 06a319f..0fb5e72 100644
--- a/tests/robotests/src/com/android/settings/notification/app/VibrationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/VibrationPreferenceControllerTest.java
@@ -45,6 +45,8 @@
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,6 +57,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+
@RunWith(RobolectricTestRunner.class)
public class VibrationPreferenceControllerTest {
@@ -98,7 +102,7 @@
when(mVibrator.hasVibrator()).thenReturn(false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -106,7 +110,7 @@
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -115,7 +119,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -123,16 +127,33 @@
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_VIBRATION));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -145,7 +166,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -158,7 +179,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -170,7 +191,8 @@
public void testUpdateState_vibrateOn() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldVibrate()).thenReturn(true);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -182,7 +204,8 @@
public void testUpdateState_vibrateOff() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldVibrate()).thenReturn(false);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -194,7 +217,8 @@
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -210,7 +234,8 @@
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
- mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
+ null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
diff --git a/tests/robotests/src/com/android/settings/notification/app/VisibilityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/VisibilityPreferenceControllerTest.java
index 2150c82..a061208 100644
--- a/tests/robotests/src/com/android/settings/notification/app/VisibilityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/VisibilityPreferenceControllerTest.java
@@ -51,6 +51,8 @@
import com.android.settings.testutils.shadow.ShadowRestrictionUtils;
import com.android.settingslib.RestrictedLockUtils;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -121,7 +123,7 @@
when(mLockUtils.isSecure(anyInt())).thenReturn(false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -129,7 +131,7 @@
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -138,15 +140,32 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
+ public void testIsAvailable_filteredIn() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null,
+ ImmutableList.of(NotificationChannel.EDIT_LOCKED_DEVICE));
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_filteredOut() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
public void testUpdateState_disabledByAdmin_disableSecure() {
ShadowRestrictionUtils.setRestricted(true);
UserInfo userInfo = new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE);
@@ -160,7 +179,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -182,7 +201,7 @@
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
- RestrictedLockUtils.EnforcedAdmin.class));
+ RestrictedLockUtils.EnforcedAdmin.class), null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -197,7 +216,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -222,7 +241,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -245,7 +264,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -262,7 +281,7 @@
public void testUpdateState_noGlobalRestriction() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -293,7 +312,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -312,7 +331,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -331,7 +350,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", 4);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -350,7 +369,7 @@
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", 4);
channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
- mController.onResume(appRow, channel, null, null, null, null);
+ mController.onResume(appRow, channel, null, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
index 02bf172..1ae31e8 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
@@ -65,6 +65,14 @@
}
@Test
+ public void register_true_shouldFetchInitialStateAndSendSummaryChange() {
+ mSummaryUpdater.register(true);
+
+ verify(mWifiTracker).fetchInitialState();
+ verify(mListener).onSummaryChanged(anyString());
+ }
+
+ @Test
public void register_false_shouldUnregisterListenerAndTracker() {
mSummaryUpdater.register(true);
mSummaryUpdater.register(false);
diff --git a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java
new file mode 100644
index 0000000..9b9bb11
--- /dev/null
+++ b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.network.telephony;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidJUnit4.class)
+public final class Enable2gPreferenceControllerTest {
+ private static final int SUB_ID = 2;
+
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private CarrierConfigManager mCarrierConfigManager;
+
+ private PersistableBundle mPersistableBundle;
+ private Enable2gPreferenceController mController;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
+ when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
+ when(mContext.getSystemService(CarrierConfigManager.class))
+ .thenReturn(mCarrierConfigManager);
+
+ doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
+
+ mPersistableBundle = new PersistableBundle();
+ doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
+ doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ mController = new Enable2gPreferenceController(mContext, "mobile_data");
+ mController.init(SUB_ID);
+ }
+
+ @Test
+ public void getAvailabilityStatus_invalidSubId_returnUnavailable() {
+ mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_hideEnable2g_returnUnavailable() {
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
+ true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_nullCarrierConfig_returnUnavailable() {
+ doReturn(true).when(mTelephonyManager).isRadioInterfaceCapabilitySupported(
+ mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
+ false);
+ doReturn(null).when(mCarrierConfigManager);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_capabilityNotSupported_returnUnavailable() {
+ doReturn(false).when(mTelephonyManager).isRadioInterfaceCapabilitySupported(
+ mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
+ false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_returnAvailable() {
+ doReturn(true).when(mTelephonyManager).isRadioInterfaceCapabilitySupported(
+ mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED);
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
+ false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+}
diff --git a/tests/unit/src/com/android/settings/vpn2/VpnUtilsTest.java b/tests/unit/src/com/android/settings/vpn2/VpnUtilsTest.java
index f214764..ff5bb81 100644
--- a/tests/unit/src/com/android/settings/vpn2/VpnUtilsTest.java
+++ b/tests/unit/src/com/android/settings/vpn2/VpnUtilsTest.java
@@ -21,7 +21,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import android.net.ConnectivityManager;
+import android.net.VpnManager;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -32,11 +32,11 @@
public final class VpnUtilsTest {
@Test
public void testIsAlwaysOnVpnSet() {
- final ConnectivityManager cm = mock(ConnectivityManager.class);
- when(cm.getAlwaysOnVpnPackageForUser(0)).thenReturn("com.example.vpn");
- assertThat(VpnUtils.isAlwaysOnVpnSet(cm, 0)).isTrue();
+ final VpnManager vm = mock(VpnManager.class);
+ when(vm.getAlwaysOnVpnPackageForUser(0)).thenReturn("com.example.vpn");
+ assertThat(VpnUtils.isAlwaysOnVpnSet(vm, 0)).isTrue();
- when(cm.getAlwaysOnVpnPackageForUser(0)).thenReturn(null);
- assertThat(VpnUtils.isAlwaysOnVpnSet(cm, 0)).isFalse();
+ when(vm.getAlwaysOnVpnPackageForUser(0)).thenReturn(null);
+ assertThat(VpnUtils.isAlwaysOnVpnSet(vm, 0)).isFalse();
}
}