Merge "better defualt behaviour for msim" am: fd810d8727

am: 6512f5eb10

Change-Id: Iedf27158b48f606a1f24e8780f98c3399e3337c7
This commit is contained in:
fionaxu
2017-04-28 20:03:56 +00:00
committed by android-build-merger

View File

@@ -885,7 +885,7 @@ public class TelephonyManager {
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/ */
public String getDeviceSoftwareVersion() { public String getDeviceSoftwareVersion() {
return getDeviceSoftwareVersion(getDefaultSim()); return getDeviceSoftwareVersion(getSlotIndex());
} }
/** /**
@@ -971,7 +971,7 @@ public class TelephonyManager {
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/ */
public String getImei() { public String getImei() {
return getImei(getDefaultSim()); return getImei(getSlotIndex());
} }
/** /**
@@ -1003,7 +1003,7 @@ public class TelephonyManager {
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/ */
public String getMeid() { public String getMeid() {
return getMeid(getDefaultSim()); return getMeid(getSlotIndex());
} }
/** /**
@@ -1033,7 +1033,7 @@ public class TelephonyManager {
*/ */
/** {@hide}*/ /** {@hide}*/
public String getNai() { public String getNai() {
return getNai(getDefaultSim()); return getNai(getSlotIndex());
} }
/** /**
@@ -1277,7 +1277,7 @@ public class TelephonyManager {
} }
private int getPhoneTypeFromProperty() { private int getPhoneTypeFromProperty() {
return getPhoneTypeFromProperty(getDefaultPhone()); return getPhoneTypeFromProperty(getPhoneId());
} }
/** {@hide} */ /** {@hide} */
@@ -1291,7 +1291,7 @@ public class TelephonyManager {
} }
private int getPhoneTypeFromNetworkType() { private int getPhoneTypeFromNetworkType() {
return getPhoneTypeFromNetworkType(getDefaultPhone()); return getPhoneTypeFromNetworkType(getPhoneId());
} }
/** {@hide} */ /** {@hide} */
@@ -1474,7 +1474,7 @@ public class TelephonyManager {
* on a CDMA network). * on a CDMA network).
*/ */
public String getNetworkOperator() { public String getNetworkOperator() {
return getNetworkOperatorForPhone(getDefaultPhone()); return getNetworkOperatorForPhone(getPhoneId());
} }
/** /**
@@ -1520,7 +1520,7 @@ public class TelephonyManager {
* @see #createForPhoneAccountHandle(PhoneAccountHandle) * @see #createForPhoneAccountHandle(PhoneAccountHandle)
*/ */
public String getNetworkSpecifier() { public String getNetworkSpecifier() {
return String.valueOf(mSubId); return String.valueOf(getSubId());
} }
/** /**
@@ -1539,7 +1539,7 @@ public class TelephonyManager {
public PersistableBundle getCarrierConfig() { public PersistableBundle getCarrierConfig() {
CarrierConfigManager carrierConfigManager = mContext CarrierConfigManager carrierConfigManager = mContext
.getSystemService(CarrierConfigManager.class); .getSystemService(CarrierConfigManager.class);
return carrierConfigManager.getConfigForSubId(mSubId); return carrierConfigManager.getConfigForSubId(getSubId());
} }
/** /**
@@ -1576,7 +1576,7 @@ public class TelephonyManager {
* on a CDMA network). * on a CDMA network).
*/ */
public String getNetworkCountryIso() { public String getNetworkCountryIso() {
return getNetworkCountryIsoForPhone(getDefaultPhone()); return getNetworkCountryIsoForPhone(getPhoneId());
} }
/** /**
@@ -1722,6 +1722,9 @@ public class TelephonyManager {
* Returns a constant indicating the radio technology (network type) * Returns a constant indicating the radio technology (network type)
* currently in use on the device for data transmission. * currently in use on the device for data transmission.
* *
* If this object has been created with {@link #createForSubscriptionId}, applies to the given
* subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()}
*
* <p> * <p>
* Requires Permission: * Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -1746,7 +1749,7 @@ public class TelephonyManager {
* @see #NETWORK_TYPE_HSPAP * @see #NETWORK_TYPE_HSPAP
*/ */
public int getDataNetworkType() { public int getDataNetworkType() {
return getDataNetworkType(getSubId()); return getDataNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()));
} }
/** /**
@@ -1970,7 +1973,7 @@ public class TelephonyManager {
* @return true if a ICC card is present * @return true if a ICC card is present
*/ */
public boolean hasIccCard() { public boolean hasIccCard() {
return hasIccCard(getDefaultSim()); return hasIccCard(getSlotIndex());
} }
/** /**
@@ -2011,7 +2014,7 @@ public class TelephonyManager {
* @see #SIM_STATE_CARD_RESTRICTED * @see #SIM_STATE_CARD_RESTRICTED
*/ */
public int getSimState() { public int getSimState() {
int slotIndex = getDefaultSim(); int slotIndex = getSlotIndex();
// slotIndex may be invalid due to sim being absent. In that case query all slots to get // slotIndex may be invalid due to sim being absent. In that case query all slots to get
// sim state // sim state
if (slotIndex < 0) { if (slotIndex < 0) {
@@ -2140,7 +2143,7 @@ public class TelephonyManager {
* @see #getSimState * @see #getSimState
*/ */
public String getSimOperatorName() { public String getSimOperatorName() {
return getSimOperatorNameForPhone(getDefaultPhone()); return getSimOperatorNameForPhone(getPhoneId());
} }
/** /**
@@ -2172,7 +2175,7 @@ public class TelephonyManager {
* Returns the ISO country code equivalent for the SIM provider's country code. * Returns the ISO country code equivalent for the SIM provider's country code.
*/ */
public String getSimCountryIso() { public String getSimCountryIso() {
return getSimCountryIsoForPhone(getDefaultPhone()); return getSimCountryIsoForPhone(getPhoneId());
} }
/** /**
@@ -2739,7 +2742,7 @@ public class TelephonyManager {
ITelephony telephony = getITelephony(); ITelephony telephony = getITelephony();
if (telephony != null) { if (telephony != null) {
return telephony return telephony
.getVisualVoicemailPackageName(mContext.getOpPackageName(), mSubId); .getVisualVoicemailPackageName(mContext.getOpPackageName(), getSubId());
} }
} catch (RemoteException ex) { } catch (RemoteException ex) {
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
@@ -4017,35 +4020,67 @@ public class TelephonyManager {
* subId is returned. Otherwise, the default subId will be returned. * subId is returned. Otherwise, the default subId will be returned.
*/ */
private int getSubId() { private int getSubId() {
if (mSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { if (SubscriptionManager.isUsableSubIdValue(mSubId)) {
return getDefaultSubscription();
}
return mSubId; return mSubId;
} }
/**
* Returns Default subscription.
*/
private static int getDefaultSubscription() {
return SubscriptionManager.getDefaultSubscriptionId(); return SubscriptionManager.getDefaultSubscriptionId();
} }
/** /**
* Returns Default phone. * Return an appropriate subscription ID for any situation.
*
* If this object has been created with {@link #createForSubscriptionId}, then the provided
* subId is returned. Otherwise, the preferred subId which is based on caller's context is
* returned.
* {@see SubscriptionManager#getDefaultDataSubscriptionId()}
* {@see SubscriptionManager#getDefaultVoiceSubscriptionId()}
* {@see SubscriptionManager#getDefaultSmsSubscriptionId()}
*/ */
private static int getDefaultPhone() { private int getSubId(int preferredSubId) {
return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubscriptionId()); if (SubscriptionManager.isUsableSubIdValue(mSubId)) {
return mSubId;
}
return preferredSubId;
} }
/** /**
* @return default SIM's slot index. If SIM is not inserted, return default SIM slot index. * Return an appropriate phone ID for any situation.
*
* If this object has been created with {@link #createForSubscriptionId}, then the phoneId
* associated with the provided subId is returned. Otherwise, the default phoneId associated
* with the default subId will be returned.
*/
private int getPhoneId() {
return SubscriptionManager.getPhoneId(getSubId());
}
/**
* Return an appropriate phone ID for any situation.
*
* If this object has been created with {@link #createForSubscriptionId}, then the phoneId
* associated with the provided subId is returned. Otherwise, return the phoneId associated
* with the preferred subId based on caller's context.
* {@see SubscriptionManager#getDefaultDataSubscriptionId()}
* {@see SubscriptionManager#getDefaultVoiceSubscriptionId()}
* {@see SubscriptionManager#getDefaultSmsSubscriptionId()}
*/
private int getPhoneId(int preferredSubId) {
return SubscriptionManager.getPhoneId(getSubId(preferredSubId));
}
/**
* Return an appropriate slot index for any situation.
*
* if this object has been created with {@link #createForSubscriptionId}, then the slot index
* associated with the provided subId is returned. Otherwise, return the slot index associated
* with the default subId.
* If SIM is not inserted, return default SIM slot index.
* *
* {@hide} * {@hide}
*/ */
@VisibleForTesting @VisibleForTesting
public int getDefaultSim() { public int getSlotIndex() {
int slotIndex = SubscriptionManager.getSlotIndex( int slotIndex = SubscriptionManager.getSlotIndex(getSubId());
SubscriptionManager.getDefaultSubscriptionId());
if (slotIndex == SubscriptionManager.SIM_NOT_INSERTED) { if (slotIndex == SubscriptionManager.SIM_NOT_INSERTED) {
slotIndex = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX; slotIndex = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX;
} }
@@ -4862,7 +4897,7 @@ public class TelephonyManager {
/** @hide */ /** @hide */
@SystemApi @SystemApi
public List<String> getCarrierPackageNamesForIntent(Intent intent) { public List<String> getCarrierPackageNamesForIntent(Intent intent) {
return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone()); return getCarrierPackageNamesForIntentAndPhone(intent, getPhoneId());
} }
/** @hide */ /** @hide */
@@ -5106,7 +5141,7 @@ public class TelephonyManager {
try { try {
ITelephony telephony = getITelephony(); ITelephony telephony = getITelephony();
if (telephony != null) { if (telephony != null) {
telephony.handleUssdRequest(mSubId, ussdRequest, wrappedCallback); telephony.handleUssdRequest(getSubId(), ussdRequest, wrappedCallback);
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e); Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e);
@@ -5124,7 +5159,8 @@ public class TelephonyManager {
public boolean isConcurrentVoiceAndDataAllowed() { public boolean isConcurrentVoiceAndDataAllowed() {
try { try {
ITelephony telephony = getITelephony(); ITelephony telephony = getITelephony();
return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed(mSubId)); return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed(
getSubId()));
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e); Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e);
} }
@@ -5261,6 +5297,8 @@ public class TelephonyManager {
/** /**
* Turns mobile data on or off. * Turns mobile data on or off.
* If this object has been created with {@link #createForSubscriptionId}, applies to the given
* subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()}
* *
* <p>Requires Permission: * <p>Requires Permission:
* {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the
@@ -5271,7 +5309,7 @@ public class TelephonyManager {
* @see #hasCarrierPrivileges * @see #hasCarrierPrivileges
*/ */
public void setDataEnabled(boolean enable) { public void setDataEnabled(boolean enable) {
setDataEnabled(getSubId(), enable); setDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enable);
} }
/** @hide */ /** @hide */
@@ -5301,6 +5339,9 @@ public class TelephonyManager {
/** /**
* Returns whether mobile data is enabled or not. * Returns whether mobile data is enabled or not.
* *
* If this object has been created with {@link #createForSubscriptionId}, applies to the given
* subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()}
*
* <p>Requires one of the following permissions: * <p>Requires one of the following permissions:
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE ACCESS_NETWORK_STATE}, * {@link android.Manifest.permission#ACCESS_NETWORK_STATE ACCESS_NETWORK_STATE},
* {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}, or that the * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}, or that the
@@ -5316,7 +5357,7 @@ public class TelephonyManager {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean isDataEnabled() { public boolean isDataEnabled() {
return getDataEnabled(getSubId()); return getDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()));
} }
/** /**
@@ -5566,7 +5607,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setSimOperatorNumeric(String numeric) { public void setSimOperatorNumeric(String numeric) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setSimOperatorNumericForPhone(phoneId, numeric); setSimOperatorNumericForPhone(phoneId, numeric);
} }
@@ -5586,7 +5627,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setSimOperatorName(String name) { public void setSimOperatorName(String name) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setSimOperatorNameForPhone(phoneId, name); setSimOperatorNameForPhone(phoneId, name);
} }
@@ -5606,7 +5647,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setSimCountryIso(String iso) { public void setSimCountryIso(String iso) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setSimCountryIsoForPhone(phoneId, iso); setSimCountryIsoForPhone(phoneId, iso);
} }
@@ -5626,7 +5667,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setSimState(String state) { public void setSimState(String state) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setSimStateForPhone(phoneId, state); setSimStateForPhone(phoneId, state);
} }
@@ -5651,7 +5692,7 @@ public class TelephonyManager {
* @hide * @hide
**/ **/
public void setSimPowerState(boolean powerUp) { public void setSimPowerState(boolean powerUp) {
setSimPowerStateForSlot(getDefaultSim(), powerUp); setSimPowerStateForSlot(getSlotIndex(), powerUp);
} }
/** /**
@@ -5685,7 +5726,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setBasebandVersion(String version) { public void setBasebandVersion(String version) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setBasebandVersionForPhone(phoneId, version); setBasebandVersionForPhone(phoneId, version);
} }
@@ -5712,7 +5753,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setPhoneType(int type) { public void setPhoneType(int type) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setPhoneType(phoneId, type); setPhoneType(phoneId, type);
} }
@@ -5740,7 +5781,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public String getOtaSpNumberSchema(String defaultValue) { public String getOtaSpNumberSchema(String defaultValue) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); return getOtaSpNumberSchemaForPhone(phoneId, defaultValue);
} }
@@ -5771,7 +5812,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public boolean getSmsReceiveCapable(boolean defaultValue) { public boolean getSmsReceiveCapable(boolean defaultValue) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
return getSmsReceiveCapableForPhone(phoneId, defaultValue); return getSmsReceiveCapableForPhone(phoneId, defaultValue);
} }
@@ -5802,7 +5843,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public boolean getSmsSendCapable(boolean defaultValue) { public boolean getSmsSendCapable(boolean defaultValue) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
return getSmsSendCapableForPhone(phoneId, defaultValue); return getSmsSendCapableForPhone(phoneId, defaultValue);
} }
@@ -5830,7 +5871,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setNetworkOperatorName(String name) { public void setNetworkOperatorName(String name) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setNetworkOperatorNameForPhone(phoneId, name); setNetworkOperatorNameForPhone(phoneId, name);
} }
@@ -5852,7 +5893,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setNetworkOperatorNumeric(String numeric) { public void setNetworkOperatorNumeric(String numeric) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setNetworkOperatorNumericForPhone(phoneId, numeric); setNetworkOperatorNumericForPhone(phoneId, numeric);
} }
@@ -5872,7 +5913,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setNetworkRoaming(boolean isRoaming) { public void setNetworkRoaming(boolean isRoaming) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setNetworkRoamingForPhone(phoneId, isRoaming); setNetworkRoamingForPhone(phoneId, isRoaming);
} }
@@ -5896,7 +5937,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public void setNetworkCountryIso(String iso) { public void setNetworkCountryIso(String iso) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId();
setNetworkCountryIsoForPhone(phoneId, iso); setNetworkCountryIsoForPhone(phoneId, iso);
} }
@@ -5916,11 +5957,15 @@ public class TelephonyManager {
/** /**
* Set the network type currently in use on the device for data transmission. * Set the network type currently in use on the device for data transmission.
*
* If this object has been created with {@link #createForSubscriptionId}, applies to the
* phoneId associated with the given subId. Otherwise, applies to the phoneId associated with
* {@link SubscriptionManager#getDefaultDataSubscriptionId()}
* @param type the network type currently in use on the device for data transmission * @param type the network type currently in use on the device for data transmission
* @hide * @hide
*/ */
public void setDataNetworkType(int type) { public void setDataNetworkType(int type) {
int phoneId = getDefaultPhone(); int phoneId = getPhoneId(SubscriptionManager.getDefaultDataSubscriptionId());
setDataNetworkTypeForPhone(phoneId, type); setDataNetworkTypeForPhone(phoneId, type);
} }
@@ -6092,7 +6137,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public String getAidForAppType(int appType) { public String getAidForAppType(int appType) {
return getAidForAppType(getDefaultSubscription(), appType); return getAidForAppType(getSubId(), appType);
} }
/** /**
@@ -6126,7 +6171,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public String getEsn() { public String getEsn() {
return getEsn(getDefaultSubscription()); return getEsn(getSubId());
} }
/** /**
@@ -6159,7 +6204,7 @@ public class TelephonyManager {
* @hide * @hide
*/ */
public String getCdmaPrlVersion() { public String getCdmaPrlVersion() {
return getCdmaPrlVersion(getDefaultSubscription()); return getCdmaPrlVersion(getSubId());
} }
/** /**