Merge "Changing getSimState to use slot idx instead of sub id." into mnc-dev

This commit is contained in:
Amit Mahajan
2015-06-08 17:26:00 +00:00
committed by Android (Google) Code Review
3 changed files with 27 additions and 14 deletions

View File

@@ -1107,9 +1107,9 @@ public class SubscriptionManager {
} }
/** /**
* Returns a constant indicating the state of sim for the subscription. * Returns a constant indicating the state of sim for the slot idx.
* *
* @param subId * @param slotIdx
* *
* {@See TelephonyManager#SIM_STATE_UNKNOWN} * {@See TelephonyManager#SIM_STATE_UNKNOWN}
* {@See TelephonyManager#SIM_STATE_ABSENT} * {@See TelephonyManager#SIM_STATE_ABSENT}
@@ -1123,16 +1123,16 @@ public class SubscriptionManager {
* *
* {@hide} * {@hide}
*/ */
public static int getSimStateForSubscriber(int subId) { public static int getSimStateForSlotIdx(int slotIdx) {
int simState; int simState;
try { try {
ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
simState = iSub.getSimStateForSubscriber(subId); simState = iSub.getSimStateForSlotIdx(slotIdx);
} catch (RemoteException ex) { } catch (RemoteException ex) {
simState = TelephonyManager.SIM_STATE_UNKNOWN; simState = TelephonyManager.SIM_STATE_UNKNOWN;
} }
logd("getSimStateForSubscriber: simState=" + simState + " subId=" + subId); logd("getSimStateForSubscriber: simState=" + simState + " slotIdx=" + slotIdx);
return simState; return simState;
} }

View File

@@ -1625,7 +1625,25 @@ public class TelephonyManager {
* @see #SIM_STATE_CARD_IO_ERROR * @see #SIM_STATE_CARD_IO_ERROR
*/ */
public int getSimState() { public int getSimState() {
return getSimState(getDefaultSim()); int slotIdx = getDefaultSim();
// slotIdx may be invalid due to sim being absent. In that case query all slots to get
// sim state
if (slotIdx < 0) {
// query for all slots and return absent if all sim states are absent, otherwise
// return unknown
for (int i = 0; i < getPhoneCount(); i++) {
int simState = getSimState(i);
if (simState != SIM_STATE_ABSENT) {
Rlog.d(TAG, "getSimState: default sim:" + slotIdx + ", sim state for " +
"slotIdx=" + i + " is " + simState + ", return state as unknown");
return SIM_STATE_UNKNOWN;
}
}
Rlog.d(TAG, "getSimState: default sim:" + slotIdx + ", all SIMs absent, return " +
"state as absent");
return SIM_STATE_ABSENT;
}
return getSimState(slotIdx);
} }
/** /**
@@ -1645,12 +1663,7 @@ public class TelephonyManager {
*/ */
/** {@hide} */ /** {@hide} */
public int getSimState(int slotIdx) { public int getSimState(int slotIdx) {
int[] subId = SubscriptionManager.getSubId(slotIdx); int simState = SubscriptionManager.getSimStateForSlotIdx(slotIdx);
if (subId == null || subId.length == 0) {
Rlog.d(TAG, "getSimState:- empty subId return SIM_STATE_ABSENT");
return SIM_STATE_UNKNOWN;
}
int simState = SubscriptionManager.getSimStateForSubscriber(subId[0]);
return simState; return simState;
} }

View File

@@ -180,10 +180,10 @@ interface ISub {
int[] getActiveSubIdList(); int[] getActiveSubIdList();
/** /**
* Get the SIM state for the subscriber * Get the SIM state for the slot idx
* @return SIM state as the ordinal of IccCardConstants.State * @return SIM state as the ordinal of IccCardConstants.State
*/ */
int getSimStateForSubscriber(int subId); int getSimStateForSlotIdx(int slotIdx);
boolean isActiveSubId(int subId); boolean isActiveSubId(int subId);
} }