[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

@@ -58,7 +58,7 @@ public class DeviceNamePreferenceController extends BasePreferenceController
public DeviceNamePreferenceController(Context context, String key) {
super(context, key);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiManager = context.getSystemService(WifiManager.class);
mWifiDeviceNameTextValidator = new WifiDeviceNameTextValidator();
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

View File

@@ -121,7 +121,7 @@ public class StorageWizardMigrateConfirm extends StorageWizardBase {
try {
moveId = getPackageManager().movePrimaryStorage(mVolume);
} catch (IllegalArgumentException e) {
StorageManager sm = (StorageManager) getSystemService(STORAGE_SERVICE);
StorageManager sm = getSystemService(StorageManager.class);
if (Objects.equals(mVolume.getFsUuid(), sm.getPrimaryStorageVolume().getUuid())) {
final Intent intent = new Intent(this, StorageWizardReady.class);

View File

@@ -146,8 +146,8 @@ public class MyDeviceInfoFragment extends DashboardFragment
// TODO: There may be an avatar setting action we can use here.
final int iconId = bundle.getInt("icon_id", 0);
if (iconId == 0) {
final UserManager userManager = (UserManager) getActivity().getSystemService(
Context.USER_SERVICE);
final UserManager userManager = getActivity().getSystemService(
UserManager.class);
final UserInfo info = Utils.getExistingUser(userManager,
android.os.Process.myUserHandle());
controller.setLabel(info.name);

View File

@@ -49,7 +49,7 @@ public class FirmwareVersionDetailPreferenceController extends BasePreferenceCon
public FirmwareVersionDetailPreferenceController(Context context, String key) {
super(context, key);
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
mUserManager = mContext.getSystemService(UserManager.class);
initializeAdminPermissions();
}

View File

@@ -49,7 +49,7 @@ public class ImeiInfoPreferenceController extends BasePreferenceController {
public ImeiInfoPreferenceController(Context context, String key) {
super(context, key);
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
mTelephonyManager = context.getSystemService(TelephonyManager.class);
mIsMultiSim = mTelephonyManager.getPhoneCount() > 1;
}

View File

@@ -46,9 +46,9 @@ public class SimStatusPreferenceController extends
public SimStatusPreferenceController(Context context, Fragment fragment) {
super(context);
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
mSubscriptionManager = (SubscriptionManager) context.getSystemService(
Context.TELEPHONY_SUBSCRIPTION_SERVICE);
mTelephonyManager = context.getSystemService(TelephonyManager.class);
mSubscriptionManager = context.getSystemService(
SubscriptionManager.class);
mFragment = fragment;
}

View File

@@ -43,7 +43,7 @@ public final class EthernetTetherPreferenceController extends TetherBasePreferen
super(context, preferenceKey);
mEthernetRegex = context.getString(
com.android.internal.R.string.config_ethernet_iface_regex);
mEthernetManager = (EthernetManager) context.getSystemService(Context.ETHERNET_SERVICE);
mEthernetManager = context.getSystemService(EthernetManager.class);
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)

View File

@@ -73,9 +73,9 @@ public class MobilePlanPreferenceController extends AbstractPreferenceController
MobilePlanPreferenceHost host) {
super(context);
mHost = host;
mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
mTm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mCm = context.getSystemService(ConnectivityManager.class);
mTm = context.getSystemService(TelephonyManager.class);
mUserManager = context.getSystemService(UserManager.class);
mIsSecondaryUser = !mUserManager.isAdminUser();
}

View File

@@ -31,7 +31,7 @@ public class NetworkResetRestrictionChecker {
public NetworkResetRestrictionChecker(Context context) {
mContext = context;
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mUserManager = context.getSystemService(UserManager.class);
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)

View File

@@ -140,6 +140,6 @@ public class NetworkScorerPicker extends InstrumentedPreferenceFragment implemen
@VisibleForTesting
NetworkScoreManager createNetworkScorerManager(Context context) {
return (NetworkScoreManager) context.getSystemService(Context.NETWORK_SCORE_SERVICE);
return context.getSystemService(NetworkScoreManager.class);
}
}

View File

@@ -37,7 +37,7 @@ public class NetworkScorerPickerPreferenceController extends BasePreferenceContr
public NetworkScorerPickerPreferenceController(Context context, String key) {
super(context, key);
mNetworkScoreManager =
(NetworkScoreManager) mContext.getSystemService(Context.NETWORK_SCORE_SERVICE);
mContext.getSystemService(NetworkScoreManager.class);
}
@Override

View File

@@ -128,10 +128,10 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
mSwitchWidgetController = switchWidgetController;
mDataSaverBackend = new DataSaverBackend(context);
mConnectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
mTetheringManager = (TetheringManager) context.getSystemService(Context.TETHERING_SERVICE);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
context.getSystemService(ConnectivityManager.class);
mTetheringManager = context.getSystemService(TetheringManager.class);
mWifiManager = context.getSystemService(WifiManager.class);
mUserManager = context.getSystemService(UserManager.class);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothPan = bluetoothPan;
mEthernetRegex =

View File

@@ -1291,8 +1291,8 @@ public class ApnEditor extends SettingsPreferenceFragment
mReadOnlyApnTypes = null;
mReadOnlyApnFields = null;
final CarrierConfigManager configManager = (CarrierConfigManager)
getSystemService(Context.CARRIER_CONFIG_SERVICE);
final CarrierConfigManager configManager =
getSystemService(CarrierConfigManager.class);
if (configManager != null) {
final PersistableBundle b = configManager.getConfigForSubId(mSubId);
if (b != null) {

View File

@@ -209,8 +209,8 @@ public class ApnSettings extends RestrictedSettingsFragment
mSubscriptionInfo = getSubscriptionInfo(mSubId);
mTelephonyManager = activity.getSystemService(TelephonyManager.class);
final CarrierConfigManager configManager = (CarrierConfigManager)
getSystemService(Context.CARRIER_CONFIG_SERVICE);
final CarrierConfigManager configManager =
getSystemService(CarrierConfigManager.class);
final PersistableBundle b = configManager.getConfigForSubId(mSubId);
mHideImsApn = b.getBoolean(CarrierConfigManager.KEY_HIDE_IMS_APN_BOOL);
mAllowAddingApns = b.getBoolean(CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL);

View File

@@ -202,7 +202,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
super.onCreate(icicle);
final Context context = getContext();
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mUserManager = context.getSystemService(UserManager.class);
mTelephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(mSubId);

View File

@@ -106,8 +106,8 @@ public class NetworkSelectSettings extends DashboardFragment {
.createForSubscriptionId(mSubId);
mNetworkScanHelper = new NetworkScanHelper(
mTelephonyManager, mCallback, mNetworkScanExecutor);
PersistableBundle bundle = ((CarrierConfigManager) getContext().getSystemService(
Context.CARRIER_CONFIG_SERVICE)).getConfigForSubId(mSubId);
PersistableBundle bundle = (getContext().getSystemService(
CarrierConfigManager.class)).getConfigForSubId(mSubId);
if (bundle != null) {
mShow4GForLTE = bundle.getBoolean(
CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL);

View File

@@ -212,8 +212,8 @@ public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragmen
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final LayoutInflater inflater =
mContext.getSystemService(LayoutInflater.class);
if (convertView == null) {
convertView = inflater.inflate(mItemResId, null);

View File

@@ -104,8 +104,8 @@ public class SimSelectNotification extends BroadcastReceiver {
subId = SubscriptionManager.getDefaultSmsSubscriptionId();
}
SubscriptionManager subscriptionManager = ((SubscriptionManager) context.getSystemService(
Context.TELEPHONY_SUBSCRIPTION_SERVICE));
SubscriptionManager subscriptionManager = (context.getSystemService(
SubscriptionManager.class));
if (!subscriptionManager.isActiveSubscriptionId(subId)) {
Log.w(TAG, "onEnableMmsDataRequest invalid sub ID " + subId);
return;
@@ -130,8 +130,8 @@ public class SimSelectNotification extends BroadcastReceiver {
return;
}
TelephonyManager tm = ((TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE)).createForSubscriptionId(subId);
TelephonyManager tm = (context.getSystemService(
TelephonyManager.class)).createForSubscriptionId(subId);
if (tm.isDataEnabledForApn(TYPE_MMS)) {
Log.w(TAG, "onEnableMmsDataRequest MMS data already enabled on sub ID " + subId);
@@ -230,14 +230,14 @@ public class SimSelectNotification extends BroadcastReceiver {
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
builder.setContentIntent(resultPendingIntent);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(notificationChannel);
notificationManager.notify(SIM_SELECT_NOTIFICATION_ID, builder.build());
}
public static void cancelSimSelectNotification(Context context) {
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
context.getSystemService(NotificationManager.class);
notificationManager.cancel(SIM_SELECT_NOTIFICATION_ID);
}
@@ -270,14 +270,14 @@ public class SimSelectNotification extends BroadcastReceiver {
// Notify the notification.
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(notificationChannel);
notificationManager.notify(ENABLE_MMS_NOTIFICATION_ID, builder.build());
}
private void cancelEnableMmsNotification(Context context) {
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
context.getSystemService(NotificationManager.class);
notificationManager.cancel(ENABLE_MMS_NOTIFICATION_ID);
}

View File

@@ -319,7 +319,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
@VisibleForTesting
static boolean appHasVpnPermission(Context context, @NonNull ApplicationInfo application) {
final AppOpsManager service =
(AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
context.getSystemService(AppOpsManager.class);
final List<AppOpsManager.PackageOps> ops = service.getOpsForPackage(application.uid,
application.packageName, new int[]{OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN});
return !ArrayUtils.isEmpty(ops);

View File

@@ -116,9 +116,9 @@ public class VpnSettings extends RestrictedSettingsFragment implements
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mVpnManager = (VpnManager) getSystemService(Context.VPN_MANAGEMENT_SERVICE);
mUserManager = getSystemService(UserManager.class);
mConnectivityManager = getSystemService(ConnectivityManager.class);
mVpnManager = getSystemService(VpnManager.class);
mUnavailable = isUiRestricted();
setHasOptionsMenu(!mUnavailable);
@@ -509,7 +509,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
}
// Fetch VPN-enabled apps from AppOps.
AppOpsManager aom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
AppOpsManager aom = context.getSystemService(AppOpsManager.class);
List<AppOpsManager.PackageOps> apps =
aom.getPackagesForOps(new int[] {OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN});
if (apps != null) {

View File

@@ -49,7 +49,7 @@ public class ChangeWifiStateDetails extends AppInfoWithHeader
super.onCreate(savedInstanceState);
final Context context = getActivity();
mAppBridge = new AppStateChangeWifiStateBridge(context, mState, null);
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
mAppOpsManager = context.getSystemService(AppOpsManager.class);
// find preferences
addPreferencesFromResource(R.xml.change_wifi_state_details);

View File

@@ -69,7 +69,7 @@ public class ConfigureWifiSettings extends DashboardFragment {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
final WifiManager wifiManager = getSystemService(WifiManager.class);
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new WifiP2pPreferenceController(context, getSettingsLifecycle(),
wifiManager));

View File

@@ -51,7 +51,7 @@ public class UseOpenWifiPreferenceController extends TogglePreferenceController
super(context, KEY_USE_OPEN_WIFI_AUTOMATICALLY);
mContentResolver = context.getContentResolver();
mNetworkScoreManager =
(NetworkScoreManager) context.getSystemService(Context.NETWORK_SCORE_SERVICE);
context.getSystemService(NetworkScoreManager.class);
mSettingObserver = new SettingObserver();
updateEnableUseWifiComponentName();
checkForFeatureSupportedScorers();

View File

@@ -64,7 +64,7 @@ public class WifiAPITest extends SettingsPreferenceFragment implements
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
mWifiManager = getSystemService(WifiManager.class);
}
@Override

View File

@@ -38,7 +38,7 @@ public class WifiConfigInfo extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
mWifiManager = getSystemService(WifiManager.class);
setContentView(R.layout.wifi_config_info);
mConfigList = (TextView) findViewById(R.id.config_list);
}

View File

@@ -75,7 +75,7 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
public WifiEnabler(Context context, SwitchWidgetController switchWidget,
MetricsFeatureProvider metricsFeatureProvider) {
this(context, switchWidget, metricsFeatureProvider,
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
context.getSystemService(ConnectivityManager.class));
}
@VisibleForTesting
@@ -86,7 +86,7 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
mSwitchWidget = switchWidget;
mSwitchWidget.setListener(this);
mMetricsFeatureProvider = metricsFeatureProvider;
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiManager = context.getSystemService(WifiManager.class);
mConnectivityManager = connectivityManager;
mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);

View File

@@ -107,7 +107,7 @@ public class WifiNoInternetDialog extends AlertActivity implements
}
};
mCM = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mCM = getSystemService(ConnectivityManager.class);
mCM.registerNetworkCallback(request, mNetworkCallback);
final NetworkInfo ni = mCM.getNetworkInfo(mNetwork);

View File

@@ -116,7 +116,7 @@ public class WifiStatusTest extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
mWifiManager = getSystemService(WifiManager.class);
mWifiStateFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
mWifiStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);

View File

@@ -83,7 +83,7 @@ public class WifiUtils {
final DevicePolicyManager dpm =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
final PackageManager pm = context.getPackageManager();
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
final UserManager um = context.getSystemService(UserManager.class);
// Check if device has DPM capability. If it has and dpm is still null, then we
// treat this case with suspicion and bail out.

View File

@@ -73,7 +73,7 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i
public WifiWakeupPreferenceController(Context context) {
super(context, KEY_ENABLE_WIFI_WAKEUP);
mLocationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE);
mLocationManager = context.getSystemService(LocationManager.class);
mWifiManager = context.getSystemService(WifiManager.class);
}

View File

@@ -128,8 +128,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
boolean isWfcModeEditable = true;
boolean isWfcRoamingModeEditable = false;
final CarrierConfigManager configManager = (CarrierConfigManager)
activity.getSystemService(Context.CARRIER_CONFIG_SERVICE);
final CarrierConfigManager configManager =
activity.getSystemService(CarrierConfigManager.class);
if (configManager != null) {
PersistableBundle b =
configManager.getConfigForSubId(WifiCallingSettingsForSub.this.mSubId);
@@ -343,8 +343,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
return;
}
final CarrierConfigManager configManager = (CarrierConfigManager)
getSystemService(Context.CARRIER_CONFIG_SERVICE);
final CarrierConfigManager configManager =
getSystemService(CarrierConfigManager.class);
boolean isWifiOnlySupported = true;
if (configManager != null) {

View File

@@ -42,7 +42,7 @@ public class AddDevicePreferenceController2 extends BasePreferenceController {
public AddDevicePreferenceController2(Context context) {
super(context, KEY_ADD_DEVICE);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiManager = context.getSystemService(WifiManager.class);
}
public void setWifiEntry(WifiEntry wifiEntry) {

View File

@@ -143,8 +143,8 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
if (admin == null) {
final DevicePolicyManager dpm = (DevicePolicyManager)
getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
final UserManager um = (UserManager)
getContext().getSystemService(Context.USER_SERVICE);
final UserManager um =
getContext().getSystemService(UserManager.class);
final int profileOwnerUserId = Utils.getManagedProfileId(
um, UserHandle.myUserId());
if (profileOwnerUserId != UserHandle.USER_NULL) {

View File

@@ -45,7 +45,7 @@ public class WifiPrivacyPreferenceController2 extends BasePreferenceController i
public WifiPrivacyPreferenceController2(Context context) {
super(context, KEY_WIFI_PRIVACY);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiManager = context.getSystemService(WifiManager.class);
}
public void setWifiEntry(WifiEntry wifiEntry) {

View File

@@ -373,8 +373,8 @@ public class WifiDppUtils {
* device security or if lock screen is unlocked
*/
public static void showLockScreen(Context context, Runnable successRunnable) {
final KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(
Context.KEYGUARD_SERVICE);
final KeyguardManager keyguardManager = context.getSystemService(
KeyguardManager.class);
if (keyguardManager.isKeyguardSecure()) {
final BiometricPrompt.AuthenticationCallback authenticationCallback =

View File

@@ -71,7 +71,7 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
super(context);
mWifiManager = wifiManager;
lifecycle.addObserver(this);
mLocationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE);
mLocationManager = context.getSystemService(LocationManager.class);
}
@Override

View File

@@ -200,7 +200,7 @@ public class WifiP2pSettings extends DashboardFragment
public void onActivityCreated(Bundle savedInstanceState) {
final Activity activity = getActivity();
if (mWifiP2pManager == null) {
mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
mWifiP2pManager = getSystemService(WifiP2pManager.class);
}
if (mWifiP2pManager != null) {

View File

@@ -202,7 +202,7 @@ public class QrCamera extends Handler {
}
final WindowManager winManager =
(WindowManager) mContext.get().getSystemService(Context.WINDOW_SERVICE);
mContext.get().getSystemService(WindowManager.class);
final int rotation = winManager.getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation) {

View File

@@ -255,7 +255,7 @@ public class TetherService extends Service {
}
private void disableTethering(final int tetheringType) {
final TetheringManager tm = (TetheringManager) getSystemService(Context.TETHERING_SERVICE);
final TetheringManager tm = getSystemService(TetheringManager.class);
tm.stopTethering(tetheringType);
}

View File

@@ -45,8 +45,8 @@ public abstract class WifiTetherBasePreferenceController extends AbstractPrefere
OnTetherConfigUpdateListener listener) {
super(context);
mListener = listener;
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mTm = (TetheringManager) context.getSystemService(Context.TETHERING_SERVICE);
mWifiManager = context.getSystemService(WifiManager.class);
mTm = context.getSystemService(TetheringManager.class);
mWifiRegexs = mTm.getTetherableWifiRegexs();
}

View File

@@ -63,7 +63,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
boolean initSoftApManager) {
super(context);
mTetheringManager = context.getSystemService(TetheringManager.class);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiManager = context.getSystemService(WifiManager.class);
mWifiRegexs = mTetheringManager.getTetherableWifiRegexs();
mLifecycle = lifecycle;
if (lifecycle != null) {

View File

@@ -110,7 +110,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
@Override
public void onAttach(Context context) {
super.onAttach(context);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiManager = context.getSystemService(WifiManager.class);
mTetherChangeReceiver = new TetherChangeReceiver();
mSSIDPreferenceController = use(WifiTetherSSIDPreferenceController.class);

View File

@@ -73,8 +73,8 @@ public class WifiTetherSwitchBarController implements
mSwitch = mSwitchBar.getSwitch();
mDataSaverBackend = new DataSaverBackend(context);
mConnectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
context.getSystemService(ConnectivityManager.class);
mWifiManager = context.getSystemService(WifiManager.class);
mSwitchBar.setChecked(mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED);
updateWifiSwitch();
}

View File

@@ -181,8 +181,8 @@ public class ImeiInfoPreferenceControllerTest {
mController.copy();
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
CLIPBOARD_SERVICE);
final ClipboardManager clipboard = mContext.getSystemService(
ClipboardManager.class);
final CharSequence data = clipboard.getPrimaryClip().getItemAt(0).getText();
assertThat(data.toString()).isEqualTo(meid);
}

View File

@@ -57,7 +57,7 @@ public class BluetoothTetherPreferenceControllerTest {
mContext = spy(ApplicationProvider.getApplicationContext());
mSwitchPreference = spy(SwitchPreference.class);
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
mController = new BluetoothTetherPreferenceController(mContext, "BLUETOOTH");
mController.setTetherEnabler(mTetherEnabler);

View File

@@ -62,9 +62,9 @@ public class EthernetTetherPreferenceControllerTest {
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mPreference = spy(SwitchPreference.class);
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
when(mContext.getSystemService(Context.ETHERNET_SERVICE)).thenReturn(mEthernetManager);
when(mContext.getSystemService(EthernetManager.class)).thenReturn(mEthernetManager);
mController = new EthernetTetherPreferenceController(mContext, "ethernet");
mController.setTetherEnabler(mTetherEnabler);
ReflectionHelpers.setField(mController, "mEthernetRegex", ETHERNET_REGEX);

View File

@@ -45,14 +45,14 @@ public class NetworkResetRestrictionCheckerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
mRestrictionChecker = spy(new NetworkResetRestrictionChecker(mContext));
}
@Test
public void testHasRestriction_notAdmin_shouldReturnTrue() {
final Context context = mock(Context.class);
when(context.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
when(context.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.isAdminUser()).thenReturn(false);
assertThat(mRestrictionChecker.hasRestriction()).isTrue();

View File

@@ -125,7 +125,7 @@ public class PrivateDnsPreferenceControllerTest {
mContext = spy(RuntimeEnvironment.application);
mContentResolver = mContext.getContentResolver();
mShadowContentResolver = Shadow.extract(mContentResolver);
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
when(mContext.getSystemService(ConnectivityManager.class))
.thenReturn(mConnectivityManager);
doNothing().when(mConnectivityManager).registerDefaultNetworkCallback(
mCallbackCaptor.capture(), nullable(Handler.class));

View File

@@ -95,10 +95,10 @@ public class TetherEnablerTest {
AtomicReference<BluetoothPan> panReference = spy(AtomicReference.class);
mSwitchBar = spy(new SwitchBar(context));
mSwitchWidgetController = spy(new SwitchBarController(mSwitchBar));
when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
when(context.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
when(context.getSystemService(ConnectivityManager.class)).thenReturn(
mConnectivityManager);
when(context.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(context.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
when(context.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
mNetworkPolicyManager);
when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
@@ -311,4 +311,4 @@ public class TetherEnablerTest {
assertThat(TetherEnabler.isTethering(TETHERING_ETHERNET_ON, TETHERING_ETHERNET)).isTrue();
assertThat(TetherEnabler.isTethering(~TETHERING_ETHERNET_ON, TETHERING_ETHERNET)).isFalse();
}
}
}

View File

@@ -55,7 +55,7 @@ public class UsbTetherPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
mController = new UsbTetherPreferenceController(mContext, "USB");
mController.setTetherEnabler(mTetherEnabler);

View File

@@ -100,7 +100,7 @@ public class WifiTetherDisablePreferenceControllerTest {
mContext = spy(ApplicationProvider.getApplicationContext());
mPreference = spy(SwitchPreference.class);
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
mController.setTetherEnabler(mTetherEnabler);

View File

@@ -74,7 +74,7 @@ public class MobileDataSliceTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());

View File

@@ -77,7 +77,7 @@ public class NetworkSelectSettingsTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);

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();

View File

@@ -74,7 +74,7 @@ public class MobileDataPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);