use of com.android.internal.telephony.uicc.asn1.Asn1Decoder 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);
}
use of com.android.internal.telephony.uicc.asn1.Asn1Decoder in project android_frameworks_opt_telephony by LineageOS.
the class EuiccSpecVersion method fromOpenChannelResponse.
/**
* Parses the response of opening a logical channel to get spec version of the eUICC card.
*
* @return Parsed spec version. If any error is encountered, null will be returned.
*/
public static EuiccSpecVersion fromOpenChannelResponse(byte[] response) {
Asn1Node node;
try {
Asn1Decoder decoder = new Asn1Decoder(response);
if (!decoder.hasNextNode()) {
return null;
}
node = decoder.nextNode();
} catch (InvalidAsn1DataException e) {
Rlog.e(LOG_TAG, "Cannot parse the select response of ISD-R.", e);
return null;
}
try {
byte[] versionType;
if (node.getTag() == TAG_ISD_R_APP_TEMPLATE) {
versionType = node.getChild(TAG_VERSION).asBytes();
} else {
versionType = node.getChild(TAG_ISD_R_APP_TEMPLATE, TAG_VERSION).asBytes();
}
if (versionType.length == 3) {
return new EuiccSpecVersion(versionType);
} else {
Rlog.e(LOG_TAG, "Cannot parse select response of ISD-R: " + node.toHex());
}
} catch (InvalidAsn1DataException | TagNotFoundException e) {
Rlog.e(LOG_TAG, "Cannot parse select response of ISD-R: " + node.toHex());
}
return null;
}
use of com.android.internal.telephony.uicc.asn1.Asn1Decoder in project android_frameworks_opt_telephony by LineageOS.
the class EuiccCard method getAllProfiles.
/**
* Gets a list of user-visible profiles.
*
* @param callback The callback to get the result.
* @param handler The handler to run the callback.
* @since 1.1.0 [GSMA SGP.22]
*/
public void getAllProfiles(AsyncResultCallback<EuiccProfileInfo[]> callback, Handler handler) {
sendApdu(newRequestProvider((RequestBuilder requestBuilder) -> requestBuilder.addStoreData(Asn1Node.newBuilder(Tags.TAG_GET_PROFILES).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);
int size = profileNodes.size();
EuiccProfileInfo[] profiles = new EuiccProfileInfo[size];
int profileCount = 0;
for (int i = 0; i < size; i++) {
Asn1Node profileNode = profileNodes.get(i);
if (!profileNode.hasChild(Tags.TAG_ICCID)) {
loge("Profile must have an ICCID.");
continue;
}
String strippedIccIdString = stripTrailingFs(profileNode.getChild(Tags.TAG_ICCID).asBytes());
EuiccProfileInfo.Builder profileBuilder = new EuiccProfileInfo.Builder(strippedIccIdString);
buildProfile(profileNode, profileBuilder);
EuiccProfileInfo profile = profileBuilder.build();
profiles[profileCount++] = profile;
}
return profiles;
}, callback, handler);
}
use of com.android.internal.telephony.uicc.asn1.Asn1Decoder in project android_frameworks_opt_telephony by LineageOS.
the class Asn1DecoderTest method testEmptyData.
@SmallTest
@Test
public void testEmptyData() throws TagNotFoundException, InvalidAsn1DataException {
String hex = "e3025a00e3025a00";
Asn1Decoder decoder = new Asn1Decoder(hex);
assertEquals(0, decoder.getPosition());
assertTrue(decoder.hasNextNode());
Asn1Node firstRoot = decoder.nextNode();
assertEquals(hex.length() / 4, decoder.getPosition());
assertTrue(firstRoot.isConstructed());
assertEquals(0xE3, firstRoot.getTag());
Asn1Node childOfFirst = firstRoot.getChild(0x5A);
assertNotNull(childOfFirst);
assertFalse(childOfFirst.isConstructed());
assertEquals(0x5A, childOfFirst.getTag());
assertTrue(childOfFirst.hasValue());
assertArrayEquals(new byte[] {}, childOfFirst.asBytes());
assertTrue(decoder.hasNextNode());
Asn1Node secondRoot = decoder.nextNode();
assertEquals(hex.length() / 2, decoder.getPosition());
assertTrue(secondRoot.isConstructed());
assertEquals(0xE3, secondRoot.getTag());
Asn1Node childOfSecond = secondRoot.getChild(0x5A);
assertNotNull(childOfSecond);
assertFalse(childOfSecond.isConstructed());
assertEquals(0x5A, childOfSecond.getTag());
assertTrue(childOfSecond.hasValue());
assertArrayEquals(new byte[] {}, childOfSecond.asBytes());
assertFalse(decoder.hasNextNode());
assertEquals(hex.length() / 2, decoder.getPosition());
}
use of com.android.internal.telephony.uicc.asn1.Asn1Decoder in project android_frameworks_opt_telephony by LineageOS.
the class Asn1DecoderTest method testLongFormLength.
@SmallTest
@Test
public void testLongFormLength() throws TagNotFoundException, InvalidAsn1DataException {
String hex = "bf37075a820003010203";
Asn1Decoder decoder = new Asn1Decoder(hex);
assertTrue(decoder.hasNextNode());
Asn1Node root = decoder.nextNode();
assertTrue(root.isConstructed());
assertEquals(0xBF37, root.getTag());
assertEquals(10, root.getEncodedLength());
assertTrue(root.isConstructed());
Asn1Node node = root.getChild(0x5A);
assertEquals(5, node.getEncodedLength());
assertArrayEquals(new byte[] { 1, 2, 3 }, node.asBytes());
}
Aggregations