blob: f2ceabcc7d7542de08c7eea6e8e6ea2247388df9 [file] [log] [blame]
Matthew Xiefe3807a2013-07-18 17:31:50 -07001/*
2 * Copyright (C) 2008 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
17package android.bluetooth;
18
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -080019import android.Manifest;
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080020import android.annotation.NonNull;
21import android.annotation.Nullable;
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -080022import android.annotation.RequiresPermission;
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080023import android.annotation.SuppressLint;
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -080024import android.annotation.SystemApi;
Mathew Inwood4dc66d32018-08-01 15:07:20 +010025import android.annotation.UnsupportedAppUsage;
Matthew Xiefe3807a2013-07-18 17:31:50 -070026import android.content.Context;
Jack Hea355e5e2017-08-22 16:06:54 -070027import android.os.Binder;
28import android.os.IBinder;
29import android.os.RemoteException;
Matthew Xiefe3807a2013-07-18 17:31:50 -070030import android.util.Log;
31
Jack Hea355e5e2017-08-22 16:06:54 -070032import java.util.ArrayList;
33import java.util.List;
34
Matthew Xiefe3807a2013-07-18 17:31:50 -070035/**
36 * This class provides the APIs to control the Bluetooth MAP
37 * Profile.
Jack Hea355e5e2017-08-22 16:06:54 -070038 *
39 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -070040 */
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080041@SystemApi
Kim Schulz0d376052013-08-22 11:18:02 +020042public final class BluetoothMap implements BluetoothProfile {
Matthew Xiefe3807a2013-07-18 17:31:50 -070043
44 private static final String TAG = "BluetoothMap";
45 private static final boolean DBG = true;
46 private static final boolean VDBG = false;
47
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080048 /** @hide */
49 @SuppressLint("ActionValue")
50 @SystemApi
Kim Schulz0d376052013-08-22 11:18:02 +020051 public static final String ACTION_CONNECTION_STATE_CHANGED =
Jack Hea355e5e2017-08-22 16:06:54 -070052 "android.bluetooth.map.profile.action.CONNECTION_STATE_CHANGED";
Matthew Xiefe3807a2013-07-18 17:31:50 -070053
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080054 /**
55 * There was an error trying to obtain the state
56 *
57 * @hide
58 */
Jack Hea355e5e2017-08-22 16:06:54 -070059 public static final int STATE_ERROR = -1;
Matthew Xiefe3807a2013-07-18 17:31:50 -070060
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080061 /** @hide */
Matthew Xiefe3807a2013-07-18 17:31:50 -070062 public static final int RESULT_FAILURE = 0;
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080063 /** @hide */
Matthew Xiefe3807a2013-07-18 17:31:50 -070064 public static final int RESULT_SUCCESS = 1;
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080065 /**
66 * Connection canceled before completion.
67 *
68 * @hide
69 */
Matthew Xiefe3807a2013-07-18 17:31:50 -070070 public static final int RESULT_CANCELED = 2;
71
Ugo Yud0115462019-03-26 21:38:08 +080072 private BluetoothAdapter mAdapter;
73 private final BluetoothProfileConnector<IBluetoothMap> mProfileConnector =
74 new BluetoothProfileConnector(this, BluetoothProfile.MAP,
75 "BluetoothMap", IBluetoothMap.class.getName()) {
76 @Override
77 public IBluetoothMap getServiceInterface(IBinder service) {
78 return IBluetoothMap.Stub.asInterface(Binder.allowBlocking(service));
Matthew Xiefe3807a2013-07-18 17:31:50 -070079 }
Ugo Yud0115462019-03-26 21:38:08 +080080 };
Matthew Xiefe3807a2013-07-18 17:31:50 -070081
82 /**
83 * Create a BluetoothMap proxy object.
84 */
Ugo Yud0115462019-03-26 21:38:08 +080085 /*package*/ BluetoothMap(Context context, ServiceListener listener) {
Kim Schulz0d376052013-08-22 11:18:02 +020086 if (DBG) Log.d(TAG, "Create BluetoothMap proxy object");
Matthew Xiefe3807a2013-07-18 17:31:50 -070087 mAdapter = BluetoothAdapter.getDefaultAdapter();
Ugo Yud0115462019-03-26 21:38:08 +080088 mProfileConnector.connect(context, listener);
Matthew Xiefe3807a2013-07-18 17:31:50 -070089 }
90
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080091 @SuppressLint("GenericException")
Matthew Xiefe3807a2013-07-18 17:31:50 -070092 protected void finalize() throws Throwable {
93 try {
94 close();
95 } finally {
96 super.finalize();
97 }
98 }
99
100 /**
101 * Close the connection to the backing service.
102 * Other public functions of BluetoothMap will return default error
103 * results once close() has been called. Multiple invocations of close()
104 * are ok.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800105 *
106 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700107 */
108 public synchronized void close() {
Ugo Yud0115462019-03-26 21:38:08 +0800109 mProfileConnector.disconnect();
110 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700111
Ugo Yud0115462019-03-26 21:38:08 +0800112 private IBluetoothMap getService() {
113 return mProfileConnector.getService();
Matthew Xiefe3807a2013-07-18 17:31:50 -0700114 }
115
116 /**
117 * Get the current state of the BluetoothMap service.
Jack Hea355e5e2017-08-22 16:06:54 -0700118 *
119 * @return One of the STATE_ return codes, or STATE_ERROR if this proxy object is currently not
120 * connected to the Map service.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800121 *
122 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700123 */
124 public int getState() {
125 if (VDBG) log("getState()");
Ugo Yud0115462019-03-26 21:38:08 +0800126 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700127 if (service != null) {
Matthew Xiefe3807a2013-07-18 17:31:50 -0700128 try {
Jack He16eeac32017-08-17 12:11:18 -0700129 return service.getState();
Jack Hea355e5e2017-08-22 16:06:54 -0700130 } catch (RemoteException e) {
131 Log.e(TAG, e.toString());
132 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700133 } else {
134 Log.w(TAG, "Proxy not attached to service");
135 if (DBG) log(Log.getStackTraceString(new Throwable()));
136 }
137 return BluetoothMap.STATE_ERROR;
138 }
139
140 /**
141 * Get the currently connected remote Bluetooth device (PCE).
Jack Hea355e5e2017-08-22 16:06:54 -0700142 *
143 * @return The remote Bluetooth device, or null if not in connected or connecting state, or if
144 * this proxy object is not connected to the Map service.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800145 *
146 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700147 */
148 public BluetoothDevice getClient() {
149 if (VDBG) log("getClient()");
Ugo Yud0115462019-03-26 21:38:08 +0800150 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700151 if (service != null) {
Matthew Xiefe3807a2013-07-18 17:31:50 -0700152 try {
Jack He16eeac32017-08-17 12:11:18 -0700153 return service.getClient();
Jack Hea355e5e2017-08-22 16:06:54 -0700154 } catch (RemoteException e) {
155 Log.e(TAG, e.toString());
156 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700157 } else {
158 Log.w(TAG, "Proxy not attached to service");
159 if (DBG) log(Log.getStackTraceString(new Throwable()));
160 }
161 return null;
162 }
163
164 /**
Kim Schulz0d376052013-08-22 11:18:02 +0200165 * Returns true if the specified Bluetooth device is connected.
166 * Returns false if not connected, or if this proxy object is not
167 * currently connected to the Map service.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800168 *
169 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700170 */
171 public boolean isConnected(BluetoothDevice device) {
172 if (VDBG) log("isConnected(" + device + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800173 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700174 if (service != null) {
Matthew Xiefe3807a2013-07-18 17:31:50 -0700175 try {
Jack He16eeac32017-08-17 12:11:18 -0700176 return service.isConnected(device);
Jack Hea355e5e2017-08-22 16:06:54 -0700177 } catch (RemoteException e) {
178 Log.e(TAG, e.toString());
179 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700180 } else {
181 Log.w(TAG, "Proxy not attached to service");
182 if (DBG) log(Log.getStackTraceString(new Throwable()));
183 }
184 return false;
185 }
186
187 /**
Kim Schulz0d376052013-08-22 11:18:02 +0200188 * Initiate connection. Initiation of outgoing connections is not
189 * supported for MAP server.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800190 *
191 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700192 */
Kim Schulz0d376052013-08-22 11:18:02 +0200193 public boolean connect(BluetoothDevice device) {
194 if (DBG) log("connect(" + device + ")" + "not supported for MAPS");
195 return false;
196 }
197
198 /**
199 * Initiate disconnect.
200 *
201 * @param device Remote Bluetooth Device
Jack Hea355e5e2017-08-22 16:06:54 -0700202 * @return false on error, true otherwise
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800203 *
204 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200205 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100206 @UnsupportedAppUsage
Kim Schulz0d376052013-08-22 11:18:02 +0200207 public boolean disconnect(BluetoothDevice device) {
208 if (DBG) log("disconnect(" + device + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800209 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700210 if (service != null && isEnabled() && isValidDevice(device)) {
Matthew Xiefe3807a2013-07-18 17:31:50 -0700211 try {
Jack He16eeac32017-08-17 12:11:18 -0700212 return service.disconnect(device);
Kim Schulz0d376052013-08-22 11:18:02 +0200213 } catch (RemoteException e) {
Jack Hea355e5e2017-08-22 16:06:54 -0700214 Log.e(TAG, Log.getStackTraceString(new Throwable()));
215 return false;
Kim Schulz0d376052013-08-22 11:18:02 +0200216 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700217 }
Jack He16eeac32017-08-17 12:11:18 -0700218 if (service == null) Log.w(TAG, "Proxy not attached to service");
Matthew Xiefe3807a2013-07-18 17:31:50 -0700219 return false;
220 }
221
222 /**
223 * Check class bits for possible Map support.
224 * This is a simple heuristic that tries to guess if a device with the
225 * given class bits might support Map. It is not accurate for all
226 * devices. It tries to err on the side of false positives.
Jack Hea355e5e2017-08-22 16:06:54 -0700227 *
Matthew Xiefe3807a2013-07-18 17:31:50 -0700228 * @return True if this device might support Map.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800229 *
230 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700231 */
232 public static boolean doesClassMatchSink(BluetoothClass btClass) {
233 // TODO optimize the rule
234 switch (btClass.getDeviceClass()) {
Jack Hea355e5e2017-08-22 16:06:54 -0700235 case BluetoothClass.Device.COMPUTER_DESKTOP:
236 case BluetoothClass.Device.COMPUTER_LAPTOP:
237 case BluetoothClass.Device.COMPUTER_SERVER:
238 case BluetoothClass.Device.COMPUTER_UNCATEGORIZED:
239 return true;
240 default:
241 return false;
Matthew Xiefe3807a2013-07-18 17:31:50 -0700242 }
243 }
244
Kim Schulz0d376052013-08-22 11:18:02 +0200245 /**
246 * Get the list of connected devices. Currently at most one.
247 *
248 * @return list of connected devices
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800249 *
250 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200251 */
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800252 @SystemApi
253 public @NonNull List<BluetoothDevice> getConnectedDevices() {
Kim Schulz0d376052013-08-22 11:18:02 +0200254 if (DBG) log("getConnectedDevices()");
Ugo Yud0115462019-03-26 21:38:08 +0800255 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700256 if (service != null && isEnabled()) {
Kim Schulz0d376052013-08-22 11:18:02 +0200257 try {
Jack He16eeac32017-08-17 12:11:18 -0700258 return service.getConnectedDevices();
Kim Schulz0d376052013-08-22 11:18:02 +0200259 } catch (RemoteException e) {
260 Log.e(TAG, Log.getStackTraceString(new Throwable()));
261 return new ArrayList<BluetoothDevice>();
262 }
263 }
Jack He16eeac32017-08-17 12:11:18 -0700264 if (service == null) Log.w(TAG, "Proxy not attached to service");
Kim Schulz0d376052013-08-22 11:18:02 +0200265 return new ArrayList<BluetoothDevice>();
266 }
267
268 /**
269 * Get the list of devices matching specified states. Currently at most one.
270 *
271 * @return list of matching devices
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800272 *
273 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200274 */
275 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
276 if (DBG) log("getDevicesMatchingStates()");
Ugo Yud0115462019-03-26 21:38:08 +0800277 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700278 if (service != null && isEnabled()) {
Kim Schulz0d376052013-08-22 11:18:02 +0200279 try {
Jack He16eeac32017-08-17 12:11:18 -0700280 return service.getDevicesMatchingConnectionStates(states);
Kim Schulz0d376052013-08-22 11:18:02 +0200281 } catch (RemoteException e) {
282 Log.e(TAG, Log.getStackTraceString(new Throwable()));
283 return new ArrayList<BluetoothDevice>();
284 }
285 }
Jack He16eeac32017-08-17 12:11:18 -0700286 if (service == null) Log.w(TAG, "Proxy not attached to service");
Kim Schulz0d376052013-08-22 11:18:02 +0200287 return new ArrayList<BluetoothDevice>();
288 }
289
290 /**
291 * Get connection state of device
292 *
293 * @return device connection state
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800294 *
295 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200296 */
297 public int getConnectionState(BluetoothDevice device) {
298 if (DBG) log("getConnectionState(" + device + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800299 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700300 if (service != null && isEnabled() && isValidDevice(device)) {
Kim Schulz0d376052013-08-22 11:18:02 +0200301 try {
Jack He16eeac32017-08-17 12:11:18 -0700302 return service.getConnectionState(device);
Kim Schulz0d376052013-08-22 11:18:02 +0200303 } catch (RemoteException e) {
304 Log.e(TAG, Log.getStackTraceString(new Throwable()));
305 return BluetoothProfile.STATE_DISCONNECTED;
306 }
307 }
Jack He16eeac32017-08-17 12:11:18 -0700308 if (service == null) Log.w(TAG, "Proxy not attached to service");
Kim Schulz0d376052013-08-22 11:18:02 +0200309 return BluetoothProfile.STATE_DISCONNECTED;
310 }
311
312 /**
313 * Set priority of the profile
314 *
315 * <p> The device should already be paired.
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800316 * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF},
Kim Schulz0d376052013-08-22 11:18:02 +0200317 *
318 * @param device Paired bluetooth device
319 * @param priority
320 * @return true if priority is set, false on error
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800321 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200322 */
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800323 @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
Kim Schulz0d376052013-08-22 11:18:02 +0200324 public boolean setPriority(BluetoothDevice device, int priority) {
325 if (DBG) log("setPriority(" + device + ", " + priority + ")");
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800326 return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority));
327 }
328
329 /**
330 * Set connection policy of the profile
331 *
332 * <p> The device should already be paired.
333 * Connection policy can be one of {@link #CONNECTION_POLICY_ALLOWED},
334 * {@link #CONNECTION_POLICY_FORBIDDEN}, {@link #CONNECTION_POLICY_UNKNOWN}
335 *
336 * @param device Paired bluetooth device
337 * @param connectionPolicy is the connection policy to set to for this profile
338 * @return true if connectionPolicy is set, false on error
339 * @hide
340 */
341 @SystemApi
342 @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800343 public boolean setConnectionPolicy(@Nullable BluetoothDevice device, int connectionPolicy) {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800344 if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800345 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700346 if (service != null && isEnabled() && isValidDevice(device)) {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800347 if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
348 && connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
Jack Hea355e5e2017-08-22 16:06:54 -0700349 return false;
Kim Schulz0d376052013-08-22 11:18:02 +0200350 }
351 try {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800352 return service.setConnectionPolicy(device, connectionPolicy);
Kim Schulz0d376052013-08-22 11:18:02 +0200353 } catch (RemoteException e) {
354 Log.e(TAG, Log.getStackTraceString(new Throwable()));
355 return false;
356 }
357 }
Jack He16eeac32017-08-17 12:11:18 -0700358 if (service == null) Log.w(TAG, "Proxy not attached to service");
Kim Schulz0d376052013-08-22 11:18:02 +0200359 return false;
360 }
361
362 /**
363 * Get the priority of the profile.
364 *
365 * <p> The priority can be any of:
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800366 * {@link #PRIORITY_OFF}, {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
Kim Schulz0d376052013-08-22 11:18:02 +0200367 *
368 * @param device Bluetooth device
369 * @return priority of the device
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800370 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200371 */
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800372 @RequiresPermission(Manifest.permission.BLUETOOTH)
Kim Schulz0d376052013-08-22 11:18:02 +0200373 public int getPriority(BluetoothDevice device) {
374 if (VDBG) log("getPriority(" + device + ")");
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800375 return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device));
376 }
377
378 /**
379 * Get the connection policy of the profile.
380 *
381 * <p> The connection policy can be any of:
382 * {@link #CONNECTION_POLICY_ALLOWED}, {@link #CONNECTION_POLICY_FORBIDDEN},
383 * {@link #CONNECTION_POLICY_UNKNOWN}
384 *
385 * @param device Bluetooth device
386 * @return connection policy of the device
387 * @hide
388 */
389 @SystemApi
390 @RequiresPermission(Manifest.permission.BLUETOOTH)
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800391 public int getConnectionPolicy(@Nullable BluetoothDevice device) {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800392 if (VDBG) log("getConnectionPolicy(" + device + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800393 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700394 if (service != null && isEnabled() && isValidDevice(device)) {
Kim Schulz0d376052013-08-22 11:18:02 +0200395 try {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800396 return service.getConnectionPolicy(device);
Kim Schulz0d376052013-08-22 11:18:02 +0200397 } catch (RemoteException e) {
398 Log.e(TAG, Log.getStackTraceString(new Throwable()));
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800399 return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
Kim Schulz0d376052013-08-22 11:18:02 +0200400 }
401 }
Jack He16eeac32017-08-17 12:11:18 -0700402 if (service == null) Log.w(TAG, "Proxy not attached to service");
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800403 return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
Kim Schulz0d376052013-08-22 11:18:02 +0200404 }
405
Matthew Xiefe3807a2013-07-18 17:31:50 -0700406 private static void log(String msg) {
407 Log.d(TAG, msg);
408 }
Kim Schulz0d376052013-08-22 11:18:02 +0200409
Jack Hea355e5e2017-08-22 16:06:54 -0700410 private boolean isEnabled() {
Kim Schulz0d376052013-08-22 11:18:02 +0200411 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
412 if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON) return true;
413 log("Bluetooth is Not enabled");
414 return false;
415 }
Jack He16eeac32017-08-17 12:11:18 -0700416 private static boolean isValidDevice(BluetoothDevice device) {
417 return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress());
Kim Schulz0d376052013-08-22 11:18:02 +0200418 }
419
Matthew Xiefe3807a2013-07-18 17:31:50 -0700420}