Merge "Modify Bluetooth Class of Device from Android stack" am: f4ec2ab706
am: c037004fd9
Change-Id: I06831c086920b93f0c1c076e255ce404769b8691
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user