• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.bluetooth;
18 
19 import static android.Manifest.permission.BLUETOOTH_CONNECT;
20 
21 import android.annotation.RequiresNoPermission;
22 import android.annotation.RequiresPermission;
23 import android.annotation.SuppressLint;
24 import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
25 import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
26 import android.os.IBinder;
27 import android.os.ParcelFileDescriptor;
28 import android.util.Log;
29 
30 import java.util.Collections;
31 import java.util.List;
32 
33 /**
34  * Public API for Bluetooth Health Profile.
35  *
36  * <p>BluetoothHealth is a proxy object for controlling the Bluetooth Service via IPC.
37  *
38  * <p>How to connect to a health device which is acting in the source role.
39  * <li>Use {@link BluetoothAdapter#getProfileProxy} to get the BluetoothHealth proxy object.
40  * <li>Create an {@link BluetoothHealth} callback and call {@link #registerSinkAppConfiguration} to
41  *     register an application configuration
42  * <li>Pair with the remote device. This currently needs to be done manually from Bluetooth Settings
43  * <li>Connect to a health device using {@link #connectChannelToSource}. Some devices will connect
44  *     the channel automatically. The {@link BluetoothHealth} callback will inform the application
45  *     of channel state change.
46  * <li>Use the file descriptor provided with a connected channel to read and write data to the
47  *     health channel.
48  * <li>The received data needs to be interpreted using a health manager which implements the IEEE
49  *     11073-xxxxx specifications.
50  * <li>When done, close the health channel by calling {@link #disconnectChannel} and unregister the
51  *     application configuration calling {@link #unregisterAppConfiguration}
52  *
53  * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should use
54  *     Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
55  *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
56  *     BluetoothDevice#createL2capChannel(int)}
57  */
58 @Deprecated
59 public final class BluetoothHealth implements BluetoothProfile {
60     private static final String TAG = BluetoothHealth.class.getSimpleName();
61 
62     /**
63      * Health Profile Source Role - the health device.
64      *
65      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
66      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
67      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
68      *     BluetoothDevice#createL2capChannel(int)}
69      */
70     @Deprecated public static final int SOURCE_ROLE = 1 << 0;
71 
72     /**
73      * Health Profile Sink Role the device talking to the health device.
74      *
75      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
76      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
77      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
78      *     BluetoothDevice#createL2capChannel(int)}
79      */
80     @Deprecated public static final int SINK_ROLE = 1 << 1;
81 
82     /**
83      * Health Profile - Channel Type used - Reliable
84      *
85      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
86      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
87      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
88      *     BluetoothDevice#createL2capChannel(int)}
89      */
90     @Deprecated public static final int CHANNEL_TYPE_RELIABLE = 10;
91 
92     /**
93      * Health Profile - Channel Type used - Streaming
94      *
95      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
96      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
97      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
98      *     BluetoothDevice#createL2capChannel(int)}
99      */
100     @Deprecated public static final int CHANNEL_TYPE_STREAMING = 11;
101 
102     /**
103      * Hide auto-created default constructor
104      *
105      * @hide
106      */
BluetoothHealth()107     BluetoothHealth() {}
108 
109     /** @hide */
110     @Override
111     @RequiresNoPermission
onServiceConnected(IBinder service)112     public void onServiceConnected(IBinder service) {}
113 
114     /** @hide */
115     @Override
116     @RequiresNoPermission
onServiceDisconnected()117     public void onServiceDisconnected() {}
118 
119     /** @hide */
120     @Override
121     @RequiresNoPermission
getAdapter()122     public BluetoothAdapter getAdapter() {
123         return null;
124     }
125 
126     /**
127      * Register an application configuration that acts as a Health SINK. This is the configuration
128      * that will be used to communicate with health devices which will act as the {@link
129      * #SOURCE_ROLE}. This is an asynchronous call and so the callback is used to notify success or
130      * failure if the function returns true.
131      *
132      * @param name The friendly name associated with the application or configuration.
133      * @param dataType The dataType of the Source role of Health Profile to which the sink wants to
134      *     connect to.
135      * @param callback A callback to indicate success or failure of the registration and all
136      *     operations done on this application configuration.
137      * @return If true, callback will be called.
138      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
139      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
140      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
141      *     BluetoothDevice#createL2capChannel(int)}
142      */
143     @Deprecated
144     @RequiresLegacyBluetoothPermission
145     @RequiresBluetoothConnectPermission
146     @RequiresPermission(BLUETOOTH_CONNECT)
147     @SuppressLint("AndroidFrameworkRequiresPermission")
registerSinkAppConfiguration( String name, int dataType, BluetoothHealthCallback callback)148     public boolean registerSinkAppConfiguration(
149             String name, int dataType, BluetoothHealthCallback callback) {
150         Log.e(TAG, "registerSinkAppConfiguration(): BluetoothHealth is deprecated");
151         return false;
152     }
153 
154     /**
155      * Unregister an application configuration that has been registered using {@link
156      * #registerSinkAppConfiguration}
157      *
158      * @param config The health app configuration
159      * @return Success or failure.
160      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
161      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
162      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
163      *     BluetoothDevice#createL2capChannel(int)}
164      */
165     @Deprecated
166     @RequiresLegacyBluetoothPermission
167     @RequiresBluetoothConnectPermission
168     @RequiresPermission(BLUETOOTH_CONNECT)
169     @SuppressLint("AndroidFrameworkRequiresPermission")
unregisterAppConfiguration(BluetoothHealthAppConfiguration config)170     public boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config) {
171         Log.e(TAG, "unregisterAppConfiguration(): BluetoothHealth is deprecated");
172         return false;
173     }
174 
175     /**
176      * Connect to a health device which has the {@link #SOURCE_ROLE}. This is an asynchronous call.
177      * If this function returns true, the callback associated with the application configuration
178      * will be called.
179      *
180      * @param device The remote Bluetooth device.
181      * @param config The application configuration which has been registered using {@link
182      *     #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
183      * @return If true, the callback associated with the application config will be called.
184      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
185      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
186      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
187      *     BluetoothDevice#createL2capChannel(int)}
188      */
189     @Deprecated
190     @RequiresLegacyBluetoothPermission
191     @RequiresBluetoothConnectPermission
192     @RequiresPermission(BLUETOOTH_CONNECT)
193     @SuppressLint("AndroidFrameworkRequiresPermission")
connectChannelToSource( BluetoothDevice device, BluetoothHealthAppConfiguration config)194     public boolean connectChannelToSource(
195             BluetoothDevice device, BluetoothHealthAppConfiguration config) {
196         Log.e(TAG, "connectChannelToSource(): BluetoothHealth is deprecated");
197         return false;
198     }
199 
200     /**
201      * Disconnect a connected health channel. This is an asynchronous call. If this function returns
202      * true, the callback associated with the application configuration will be called.
203      *
204      * @param device The remote Bluetooth device.
205      * @param config The application configuration which has been registered using {@link
206      *     #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
207      * @param channelId The channel id associated with the channel
208      * @return If true, the callback associated with the application config will be called.
209      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
210      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
211      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
212      *     BluetoothDevice#createL2capChannel(int)}
213      */
214     @Deprecated
215     @RequiresLegacyBluetoothPermission
216     @RequiresBluetoothConnectPermission
217     @RequiresPermission(BLUETOOTH_CONNECT)
218     @SuppressLint("AndroidFrameworkRequiresPermission")
disconnectChannel( BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId)219     public boolean disconnectChannel(
220             BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId) {
221         Log.e(TAG, "disconnectChannel(): BluetoothHealth is deprecated");
222         return false;
223     }
224 
225     /**
226      * Get the file descriptor of the main channel associated with the remote device and application
227      * configuration.
228      *
229      * <p>It's the responsibility of the caller to close the ParcelFileDescriptor when done.
230      *
231      * @param device The remote Bluetooth health device
232      * @param config The application configuration
233      * @return null on failure, ParcelFileDescriptor on success.
234      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
235      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
236      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
237      *     BluetoothDevice#createL2capChannel(int)}
238      */
239     @Deprecated
240     @RequiresLegacyBluetoothPermission
241     @RequiresBluetoothConnectPermission
242     @RequiresPermission(BLUETOOTH_CONNECT)
243     @SuppressLint("AndroidFrameworkRequiresPermission")
getMainChannelFd( BluetoothDevice device, BluetoothHealthAppConfiguration config)244     public ParcelFileDescriptor getMainChannelFd(
245             BluetoothDevice device, BluetoothHealthAppConfiguration config) {
246         Log.e(TAG, "getMainChannelFd(): BluetoothHealth is deprecated");
247         return null;
248     }
249 
250     /**
251      * Get the current connection state of the profile.
252      *
253      * <p>This is not specific to any application configuration but represents the connection state
254      * of the local Bluetooth adapter with the remote device. This can be used by applications like
255      * status bar which would just like to know the state of the local adapter.
256      *
257      * @param device Remote bluetooth device.
258      * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
259      *     #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
260      */
261     @Override
262     @RequiresLegacyBluetoothPermission
263     @RequiresBluetoothConnectPermission
264     @RequiresPermission(BLUETOOTH_CONNECT)
265     @SuppressLint("AndroidFrameworkRequiresPermission")
getConnectionState(BluetoothDevice device)266     public int getConnectionState(BluetoothDevice device) {
267         Log.e(TAG, "getConnectionState(): BluetoothHealth is deprecated");
268         return STATE_DISCONNECTED;
269     }
270 
271     /**
272      * Get connected devices for the health profile.
273      *
274      * <p>Return the set of devices which are in state {@link #STATE_CONNECTED}
275      *
276      * <p>This is not specific to any application configuration but represents the connection state
277      * of the local Bluetooth adapter for this profile. This can be used by applications like status
278      * bar which would just like to know the state of the local adapter.
279      *
280      * @return List of devices. The list will be empty on error.
281      */
282     @Override
283     @RequiresLegacyBluetoothPermission
284     @RequiresBluetoothConnectPermission
285     @RequiresPermission(BLUETOOTH_CONNECT)
286     @SuppressLint("AndroidFrameworkRequiresPermission")
getConnectedDevices()287     public List<BluetoothDevice> getConnectedDevices() {
288         Log.e(TAG, "getConnectedDevices(): BluetoothHealth is deprecated");
289         return Collections.emptyList();
290     }
291 
292     /**
293      * Get a list of devices that match any of the given connection states.
294      *
295      * <p>If none of the devices match any of the given states, an empty list will be returned.
296      *
297      * <p>This is not specific to any application configuration but represents the connection state
298      * of the local Bluetooth adapter for this profile. This can be used by applications like status
299      * bar which would just like to know the state of the local adapter.
300      *
301      * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
302      *     #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
303      * @return List of devices. The list will be empty on error.
304      */
305     @Override
306     @RequiresLegacyBluetoothPermission
307     @RequiresBluetoothConnectPermission
308     @RequiresPermission(BLUETOOTH_CONNECT)
309     @SuppressLint("AndroidFrameworkRequiresPermission")
getDevicesMatchingConnectionStates(int[] states)310     public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
311         Log.e(TAG, "getDevicesMatchingConnectionStates(): BluetoothHealth is deprecated");
312         return Collections.emptyList();
313     }
314 
315     /**
316      * Health Channel Connection State - Disconnected
317      *
318      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
319      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
320      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
321      *     BluetoothDevice#createL2capChannel(int)}
322      */
323     @Deprecated public static final int STATE_CHANNEL_DISCONNECTED = 0;
324 
325     /**
326      * Health Channel Connection State - Connecting
327      *
328      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
329      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
330      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
331      *     BluetoothDevice#createL2capChannel(int)}
332      */
333     @Deprecated public static final int STATE_CHANNEL_CONNECTING = 1;
334 
335     /**
336      * Health Channel Connection State - Connected
337      *
338      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
339      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
340      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
341      *     BluetoothDevice#createL2capChannel(int)}
342      */
343     @Deprecated public static final int STATE_CHANNEL_CONNECTED = 2;
344 
345     /**
346      * Health Channel Connection State - Disconnecting
347      *
348      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
349      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
350      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
351      *     BluetoothDevice#createL2capChannel(int)}
352      */
353     @Deprecated public static final int STATE_CHANNEL_DISCONNECTING = 3;
354 
355     /**
356      * Health App Configuration registration success
357      *
358      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
359      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
360      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
361      *     BluetoothDevice#createL2capChannel(int)}
362      */
363     @Deprecated public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0;
364 
365     /**
366      * Health App Configuration registration failure
367      *
368      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
369      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
370      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
371      *     BluetoothDevice#createL2capChannel(int)}
372      */
373     @Deprecated public static final int APP_CONFIG_REGISTRATION_FAILURE = 1;
374 
375     /**
376      * Health App Configuration un-registration success
377      *
378      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
379      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
380      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
381      *     BluetoothDevice#createL2capChannel(int)}
382      */
383     @Deprecated public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2;
384 
385     /**
386      * Health App Configuration un-registration failure
387      *
388      * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should
389      *     use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, {@link
390      *     BluetoothAdapter#listenUsingL2capChannel()}, or {@link
391      *     BluetoothDevice#createL2capChannel(int)}
392      */
393     @Deprecated public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3;
394 }
395