Merge "Only show enhanced options for migrated apps" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6ca32df6b6
@@ -9030,6 +9030,7 @@
|
|||||||
<string name="notif_listener_excluded_app_title">See all apps</string>
|
<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_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_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] -->
|
<!-- Title for managing VR (virtual reality) helper services. [CHAR LIMIT=50] -->
|
||||||
<string name="vr_listeners_title">VR helper services</string>
|
<string name="vr_listeners_title">VR helper services</string>
|
||||||
|
@@ -62,6 +62,13 @@
|
|||||||
android:summary="@string/notif_listener_excluded_app_summary"
|
android:summary="@string/notif_listener_excluded_app_summary"
|
||||||
android:fragment="com.android.settings.applications.specialaccess.notificationaccess.BridgedAppsSettings"
|
android:fragment="com.android.settings.applications.specialaccess.notificationaccess.BridgedAppsSettings"
|
||||||
settings:searchable="false"
|
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>
|
</PreferenceScreen>
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -16,14 +16,11 @@ package com.android.settings.applications.specialaccess.notificationaccess;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.VersionedPackage;
|
import android.content.pm.VersionedPackage;
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.service.notification.NotificationListenerFilter;
|
import android.service.notification.NotificationListenerFilter;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.CheckBoxPreference;
|
import androidx.preference.CheckBoxPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
|
|
||||||
import com.android.settings.applications.AppStateBaseBridge;
|
import com.android.settings.applications.AppStateBaseBridge;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -126,9 +123,6 @@ public class BridgedAppsPreferenceController extends BasePreferenceController im
|
|||||||
final int N = apps.size();
|
final int N = apps.size();
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
final AppEntry entry = apps.get(i);
|
final AppEntry entry = apps.get(i);
|
||||||
if (!shouldAddPreference(entry)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final String prefKey = entry.info.packageName + "|" + entry.info.uid;
|
final String prefKey = entry.info.packageName + "|" + entry.info.uid;
|
||||||
appsKeySet.add(prefKey);
|
appsKeySet.add(prefKey);
|
||||||
CheckBoxPreference preference = mScreen.findPreference(prefKey);
|
CheckBoxPreference preference = mScreen.findPreference(prefKey);
|
||||||
@@ -211,9 +205,4 @@ public class BridgedAppsPreferenceController extends BasePreferenceController im
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static boolean shouldAddPreference(AppEntry app) {
|
|
||||||
return app != null && UserHandle.isApp(app.info.uid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -69,7 +69,7 @@ public class BridgedAppsSettings extends DashboardFragment {
|
|||||||
case MENU_SHOW_SYSTEM:
|
case MENU_SHOW_SYSTEM:
|
||||||
mShowSystem = !mShowSystem;
|
mShowSystem = !mShowSystem;
|
||||||
item.setTitle(mShowSystem ? R.string.menu_hide_system : R.string.menu_show_system);
|
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;
|
: ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER;
|
||||||
|
|
||||||
use(BridgedAppsPreferenceController.class).setFilter(mFilter).rebuild();
|
use(BridgedAppsPreferenceController.class).setFilter(mFilter).rebuild();
|
||||||
|
@@ -22,6 +22,8 @@ import android.app.Activity;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.companion.ICompanionDeviceManager;
|
import android.companion.ICompanionDeviceManager;
|
||||||
|
import android.compat.annotation.ChangeId;
|
||||||
|
import android.compat.annotation.EnabledAfter;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -29,6 +31,7 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -88,11 +91,18 @@ public class NotificationAccessDetails extends DashboardFragment {
|
|||||||
mPm = getPackageManager();
|
mPm = getPackageManager();
|
||||||
retrieveAppEntry();
|
retrieveAppEntry();
|
||||||
loadNotificationListenerService();
|
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)
|
use(ApprovalPreferenceController.class)
|
||||||
.setPkgInfo(mPackageInfo)
|
.setPkgInfo(mPackageInfo)
|
||||||
.setCn(mComponentName)
|
.setCn(mComponentName)
|
||||||
.setNm(context.getSystemService(NotificationManager.class))
|
.setNm(context.getSystemService(NotificationManager.class))
|
||||||
.setPm(context.getPackageManager())
|
.setPm(mPm)
|
||||||
.setParent(this);
|
.setParent(this);
|
||||||
use(HeaderPreferenceController.class)
|
use(HeaderPreferenceController.class)
|
||||||
.setFragment(this)
|
.setFragment(this)
|
||||||
@@ -104,15 +114,27 @@ public class NotificationAccessDetails extends DashboardFragment {
|
|||||||
ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE)))
|
ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE)))
|
||||||
.setCn(mComponentName)
|
.setCn(mComponentName)
|
||||||
.setUserId(mUserId);
|
.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 -> {
|
getPreferenceControllers().forEach(controllers -> {
|
||||||
controllers.forEach(controller -> {
|
controllers.forEach(controller -> {
|
||||||
if (controller instanceof TypeFilterPreferenceController) {
|
if (controller instanceof TypeFilterPreferenceController) {
|
||||||
TypeFilterPreferenceController tfpc =
|
TypeFilterPreferenceController tfpc =
|
||||||
(TypeFilterPreferenceController) controller;
|
(TypeFilterPreferenceController) controller;
|
||||||
tfpc.setNm(new NotificationBackend())
|
tfpc.setNm(backend)
|
||||||
.setCn(mComponentName)
|
.setCn(mComponentName)
|
||||||
.setServiceInfo(mServiceInfo)
|
.setServiceInfo(mServiceInfo)
|
||||||
.setUserId(mUserId);
|
.setUserId(mUserId)
|
||||||
|
.setTargetSdk(finalListenerTargetSdk);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -154,7 +176,7 @@ public class NotificationAccessDetails extends DashboardFragment {
|
|||||||
setIntentAndFinish(true /* appChanged */);
|
setIntentAndFinish(true /* appChanged */);
|
||||||
}
|
}
|
||||||
Preference apps = getPreferenceScreen().findPreference(
|
Preference apps = getPreferenceScreen().findPreference(
|
||||||
use(BridgedAppsPreferenceController.class).getPreferenceKey());
|
use(BridgedAppsLinkPreferenceController.class).getPreferenceKey());
|
||||||
if (apps != null) {
|
if (apps != null) {
|
||||||
|
|
||||||
apps.setOnPreferenceClickListener(preference -> {
|
apps.setOnPreferenceClickListener(preference -> {
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -19,6 +19,7 @@ package com.android.settings.applications.specialaccess.notificationaccess;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.os.Build;
|
||||||
import android.service.notification.NotificationListenerFilter;
|
import android.service.notification.NotificationListenerFilter;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -41,6 +42,7 @@ public abstract class TypeFilterPreferenceController extends BasePreferenceContr
|
|||||||
private NotificationBackend mNm;
|
private NotificationBackend mNm;
|
||||||
private NotificationListenerFilter mNlf;
|
private NotificationListenerFilter mNlf;
|
||||||
private ServiceInfo mSi;
|
private ServiceInfo mSi;
|
||||||
|
private int mTargetSdk;
|
||||||
|
|
||||||
public TypeFilterPreferenceController(Context context, String key) {
|
public TypeFilterPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
@@ -66,15 +68,26 @@ public abstract class TypeFilterPreferenceController extends BasePreferenceContr
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TypeFilterPreferenceController setTargetSdk(int targetSdk) {
|
||||||
|
mTargetSdk = targetSdk;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected int getType();
|
abstract protected int getType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (mNm.isNotificationListenerAccessGranted(mCn)) {
|
if (mNm.isNotificationListenerAccessGranted(mCn)) {
|
||||||
return AVAILABLE;
|
if (mTargetSdk > Build.VERSION_CODES.S) {
|
||||||
} else {
|
return AVAILABLE;
|
||||||
return DISABLED_DEPENDENT_SETTING;
|
}
|
||||||
|
|
||||||
|
mNlf = mNm.getListenerFilter(mCn, mUserId);
|
||||||
|
if (!mNlf.areAllTypesAllowed() || !mNlf.getDisallowedPackages().isEmpty()) {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasFlag(int value, int flag) {
|
private boolean hasFlag(int value, int flag) {
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -20,8 +20,12 @@ import static android.service.notification.NotificationListenerService.FLAG_FILT
|
|||||||
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ONGOING;
|
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ONGOING;
|
||||||
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_SILENT;
|
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 com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -29,6 +33,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.service.notification.NotificationListenerFilter;
|
import android.service.notification.NotificationListenerFilter;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
@@ -81,6 +86,44 @@ public class TypeFilterPreferenceControllerTest {
|
|||||||
mController.setNm(mNm);
|
mController.setNm(mNm);
|
||||||
mController.setServiceInfo(mSi);
|
mController.setServiceInfo(mSi);
|
||||||
mController.setUserId(0);
|
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
|
@Test
|
||||||
|
Reference in New Issue
Block a user