Search in sources :

Example 11 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node in project android_frameworks_opt_telephony by LineageOS.

the class Asn1NodeTest method testNonExitingChildren.

@SmallTest
@Test
public void testNonExitingChildren() throws TagNotFoundException, InvalidAsn1DataException {
    Asn1Node node = Asn1Node.newBuilder(0x3F34).addChild(Asn1Node.newBuilder(0x34)).addChild(Asn1Node.newBuilder(0x35).addChild(Asn1Node.newBuilder(0x36))).addChildAsInteger(0x11, 123).build();
    assertEquals(0, node.getChild(0x34).getChildren(0x37).size());
    assertEquals(0, node.getChildren(0x37).size());
    assertEquals(0, node.getChild(0x11).getChildren(0x37).size());
    assertEquals(0, node.getChild(0x11).getChildren().size());
    try {
        node.getChild(0x35).getChild(0x37);
        fail("0x37 should not exist.");
    } catch (TagNotFoundException e) {
        assertEquals(0x37, e.getTag());
    }
    try {
        node.getChild(0x35, 0x37);
        fail("0x37 should not exist.");
    } catch (TagNotFoundException e) {
        assertEquals(0x37, e.getTag());
    }
    try {
        node.getChild(0x11).getChild(0x37);
        fail("0x37 should not exist.");
    } catch (TagNotFoundException e) {
        assertEquals(0x37, e.getTag());
    }
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) TagNotFoundException(com.android.internal.telephony.uicc.asn1.TagNotFoundException) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node in project android_frameworks_opt_telephony by LineageOS.

the class Asn1NodeTest method testLongFormLength.

