Merge "better defualt behaviour for msim" into oc-dev

This commit is contained in:
Chen Xu
2017-04-19 00:34:52 +00:00
committed by Android (Google) Code Review

View File

@@ -911,7 +911,7 @@ public class TelephonyManager {
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getDeviceSoftwareVersion() {
return getDeviceSoftwareVersion(getDefaultSim());
return getDeviceSoftwareVersion(getSlotIndex());
}
/**
@@ -997,7 +997,7 @@ public class TelephonyManager {
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getImei() {
return getImei(getDefaultSim());
return getImei(getSlotIndex());
}
/**
@@ -1029,7 +1029,7 @@ public class TelephonyManager {
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getMeid() {
return getMeid(getDefaultSim());
return getMeid(getSlotIndex());
}
/**
@@ -1059,7 +1059,7 @@ public class TelephonyManager {
*/
/** {@hide}*/
public String getNai() {
return getNai(getDefaultSim());
return getNai(getSlotIndex());
}
/**
@@ -1303,7 +1303,7 @@ public class TelephonyManager {
}
private int getPhoneTypeFromProperty() {
return getPhoneTypeFromProperty(getDefaultPhone());
return getPhoneTypeFromProperty(getPhoneId());
}
/** {@hide} */
@@ -1317,7 +1317,7 @@ public class TelephonyManager {
}
private int getPhoneTypeFromNetworkType() {
return getPhoneTypeFromNetworkType(getDefaultPhone());
return getPhoneTypeFromNetworkType(getPhoneId());
}
/** {@hide} */
@@ -1500,7 +1500,7 @@ public class TelephonyManager {
* on a CDMA network).
*/
public String getNetworkOperator() {
return getNetworkOperatorForPhone(getDefaultPhone());
return getNetworkOperatorForPhone(getPhoneId());
}
/**
@@ -1546,7 +1546,7 @@ public class TelephonyManager {
* @see #createForPhoneAccountHandle(PhoneAccountHandle)
*/
public String getNetworkSpecifier() {
return String.valueOf(mSubId);
return String.valueOf(getSubId());
}
/**
@@ -1565,7 +1565,7 @@ public class TelephonyManager {
public PersistableBundle getCarrierConfig() {
CarrierConfigManager carrierConfigManager = mContext
.getSystemService(CarrierConfigManager.class);
return carrierConfigManager.getConfigForSubId(mSubId);
return carrierConfigManager.getConfigForSubId(getSubId());
}
/**
@@ -1602,7 +1602,7 @@ public class TelephonyManager {
* on a CDMA network).
*/
public String getNetworkCountryIso() {
return getNetworkCountryIsoForPhone(getDefaultPhone());
return getNetworkCountryIsoForPhone(getPhoneId());
}
/**
@@ -1748,6 +1748,9 @@ public class TelephonyManager {
* Returns a constant indicating the radio technology (network type)
* 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>
* Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -1772,7 +1775,7 @@ public class TelephonyManager {
* @see #NETWORK_TYPE_HSPAP
*/
public int getDataNetworkType() {
return getDataNetworkType(getSubId());
return getDataNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()));
}
/**
@@ -1996,7 +1999,7 @@ public class TelephonyManager {
* @return true if a ICC card is present
*/
public boolean hasIccCard() {
return hasIccCard(getDefaultSim());
return hasIccCard(getSlotIndex());
}
/**
@@ -2037,7 +2040,7 @@ public class TelephonyManager {
* @see #SIM_STATE_CARD_RESTRICTED
*/
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
// sim state
if (slotIndex < 0) {
@@ -2166,7 +2169,7 @@ public class TelephonyManager {
* @see #getSimState
*/
public String getSimOperatorName() {
return getSimOperatorNameForPhone(getDefaultPhone());
return getSimOperatorNameForPhone(getPhoneId());
}
/**
@@ -2198,7 +2201,7 @@ public class TelephonyManager {
* Returns the ISO country code equivalent for the SIM provider's country code.
*/
public String getSimCountryIso() {
return getSimCountryIsoForPhone(getDefaultPhone());
return getSimCountryIsoForPhone(getPhoneId());
}
/**
@@ -2754,7 +2757,7 @@ public class TelephonyManager {
ITelephony telephony = getITelephony();
if (telephony != null) {
return telephony
.getVisualVoicemailPackageName(mContext.getOpPackageName(), mSubId);
.getVisualVoicemailPackageName(mContext.getOpPackageName(), getSubId());
}
} catch (RemoteException ex) {
} catch (NullPointerException ex) {
@@ -4057,35 +4060,67 @@ public class TelephonyManager {
* subId is returned. Otherwise, the default subId will be returned.
*/
private int getSubId() {
if (mSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
return getDefaultSubscription();
if (SubscriptionManager.isUsableSubIdValue(mSubId)) {
return mSubId;
}
return mSubId;
return SubscriptionManager.getDefaultSubscriptionId();
}
/**
* Returns Default subscription.
* 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 getDefaultSubscription() {
return SubscriptionManager.getDefaultSubscriptionId();
private int getSubId(int preferredSubId) {
if (SubscriptionManager.isUsableSubIdValue(mSubId)) {
return mSubId;
}
return preferredSubId;
}
/**
* Returns Default phone.
* 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 static int getDefaultPhone() {
return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubscriptionId());
private int getPhoneId() {
return SubscriptionManager.getPhoneId(getSubId());
}
/**
* @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, 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}
*/
@VisibleForTesting
public int getDefaultSim() {
int slotIndex = SubscriptionManager.getSlotIndex(
SubscriptionManager.getDefaultSubscriptionId());
public int getSlotIndex() {
int slotIndex = SubscriptionManager.getSlotIndex(getSubId());
if (slotIndex == SubscriptionManager.SIM_NOT_INSERTED) {
slotIndex = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX;
}
@@ -4902,7 +4937,7 @@ public class TelephonyManager {
/** @hide */
@SystemApi
public List<String> getCarrierPackageNamesForIntent(Intent intent) {
return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone());
return getCarrierPackageNamesForIntentAndPhone(intent, getPhoneId());
}
/** @hide */
@@ -5164,7 +5199,7 @@ public class TelephonyManager {
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
telephony.handleUssdRequest(mSubId, ussdRequest, wrappedCallback);
telephony.handleUssdRequest(getSubId(), ussdRequest, wrappedCallback);
}
} catch (RemoteException e) {
Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e);
@@ -5184,7 +5219,8 @@ public class TelephonyManager {
public boolean isConcurrentVoiceAndDataSupported() {
try {
ITelephony telephony = getITelephony();
return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed(mSubId));
return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed(
getSubId()));
} catch (RemoteException e) {
Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e);
}
@@ -5321,6 +5357,8 @@ public class TelephonyManager {
/**
* 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:
* {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the
@@ -5331,7 +5369,7 @@ public class TelephonyManager {
* @see #hasCarrierPrivileges
*/
public void setDataEnabled(boolean enable) {
setDataEnabled(getSubId(), enable);
setDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enable);
}
/** @hide */
@@ -5361,6 +5399,9 @@ public class TelephonyManager {
/**
* 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:
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE ACCESS_NETWORK_STATE},
* {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}, or that the
@@ -5376,7 +5417,7 @@ public class TelephonyManager {
*/
@SuppressWarnings("deprecation")
public boolean isDataEnabled() {
return getDataEnabled(getSubId());
return getDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()));
}
/**
@@ -5626,7 +5667,7 @@ public class TelephonyManager {
* @hide
*/
public void setSimOperatorNumeric(String numeric) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setSimOperatorNumericForPhone(phoneId, numeric);
}
@@ -5646,7 +5687,7 @@ public class TelephonyManager {
* @hide
*/
public void setSimOperatorName(String name) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setSimOperatorNameForPhone(phoneId, name);
}
@@ -5666,7 +5707,7 @@ public class TelephonyManager {
* @hide
*/
public void setSimCountryIso(String iso) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setSimCountryIsoForPhone(phoneId, iso);
}
@@ -5686,7 +5727,7 @@ public class TelephonyManager {
* @hide
*/
public void setSimState(String state) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setSimStateForPhone(phoneId, state);
}
@@ -5711,7 +5752,7 @@ public class TelephonyManager {
* @hide
**/
public void setSimPowerState(boolean powerUp) {
setSimPowerStateForSlot(getDefaultSim(), powerUp);
setSimPowerStateForSlot(getSlotIndex(), powerUp);
}
/**
@@ -5745,7 +5786,7 @@ public class TelephonyManager {
* @hide
*/
public void setBasebandVersion(String version) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setBasebandVersionForPhone(phoneId, version);
}
@@ -5772,7 +5813,7 @@ public class TelephonyManager {
* @hide
*/
public void setPhoneType(int type) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setPhoneType(phoneId, type);
}
@@ -5800,7 +5841,7 @@ public class TelephonyManager {
* @hide
*/
public String getOtaSpNumberSchema(String defaultValue) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
return getOtaSpNumberSchemaForPhone(phoneId, defaultValue);
}
@@ -5831,7 +5872,7 @@ public class TelephonyManager {
* @hide
*/
public boolean getSmsReceiveCapable(boolean defaultValue) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
return getSmsReceiveCapableForPhone(phoneId, defaultValue);
}
@@ -5862,7 +5903,7 @@ public class TelephonyManager {
* @hide
*/
public boolean getSmsSendCapable(boolean defaultValue) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
return getSmsSendCapableForPhone(phoneId, defaultValue);
}
@@ -5890,7 +5931,7 @@ public class TelephonyManager {
* @hide
*/
public void setNetworkOperatorName(String name) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setNetworkOperatorNameForPhone(phoneId, name);
}
@@ -5912,7 +5953,7 @@ public class TelephonyManager {
* @hide
*/
public void setNetworkOperatorNumeric(String numeric) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setNetworkOperatorNumericForPhone(phoneId, numeric);
}
@@ -5932,7 +5973,7 @@ public class TelephonyManager {
* @hide
*/
public void setNetworkRoaming(boolean isRoaming) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setNetworkRoamingForPhone(phoneId, isRoaming);
}
@@ -5956,7 +5997,7 @@ public class TelephonyManager {
* @hide
*/
public void setNetworkCountryIso(String iso) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId();
setNetworkCountryIsoForPhone(phoneId, iso);
}
@@ -5976,11 +6017,15 @@ public class TelephonyManager {
/**
* 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
* @hide
*/
public void setDataNetworkType(int type) {
int phoneId = getDefaultPhone();
int phoneId = getPhoneId(SubscriptionManager.getDefaultDataSubscriptionId());
setDataNetworkTypeForPhone(phoneId, type);
}
@@ -6200,7 +6245,7 @@ public class TelephonyManager {
* @hide
*/
public String getAidForAppType(int appType) {
return getAidForAppType(getDefaultSubscription(), appType);
return getAidForAppType(getSubId(), appType);
}
/**
@@ -6234,7 +6279,7 @@ public class TelephonyManager {
* @hide
*/
public String getEsn() {
return getEsn(getDefaultSubscription());
return getEsn(getSubId());
}
/**
@@ -6267,7 +6312,7 @@ public class TelephonyManager {
* @hide
*/
public String getCdmaPrlVersion() {
return getCdmaPrlVersion(getDefaultSubscription());
return getCdmaPrlVersion(getSubId());
}
/**