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

Commit 0690fc4d authored by Chen Xu's avatar Chen Xu Committed by Automerger Merge Worker
Browse files

Merge "SIM deprecated API Refactoring" am: e6190813 am: 576daa91 am: 6e261d1c

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1933235

Change-Id: I45b456578dd7a15bbadd2ebea2f3f69038d0be22
parents 242baad9 6e261d1c
Loading
Loading
Loading
Loading
+8 −25
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import android.telephony.TelephonyFrameworkInitializer;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyRegistryManager;
import android.telephony.UiccAccessRule;
import android.telephony.UiccPortInfo;
import android.telephony.UiccSlotInfo;
import android.telephony.euicc.EuiccManager;
import android.text.TextUtils;
@@ -4066,7 +4067,8 @@ public class SubscriptionController extends ISub.Stub {
        // Can't find the existing SIM.
        if (slotInfo == null) return false;

        if (enable && !slotInfo.getIsActive()) {
        // this for physical slot which has only one port
        if (enable && !slotInfo.getPorts().stream().findFirst().get().isActive()) {
            // We need to send intents to Euicc if we are turning on an inactive slot.
            // Euicc will decide whether to ask user to switch to DSDS, or change SIM
            // slot mapping.
@@ -4121,36 +4123,17 @@ public class SubscriptionController extends ISub.Stub {
                        + physicalSlotIndex, enabled ? 1 : 0);
    }

    private int getPhysicalSlotIndex(boolean isEmbedded, int subId) {
        UiccSlotInfo[] slotInfos = mTelephonyManager.getUiccSlotsInfo();
        int logicalSlotIndex = getSlotIndex(subId);
        int physicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
        boolean isLogicalSlotIndexValid = SubscriptionManager.isValidSlotIndex(logicalSlotIndex);

        for (int i = 0; i < slotInfos.length; i++) {
            // If we can know the logicalSlotIndex from subId, we should find the exact matching
            // physicalSlotIndex. However for some cases like inactive eSIM, the logicalSlotIndex
            // will be -1. In this case, we assume there's only one eSIM, and return the
            // physicalSlotIndex of that eSIM.
            if ((isLogicalSlotIndexValid && slotInfos[i].getLogicalSlotIdx() == logicalSlotIndex)
                    || (!isLogicalSlotIndexValid && slotInfos[i].getIsEuicc() && isEmbedded)) {
                physicalSlotIndex = i;
                break;
            }
        }

        return physicalSlotIndex;
    }

    private int getPhysicalSlotIndexFromLogicalSlotIndex(int logicalSlotIndex) {
        int physicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
        UiccSlotInfo[] slotInfos = mTelephonyManager.getUiccSlotsInfo();
        for (int i = 0; i < slotInfos.length; i++) {
            if (slotInfos[i].getLogicalSlotIdx() == logicalSlotIndex) {
            for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
                if (portInfo.getLogicalSlotIndex() == logicalSlotIndex) {
                    physicalSlotIndex = i;
                    break;
                }
            }
        }

        return physicalSlotIndex;
    }
+11 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.telephony.uicc.UiccCard;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UiccPort;
import com.android.internal.telephony.uicc.UiccSlot;
import com.android.telephony.Rlog;

@@ -1154,6 +1155,11 @@ public class SubscriptionInfoUpdater extends Handler {
            // should do a review of whether to make this public
            int slotId = UiccController.getInstance().getSlotIdFromPhoneId(phoneId);
            i.putExtra(PhoneConstants.SLOT_KEY, slotId);
            UiccPort portInfo = UiccController.getInstance().getUiccPortForPhone(phoneId);
            if (portInfo != null) {
                int portId = portInfo.getPortIdx();
                i.putExtra(PhoneConstants.PORT_KEY, portId);
            }
            logd("Broadcasting intent ACTION_SIM_CARD_STATE_CHANGED " + simStateString(state)
                    + " for phone: " + phoneId + " slot: " + slotId);
            sContext.sendBroadcast(i, Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
@@ -1181,6 +1187,11 @@ public class SubscriptionInfoUpdater extends Handler {
            // should do a review of whether to make this public
            int slotId = UiccController.getInstance().getSlotIdFromPhoneId(phoneId);
            i.putExtra(PhoneConstants.SLOT_KEY, slotId);
            UiccPort portInfo = UiccController.getInstance().getUiccPortForPhone(phoneId);
            if (portInfo != null) {
                int portId = portInfo.getPortIdx();
                i.putExtra(PhoneConstants.PORT_KEY, portId);
            }
            logd("Broadcasting intent ACTION_SIM_APPLICATION_STATE_CHANGED " + simStateString(state)
                    + " for phone: " + phoneId + " slot: " + slotId);
            sContext.sendBroadcast(i, Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
+8 −8
Original line number Diff line number Diff line
@@ -329,8 +329,8 @@ public class EuiccCardController extends IEuiccCardController.Stub {
    }

    @Override
    public void disableProfile(String callingPackage, String cardId, String iccid, boolean refresh,
            IDisableProfileCallback callback) {
    public void disableProfile(String callingPackage, String cardId, String iccid, int portIndex,
            boolean refresh, IDisableProfileCallback callback) {
        try {
            checkCallingPackage(callingPackage);
        } catch (SecurityException se) {
@@ -342,12 +342,12 @@ public class EuiccCardController extends IEuiccCardController.Stub {
            return;
        }

        EuiccPort port = getEuiccPort(cardId, TelephonyManager.DEFAULT_PORT_INDEX);
        EuiccPort port = getEuiccPort(cardId, portIndex);
        if (port == null) {
            try {
                callback.onComplete(EuiccCardManager.RESULT_EUICC_NOT_FOUND);
            } catch (RemoteException exception) {
                loge("disableProfile callback failure.", exception);
                loge("disableProfile callback failure for portIndex: " + portIndex , exception);
            }
            return;
        }
@@ -377,8 +377,8 @@ public class EuiccCardController extends IEuiccCardController.Stub {
    }

    @Override
    public void switchToProfile(String callingPackage, String cardId, String iccid, boolean refresh,
            ISwitchToProfileCallback callback) {
    public void switchToProfile(String callingPackage, String cardId, String iccid, int portIndex,
            boolean refresh, ISwitchToProfileCallback callback) {
        try {
            checkCallingPackage(callingPackage);
        } catch (SecurityException se) {
@@ -390,12 +390,12 @@ public class EuiccCardController extends IEuiccCardController.Stub {
            return;
        }

        EuiccPort port = getEuiccPort(cardId, TelephonyManager.DEFAULT_PORT_INDEX);
        EuiccPort port = getEuiccPort(cardId, portIndex);
        if (port == null) {
            try {
                callback.onComplete(EuiccCardManager.RESULT_EUICC_NOT_FOUND, null);
            } catch (RemoteException exception) {
                loge("switchToProfile callback failure.", exception);
                loge("switchToProfile callback failure for portIndex :" + portIndex, exception);
            }
            return;
        }
+1 −1
Original line number Diff line number Diff line
@@ -1042,7 +1042,7 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
        int slotId = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
        for (UiccCardInfo info : infos) {
            if (info.getCardId() == cardId) {
                slotId = info.getSlotIndex();
                slotId = info.getPhysicalSlotIndex();
            }
        }
        return slotId;
+34 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.telephony.TelephonyFrameworkInitializer;
import android.telephony.TelephonyManager;
import android.telephony.UiccAccessRule;
import android.telephony.UiccCardInfo;
import android.telephony.UiccPortInfo;
import android.telephony.euicc.DownloadableSubscription;
import android.telephony.euicc.EuiccCardManager.ResetOption;
import android.telephony.euicc.EuiccInfo;
@@ -54,6 +55,9 @@ import android.util.Pair;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.euicc.EuiccConnector.OtaStatusChangedCallback;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UiccPort;
import com.android.internal.telephony.util.ArrayUtils;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -1567,4 +1571,34 @@ public class EuiccController extends IEuiccController.Stub {
                Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
                == PackageManager.PERMISSION_GRANTED;
    }
    @Override
    public boolean isSimPortAvailable(int cardId, int portIndex, String callingPackage) {
        List<UiccCardInfo> cardInfos = mTelephonyManager.getUiccCardsInfo();
        if (ArrayUtils.isEmpty(cardInfos)) {
            return false;
        }
        int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
        for (UiccCardInfo info : cardInfos) {
            //return false if physical card
            if (info != null && info.getCardId() == cardId && (!info.isEuicc()
                    || info.isRemovable())) {
                return false;
            }
            for (UiccPortInfo portInfo : info.getPorts()) {
                UiccPort port = UiccController.getInstance().getUiccPort(portIndex);
                if (port == null) {
                    return false;
                }
                // port is available if port is inactive and ICCID  or calling app has carrier
                // privilege over the profile installed on the selected port.
                result = port.getUiccProfile().getCarrierPrivilegeStatus(
                        mContext.getPackageManager(), callingPackage);
                if ((result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS)
                        || (portInfo.getIccId() == null && portInfo.isActive())) {
                    return true;
                }
            }
        }
        return false;
    }
}
Loading