diff options
author | 2024-02-14 19:48:33 +0000 | |
---|---|---|
committer | 2024-02-14 19:48:33 +0000 | |
commit | 4201d5607ad0840a0f28d6e929e1bbcc642e2bbc (patch) | |
tree | 415b28e2fe3df50e5c4a0e02e59ce662dc7adf27 | |
parent | 45ff6b03c3f58a999b9548eaa7d53db3fc8ac797 (diff) | |
parent | 855c621dfbc2065c3af950eeb9d65b707589dfc6 (diff) |
Merge "isSubscriptionAssociatedWithUser API" into main
-rw-r--r-- | core/api/current.txt | 1 | ||||
-rw-r--r-- | telephony/java/android/telephony/SubscriptionManager.java | 32 | ||||
-rw-r--r-- | telephony/java/com/android/internal/telephony/ISub.aidl | 13 |
3 files changed, 44 insertions, 2 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 661caba77757..ec8699a377fe 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -45776,6 +45776,7 @@ package android.telephony { method @NonNull @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public java.util.List<android.telephony.SubscriptionInfo> getSubscriptionsInGroup(@NonNull android.os.ParcelUuid); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public boolean isActiveSubscriptionId(int); method public boolean isNetworkRoaming(int); + method @FlaggedApi("com.android.internal.telephony.flags.subscription_user_association_query") @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public boolean isSubscriptionAssociatedWithUser(int); method public static boolean isUsableSubscriptionId(int); method public static boolean isValidSubscriptionId(int); method public void removeOnOpportunisticSubscriptionsChangedListener(@NonNull android.telephony.SubscriptionManager.OnOpportunisticSubscriptionsChangedListener); diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index cd641b8be0b6..c5f2d42389e5 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -4690,7 +4690,6 @@ public class SubscriptionManager { * @param subscriptionId the subId of the subscription * @param userHandle user handle of the user * @return {@code true} if subscription is associated with user - * {code true} if there are no subscriptions on device * else {@code false} if subscription is not associated with user. * * @throws IllegalArgumentException if subscription doesn't exist. @@ -4721,6 +4720,37 @@ public class SubscriptionManager { } /** + * Returns whether the given subscription is associated with the calling user. + * + * @param subscriptionId the subscription ID of the subscription + * @return {@code true} if the subscription is associated with the user that the current process + * is running in; {@code false} otherwise. + * + * @throws IllegalArgumentException if subscription doesn't exist. + * @throws SecurityException if the caller doesn't have permissions required. + */ + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) + @FlaggedApi(Flags.FLAG_SUBSCRIPTION_USER_ASSOCIATION_QUERY) + public boolean isSubscriptionAssociatedWithUser(int subscriptionId) { + if (!isValidSubscriptionId(subscriptionId)) { + throw new IllegalArgumentException("[isSubscriptionAssociatedWithCallingUser]: " + + "Invalid subscriptionId: " + subscriptionId); + } + + try { + ISub iSub = TelephonyManager.getSubscriptionService(); + if (iSub != null) { + return iSub.isSubscriptionAssociatedWithCallingUser(subscriptionId); + } else { + throw new IllegalStateException("subscription service unavailable."); + } + } catch (RemoteException ex) { + ex.rethrowAsRuntimeException(); + } + return false; + } + + /** * Get list of subscriptions associated with user. * * @param userHandle user handle of the user diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl index cc770aa65888..6678f408e720 100644 --- a/telephony/java/com/android/internal/telephony/ISub.aidl +++ b/telephony/java/com/android/internal/telephony/ISub.aidl @@ -332,12 +332,23 @@ interface ISub { UserHandle getSubscriptionUserHandle(int subId); /** + * Returns whether the given subscription is associated with the calling user. + * + * @param subscriptionId the subscription ID of the subscription + * @return {@code true} if the subscription is associated with the user that the current process + * is running in; {@code false} otherwise. + * + * @throws IllegalArgumentException if subscription doesn't exist. + * @throws SecurityException if the caller doesn't have permissions required. + */ + boolean isSubscriptionAssociatedWithCallingUser(int subscriptionId); + + /** * Check if subscription and user are associated with each other. * * @param subscriptionId the subId of the subscription * @param userHandle user handle of the user * @return {@code true} if subscription is associated with user - * {code true} if there are no subscriptions on device * else {@code false} if subscription is not associated with user. * * @throws IllegalArgumentException if subscription is invalid. |