From 8fe1f7cb5c2aa6eb5f4df545483a326e14d23770 Mon Sep 17 00:00:00 2001 From: Nazanin Bakhshi Date: Mon, 19 Aug 2019 16:36:07 -0700 Subject: [PATCH 1/2] add checking for carrierConfigs certificates for psim Test: utests Bug: 139133814 Change-Id: I2d5cf7ee4e516ff16a67a5fbef6674a380095888 Merged-In: I2d5cf7ee4e516ff16a67a5fbef6674a380095888 --- .../java/android/telephony/SubscriptionInfo.java | 11 ----------- .../java/android/telephony/SubscriptionManager.java | 7 +------ 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index 36e81232100ce..bb2269fc4d00b 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -551,7 +551,6 @@ public class SubscriptionInfo implements Parcelable { * * @param context Context of the application to check. * @return whether the app is authorized to manage this subscription per its metadata. - * @throws UnsupportedOperationException if this subscription is not embedded. * @hide * @deprecated - Do not use. */ @@ -567,15 +566,11 @@ public class SubscriptionInfo implements Parcelable { * @param context Any context. * @param packageName Package name of the app to check. * @return whether the app is authorized to manage this subscription per its metadata. - * @throws UnsupportedOperationException if this subscription is not embedded. * @hide * @deprecated - Do not use. */ @Deprecated public boolean canManageSubscription(Context context, String packageName) { - if (!isEmbedded()) { - throw new UnsupportedOperationException("Not an embedded subscription"); - } List allAccessRules = getAllAccessRules(); if (allAccessRules == null) { return false; @@ -606,9 +601,6 @@ public class SubscriptionInfo implements Parcelable { */ @SystemApi public @Nullable List getAccessRules() { - if (!isEmbedded()) { - throw new UnsupportedOperationException("Not an embedded subscription"); - } if (mNativeAccessRules == null) return null; return Arrays.asList(mNativeAccessRules); } @@ -619,9 +611,6 @@ public class SubscriptionInfo implements Parcelable { * @hide */ public @Nullable List getAllAccessRules() { - if (!isEmbedded()) { - throw new UnsupportedOperationException("Not an embedded subscription"); - } List merged = new ArrayList<>(); if (mNativeAccessRules != null) merged.addAll(getAccessRules()); if (mCarrierConfigAccessRules != null) { diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index b35549ead969c..8ef63d501a907 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -2624,7 +2624,6 @@ public class SubscriptionManager { * * @param info The subscription to check. * @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) { return canManageSubscription(info, mContext.getPackageName()); @@ -2640,13 +2639,9 @@ public class SubscriptionManager { * @param info The subscription 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. - * @throws IllegalArgumentException if this subscription is not embedded. * @hide */ public boolean canManageSubscription(SubscriptionInfo info, String packageName) { - if (!info.isEmbedded()) { - throw new IllegalArgumentException("Not an embedded subscription"); - } if (info.getAllAccessRules() == null) { return false; } @@ -3048,7 +3043,7 @@ public class SubscriptionManager { // to the caller. boolean hasCarrierPrivilegePermission = TelephonyManager.from(mContext) .hasCarrierPrivileges(info.getSubscriptionId()) - || (info.isEmbedded() && canManageSubscription(info)); + || canManageSubscription(info); return hasCarrierPrivilegePermission; } From e55c2f992ce5a171009e87fb175c770615fd1f32 Mon Sep 17 00:00:00 2001 From: Nazanin Bakhshi Date: Thu, 29 Aug 2019 16:19:12 -0700 Subject: [PATCH 2/2] Fix crashes seen when checking for carrierConfig certificates 1. Do not throw exception when packageName is not found 2. Fix NPE caused by null SubscriptionInfo Bug: 140122832 Test: Utest and manual test Change-Id: I686647419896a1780f0697b3ed5d319363675f5f Merged-In: I686647419896a1780f0697b3ed5d319363675f5f --- telephony/java/android/telephony/SubscriptionInfo.java | 7 +++++-- telephony/java/android/telephony/SubscriptionManager.java | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index bb2269fc4d00b..58f2858513758 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -580,7 +580,8 @@ public class SubscriptionInfo implements Parcelable { try { packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } 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) { if (rule.getCarrierPrivilegeStatus(packageInfo) @@ -612,7 +613,9 @@ public class SubscriptionInfo implements Parcelable { */ public @Nullable List getAllAccessRules() { List merged = new ArrayList<>(); - if (mNativeAccessRules != null) merged.addAll(getAccessRules()); + if (mNativeAccessRules != null) { + merged.addAll(getAccessRules()); + } if (mCarrierConfigAccessRules != null) { merged.addAll(Arrays.asList(mCarrierConfigAccessRules)); } diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 8ef63d501a907..8e6e9b842c34e 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -2642,7 +2642,7 @@ public class SubscriptionManager { * @hide */ public boolean canManageSubscription(SubscriptionInfo info, String packageName) { - if (info.getAllAccessRules() == null) { + if (info == null || info.getAllAccessRules() == null) { return false; } PackageManager packageManager = mContext.getPackageManager(); @@ -2650,7 +2650,8 @@ public class SubscriptionManager { try { packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (PackageManager.NameNotFoundException e) { - throw new IllegalArgumentException("Unknown package: " + packageName, e); + logd("Unknown package: " + packageName); + return false; } for (UiccAccessRule rule : info.getAllAccessRules()) { if (rule.getCarrierPrivilegeStatus(packageInfo)