Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c5cd7b8 authored by Joseph Pirozzo's avatar Joseph Pirozzo Committed by Automerger Merge Worker
Browse files

Merge "Add BluetoothMapClient to system API" am: 9cabf5a07b am: 1211be32 am: ba176a73

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1564659

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I5f8b277c6f9e8ecb847285108ef4cc1b856516fe
parents 46cd7cc2 ba176a73
Loading
Loading
Loading
Loading
+86 −15
Original line number Original line Diff line number Diff line
@@ -18,7 +18,9 @@ package android.bluetooth;


import android.Manifest;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
@@ -30,6 +32,7 @@ import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.List;


/**
/**
@@ -37,44 +40,60 @@ import java.util.List;
 *
 *
 * @hide
 * @hide
 */
 */
@SystemApi
public final class BluetoothMapClient implements BluetoothProfile {
public final class BluetoothMapClient implements BluetoothProfile {


    private static final String TAG = "BluetoothMapClient";
    private static final String TAG = "BluetoothMapClient";
    private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
    private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
    private static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE);
    private static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE);


    /** @hide */
    public static final String ACTION_CONNECTION_STATE_CHANGED =
    public static final String ACTION_CONNECTION_STATE_CHANGED =
            "android.bluetooth.mapmce.profile.action.CONNECTION_STATE_CHANGED";
            "android.bluetooth.mapmce.profile.action.CONNECTION_STATE_CHANGED";
    /** @hide */
    public static final String ACTION_MESSAGE_RECEIVED =
    public static final String ACTION_MESSAGE_RECEIVED =
            "android.bluetooth.mapmce.profile.action.MESSAGE_RECEIVED";
            "android.bluetooth.mapmce.profile.action.MESSAGE_RECEIVED";
    /* Actions to be used for pending intents */
    /* Actions to be used for pending intents */
    /** @hide */
    public static final String ACTION_MESSAGE_SENT_SUCCESSFULLY =
    public static final String ACTION_MESSAGE_SENT_SUCCESSFULLY =
            "android.bluetooth.mapmce.profile.action.MESSAGE_SENT_SUCCESSFULLY";
            "android.bluetooth.mapmce.profile.action.MESSAGE_SENT_SUCCESSFULLY";
    /** @hide */
    public static final String ACTION_MESSAGE_DELIVERED_SUCCESSFULLY =
    public static final String ACTION_MESSAGE_DELIVERED_SUCCESSFULLY =
            "android.bluetooth.mapmce.profile.action.MESSAGE_DELIVERED_SUCCESSFULLY";
            "android.bluetooth.mapmce.profile.action.MESSAGE_DELIVERED_SUCCESSFULLY";


    /**
    /**
     * Action to notify read status changed
     * Action to notify read status changed
     *
     * @hide
     */
     */
    public static final String ACTION_MESSAGE_READ_STATUS_CHANGED =
    public static final String ACTION_MESSAGE_READ_STATUS_CHANGED =
            "android.bluetooth.mapmce.profile.action.MESSAGE_READ_STATUS_CHANGED";
            "android.bluetooth.mapmce.profile.action.MESSAGE_READ_STATUS_CHANGED";


    /**
    /**
     * Action to notify deleted status changed
     * Action to notify deleted status changed
     *
     * @hide
     */
     */
    public static final String ACTION_MESSAGE_DELETED_STATUS_CHANGED =
    public static final String ACTION_MESSAGE_DELETED_STATUS_CHANGED =
            "android.bluetooth.mapmce.profile.action.MESSAGE_DELETED_STATUS_CHANGED";
            "android.bluetooth.mapmce.profile.action.MESSAGE_DELETED_STATUS_CHANGED";


    /* Extras used in ACTION_MESSAGE_RECEIVED intent.
    /**
     * NOTE: HANDLE is only valid for a single session with the device. */
     * Extras used in ACTION_MESSAGE_RECEIVED intent.
     * NOTE: HANDLE is only valid for a single session with the device.
     */
    /** @hide */
    public static final String EXTRA_MESSAGE_HANDLE =
    public static final String EXTRA_MESSAGE_HANDLE =
            "android.bluetooth.mapmce.profile.extra.MESSAGE_HANDLE";
            "android.bluetooth.mapmce.profile.extra.MESSAGE_HANDLE";
    /** @hide */
    public static final String EXTRA_MESSAGE_TIMESTAMP =
    public static final String EXTRA_MESSAGE_TIMESTAMP =
            "android.bluetooth.mapmce.profile.extra.MESSAGE_TIMESTAMP";
            "android.bluetooth.mapmce.profile.extra.MESSAGE_TIMESTAMP";
    /** @hide */
    public static final String EXTRA_MESSAGE_READ_STATUS =
    public static final String EXTRA_MESSAGE_READ_STATUS =
            "android.bluetooth.mapmce.profile.extra.MESSAGE_READ_STATUS";
            "android.bluetooth.mapmce.profile.extra.MESSAGE_READ_STATUS";
    /** @hide */
    public static final String EXTRA_SENDER_CONTACT_URI =
    public static final String EXTRA_SENDER_CONTACT_URI =
            "android.bluetooth.mapmce.profile.extra.SENDER_CONTACT_URI";
            "android.bluetooth.mapmce.profile.extra.SENDER_CONTACT_URI";
    /** @hide */
    public static final String EXTRA_SENDER_CONTACT_NAME =
    public static final String EXTRA_SENDER_CONTACT_NAME =
            "android.bluetooth.mapmce.profile.extra.SENDER_CONTACT_NAME";
            "android.bluetooth.mapmce.profile.extra.SENDER_CONTACT_NAME";


