Merge "Remove usage of Telephonymanager getDefault() and from() hidden APIs"
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 9c9829f..c15618b 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -1295,8 +1295,11 @@
mContext.getContentResolver(),
Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
- boolean inCall = TelephonyManager.getDefault().getCallState()
- != TelephonyManager.CALL_STATE_IDLE;
+ boolean inCall = false;
+ TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class);
+ if (telephonyManager != null) {
+ inCall = telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE;
+ }
boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH);
return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall
&& !isUserSwitchDisallowed;
diff --git a/core/java/com/android/internal/app/LocaleStore.java b/core/java/com/android/internal/app/LocaleStore.java
index c11089b..49f77e1 100644
--- a/core/java/com/android/internal/app/LocaleStore.java
+++ b/core/java/com/android/internal/app/LocaleStore.java
@@ -194,7 +194,7 @@
private static Set<String> getSimCountries(Context context) {
Set<String> result = new HashSet<>();
- TelephonyManager tm = TelephonyManager.from(context);
+ TelephonyManager tm = context.getSystemService(TelephonyManager.class);
if (tm != null) {
String iso = tm.getSimCountryIso().toUpperCase(Locale.US);
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 0d9dcff..faac78d 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -7234,7 +7234,7 @@
}
private void listenForCallState() {
- TelephonyManager.from(getContext()).listen(new PhoneStateListener() {
+ getContext().getSystemService(TelephonyManager.class).listen(new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (mCallState == state) return;
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 37931be..2e56fb0 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -1939,7 +1939,7 @@
}
TelephonyManager getTelephonyManager() {
- return TelephonyManager.from(mContext);
+ return mContext.getSystemService(TelephonyManager.class);
}
TrustManager getTrustManager() {