Merge "Add support for selected contacts device to device sharing."

This commit is contained in:
Grace Jia
2021-05-03 21:49:45 +00:00
committed by Gerrit Code Review
4 changed files with 116 additions and 4 deletions

View File

@@ -40797,6 +40797,7 @@ package android.telephony {
method public static int getDefaultSubscriptionId();
method public static int getDefaultVoiceSubscriptionId();
method public int getDeviceToDeviceStatusSharing(int);
method @NonNull public java.util.List<android.net.Uri> getDeviceToDeviceStatusSharingContacts(int);
method @NonNull @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public java.util.List<android.telephony.SubscriptionInfo> getOpportunisticSubscriptions();
method public static int getSlotIndex(int);
method @Nullable public int[] getSubscriptionIds(int);
@@ -40810,6 +40811,7 @@ package android.telephony {
method public void removeOnSubscriptionsChangedListener(android.telephony.SubscriptionManager.OnSubscriptionsChangedListener);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void removeSubscriptionsFromGroup(@NonNull java.util.List<java.lang.Integer>, @NonNull android.os.ParcelUuid);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDeviceToDeviceStatusSharing(int, int);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDeviceToDeviceStatusSharingContacts(@NonNull java.util.List<android.net.Uri>, int);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setOpportunistic(boolean, int);
method public void setSubscriptionOverrideCongested(int, boolean, long);
method public void setSubscriptionOverrideCongested(int, boolean, @NonNull int[], long);
@@ -40824,8 +40826,9 @@ package android.telephony {
field public static final int D2D_SHARING_ALL = 3; // 0x3
field public static final int D2D_SHARING_ALL_CONTACTS = 1; // 0x1
field public static final int D2D_SHARING_DISABLED = 0; // 0x0
field public static final int D2D_SHARING_STARRED_CONTACTS = 2; // 0x2
field public static final int D2D_SHARING_SELECTED_CONTACTS = 2; // 0x2
field public static final String D2D_STATUS_SHARING = "d2d_sharing_status";
field public static final String D2D_STATUS_SHARING_SELECTED_CONTACTS = "d2d_sharing_contacts";
field public static final int DATA_ROAMING_DISABLE = 0; // 0x0
field public static final int DATA_ROAMING_ENABLE = 1; // 0x1
field public static final int DEFAULT_SUBSCRIPTION_ID = 2147483647; // 0x7fffffff

View File

@@ -5342,5 +5342,14 @@ public final class Telephony {
* @hide
*/
public static final String COLUMN_VOIMS_OPT_IN_STATUS = "voims_opt_in_status";
/**
* TelephonyProvider column name for information selected contacts that allow device to
* device sharing.
*
* @hide
*/
public static final String COLUMN_D2D_STATUS_SHARING_SELECTED_CONTACTS =
"d2d_sharing_contacts";
}
}

View File

@@ -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 {}
@@ -618,6 +624,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>
@@ -2418,6 +2431,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
@@ -3431,6 +3495,40 @@ public class SubscriptionManager {
mContext);
}
/**
* 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.

View File

@@ -302,4 +302,6 @@ interface ISub {
int setUiccApplicationsEnabled(boolean enabled, int subscriptionId);
int setDeviceToDeviceStatusSharing(int sharing, int subId);
int setDeviceToDeviceStatusSharingContacts(String contacts, int subscriptionId);
}