use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class UiccCarrierPrivilegeRules method parseRefArdo.
/*
* Parses a single rule.
*/
private static UiccAccessRule parseRefArdo(String rule) {
log("Got rule: " + rule);
String certificateHash = null;
String packageName = null;
String tmp = null;
long accessType = 0;
while (!rule.isEmpty()) {
if (rule.startsWith(TAG_REF_DO)) {
// E1
TLV refDo = new TLV(TAG_REF_DO);
rule = refDo.parse(rule, false);
// Allow 4F tag with a default value "FF FF FF FF FF FF" to be compatible with
// devices having GP access control enforcer:
// - If no 4F tag is present, it's a CP rule.
// - If 4F tag has value "FF FF FF FF FF FF", it's a CP rule.
// - If 4F tag has other values, it's not a CP rule and Android should ignore it.
// C1
TLV deviceDo = new TLV(TAG_DEVICE_APP_ID_REF_DO);
if (refDo.value.startsWith(TAG_AID_REF_DO)) {
// 4F
TLV cpDo = new TLV(TAG_AID_REF_DO);
String remain = cpDo.parse(refDo.value, false);
if (!cpDo.lengthBytes.equals("06") || !cpDo.value.equals(CARRIER_PRIVILEGE_AID) || remain.isEmpty() || !remain.startsWith(TAG_DEVICE_APP_ID_REF_DO)) {
return null;
}
tmp = deviceDo.parse(remain, false);
certificateHash = deviceDo.value;
} else if (refDo.value.startsWith(TAG_DEVICE_APP_ID_REF_DO)) {
tmp = deviceDo.parse(refDo.value, false);
certificateHash = deviceDo.value;
} else {
return null;
}
if (!tmp.isEmpty()) {
if (!tmp.startsWith(TAG_PKG_REF_DO)) {
return null;
}
// CA
TLV pkgDo = new TLV(TAG_PKG_REF_DO);
pkgDo.parse(tmp, true);
packageName = new String(IccUtils.hexStringToBytes(pkgDo.value));
} else {
packageName = null;
}
} else if (rule.startsWith(TAG_AR_DO)) {
// E3
TLV arDo = new TLV(TAG_AR_DO);
rule = arDo.parse(rule, false);
// Skip all the irrelevant tags (All the optional tags here are two bytes
// according to the spec GlobalPlatform Secure Element Access Control).
String remain = arDo.value;
while (!remain.isEmpty() && !remain.startsWith(TAG_PERM_AR_DO)) {
TLV tmpDo = new TLV(remain.substring(0, 2));
remain = tmpDo.parse(remain, false);
}
if (remain.isEmpty()) {
return null;
}
// DB
TLV permDo = new TLV(TAG_PERM_AR_DO);
permDo.parse(remain, true);
} else {
// Spec requires it must be either TAG_REF_DO or TAG_AR_DO.
throw new RuntimeException("Invalid Rule type");
}
}
UiccAccessRule accessRule = new UiccAccessRule(IccUtils.hexStringToBytes(certificateHash), packageName, accessType);
return accessRule;
}
use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionInfoUpdater method updateSubscriptionByCarrierConfig.
/**
* Update the currently active Subscription based on information from CarrierConfig
*/
@VisibleForTesting
public void updateSubscriptionByCarrierConfig(int phoneId, String configPackageName, PersistableBundle config) {
if (!SubscriptionManager.isValidPhoneId(phoneId) || TextUtils.isEmpty(configPackageName) || config == null) {
if (DBG) {
logd("In updateSubscriptionByCarrierConfig(): phoneId=" + phoneId + " configPackageName=" + configPackageName + " config=" + ((config == null) ? "null" : config.hashCode()));
}
return;
}
SubscriptionController sc = SubscriptionController.getInstance();
if (sc == null) {
loge("SubscriptionController was null");
return;
}
int currentSubId = sc.getSubIdUsingPhoneId(phoneId);
if (!SubscriptionManager.isValidSubscriptionId(currentSubId) || currentSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
if (DBG)
logd("No subscription is active for phone being updated");
return;
}
SubscriptionInfo currentSubInfo = sc.getSubscriptionInfo(currentSubId);
if (currentSubInfo == null) {
loge("Couldn't retrieve subscription info for current subscription");
return;
}
ContentValues cv = new ContentValues();
ParcelUuid groupUuid = null;
// carrier certificates are not subscription-specific, so we want to load them even if
// this current package is not a CarrierServicePackage
String[] certs = config.getStringArray(CarrierConfigManager.KEY_CARRIER_CERTIFICATE_STRING_ARRAY);
UiccAccessRule[] carrierConfigAccessRules = null;
if (certs != null) {
carrierConfigAccessRules = new UiccAccessRule[certs.length];
for (int i = 0; i < certs.length; i++) {
carrierConfigAccessRules[i] = new UiccAccessRule(IccUtils.hexStringToBytes(certs[i]), null, 0);
}
}
cv.put(SubscriptionManager.ACCESS_RULES_FROM_CARRIER_CONFIGS, UiccAccessRule.encodeRules(carrierConfigAccessRules));
if (!isCarrierServicePackage(phoneId, configPackageName)) {
loge("Cannot manage subId=" + currentSubId + ", carrierPackage=" + configPackageName);
} else {
boolean isOpportunistic = config.getBoolean(CarrierConfigManager.KEY_IS_OPPORTUNISTIC_SUBSCRIPTION_BOOL, false);
if (currentSubInfo.isOpportunistic() != isOpportunistic) {
if (DBG)
logd("Set SubId=" + currentSubId + " isOpportunistic=" + isOpportunistic);
cv.put(SubscriptionManager.IS_OPPORTUNISTIC, isOpportunistic ? "1" : "0");
}
String groupUuidString = config.getString(CarrierConfigManager.KEY_SUBSCRIPTION_GROUP_UUID_STRING, "");
if (!TextUtils.isEmpty(groupUuidString)) {
try {
// Update via a UUID Structure to ensure consistent formatting
groupUuid = ParcelUuid.fromString(groupUuidString);
if (groupUuid.equals(REMOVE_GROUP_UUID) && currentSubInfo.getGroupUuid() != null) {
cv.put(SubscriptionManager.GROUP_UUID, (String) null);
if (DBG)
logd("Group Removed for" + currentSubId);
} else if (SubscriptionController.getInstance().canPackageManageGroup(groupUuid, configPackageName)) {
cv.put(SubscriptionManager.GROUP_UUID, groupUuid.toString());
cv.put(SubscriptionManager.GROUP_OWNER, configPackageName);
if (DBG)
logd("Group Added for" + currentSubId);
} else {
loge("configPackageName " + configPackageName + " doesn't own grouUuid " + groupUuid);
}
} catch (IllegalArgumentException e) {
loge("Invalid Group UUID=" + groupUuidString);
}
}
}
if (cv.size() > 0 && sContext.getContentResolver().update(SubscriptionManager.getUriForSubscriptionId(currentSubId), cv, null, null) > 0) {
sc.refreshCachedActiveSubscriptionInfoList();
sc.notifySubscriptionInfoChanged();
MultiSimSettingController.getInstance().notifySubscriptionGroupChanged(groupUuid);
}
}
use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionController method getSubInfoRecord.
/**
* New SubInfoRecord instance and fill in detail info
* @param cursor
* @return the query result of desired SubInfoRecord
*/
@UnsupportedAppUsage
private SubscriptionInfo getSubInfoRecord(Cursor cursor) {
int id = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID));
String iccId = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.ICC_ID));
int simSlotIndex = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.SIM_SLOT_INDEX));
String displayName = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.DISPLAY_NAME));
String carrierName = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.CARRIER_NAME));
int nameSource = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.NAME_SOURCE));
int iconTint = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.HUE));
String number = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.NUMBER));
int dataRoaming = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.DATA_ROAMING));
// Get the blank bitmap for this SubInfoRecord
Bitmap iconBitmap = BitmapFactory.decodeResource(mContext.getResources(), com.android.internal.R.drawable.ic_sim_card_multi_24px_clr);
String mcc = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.MCC_STRING));
String mnc = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.MNC_STRING));
String ehplmnsRaw = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.EHPLMNS));
String hplmnsRaw = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.HPLMNS));
String[] ehplmns = ehplmnsRaw == null ? null : ehplmnsRaw.split(",");
String[] hplmns = hplmnsRaw == null ? null : hplmnsRaw.split(",");
// cardId is the private ICCID/EID string, also known as the card string
String cardId = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.CARD_ID));
String countryIso = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.ISO_COUNTRY_CODE));
// publicCardId is the publicly exposed int card ID
int publicCardId = mUiccController.convertToPublicCardId(cardId);
boolean isEmbedded = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.IS_EMBEDDED)) == 1;
int carrierId = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.CARRIER_ID));
UiccAccessRule[] accessRules;
if (isEmbedded) {
accessRules = UiccAccessRule.decodeRules(cursor.getBlob(cursor.getColumnIndexOrThrow(SubscriptionManager.ACCESS_RULES)));
} else {
accessRules = null;
}
UiccAccessRule[] carrierConfigAccessRules = UiccAccessRule.decodeRules(cursor.getBlob(cursor.getColumnIndexOrThrow(SubscriptionManager.ACCESS_RULES_FROM_CARRIER_CONFIGS)));
boolean isOpportunistic = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.IS_OPPORTUNISTIC)) == 1;
String groupUUID = cursor.getString(cursor.getColumnIndexOrThrow(SubscriptionManager.GROUP_UUID));
int profileClass = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.PROFILE_CLASS));
int subType = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.SUBSCRIPTION_TYPE));
String groupOwner = getOptionalStringFromCursor(cursor, SubscriptionManager.GROUP_OWNER, /*defaultVal*/
null);
boolean areUiccApplicationsEnabled = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.UICC_APPLICATIONS_ENABLED)) == 1;
if (VDBG) {
String iccIdToPrint = SubscriptionInfo.givePrintableIccid(iccId);
String cardIdToPrint = SubscriptionInfo.givePrintableIccid(cardId);
logd("[getSubInfoRecord] id:" + id + " iccid:" + iccIdToPrint + " simSlotIndex:" + simSlotIndex + " carrierid:" + carrierId + " displayName:" + displayName + " nameSource:" + nameSource + " iconTint:" + iconTint + " dataRoaming:" + dataRoaming + " mcc:" + mcc + " mnc:" + mnc + " countIso:" + countryIso + " isEmbedded:" + isEmbedded + " accessRules:" + Arrays.toString(accessRules) + " carrierConfigAccessRules: " + Arrays.toString(carrierConfigAccessRules) + " cardId:" + cardIdToPrint + " publicCardId:" + publicCardId + " isOpportunistic:" + isOpportunistic + " groupUUID:" + groupUUID + " profileClass:" + profileClass + " subscriptionType: " + subType + " carrierConfigAccessRules:" + carrierConfigAccessRules + " areUiccApplicationsEnabled: " + areUiccApplicationsEnabled);
}
// If line1number has been set to a different number, use it instead.
String line1Number = mTelephonyManager.getLine1Number(id);
if (!TextUtils.isEmpty(line1Number) && !line1Number.equals(number)) {
number = line1Number;
}
SubscriptionInfo info = new SubscriptionInfo(id, iccId, simSlotIndex, displayName, carrierName, nameSource, iconTint, number, dataRoaming, iconBitmap, mcc, mnc, countryIso, isEmbedded, accessRules, cardId, publicCardId, isOpportunistic, groupUUID, false, /* isGroupDisabled */
carrierId, profileClass, subType, groupOwner, carrierConfigAccessRules, areUiccApplicationsEnabled);
info.setAssociatedPlmns(ehplmns, hplmns);
return info;
}
use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class EuiccControllerTest method setHasCarrierPrivilegesOnActiveSubscription.
private void setHasCarrierPrivilegesOnActiveSubscription(boolean hasPrivileges) throws Exception {
SubscriptionInfo subInfo = new SubscriptionInfo(0, "", 0, "", "", 0, 0, "", 0, null, "", "", "", true, /* isEmbedded */
hasPrivileges ? new UiccAccessRule[] { ACCESS_RULE } : null, "", CARD_ID, false, null, false, 0, 0, 0, null, null, true);
when(mSubscriptionManager.canManageSubscription(subInfo, PACKAGE_NAME)).thenReturn(hasPrivileges);
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(Collections.singletonList(subInfo));
}
use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class EuiccControllerTest method setCanManageSubscriptionOnTargetSim.
private void setCanManageSubscriptionOnTargetSim(boolean isTargetEuicc, boolean hasPrivileges) throws Exception {
UiccCardInfo cardInfo1 = new UiccCardInfo(isTargetEuicc, CARD_ID, "", "", 0, false);
UiccCardInfo cardInfo2 = new UiccCardInfo(true, /* isEuicc */
1, /* cardId */
"", "", 0, false);
ArrayList<UiccCardInfo> cardInfos = new ArrayList<>();
cardInfos.add(cardInfo1);
cardInfos.add(cardInfo2);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(cardInfos);
SubscriptionInfo subInfo1 = new SubscriptionInfo(0, "", 0, "", "", 0, 0, "", 0, null, "", "", "", true, /* isEmbedded */
hasPrivileges ? new UiccAccessRule[] { ACCESS_RULE } : null, "", CARD_ID, false, null, false, 0, 0, 0, null, null, true);
SubscriptionInfo subInfo2 = new SubscriptionInfo(0, "", 0, "", "", 0, 0, "", 0, null, "", "", "", true, /* isEmbedded */
hasPrivileges ? new UiccAccessRule[] { ACCESS_RULE } : null, "", 1, /* cardId */
false, null, false, 0, 0, 0, null, null, true);
when(mSubscriptionManager.canManageSubscription(subInfo1, PACKAGE_NAME)).thenReturn(hasPrivileges);
when(mSubscriptionManager.canManageSubscription(subInfo2, PACKAGE_NAME)).thenReturn(hasPrivileges);
ArrayList<SubscriptionInfo> subInfos = new ArrayList<>(Arrays.asList(subInfo1, subInfo2));
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(subInfos);
}
Aggregations