isSubscriptionAssociatedWithUser Implementation
Implements a public API in which a caller can determine whether the
given subscription is associated with their own user.
Bug: 325045841
Test: atest SubscriptionManagerTest -c
Change-Id: Ib09527a497a7108dca3777c4ee310f8a551baf22
diff --git a/flags/subscription.aconfig b/flags/subscription.aconfig
index fa77fc3..cebedd5 100644
--- a/flags/subscription.aconfig
+++ b/flags/subscription.aconfig
@@ -33,4 +33,11 @@
namespace: "telephony"
description: "Support the psim to esim conversion."
bug: "315073761"
+}
+
+flag {
+ name: "subscription_user_association_query"
+ namespace: "telephony"
+ description: "Supports querying if a subscription is associated with the caller"
+ bug: "325045841"
}
\ No newline at end of file
diff --git a/src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java b/src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java
index 92de811..8757c97 100644
--- a/src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java
+++ b/src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java
@@ -3944,12 +3944,31 @@
}
/**
+ * 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 calling process
+ * is running in; {@code false} otherwise.
+ *
+ * @throws IllegalArgumentException if subscription doesn't exist.
+ * @throws SecurityException if the caller doesn't have permissions required.
+ */
+ @Override
+ public boolean isSubscriptionAssociatedWithCallingUser(int subscriptionId) {
+ enforcePermissions("isSubscriptionAssociatedWithCallingUser",
+ Manifest.permission.READ_PHONE_STATE);
+
+ UserHandle myUserHandle = UserHandle.of(UserHandle.getCallingUserId());
+ return mFeatureFlags.subscriptionUserAssociationQuery()
+ && isSubscriptionAssociatedWithUserNoCheck(subscriptionId, myUserHandle);
+ }
+
+ /**
* 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 SecurityException if the caller doesn't have permissions required.
@@ -3960,6 +3979,12 @@
@NonNull UserHandle userHandle) {
enforcePermissions("isSubscriptionAssociatedWithUser",
Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION);
+
+ return isSubscriptionAssociatedWithUserNoCheck(subscriptionId, userHandle);
+ }
+
+ private boolean isSubscriptionAssociatedWithUserNoCheck(int subscriptionId,
+ @NonNull UserHandle userHandle) {
SubscriptionInfoInternal subInfoInternal = mSubscriptionDatabaseManager
.getSubscriptionInfoInternal(subscriptionId);
// Throw IAE if no record of the sub's association state.