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

Commit 1b78a9f4 authored by Chen Xu's avatar Chen Xu Committed by Android (Google) Code Review
Browse files

Merge "[MEP] Modify deprecated iccLogicalChannel APIs to pass first active...

Merge "[MEP] Modify deprecated iccLogicalChannel APIs to pass first active port index instead of DEFAULT_PORT_INDEX 0."
parents 9ee529d8 aa04662b
Loading
Loading
Loading
Loading
+35 −8
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
@@ -6806,6 +6807,24 @@ public class TelephonyManager {
        return null;
    }
    /**
     * Get the first active portIndex from the corresponding physical slot index.
     * @param physicalSlotIndex physical slot index
     * @return first active port index or INVALID_PORT_INDEX if no port is active
     */
    private int getFirstActivePortIndex(int physicalSlotIndex) {
        UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
        if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.length
                && slotInfos[physicalSlotIndex] != null) {
            Optional<UiccPortInfo> result =  slotInfos[physicalSlotIndex].getPorts().stream()
                    .filter(portInfo -> portInfo.isActive()).findFirst();
            if (result.isPresent()) {
                return result.get().getPortIndex();
            }
        }
        return INVALID_PORT_INDEX;
    }
    /**
     * Opens a logical channel to the ICC card.
     *
@@ -6852,7 +6871,8 @@ public class TelephonyManager {
     * @param p2 P2 parameter (described in ISO 7816-4).
     * @return an IccOpenLogicalChannelResponse object.
     * @hide
     * @deprecated instead use {@link #iccOpenLogicalChannelByPort(int, int, String, int)}
     * @deprecated This API is not compatible on eUICC supporting Multiple Enabled Profile(MEP),
     * instead use {@link #iccOpenLogicalChannelByPort(int, int, String, int)}
     */
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)
@@ -6866,6 +6886,7 @@ public class TelephonyManager {
            if (telephony != null) {
                IccLogicalChannelRequest request = new IccLogicalChannelRequest();
                request.slotIndex = slotIndex;
                request.portIndex = getFirstActivePortIndex(slotIndex);
                request.aid = aid;
                request.p2 = p2;
                request.callingPackage = getOpPackageName();
@@ -7021,7 +7042,8 @@ public class TelephonyManager {
     *            iccOpenLogicalChannel.
     * @return true if the channel was closed successfully.
     * @hide
     * @deprecated instead use {@link #iccCloseLogicalChannelByPort(int, int, int)}
     * @deprecated This API is not compatible on eUICC supporting Multiple Enabled Profile(MEP),
     * instead use {@link #iccCloseLogicalChannelByPort(int, int, int)}
     */
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)
@@ -7033,6 +7055,7 @@ public class TelephonyManager {
            if (telephony != null) {
                IccLogicalChannelRequest request = new IccLogicalChannelRequest();
                request.slotIndex = slotIndex;
                request.portIndex = getFirstActivePortIndex(slotIndex);
                request.channel = channel;
                return telephony.iccCloseLogicalChannel(request);
            }
@@ -7153,7 +7176,8 @@ public class TelephonyManager {
     * @return The APDU response from the ICC card with the status appended at the end, or null if
     * there is an issue connecting to the Telephony service.
     * @hide
     * @deprecated instead use
     * @deprecated This API is not compatible on eUICC supporting Multiple Enabled Profile(MEP),
     * instead use
     * {@link #iccTransmitApduLogicalChannelByPort(int, int, int, int, int, int, int, int, String)}
     */
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
@@ -7166,8 +7190,9 @@ public class TelephonyManager {
        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                return telephony.iccTransmitApduLogicalChannelByPort(slotIndex, DEFAULT_PORT_INDEX,
                         channel, cla, instruction, p1, p2, p3, data);
                return telephony.iccTransmitApduLogicalChannelByPort(slotIndex,
                        getFirstActivePortIndex(slotIndex), channel, cla, instruction,
                        p1, p2, p3, data);
            }
        } catch (RemoteException ex) {
        } catch (NullPointerException ex) {
@@ -7305,7 +7330,8 @@ public class TelephonyManager {
     * @return The APDU response from the ICC card with the status appended at
     *            the end.
     * @hide
     * @deprecated instead use
     * @deprecated This API is not compatible on eUICC supporting Multiple Enabled Profile(MEP),
     * instead use
     * {@link #iccTransmitApduBasicChannelByPort(int, int, int, int, int, int, int, String)}
     */
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
@@ -7318,8 +7344,9 @@ public class TelephonyManager {
        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                return telephony.iccTransmitApduBasicChannelByPort(slotIndex, DEFAULT_PORT_INDEX,
                         getOpPackageName(), cla, instruction, p1, p2, p3, data);
                return telephony.iccTransmitApduBasicChannelByPort(slotIndex,
                        getFirstActivePortIndex(slotIndex), getOpPackageName(),
                        cla, instruction, p1, p2, p3, data);
            }
        } catch (RemoteException ex) {
        } catch (NullPointerException ex) {