Loading telephony/common/com/android/internal/telephony/TelephonyPermissions.java +21 −3 Original line number Diff line number Diff line Loading @@ -748,6 +748,18 @@ public final class TelephonyPermissions { */ public static void enforceAnyPermissionGrantedOrCarrierPrivileges(Context context, int subId, int uid, String message, String... permissions) { enforceAnyPermissionGrantedOrCarrierPrivileges( context, subId, uid, false, message, permissions); } /** * Given a list of permissions, check to see if the caller has at least one of them granted. If * not, check to see if the caller has carrier privileges on the specified subscription (or any * subscription if {@code allowCarrierPrivilegeOnAnySub} is {@code true}. If the caller does not * have any of these permissions, throw a {@link SecurityException}. */ public static void enforceAnyPermissionGrantedOrCarrierPrivileges(Context context, int subId, int uid, boolean allowCarrierPrivilegeOnAnySub, String message, String... permissions) { if (permissions.length == 0) return; boolean isGranted = false; for (String perm : permissions) { Loading @@ -758,7 +770,12 @@ public final class TelephonyPermissions { } if (isGranted) return; if (allowCarrierPrivilegeOnAnySub) { if (checkCarrierPrivilegeForAnySubId(context, Binder.getCallingUid())) return; } else { if (checkCarrierPrivilegeForSubId(context, subId)) return; } StringBuilder b = new StringBuilder(message); b.append(": Neither user "); Loading @@ -769,7 +786,8 @@ public final class TelephonyPermissions { b.append(" or "); b.append(permissions[i]); } b.append(" or carrier privileges"); b.append(" or carrier privileges. subId=" + subId + ", allowCarrierPrivilegeOnAnySub=" + allowCarrierPrivilegeOnAnySub); throw new SecurityException(b.toString()); } Loading telephony/java/android/telephony/SubscriptionManager.java +44 −14 Original line number Diff line number Diff line Loading @@ -754,6 +754,15 @@ public class SubscriptionManager { /** Indicates that data roaming is disabled for a subscription */ public static final int DATA_ROAMING_DISABLE = SimInfo.DATA_ROAMING_DISABLE; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"DATA_ROAMING_"}, value = { DATA_ROAMING_ENABLE, DATA_ROAMING_DISABLE }) public @interface DataRoamingMode {} /** * TelephonyProvider column name for subscription carrier id. * @see TelephonyManager#getSimCarrierId() Loading Loading @@ -3726,10 +3735,15 @@ public class SubscriptionManager { } /** * DO NOT USE. * This API is designed for features that are not finished at this point. Do not call this API. * Check if a subscription is active. * * @param subscriptionId The subscription id to check. * * @return {@code true} if the subscription is active. * * @throws IllegalArgumentException if the provided slot index is invalid. * * @hide * TODO b/135547512: further clean up */ @SystemApi @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) Loading @@ -3750,8 +3764,12 @@ public class SubscriptionManager { * Set the device to device status sharing user preference for a subscription ID. The setting * app uses this method to indicate with whom they wish to share device to device status * information. * @param sharing the status sharing preference * @param subscriptionId the unique Subscription ID in database * * @param subscriptionId the unique Subscription ID in database. * @param sharing the status sharing preference. * * @throws IllegalArgumentException if the subscription does not exist, or the sharing * preference is invalid. */ @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) public void setDeviceToDeviceStatusSharingPreference(int subscriptionId, Loading Loading @@ -3782,8 +3800,12 @@ public class SubscriptionManager { * Set the list of contacts that allow device to device status sharing for a subscription ID. * The setting app uses this method to indicate with whom they wish to share device to device * status information. * @param contacts The list of contacts that allow device to device status sharing * @param subscriptionId The unique Subscription ID in database * * @param subscriptionId The unique Subscription ID in database. * @param contacts The list of contacts that allow device to device status sharing. * * @throws IllegalArgumentException if the subscription does not exist, or contacts is * {@code null}. */ @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) public void setDeviceToDeviceStatusSharingContacts(int subscriptionId, Loading Loading @@ -3813,16 +3835,24 @@ public class SubscriptionManager { } /** * DO NOT USE. * This API is designed for features that are not finished at this point. Do not call this API. * Get the active subscription id by logical SIM slot index. * * @param slotIndex The logical SIM slot index. * @return The active subscription id. * * @throws IllegalArgumentException if the provided slot index is invalid. * * @hide * TODO b/135547512: further clean up */ @SystemApi @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getEnabledSubscriptionId(int slotIndex) { int subId = INVALID_SUBSCRIPTION_ID; if (!isValidSlotIndex(slotIndex)) { throw new IllegalArgumentException("Invalid slot index " + slotIndex); } try { ISub iSub = TelephonyManager.getSubscriptionService(); if (iSub != null) { Loading Loading @@ -3864,12 +3894,12 @@ public class SubscriptionManager { /** * Get active data subscription id. Active data subscription refers to the subscription * currently chosen to provide cellular internet connection to the user. This may be * different from getDefaultDataSubscriptionId(). Eg. Opportunistics data * different from getDefaultDataSubscriptionId(). * * See {@link PhoneStateListener#onActiveDataSubscriptionIdChanged(int)} for the details. * @return Active data subscription id if any is chosen, or {@link #INVALID_SUBSCRIPTION_ID} if * not. * * @return Active data subscription id if any is chosen, or * SubscriptionManager.INVALID_SUBSCRIPTION_ID if not. * @see TelephonyCallback.ActiveDataSubscriptionIdListener */ public static int getActiveDataSubscriptionId() { if (isSubscriptionManagerServiceEnabled()) { Loading Loading
telephony/common/com/android/internal/telephony/TelephonyPermissions.java +21 −3 Original line number Diff line number Diff line Loading @@ -748,6 +748,18 @@ public final class TelephonyPermissions { */ public static void enforceAnyPermissionGrantedOrCarrierPrivileges(Context context, int subId, int uid, String message, String... permissions) { enforceAnyPermissionGrantedOrCarrierPrivileges( context, subId, uid, false, message, permissions); } /** * Given a list of permissions, check to see if the caller has at least one of them granted. If * not, check to see if the caller has carrier privileges on the specified subscription (or any * subscription if {@code allowCarrierPrivilegeOnAnySub} is {@code true}. If the caller does not * have any of these permissions, throw a {@link SecurityException}. */ public static void enforceAnyPermissionGrantedOrCarrierPrivileges(Context context, int subId, int uid, boolean allowCarrierPrivilegeOnAnySub, String message, String... permissions) { if (permissions.length == 0) return; boolean isGranted = false; for (String perm : permissions) { Loading @@ -758,7 +770,12 @@ public final class TelephonyPermissions { } if (isGranted) return; if (allowCarrierPrivilegeOnAnySub) { if (checkCarrierPrivilegeForAnySubId(context, Binder.getCallingUid())) return; } else { if (checkCarrierPrivilegeForSubId(context, subId)) return; } StringBuilder b = new StringBuilder(message); b.append(": Neither user "); Loading @@ -769,7 +786,8 @@ public final class TelephonyPermissions { b.append(" or "); b.append(permissions[i]); } b.append(" or carrier privileges"); b.append(" or carrier privileges. subId=" + subId + ", allowCarrierPrivilegeOnAnySub=" + allowCarrierPrivilegeOnAnySub); throw new SecurityException(b.toString()); } Loading
telephony/java/android/telephony/SubscriptionManager.java +44 −14 Original line number Diff line number Diff line Loading @@ -754,6 +754,15 @@ public class SubscriptionManager { /** Indicates that data roaming is disabled for a subscription */ public static final int DATA_ROAMING_DISABLE = SimInfo.DATA_ROAMING_DISABLE; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"DATA_ROAMING_"}, value = { DATA_ROAMING_ENABLE, DATA_ROAMING_DISABLE }) public @interface DataRoamingMode {} /** * TelephonyProvider column name for subscription carrier id. * @see TelephonyManager#getSimCarrierId() Loading Loading @@ -3726,10 +3735,15 @@ public class SubscriptionManager { } /** * DO NOT USE. * This API is designed for features that are not finished at this point. Do not call this API. * Check if a subscription is active. * * @param subscriptionId The subscription id to check. * * @return {@code true} if the subscription is active. * * @throws IllegalArgumentException if the provided slot index is invalid. * * @hide * TODO b/135547512: further clean up */ @SystemApi @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) Loading @@ -3750,8 +3764,12 @@ public class SubscriptionManager { * Set the device to device status sharing user preference for a subscription ID. The setting * app uses this method to indicate with whom they wish to share device to device status * information. * @param sharing the status sharing preference * @param subscriptionId the unique Subscription ID in database * * @param subscriptionId the unique Subscription ID in database. * @param sharing the status sharing preference. * * @throws IllegalArgumentException if the subscription does not exist, or the sharing * preference is invalid. */ @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) public void setDeviceToDeviceStatusSharingPreference(int subscriptionId, Loading Loading @@ -3782,8 +3800,12 @@ public class SubscriptionManager { * Set the list of contacts that allow device to device status sharing for a subscription ID. * The setting app uses this method to indicate with whom they wish to share device to device * status information. * @param contacts The list of contacts that allow device to device status sharing * @param subscriptionId The unique Subscription ID in database * * @param subscriptionId The unique Subscription ID in database. * @param contacts The list of contacts that allow device to device status sharing. * * @throws IllegalArgumentException if the subscription does not exist, or contacts is * {@code null}. */ @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) public void setDeviceToDeviceStatusSharingContacts(int subscriptionId, Loading Loading @@ -3813,16 +3835,24 @@ public class SubscriptionManager { } /** * DO NOT USE. * This API is designed for features that are not finished at this point. Do not call this API. * Get the active subscription id by logical SIM slot index. * * @param slotIndex The logical SIM slot index. * @return The active subscription id. * * @throws IllegalArgumentException if the provided slot index is invalid. * * @hide * TODO b/135547512: further clean up */ @SystemApi @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getEnabledSubscriptionId(int slotIndex) { int subId = INVALID_SUBSCRIPTION_ID; if (!isValidSlotIndex(slotIndex)) { throw new IllegalArgumentException("Invalid slot index " + slotIndex); } try { ISub iSub = TelephonyManager.getSubscriptionService(); if (iSub != null) { Loading Loading @@ -3864,12 +3894,12 @@ public class SubscriptionManager { /** * Get active data subscription id. Active data subscription refers to the subscription * currently chosen to provide cellular internet connection to the user. This may be * different from getDefaultDataSubscriptionId(). Eg. Opportunistics data * different from getDefaultDataSubscriptionId(). * * See {@link PhoneStateListener#onActiveDataSubscriptionIdChanged(int)} for the details. * @return Active data subscription id if any is chosen, or {@link #INVALID_SUBSCRIPTION_ID} if * not. * * @return Active data subscription id if any is chosen, or * SubscriptionManager.INVALID_SUBSCRIPTION_ID if not. * @see TelephonyCallback.ActiveDataSubscriptionIdListener */ public static int getActiveDataSubscriptionId() { if (isSubscriptionManagerServiceEnabled()) { Loading