diff options
author | Grace Jia <xiaotonj@google.com> | 2021-03-18 14:47:31 -0700 |
---|---|---|
committer | Grace Jia <xiaotonj@google.com> | 2021-03-23 15:51:24 +0000 |
commit | 2bd23cfbcc1d6a0852df5d4e53bf520bb0a40177 (patch) | |
tree | 3fea0514cd58b1a1c1b7d2e4035fd030bfa22b77 /telephony/java | |
parent | d6a0393fe0f588588031b60e7e5c8688f9e2197a (diff) |
Add support for selected contacts device to device sharing.
Bug: 163085177
Test: CTS tests
Change-Id: I4f6da463a29ba9cf067d36941a9b4e584012c817
Merged-In: I4f6da463a29ba9cf067d36941a9b4e584012c817
Diffstat (limited to 'telephony/java')
-rw-r--r-- | telephony/java/android/telephony/SubscriptionManager.java | 104 | ||||
-rwxr-xr-x | telephony/java/com/android/internal/telephony/ISub.aidl | 2 |
2 files changed, 103 insertions, 3 deletions
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index a46621a83c1e..67fe783ee7a4 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -56,6 +56,7 @@ import android.os.RemoteException; import android.provider.Telephony.SimInfo; import android.telephony.euicc.EuiccManager; import android.telephony.ims.ImsMmTelManager; +import android.util.Base64; import android.util.Log; import android.util.Pair; @@ -67,6 +68,11 @@ import com.android.internal.util.FunctionalUtils; import com.android.internal.util.Preconditions; import com.android.telephony.Rlog; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; @@ -612,9 +618,9 @@ public class SubscriptionManager { public static final int D2D_SHARING_ALL_CONTACTS = 1; /** - * Device status is shared with all starred contacts. + * Device status is shared with all selected contacts. */ - public static final int D2D_SHARING_STARRED_CONTACTS = 2; + public static final int D2D_SHARING_SELECTED_CONTACTS = 2; /** * Device status is shared whenever possible. @@ -627,7 +633,7 @@ public class SubscriptionManager { value = { D2D_SHARING_DISABLED, D2D_SHARING_ALL_CONTACTS, - D2D_SHARING_STARRED_CONTACTS, + D2D_SHARING_SELECTED_CONTACTS, D2D_SHARING_ALL }) public @interface DeviceToDeviceStatusSharingPreference {} @@ -639,6 +645,13 @@ public class SubscriptionManager { public static final String D2D_STATUS_SHARING = SimInfo.COLUMN_D2D_STATUS_SHARING; /** + * TelephonyProvider column name for contacts information that allow device to device sharing. + * <P>Type: TEXT (String)</P> + */ + public static final String D2D_STATUS_SHARING_SELECTED_CONTACTS = + SimInfo.COLUMN_D2D_STATUS_SHARING_SELECTED_CONTACTS; + + /** * TelephonyProvider column name for the color of a SIM. * <P>Type: INTEGER (int)</P> */ @@ -2439,6 +2452,57 @@ public class SubscriptionManager { } /** + * Serialize list of contacts uri to string + * @hide + */ + public static String serializeUriLists(List<Uri> uris) { + List<String> contacts = new ArrayList<>(); + for (Uri uri : uris) { + contacts.add(uri.toString()); + } + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(contacts); + oos.flush(); + return Base64.encodeToString(bos.toByteArray(), Base64.DEFAULT); + } catch (IOException e) { + logd("serializeUriLists IO exception"); + } + return ""; + } + + /** + * Return list of contacts uri corresponding to query result. + * @param subId Subscription Id of Subscription + * @param propKey Column name in SubscriptionInfo database + * @return list of contacts uri to be returned + * @hide + */ + private static List<Uri> getContactsFromSubscriptionProperty(int subId, String propKey, + Context context) { + String result = getSubscriptionProperty(subId, propKey, context); + if (result != null) { + try { + byte[] b = Base64.decode(result, Base64.DEFAULT); + ByteArrayInputStream bis = new ByteArrayInputStream(b); + ObjectInputStream ois = new ObjectInputStream(bis); + List<String> contacts = ArrayList.class.cast(ois.readObject()); + List<Uri> uris = new ArrayList<>(); + for (String contact : contacts) { + uris.add(Uri.parse(contact)); + } + return uris; + } catch (IOException e) { + logd("getContactsFromSubscriptionProperty IO exception"); + } catch (ClassNotFoundException e) { + logd("getContactsFromSubscriptionProperty ClassNotFound exception"); + } + } + return new ArrayList<>(); + } + + /** * Store properties associated with SubscriptionInfo in database * @param subId Subscription Id of Subscription * @param propKey Column name in SubscriptionInfo database @@ -3443,6 +3507,40 @@ public class SubscriptionManager { } /** + * Set the list of contacts that allow device to device status sharing for a subscription ID. + * The setting app uses this method to indicate with whom they wish to share device to device + * status information. + * @param contacts The list of contacts that allow device to device status sharing + * @param subscriptionId The unique Subscription ID in database + */ + @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) + public void setDeviceToDeviceStatusSharingContacts(@NonNull List<Uri> contacts, + int subscriptionId) { + String contactString = serializeUriLists(contacts); + if (VDBG) { + logd("[setDeviceToDeviceStatusSharingContacts] + contacts: " + contactString + + " subId: " + subscriptionId); + } + setSubscriptionPropertyHelper(subscriptionId, "setDeviceToDeviceSharingStatus", + (iSub)->iSub.setDeviceToDeviceStatusSharingContacts(serializeUriLists(contacts), + subscriptionId)); + } + + /** + * Returns the list of contacts that allow device to device status sharing. + * @param subscriptionId Subscription id of subscription + * @return The list of contacts that allow device to device status sharing + */ + public @NonNull List<Uri> getDeviceToDeviceStatusSharingContacts( + int subscriptionId) { + if (VDBG) { + logd("[getDeviceToDeviceStatusSharingContacts] + subId: " + subscriptionId); + } + return getContactsFromSubscriptionProperty(subscriptionId, + D2D_STATUS_SHARING_SELECTED_CONTACTS, mContext); + } + + /** * DO NOT USE. * This API is designed for features that are not finished at this point. Do not call this API. * @hide diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl index 9493c76d9a57..6493772039e6 100755 --- a/telephony/java/com/android/internal/telephony/ISub.aidl +++ b/telephony/java/com/android/internal/telephony/ISub.aidl @@ -302,4 +302,6 @@ interface ISub { int setUiccApplicationsEnabled(boolean enabled, int subscriptionId); int setDeviceToDeviceStatusSharing(int sharing, int subId); + + int setDeviceToDeviceStatusSharingContacts(String contacts, int subscriptionId); } |