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