Loading core/java/android/bluetooth/BluetoothHidDevice.java +82 −95 Original line number Diff line number Diff line Loading @@ -31,36 +31,33 @@ import java.util.Arrays; import java.util.List; /** * Provides the public APIs to control the Bluetooth HID Device * profile. * Provides the public APIs to control the Bluetooth HID Device profile. * * BluetoothHidDevice is a proxy object for controlling the Bluetooth HID * Device Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get * the BluetoothHidDevice proxy object. * <p>BluetoothHidDevice is a proxy object for controlling the Bluetooth HID Device Service via IPC. * Use {@link BluetoothAdapter#getProfileProxy} to get the BluetoothHidDevice proxy object. * * {@hide} * <p>{@hide} */ public final class BluetoothHidDevice implements BluetoothProfile { private static final String TAG = BluetoothHidDevice.class.getSimpleName(); /** * Intent used to broadcast the change in connection state of the Input * Host profile. * Intent used to broadcast the change in connection state of the Input Host profile. * * <p>This intent will have 3 extras: * * <ul> * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile.</li> * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> * <li>{@link #EXTRA_STATE} - The current state of the profile. * <li>{@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. * <li>{@link BluetoothDevice#EXTRA_DEVICE} - The remote device. * </ul> * * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}. * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of {@link * #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, {@link #STATE_CONNECTED}, {@link * #STATE_DISCONNECTING}. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to * receive. * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to receive. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_CONNECTION_STATE_CHANGED = Loading @@ -69,8 +66,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { /** * Constants representing device subclass. * * @see #registerApp * (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings, * @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings, * BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceCallback) */ public static final byte SUBCLASS1_NONE = (byte) 0x00; Loading Loading @@ -110,8 +106,8 @@ public final class BluetoothHidDevice implements BluetoothProfile { public static final byte ERROR_RSP_UNKNOWN = (byte) 14; /** * Constants representing protocol mode used set by host. Default is always * {@link #PROTOCOL_REPORT_MODE} unless notified otherwise. * Constants representing protocol mode used set by host. Default is always {@link * #PROTOCOL_REPORT_MODE} unless notified otherwise. * * @see BluetoothHidDeviceCallback#onSetProtocol(BluetoothDevice, byte) */ Loading @@ -126,8 +122,8 @@ public final class BluetoothHidDevice implements BluetoothProfile { private BluetoothAdapter mAdapter; private static class BluetoothHidDeviceCallbackWrapper extends IBluetoothHidDeviceCallback.Stub { private static class BluetoothHidDeviceCallbackWrapper extends IBluetoothHidDeviceCallback.Stub { private BluetoothHidDeviceCallback mCallback; Loading Loading @@ -184,12 +180,10 @@ public final class BluetoothHidDevice implements BluetoothProfile { doBind(); } } catch (IllegalStateException e) { Log.e(TAG, "onBluetoothStateChange: could not bind to HID Dev " Log.e(TAG, "onBluetoothStateChange: could not bind to HID Dev " + "service: ", e); } catch (SecurityException e) { Log.e(TAG, "onBluetoothStateChange: could not bind to HID Dev " Log.e(TAG, "onBluetoothStateChange: could not bind to HID Dev " + "service: ", e); } } else { Loading @@ -200,15 +194,17 @@ public final class BluetoothHidDevice implements BluetoothProfile { } }; private final ServiceConnection mConnection = new ServiceConnection() { private final ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { Log.d(TAG, "onServiceConnected()"); mService = IBluetoothHidDevice.Stub.asInterface(service); if (mServiceListener != null) { mServiceListener.onServiceConnected(BluetoothProfile.HID_DEVICE, BluetoothHidDevice.this); mServiceListener.onServiceConnected( BluetoothProfile.HID_DEVICE, BluetoothHidDevice.this); } } public void onServiceDisconnected(ComponentName className) { Log.d(TAG, "onServiceDisconnected()"); mService = null; Loading Loading @@ -280,9 +276,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { mServiceListener = null; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public List<BluetoothDevice> getConnectedDevices() { Log.v(TAG, "getConnectedDevices()"); Loading @@ -301,9 +295,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { return new ArrayList<BluetoothDevice>(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { Log.v(TAG, "getDevicesMatchingConnectionStates(): states=" + Arrays.toString(states)); Loading @@ -322,9 +314,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { return new ArrayList<BluetoothDevice>(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int getConnectionState(BluetoothDevice device) { Log.v(TAG, "getConnectionState(): device=" + device); Loading @@ -344,26 +334,24 @@ public final class BluetoothHidDevice implements BluetoothProfile { } /** * Registers application to be used for HID device. Connections to HID * Device are only possible when application is registered. Only one * application can be registered at time. 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. * Registers application to be used for HID device. Connections to HID Device are only possible * 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. * * @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 * @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 * @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. * sent. The BluetoothHidDeviceCallback object is required. * @return true if the command is successfully sent; otherwise false. */ public boolean registerApp(BluetoothHidDeviceAppSdpSettings sdp, Loading Loading @@ -395,14 +383,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 * 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, 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. * * @return true if the command is successfully sent; otherwise false. */ Loading Loading @@ -451,8 +438,8 @@ 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)}. * Sends report to remote host as reply for GET_REPORT request from {@link * BluetoothHidDeviceCallback#onGetReport(BluetoothDevice, byte, byte, int)}. * * @param type Report Type, as in request. * @param id Report Id, as in request. Loading @@ -479,8 +466,8 @@ 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[])}. * Sends error handshake message as reply for invalid SET_REPORT request from {@link * BluetoothHidDeviceCallback#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. Loading Loading @@ -508,6 +495,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { * Sends Virtual Cable Unplug to currently connected host. * * @return * {@hide} */ public boolean unplug(BluetoothDevice device) { Log.v(TAG, "unplug(): device=" + device); Loading @@ -529,11 +517,11 @@ 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. * 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 true if the command is successfully sent; otherwise false. */ Loading @@ -557,10 +545,9 @@ 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. * 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 true if the command is successfully sent; otherwise false. */ Loading core/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java +21 −18 Original line number Diff line number Diff line Loading @@ -20,15 +20,14 @@ import android.os.Parcel; import android.os.Parcelable; /** * Represents the Quality of Service (QoS) settings for a Bluetooth HID Device * application. * Represents the Quality of Service (QoS) settings for a Bluetooth HID Device application. * * The BluetoothHidDevice framework will update the L2CAP QoS settings for the * app during registration. * <p>The BluetoothHidDevice framework will update the L2CAP QoS settings for the app during * registration. * * {@see BluetoothHidDevice} * <p>{@see BluetoothHidDevice} * * {@hide} * <p>{@hide} */ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { Loading @@ -46,13 +45,12 @@ 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 } * 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 Loading Loading @@ -127,9 +125,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { }; } /** * A helper to build the BluetoothHidDeviceAppQosSettings object. */ /** A helper to build the BluetoothHidDeviceAppQosSettings object. */ public static class Builder { // Optional parameters - initialized to default values private int mServiceType = SERVICE_BEST_EFFORT; Loading @@ -141,6 +137,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * 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. Loading @@ -151,6 +148,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { } /** * Set the token rate. * * @param val token rate * @return BluetoothHidDeviceAppQosSettings Builder with specified token rate. */ Loading @@ -161,6 +159,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * Set the bucket size. * * @param val bucket size * @return BluetoothHidDeviceAppQosSettings Builder with specified bucket size. */ Loading @@ -171,6 +170,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * Set the peak bandwidth. * * @param val peak bandwidth * @return BluetoothHidDeviceAppQosSettings Builder with specified peak bandwidth. */ Loading @@ -180,6 +180,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { } /** * Set the latency. * * @param val latency * @return BluetoothHidDeviceAppQosSettings Builder with specified latency. */ Loading @@ -190,6 +191,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * Set the delay variation. * * @param val delay variation * @return BluetoothHidDeviceAppQosSettings Builder with specified delay variation. */ Loading @@ -200,6 +202,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * Build the BluetoothHidDeviceAppQosSettings object. * * @return BluetoothHidDeviceAppQosSettings object with current settings. */ public BluetoothHidDeviceAppQosSettings build() { Loading core/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java +12 −13 Original line number Diff line number Diff line Loading @@ -22,16 +22,14 @@ import android.os.Parcelable; import java.util.Arrays; /** * Represents the Service Discovery Protocol (SDP) settings for a Bluetooth * HID Device application. * Represents the Service Discovery Protocol (SDP) settings for a Bluetooth HID Device application. * * The BluetoothHidDevice framework adds the SDP record during app * registration, so that the Android device can be discovered as a Bluetooth * HID Device. * <p>The BluetoothHidDevice framework adds the SDP record during app registration, so that the * Android device can be discovered as a Bluetooth HID Device. * * {@see BluetoothHidDevice} * <p>{@see BluetoothHidDevice} * * {@hide} * <p>{@hide} */ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { Loading @@ -43,18 +41,19 @@ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { /** * 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"> * @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"> * @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) { public BluetoothHidDeviceAppSdpSettings( String name, String description, String provider, byte subclass, byte[] descriptors) { this.name = name; this.description = description; this.provider = provider; Loading core/java/android/bluetooth/BluetoothHidDeviceCallback.java +33 −40 Original line number Diff line number Diff line Loading @@ -19,27 +19,24 @@ 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. * 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. * * {@see BluetoothHidDevice} * <p>{@see BluetoothHidDevice} * * {@hide} * <p>{@hide} */ 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. * 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 Loading @@ -48,14 +45,14 @@ public abstract class BluetoothHidDeviceCallback { * otherwise. */ public void onAppStatusChanged(BluetoothDevice pluggedDevice, boolean registered) { Log.d(TAG, "onAppStatusChanged: pluggedDevice=" + pluggedDevice + " registered=" + 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>. * 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. Loading @@ -66,9 +63,9 @@ public abstract class BluetoothHidDeviceCallback { } /** * Callback called when GET_REPORT is received from remote host. Should be * replied by application using * {@link BluetoothHidDevice#replyReport(BluetoothDevice, byte, byte, byte[])}. * 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. Loading @@ -81,9 +78,9 @@ public abstract class BluetoothHidDeviceCallback { } /** * 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)}. * 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. Loading @@ -94,10 +91,9 @@ public abstract class BluetoothHidDeviceCallback { } /** * 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. * 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. */ Loading @@ -106,9 +102,8 @@ public abstract class BluetoothHidDeviceCallback { } /** * Callback called when report data is received over interrupt channel. * Report Type is assumed to be * {@link BluetoothHidDevice#REPORT_TYPE_OUTPUT}. * 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. Loading @@ -118,10 +113,8 @@ public abstract class BluetoothHidDeviceCallback { } /** * Callback called when Virtual Cable is removed. This can be either due to * {@link BluetoothHidDevice#unplug(BluetoothDevice)} or request from remote * side. After this callback is received connection will be disconnected * automatically. * 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); Loading Loading
core/java/android/bluetooth/BluetoothHidDevice.java +82 −95 Original line number Diff line number Diff line Loading @@ -31,36 +31,33 @@ import java.util.Arrays; import java.util.List; /** * Provides the public APIs to control the Bluetooth HID Device * profile. * Provides the public APIs to control the Bluetooth HID Device profile. * * BluetoothHidDevice is a proxy object for controlling the Bluetooth HID * Device Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get * the BluetoothHidDevice proxy object. * <p>BluetoothHidDevice is a proxy object for controlling the Bluetooth HID Device Service via IPC. * Use {@link BluetoothAdapter#getProfileProxy} to get the BluetoothHidDevice proxy object. * * {@hide} * <p>{@hide} */ public final class BluetoothHidDevice implements BluetoothProfile { private static final String TAG = BluetoothHidDevice.class.getSimpleName(); /** * Intent used to broadcast the change in connection state of the Input * Host profile. * Intent used to broadcast the change in connection state of the Input Host profile. * * <p>This intent will have 3 extras: * * <ul> * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile.</li> * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> * <li>{@link #EXTRA_STATE} - The current state of the profile. * <li>{@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. * <li>{@link BluetoothDevice#EXTRA_DEVICE} - The remote device. * </ul> * * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}. * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of {@link * #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, {@link #STATE_CONNECTED}, {@link * #STATE_DISCONNECTING}. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to * receive. * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to receive. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_CONNECTION_STATE_CHANGED = Loading @@ -69,8 +66,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { /** * Constants representing device subclass. * * @see #registerApp * (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings, * @see #registerApp (BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceAppQosSettings, * BluetoothHidDeviceAppQosSettings, BluetoothHidDeviceCallback) */ public static final byte SUBCLASS1_NONE = (byte) 0x00; Loading Loading @@ -110,8 +106,8 @@ public final class BluetoothHidDevice implements BluetoothProfile { public static final byte ERROR_RSP_UNKNOWN = (byte) 14; /** * Constants representing protocol mode used set by host. Default is always * {@link #PROTOCOL_REPORT_MODE} unless notified otherwise. * Constants representing protocol mode used set by host. Default is always {@link * #PROTOCOL_REPORT_MODE} unless notified otherwise. * * @see BluetoothHidDeviceCallback#onSetProtocol(BluetoothDevice, byte) */ Loading @@ -126,8 +122,8 @@ public final class BluetoothHidDevice implements BluetoothProfile { private BluetoothAdapter mAdapter; private static class BluetoothHidDeviceCallbackWrapper extends IBluetoothHidDeviceCallback.Stub { private static class BluetoothHidDeviceCallbackWrapper extends IBluetoothHidDeviceCallback.Stub { private BluetoothHidDeviceCallback mCallback; Loading Loading @@ -184,12 +180,10 @@ public final class BluetoothHidDevice implements BluetoothProfile { doBind(); } } catch (IllegalStateException e) { Log.e(TAG, "onBluetoothStateChange: could not bind to HID Dev " Log.e(TAG, "onBluetoothStateChange: could not bind to HID Dev " + "service: ", e); } catch (SecurityException e) { Log.e(TAG, "onBluetoothStateChange: could not bind to HID Dev " Log.e(TAG, "onBluetoothStateChange: could not bind to HID Dev " + "service: ", e); } } else { Loading @@ -200,15 +194,17 @@ public final class BluetoothHidDevice implements BluetoothProfile { } }; private final ServiceConnection mConnection = new ServiceConnection() { private final ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { Log.d(TAG, "onServiceConnected()"); mService = IBluetoothHidDevice.Stub.asInterface(service); if (mServiceListener != null) { mServiceListener.onServiceConnected(BluetoothProfile.HID_DEVICE, BluetoothHidDevice.this); mServiceListener.onServiceConnected( BluetoothProfile.HID_DEVICE, BluetoothHidDevice.this); } } public void onServiceDisconnected(ComponentName className) { Log.d(TAG, "onServiceDisconnected()"); mService = null; Loading Loading @@ -280,9 +276,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { mServiceListener = null; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public List<BluetoothDevice> getConnectedDevices() { Log.v(TAG, "getConnectedDevices()"); Loading @@ -301,9 +295,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { return new ArrayList<BluetoothDevice>(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { Log.v(TAG, "getDevicesMatchingConnectionStates(): states=" + Arrays.toString(states)); Loading @@ -322,9 +314,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { return new ArrayList<BluetoothDevice>(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int getConnectionState(BluetoothDevice device) { Log.v(TAG, "getConnectionState(): device=" + device); Loading @@ -344,26 +334,24 @@ public final class BluetoothHidDevice implements BluetoothProfile { } /** * Registers application to be used for HID device. Connections to HID * Device are only possible when application is registered. Only one * application can be registered at time. 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. * Registers application to be used for HID device. Connections to HID Device are only possible * 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. * * @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 * @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 * @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. * sent. The BluetoothHidDeviceCallback object is required. * @return true if the command is successfully sent; otherwise false. */ public boolean registerApp(BluetoothHidDeviceAppSdpSettings sdp, Loading Loading @@ -395,14 +383,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 * 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, 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. * * @return true if the command is successfully sent; otherwise false. */ Loading Loading @@ -451,8 +438,8 @@ 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)}. * Sends report to remote host as reply for GET_REPORT request from {@link * BluetoothHidDeviceCallback#onGetReport(BluetoothDevice, byte, byte, int)}. * * @param type Report Type, as in request. * @param id Report Id, as in request. Loading @@ -479,8 +466,8 @@ 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[])}. * Sends error handshake message as reply for invalid SET_REPORT request from {@link * BluetoothHidDeviceCallback#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. Loading Loading @@ -508,6 +495,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { * Sends Virtual Cable Unplug to currently connected host. * * @return * {@hide} */ public boolean unplug(BluetoothDevice device) { Log.v(TAG, "unplug(): device=" + device); Loading @@ -529,11 +517,11 @@ 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. * 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 true if the command is successfully sent; otherwise false. */ Loading @@ -557,10 +545,9 @@ 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. * 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 true if the command is successfully sent; otherwise false. */ Loading
core/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java +21 −18 Original line number Diff line number Diff line Loading @@ -20,15 +20,14 @@ import android.os.Parcel; import android.os.Parcelable; /** * Represents the Quality of Service (QoS) settings for a Bluetooth HID Device * application. * Represents the Quality of Service (QoS) settings for a Bluetooth HID Device application. * * The BluetoothHidDevice framework will update the L2CAP QoS settings for the * app during registration. * <p>The BluetoothHidDevice framework will update the L2CAP QoS settings for the app during * registration. * * {@see BluetoothHidDevice} * <p>{@see BluetoothHidDevice} * * {@hide} * <p>{@hide} */ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { Loading @@ -46,13 +45,12 @@ 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 } * 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 Loading Loading @@ -127,9 +125,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { }; } /** * A helper to build the BluetoothHidDeviceAppQosSettings object. */ /** A helper to build the BluetoothHidDeviceAppQosSettings object. */ public static class Builder { // Optional parameters - initialized to default values private int mServiceType = SERVICE_BEST_EFFORT; Loading @@ -141,6 +137,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * 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. Loading @@ -151,6 +148,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { } /** * Set the token rate. * * @param val token rate * @return BluetoothHidDeviceAppQosSettings Builder with specified token rate. */ Loading @@ -161,6 +159,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * Set the bucket size. * * @param val bucket size * @return BluetoothHidDeviceAppQosSettings Builder with specified bucket size. */ Loading @@ -171,6 +170,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * Set the peak bandwidth. * * @param val peak bandwidth * @return BluetoothHidDeviceAppQosSettings Builder with specified peak bandwidth. */ Loading @@ -180,6 +180,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { } /** * Set the latency. * * @param val latency * @return BluetoothHidDeviceAppQosSettings Builder with specified latency. */ Loading @@ -190,6 +191,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * Set the delay variation. * * @param val delay variation * @return BluetoothHidDeviceAppQosSettings Builder with specified delay variation. */ Loading @@ -200,6 +202,7 @@ public final class BluetoothHidDeviceAppQosSettings implements Parcelable { /** * Build the BluetoothHidDeviceAppQosSettings object. * * @return BluetoothHidDeviceAppQosSettings object with current settings. */ public BluetoothHidDeviceAppQosSettings build() { Loading
core/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java +12 −13 Original line number Diff line number Diff line Loading @@ -22,16 +22,14 @@ import android.os.Parcelable; import java.util.Arrays; /** * Represents the Service Discovery Protocol (SDP) settings for a Bluetooth * HID Device application. * Represents the Service Discovery Protocol (SDP) settings for a Bluetooth HID Device application. * * The BluetoothHidDevice framework adds the SDP record during app * registration, so that the Android device can be discovered as a Bluetooth * HID Device. * <p>The BluetoothHidDevice framework adds the SDP record during app registration, so that the * Android device can be discovered as a Bluetooth HID Device. * * {@see BluetoothHidDevice} * <p>{@see BluetoothHidDevice} * * {@hide} * <p>{@hide} */ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { Loading @@ -43,18 +41,19 @@ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { /** * 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"> * @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"> * @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) { public BluetoothHidDeviceAppSdpSettings( String name, String description, String provider, byte subclass, byte[] descriptors) { this.name = name; this.description = description; this.provider = provider; Loading
core/java/android/bluetooth/BluetoothHidDeviceCallback.java +33 −40 Original line number Diff line number Diff line Loading @@ -19,27 +19,24 @@ 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. * 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. * * {@see BluetoothHidDevice} * <p>{@see BluetoothHidDevice} * * {@hide} * <p>{@hide} */ 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. * 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 Loading @@ -48,14 +45,14 @@ public abstract class BluetoothHidDeviceCallback { * otherwise. */ public void onAppStatusChanged(BluetoothDevice pluggedDevice, boolean registered) { Log.d(TAG, "onAppStatusChanged: pluggedDevice=" + pluggedDevice + " registered=" + 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>. * 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. Loading @@ -66,9 +63,9 @@ public abstract class BluetoothHidDeviceCallback { } /** * Callback called when GET_REPORT is received from remote host. Should be * replied by application using * {@link BluetoothHidDevice#replyReport(BluetoothDevice, byte, byte, byte[])}. * 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. Loading @@ -81,9 +78,9 @@ public abstract class BluetoothHidDeviceCallback { } /** * 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)}. * 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. Loading @@ -94,10 +91,9 @@ public abstract class BluetoothHidDeviceCallback { } /** * 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. * 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. */ Loading @@ -106,9 +102,8 @@ public abstract class BluetoothHidDeviceCallback { } /** * Callback called when report data is received over interrupt channel. * Report Type is assumed to be * {@link BluetoothHidDevice#REPORT_TYPE_OUTPUT}. * 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. Loading @@ -118,10 +113,8 @@ public abstract class BluetoothHidDeviceCallback { } /** * Callback called when Virtual Cable is removed. This can be either due to * {@link BluetoothHidDevice#unplug(BluetoothDevice)} or request from remote * side. After this callback is received connection will be disconnected * automatically. * 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); Loading