Merge "Fix the talkback problem of the "Verified link info" icon" into sc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2857bf5..8839323 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9030,6 +9030,7 @@
<string name="notif_listener_excluded_app_title">See all apps</string>
<string name="notif_listener_excluded_app_summary">Change notification settings for each app that can send notifications</string>
<string name="notif_listener_excluded_app_screen_title">Apps shown on device</string>
+ <string name="notif_listener_not_migrated">This app doesn\u2019t support enhanced settings</string>
<!-- Title for managing VR (virtual reality) helper services. [CHAR LIMIT=50] -->
<string name="vr_listeners_title">VR helper services</string>
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index bebb336..ac51a82 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -44,7 +44,7 @@
settings:searchable="true"/>
<!--TODO(b/170973645): Get icon-->
- <Preference
+ <com.android.settings.widget.PrimarySwitchPreference
android:fragment="com.android.settings.accessibility.ToggleReduceBrightColorsPreferenceFragment"
android:key="reduce_bright_colors_preference"
android:persistent="false"
diff --git a/res/xml/notification_access_permission_details.xml b/res/xml/notification_access_permission_details.xml
index c4bb7f0..cec383c 100644
--- a/res/xml/notification_access_permission_details.xml
+++ b/res/xml/notification_access_permission_details.xml
@@ -62,6 +62,13 @@
android:summary="@string/notif_listener_excluded_app_summary"
android:fragment="com.android.settings.applications.specialaccess.notificationaccess.BridgedAppsSettings"
settings:searchable="false"
- settings:controller="com.android.settings.applications.specialaccess.notificationaccess.BridgedAppsPreferenceController" />
+ settings:controller="com.android.settings.applications.specialaccess.notificationaccess.BridgedAppsLinkPreferenceController" />
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="notif_listener_not_migrated"
+ android:title="@string/notif_listener_not_migrated"
+ settings:controller="com.android.settings.applications.specialaccess.notificationaccess.PreUpgradePreferenceController"
+ android:selectable="false"
+ settings:searchable="false"/>
</PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java b/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java
index bfe61b7..037969d 100644
--- a/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java
+++ b/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 The Android Open Source Project
+ * 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.
@@ -17,17 +17,60 @@
package com.android.settings.accessibility;
import android.content.Context;
+import android.database.ContentObserver;
import android.hardware.display.ColorDisplayManager;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.widget.PrimarySwitchPreference;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
/** PreferenceController that shows the Reduce Bright Colors summary */
-public class ReduceBrightColorsPreferenceController extends BasePreferenceController {
+public class ReduceBrightColorsPreferenceController extends TogglePreferenceController
+ implements LifecycleObserver, OnStart, OnStop {
+ private ContentObserver mSettingsContentObserver;
+ private PrimarySwitchPreference mPreference;
+ private final Context mContext;
public ReduceBrightColorsPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
+ mContext = context;
+ mSettingsContentObserver = new ContentObserver(new Handler(Looper.getMainLooper())){
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ final String path = uri == null ? null : uri.getLastPathSegment();
+ if (TextUtils.equals(path, Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED)) {
+ updateState(mPreference);
+ }
+ }
+ };
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.Secure.getIntForUser(mContext.getContentResolver(),
+ Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED,
+ 0,
+ UserHandle.USER_CURRENT) == 1;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return Settings.Secure.putIntForUser(mContext.getContentResolver(),
+ Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, isChecked ? 1 : 0,
+ UserHandle.USER_CURRENT);
}
@Override
@@ -37,8 +80,31 @@
}
@Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ refreshSummary(preference);
+ }
+
+ @Override
public int getAvailabilityStatus() {
return ColorDisplayManager.isColorTransformAccelerated(mContext) ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void onStart() {
+ mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED),
+ false, mSettingsContentObserver, UserHandle.USER_CURRENT);
+ }
+ @Override
+ public void onStop() {
+ mContext.getContentResolver().unregisterContentObserver(mSettingsContentObserver);
+ }
}
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsLinkPreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsLinkPreferenceController.java
new file mode 100644
index 0000000..1c787ba
--- /dev/null
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsLinkPreferenceController.java
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+package com.android.settings.applications.specialaccess.notificationaccess;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.os.Build;
+import android.service.notification.NotificationListenerFilter;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.notification.NotificationBackend;
+
+
+public class BridgedAppsLinkPreferenceController extends BasePreferenceController {
+
+ private ComponentName mCn;
+ private int mUserId;
+ private NotificationBackend mNm;
+ private NotificationListenerFilter mNlf;
+ private int mTargetSdk;
+
+ public BridgedAppsLinkPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+
+ public BridgedAppsLinkPreferenceController setCn(ComponentName cn) {
+ mCn = cn;
+ return this;
+ }
+
+ public BridgedAppsLinkPreferenceController setUserId(int userId) {
+ mUserId = userId;
+ return this;
+ }
+
+ public BridgedAppsLinkPreferenceController setNm(NotificationBackend nm) {
+ mNm = nm;
+ return this;
+ }
+
+ public BridgedAppsLinkPreferenceController setTargetSdk(int targetSdk) {
+ mTargetSdk = targetSdk;
+ return this;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (mNm.isNotificationListenerAccessGranted(mCn)) {
+ if (mTargetSdk > Build.VERSION_CODES.S) {
+ return AVAILABLE;
+ }
+
+ mNlf = mNm.getListenerFilter(mCn, mUserId);
+ if (!mNlf.areAllTypesAllowed() || !mNlf.getDisallowedPackages().isEmpty()) {
+ return AVAILABLE;
+ }
+ }
+ return DISABLED_DEPENDENT_SETTING;
+ }
+}
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsPreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsPreferenceController.java
index 7ff3c9c..c56f630 100644
--- a/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsPreferenceController.java
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsPreferenceController.java
@@ -16,14 +16,11 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.VersionedPackage;
-import android.os.UserHandle;
import android.service.notification.NotificationListenerFilter;
-import androidx.annotation.VisibleForTesting;
import androidx.preference.CheckBoxPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
import com.android.settings.applications.AppStateBaseBridge;
import com.android.settings.core.BasePreferenceController;
@@ -126,9 +123,6 @@
final int N = apps.size();
for (int i = 0; i < N; i++) {
final AppEntry entry = apps.get(i);
- if (!shouldAddPreference(entry)) {
- continue;
- }
final String prefKey = entry.info.packageName + "|" + entry.info.uid;
appsKeySet.add(prefKey);
CheckBoxPreference preference = mScreen.findPreference(prefKey);
@@ -211,9 +205,4 @@
}
}
}
-
- @VisibleForTesting
- static boolean shouldAddPreference(AppEntry app) {
- return app != null && UserHandle.isApp(app.info.uid);
- }
}
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsSettings.java b/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsSettings.java
index d396a01..21497eb 100644
--- a/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsSettings.java
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsSettings.java
@@ -69,7 +69,7 @@
case MENU_SHOW_SYSTEM:
mShowSystem = !mShowSystem;
item.setTitle(mShowSystem ? R.string.menu_hide_system : R.string.menu_show_system);
- mFilter = mShowSystem ? ApplicationsState.FILTER_ALL_ENABLED
+ mFilter = mShowSystem ? ApplicationsState.FILTER_NOT_HIDE
: ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER;
use(BridgedAppsPreferenceController.class).setFilter(mFilter).rebuild();
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/NotificationAccessDetails.java b/src/com/android/settings/applications/specialaccess/notificationaccess/NotificationAccessDetails.java
index 1ac578d..9e03657 100644
--- a/src/com/android/settings/applications/specialaccess/notificationaccess/NotificationAccessDetails.java
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/NotificationAccessDetails.java
@@ -22,6 +22,8 @@
import android.app.NotificationManager;
import android.app.settings.SettingsEnums;
import android.companion.ICompanionDeviceManager;
+import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledAfter;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -29,6 +31,7 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
+import android.os.Build;
import android.os.Bundle;
import android.os.ServiceManager;
import android.os.UserHandle;
@@ -88,11 +91,18 @@
mPm = getPackageManager();
retrieveAppEntry();
loadNotificationListenerService();
+ NotificationBackend backend = new NotificationBackend();
+ int listenerTargetSdk = Build.VERSION_CODES.S;
+ try {
+ listenerTargetSdk = mPm.getTargetSdkVersion(mComponentName.getPackageName());
+ } catch (PackageManager.NameNotFoundException e){
+ // how did we get here?
+ }
use(ApprovalPreferenceController.class)
.setPkgInfo(mPackageInfo)
.setCn(mComponentName)
.setNm(context.getSystemService(NotificationManager.class))
- .setPm(context.getPackageManager())
+ .setPm(mPm)
.setParent(this);
use(HeaderPreferenceController.class)
.setFragment(this)
@@ -104,15 +114,27 @@
ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE)))
.setCn(mComponentName)
.setUserId(mUserId);
+ use(PreUpgradePreferenceController.class)
+ .setNm(backend)
+ .setCn(mComponentName)
+ .setUserId(mUserId)
+ .setTargetSdk(listenerTargetSdk);
+ use(BridgedAppsLinkPreferenceController.class)
+ .setNm(backend)
+ .setCn(mComponentName)
+ .setUserId(mUserId)
+ .setTargetSdk(listenerTargetSdk);
+ final int finalListenerTargetSdk = listenerTargetSdk;
getPreferenceControllers().forEach(controllers -> {
controllers.forEach(controller -> {
if (controller instanceof TypeFilterPreferenceController) {
TypeFilterPreferenceController tfpc =
(TypeFilterPreferenceController) controller;
- tfpc.setNm(new NotificationBackend())
+ tfpc.setNm(backend)
.setCn(mComponentName)
.setServiceInfo(mServiceInfo)
- .setUserId(mUserId);
+ .setUserId(mUserId)
+ .setTargetSdk(finalListenerTargetSdk);
}
});
});
@@ -154,7 +176,7 @@
setIntentAndFinish(true /* appChanged */);
}
Preference apps = getPreferenceScreen().findPreference(
- use(BridgedAppsPreferenceController.class).getPreferenceKey());
+ use(BridgedAppsLinkPreferenceController.class).getPreferenceKey());
if (apps != null) {
apps.setOnPreferenceClickListener(preference -> {
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/PreUpgradePreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/PreUpgradePreferenceController.java
new file mode 100644
index 0000000..743fd55
--- /dev/null
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/PreUpgradePreferenceController.java
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.applications.specialaccess.notificationaccess;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.os.Build;
+import android.service.notification.NotificationListenerFilter;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.notification.NotificationBackend;
+
+public class PreUpgradePreferenceController extends BasePreferenceController {
+
+ private ComponentName mCn;
+ private int mUserId;
+ private NotificationBackend mNm;
+ private NotificationListenerFilter mNlf;
+ private int mTargetSdk;
+
+ public PreUpgradePreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ public PreUpgradePreferenceController setCn(ComponentName cn) {
+ mCn = cn;
+ return this;
+ }
+
+ public PreUpgradePreferenceController setUserId(int userId) {
+ mUserId = userId;
+ return this;
+ }
+
+ public PreUpgradePreferenceController setNm(NotificationBackend nm) {
+ mNm = nm;
+ return this;
+ }
+
+ public PreUpgradePreferenceController setTargetSdk(int targetSdk) {
+ mTargetSdk = targetSdk;
+ return this;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (mNm.isNotificationListenerAccessGranted(mCn)) {
+ mNlf = mNm.getListenerFilter(mCn, mUserId);
+
+ if (mTargetSdk > Build.VERSION_CODES.S) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+
+ if (!mNlf.areAllTypesAllowed() || !mNlf.getDisallowedPackages().isEmpty()) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ return AVAILABLE;
+ } else {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/TypeFilterPreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/TypeFilterPreferenceController.java
index a5ac1e1..68c342b 100644
--- a/src/com/android/settings/applications/specialaccess/notificationaccess/TypeFilterPreferenceController.java
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/TypeFilterPreferenceController.java
@@ -19,6 +19,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ServiceInfo;
+import android.os.Build;
import android.service.notification.NotificationListenerFilter;
import android.service.notification.NotificationListenerService;
import android.text.TextUtils;
@@ -41,6 +42,7 @@
private NotificationBackend mNm;
private NotificationListenerFilter mNlf;
private ServiceInfo mSi;
+ private int mTargetSdk;
public TypeFilterPreferenceController(Context context, String key) {
super(context, key);
@@ -66,15 +68,26 @@
return this;
}
+ public TypeFilterPreferenceController setTargetSdk(int targetSdk) {
+ mTargetSdk = targetSdk;
+ return this;
+ }
+
abstract protected int getType();
@Override
public int getAvailabilityStatus() {
if (mNm.isNotificationListenerAccessGranted(mCn)) {
- return AVAILABLE;
- } else {
- return DISABLED_DEPENDENT_SETTING;
+ if (mTargetSdk > Build.VERSION_CODES.S) {
+ return AVAILABLE;
+ }
+
+ mNlf = mNm.getListenerFilter(mCn, mUserId);
+ if (!mNlf.areAllTypesAllowed() || !mNlf.getDisallowedPackages().isEmpty()) {
+ return AVAILABLE;
+ }
}
+ return DISABLED_DEPENDENT_SETTING;
}
private boolean hasFlag(int value, int flag) {
diff --git a/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java
index 01942f0..325e6a8 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
+import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -31,7 +32,6 @@
@RunWith(AndroidJUnit4.class)
public class ReduceBrightColorsPreferenceControllerTest {
private static final String PREF_KEY = "rbc_preference";
-
private final Context mContext = ApplicationProvider.getApplicationContext();
private final ReduceBrightColorsPreferenceController mController =
new ReduceBrightColorsPreferenceController(mContext, PREF_KEY);
@@ -41,4 +41,18 @@
assertThat(mController.getSummary().toString().contains(
mContext.getText(R.string.reduce_bright_colors_preference_summary))).isTrue();
}
+
+ @Test
+ public void isChecked_reduceBrightColorsIsActivated_returnTrue() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
+ assertThat(mController.isChecked()).isTrue();
+ }
+
+ @Test
+ public void isChecked_reduceBrightColorsIsNotActivated_returnFalse() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
+ assertThat(mController.isChecked()).isFalse();
+ }
}
diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsLinkPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsLinkPreferenceControllerTest.java
new file mode 100644
index 0000000..c594131
--- /dev/null
+++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/BridgedAppsLinkPreferenceControllerTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.applications.specialaccess.notificationaccess;
+
+import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_CONVERSATIONS;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.os.Build;
+import android.service.notification.NotificationListenerFilter;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settings.notification.NotificationBackend;
+
+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 class BridgedAppsLinkPreferenceControllerTest {
+
+ private Context mContext;
+ private BridgedAppsLinkPreferenceController mController;
+ @Mock
+ NotificationBackend mNm;
+ ComponentName mCn = new ComponentName("a", "b");
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = ApplicationProvider.getApplicationContext();
+
+ mController = new BridgedAppsLinkPreferenceController(mContext, "key");
+ mController.setCn(mCn);
+ mController.setNm(mNm);
+ mController.setUserId(0);
+ }
+
+ @Test
+ public void testAvailable_notGranted() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(false);
+ mController.setTargetSdk(Build.VERSION_CODES.CUR_DEVELOPMENT + 1);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
+ }
+
+ @Test
+ public void testAvailable_lowTargetSdk_noCustomizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.S);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
+ }
+
+ @Test
+ public void testAvailable_lowTargetSdk_customizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.S);
+ NotificationListenerFilter nlf = new NotificationListenerFilter();
+ nlf.setTypes(FLAG_FILTER_TYPE_CONVERSATIONS);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void testAvailable_highTargetSdk_noCustomizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.CUR_DEVELOPMENT + 1);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+}
diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/PreUpgradePreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/PreUpgradePreferenceControllerTest.java
new file mode 100644
index 0000000..d4008d4
--- /dev/null
+++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/PreUpgradePreferenceControllerTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.applications.specialaccess.notificationaccess;
+
+import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_CONVERSATIONS;
+
+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.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.os.Build;
+import android.service.notification.NotificationListenerFilter;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settings.notification.NotificationBackend;
+
+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 class PreUpgradePreferenceControllerTest {
+
+ private Context mContext;
+ private PreUpgradePreferenceController mController;
+ @Mock
+ NotificationBackend mNm;
+ ComponentName mCn = new ComponentName("a", "b");
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = ApplicationProvider.getApplicationContext();
+
+ mController = new PreUpgradePreferenceController(mContext, "key");
+ mController.setCn(mCn);
+ mController.setNm(mNm);
+ mController.setUserId(0);
+ }
+
+ @Test
+ public void testAvailable_notGranted() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(false);
+ mController.setTargetSdk(Build.VERSION_CODES.S);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void testAvailable_lowTargetSdk_noCustomizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.S);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void testAvailable_lowTargetSdk_customizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.S);
+ NotificationListenerFilter nlf = new NotificationListenerFilter();
+ nlf.setTypes(FLAG_FILTER_TYPE_CONVERSATIONS);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void testAvailable_highTargetSdk_noCustomizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.CUR_DEVELOPMENT + 1);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+}
diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/TypeFilterPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/TypeFilterPreferenceControllerTest.java
index d36f775..1aa8292 100644
--- a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/TypeFilterPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/TypeFilterPreferenceControllerTest.java
@@ -20,8 +20,12 @@
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ONGOING;
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_SILENT;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -29,6 +33,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ServiceInfo;
+import android.os.Build;
import android.os.Bundle;
import android.service.notification.NotificationListenerFilter;
import android.service.notification.NotificationListenerService;
@@ -81,6 +86,44 @@
mController.setNm(mNm);
mController.setServiceInfo(mSi);
mController.setUserId(0);
+ mController.setTargetSdk(Build.VERSION_CODES.CUR_DEVELOPMENT + 1);
+ }
+
+ @Test
+ public void testAvailable_notGranted() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(false);
+ mController.setTargetSdk(Build.VERSION_CODES.CUR_DEVELOPMENT + 1);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
+ }
+
+ @Test
+ public void testAvailable_lowTargetSdk_noCustomizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.S);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
+ }
+
+ @Test
+ public void testAvailable_lowTargetSdk_customizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.S);
+ NotificationListenerFilter nlf = new NotificationListenerFilter();
+ nlf.setTypes(FLAG_FILTER_TYPE_CONVERSATIONS);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void testAvailable_highTargetSdk_noCustomizations() {
+ when(mNm.isNotificationListenerAccessGranted(any())).thenReturn(true);
+ mController.setTargetSdk(Build.VERSION_CODES.CUR_DEVELOPMENT + 1);
+ when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test