Merge "HIDD: Address API Review concerns"
am: 8085d6f247
Change-Id: I7f4e272657874b02d122f7ddc291c0f006eeee30
This commit is contained in:
@@ -7922,7 +7922,7 @@ package android.bluetooth {
|
||||
method public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
|
||||
method public int getConnectionState(android.bluetooth.BluetoothDevice);
|
||||
method public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(int[]);
|
||||
method public boolean registerApp(android.bluetooth.BluetoothHidDeviceAppSdpSettings, android.bluetooth.BluetoothHidDeviceAppQosSettings, android.bluetooth.BluetoothHidDeviceAppQosSettings, android.bluetooth.BluetoothHidDeviceCallback);
|
||||
method public boolean registerApp(android.bluetooth.BluetoothHidDeviceAppSdpSettings, android.bluetooth.BluetoothHidDeviceAppQosSettings, android.bluetooth.BluetoothHidDeviceAppQosSettings, java.util.concurrent.Executor, android.bluetooth.BluetoothHidDevice.Callback);
|
||||
method public boolean replyReport(android.bluetooth.BluetoothDevice, byte, byte, byte[]);
|
||||
method public boolean reportError(android.bluetooth.BluetoothDevice, byte);
|
||||
method public boolean sendReport(android.bluetooth.BluetoothDevice, int, byte[]);
|
||||
@@ -7952,49 +7952,8 @@ package android.bluetooth {
|
||||
field public static final byte SUBCLASS2_UNCATEGORIZED = 0; // 0x0
|
||||
}
|
||||
|
||||
public final class BluetoothHidDeviceAppQosSettings implements android.os.Parcelable {
|
||||
ctor public BluetoothHidDeviceAppQosSettings(int, int, int, int, int, int);
|
||||
method public int describeContents();
|
||||
method public int[] toArray();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothHidDeviceAppQosSettings> CREATOR;
|
||||
field public static final int MAX = -1; // 0xffffffff
|
||||
field public static final int SERVICE_BEST_EFFORT = 1; // 0x1
|
||||
field public static final int SERVICE_GUARANTEED = 2; // 0x2
|
||||
field public static final int SERVICE_NO_TRAFFIC = 0; // 0x0
|
||||
field public final int delayVariation;
|
||||
field public final int latency;
|
||||
field public final int peakBandwidth;
|
||||
field public final int serviceType;
|
||||
field public final int tokenBucketSize;
|
||||
field public final int tokenRate;
|
||||
}
|
||||
|
||||
public static class BluetoothHidDeviceAppQosSettings.Builder {
|
||||
ctor public BluetoothHidDeviceAppQosSettings.Builder();
|
||||
method public android.bluetooth.BluetoothHidDeviceAppQosSettings build();
|
||||
method public android.bluetooth.BluetoothHidDeviceAppQosSettings.Builder delayVariation(int);
|
||||
method public android.bluetooth.BluetoothHidDeviceAppQosSettings.Builder latency(int);
|
||||
method public android.bluetooth.BluetoothHidDeviceAppQosSettings.Builder peakBandwidth(int);
|
||||
method public android.bluetooth.BluetoothHidDeviceAppQosSettings.Builder serviceType(int);
|
||||
method public android.bluetooth.BluetoothHidDeviceAppQosSettings.Builder tokenBucketSize(int);
|
||||
method public android.bluetooth.BluetoothHidDeviceAppQosSettings.Builder tokenRate(int);
|
||||
}
|
||||
|
||||
public final class BluetoothHidDeviceAppSdpSettings implements android.os.Parcelable {
|
||||
ctor public BluetoothHidDeviceAppSdpSettings(java.lang.String, java.lang.String, java.lang.String, byte, byte[]);
|
||||
method public int describeContents();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothHidDeviceAppSdpSettings> CREATOR;
|
||||
field public final java.lang.String description;
|
||||
field public final byte[] descriptors;
|
||||
field public final java.lang.String name;
|
||||
field public final java.lang.String provider;
|
||||
field public final byte subclass;
|
||||
}
|
||||
|
||||
public abstract class BluetoothHidDeviceCallback {
|
||||
ctor public BluetoothHidDeviceCallback();
|
||||
public static abstract class BluetoothHidDevice.Callback {
|
||||
ctor public BluetoothHidDevice.Callback();
|
||||
method public void onAppStatusChanged(android.bluetooth.BluetoothDevice, boolean);
|
||||
method public void onConnectionStateChanged(android.bluetooth.BluetoothDevice, int);
|
||||
method public void onGetReport(android.bluetooth.BluetoothDevice, byte, byte, int);
|
||||
@@ -8004,6 +7963,35 @@ package android.bluetooth {
|
||||
method public void onVirtualCableUnplug(android.bluetooth.BluetoothDevice);
|
||||
}
|
||||
|
||||
public final class BluetoothHidDeviceAppQosSettings implements android.os.Parcelable {
|
||||
ctor public BluetoothHidDeviceAppQosSettings(int, int, int, int, int, int);
|
||||
method public int describeContents();
|
||||
method public int getDelayVariation();
|
||||
method public int getLatency();
|
||||
method public int getPeakBandwidth();
|
||||
method public int getServiceType();
|
||||
method public int getTokenBucketSize();
|
||||
method public int getTokenRate();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothHidDeviceAppQosSettings> CREATOR;
|
||||
field public static final int MAX = -1; // 0xffffffff
|
||||
field public static final int SERVICE_BEST_EFFORT = 1; // 0x1
|
||||
field public static final int SERVICE_GUARANTEED = 2; // 0x2
|
||||
field public static final int SERVICE_NO_TRAFFIC = 0; // 0x0
|
||||
}
|
||||
|
||||
public final class BluetoothHidDeviceAppSdpSettings implements android.os.Parcelable {
|
||||
ctor public BluetoothHidDeviceAppSdpSettings(java.lang.String, java.lang.String, java.lang.String, byte, byte[]);
|
||||
method public int describeContents();
|
||||
method public java.lang.String getDescription();
|
||||
method public byte[] getDescriptors();
|
||||
method public java.lang.String getName();
|
||||
method public java.lang.String getProvider();
|
||||
method public byte getSubclass();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothHidDeviceAppSdpSettings> CREATOR;
|
||||
}
|
||||
|
||||
public final class BluetoothManager {
|
||||
method public android.bluetooth.BluetoothAdapter getAdapter();
|
||||
method public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices(int);
|
||||
|
||||
@@ -27,8 +27,8 @@ import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Provides the public APIs to control the Bluetooth HID Device profile.
|
||||
@@ -37,7 +37,6 @@ import java.util.List;
|
||||
* Use {@link BluetoothAdapter#getProfileProxy} to get the BluetoothHidDevice proxy object.
|
||||
*/
|
||||
public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
|
||||
private static final String TAG = BluetoothHidDevice.class.getSimpleName();
|
||||
|
||||
/**
|
||||
@@ -62,106 +61,327 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
"android.bluetooth.hiddevice.profile.action.CONNECTION_STATE_CHANGED";
|
||||
|
||||
/**
|
||||
* Constants representing device subclass.
|
||||
* Constant representing unspecified HID device subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceCallback)
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS1_NONE = (byte) 0x00;
|
||||
/**
|
||||
* Constant representing keyboard subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS1_KEYBOARD = (byte) 0x40;
|
||||
/**
|
||||
* Constant representing mouse subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS1_MOUSE = (byte) 0x80;
|
||||
/**
|
||||
* Constant representing combo keyboard and mouse subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS1_COMBO = (byte) 0xC0;
|
||||
|
||||
/**
|
||||
* Constant representing uncategorized HID device subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS2_UNCATEGORIZED = (byte) 0x00;
|
||||
/**
|
||||
* Constant representing joystick subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS2_JOYSTICK = (byte) 0x01;
|
||||
/**
|
||||
* Constant representing gamepad subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS2_GAMEPAD = (byte) 0x02;
|
||||
/**
|
||||
* Constant representing remote control subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS2_REMOTE_CONTROL = (byte) 0x03;
|
||||
/**
|
||||
* Constant representing sensing device subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS2_SENSING_DEVICE = (byte) 0x04;
|
||||
/**
|
||||
* Constant representing digitizer tablet subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS2_DIGITIZER_TABLET = (byte) 0x05;
|
||||
/**
|
||||
* Constant representing card reader subclass.
|
||||
*
|
||||
* @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)
|
||||
*/
|
||||
public static final byte SUBCLASS2_CARD_READER = (byte) 0x06;
|
||||
|
||||
/**
|
||||
* Constants representing report types.
|
||||
* Constant representing HID Input Report type.
|
||||
*
|
||||
* @see BluetoothHidDeviceCallback#onGetReport(BluetoothDevice, byte, byte, int)
|
||||
* @see BluetoothHidDeviceCallback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
* @see BluetoothHidDeviceCallback#onInterruptData(BluetoothDevice, byte, byte[])
|
||||
* @see Callback#onGetReport(BluetoothDevice, byte, byte, int)
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
* @see Callback#onInterruptData(BluetoothDevice, byte, byte[])
|
||||
*/
|
||||
public static final byte REPORT_TYPE_INPUT = (byte) 1;
|
||||
/**
|
||||
* Constant representing HID Output Report type.
|
||||
*
|
||||
* @see Callback#onGetReport(BluetoothDevice, byte, byte, int)
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
* @see Callback#onInterruptData(BluetoothDevice, byte, byte[])
|
||||
*/
|
||||
public static final byte REPORT_TYPE_OUTPUT = (byte) 2;
|
||||
/**
|
||||
* Constant representing HID Feature Report type.
|
||||
*
|
||||
* @see Callback#onGetReport(BluetoothDevice, byte, byte, int)
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
* @see Callback#onInterruptData(BluetoothDevice, byte, byte[])
|
||||
*/
|
||||
public static final byte REPORT_TYPE_FEATURE = (byte) 3;
|
||||
|
||||
/**
|
||||
* Constants representing error response for Set Report.
|
||||
* Constant representing success response for Set Report.
|
||||
*
|
||||
* @see BluetoothHidDeviceCallback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
*/
|
||||
public static final byte ERROR_RSP_SUCCESS = (byte) 0;
|
||||
/**
|
||||
* Constant representing error response for Set Report due to "not ready".
|
||||
*
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
*/
|
||||
public static final byte ERROR_RSP_NOT_READY = (byte) 1;
|
||||
/**
|
||||
* Constant representing error response for Set Report due to "invalid report ID".
|
||||
*
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
*/
|
||||
public static final byte ERROR_RSP_INVALID_RPT_ID = (byte) 2;
|
||||
/**
|
||||
* Constant representing error response for Set Report due to "unsupported request".
|
||||
*
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
*/
|
||||
public static final byte ERROR_RSP_UNSUPPORTED_REQ = (byte) 3;
|
||||
/**
|
||||
* Constant representing error response for Set Report due to "invalid parameter".
|
||||
*
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
*/
|
||||
public static final byte ERROR_RSP_INVALID_PARAM = (byte) 4;
|
||||
/**
|
||||
* Constant representing error response for Set Report with unknown reason.
|
||||
*
|
||||
* @see Callback#onSetReport(BluetoothDevice, byte, byte, byte[])
|
||||
*/
|
||||
public static final byte ERROR_RSP_UNKNOWN = (byte) 14;
|
||||
|
||||
/**
|
||||
* Constants representing protocol mode used set by host. Default is always {@link
|
||||
* Constant representing boot protocol mode used set by host. Default is always {@link
|
||||
* #PROTOCOL_REPORT_MODE} unless notified otherwise.
|
||||
*
|
||||
* @see BluetoothHidDeviceCallback#onSetProtocol(BluetoothDevice, byte)
|
||||
* @see Callback#onSetProtocol(BluetoothDevice, byte)
|
||||
*/
|
||||
public static final byte PROTOCOL_BOOT_MODE = (byte) 0;
|
||||
/**
|
||||
* Constant representing report protocol mode used set by host. Default is always {@link
|
||||
* #PROTOCOL_REPORT_MODE} unless notified otherwise.
|
||||
*
|
||||
* @see Callback#onSetProtocol(BluetoothDevice, byte)
|
||||
*/
|
||||
public static final byte PROTOCOL_REPORT_MODE = (byte) 1;
|
||||
|
||||
/**
|
||||
* The template class that applications use to call callback functions on events from the HID
|
||||
* host. Callback functions are wrapped in this class and registered to the Android system
|
||||
* during app registration.
|
||||
*/
|
||||
public abstract static class Callback {
|
||||
|
||||
private static final String TAG = "BluetoothHidDevCallback";
|
||||
|
||||
/**
|
||||
* Callback called when application registration state changes. Usually it's called due to
|
||||
* either {@link BluetoothHidDevice#registerApp (String, String, String, byte, byte[],
|
||||
* Executor, Callback)} or {@link BluetoothHidDevice#unregisterApp()} , but can be also
|
||||
* unsolicited in case e.g. Bluetooth was turned off in which case application is
|
||||
* unregistered automatically.
|
||||
*
|
||||
* @param pluggedDevice {@link BluetoothDevice} object which represents host that currently
|
||||
* has Virtual Cable established with device. Only valid when application is registered,
|
||||
* can be <code>null</code>.
|
||||
* @param registered <code>true</code> if application is registered, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public void onAppStatusChanged(BluetoothDevice pluggedDevice, boolean registered) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"onAppStatusChanged: pluggedDevice="
|
||||
+ pluggedDevice
|
||||
+ " registered="
|
||||
+ registered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when connection state with remote host was changed. Application can
|
||||
* assume than Virtual Cable is established when called with {@link
|
||||
* BluetoothProfile#STATE_CONNECTED} <code>state</code>.
|
||||
*
|
||||
* @param device {@link BluetoothDevice} object representing host device which connection
|
||||
* state was changed.
|
||||
* @param state Connection state as defined in {@link BluetoothProfile}.
|
||||
*/
|
||||
public void onConnectionStateChanged(BluetoothDevice device, int state) {
|
||||
Log.d(TAG, "onConnectionStateChanged: device=" + device + " state=" + state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when GET_REPORT is received from remote host. Should be replied by
|
||||
* application using {@link BluetoothHidDevice#replyReport(BluetoothDevice, byte, byte,
|
||||
* byte[])}.
|
||||
*
|
||||
* @param type Requested Report Type.
|
||||
* @param id Requested Report Id, can be 0 if no Report Id are defined in descriptor.
|
||||
* @param bufferSize Requested buffer size, application shall respond with at least given
|
||||
* number of bytes.
|
||||
*/
|
||||
public void onGetReport(BluetoothDevice device, byte type, byte id, int bufferSize) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"onGetReport: device="
|
||||
+ device
|
||||
+ " type="
|
||||
+ type
|
||||
+ " id="
|
||||
+ id
|
||||
+ " bufferSize="
|
||||
+ bufferSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when SET_REPORT is received from remote host. In case received data are
|
||||
* invalid, application shall respond with {@link
|
||||
* BluetoothHidDevice#reportError(BluetoothDevice, byte)}.
|
||||
*
|
||||
* @param type Report Type.
|
||||
* @param id Report Id.
|
||||
* @param data Report data.
|
||||
*/
|
||||
public void onSetReport(BluetoothDevice device, byte type, byte id, byte[] data) {
|
||||
Log.d(TAG, "onSetReport: device=" + device + " type=" + type + " id=" + id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when SET_PROTOCOL is received from remote host. Application shall use
|
||||
* this information to send only reports valid for given protocol mode. By default, {@link
|
||||
* BluetoothHidDevice#PROTOCOL_REPORT_MODE} shall be assumed.
|
||||
*
|
||||
* @param protocol Protocol Mode.
|
||||
*/
|
||||
public void onSetProtocol(BluetoothDevice device, byte protocol) {
|
||||
Log.d(TAG, "onSetProtocol: device=" + device + " protocol=" + protocol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when report data is received over interrupt channel. Report Type is
|
||||
* assumed to be {@link BluetoothHidDevice#REPORT_TYPE_OUTPUT}.
|
||||
*
|
||||
* @param reportId Report Id.
|
||||
* @param data Report data.
|
||||
*/
|
||||
public void onInterruptData(BluetoothDevice device, byte reportId, byte[] data) {
|
||||
Log.d(TAG, "onInterruptData: device=" + device + " reportId=" + reportId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when Virtual Cable is removed. After this callback is received connection
|
||||
* will be disconnected automatically.
|
||||
*/
|
||||
public void onVirtualCableUnplug(BluetoothDevice device) {
|
||||
Log.d(TAG, "onVirtualCableUnplug: device=" + device);
|
||||
}
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private ServiceListener mServiceListener;
|
||||
|
||||
private volatile IBluetoothHidDevice mService;
|
||||
|
||||
private BluetoothAdapter mAdapter;
|
||||
|
||||
private static class BluetoothHidDeviceCallbackWrapper
|
||||
extends IBluetoothHidDeviceCallback.Stub {
|
||||
private static class CallbackWrapper extends IBluetoothHidDeviceCallback.Stub {
|
||||
|
||||
private BluetoothHidDeviceCallback mCallback;
|
||||
private final Executor mExecutor;
|
||||
private final Callback mCallback;
|
||||
|
||||
public BluetoothHidDeviceCallbackWrapper(BluetoothHidDeviceCallback callback) {
|
||||
CallbackWrapper(Executor executor, Callback callback) {
|
||||
mExecutor = executor;
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppStatusChanged(BluetoothDevice pluggedDevice, boolean registered) {
|
||||
mCallback.onAppStatusChanged(pluggedDevice, registered);
|
||||
clearCallingIdentity();
|
||||
mExecutor.execute(() -> mCallback.onAppStatusChanged(pluggedDevice, registered));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionStateChanged(BluetoothDevice device, int state) {
|
||||
mCallback.onConnectionStateChanged(device, state);
|
||||
clearCallingIdentity();
|
||||
mExecutor.execute(() -> mCallback.onConnectionStateChanged(device, state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetReport(BluetoothDevice device, byte type, byte id, int bufferSize) {
|
||||
mCallback.onGetReport(device, type, id, bufferSize);
|
||||
clearCallingIdentity();
|
||||
mExecutor.execute(() -> mCallback.onGetReport(device, type, id, bufferSize));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetReport(BluetoothDevice device, byte type, byte id, byte[] data) {
|
||||
mCallback.onSetReport(device, type, id, data);
|
||||
clearCallingIdentity();
|
||||
mExecutor.execute(() -> mCallback.onSetReport(device, type, id, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetProtocol(BluetoothDevice device, byte protocol) {
|
||||
mCallback.onSetProtocol(device, protocol);
|
||||
clearCallingIdentity();
|
||||
mExecutor.execute(() -> mCallback.onSetProtocol(device, protocol));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterruptData(BluetoothDevice device, byte reportId, byte[] data) {
|
||||
mCallback.onInterruptData(device, reportId, data);
|
||||
clearCallingIdentity();
|
||||
mExecutor.execute(() -> mCallback.onInterruptData(device, reportId, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVirtualCableUnplug(BluetoothDevice device) {
|
||||
mCallback.onVirtualCableUnplug(device);
|
||||
clearCallingIdentity();
|
||||
mExecutor.execute(() -> mCallback.onVirtualCableUnplug(device));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,8 +433,6 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
};
|
||||
|
||||
BluetoothHidDevice(Context context, ServiceListener listener) {
|
||||
Log.v(TAG, "BluetoothHidDevice");
|
||||
|
||||
mContext = context;
|
||||
mServiceListener = listener;
|
||||
mAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
@@ -245,7 +463,6 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
}
|
||||
|
||||
void doUnbind() {
|
||||
Log.d(TAG, "Unbinding HidDevService");
|
||||
if (mService != null) {
|
||||
mService = null;
|
||||
try {
|
||||
@@ -257,8 +474,6 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
}
|
||||
|
||||
void close() {
|
||||
Log.v(TAG, "close()");
|
||||
|
||||
IBluetoothManager mgr = mAdapter.getBluetoothManager();
|
||||
if (mgr != null) {
|
||||
try {
|
||||
@@ -277,8 +492,6 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public List<BluetoothDevice> getConnectedDevices() {
|
||||
Log.v(TAG, "getConnectedDevices()");
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
if (service != null) {
|
||||
try {
|
||||
@@ -290,14 +503,12 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
Log.w(TAG, "Proxy not attached to service");
|
||||
}
|
||||
|
||||
return new ArrayList<BluetoothDevice>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
|
||||
Log.v(TAG, "getDevicesMatchingConnectionStates(): states=" + Arrays.toString(states));
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
if (service != null) {
|
||||
try {
|
||||
@@ -309,14 +520,12 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
Log.w(TAG, "Proxy not attached to service");
|
||||
}
|
||||
|
||||
return new ArrayList<BluetoothDevice>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int getConnectionState(BluetoothDevice device) {
|
||||
Log.v(TAG, "getConnectionState(): device=" + device);
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
if (service != null) {
|
||||
try {
|
||||
@@ -336,9 +545,9 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
* when application is registered. Only one application can be registered at one time. When an
|
||||
* application is registered, the HID Host service will be disabled until it is unregistered.
|
||||
* When no longer used, application should be unregistered using {@link #unregisterApp()}. The
|
||||
* registration status should be tracked by the application by handling callback from
|
||||
* BluetoothHidDeviceCallback#onAppStatusChanged. The app registration status is not related to
|
||||
* the return value of this method.
|
||||
* app will be automatically unregistered if it is not foreground. The registration status
|
||||
* should be tracked by the application by handling callback from Callback#onAppStatusChanged.
|
||||
* The app registration status is not related to the return value of this method.
|
||||
*
|
||||
* @param sdp {@link BluetoothHidDeviceAppSdpSettings} object of HID Device SDP record. The HID
|
||||
* Device SDP record is required.
|
||||
@@ -348,27 +557,36 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
* @param outQos {@link BluetoothHidDeviceAppQosSettings} object of Outgoing QoS Settings. The
|
||||
* Outgoing QoS Settings is not required. Use null or default
|
||||
* BluetoothHidDeviceAppQosSettings.Builder for default values.
|
||||
* @param callback {@link BluetoothHidDeviceCallback} object to which callback messages will be
|
||||
* sent. The BluetoothHidDeviceCallback object is required.
|
||||
* @param executor {@link Executor} object on which callback will be executed. The Executor
|
||||
* object is required.
|
||||
* @param callback {@link Callback} object to which callback messages will be sent. The Callback
|
||||
* object is required.
|
||||
* @return true if the command is successfully sent; otherwise false.
|
||||
*/
|
||||
public boolean registerApp(BluetoothHidDeviceAppSdpSettings sdp,
|
||||
BluetoothHidDeviceAppQosSettings inQos, BluetoothHidDeviceAppQosSettings outQos,
|
||||
BluetoothHidDeviceCallback callback) {
|
||||
Log.v(TAG, "registerApp(): sdp=" + sdp + " inQos=" + inQos + " outQos=" + outQos
|
||||
+ " callback=" + callback);
|
||||
|
||||
public boolean registerApp(
|
||||
BluetoothHidDeviceAppSdpSettings sdp,
|
||||
BluetoothHidDeviceAppQosSettings inQos,
|
||||
BluetoothHidDeviceAppQosSettings outQos,
|
||||
Executor executor,
|
||||
Callback callback) {
|
||||
boolean result = false;
|
||||
|
||||
if (sdp == null || callback == null) {
|
||||
return false;
|
||||
if (sdp == null) {
|
||||
throw new IllegalArgumentException("sdp parameter cannot be null");
|
||||
}
|
||||
|
||||
if (executor == null) {
|
||||
throw new IllegalArgumentException("executor parameter cannot be null");
|
||||
}
|
||||
|
||||
if (callback == null) {
|
||||
throw new IllegalArgumentException("callback parameter cannot be null");
|
||||
}
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
if (service != null) {
|
||||
try {
|
||||
BluetoothHidDeviceCallbackWrapper cbw =
|
||||
new BluetoothHidDeviceCallbackWrapper(callback);
|
||||
CallbackWrapper cbw = new CallbackWrapper(executor, callback);
|
||||
result = service.registerApp(sdp, inQos, outQos, cbw);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
@@ -384,16 +602,13 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
* Unregisters application. Active connection will be disconnected and no new connections will
|
||||
* be allowed until registered again using {@link #registerApp
|
||||
* (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings,
|
||||
* BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceCallback)} The registration status should
|
||||
* be tracked by the application by handling callback from
|
||||
* BluetoothHidDeviceCallback#onAppStatusChanged. The app registration status is not related to
|
||||
* the return value of this method.
|
||||
* BluetoothHidDeviceAppQosSettings, Executor, Callback)}. The registration status should be
|
||||
* tracked by the application by handling callback from Callback#onAppStatusChanged. The app
|
||||
* registration status is not related to the return value of this method.
|
||||
*
|
||||
* @return true if the command is successfully sent; otherwise false.
|
||||
*/
|
||||
public boolean unregisterApp() {
|
||||
Log.v(TAG, "unregisterApp()");
|
||||
|
||||
boolean result = false;
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
@@ -437,7 +652,7 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
|
||||
/**
|
||||
* Sends report to remote host as reply for GET_REPORT request from {@link
|
||||
* BluetoothHidDeviceCallback#onGetReport(BluetoothDevice, byte, byte, int)}.
|
||||
* Callback#onGetReport(BluetoothDevice, byte, byte, int)}.
|
||||
*
|
||||
* @param type Report Type, as in request.
|
||||
* @param id Report Id, as in request.
|
||||
@@ -445,8 +660,6 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
* @return true if the command is successfully sent; otherwise false.
|
||||
*/
|
||||
public boolean replyReport(BluetoothDevice device, byte type, byte id, byte[] data) {
|
||||
Log.v(TAG, "replyReport(): device=" + device + " type=" + type + " id=" + id);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
@@ -465,14 +678,12 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
|
||||
/**
|
||||
* Sends error handshake message as reply for invalid SET_REPORT request from {@link
|
||||
* BluetoothHidDeviceCallback#onSetReport(BluetoothDevice, byte, byte, byte[])}.
|
||||
* Callback#onSetReport(BluetoothDevice, byte, byte, byte[])}.
|
||||
*
|
||||
* @param error Error to be sent for SET_REPORT via HANDSHAKE.
|
||||
* @return true if the command is successfully sent; otherwise false.
|
||||
*/
|
||||
public boolean reportError(BluetoothDevice device, byte error) {
|
||||
Log.v(TAG, "reportError(): device=" + device + " error=" + error);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
@@ -496,8 +707,6 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
* {@hide}
|
||||
*/
|
||||
public boolean unplug(BluetoothDevice device) {
|
||||
Log.v(TAG, "unplug(): device=" + device);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
@@ -517,15 +726,12 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
/**
|
||||
* Initiates connection to host which is currently paired with this device. If the application
|
||||
* is not registered, #connect(BluetoothDevice) will fail. The connection state should be
|
||||
* tracked by the application by handling callback from
|
||||
* BluetoothHidDeviceCallback#onConnectionStateChanged. The connection state is not related to
|
||||
* the return value of this method.
|
||||
* tracked by the application by handling callback from Callback#onConnectionStateChanged. The
|
||||
* connection state is not related to the return value of this method.
|
||||
*
|
||||
* @return true if the command is successfully sent; otherwise false.
|
||||
*/
|
||||
public boolean connect(BluetoothDevice device) {
|
||||
Log.v(TAG, "connect(): device=" + device);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
@@ -544,14 +750,12 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
|
||||
/**
|
||||
* Disconnects from currently connected host. The connection state should be tracked by the
|
||||
* application by handling callback from BluetoothHidDeviceCallback#onConnectionStateChanged.
|
||||
* The connection state is not related to the return value of this method.
|
||||
* application by handling callback from Callback#onConnectionStateChanged. The connection state
|
||||
* is not related to the return value of this method.
|
||||
*
|
||||
* @return true if the command is successfully sent; otherwise false.
|
||||
*/
|
||||
public boolean disconnect(BluetoothDevice device) {
|
||||
Log.v(TAG, "disconnect(): device=" + device);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
final IBluetoothHidDevice service = mService;
|
||||
|
||||
@@ -29,12 +29,12 @@ import android.os.Parcelable;
|
||||
*/
|
||||
public final class BluetoothHidDeviceAppQosSettings implements Parcelable {
|
||||
|
||||
public final int serviceType;
|
||||
public final int tokenRate;
|
||||
public final int tokenBucketSize;
|
||||
public final int peakBandwidth;
|
||||
public final int latency;
|
||||
public final int delayVariation;
|
||||
private final int mServiceType;
|
||||
private final int mTokenRate;
|
||||
private final int mTokenBucketSize;
|
||||
private final int mPeakBandwidth;
|
||||
private final int mLatency;
|
||||
private final int mDelayVariation;
|
||||
|
||||
public static final int SERVICE_NO_TRAFFIC = 0x00;
|
||||
public static final int SERVICE_BEST_EFFORT = 0x01;
|
||||
@@ -44,38 +44,53 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable {
|
||||
|
||||
/**
|
||||
* Create a BluetoothHidDeviceAppQosSettings object for the Bluetooth L2CAP channel. The QoS
|
||||
* Settings is optional. Recommended to use BluetoothHidDeviceAppQosSettings.Builder.
|
||||
* Please refer to Bluetooth HID Specfication v1.1.1 Section 5.2 and Appendix D for parameters.
|
||||
* Settings is optional. Please refer to Bluetooth HID Specfication v1.1.1 Section 5.2 and
|
||||
* Appendix D for parameters.
|
||||
*
|
||||
* @param serviceType L2CAP service type
|
||||
* @param tokenRate L2CAP token rate
|
||||
* @param tokenBucketSize L2CAP token bucket size
|
||||
* @param peakBandwidth L2CAP peak bandwidth
|
||||
* @param latency L2CAP latency
|
||||
* @param delayVariation L2CAP delay variation
|
||||
* @param serviceType L2CAP service type, default = SERVICE_BEST_EFFORT
|
||||
* @param tokenRate L2CAP token rate, default = 0
|
||||
* @param tokenBucketSize L2CAP token bucket size, default = 0
|
||||
* @param peakBandwidth L2CAP peak bandwidth, default = 0
|
||||
* @param latency L2CAP latency, default = MAX
|
||||
* @param delayVariation L2CAP delay variation, default = MAX
|
||||
*/
|
||||
public BluetoothHidDeviceAppQosSettings(int serviceType, int tokenRate, int tokenBucketSize,
|
||||
int peakBandwidth, int latency, int delayVariation) {
|
||||
this.serviceType = serviceType;
|
||||
this.tokenRate = tokenRate;
|
||||
this.tokenBucketSize = tokenBucketSize;
|
||||
this.peakBandwidth = peakBandwidth;
|
||||
this.latency = latency;
|
||||
this.delayVariation = delayVariation;
|
||||
public BluetoothHidDeviceAppQosSettings(
|
||||
int serviceType,
|
||||
int tokenRate,
|
||||
int tokenBucketSize,
|
||||
int peakBandwidth,
|
||||
int latency,
|
||||
int delayVariation) {
|
||||
mServiceType = serviceType;
|
||||
mTokenRate = tokenRate;
|
||||
mTokenBucketSize = tokenBucketSize;
|
||||
mPeakBandwidth = peakBandwidth;
|
||||
mLatency = latency;
|
||||
mDelayVariation = delayVariation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof BluetoothHidDeviceAppQosSettings) {
|
||||
BluetoothHidDeviceAppQosSettings qos = (BluetoothHidDeviceAppQosSettings) o;
|
||||
return this.serviceType == qos.serviceType
|
||||
&& this.tokenRate == qos.tokenRate
|
||||
&& this.tokenBucketSize == qos.tokenBucketSize
|
||||
&& this.peakBandwidth == qos.peakBandwidth
|
||||
&& this.latency == qos.latency
|
||||
&& this.delayVariation == qos.delayVariation;
|
||||
}
|
||||
return false;
|
||||
public int getServiceType() {
|
||||
return mServiceType;
|
||||
}
|
||||
|
||||
public int getTokenRate() {
|
||||
return mTokenRate;
|
||||
}
|
||||
|
||||
public int getTokenBucketSize() {
|
||||
return mTokenBucketSize;
|
||||
}
|
||||
|
||||
public int getPeakBandwidth() {
|
||||
return mPeakBandwidth;
|
||||
}
|
||||
|
||||
public int getLatency() {
|
||||
return mLatency;
|
||||
}
|
||||
|
||||
public int getDelayVariation() {
|
||||
return mDelayVariation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,104 +121,11 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeInt(serviceType);
|
||||
out.writeInt(tokenRate);
|
||||
out.writeInt(tokenBucketSize);
|
||||
out.writeInt(peakBandwidth);
|
||||
out.writeInt(latency);
|
||||
out.writeInt(delayVariation);
|
||||
}
|
||||
|
||||
/** @return an int array representation of this instance */
|
||||
public int[] toArray() {
|
||||
return new int[] {
|
||||
serviceType, tokenRate, tokenBucketSize, peakBandwidth, latency, delayVariation
|
||||
};
|
||||
}
|
||||
|
||||
/** A helper to build the BluetoothHidDeviceAppQosSettings object. */
|
||||
public static class Builder {
|
||||
// Optional parameters - initialized to default values
|
||||
private int mServiceType = SERVICE_BEST_EFFORT;
|
||||
private int mTokenRate = 0;
|
||||
private int mTokenBucketSize = 0;
|
||||
private int mPeakBandwidth = 0;
|
||||
private int mLatency = MAX;
|
||||
private int mDelayVariation = MAX;
|
||||
|
||||
/**
|
||||
* Set the service type.
|
||||
*
|
||||
* @param val service type. Should be one of {SERVICE_NO_TRAFFIC, SERVICE_BEST_EFFORT,
|
||||
* SERVICE_GUARANTEED}, with SERVICE_BEST_EFFORT being the default one.
|
||||
* @return BluetoothHidDeviceAppQosSettings Builder with specified service type.
|
||||
*/
|
||||
public Builder serviceType(int val) {
|
||||
mServiceType = val;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the token rate.
|
||||
*
|
||||
* @param val token rate
|
||||
* @return BluetoothHidDeviceAppQosSettings Builder with specified token rate.
|
||||
*/
|
||||
public Builder tokenRate(int val) {
|
||||
mTokenRate = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bucket size.
|
||||
*
|
||||
* @param val bucket size
|
||||
* @return BluetoothHidDeviceAppQosSettings Builder with specified bucket size.
|
||||
*/
|
||||
public Builder tokenBucketSize(int val) {
|
||||
mTokenBucketSize = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the peak bandwidth.
|
||||
*
|
||||
* @param val peak bandwidth
|
||||
* @return BluetoothHidDeviceAppQosSettings Builder with specified peak bandwidth.
|
||||
*/
|
||||
public Builder peakBandwidth(int val) {
|
||||
mPeakBandwidth = val;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the latency.
|
||||
*
|
||||
* @param val latency
|
||||
* @return BluetoothHidDeviceAppQosSettings Builder with specified latency.
|
||||
*/
|
||||
public Builder latency(int val) {
|
||||
mLatency = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the delay variation.
|
||||
*
|
||||
* @param val delay variation
|
||||
* @return BluetoothHidDeviceAppQosSettings Builder with specified delay variation.
|
||||
*/
|
||||
public Builder delayVariation(int val) {
|
||||
mDelayVariation = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the BluetoothHidDeviceAppQosSettings object.
|
||||
*
|
||||
* @return BluetoothHidDeviceAppQosSettings object with current settings.
|
||||
*/
|
||||
public BluetoothHidDeviceAppQosSettings build() {
|
||||
return new BluetoothHidDeviceAppQosSettings(mServiceType, mTokenRate, mTokenBucketSize,
|
||||
mPeakBandwidth, mLatency, mDelayVariation);
|
||||
}
|
||||
out.writeInt(mServiceType);
|
||||
out.writeInt(mTokenRate);
|
||||
out.writeInt(mTokenBucketSize);
|
||||
out.writeInt(mPeakBandwidth);
|
||||
out.writeInt(mLatency);
|
||||
out.writeInt(mDelayVariation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package android.bluetooth;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Represents the Service Discovery Protocol (SDP) settings for a Bluetooth HID Device application.
|
||||
@@ -31,11 +30,11 @@ import java.util.Arrays;
|
||||
*/
|
||||
public final class BluetoothHidDeviceAppSdpSettings implements Parcelable {
|
||||
|
||||
public final String name;
|
||||
public final String description;
|
||||
public final String provider;
|
||||
public final byte subclass;
|
||||
public final byte[] descriptors;
|
||||
private final String mName;
|
||||
private final String mDescription;
|
||||
private final String mProvider;
|
||||
private final byte mSubclass;
|
||||
private final byte[] mDescriptors;
|
||||
|
||||
/**
|
||||
* Create a BluetoothHidDeviceAppSdpSettings object for the Bluetooth SDP record.
|
||||
@@ -52,24 +51,31 @@ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable {
|
||||
*/
|
||||
public BluetoothHidDeviceAppSdpSettings(
|
||||
String name, String description, String provider, byte subclass, byte[] descriptors) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.provider = provider;
|
||||
this.subclass = subclass;
|
||||
this.descriptors = descriptors.clone();
|
||||
mName = name;
|
||||
mDescription = description;
|
||||
mProvider = provider;
|
||||
mSubclass = subclass;
|
||||
mDescriptors = descriptors.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof BluetoothHidDeviceAppSdpSettings) {
|
||||
BluetoothHidDeviceAppSdpSettings sdp = (BluetoothHidDeviceAppSdpSettings) o;
|
||||
return this.name.equals(sdp.name)
|
||||
&& this.description.equals(sdp.description)
|
||||
&& this.provider.equals(sdp.provider)
|
||||
&& this.subclass == sdp.subclass
|
||||
&& Arrays.equals(this.descriptors, sdp.descriptors);
|
||||
}
|
||||
return false;
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return mDescription;
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
public byte getSubclass() {
|
||||
return mSubclass;
|
||||
}
|
||||
|
||||
public byte[] getDescriptors() {
|
||||
return mDescriptors;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,10 +105,10 @@ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(name);
|
||||
out.writeString(description);
|
||||
out.writeString(provider);
|
||||
out.writeByte(subclass);
|
||||
out.writeByteArray(descriptors);
|
||||
out.writeString(mName);
|
||||
out.writeString(mDescription);
|
||||
out.writeString(mProvider);
|
||||
out.writeByte(mSubclass);
|
||||
out.writeByteArray(mDescriptors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.bluetooth;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* The template class that applications use to call callback functions on events from the HID host.
|
||||
* Callback functions are wrapped in this class and registered to the Android system during app
|
||||
* registration.
|
||||
*
|
||||
* <p>{@see BluetoothHidDevice}
|
||||
*/
|
||||
public abstract class BluetoothHidDeviceCallback {
|
||||
|
||||
private static final String TAG = "BluetoothHidDevCallback";
|
||||
|
||||
/**
|
||||
* Callback called when application registration state changes. Usually it's called due to
|
||||
* either {@link BluetoothHidDevice#registerApp (String, String, String, byte, byte[],
|
||||
* BluetoothHidDeviceCallback)} or {@link BluetoothHidDevice#unregisterApp()} , but can be also
|
||||
* unsolicited in case e.g. Bluetooth was turned off in which case application is unregistered
|
||||
* automatically.
|
||||
*
|
||||
* @param pluggedDevice {@link BluetoothDevice} object which represents host that currently has
|
||||
* Virtual Cable established with device. Only valid when application is registered, can be
|
||||
* <code>null</code>.
|
||||
* @param registered <code>true</code> if application is registered, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public void onAppStatusChanged(BluetoothDevice pluggedDevice, boolean registered) {
|
||||
Log.d(TAG,
|
||||
"onAppStatusChanged: pluggedDevice=" + pluggedDevice + " registered=" + registered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when connection state with remote host was changed. Application can assume
|
||||
* than Virtual Cable is established when called with {@link BluetoothProfile#STATE_CONNECTED}
|
||||
* <code>state</code>.
|
||||
*
|
||||
* @param device {@link BluetoothDevice} object representing host device which connection state
|
||||
* was changed.
|
||||
* @param state Connection state as defined in {@link BluetoothProfile}.
|
||||
*/
|
||||
public void onConnectionStateChanged(BluetoothDevice device, int state) {
|
||||
Log.d(TAG, "onConnectionStateChanged: device=" + device + " state=" + state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when GET_REPORT is received from remote host. Should be replied by
|
||||
* application using {@link BluetoothHidDevice#replyReport(BluetoothDevice, byte, byte,
|
||||
* byte[])}.
|
||||
*
|
||||
* @param type Requested Report Type.
|
||||
* @param id Requested Report Id, can be 0 if no Report Id are defined in descriptor.
|
||||
* @param bufferSize Requested buffer size, application shall respond with at least given number
|
||||
* of bytes.
|
||||
*/
|
||||
public void onGetReport(BluetoothDevice device, byte type, byte id, int bufferSize) {
|
||||
Log.d(TAG, "onGetReport: device=" + device + " type=" + type + " id=" + id + " bufferSize="
|
||||
+ bufferSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when SET_REPORT is received from remote host. In case received data are
|
||||
* invalid, application shall respond with {@link
|
||||
* BluetoothHidDevice#reportError(BluetoothDevice, byte)}.
|
||||
*
|
||||
* @param type Report Type.
|
||||
* @param id Report Id.
|
||||
* @param data Report data.
|
||||
*/
|
||||
public void onSetReport(BluetoothDevice device, byte type, byte id, byte[] data) {
|
||||
Log.d(TAG, "onSetReport: device=" + device + " type=" + type + " id=" + id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when SET_PROTOCOL is received from remote host. Application shall use this
|
||||
* information to send only reports valid for given protocol mode. By default, {@link
|
||||
* BluetoothHidDevice#PROTOCOL_REPORT_MODE} shall be assumed.
|
||||
*
|
||||
* @param protocol Protocol Mode.
|
||||
*/
|
||||
public void onSetProtocol(BluetoothDevice device, byte protocol) {
|
||||
Log.d(TAG, "onSetProtocol: device=" + device + " protocol=" + protocol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when report data is received over interrupt channel. Report Type is assumed
|
||||
* to be {@link BluetoothHidDevice#REPORT_TYPE_OUTPUT}.
|
||||
*
|
||||
* @param reportId Report Id.
|
||||
* @param data Report data.
|
||||
*/
|
||||
public void onInterruptData(BluetoothDevice device, byte reportId, byte[] data) {
|
||||
Log.d(TAG, "onInterruptData: device=" + device + " reportId=" + reportId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when Virtual Cable is removed. After this callback is
|
||||
* received connection will be disconnected automatically.
|
||||
*/
|
||||
public void onVirtualCableUnplug(BluetoothDevice device) {
|
||||
Log.d(TAG, "onVirtualCableUnplug: device=" + device);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user