diff options
| author | 2022-10-23 14:56:45 +0000 | |
|---|---|---|
| committer | 2022-10-23 14:56:45 +0000 | |
| commit | 5568769a3b9285799c59e8ac2eb1d2d981790f22 (patch) | |
| tree | d8574b1641ff24872205927a83dad57b125ab56e | |
| parent | 27ecdb188a86e4ded41fdb9b03bce0a9cbbb3913 (diff) | |
| parent | 4f838959590b7769a0c06a7af5aa65834e479e18 (diff) | |
Merge "Add setUserHandle and getUserHandle apis."
| -rw-r--r-- | core/api/system-current.txt | 3 | ||||
| -rw-r--r-- | core/res/AndroidManifest.xml | 6 | ||||
| -rw-r--r-- | packages/Shell/AndroidManifest.xml | 1 | ||||
| -rw-r--r-- | telephony/java/android/telephony/SubscriptionManager.java | 76 | ||||
| -rwxr-xr-x | telephony/java/com/android/internal/telephony/ISub.aidl | 25 |
5 files changed, 111 insertions, 0 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 2a3518128373..b68e4884e6e1 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -190,6 +190,7 @@ package android { field public static final String MANAGE_SOUND_TRIGGER = "android.permission.MANAGE_SOUND_TRIGGER"; field public static final String MANAGE_SPEECH_RECOGNITION = "android.permission.MANAGE_SPEECH_RECOGNITION"; field public static final String MANAGE_SUBSCRIPTION_PLANS = "android.permission.MANAGE_SUBSCRIPTION_PLANS"; + field public static final String MANAGE_SUBSCRIPTION_USER_ASSOCIATION = "android.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION"; field public static final String MANAGE_TEST_NETWORKS = "android.permission.MANAGE_TEST_NETWORKS"; field public static final String MANAGE_TIME_AND_ZONE_DETECTION = "android.permission.MANAGE_TIME_AND_ZONE_DETECTION"; field public static final String MANAGE_UI_TRANSLATION = "android.permission.MANAGE_UI_TRANSLATION"; @@ -13390,6 +13391,7 @@ package android.telephony { method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int[] getCompleteActiveSubscriptionIdList(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getEnabledSubscriptionId(int); method @NonNull public static android.content.res.Resources getResourcesForSubId(@NonNull android.content.Context, int); + method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION) public android.os.UserHandle getUserHandle(int); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isSubscriptionEnabled(int); method public void requestEmbeddedSubscriptionInfoListRefresh(); method public void requestEmbeddedSubscriptionInfoListRefresh(int); @@ -13400,6 +13402,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setPreferredDataSubscriptionId(int, boolean, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.Consumer<java.lang.Integer>); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setSubscriptionEnabled(int, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setUiccApplicationsEnabled(int, boolean); + method @RequiresPermission(android.Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION) public void setUserHandle(int, @Nullable android.os.UserHandle); field @RequiresPermission(android.Manifest.permission.MANAGE_SUBSCRIPTION_PLANS) public static final String ACTION_SUBSCRIPTION_PLANS_CHANGED = "android.telephony.action.SUBSCRIPTION_PLANS_CHANGED"; field @NonNull public static final android.net.Uri ADVANCED_CALLING_ENABLED_CONTENT_URI; field @NonNull public static final android.net.Uri CROSS_SIM_ENABLED_CONTENT_URI; diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 32325e21009c..554b15374943 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -3057,6 +3057,12 @@ <permission android:name="android.permission.CREATE_USERS" android:protectionLevel="signature" /> + <!-- @SystemApi @hide Allows an application to set user association + with a certain subscription. Used by Enterprise to associate a + subscription with a work or personal profile. --> + <permission android:name="android.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION" + android:protectionLevel="signature" /> + <!-- @SystemApi @hide Allows an application to call APIs that allow it to query users on the device. --> <permission android:name="android.permission.QUERY_USERS" diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml index 111eb1ce2eb8..90fab08ed43e 100644 --- a/packages/Shell/AndroidManifest.xml +++ b/packages/Shell/AndroidManifest.xml @@ -211,6 +211,7 @@ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> <uses-permission android:name="android.permission.CREATE_USERS" /> + <uses-permission android:name="android.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION" /> <uses-permission android:name="android.permission.QUERY_USERS" /> <uses-permission android:name="android.permission.MANAGE_CREDENTIAL_MANAGEMENT_APP" /> <uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" /> diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index eb3affcd3322..439eaa69e771 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -54,6 +54,7 @@ import android.os.Looper; import android.os.ParcelUuid; import android.os.Process; import android.os.RemoteException; +import android.os.UserHandle; import android.provider.Telephony.SimInfo; import android.telephony.euicc.EuiccManager; import android.telephony.ims.ImsMmTelManager; @@ -4154,4 +4155,79 @@ public class SubscriptionManager { return "UNKNOWN(" + usageSetting + ")"; } } + + /** + * Set userHandle for a subscription. + * + * Used to set an association between a subscription and a user on the device so that voice + * calling and SMS from that subscription can be associated with that user. + * Data services are always shared between users on the device. + * + * @param subscriptionId the subId of the subscription. + * @param userHandle the userHandle associated with the subscription. + * Pass {@code null} user handle to clear the association. + * + * @throws IllegalArgumentException if subscription is invalid. + * @throws SecurityException if the caller doesn't have permissions required. + * @throws IllegalStateException if subscription service is not available. + * + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION) + public void setUserHandle(int subscriptionId, @Nullable UserHandle userHandle) { + if (!isValidSubscriptionId(subscriptionId)) { + throw new IllegalArgumentException("[setUserHandle]: Invalid subscriptionId: " + + subscriptionId); + } + + try { + ISub iSub = TelephonyManager.getSubscriptionService(); + if (iSub != null) { + iSub.setUserHandle(userHandle, subscriptionId, mContext.getOpPackageName()); + } else { + throw new IllegalStateException("[setUserHandle]: " + + "subscription service unavailable"); + } + } catch (RemoteException ex) { + ex.rethrowAsRuntimeException(); + } + } + + /** + * Get UserHandle of this subscription. + * + * Used to get user handle associated with this subscription. + * + * @param subscriptionId the subId of the subscription. + * @return userHandle associated with this subscription + * or {@code null} if subscription is not associated with any user. + * + * @throws IllegalArgumentException if subscription is invalid. + * @throws SecurityException if the caller doesn't have permissions required. + * @throws IllegalStateException if subscription service is not available. + * + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION) + public @Nullable UserHandle getUserHandle(int subscriptionId) { + if (!isValidSubscriptionId(subscriptionId)) { + throw new IllegalArgumentException("[getUserHandle]: Invalid subscriptionId: " + + subscriptionId); + } + + try { + ISub iSub = TelephonyManager.getSubscriptionService(); + if (iSub != null) { + return iSub.getUserHandle(subscriptionId, mContext.getOpPackageName()); + } else { + throw new IllegalStateException("[getUserHandle]: " + + "subscription service unavailable"); + } + } catch (RemoteException ex) { + ex.rethrowAsRuntimeException(); + } + return null; + } } diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl index 917f35bc1b82..0211a7f5c5c5 100755 --- a/telephony/java/com/android/internal/telephony/ISub.aidl +++ b/telephony/java/com/android/internal/telephony/ISub.aidl @@ -18,6 +18,7 @@ package com.android.internal.telephony; import android.telephony.SubscriptionInfo; import android.os.ParcelUuid; +import android.os.UserHandle; import com.android.internal.telephony.ISetOpportunisticDataCallback; interface ISub { @@ -316,4 +317,28 @@ interface ISub { * @throws SecurityException if doesn't have MODIFY_PHONE_STATE or Carrier Privileges */ int setUsageSetting(int usageSetting, int subId, String callingPackage); + + /** + * Set userHandle for this subscription. + * + * @param userHandle the user handle for this subscription + * @param subId the unique SubscriptionInfo index in database + * @param callingPackage The package making the IPC. + * + * @throws SecurityException if doesn't have MANAGE_SUBSCRIPTION_USER_ASSOCIATION + * @throws IllegalArgumentException if subId is invalid. + */ + int setUserHandle(in UserHandle userHandle, int subId, String callingPackage); + + /** + * Get UserHandle for this subscription + * + * @param subId the unique SubscriptionInfo index in database + * @param callingPackage the package making the IPC + * @return userHandle associated with this subscription. + * + * @throws SecurityException if doesn't have SMANAGE_SUBSCRIPTION_USER_ASSOCIATION + * @throws IllegalArgumentException if subId is invalid. + */ + UserHandle getUserHandle(int subId, String callingPackage); } |