Merge "Modify Bluetooth Class of Device from Android stack" am: f4ec2ab706 am: c037004fd9
am: 69da7a1766
Change-Id: I5815862db057bf1925bfa9482a451aa0ac3b08ad
This commit is contained in:
@@ -1133,6 +1133,29 @@ public final class BluetoothAdapter {
|
|||||||
return false;
|
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.
|
* Get the current Bluetooth scan mode of the local Bluetooth adapter.
|
||||||
* <p>The Bluetooth scan mode determines if the local adapter is
|
* <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.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Bluetooth class, which describes general characteristics
|
* Represents a Bluetooth class, which describes general characteristics
|
||||||
* and capabilities of a device. For example, a Bluetooth class will
|
* 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 (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 */
|
/** @hide */
|
||||||
public static final int PROFILE_HEADSET = 0;
|
public static final int PROFILE_HEADSET = 0;
|
||||||
/** @hide */
|
/** @hide */
|
||||||
|
|||||||
Reference in New Issue
Block a user