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

Commit 7a990d12 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6127482 from c438b23f94684264a1e212ac8f154587d2dccb44 to rvc-release

Change-Id: I248d7fef79727218d34cbd144328074bac470dc7
parents be296f09 463b7c69
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2670,6 +2670,9 @@ public final class BluetoothAdapter {
        } else if (profile == BluetoothProfile.PAN) {
            BluetoothPan pan = new BluetoothPan(context, listener);
            return true;
        } else if (profile == BluetoothProfile.PBAP) {
            BluetoothPbap pbap = new BluetoothPbap(context, listener);
            return true;
        } else if (profile == BluetoothProfile.HEALTH) {
            Log.e(TAG, "getProfileProxy(): BluetoothHealth is deprecated");
            return false;
@@ -2742,6 +2745,10 @@ public final class BluetoothAdapter {
                BluetoothPan pan = (BluetoothPan) proxy;
                pan.close();
                break;
            case BluetoothProfile.PBAP:
                BluetoothPbap pbap = (BluetoothPbap) proxy;
                pbap.close();
                break;
            case BluetoothProfile.GATT:
                BluetoothGatt gatt = (BluetoothGatt) proxy;
                gatt.close();
+63 −0
Original line number Diff line number Diff line
@@ -16,8 +16,12 @@

package android.bluetooth;

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
@@ -36,6 +40,7 @@ import java.util.concurrent.Executor;
 */
public final class BluetoothHidDevice implements BluetoothProfile {
    private static final String TAG = BluetoothHidDevice.class.getSimpleName();
    private static final boolean DBG = false;

    /**
     * Intent used to broadcast the change in connection state of the Input Host profile.
@@ -682,4 +687,62 @@ public final class BluetoothHidDevice implements BluetoothProfile {

        return result;
    }

    /**
     * Connects Hid Device if connectionPolicy is {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED}
     * and disconnects Hid device if connectionPolicy is
     * {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN}.
     *
     * <p> The device should already be paired.
     * Connection policy can be one of:
     * {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED},
     * {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN},
     * {@link BluetoothProfile#CONNECTION_POLICY_UNKNOWN}
     *
     * @param device Paired bluetooth device
     * @param connectionPolicy determines whether hid device should be connected or disconnected
     * @return true if hid device is connected or disconnected, false otherwise
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
            @ConnectionPolicy int connectionPolicy) {
        log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
        try {
            final IBluetoothHidDevice service = getService();
            if (service != null && isEnabled()
                    && isValidDevice(device)) {
                if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
                        && connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
                    return false;
                }
                return service.setConnectionPolicy(device, connectionPolicy);
            }
            if (service == null) Log.w(TAG, "Proxy not attached to service");
            return false;
        } catch (RemoteException e) {
            Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
            return false;
        }
    }

    private boolean isEnabled() {
        if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
        return false;
    }

    private boolean isValidDevice(BluetoothDevice device) {
        if (device == null) return false;

        if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
        return false;
    }

    private static void log(String msg) {
        if (DBG) {
            Log.d(TAG, msg);
        }
    }
}
+44 −5
Original line number Diff line number Diff line
@@ -17,7 +17,10 @@
package android.bluetooth;

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
@@ -35,21 +38,35 @@ import java.util.List;
 *
 * @hide
 */
@SystemApi
public final class BluetoothMap implements BluetoothProfile {

    private static final String TAG = "BluetoothMap";
    private static final boolean DBG = true;
    private static final boolean VDBG = false;

    /** @hide */
    @SuppressLint("ActionValue")
    @SystemApi
    public static final String ACTION_CONNECTION_STATE_CHANGED =
            "android.bluetooth.map.profile.action.CONNECTION_STATE_CHANGED";

    /** 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;

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

    private BluetoothAdapter mAdapter;
@@ -71,6 +88,7 @@ public final class BluetoothMap implements BluetoothProfile {
        mProfileConnector.connect(context, listener);
    }

    @SuppressLint("GenericException")
    protected void finalize() throws Throwable {
        try {
            close();
@@ -84,6 +102,8 @@ public final class BluetoothMap implements BluetoothProfile {
     * Other public functions of BluetoothMap will return default error
     * results once close() has been called. Multiple invocations of close()
     * are ok.
     *
     * @hide
     */
    public synchronized void close() {
        mProfileConnector.disconnect();
@@ -98,6 +118,8 @@ public final class BluetoothMap implements BluetoothProfile {
     *
     * @return One of the STATE_ return codes, or STATE_ERROR if this proxy object is currently not
     * connected to the Map service.
     *
     * @hide
     */
    public int getState() {
        if (VDBG) log("getState()");
@@ -120,6 +142,8 @@ public final class BluetoothMap implements BluetoothProfile {
     *
     * @return The remote Bluetooth device, or null if not in connected or connecting state, or if
     * this proxy object is not connected to the Map service.
     *
     * @hide
     */
    public BluetoothDevice getClient() {
        if (VDBG) log("getClient()");
@@ -141,6 +165,8 @@ public final class BluetoothMap implements BluetoothProfile {
     * Returns true if the specified Bluetooth device is connected.
     * Returns false if not connected, or if this proxy object is not
     * currently connected to the Map service.
     *
     * @hide
     */
    public boolean isConnected(BluetoothDevice device) {
        if (VDBG) log("isConnected(" + device + ")");
@@ -161,6 +187,8 @@ public final class BluetoothMap implements BluetoothProfile {
    /**
     * Initiate connection. Initiation of outgoing connections is not
     * supported for MAP server.
     *
     * @hide
     */
    public boolean connect(BluetoothDevice device) {
        if (DBG) log("connect(" + device + ")" + "not supported for MAPS");
@@ -172,6 +200,8 @@ public final class BluetoothMap implements BluetoothProfile {
     *
     * @param device Remote Bluetooth Device
     * @return false on error, true otherwise
     *
     * @hide
     */
    @UnsupportedAppUsage
    public boolean disconnect(BluetoothDevice device) {
@@ -196,6 +226,8 @@ public final class BluetoothMap implements BluetoothProfile {
     * devices. It tries to err on the side of false positives.
     *
     * @return True if this device might support Map.
     *
     * @hide
     */
    public static boolean doesClassMatchSink(BluetoothClass btClass) {
        // TODO optimize the rule
@@ -214,8 +246,11 @@ public final class BluetoothMap implements BluetoothProfile {
     * Get the list of connected devices. Currently at most one.
     *
     * @return list of connected devices
     *
     * @hide
     */
    public List<BluetoothDevice> getConnectedDevices() {
    @SystemApi
    public @NonNull List<BluetoothDevice> getConnectedDevices() {
        if (DBG) log("getConnectedDevices()");
        final IBluetoothMap service = getService();
        if (service != null && isEnabled()) {
@@ -234,6 +269,8 @@ public final class BluetoothMap implements BluetoothProfile {
     * Get the list of devices matching specified states. Currently at most one.
     *
     * @return list of matching devices
     *
     * @hide
     */
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) log("getDevicesMatchingStates()");
@@ -254,6 +291,8 @@ public final class BluetoothMap implements BluetoothProfile {
     * Get connection state of device
     *
     * @return device connection state
     *
     * @hide
     */
    public int getConnectionState(BluetoothDevice device) {
        if (DBG) log("getConnectionState(" + device + ")");
@@ -301,7 +340,7 @@ public final class BluetoothMap implements BluetoothProfile {
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
    public boolean setConnectionPolicy(@Nullable BluetoothDevice device, int connectionPolicy) {
        if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
        final IBluetoothMap service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
@@ -349,7 +388,7 @@ public final class BluetoothMap implements BluetoothProfile {
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public int getConnectionPolicy(BluetoothDevice device) {
    public int getConnectionPolicy(@Nullable BluetoothDevice device) {
        if (VDBG) log("getConnectionPolicy(" + device + ")");
        final IBluetoothMap service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
+37 −0
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package android.bluetooth;

import android.Manifest;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
@@ -255,6 +257,41 @@ public final class BluetoothPan implements BluetoothProfile {
        return false;
    }

    /**
     * Set connection policy of the profile
     *
     * <p> The device should already be paired.
     * Connection policy can be one of {@link #CONNECTION_POLICY_ALLOWED},
     * {@link #CONNECTION_POLICY_FORBIDDEN}, {@link #CONNECTION_POLICY_UNKNOWN}
     *
     * @param device Paired bluetooth device
     * @param connectionPolicy is the connection policy to set to for this profile
     * @return true if connectionPolicy is set, false on error
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
            @ConnectionPolicy int connectionPolicy) {
        if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
        try {
            final IBluetoothPan service = getService();
            if (service != null && isEnabled()
                    && isValidDevice(device)) {
                if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
                        && connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
                    return false;
                }
                return service.setConnectionPolicy(device, connectionPolicy);
            }
            if (service == null) Log.w(TAG, "Proxy not attached to service");
            return false;
        } catch (RemoteException e) {
            Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
            return false;
        }
    }

    /**
     * {@inheritDoc}
     */
+3 −3
Original line number Diff line number Diff line
@@ -274,15 +274,15 @@ public class BluetoothPbap implements BluetoothProfile {
    }

    /**
     * Pbap does not store connection policy, so this function only disconnects Pbap if
     * connectionPolicy is CONNECTION_POLICY_FORBIDDEN.
     * Pbap does not store connection policy, so this function only disconnects pbap if
     * connectionPolicy is {@link #CONNECTION_POLICY_FORBIDDEN}.
     *
     * <p> The device should already be paired.
     * Connection policy can be one of {@link #CONNECTION_POLICY_ALLOWED},
     * {@link #CONNECTION_POLICY_FORBIDDEN}, {@link #CONNECTION_POLICY_UNKNOWN}
     *
     * @param device Paired bluetooth device
     * @param connectionPolicy is the connection policy to set to for this profile
     * @param connectionPolicy determines whether to disconnect the device
     * @return true if pbap is successfully disconnected, false otherwise
     * @hide
     */