have PhoneInterfaceManager use phone obj with default subid instead of
global mPhone object
Test: test on phone TBD
Bug: 115783661
Change-Id: I118d2c9f4f15093fcc25b9a84d248a778e8f3900
Merged-In: I118d2c9f4f15093fcc25b9a84d248a778e8f3900
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 2cefd52..ccbb4d0 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -330,7 +330,7 @@
// The asynchronous caching will start just after this call.
callerInfoCache = CallerInfoCache.init(this);
- phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
+ phoneMgr = PhoneInterfaceManager.init(this);
configLoader = CarrierConfigLoader.init(this);
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index c8453a6..0115cd9 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -242,7 +242,6 @@
private static PhoneInterfaceManager sInstance;
private PhoneGlobals mApp;
- private Phone mPhone;
private CallManager mCM;
private UserManager mUserManager;
private AppOpsManager mAppOps;
@@ -367,6 +366,7 @@
AsyncResult ar;
UiccCard uiccCard;
IccAPDUArgument iccArgument;
+ final Phone defaultPhone = getDefaultPhone();
switch (msg.what) {
case CMD_HANDLE_USSD_REQUEST: {
@@ -621,7 +621,8 @@
case CMD_NV_READ_ITEM:
request = (MainThreadRequest) msg.obj;
onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
- mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
+ defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
+ request.workSource);
break;
case EVENT_NV_READ_ITEM_DONE:
@@ -647,7 +648,7 @@
request = (MainThreadRequest) msg.obj;
onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
- mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
+ defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
request.workSource);
break;
@@ -658,7 +659,7 @@
case CMD_NV_WRITE_CDMA_PRL:
request = (MainThreadRequest) msg.obj;
onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
- mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
+ defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
break;
case EVENT_NV_WRITE_CDMA_PRL_DONE:
@@ -668,7 +669,7 @@
case CMD_RESET_MODEM_CONFIG:
request = (MainThreadRequest) msg.obj;
onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
- mPhone.resetModemConfig(onCompleted);
+ defaultPhone.resetModemConfig(onCompleted);
break;
case EVENT_RESET_MODEM_CONFIG_DONE:
@@ -714,7 +715,7 @@
case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
request = (MainThreadRequest)msg.obj;
onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
- mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
+ defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
break;
case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
@@ -810,7 +811,7 @@
case CMD_GET_MODEM_ACTIVITY_INFO:
request = (MainThreadRequest) msg.obj;
onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
- mPhone.getModemActivityInfo(onCompleted, request.workSource);
+ defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
break;
case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
@@ -838,7 +839,7 @@
case CMD_SET_ALLOWED_CARRIERS:
request = (MainThreadRequest) msg.obj;
onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
- mPhone.setAllowedCarriers(
+ defaultPhone.setAllowedCarriers(
(List<CarrierIdentifier>) request.argument,
onCompleted, request.workSource);
break;
@@ -868,7 +869,7 @@
case CMD_GET_ALLOWED_CARRIERS:
request = (MainThreadRequest) msg.obj;
onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
- mPhone.getAllowedCarriers(onCompleted, request.workSource);
+ defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
break;
case EVENT_GET_ALLOWED_CARRIERS_DONE:
@@ -1075,7 +1076,7 @@
case CMD_MODEM_REBOOT:
request = (MainThreadRequest) msg.obj;
onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
- mPhone.rebootModem(onCompleted);
+ defaultPhone.rebootModem(onCompleted);
break;
case EVENT_CMD_MODEM_REBOOT_DONE:
handleNullReturnEvent(msg, "rebootModem");
@@ -1226,10 +1227,10 @@
* Initialize the singleton PhoneInterfaceManager instance.
* This is only done once, at startup, from PhoneApp.onCreate().
*/
- /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
+ /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
synchronized (PhoneInterfaceManager.class) {
if (sInstance == null) {
- sInstance = new PhoneInterfaceManager(app, phone);
+ sInstance = new PhoneInterfaceManager(app);
} else {
Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
}
@@ -1238,22 +1239,26 @@
}
/** Private constructor; @see init() */
- private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
+ private PhoneInterfaceManager(PhoneGlobals app) {
mApp = app;
- mPhone = phone;
mCM = PhoneGlobals.getInstance().mCM;
mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
mMainThreadHandler = new MainThreadHandler();
- mTelephonySharedPreferences =
- PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
mSubscriptionController = SubscriptionController.getInstance();
+ mTelephonySharedPreferences =
+ PreferenceManager.getDefaultSharedPreferences(mApp);
mNetworkScanRequestTracker = new NetworkScanRequestTracker();
mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
publish();
}
+ private Phone getDefaultPhone() {
+ Phone thePhone = getPhone(getDefaultSubscription());
+ return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
+ }
+
private void publish() {
if (DBG) log("publish: " + this);
@@ -1262,7 +1267,7 @@
private Phone getPhoneFromRequest(MainThreadRequest request) {
return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
- ? mPhone : getPhone(request.subId);
+ ? getDefaultPhone() : getPhone(request.subId);
}
private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
@@ -1810,10 +1815,10 @@
@Override
public Bundle getCellLocation(String callingPackage) {
- mPhone.getContext().getSystemService(AppOpsManager.class)
+ mApp.getSystemService(AppOpsManager.class)
.checkPackage(Binder.getCallingUid(), callingPackage);
- if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
- callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
+ if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
+ Binder.getCallingUid(), Binder.getCallingPid(), true)) {
return null;
}
@@ -1913,8 +1918,8 @@
*/
private int getTargetSdk(String packageName) {
try {
- final ApplicationInfo ai =
- mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
+ final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
+ packageName, 0);
if (ai != null) return ai.targetSdkVersion;
} catch (PackageManager.NameNotFoundException unexpected) {
}
@@ -1962,9 +1967,9 @@
@Override
public List<CellInfo> getAllCellInfo(String callingPackage) {
- mPhone.getContext().getSystemService(AppOpsManager.class)
+ mApp.getSystemService(AppOpsManager.class)
.checkPackage(Binder.getCallingUid(), callingPackage);
- if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
+ if (!LocationAccessPolicy.canAccessCellLocation(mApp,
callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
return null;
}
@@ -2005,10 +2010,10 @@
private void requestCellInfoUpdateInternal(
int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
- mPhone.getContext().getSystemService(AppOpsManager.class)
+ mApp.getSystemService(AppOpsManager.class)
.checkPackage(Binder.getCallingUid(), callingPackage);
- if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
- callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
+ if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
+ Binder.getCallingUid(), Binder.getCallingPid(), true)) {
return;
}
@@ -2025,7 +2030,7 @@
final long identity = Binder.clearCallingIdentity();
try {
- mPhone.setCellInfoListRate(rateInMillis, workSource);
+ getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2068,6 +2073,7 @@
if (phone == null) {
return null;
}
+
int subId = phone.getSubId();
if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
mApp, subId, callingPackage, "getMeidForSlot")) {
@@ -2206,8 +2212,7 @@
}
private void enforceConnectivityInternalPermission() {
- mApp.enforceCallingOrSelfPermission(
- android.Manifest.permission.CONNECTIVITY_INTERNAL,
+ mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
"ConnectivityService");
}
@@ -2348,9 +2353,10 @@
final long identity = Binder.clearCallingIdentity();
try {
final Phone phone = getPhone(subId);
- if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
+ if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
return phone.getLine1Number();
} else {
+ loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
return null;
}
} finally {
@@ -2409,7 +2415,7 @@
public boolean needsOtaServiceProvisioning() {
final long identity = Binder.clearCallingIdentity();
try {
- return mPhone.needsOtaServiceProvisioning();
+ return getDefaultPhone().needsOtaServiceProvisioning();
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2435,7 +2441,7 @@
@Override
public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
- String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
+ String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
if (!TextUtils.equals(callingPackage, systemDialer)) {
throw new SecurityException("caller must be system dialer");
}
@@ -2446,7 +2452,7 @@
if (phoneAccountHandle == null) {
return null;
}
- return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
+ return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2462,8 +2468,7 @@
final long identity = Binder.clearCallingIdentity();
try {
- return RemoteVvmTaskManager
- .getRemotePackage(mPhone.getContext(), subId).getPackageName();
+ return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2477,7 +2482,7 @@
final long identity = Binder.clearCallingIdentity();
try {
VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
- mPhone.getContext(), callingPackage, subId, settings);
+ mApp, callingPackage, subId, settings);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2490,7 +2495,7 @@
final long identity = Binder.clearCallingIdentity();
try {
VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
- mPhone.getContext(), callingPackage, subId);
+ mApp, callingPackage, subId);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2504,7 +2509,7 @@
final long identity = Binder.clearCallingIdentity();
try {
return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
- mPhone.getContext(), callingPackage, subId);
+ mApp, callingPackage, subId);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2517,7 +2522,7 @@
final long identity = Binder.clearCallingIdentity();
try {
return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
- mPhone.getContext(), subId);
+ mApp, subId);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2671,8 +2676,10 @@
*/
@Override
public void sendDialerSpecialCode(String callingPackage, String inputCode) {
+ final Phone defaultPhone = getDefaultPhone();
mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
- String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
+ String defaultDialer = TelecomManager.from(defaultPhone.getContext())
+ .getDefaultDialerPackage();
if (!TextUtils.equals(callingPackage, defaultDialer)) {
TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
getDefaultSubscription(), "sendDialerSpecialCode");
@@ -2680,7 +2687,7 @@
final long identity = Binder.clearCallingIdentity();
try {
- mPhone.sendDialerSpecialCode(inputCode);
+ defaultPhone.sendDialerSpecialCode(inputCode);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2723,7 +2730,7 @@
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
final long token = Binder.clearCallingIdentity();
try {
- ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
+ ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
.addRegistrationCallbackForSubscription(c, subId);
} finally {
Binder.restoreCallingIdentity(token);
@@ -2735,7 +2742,7 @@
enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Binder.withCleanCallingIdentity(() ->
- ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
+ ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
.removeRegistrationCallbackForSubscription(c, subId));
}
@@ -2746,7 +2753,7 @@
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
final long token = Binder.clearCallingIdentity();
try {
- ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
+ ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
.addCapabilitiesCallbackForSubscription(c, subId);
} finally {
Binder.restoreCallingIdentity(token);
@@ -2758,7 +2765,7 @@
enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Binder.withCleanCallingIdentity(() ->
- ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
+ ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
.removeCapabilitiesCallbackForSubscription(c, subId));
}
@@ -2768,7 +2775,7 @@
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
final long token = Binder.clearCallingIdentity();
try {
- return ImsManager.getInstance(mPhone.getContext(),
+ return ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
} catch (ImsException e) {
Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
@@ -2797,7 +2804,7 @@
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
final long token = Binder.clearCallingIdentity();
try {
- return ImsManager.getInstance(mPhone.getContext(),
+ return ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
} finally {
Binder.restoreCallingIdentity(token);
@@ -2811,7 +2818,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(),
+ ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2824,7 +2831,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(),
+ return ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).isVtEnabledByUser();
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2838,8 +2845,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(),
- getSlotIndexOrException(subId)).setVtSetting(isEnabled);
+ ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2851,7 +2857,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(),
+ return ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).isWfcEnabledByUser();
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2865,8 +2871,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(),
- getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
+ ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -2878,7 +2883,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(),
+ return ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2892,7 +2897,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(),
+ ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2906,7 +2911,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(),
+ ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2919,7 +2924,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(),
+ return ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2933,7 +2938,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(),
+ ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2946,7 +2951,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(),
+ return ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2960,7 +2965,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(),
+ ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2974,7 +2979,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(),
+ ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2987,7 +2992,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(),
+ return ImsManager.getInstance(mApp,
getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
} finally {
Binder.restoreCallingIdentity(identity);
@@ -3000,7 +3005,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
+ ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
.getConfigInterface().addConfigCallback(callback);
} catch (ImsException e) {
throw new IllegalArgumentException(e.getMessage());
@@ -3015,7 +3020,7 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
+ ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
.getConfigInterface().removeConfigCallback(callback);
} catch (ImsException e) {
throw new IllegalArgumentException(e.getMessage());
@@ -3030,8 +3035,8 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
- .getConfigInterface().getConfigInt(key);
+ return ImsManager.getInstance(mApp,
+ getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
} catch (ImsException e) {
throw new IllegalArgumentException(e.getMessage());
} finally {
@@ -3045,8 +3050,8 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
- .getConfigInterface().getConfigString(key);
+ return ImsManager.getInstance(mApp,
+ getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
} catch (ImsException e) {
throw new IllegalArgumentException(e.getMessage());
} finally {
@@ -3061,8 +3066,8 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
- .getConfigInterface().setConfig(key, value);
+ return ImsManager.getInstance(mApp,
+ getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
} catch (ImsException e) {
throw new IllegalArgumentException(e.getMessage());
} finally {
@@ -3077,8 +3082,8 @@
final long identity = Binder.clearCallingIdentity();
try {
// TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
- return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
- .getConfigInterface().setConfig(key, value);
+ return ImsManager.getInstance(mApp,
+ getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
} catch (ImsException e) {
throw new IllegalArgumentException(e.getMessage());
} finally {
@@ -3232,10 +3237,6 @@
}
}
- public void setPhone(Phone phone) {
- mPhone = phone;
- }
-
/**
* {@hide}
* Returns Default subId, 0 in the case of single standby.
@@ -3262,7 +3263,7 @@
public int getWhenToMakeWifiCalls() {
final long identity = Binder.clearCallingIdentity();
try {
- return Settings.System.getInt(mPhone.getContext().getContentResolver(),
+ return Settings.System.getInt(mApp.getContentResolver(),
Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
getWhenToMakeWifiCallsDefaultPreference());
} finally {
@@ -3277,7 +3278,7 @@
final long identity = Binder.clearCallingIdentity();
try {
if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
- Settings.System.putInt(mPhone.getContext().getContentResolver(),
+ Settings.System.putInt(mApp.getContentResolver(),
Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -3300,8 +3301,8 @@
try {
if (TextUtils.equals(ISDR_AID, aid)) {
// Only allows LPA to open logical channel to ISD-R.
- ComponentInfo bestComponent =
- EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
+ ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
+ .getContext().getPackageManager());
if (bestComponent == null
|| !TextUtils.equals(callingPackage, bestComponent.packageName)) {
loge("The calling package is not allowed to access ISD-R.");
@@ -3387,8 +3388,8 @@
if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
&& TextUtils.equals(ISDR_AID, data)) {
// Only allows LPA to select ISD-R.
- ComponentInfo bestComponent =
- EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
+ ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
+ .getContext().getPackageManager());
if (bestComponent == null
|| !TextUtils.equals(callingPackage, bestComponent.packageName)) {
loge("The calling package is not allowed to select ISD-R.");
@@ -3637,14 +3638,15 @@
}
public String[] getPcscfAddress(String apnType, String callingPackage) {
+ final Phone defaultPhone = getDefaultPhone();
if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
- mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
+ mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
return new String[0];
}
final long identity = Binder.clearCallingIdentity();
try {
- return mPhone.getPcscfAddress(apnType);
+ return defaultPhone.getPcscfAddress(apnType);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -3798,7 +3800,7 @@
final long identity = Binder.clearCallingIdentity();
try {
- mPhone.setImsRegistrationState(registered);
+ getDefaultPhone().setImsRegistrationState(registered);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -3930,15 +3932,16 @@
*/
@Override
public int getCalculatedPreferredNetworkType(String callingPackage) {
- if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
- mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
+ final Phone defaultPhone = getDefaultPhone();
+ if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
+ callingPackage, "getCalculatedPreferredNetworkType")) {
return RILConstants.PREFERRED_NETWORK_MODE;
}
final long identity = Binder.clearCallingIdentity();
try {
// FIXME: need to get SubId from somewhere.
- return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
+ return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -3986,7 +3989,7 @@
CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
if (success) {
- Settings.Global.putInt(mPhone.getContext().getContentResolver(),
+ Settings.Global.putInt(mApp.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
}
return success;
@@ -4008,11 +4011,12 @@
enforceModifyPermission();
final long identity = Binder.clearCallingIdentity();
+ final Phone defaultPhone = getDefaultPhone();
try {
- int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
+ int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Settings.Global.TETHER_DUN_REQUIRED, 2);
// If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
- if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
+ if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
dunRequired = 1;
}
return dunRequired;
@@ -4041,7 +4045,7 @@
if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
phone.setUserDataEnabled(enable);
} else {
- loge("setUserDataEnabled: no phone for subId=" + subId);
+ loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
}
} finally {
Binder.restoreCallingIdentity(identity);
@@ -4173,14 +4177,16 @@
@Override
public int checkCarrierPrivilegesForPackage(String pkgName) {
+ final Phone defaultPhone = getDefaultPhone();
if (TextUtils.isEmpty(pkgName))
return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
- UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
+ UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
if (card == null) {
loge("checkCarrierPrivilegesForPackage: No UICC");
return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
}
- return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
+ return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
+ pkgName);
}
@Override
@@ -4195,8 +4201,7 @@
continue;
}
- result = card.getCarrierPrivilegeStatus(
- mPhone.getContext().getPackageManager(), pkgName);
+ result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
break;
}
@@ -4216,13 +4221,12 @@
loge("getCarrierPackageNamesForIntent: No UICC");
return null ;
}
- return card.getCarrierPackageNamesForIntent(
- mPhone.getContext().getPackageManager(), intent);
+ return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
}
@Override
public List<String> getPackagesWithCarrierPrivileges() {
- PackageManager pm = mPhone.getContext().getPackageManager();
+ PackageManager pm = mApp.getPackageManager();
List<String> privilegedPackages = new ArrayList<>();
List<PackageInfo> packages = null;
for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
@@ -4378,7 +4382,7 @@
final long identity = Binder.clearCallingIdentity();
try {
- final Context context = mPhone.getContext();
+ final Context context = mApp;
final TelephonyManager tele = TelephonyManager.from(context);
final SubscriptionManager sub = SubscriptionManager.from(context);
@@ -4544,11 +4548,13 @@
@Override
public void enableVideoCalling(boolean enable) {
+ final Phone defaultPhone = getDefaultPhone();
enforceModifyPermission();
final long identity = Binder.clearCallingIdentity();
try {
- ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
+ ImsManager.getInstance(defaultPhone.getContext(),
+ defaultPhone.getPhoneId()).setVtSetting(enable);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -4556,8 +4562,9 @@
@Override
public boolean isVideoCallingEnabled(String callingPackage) {
+ final Phone defaultPhone = getDefaultPhone();
if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
- mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
+ mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
return false;
}
@@ -4568,7 +4575,7 @@
// In the long run, we may instead need to check if there exists a connection service
// which can support video calling.
ImsManager imsManager =
- ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
+ ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
return imsManager.isVtEnabledByPlatform()
&& imsManager.isEnhanced4gLteModeSettingEnabledByUser()
&& imsManager.isVtEnabledByUser();
@@ -4588,7 +4595,7 @@
try {
CarrierConfigManager configManager =
(CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
- return configManager.getConfigForSubId(mPhone.getSubId())
+ return configManager.getConfigForSubId(subId)
.getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -4606,7 +4613,7 @@
try {
CarrierConfigManager configManager =
(CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
- return configManager.getConfigForSubId(mPhone.getSubId())
+ return configManager.getConfigForSubId(subId)
.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
} finally {
Binder.restoreCallingIdentity(identity);
@@ -4615,7 +4622,7 @@
@Override
public boolean isTtyModeSupported() {
- TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
+ TelecomManager telecomManager = TelecomManager.from(mApp);
return telecomManager.isTtySupported();
}
@@ -4623,7 +4630,7 @@
public boolean isHearingAidCompatibilitySupported() {
final long identity = Binder.clearCallingIdentity();
try {
- return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
+ return mApp.getResources().getBoolean(R.bool.hac_enabled);
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -4638,12 +4645,16 @@
@Override
public boolean isRttSupported(int subscriptionId) {
final long identity = Binder.clearCallingIdentity();
+ final Phone phone = getPhone(subscriptionId);
+ if (phone == null) {
+ loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
+ return false;
+ }
try {
- boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
- mPhone.getSubId()).getBoolean(
+ boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
boolean isDeviceSupported =
- mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
+ phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
return isCarrierSupported && isDeviceSupported;
} finally {
Binder.restoreCallingIdentity(identity);
@@ -4658,8 +4669,7 @@
final long identity = Binder.clearCallingIdentity();
try {
return isRttSupported(subscriptionId) && Settings.Secure.getInt(
- mPhone.getContext().getContentResolver(),
- Settings.Secure.RTT_CALLING_MODE, 0) != 0;
+ mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
} finally {
Binder.restoreCallingIdentity(identity);
}
@@ -4777,14 +4787,15 @@
}
final long identity = Binder.clearCallingIdentity();
+
try {
if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
setUserDataEnabled(subId, getDefaultDataEnabled());
setNetworkSelectionModeAutomatic(subId);
setPreferredNetworkType(subId, getDefaultNetworkType(subId));
- mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
- CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
+ setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
+ CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
}
} finally {
Binder.restoreCallingIdentity(identity);
@@ -4844,8 +4855,7 @@
// exact locale (e.g. fr_FR = French/France). So, if the locale returned from
// the SIM and carrier preferences does not include a country we add the country
// determined from the SIM MCC to provide an exact locale.
- final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
- simLanguage);
+ final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
if (mccLocale != null) {
if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
return mccLocale.toLanguageTag();
@@ -4859,16 +4869,14 @@
}
private List<SubscriptionInfo> getAllSubscriptionInfoList() {
- return mSubscriptionController.getAllSubInfoList(
- mPhone.getContext().getOpPackageName());
+ return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
}
/**
* NOTE: this method assumes permission checks are done and caller identity has been cleared.
*/
private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
- return mSubscriptionController.getActiveSubscriptionInfoList(
- mPhone.getContext().getOpPackageName());
+ return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
}
private final ModemActivityInfo mLastModemActivityInfo =
@@ -4983,7 +4991,7 @@
try {
Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
if (phone == null) {
- phone = mPhone;
+ phone = getDefaultPhone();
}
return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
@@ -5006,9 +5014,10 @@
@Override
public void setVoicemailRingtoneUri(String callingPackage,
PhoneAccountHandle phoneAccountHandle, Uri uri) {
+ final Phone defaultPhone = getDefaultPhone();
mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
if (!TextUtils.equals(callingPackage,
- TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
+ TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
"setVoicemailRingtoneUri");
@@ -5018,7 +5027,7 @@
try {
Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
if (phone == null) {
- phone = mPhone;
+ phone = defaultPhone;
}
VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
} finally {
@@ -5039,7 +5048,7 @@
try {
Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
if (phone == null) {
- phone = mPhone;
+ phone = getDefaultPhone();
}
return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
@@ -5062,9 +5071,10 @@
@Override
public void setVoicemailVibrationEnabled(String callingPackage,
PhoneAccountHandle phoneAccountHandle, boolean enabled) {
+ final Phone defaultPhone = getDefaultPhone();
mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
if (!TextUtils.equals(callingPackage,
- TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
+ TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
"setVoicemailVibrationEnabled");
@@ -5074,7 +5084,7 @@
try {
Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
if (phone == null) {
- phone = mPhone;
+ phone = defaultPhone;
}
VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
} finally {
@@ -5111,7 +5121,7 @@
final long identity = Binder.clearCallingIdentity();
try {
ComponentName componentName =
- RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
+ RemoteVvmTaskManager.getRemotePackage(mApp, subId);
if (componentName == null) {
throw new SecurityException(
"Caller not current active visual voicemail package[null]");
@@ -5364,8 +5374,8 @@
*/
@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
- if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
- != PERMISSION_GRANTED) {
+ if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+ != PackageManager.PERMISSION_GRANTED) {
writer.println("Permission Denial: can't dump Phone from pid="
+ Binder.getCallingPid()
+ ", uid=" + Binder.getCallingUid()
@@ -5373,7 +5383,7 @@
+ android.Manifest.permission.DUMP);
return;
}
- DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
+ DumpsysHandler.dump(mApp, fd, writer, args);
}
@Override
@@ -5457,7 +5467,7 @@
}
private WorkSource getWorkSource(int uid) {
- String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
+ String packageName = mApp.getPackageManager().getNameForUid(uid);
return new WorkSource(uid, packageName);
}
@@ -5490,8 +5500,7 @@
private boolean isUssdApiAllowed(int subId) {
CarrierConfigManager configManager =
- (CarrierConfigManager) mPhone.getContext().getSystemService(
- Context.CARRIER_CONFIG_SERVICE);
+ (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
if (configManager == null) {
return false;
}
@@ -5796,7 +5805,7 @@
*/
private boolean getDefaultDataRoamingEnabled(int subId) {
final CarrierConfigManager configMgr = (CarrierConfigManager)
- mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
+ mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(