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

Commit c037004f authored by Pulkit Bhuwalka's avatar Pulkit Bhuwalka Committed by android-build-merger
Browse files

Merge "Modify Bluetooth Class of Device from Android stack"

am: f4ec2ab7

Change-Id: I9a0b06f44d2fe7be343fc38ce240d82f1b309d7d
parents 53eb9d35 f4ec2ab7
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -1133,6 +1133,29 @@ public final class BluetoothAdapter {
        return false;
    }

    /**
     * Sets the {@link BluetoothClass} Bluetooth Class of Device (CoD) of
     * the local Bluetooth adapter.
     *
     * @param bluetoothClass {@link BluetoothClass} to set the local Bluetooth adapter to.
     * @return true if successful, false if unsuccessful.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean setBluetoothClass(BluetoothClass bluetoothClass) {
        if (getState() != STATE_ON) return false;
        try {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.setBluetoothClass(bluetoothClass);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        return false;
    }

    /**
     * Get the current Bluetooth scan mode of the local Bluetooth adapter.
     * <p>The Bluetooth scan mode determines if the local adapter is
+46 −0
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@ package android.bluetooth;
import android.os.Parcel;
import android.os.Parcelable;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

/**
 * Represents a Bluetooth class, which describes general characteristics
 * and capabilities of a device. For example, a Bluetooth class will
@@ -275,6 +279,48 @@ public final class BluetoothClass implements Parcelable {
        return (mClass & Device.BITMASK);
    }

    /**
     * Return the Bluetooth Class of Device (CoD) value including the
     * {@link BluetoothClass.Service}, {@link BluetoothClass.Device.Major} and
     * minor device fields.
     *
     * <p>This value is an integer representation of Bluetooth CoD as in
     * Bluetooth specification.
     *
     * @see <a href="Bluetooth CoD">https://www.bluetooth.com/specifications/assigned-numbers/baseband</a>
     *
     * @hide
     */
    public int getClassOfDevice() {
        return mClass;
    }

    /**
     * Return the Bluetooth Class of Device (CoD) value including the
     * {@link BluetoothClass.Service}, {@link BluetoothClass.Device.Major} and
     * minor device fields.
     *
     * <p>This value is a byte array representation of Bluetooth CoD as in
     * Bluetooth specification.
     *
     * <p>Bluetooth COD information is 3 bytes, but stored as an int. Hence the
     * MSB is useless and needs to be thrown away. The lower 3 bytes are
     * converted into a byte array MSB to LSB. Hence, using BIG_ENDIAN.
     *
     * @see <a href="Bluetooth CoD">https://www.bluetooth.com/specifications/assigned-numbers/baseband</a>
     *
     * @hide
     */
    public byte[] getClassOfDeviceBytes() {
        byte[] bytes = ByteBuffer.allocate(4)
                .order(ByteOrder.BIG_ENDIAN)
                .putInt(mClass)
                .array();

        // Discard the top byte
        return Arrays.copyOfRange(bytes, 1, bytes.length);
    }

    /** @hide */
    public static final int PROFILE_HEADSET = 0;
    /** @hide */