Snap for 10342904 from 7d837a745a
to udc-qpr1-release
Change-Id: Idaa9b939c41cb71cb2d3a705252a976f3ee9c952
This commit is contained in:
@@ -23,6 +23,7 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.data.ApnSetting;
|
import android.telephony.data.ApnSetting;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.network.MobileDataContentObserver;
|
import com.android.settings.network.MobileDataContentObserver;
|
||||||
@@ -38,6 +39,7 @@ public class MmsMessagePreferenceController extends TelephonyTogglePreferenceCon
|
|||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
private MobileDataContentObserver mMobileDataContentObserver;
|
private MobileDataContentObserver mMobileDataContentObserver;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
public MmsMessagePreferenceController(Context context, String key) {
|
public MmsMessagePreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
@@ -61,6 +63,7 @@ public class MmsMessagePreferenceController extends TelephonyTogglePreferenceCon
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
mMobileDataContentObserver.register(mContext, mSubId);
|
mMobileDataContentObserver.register(mContext, mSubId);
|
||||||
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +78,7 @@ public class MmsMessagePreferenceController extends TelephonyTogglePreferenceCon
|
|||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mScreen = screen;
|
mScreen = screen;
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -148,12 +148,13 @@ public class TetherSettings extends RestrictedSettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
// Even when the UI is restricted, addPreferencesFromResource cannot be omitted.
|
||||||
|
addPreferencesFromResource(R.xml.tether_prefs);
|
||||||
setIfOnlyAvailableForAdmins(true);
|
setIfOnlyAvailableForAdmins(true);
|
||||||
if (isUiRestricted()) {
|
if (isUiRestricted()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.tether_prefs);
|
|
||||||
mContext = getContext();
|
mContext = getContext();
|
||||||
mDataSaverBackend = new DataSaverBackend(mContext);
|
mDataSaverBackend = new DataSaverBackend(mContext);
|
||||||
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
||||||
|
@@ -43,6 +43,7 @@ import android.widget.Toast;
|
|||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.applications.AppInfoBase;
|
import com.android.settings.applications.AppInfoBase;
|
||||||
@@ -63,8 +64,8 @@ import java.util.List;
|
|||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
public class NotificationAccessSettings extends EmptyTextSettings {
|
public class NotificationAccessSettings extends EmptyTextSettings {
|
||||||
private static final String TAG = "NotifAccessSettings";
|
private static final String TAG = "NotifAccessSettings";
|
||||||
private static final String ALLOWED_KEY = "allowed";
|
static final String ALLOWED_KEY = "allowed";
|
||||||
private static final String NOT_ALLOWED_KEY = "not_allowed";
|
static final String NOT_ALLOWED_KEY = "not_allowed";
|
||||||
private static final int MAX_CN_LENGTH = 500;
|
private static final int MAX_CN_LENGTH = 500;
|
||||||
|
|
||||||
private static final ManagedServiceSettings.Config CONFIG =
|
private static final ManagedServiceSettings.Config CONFIG =
|
||||||
@@ -80,9 +81,9 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
|||||||
.setEmptyText(R.string.no_notification_listeners)
|
.setEmptyText(R.string.no_notification_listeners)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private NotificationManager mNm;
|
@VisibleForTesting NotificationManager mNm;
|
||||||
protected Context mContext;
|
protected Context mContext;
|
||||||
private PackageManager mPm;
|
@VisibleForTesting PackageManager mPm;
|
||||||
private DevicePolicyManager mDpm;
|
private DevicePolicyManager mDpm;
|
||||||
private ServiceListing mServiceListing;
|
private ServiceListing mServiceListing;
|
||||||
private IconDrawableFactory mIconDrawableFactory;
|
private IconDrawableFactory mIconDrawableFactory;
|
||||||
@@ -102,12 +103,6 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
|||||||
.setNoun(CONFIG.noun)
|
.setNoun(CONFIG.noun)
|
||||||
.setSetting(CONFIG.setting)
|
.setSetting(CONFIG.setting)
|
||||||
.setTag(CONFIG.tag)
|
.setTag(CONFIG.tag)
|
||||||
.setValidator(info -> {
|
|
||||||
if (info.getComponentName().flattenToString().length() > MAX_CN_LENGTH) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.build();
|
.build();
|
||||||
mServiceListing.addCallback(this::updateList);
|
mServiceListing.addCallback(this::updateList);
|
||||||
|
|
||||||
@@ -140,7 +135,8 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
|||||||
mServiceListing.setListening(false);
|
mServiceListing.setListening(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateList(List<ServiceInfo> services) {
|
@VisibleForTesting
|
||||||
|
void updateList(List<ServiceInfo> services) {
|
||||||
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||||
final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());
|
final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());
|
||||||
|
|
||||||
@@ -153,6 +149,11 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
|||||||
services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
|
services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
|
||||||
for (ServiceInfo service : services) {
|
for (ServiceInfo service : services) {
|
||||||
final ComponentName cn = new ComponentName(service.packageName, service.name);
|
final ComponentName cn = new ComponentName(service.packageName, service.name);
|
||||||
|
boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
|
||||||
|
if (!isAllowed && cn.flattenToString().length() > MAX_CN_LENGTH) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
CharSequence title = null;
|
CharSequence title = null;
|
||||||
try {
|
try {
|
||||||
title = mPm.getApplicationInfoAsUser(
|
title = mPm.getApplicationInfoAsUser(
|
||||||
@@ -200,7 +201,7 @@ public class NotificationAccessSettings extends EmptyTextSettings {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
pref.setKey(cn.flattenToString());
|
pref.setKey(cn.flattenToString());
|
||||||
if (mNm.isNotificationListenerAccessGranted(cn)) {
|
if (isAllowed) {
|
||||||
allowedCategory.addPreference(pref);
|
allowedCategory.addPreference(pref);
|
||||||
} else {
|
} else {
|
||||||
notAllowedCategory.addPreference(pref);
|
notAllowedCategory.addPreference(pref);
|
||||||
|
@@ -124,6 +124,9 @@ public class NotificationBackend {
|
|||||||
|
|
||||||
static public CharSequence getDeviceList(ICompanionDeviceManager cdm, LocalBluetoothManager lbm,
|
static public CharSequence getDeviceList(ICompanionDeviceManager cdm, LocalBluetoothManager lbm,
|
||||||
String pkg, int userId) {
|
String pkg, int userId) {
|
||||||
|
if (cdm == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
boolean multiple = false;
|
boolean multiple = false;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
@@ -94,7 +94,6 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
|
private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
|
||||||
private Preference mUpdateAddress;
|
private Preference mUpdateAddress;
|
||||||
|
|
||||||
private boolean mValidListener = false;
|
|
||||||
private boolean mEditableWfcMode = true;
|
private boolean mEditableWfcMode = true;
|
||||||
private boolean mEditableWfcRoamingMode = true;
|
private boolean mEditableWfcRoamingMode = true;
|
||||||
private boolean mUseWfcHomeModeForRoaming = false;
|
private boolean mUseWfcHomeModeForRoaming = false;
|
||||||
@@ -104,7 +103,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
private ProvisioningManager mProvisioningManager;
|
private ProvisioningManager mProvisioningManager;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
private final PhoneTelephonyCallback mTelephonyCallback = new PhoneTelephonyCallback();
|
private PhoneTelephonyCallback mTelephonyCallback;
|
||||||
|
|
||||||
private class PhoneTelephonyCallback extends TelephonyCallback implements
|
private class PhoneTelephonyCallback extends TelephonyCallback implements
|
||||||
TelephonyCallback.CallStateListener {
|
TelephonyCallback.CallStateListener {
|
||||||
@@ -420,27 +419,20 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
updateBody();
|
updateBody();
|
||||||
|
Context context = getActivity();
|
||||||
final Context context = getActivity();
|
if (mTelephonyCallback == null && queryImsState(mSubId).isWifiCallingSupported()) {
|
||||||
if (queryImsState(mSubId).isWifiCallingSupported()) {
|
mTelephonyCallback = new PhoneTelephonyCallback();
|
||||||
getTelephonyManagerForSub(mSubId).registerTelephonyCallback(
|
getTelephonyManagerForSub(mSubId).registerTelephonyCallback(
|
||||||
context.getMainExecutor(), mTelephonyCallback);
|
context.getMainExecutor(), mTelephonyCallback);
|
||||||
|
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
|
||||||
mValidListener = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.registerReceiver(mIntentReceiver, mIntentFilter,
|
context.registerReceiver(mIntentReceiver, mIntentFilter,
|
||||||
Context.RECEIVER_EXPORTED_UNAUDITED);
|
Context.RECEIVER_EXPORTED_UNAUDITED);
|
||||||
|
|
||||||
final Intent intent = getActivity().getIntent();
|
final Intent intent = getActivity().getIntent();
|
||||||
if (intent.getBooleanExtra(Phone.EXTRA_KEY_ALERT_SHOW, false)) {
|
if (intent.getBooleanExtra(Phone.EXTRA_KEY_ALERT_SHOW, false)) {
|
||||||
showAlert(intent);
|
showAlert(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register callback for provisioning changes.
|
// Register callback for provisioning changes.
|
||||||
registerProvisioningChangedCallback();
|
registerProvisioningChangedCallback();
|
||||||
}
|
}
|
||||||
@@ -448,19 +440,13 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
Context context = getActivity();
|
||||||
final Context context = getActivity();
|
if (mTelephonyCallback != null) {
|
||||||
|
|
||||||
if (mValidListener) {
|
|
||||||
mValidListener = false;
|
|
||||||
|
|
||||||
getTelephonyManagerForSub(mSubId).unregisterTelephonyCallback(mTelephonyCallback);
|
getTelephonyManagerForSub(mSubId).unregisterTelephonyCallback(mTelephonyCallback);
|
||||||
|
mTelephonyCallback = null;
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.unregisterReceiver(mIntentReceiver);
|
context.unregisterReceiver(mIntentReceiver);
|
||||||
|
|
||||||
// Remove callback for provisioning changes.
|
// Remove callback for provisioning changes.
|
||||||
unregisterProvisioningChangedCallback();
|
unregisterProvisioningChangedCallback();
|
||||||
}
|
}
|
||||||
|
@@ -131,10 +131,12 @@ public class TetherSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowRestrictedSettingsFragment.class)
|
@Config(shadows = ShadowRestrictedSettingsFragment.class)
|
||||||
public void onCreate_isUiRestricted_doNotSetupViewModel() {
|
public void onCreate_isUiRestricted_doNotSetupViewModel() {
|
||||||
|
doNothing().when(mTetherSettings).addPreferencesFromResource(anyInt());
|
||||||
when(mTetherSettings.isUiRestricted()).thenReturn(true);
|
when(mTetherSettings.isUiRestricted()).thenReturn(true);
|
||||||
|
|
||||||
mTetherSettings.onCreate(null);
|
mTetherSettings.onCreate(null);
|
||||||
|
|
||||||
|
verify(mTetherSettings).addPreferencesFromResource(anyInt());
|
||||||
verify(mTetherSettings, never()).setupViewModel();
|
verify(mTetherSettings, never()).setupViewModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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 com.android.settings.notification.NotificationAccessSettings.ALLOWED_KEY;
|
||||||
|
import static com.android.settings.notification.NotificationAccessSettings.NOT_ALLOWED_KEY;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ServiceInfo;
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||||
|
public class NotificationAccessSettingsTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private NotificationAccessSettings mAccessSettings;
|
||||||
|
@Mock
|
||||||
|
private NotificationManager mNotificationManager;
|
||||||
|
@Mock
|
||||||
|
private PackageManager mPackageManager;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
ShadowApplication shadowApp = ShadowApplication.getInstance();
|
||||||
|
shadowApp.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||||
|
|
||||||
|
mAccessSettings = new NotificationAccessSettings();
|
||||||
|
FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).setup().get();
|
||||||
|
activity.getSupportFragmentManager().beginTransaction().add(mAccessSettings, null).commit();
|
||||||
|
|
||||||
|
when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), anyInt())).then(
|
||||||
|
(Answer<ApplicationInfo>) invocation -> {
|
||||||
|
ApplicationInfo appInfo = mock(ApplicationInfo.class);
|
||||||
|
when(appInfo.loadLabel(any())).thenReturn(invocation.getArgument(0));
|
||||||
|
return appInfo;
|
||||||
|
});
|
||||||
|
|
||||||
|
mAccessSettings.mNm = mNotificationManager;
|
||||||
|
mAccessSettings.mPm = mPackageManager;
|
||||||
|
ShadowBluetoothUtils.sLocalBluetoothManager = mock(LocalBluetoothManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateList_enabledLongName_shown() {
|
||||||
|
ComponentName longCn = new ComponentName("test.pkg1",
|
||||||
|
Strings.repeat("Blah", 200) + "Service");
|
||||||
|
ComponentName shortCn = new ComponentName("test.pkg2", "ReasonableService");
|
||||||
|
ArrayList<ServiceInfo> services = new ArrayList<>();
|
||||||
|
services.add(newServiceInfo(longCn.getPackageName(), longCn.getClassName(), 1));
|
||||||
|
services.add(newServiceInfo(shortCn.getPackageName(), shortCn.getClassName(), 2));
|
||||||
|
when(mNotificationManager.isNotificationListenerAccessGranted(any())).thenReturn(true);
|
||||||
|
|
||||||
|
mAccessSettings.updateList(services);
|
||||||
|
|
||||||
|
PreferenceScreen screen = mAccessSettings.getPreferenceScreen();
|
||||||
|
PreferenceCategory allowed = checkNotNull(screen.findPreference(ALLOWED_KEY));
|
||||||
|
PreferenceCategory notAllowed = checkNotNull(screen.findPreference(NOT_ALLOWED_KEY));
|
||||||
|
assertThat(allowed.getPreferenceCount()).isEqualTo(2);
|
||||||
|
assertThat(allowed.getPreference(0).getKey()).isEqualTo(longCn.flattenToString());
|
||||||
|
assertThat(allowed.getPreference(1).getKey()).isEqualTo(shortCn.flattenToString());
|
||||||
|
assertThat(notAllowed.getPreferenceCount()).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateList_disabledLongName_notShown() {
|
||||||
|
ComponentName longCn = new ComponentName("test.pkg1",
|
||||||
|
Strings.repeat("Blah", 200) + "Service");
|
||||||
|
ComponentName shortCn = new ComponentName("test.pkg2", "ReasonableService");
|
||||||
|
ArrayList<ServiceInfo> services = new ArrayList<>();
|
||||||
|
services.add(newServiceInfo(longCn.getPackageName(), longCn.getClassName(), 1));
|
||||||
|
services.add(newServiceInfo(shortCn.getPackageName(), shortCn.getClassName(), 2));
|
||||||
|
when(mNotificationManager.isNotificationListenerAccessGranted(any())).thenReturn(false);
|
||||||
|
|
||||||
|
mAccessSettings.updateList(services);
|
||||||
|
|
||||||
|
PreferenceScreen screen = mAccessSettings.getPreferenceScreen();
|
||||||
|
PreferenceCategory allowed = checkNotNull(screen.findPreference(ALLOWED_KEY));
|
||||||
|
PreferenceCategory notAllowed = checkNotNull(screen.findPreference(NOT_ALLOWED_KEY));
|
||||||
|
assertThat(allowed.getPreferenceCount()).isEqualTo(0);
|
||||||
|
assertThat(notAllowed.getPreferenceCount()).isEqualTo(1);
|
||||||
|
assertThat(notAllowed.getPreference(0).getKey()).isEqualTo(shortCn.flattenToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ServiceInfo newServiceInfo(String packageName, String serviceName, int uid) {
|
||||||
|
ServiceInfo serviceInfo = new ServiceInfo();
|
||||||
|
serviceInfo.packageName = packageName;
|
||||||
|
serviceInfo.name = serviceName;
|
||||||
|
serviceInfo.applicationInfo = new ApplicationInfo();
|
||||||
|
serviceInfo.applicationInfo.uid = uid;
|
||||||
|
return serviceInfo;
|
||||||
|
}
|
||||||
|
}
|
@@ -18,15 +18,15 @@ package com.android.settings.slices;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.slice.Slice;
|
import androidx.slice.Slice;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -80,7 +80,6 @@ public class SlicePreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onStop_unregisterObserver() {
|
public void onStop_unregisterObserver() {
|
||||||
when(mLiveData.hasActiveObservers()).thenReturn(true);
|
|
||||||
mController.onStart();
|
mController.onStart();
|
||||||
|
|
||||||
mController.onStop();
|
mController.onStop();
|
||||||
@@ -88,20 +87,18 @@ public class SlicePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onStop_noActiveObservers_notUnregisterObserver() {
|
public void onStop_unregisterObserverAndHasSecurityException_noCrash() {
|
||||||
when(mLiveData.hasActiveObservers()).thenReturn(false);
|
LiveData<Slice> liveData = new LiveData<Slice>() {
|
||||||
|
@Override
|
||||||
|
public void removeObserver(@NonNull Observer<? super Slice> observer) {
|
||||||
|
super.removeObserver(observer);
|
||||||
|
throw new SecurityException("SecurityException Test");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mController.mLiveData = liveData;
|
||||||
mController.onStart();
|
mController.onStart();
|
||||||
|
|
||||||
mController.onStop();
|
mController.onStop();
|
||||||
verify(mLiveData, never()).removeObserver(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onStop_notRegisterObserver_notUnregisterObserver() {
|
|
||||||
when(mLiveData.hasActiveObservers()).thenReturn(true);
|
|
||||||
|
|
||||||
mController.onStop();
|
|
||||||
verify(mLiveData, never()).removeObserver(mController);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -21,15 +21,20 @@ import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_U
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Looper;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.data.ApnSetting;
|
import android.telephony.data.ApnSetting;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
@@ -63,7 +68,7 @@ public class MmsMessagePreferenceControllerTest {
|
|||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
|
when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
|
||||||
|
|
||||||
mPreference = new SwitchPreference(mContext);
|
mPreference = spy(new SwitchPreference(mContext));
|
||||||
mController = new MmsMessagePreferenceController(mContext, "mms_message");
|
mController = new MmsMessagePreferenceController(mContext, "mms_message");
|
||||||
mController.init(SUB_ID);
|
mController.init(SUB_ID);
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
@@ -118,4 +123,20 @@ public class MmsMessagePreferenceControllerTest {
|
|||||||
verify(mTelephonyManager).setMobileDataPolicyEnabled(
|
verify(mTelephonyManager).setMobileDataPolicyEnabled(
|
||||||
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, false);
|
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onStart_updatePreferenceUiState() {
|
||||||
|
if (Looper.myLooper() == null) {
|
||||||
|
Looper.prepare();
|
||||||
|
}
|
||||||
|
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
|
PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
|
preferenceScreen.addPreference(mPreference);
|
||||||
|
mController.displayPreference(preferenceScreen);
|
||||||
|
|
||||||
|
mController.onStart();
|
||||||
|
|
||||||
|
// First is preference initialization, and second is in onStart();
|
||||||
|
verify(mPreference, times(2)).setChecked(anyBoolean());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user