diff options
author | Grace Jia <xiaotonj@google.com> | 2021-05-03 22:30:55 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-05-03 22:30:55 +0000 |
commit | 71de23564da289ba940388be7135e4b121c05eb7 (patch) | |
tree | fac077e260b7aa8589311fb3f57ccd917124829d /telephony/java | |
parent | 488b6ef04a964b41b8347ae0a8271fafb43b568f (diff) | |
parent | a9a60d31bc39c1368fdd7072516ba8b4e15c4f05 (diff) |
Merge "Add support for selected contacts device to device sharing." am: 83bc8699a1 am: a9a60d31bc
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1694227
Change-Id: I88e4170b568b7c7fe1610800d6b6181d171a3abc
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 417c8aa36015..06a2648f3bf6 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; @@ -592,9 +598,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. @@ -607,7 +613,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 DeviceToDeviceStatusSharing {} @@ -619,6 +625,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> */ @@ -2419,6 +2432,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 @@ -3432,6 +3496,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); } |