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

Commit 4201d560 authored by Nikhil Kumar's avatar Nikhil Kumar Committed by Android (Google) Code Review
Browse files

Merge "isSubscriptionAssociatedWithUser API" into main

parents 45ff6b03 855c621d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+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.