@@ -84,6 +103,8 @@ public final class BluetoothMapClient implements BluetoothProfile {
     * Possible values are:
     * Possible values are:
     * true: deleted
     * true: deleted
     * false: undeleted
     * false: undeleted
     *
     * @hide
     */
     */
    public static final String EXTRA_MESSAGE_DELETED_STATUS =
    public static final String EXTRA_MESSAGE_DELETED_STATUS =
            "android.bluetooth.mapmce.profile.extra.MESSAGE_DELETED_STATUS";
            "android.bluetooth.mapmce.profile.extra.MESSAGE_DELETED_STATUS";
@@ -93,24 +114,42 @@ public final class BluetoothMapClient implements BluetoothProfile {
     * Possible values are:
     * Possible values are:
     * 0: failure
     * 0: failure
     * 1: success
     * 1: success
     *
     * @hide
     */
     */
    public static final String EXTRA_RESULT_CODE =
    public static final String EXTRA_RESULT_CODE =
            "android.bluetooth.device.extra.RESULT_CODE";
            "android.bluetooth.device.extra.RESULT_CODE";


    /** There was an error trying to obtain the state */
    /**
     * There was an error trying to obtain the state
     * @hide
     */
    public static final int STATE_ERROR = -1;
    public static final int STATE_ERROR = -1;


    /** @hide */
    public static final int RESULT_FAILURE = 0;
    public static final int RESULT_FAILURE = 0;
    /** @hide */
    public static final int RESULT_SUCCESS = 1;
    public static final int RESULT_SUCCESS = 1;
    /** Connection canceled before completion. */
    /**
     * Connection canceled before completion.
     * @hide
     */
    public static final int RESULT_CANCELED = 2;
    public static final int RESULT_CANCELED = 2;

    /** @hide */
    private static final int UPLOADING_FEATURE_BITMASK = 0x08;
    private static final int UPLOADING_FEATURE_BITMASK = 0x08;


    /** Parameters in setMessageStatus */
    /*
     * UNREAD, READ, UNDELETED, DELETED are passed as parameters
     * to setMessageStatus to indicate the messages new state.
     */

    /** @hide */
    public static final int UNREAD = 0;
    public static final int UNREAD = 0;
    /** @hide */
    public static final int READ = 1;
    public static final int READ = 1;
    /** @hide */
    public static final int UNDELETED = 2;
    public static final int UNDELETED = 2;
    /** @hide */
    public static final int DELETED = 3;
    public static final int DELETED = 3;


    private BluetoothAdapter mAdapter;
    private BluetoothAdapter mAdapter;
@@ -132,19 +171,12 @@ public final class BluetoothMapClient implements BluetoothProfile {
        mProfileConnector.connect(context, listener);
        mProfileConnector.connect(context, listener);
    }
    }


    protected void finalize() throws Throwable {
        try {
            close();
        } finally {
            super.finalize();
        }
    }

    /**
    /**
     * Close the connection to the backing service.
     * Close the connection to the backing service.
     * Other public functions of BluetoothMap will return default error
     * Other public functions of BluetoothMap will return default error
     * results once close() has been called. Multiple invocations of close()
     * results once close() has been called. Multiple invocations of close()
     * are ok.
     * are ok.
     * @hide
     */
     */
    public void close() {
    public void close() {
        mProfileConnector.disconnect();
        mProfileConnector.disconnect();
@@ -158,6 +190,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
     * Returns true if the specified Bluetooth device is connected.
     * Returns true if the specified Bluetooth device is connected.
     * Returns false if not connected, or if this proxy object is not
     * Returns false if not connected, or if this proxy object is not
     * currently connected to the Map service.
     * currently connected to the Map service.
     * @hide
     */
     */
    public boolean isConnected(BluetoothDevice device) {
    public boolean isConnected(BluetoothDevice device) {
        if (VDBG) Log.d(TAG, "isConnected(" + device + ")");
        if (VDBG) Log.d(TAG, "isConnected(" + device + ")");
@@ -225,6 +258,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
     * Get the list of connected devices. Currently at most one.
     * Get the list of connected devices. Currently at most one.
     *
     *
     * @return list of connected devices
     * @return list of connected devices
     * @hide
     */
     */
    @Override
    @Override
    public List<BluetoothDevice> getConnectedDevices() {
    public List<BluetoothDevice> getConnectedDevices() {
@@ -246,6 +280,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
     * Get the list of devices matching specified states. Currently at most one.
     * Get the list of devices matching specified states. Currently at most one.
     *
     *
     * @return list of matching devices
     * @return list of matching devices
     * @hide
     */
     */
    @Override
    @Override
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
@@ -267,6 +302,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
     * Get connection state of device
     * Get connection state of device
     *
     *
     * @return device connection state
     * @return device connection state
     * @hide
     */
     */
    @Override
    @Override
    public int getConnectionState(BluetoothDevice device) {
    public int getConnectionState(BluetoothDevice device) {
@@ -377,6 +413,38 @@ public final class BluetoothMapClient implements BluetoothProfile {
        return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
        return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
    }
    }


    /**
     * Send a message.
     *
     * Send an SMS message to either the contacts primary number or the telephone number specified.
     *
     * @param device Bluetooth device
     * @param contacts Uri Collection of the contacts
     * @param message Message to be sent
     * @param sentIntent intent issued when message is sent
     * @param deliveredIntent intent issued when message is delivered
     * @return true if the message is enqueued, false on error
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.SEND_SMS)
    public boolean sendMessage(@NonNull BluetoothDevice device, @NonNull Collection<Uri> contacts,
            @NonNull String message, @Nullable PendingIntent sentIntent,
            @Nullable PendingIntent deliveredIntent) {
        if (DBG) Log.d(TAG, "sendMessage(" + device + ", " + contacts + ", " + message);
        final IBluetoothMapClient service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
            try {
                return service.sendMessage(device, contacts.toArray(new Uri[contacts.size()]),
                        message, sentIntent, deliveredIntent);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return false;
            }
        }
        return false;
    }

     /**
     /**
     * Send a message.
     * Send a message.
     *
     *
@@ -388,6 +456,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
     * @param sentIntent intent issued when message is sent
     * @param sentIntent intent issued when message is sent
     * @param deliveredIntent intent issued when message is delivered
     * @param deliveredIntent intent issued when message is delivered
     * @return true if the message is enqueued, false on error
     * @return true if the message is enqueued, false on error
     * @hide
     */
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public boolean sendMessage(BluetoothDevice device, Uri[] contacts, String message,
    public boolean sendMessage(BluetoothDevice device, Uri[] contacts, String message,
@@ -410,6 +479,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
     *
     *
     * @param device Bluetooth device
     * @param device Bluetooth device
     * @return true if the message is enqueued, false on error
     * @return true if the message is enqueued, false on error
     * @hide
     */
     */
    public boolean getUnreadMessages(BluetoothDevice device) {
    public boolean getUnreadMessages(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "getUnreadMessages(" + device + ")");
        if (DBG) Log.d(TAG, "getUnreadMessages(" + device + ")");
@@ -431,6 +501,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
     * @param device The Bluetooth device to get this value for.
     * @param device The Bluetooth device to get this value for.
     * @return Returns true if the Uploading bit value in SDP record's
     * @return Returns true if the Uploading bit value in SDP record's
     *         MapSupportedFeatures field is set. False is returned otherwise.
     *         MapSupportedFeatures field is set. False is returned otherwise.
     * @hide
     */
     */
    public boolean isUploadingSupported(BluetoothDevice device) {
    public boolean isUploadingSupported(BluetoothDevice device) {
        final IBluetoothMapClient service = getService();
        final IBluetoothMapClient service = getService();
@@ -457,7 +528,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
     *            "read", <code>UNDELETED</code> for "undeleted", <code>DELETED</code> for
     *            "read", <code>UNDELETED</code> for "undeleted", <code>DELETED</code> for
     *            "deleted", otherwise return error
     *            "deleted", otherwise return error
     * @return <code>true</code> if request has been sent, <code>false</code> on error
     * @return <code>true</code> if request has been sent, <code>false</code> on error
     *
     * @hide
     */
     */
    @RequiresPermission(Manifest.permission.READ_SMS)
    @RequiresPermission(Manifest.permission.READ_SMS)
    public boolean setMessageStatus(BluetoothDevice device, String handle, int status) {
    public boolean setMessageStatus(BluetoothDevice device, String handle, int status) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -186,6 +186,7 @@ public interface BluetoothProfile {
     *
     *
     * @hide
     * @hide
     */
     */
    @SystemApi
    int MAP_CLIENT = 18;
    int MAP_CLIENT = 18;


    /**
    /**