use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class EuiccController method checkCarrierPrivilegeInMetadata.
// Returns whether the caller has carrier privilege on the given subscription.
private boolean checkCarrierPrivilegeInMetadata(DownloadableSubscription subscription, String callingPackage) {
UiccAccessRule[] rules = null;
List<UiccAccessRule> rulesList = subscription.getAccessRules();
if (rulesList != null) {
rules = rulesList.toArray(new UiccAccessRule[rulesList.size()]);
}
if (rules == null) {
Log.e(TAG, "No access rules but caller is unprivileged");
return false;
}
final PackageInfo info;
try {
info = mPackageManager.getPackageInfo(callingPackage, PackageManager.GET_SIGNING_CERTIFICATES);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Calling package valid but gone");
return false;
}
for (int i = 0; i < rules.length; i++) {
if (rules[i].getCarrierPrivilegeStatus(info) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Log.i(TAG, "Calling package has carrier privilege to this profile");
return true;
}
}
Log.e(TAG, "Calling package doesn't have carrier privilege to this profile");
return false;
}
use of android.telephony.UiccAccessRule 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;
}
use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionInfoUpdaterTest method testUpdateFromCarrierConfigCarrierCertificates.
@Test
@SmallTest
public void testUpdateFromCarrierConfigCarrierCertificates() {
String[] certs = new String[2];
certs[0] = "d1f1";
certs[1] = "b5d6";
UiccAccessRule[] carrierConfigAccessRules = new UiccAccessRule[certs.length];
for (int i = 0; i < certs.length; i++) {
carrierConfigAccessRules[i] = new UiccAccessRule(IccUtils.hexStringToBytes(certs[i]), null, 0);
}
final int phoneId = mPhone.getPhoneId();
PersistableBundle carrierConfig = new PersistableBundle();
carrierConfig.putStringArray(CarrierConfigManager.KEY_CARRIER_CERTIFICATE_STRING_ARRAY, certs);
String carrierPackageName = "FakeCarrierPackageName";
doReturn(FAKE_SUB_ID_1).when(mSubscriptionController).getSubIdUsingPhoneId(phoneId);
doReturn(mSubInfo).when(mSubscriptionController).getSubscriptionInfo(eq(FAKE_SUB_ID_1));
doReturn(false).when(mSubInfo).isOpportunistic();
doReturn(Collections.singletonList(carrierPackageName)).when(mTelephonyManager).getCarrierPackageNamesForIntentAndPhone(any(), eq(phoneId));
((MockContentResolver) mContext.getContentResolver()).addProvider(SubscriptionManager.CONTENT_URI.getAuthority(), new FakeSubscriptionContentProvider());
mUpdater.updateSubscriptionByCarrierConfig(mPhone.getPhoneId(), carrierPackageName, carrierConfig);
ArgumentCaptor<ContentValues> cvCaptor = ArgumentCaptor.forClass(ContentValues.class);
verify(mContentProvider, times(1)).update(eq(SubscriptionManager.getUriForSubscriptionId(FAKE_SUB_ID_1)), cvCaptor.capture(), eq(null), eq(null));
assertEquals(carrierConfigAccessRules, UiccAccessRule.decodeRules(cvCaptor.getValue().getAsByteArray(SubscriptionManager.ACCESS_RULES_FROM_CARRIER_CONFIGS)));
assertEquals(1, cvCaptor.getValue().size());
verify(mSubscriptionController, times(1)).refreshCachedActiveSubscriptionInfoList();
verify(mSubscriptionController, times(1)).notifySubscriptionInfoChanged();
}
use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class UiccProfile method getUninstalledCarrierPackages.
private Set<String> getUninstalledCarrierPackages() {
String whitelistSetting = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.CARRIER_APP_WHITELIST);
if (TextUtils.isEmpty(whitelistSetting)) {
return Collections.emptySet();
}
Map<String, String> certPackageMap = parseToCertificateToPackageMap(whitelistSetting);
if (certPackageMap.isEmpty()) {
return Collections.emptySet();
}
if (mCarrierPrivilegeRules == null) {
return Collections.emptySet();
}
Set<String> uninstalledCarrierPackages = new ArraySet<>();
List<UiccAccessRule> accessRules = mCarrierPrivilegeRules.getAccessRules();
for (UiccAccessRule accessRule : accessRules) {
String certHexString = accessRule.getCertificateHexString().toUpperCase();
String pkgName = certPackageMap.get(certHexString);
if (!TextUtils.isEmpty(pkgName) && !isPackageBundled(mContext, pkgName)) {
uninstalledCarrierPackages.add(pkgName);
}
}
return uninstalledCarrierPackages;
}
use of android.telephony.UiccAccessRule in project android_frameworks_opt_telephony by LineageOS.
the class UiccCarrierPrivilegeRules method parseRules.
/*
* Parses the rules from the input string.
*/
private static List<UiccAccessRule> parseRules(String rules) {
log("Got rules: " + rules);
// FF40
TLV allRefArDo = new TLV(TAG_ALL_REF_AR_DO);
allRefArDo.parse(rules, true);
String arDos = allRefArDo.value;
List<UiccAccessRule> accessRules = new ArrayList<>();
while (!arDos.isEmpty()) {
// E2
TLV refArDo = new TLV(TAG_REF_AR_DO);
arDos = refArDo.parse(arDos, false);
UiccAccessRule accessRule = parseRefArdo(refArDo.value);
if (accessRule != null) {
accessRules.add(accessRule);
} else {
Rlog.e(LOG_TAG, "Skip unrecognized rule." + refArDo.value);
}
}
return accessRules;
}
Aggregations