diff options
Diffstat (limited to 'framework/java')
3 files changed, 148 insertions, 11 deletions
diff --git a/framework/java/android/bluetooth/BluetoothHidDevice.java b/framework/java/android/bluetooth/BluetoothHidDevice.java index e3d763ab9b..6692e137fa 100644 --- a/framework/java/android/bluetooth/BluetoothHidDevice.java +++ b/framework/java/android/bluetooth/BluetoothHidDevice.java @@ -350,13 +350,22 @@ public final class BluetoothHidDevice implements BluetoothProfile { * application can be registered at time. When no longer used, application * should be unregistered using * {@link #unregisterApp(BluetoothHidDeviceAppConfiguration)}. + * 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. * * @param sdp {@link BluetoothHidDeviceAppSdpSettings} object of HID Device SDP record. + * The HID Device SDP record is required. * @param inQos {@link BluetoothHidDeviceAppQosSettings} object of Incoming QoS Settings. + * The Incoming QoS Settings is not required. Use null or default + * BluetoothHidDeviceAppQosSettings.Builder for default values. * @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. - * @return + * The BluetoothHidDeviceCallback object is required. + * @return true if the command is successfully sent; otherwise false. */ public boolean registerApp(BluetoothHidDeviceAppSdpSettings sdp, BluetoothHidDeviceAppQosSettings inQos, BluetoothHidDeviceAppQosSettings outQos, @@ -394,12 +403,15 @@ public final class BluetoothHidDevice implements BluetoothProfile { * {@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. * * @param config {@link BluetoothHidDeviceAppConfiguration} object as obtained from {@link * BluetoothHidDeviceCallback#onAppStatusChanged(BluetoothDevice, * BluetoothHidDeviceAppConfiguration, * boolean)} - * @return + * @return true if the command is successfully sent; otherwise false. */ public boolean unregisterApp(BluetoothHidDeviceAppConfiguration config) { Log.v(TAG, "unregisterApp()"); @@ -426,7 +438,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { * @param id Report Id, as defined in descriptor. Can be 0 in case Report Id are not defined in * descriptor. * @param data Report data, not including Report Id. - * @return + * @return true if the command is successfully sent; otherwise false. */ public boolean sendReport(BluetoothDevice device, int id, byte[] data) { boolean result = false; @@ -452,7 +464,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { * @param type Report Type, as in request. * @param id Report Id, as in request. * @param data Report data, not including Report Id. - * @return + * @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); @@ -478,7 +490,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { * from {@link BluetoothHidDeviceCallback#onSetReport(BluetoothDevice, byte, byte, byte[])}. * * @param error Error to be sent for SET_REPORT via HANDSHAKE. - * @return + * @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); @@ -524,10 +536,13 @@ public final class BluetoothHidDevice implements BluetoothProfile { } /** - * Initiates connection to host which currently has Virtual Cable - * established with device. + * 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. * - * @return + * @return true if the command is successfully sent; otherwise false. */ public boolean connect(BluetoothDevice device) { Log.v(TAG, "connect(): device=" + device); @@ -550,8 +565,11 @@ 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. * - * @return + * @return true if the command is successfully sent; otherwise false. */ public boolean disconnect(BluetoothDevice device) { Log.v(TAG, "disconnect(): device=" + device); diff --git a/framework/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java b/framework/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java index ccc3ef4008..881ae98d98 100644 --- a/framework/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java +++ b/framework/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java @@ -45,6 +45,21 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { public static final int MAX = (int) 0xffffffff; + /** + * Create a BluetoothHidDeviceAppQosSettings object for the Bluetooth L2CAP channel. + * The QoS Settings is optional. + * Recommended to use BluetoothHidDeviceAppQosSettings.Builder. + * {@see <a href="https://www.bluetooth.com/specifications/profiles-overview"> + * https://www.bluetooth.com/specifications/profiles-overview + * </a> + * Bluetooth HID Specfication v1.1.1 Section 5.2 and Appendix D } + * @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 + */ public BluetoothHidDeviceAppQosSettings(int serviceType, int tokenRate, int tokenBucketSize, int peakBandwidth, int latency, int delayVariation) { this.serviceType = serviceType; @@ -59,7 +74,12 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { public boolean equals(Object o) { if (o instanceof BluetoothHidDeviceAppQosSettings) { BluetoothHidDeviceAppQosSettings qos = (BluetoothHidDeviceAppQosSettings) o; - return false; + 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; } @@ -106,4 +126,85 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { 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); + } + } } diff --git a/framework/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java b/framework/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java index f01c493289..4669637043 100644 --- a/framework/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java +++ b/framework/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java @@ -19,6 +19,8 @@ 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. @@ -39,6 +41,18 @@ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { public final byte subclass; public final byte[] descriptors; + /** + * Create a BluetoothHidDeviceAppSdpSettings object for the Bluetooth SDP record. + * @param name Name of this Bluetooth HID device. Maximum length is 50 bytes. + * @param description Description for this Bluetooth HID device. Maximum length is 50 bytes. + * @param provider Provider of this Bluetooth HID device. Maximum length is 50 bytes. + * @param subclass Subclass of this Bluetooth HID device. + * See <a href="www.usb.org/developers/hidpage/HID1_11.pdf"> + * www.usb.org/developers/hidpage/HID1_11.pdf Section 4.2</a> + * @param descriptors Descriptors of this Bluetooth HID device. + * See <a href="www.usb.org/developers/hidpage/HID1_11.pdf"> + * www.usb.org/developers/hidpage/HID1_11.pdf Chapter 6</a> Maximum length is 2048 bytes. + */ public BluetoothHidDeviceAppSdpSettings(String name, String description, String provider, byte subclass, byte[] descriptors) { this.name = name; @@ -52,7 +66,11 @@ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { public boolean equals(Object o) { if (o instanceof BluetoothHidDeviceAppSdpSettings) { BluetoothHidDeviceAppSdpSettings sdp = (BluetoothHidDeviceAppSdpSettings) o; - return false; + 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; } |