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

Commit 0be6d774 authored by yinxu's avatar yinxu Committed by android-build-merger
Browse files

Merge "Parse ATR in the UiccSlot" am: 8285290c am: 03931c62

am: 2dfec96c

Change-Id: Ie57b14224933684e7bf9294880afae09f39ed6c5
parents 16c54711 2dfec96c
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -14,13 +14,12 @@
 * limitations under the License.
 */

package com.android.internal.telephony;
package com.android.internal.telephony.uicc;

import android.annotation.Nullable;
import android.telephony.Rlog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.uicc.IccUtils;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -205,6 +204,11 @@ public class AnswerToReset {
    }

    private boolean parseAtrString(String atr) {
        if (atr == null) {
            loge("The input ATR string can not be null");
            return false;
        }

        if (atr.length() % 2 != 0) {
            loge("The length of input ATR string " + atr.length() + " is not even.");
            return false;
+15 −3
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class UiccSlot extends Handler {
    private boolean mIsEuicc;
    private String mIccId;
    private Integer mPhoneId = null;
    private AnswerToReset mAtr;

    private static final int EVENT_CARD_REMOVED = 13;
    private static final int EVENT_CARD_ADDED = 14;
@@ -151,9 +152,9 @@ public class UiccSlot extends Handler {
                mIccId = iss.iccid;
            } else if (!mActive && iss.slotState == IccSlotStatus.SlotState.SLOTSTATE_ACTIVE) {
                mActive = true;
                parseAtr(iss.atr);
                // todo - ignoring these fields for now; relying on sim state changed to update
                // these
                //      iss.atr;
                //      iss.cardState;
                //      iss.iccid;
                //      iss.logicalSlotIndex;
@@ -161,10 +162,21 @@ public class UiccSlot extends Handler {
        }
    }

    private void parseAtr(String atr) {
        // todo - parse atr and set mIsEuicc based on it
    private void checkIsEuiccSupported() {
        if (mAtr != null && mAtr.isEuiccSupported()) {
            mIsEuicc = true;
        } else {
            mIsEuicc = false;
        }
    }

    private void parseAtr(String atr) {
        mAtr = AnswerToReset.parseAtr(atr);
        if (mAtr == null) {
            return;
        }
        checkIsEuiccSupported();
    }

    public boolean isEuicc() {
        return mIsEuicc;
+9 −2
Original line number Diff line number Diff line
@@ -13,12 +13,12 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.telephony;
package com.android.internal.telephony.uicc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import android.test.suitebuilder.annotation.SmallTest;
@@ -31,6 +31,13 @@ import java.util.Arrays;

public class AnswerToResetTest {

    @Test
    @SmallTest
    public void tesAnswerToRestNullString() {
        AnswerToReset atr = AnswerToReset.parseAtr(null);
        assertNull(atr);
    }

    @Test
    @SmallTest
    public void tesAnswerToRestOddLength() {
+68 −0
Original line number Diff line number Diff line
@@ -124,4 +124,72 @@ public class UiccSlotTest extends TelephonyTest {
        // assert on updated values
        assertTrue(mUiccSlot.isActive());
    }

    @Test
    @SmallTest
    public void testUpdateSlotStatusEuiccIsSupported() {
        IccSlotStatus iss = new IccSlotStatus();
        iss.slotState = IccSlotStatus.SlotState.SLOTSTATE_INACTIVE;
        iss.cardState = IccCardStatus.CardState.CARDSTATE_PRESENT;
        iss.iccid = "fake-iccid";
        iss.atr = "3F979580BFFE8210428031A073BE211797";

        // initial state
        assertTrue(mUiccSlot.isActive());
        assertNull(mUiccSlot.getUiccCard());
        assertEquals(IccCardStatus.CardState.CARDSTATE_ABSENT, mUiccSlot.getCardState());
        assertNull(mUiccSlot.getIccId());

        // update slot to inactive
        mUiccSlot.update(null, iss);

        // assert on updated values
        assertFalse(mUiccSlot.isActive());
        assertNull(mUiccSlot.getUiccCard());
        assertEquals(IccCardStatus.CardState.CARDSTATE_PRESENT, mUiccSlot.getCardState());
        assertEquals(iss.iccid, mUiccSlot.getIccId());

        iss.slotState = IccSlotStatus.SlotState.SLOTSTATE_ACTIVE;

        // update slot to active
        mUiccSlot.update(mSimulatedCommands, iss);

        // assert on updated values
        assertTrue(mUiccSlot.isActive());
        assertTrue(mUiccSlot.isEuicc());
    }

    @Test
    @SmallTest
    public void testUpdateSlotStatusEuiccIsNotSupported() {
        IccSlotStatus iss = new IccSlotStatus();
        iss.slotState = IccSlotStatus.SlotState.SLOTSTATE_INACTIVE;
        iss.cardState = IccCardStatus.CardState.CARDSTATE_PRESENT;
        iss.iccid = "fake-iccid";
        iss.atr = "3F979580BFFE8110428031A073BE211797";

        // initial state
        assertTrue(mUiccSlot.isActive());
        assertNull(mUiccSlot.getUiccCard());
        assertEquals(IccCardStatus.CardState.CARDSTATE_ABSENT, mUiccSlot.getCardState());
        assertNull(mUiccSlot.getIccId());

        // update slot to inactive
        mUiccSlot.update(null, iss);

        // assert on updated values
        assertFalse(mUiccSlot.isActive());
        assertNull(mUiccSlot.getUiccCard());
        assertEquals(IccCardStatus.CardState.CARDSTATE_PRESENT, mUiccSlot.getCardState());
        assertEquals(iss.iccid, mUiccSlot.getIccId());

        iss.slotState = IccSlotStatus.SlotState.SLOTSTATE_ACTIVE;

        // update slot to active
        mUiccSlot.update(mSimulatedCommands, iss);

        // assert on updated values
        assertTrue(mUiccSlot.isActive());
        assertFalse(mUiccSlot.isEuicc());
    }
}