Search in sources :

Example 6 with UiccAccessRule

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;
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 7 with UiccAccessRule

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;
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) Nullable(android.annotation.Nullable)

Example 8 with UiccAccessRule

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();
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) ContentValues(android.content.ContentValues) PersistableBundle(android.os.PersistableBundle) Mockito.anyString(org.mockito.Mockito.anyString) MockContentResolver(android.test.mock.MockContentResolver) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with UiccAccessRule

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;
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) ArraySet(android.util.ArraySet)

Example 10 with UiccAccessRule

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;
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) ArrayList(java.util.ArrayList)

Aggregations

UiccAccessRule (android.telephony.UiccAccessRule)16 SubscriptionInfo (android.telephony.SubscriptionInfo)6 ArrayList (java.util.ArrayList)4 ContentValues (android.content.ContentValues)3 EuiccProfileInfo (android.service.euicc.EuiccProfileInfo)2 Test (org.junit.Test)2 Nullable (android.annotation.Nullable)1 UnsupportedAppUsage (android.compat.annotation.UnsupportedAppUsage)1 ContentResolver (android.content.ContentResolver)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Bitmap (android.graphics.Bitmap)1 AsyncResult (android.os.AsyncResult)1 ParcelUuid (android.os.ParcelUuid)1 PersistableBundle (android.os.PersistableBundle)1 CarrierIdentifier (android.service.carrier.CarrierIdentifier)1 UiccCardInfo (android.telephony.UiccCardInfo)1 MockContentResolver (android.test.mock.MockContentResolver)1 SmallTest (android.test.suitebuilder.annotation.SmallTest)1 ArraySet (android.util.ArraySet)1