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

Commit ec633b97 authored by Jordan Liu's avatar Jordan Liu Committed by android-build-merger
Browse files

Merge "Wait for the on-going APDU command procedure for eSIM"

am: 3b1c2701

Change-Id: I02b38fdc3152c4b72176e3614644345662a722e9
parents 2334a20b 3b1c2701
Loading
Loading
Loading
Loading
+28 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.telephony.uicc.euicc.apdu;

import android.annotation.Nullable;
import android.os.Handler;
import android.os.Looper;
import android.telephony.IccOpenLogicalChannelResponse;
import android.telephony.Rlog;

@@ -50,10 +51,16 @@ public class ApduSender {
    private static final int STATUS_NO_ERROR = 0x9000;
    private static final int SW1_NO_ERROR = 0x91;

    private static final int WAIT_TIME_MS = 2000;

    private static void logv(String msg) {
        Rlog.v(LOG_TAG, msg);
    }

    private static void logd(String msg) {
        Rlog.d(LOG_TAG, msg);
    }

    private final String mAid;
    private final boolean mSupportExtendedApdu;
    private final OpenLogicalChannelInvocation mOpenChannel;
@@ -93,12 +100,27 @@ public class ApduSender {
            ApduSenderResultCallback resultCallback,
            Handler handler) {
        synchronized (mChannelLock) {
            if (mChannelOpened) {
                if (!Looper.getMainLooper().equals(Looper.myLooper())) {
                    logd("Logical channel has already been opened. Wait.");
                    try {
                        mChannelLock.wait(WAIT_TIME_MS);
                    } catch (InterruptedException e) {
                        // nothing to do
                    }
                    if (mChannelOpened) {
                        AsyncResultHelper.throwException(
                        new ApduException("Logical channel has already been opened."),
                                new ApduException("The logical channel is still in use."),
                                resultCallback, handler);
                        return;
                    }
                } else {
                    AsyncResultHelper.throwException(
                            new ApduException("The logical channel is in use."),
                            resultCallback, handler);
                    return;
                }
            }
            mChannelOpened = true;
        }

@@ -111,6 +133,7 @@ public class ApduSender {
                        || status != IccOpenLogicalChannelResponse.STATUS_NO_ERROR) {
                    synchronized (mChannelLock) {
                        mChannelOpened = false;
                        mChannelLock.notify();
                    }
                    resultCallback.onException(
                            new ApduException("Failed to open logical channel opened for AID: "
@@ -245,6 +268,7 @@ public class ApduSender {
            public void onResult(Boolean aBoolean) {
                synchronized (mChannelLock) {
                    mChannelOpened = false;
                    mChannelLock.notify();
                }

                if (exception == null) {