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

Commit f0d99e7d authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Add a retry mechanism to retrieve access rules again depending on the...

Merge "Add a retry mechanism to retrieve access rules again depending on the status words" into qt-qpr1-dev am: 9a4d18df am: edf9ca7c

Change-Id: Ica449da18b50f2394d0de2c2a42215156bfd9c8e
parents 20ac9df7 edf9ca7c
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -114,6 +114,8 @@ public class UiccCarrierPrivilegeRules extends Handler {
    // Max number of retries for open logical channel, interval is 10s.
    private static final int MAX_RETRY = 1;
    private static final int RETRY_INTERVAL_MS = 10000;
    private static final int STATUS_CODE_CONDITION_NOT_SATISFIED = 0x6985;
    private static final int STATUS_CODE_APPLET_SELECT_FAILED = 0x6999;

    // Used for parsing the data from the UICC.
    public static class TLV {
@@ -426,6 +428,30 @@ public class UiccCarrierPrivilegeRules extends Handler {
        return null;
    }

    /**
     * The following three situations could be due to logical channels temporarily unavailable, so
     * we retry up to MAX_RETRY times, with an interval of RETRY_INTERVAL_MS: 1. MISSING_RESOURCE,
     * 2. NO_SUCH_ELEMENT and the status code is 6985, 3. INTERNAL_ERR and the status code is 6999.
     */
    public static boolean shouldRetry(AsyncResult ar, int retryCount) {
        if (ar.exception instanceof CommandException && retryCount < MAX_RETRY) {
            CommandException.Error error = ((CommandException) (ar.exception)).getCommandError();
            int[] results = (int[]) ar.result;
            int statusCode = 0;
            if (results.length == 3) {
                byte[] bytes = new byte[]{(byte) results[1], (byte) results[2]};
                statusCode = Integer.parseInt(IccUtils.bytesToHexString(bytes), 16);
                log("status code: " + String.valueOf(statusCode));
            }
            return (error == CommandException.Error.MISSING_RESOURCE)
                            || (error == CommandException.Error.NO_SUCH_ELEMENT
                    && statusCode == STATUS_CODE_CONDITION_NOT_SATISFIED)
                            || (error == CommandException.Error.INTERNAL_ERR
                    && statusCode == STATUS_CODE_APPLET_SELECT_FAILED);
        }
        return false;
    }

    @Override
    public void handleMessage(Message msg) {
        AsyncResult ar;
@@ -442,11 +468,8 @@ public class UiccCarrierPrivilegeRules extends Handler {
                            DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId,
                                    mAIDInUse));
                } else {
                    // MISSING_RESOURCE could be due to logical channels temporarily unavailable,
                    // so we retry up to MAX_RETRY times, with an interval of RETRY_INTERVAL_MS.
                    if (ar.exception instanceof CommandException && mRetryCount < MAX_RETRY
                            && ((CommandException) (ar.exception)).getCommandError()
                            == CommandException.Error.MISSING_RESOURCE) {
                    if (shouldRetry(ar, mRetryCount)) {
                        log("should retry");
                        mRetryCount++;
                        removeCallbacks(mRetryRunnable);
                        postDelayed(mRetryRunnable, RETRY_INTERVAL_MS);
+33 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.TelephonyTest;

import org.junit.After;
@@ -256,6 +257,38 @@ public class UiccCarrierPrivilegeRulesTest extends TelephonyTest {
        assertEquals(0, mUiccCarrierPrivilegeRules.getPackageNames().size());
    }

    @Test
    @SmallTest
    public void testRetryARAM_shouldRetry() {
        AsyncResult ar1 = new AsyncResult(
                null,
                new int[]{0, 105, -123},
                new CommandException(CommandException.Error.NO_SUCH_ELEMENT));
        assertTrue(mUiccCarrierPrivilegeRules.shouldRetry(ar1, 0));

        AsyncResult ar2 = new AsyncResult(
                null,
                new int[]{0},
                new CommandException(CommandException.Error.MISSING_RESOURCE));
        assertTrue(mUiccCarrierPrivilegeRules.shouldRetry(ar2, 0));

        AsyncResult ar3 = new AsyncResult(
                null,
                new int[]{0, 105, 153},
                new CommandException(CommandException.Error.INTERNAL_ERR));
        assertTrue(mUiccCarrierPrivilegeRules.shouldRetry(ar3, 0));
    }

    @Test
    @SmallTest
    public void testRetryARAM_shouldNotRetry() {
        AsyncResult ar = new AsyncResult(
                null,
                new int[]{0, 106, -126},
                new CommandException(CommandException.Error.NO_SUCH_ELEMENT));
        assertTrue(!mUiccCarrierPrivilegeRules.shouldRetry(ar, 0));
    }

    private static final String ARAM = "A00000015141434C00";
    private static final String ARAD = "A00000015144414300";
    private static final String PKCS15_AID = "A000000063504B43532D3135";