Merge changes from topic "carrier_certs_cherrypick"

* changes:
  Fix crashes seen when checking for carrierConfig certificates
  add checking for carrierConfigs certificates for psim
This commit is contained in:
Xiangyu/Malcolm Chen
2019-11-12 23:31:47 +00:00
committed by Gerrit Code Review
2 changed files with 9 additions and 21 deletions

View File

@@ -551,7 +551,6 @@ public class SubscriptionInfo implements Parcelable {
* *
* @param context Context of the application to check. * @param context Context of the application to check.
* @return whether the app is authorized to manage this subscription per its metadata. * @return whether the app is authorized to manage this subscription per its metadata.
* @throws UnsupportedOperationException if this subscription is not embedded.
* @hide * @hide
* @deprecated - Do not use. * @deprecated - Do not use.
*/ */
@@ -567,15 +566,11 @@ public class SubscriptionInfo implements Parcelable {
* @param context Any context. * @param context Any context.
* @param packageName Package name of the app to check. * @param packageName Package name of the app to check.
* @return whether the app is authorized to manage this subscription per its metadata. * @return whether the app is authorized to manage this subscription per its metadata.
* @throws UnsupportedOperationException if this subscription is not embedded.
* @hide * @hide
* @deprecated - Do not use. * @deprecated - Do not use.
*/ */
@Deprecated @Deprecated
public boolean canManageSubscription(Context context, String packageName) { public boolean canManageSubscription(Context context, String packageName) {
if (!isEmbedded()) {
throw new UnsupportedOperationException("Not an embedded subscription");
}
List<UiccAccessRule> allAccessRules = getAllAccessRules(); List<UiccAccessRule> allAccessRules = getAllAccessRules();
if (allAccessRules == null) { if (allAccessRules == null) {
return false; return false;
@@ -585,7 +580,8 @@ public class SubscriptionInfo implements Parcelable {
try { try {
packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
throw new IllegalArgumentException("Unknown package: " + packageName, e); Log.d("SubscriptionInfo", "canManageSubscription: Unknown package: " + packageName, e);
return false;
} }
for (UiccAccessRule rule : allAccessRules) { for (UiccAccessRule rule : allAccessRules) {
if (rule.getCarrierPrivilegeStatus(packageInfo) if (rule.getCarrierPrivilegeStatus(packageInfo)
@@ -606,9 +602,6 @@ public class SubscriptionInfo implements Parcelable {
*/ */
@SystemApi @SystemApi
public @Nullable List<UiccAccessRule> getAccessRules() { public @Nullable List<UiccAccessRule> getAccessRules() {
if (!isEmbedded()) {
throw new UnsupportedOperationException("Not an embedded subscription");
}
if (mNativeAccessRules == null) return null; if (mNativeAccessRules == null) return null;
return Arrays.asList(mNativeAccessRules); return Arrays.asList(mNativeAccessRules);
} }
@@ -619,11 +612,10 @@ public class SubscriptionInfo implements Parcelable {
* @hide * @hide
*/ */
public @Nullable List<UiccAccessRule> getAllAccessRules() { public @Nullable List<UiccAccessRule> getAllAccessRules() {
if (!isEmbedded()) {
throw new UnsupportedOperationException("Not an embedded subscription");
}
List<UiccAccessRule> merged = new ArrayList<>(); List<UiccAccessRule> merged = new ArrayList<>();
if (mNativeAccessRules != null) merged.addAll(getAccessRules()); if (mNativeAccessRules != null) {
merged.addAll(getAccessRules());
}
if (mCarrierConfigAccessRules != null) { if (mCarrierConfigAccessRules != null) {
merged.addAll(Arrays.asList(mCarrierConfigAccessRules)); merged.addAll(Arrays.asList(mCarrierConfigAccessRules));
} }

View File

@@ -2624,7 +2624,6 @@ public class SubscriptionManager {
* *
* @param info The subscription to check. * @param info The subscription to check.
* @return whether the app is authorized to manage this subscription per its metadata. * @return whether the app is authorized to manage this subscription per its metadata.
* @throws IllegalArgumentException if this subscription is not embedded.
*/ */
public boolean canManageSubscription(SubscriptionInfo info) { public boolean canManageSubscription(SubscriptionInfo info) {
return canManageSubscription(info, mContext.getPackageName()); return canManageSubscription(info, mContext.getPackageName());
@@ -2640,14 +2639,10 @@ public class SubscriptionManager {
* @param info The subscription to check. * @param info The subscription to check.
* @param packageName Package name of the app to check. * @param packageName Package name of the app to check.
* @return whether the app is authorized to manage this subscription per its access rules. * @return whether the app is authorized to manage this subscription per its access rules.
* @throws IllegalArgumentException if this subscription is not embedded.
* @hide * @hide
*/ */
public boolean canManageSubscription(SubscriptionInfo info, String packageName) { public boolean canManageSubscription(SubscriptionInfo info, String packageName) {
if (!info.isEmbedded()) { if (info == null || info.getAllAccessRules() == null) {
throw new IllegalArgumentException("Not an embedded subscription");
}
if (info.getAllAccessRules() == null) {
return false; return false;
} }
PackageManager packageManager = mContext.getPackageManager(); PackageManager packageManager = mContext.getPackageManager();
@@ -2655,7 +2650,8 @@ public class SubscriptionManager {
try { try {
packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
throw new IllegalArgumentException("Unknown package: " + packageName, e); logd("Unknown package: " + packageName);
return false;
} }
for (UiccAccessRule rule : info.getAllAccessRules()) { for (UiccAccessRule rule : info.getAllAccessRules()) {
if (rule.getCarrierPrivilegeStatus(packageInfo) if (rule.getCarrierPrivilegeStatus(packageInfo)
@@ -3048,7 +3044,7 @@ public class SubscriptionManager {
// to the caller. // to the caller.
boolean hasCarrierPrivilegePermission = TelephonyManager.from(mContext) boolean hasCarrierPrivilegePermission = TelephonyManager.from(mContext)
.hasCarrierPrivileges(info.getSubscriptionId()) .hasCarrierPrivileges(info.getSubscriptionId())
|| (info.isEmbedded() && canManageSubscription(info)); || canManageSubscription(info);
return hasCarrierPrivilegePermission; return hasCarrierPrivilegePermission;
} }