@SmallTest
@Test
public void testLongFormLength() throws TagNotFoundException, InvalidAsn1DataException {
    Asn1Node node = Asn1Node.newBuilder(0xBF37).addChildAsBytes(0x5A, new byte[257]).build();
    assertEquals(266, node.getEncodedLength());
    assertEquals(261, node.getDataLength());
    assertEquals(257, node.getChild(0x5A).getDataLength());
    assertEquals("BF37820105", node.getHeadAsHex());
    byte[] expected = new byte[266];
    System.arraycopy(IccUtils.hexStringToBytes("BF378201055A820101"), 0, expected, 0, 9);
    byte[] actual = new byte[266];
    node.writeToBytes(actual, 0);
    assertArrayEquals(expected, actual);
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 13 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node in project android_frameworks_opt_telephony by LineageOS.

the class Asn1NodeTest method testChildren.

@SmallTest
@Test
public void testChildren() throws TagNotFoundException, InvalidAsn1DataException {
    Asn1Node node = Asn1Node.newBuilder(0x3F34).addChild(Asn1Node.newBuilder(0x35).addChild(Asn1Node.newBuilder(0x36))).addChild(Asn1Node.newBuilder(0x35)).addChild(Asn1Node.newBuilder(0x37)).build();
    assertEquals(0x3F34, node.getTag());
    assertEquals(3, node.getChildren().size());
    assertEquals(0x35, node.getChildren().get(0).getTag());
    assertEquals(0x35, node.getChildren().get(1).getTag());
    assertEquals(0x37, node.getChildren().get(2).getTag());
    assertEquals(2, node.getChildren(0x35).size());
    assertEquals(0x35, node.getChildren(0x35).get(0).getTag());
    assertEquals(0x35, node.getChildren(0x35).get(1).getTag());
    assertEquals(1, node.getChild(0x35).getChildren().size());
    assertEquals(0, node.getChildren().get(1).getChildren().size());
    assertEquals(0x36, node.getChild(0x35).getChildren().get(0).getTag());
    assertTrue(node.hasChild(0x35, 0x36));
    assertFalse(node.hasChild(0x38, 0x39));
    assertTrue(node.getChild(0x35).hasChild(0x36));
    assertFalse(node.getChild(0x35).hasChild(0x39));
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 14 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node in project android_frameworks_opt_telephony by LineageOS.

the class EuiccCard method buildUiccAccessRule.

@Nullable
private static UiccAccessRule[] buildUiccAccessRule(List<Asn1Node> nodes) throws InvalidAsn1DataException, TagNotFoundException {
    if (nodes.isEmpty()) {
        return null;
    }
    int count = nodes.size();
    UiccAccessRule[] rules = new UiccAccessRule[count];
    for (int i = 0; i < count; i++) {
        Asn1Node node = nodes.get(i);
        Asn1Node refDoNode = node.getChild(Tags.TAG_REF_DO);
        byte[] signature = refDoNode.getChild(Tags.TAG_DEVICE_APP_ID_REF_DO).asBytes();
        String packageName = null;
        if (refDoNode.hasChild(Tags.TAG_PKG_REF_DO)) {
            packageName = refDoNode.getChild(Tags.TAG_PKG_REF_DO).asString();
        }
        long accessType = 0;
        if (node.hasChild(Tags.TAG_AR_DO, Tags.TAG_PERM_AR_DO)) {
            Asn1Node permArDoNode = node.getChild(Tags.TAG_AR_DO, Tags.TAG_PERM_AR_DO);
            accessType = permArDoNode.asRawLong();
        }
        rules[i] = new UiccAccessRule(signature, packageName, accessType);
    }
    return rules;
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) Nullable(android.annotation.Nullable)

Example 15 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node in project android_frameworks_opt_telephony by LineageOS.

the class EuiccCard method getProfile.

/**
 * Gets a profile.
 *
 * @param callback The callback to get the result.
 * @param handler The handler to run the callback.
 * @since 1.1.0 [GSMA SGP.22]
 */
public final void getProfile(String iccid, AsyncResultCallback<EuiccProfileInfo> callback, Handler handler) {
    sendApdu(newRequestProvider((RequestBuilder requestBuilder) -> requestBuilder.addStoreData(Asn1Node.newBuilder(Tags.TAG_GET_PROFILES).addChild(Asn1Node.newBuilder(Tags.TAG_CTX_COMP_0).addChildAsBytes(Tags.TAG_ICCID, IccUtils.bcdToBytes(padTrailingFs(iccid))).build()).addChildAsBytes(Tags.TAG_TAG_LIST, Tags.EUICC_PROFILE_TAGS).build().toHex())), response -> {
        List<Asn1Node> profileNodes = new Asn1Decoder(response).nextNode().getChild(Tags.TAG_CTX_COMP_0).getChildren(Tags.TAG_PROFILE_INFO);
        if (profileNodes.isEmpty()) {
            return null;
        }
        Asn1Node profileNode = profileNodes.get(0);
        String strippedIccIdString = stripTrailingFs(profileNode.getChild(Tags.TAG_ICCID).asBytes());
        EuiccProfileInfo.Builder profileBuilder = new EuiccProfileInfo.Builder(strippedIccIdString);
        buildProfile(profileNode, profileBuilder);
        return profileBuilder.build();
    }, callback, handler);
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) RequestBuilder(com.android.internal.telephony.uicc.euicc.apdu.RequestBuilder) EuiccProfileInfo(android.service.euicc.EuiccProfileInfo) Asn1Decoder(com.android.internal.telephony.uicc.asn1.Asn1Decoder) RequestBuilder(com.android.internal.telephony.uicc.euicc.apdu.RequestBuilder)

Aggregations

Asn1Node (com.android.internal.telephony.uicc.asn1.Asn1Node)31 Test (org.junit.Test)23 SmallTest (android.test.suitebuilder.annotation.SmallTest)22 Asn1Decoder (com.android.internal.telephony.uicc.asn1.Asn1Decoder)10 RequestBuilder (com.android.internal.telephony.uicc.euicc.apdu.RequestBuilder)6 InvalidAsn1DataException (com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException)3 EuiccProfileInfo (android.service.euicc.EuiccProfileInfo)2 EuiccNotification (android.telephony.euicc.EuiccNotification)2 TagNotFoundException (com.android.internal.telephony.uicc.asn1.TagNotFoundException)2 Nullable (android.annotation.Nullable)1 CarrierIdentifier (android.service.carrier.CarrierIdentifier)1 UiccAccessRule (android.telephony.UiccAccessRule)1 EuiccRulesAuthTable (android.telephony.euicc.EuiccRulesAuthTable)1 TelephonyTest (com.android.internal.telephony.TelephonyTest)1