From 16dce22bf52f193469ff65954b7187ffb881389c Mon Sep 17 00:00:00 2001 From: Jayachandran C Date: Fri, 15 Nov 2019 15:42:01 -0800 Subject: [PATCH] Remove usage of Telephonymanager getDefault() and from() hidden APIs This CL changes to use getSystemService(TelephonyManager.class) Bug: 140768340 Test: Build Change-Id: I1fcf2c17456f126584df359547f64c07c168aa65 --- core/java/android/os/UserManager.java | 7 +++++-- core/java/com/android/internal/app/LocaleStore.java | 2 +- .../server/notification/NotificationManagerService.java | 2 +- .../server/devicepolicy/DevicePolicyManagerService.java | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 9c9829fb08e2c..c15618bdaa786 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -1295,8 +1295,11 @@ public class UserManager { 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 c11089ba19bd5..49f77e11cf80b 100644 --- a/core/java/com/android/internal/app/LocaleStore.java +++ b/core/java/com/android/internal/app/LocaleStore.java @@ -194,7 +194,7 @@ public class LocaleStore { private static Set getSimCountries(Context context) { Set 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 0d9dcff51b498..faac78d68879b 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 @@ public class NotificationManagerService extends SystemService { } 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 37931be4eb10f..2e56fb096e3b9 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 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } TelephonyManager getTelephonyManager() { - return TelephonyManager.from(mContext); + return mContext.getSystemService(TelephonyManager.class); } TrustManager getTrustManager() {