[Settings] Support getSystemService(Class<T>)

Add getSystemService(Class<T>) to align the capability with framework
part.

This is a back port from aosp/1639943, aosp/1645152 and aosp/1648047

Bug: 179640862
Test: local
Change-Id: I035db55a71f94000ca35f8d71f03c19208423c73
This commit is contained in:
Bonian Chen
2021-03-24 00:59:46 +08:00
parent d8c9a53931
commit d5ccde31a8
63 changed files with 103 additions and 103 deletions

View File

@@ -78,7 +78,7 @@ public class NetworkRequestDialogActivityTest {
mActivity = spy(activity);
mWifiManager = mock(WifiManager.class);
when(mActivity.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
}
@Test

View File

@@ -53,7 +53,7 @@ public class WifiEnablerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
mEnabler = new WifiEnabler(mContext, mock(SwitchWidgetController.class),
mock(MetricsFeatureProvider.class), mConnectivityManager);
}

View File

@@ -78,7 +78,7 @@ public class WifiPrimarySwitchPreferenceControllerTest {
when(mContext.getSystemService(NetworkScoreManager.class)).thenReturn(mNetworkScoreManager);
mController = new WifiPrimarySwitchPreferenceController(mContext, mMetricsFeatureProvider);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
when(mWifiManager.getWifiState()).thenReturn(WifiManager.WIFI_STATE_DISABLED);
}

View File

@@ -209,7 +209,7 @@ public class WifiSettingsTest {
final Resources.Theme theme = mContext.getTheme();
when(activity.getTheme()).thenReturn(theme);
UserManager userManager = mock(UserManager.class);
when(activity.getSystemService(Context.USER_SERVICE))
when(activity.getSystemService(UserManager.class))
.thenReturn(userManager);
when(mWifiSettings.findPreference(WifiSettings.PREF_KEY_DATA_USAGE))

View File

@@ -77,7 +77,7 @@ public class DisclaimerItemListAdapterTest {
when(mLayoutInflater.inflate(anyInt(), anyObject(), anyBoolean())).thenReturn(mView);
when(mViewGroup.getContext()).thenReturn(mContext);
when(mViewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).thenReturn(
when(mViewGroup.getContext().getSystemService(LayoutInflater.class)).thenReturn(
mLayoutInflater);
when(mView.findViewById(ID_DISCLAIMER_ITEM_TITLE)).thenReturn(mTestView);
when(mView.findViewById(ID_DISCLAIMER_ITEM_DESCRIPTION)).thenReturn(mDescView);

View File

@@ -54,7 +54,7 @@ public class EmergencyCallLimitationDisclaimerTest {
mContext = spy(RuntimeEnvironment.application);
doReturn(mCarrierConfigManager).when(mContext).getSystemService(
Context.CARRIER_CONFIG_SERVICE);
CarrierConfigManager.class);
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle);
doReturn(getSharedPreferences()).when(mContext).getSharedPreferences(anyString(), anyInt());

View File

@@ -54,7 +54,7 @@ public class LocationPolicyDisclaimerTest {
mContext = spy(RuntimeEnvironment.application);
doReturn(mCarrierConfigManager).when(mContext).getSystemService(
Context.CARRIER_CONFIG_SERVICE);
CarrierConfigManager.class);
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle);
doReturn(getSharedPreferences()).when(mContext).getSharedPreferences(anyString(), anyInt());
}

View File

@@ -73,8 +73,8 @@ public class WifiTetherApBandPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mPreference = new ListPreference(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
when(mScreen.findPreference(anyString())).thenReturn(mPreference);

View File

@@ -80,10 +80,10 @@ public class WifiTetherSettingsTest {
MockitoAnnotations.initMocks(this);
doReturn(mConnectivityManager)
.when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
doReturn(mTetheringManager).when(mContext).getSystemService(Context.TETHERING_SERVICE);
.when(mContext).getSystemService(ConnectivityManager.class);
doReturn(mTetheringManager).when(mContext).getSystemService(TetheringManager.class);
doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
mWifiTetherSettings = new WifiTetherSettings();
}
@@ -133,7 +133,7 @@ public class WifiTetherSettingsTest {
when(settings.getContext()).thenReturn(mContext);
final Resources.Theme theme = mContext.getTheme();
when(activity.getTheme()).thenReturn(theme);
when(activity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
when(activity.getSystemService(UserManager.class)).thenReturn(mUserManager);
doNothing().when(settings)
.onCreatePreferences(any(Bundle.class), nullable(String.class));
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();