From be9240bcf072dcbdc410cacefe3240c121ce5ff3 Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Mon, 3 Dec 2018 20:29:33 -0800 Subject: [PATCH] Add APIs to remove sub from a group and get subs in the same gorup. Add APIs in SubscriptionController so that caller with permissions can remove subscriptions from a group or get all subscriptions with the same group. Bug: 118349116 Test: unittest Change-Id: Iba4d31b437b372b3f41a6ed23f03b96a685a324c Merged-In: Iba4d31b437b372b3f41a6ed23f03b96a685a324c --- api/current.txt | 2 + .../telephony/SubscriptionManager.java | 86 ++++++++++++++++++- .../android/telephony/TelephonyManager.java | 2 +- .../com/android/internal/telephony/ISub.aidl | 4 + 4 files changed, 90 insertions(+), 4 deletions(-) diff --git a/api/current.txt b/api/current.txt index 0eb6985de2d94..71a44748f1a41 100755 --- a/api/current.txt +++ b/api/current.txt @@ -42869,12 +42869,14 @@ package android.telephony { method public static int getSlotIndex(int); method public int[] getSubscriptionIds(int); method public java.util.List getSubscriptionPlans(int); + method public java.util.List getSubscriptionsInGroup(int); method public boolean isActiveSubscriptionId(int); method public boolean isNetworkRoaming(int); method public static boolean isUsableSubscriptionId(int); method public static boolean isValidSubscriptionId(int); method public void removeOnOpportunisticSubscriptionsChangedListener(android.telephony.SubscriptionManager.OnOpportunisticSubscriptionsChangedListener); method public void removeOnSubscriptionsChangedListener(android.telephony.SubscriptionManager.OnSubscriptionsChangedListener); + method public boolean removeSubscriptionsFromGroup(int[]); method public java.lang.String setSubscriptionGroup(int[]); method public void setSubscriptionOverrideCongested(int, boolean, long); method public void setSubscriptionOverrideUnmetered(int, boolean, long); diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index ff20fd23b0c1d..7520f6434b04e 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -19,6 +19,7 @@ package android.telephony; import static android.net.NetworkPolicyManager.OVERRIDE_CONGESTED; import static android.net.NetworkPolicyManager.OVERRIDE_UNMETERED; +import android.Manifest; import android.annotation.CallbackExecutor; import android.annotation.DurationMillisLong; import android.annotation.NonNull; @@ -2389,16 +2390,21 @@ public class SubscriptionManager { * together, some of them may be invisible to the users, etc. * * Caller will either have {@link android.Manifest.permission#MODIFY_PHONE_STATE} - * permission or can manage all subscriptions in the list, according to their - * acess rules. + * permission or had carrier privilege permission on the subscriptions: + * {@link TelephonyManager#hasCarrierPrivileges(int)} or + * {@link #canManageSubscription(SubscriptionInfo)} + * + * @throws SecurityException if the caller doesn't meet the requirements + * outlined above. * * @param subIdList list of subId that will be in the same group * @return groupUUID a UUID assigned to the subscription group. It returns * null if fails. * */ + @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public String setSubscriptionGroup(int[] subIdList) { + public @Nullable String setSubscriptionGroup(@NonNull int[] subIdList) { String pkgForDebug = mContext != null ? mContext.getOpPackageName() : ""; if (VDBG) { logd("[setSubscriptionGroup]+ subIdList:" + Arrays.toString(subIdList)); @@ -2417,6 +2423,80 @@ public class SubscriptionManager { return groupUUID; } + /** + * Remove a list of subscriptions from their subscription group. + * See {@link #setSubscriptionGroup(int[])} for more details. + * + * Caller will either have {@link android.Manifest.permission#MODIFY_PHONE_STATE} + * permission or had carrier privilege permission on the subscriptions: + * {@link TelephonyManager#hasCarrierPrivileges(int)} or + * {@link #canManageSubscription(SubscriptionInfo)} + * + * @throws SecurityException if the caller doesn't meet the requirements + * outlined above. + * + * @param subIdList list of subId that need removing from their groups. + * @return whether the operation succeeds. + * + */ + @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges + @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) + public boolean removeSubscriptionsFromGroup(@NonNull int[] subIdList) { + String pkgForDebug = mContext != null ? mContext.getOpPackageName() : ""; + if (VDBG) { + logd("[removeSubscriptionsFromGroup]+ subIdList:" + Arrays.toString(subIdList)); + } + + try { + ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); + if (iSub != null) { + return iSub.removeSubscriptionsFromGroup(subIdList, pkgForDebug); + } + } catch (RemoteException ex) { + // ignore it + } + + return false; + } + + /** + * Get subscriptionInfo list of subscriptions that are in the same group of given subId. + * See {@link #setSubscriptionGroup(int[])} for more details. + * + * Caller will either have {@link android.Manifest.permission#READ_PHONE_STATE} + * permission or had carrier privilege permission on the subscription. + * {@link TelephonyManager#hasCarrierPrivileges(int)} + * + * @throws SecurityException if the caller doesn't meet the requirements + * outlined above. + * + * @param subId of which list of subInfo from the same group will be returned. + * @return list of subscriptionInfo that belong to the same group, including the given + * subscription itself. It will return null if the subscription doesn't exist or it + * doesn't belong to any group. + * + */ + @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges + @RequiresPermission(Manifest.permission.READ_PHONE_STATE) + public @Nullable List getSubscriptionsInGroup(int subId) { + String pkgForDebug = mContext != null ? mContext.getOpPackageName() : ""; + if (VDBG) { + logd("[getSubscriptionsInGroup]+ subId:" + subId); + } + + List result = null; + try { + ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); + if (iSub != null) { + result = iSub.getSubscriptionsInGroup(subId, pkgForDebug); + } + } catch (RemoteException ex) { + // ignore it + } + + return result; + } + /** * Set metered by simInfo index * diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 585c0e40d478c..0aa62c40f39d9 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -6603,7 +6603,7 @@ public class TelephonyManager { try { ITelephony telephony = getITelephony(); if (telephony != null) { - return telephony.getCarrierPrivilegeStatus(mSubId) == + return telephony.getCarrierPrivilegeStatus(subId) == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; } } catch (RemoteException ex) { diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl index f9db4b0afd127..65d1a920a3249 100755 --- a/telephony/java/com/android/internal/telephony/ISub.aidl +++ b/telephony/java/com/android/internal/telephony/ISub.aidl @@ -210,6 +210,10 @@ interface ISub { */ List getOpportunisticSubscriptions(String callingPackage); + boolean removeSubscriptionsFromGroup(in int[] subIdList, String callingPackage); + + List getSubscriptionsInGroup(int subId, String callingPackage); + int getSlotIndex(int subId); int[] getSubId(int slotIndex);