Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9387f1df authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Changing getSimState to use slot idx instead of sub id.

Bug: 20736251
Change-Id: I43ec6450358f833f878ed4eee993ea79d5220c65
parent 72285e56
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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_ABSENT}
@@ -1123,16 +1123,16 @@ public class SubscriptionManager {
     *
     * {@hide}
     */
    public static int getSimStateForSubscriber(int subId) {
    public static int getSimStateForSlotIdx(int slotIdx) {
        int simState;

        try {
            ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
            simState = iSub.getSimStateForSubscriber(subId);
            simState = iSub.getSimStateForSlotIdx(slotIdx);
        } catch (RemoteException ex) {
            simState = TelephonyManager.SIM_STATE_UNKNOWN;
        }
        logd("getSimStateForSubscriber: simState=" + simState + " subId=" + subId);
        logd("getSimStateForSubscriber: simState=" + simState + " slotIdx=" + slotIdx);
        return simState;
    }

+20 −7
Original line number Diff line number Diff line
@@ -1625,7 +1625,25 @@ public class TelephonyManager {
     * @see #SIM_STATE_CARD_IO_ERROR
     */
    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} */
    public int getSimState(int slotIdx) {
        int[] subId = SubscriptionManager.getSubId(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]);
        int simState = SubscriptionManager.getSimStateForSlotIdx(slotIdx);
        return simState;
    }

+2 −2
Original line number Diff line number Diff line
@@ -180,10 +180,10 @@ interface ISub {
    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
     */
    int getSimStateForSubscriber(int subId);
    int getSimStateForSlotIdx(int slotIdx);

    boolean isActiveSubId(int subId);
}