Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 855c621d authored by Adam Bookatz's avatar Adam Bookatz Committed by Nikhil Kumar
Browse files

isSubscriptionAssociatedWithUser API

Introduces a public API in which a caller can determine whether the
given subscription is associated with their own user.

Bug: 325045841
API-Coverage-Bug: 325205061
Test: atest SubscriptionManagerTest -c
Change-Id: I3627b06e5b68a35b8a5786a616840fbe31f02558
parent e48ea8e7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -45725,6 +45725,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);
+31 −1
Original line number Diff line number Diff line
@@ -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.
@@ -4720,6 +4719,37 @@ public class SubscriptionManager {
        return false;
    }

    /**
     * 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.
     *
+12 −1
Original line number Diff line number Diff line
@@ -331,13 +331,24 @@ 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.