blob: 14a71c44673b358895bf5bfbf47141d8f508c8c7 [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;
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -080021import android.annotation.RequiresPermission;
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080022import android.annotation.SuppressLint;
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -080023import android.annotation.SystemApi;
Artur Satayev76c1d9d2019-12-10 17:47:52 +000024import android.compat.annotation.UnsupportedAppUsage;
Matthew Xiefe3807a2013-07-18 17:31:50 -070025import android.content.Context;
Jack Hea355e5e2017-08-22 16:06:54 -070026import android.os.Binder;
27import android.os.IBinder;
28import android.os.RemoteException;
Rahul Sabnis946bf882020-02-25 11:33:43 -080029import android.util.CloseGuard;
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
Rahul Sabnis946bf882020-02-25 11:33:43 -080042public final class BluetoothMap implements BluetoothProfile, AutoCloseable {
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 Sabnis946bf882020-02-25 11:33:43 -080048 private CloseGuard mCloseGuard;
49
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080050 /** @hide */
51 @SuppressLint("ActionValue")
52 @SystemApi
Kim Schulz0d376052013-08-22 11:18:02 +020053 public static final String ACTION_CONNECTION_STATE_CHANGED =
Jack Hea355e5e2017-08-22 16:06:54 -070054 "android.bluetooth.map.profile.action.CONNECTION_STATE_CHANGED";
Matthew Xiefe3807a2013-07-18 17:31:50 -070055
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080056 /**
57 * There was an error trying to obtain the state
58 *
59 * @hide
60 */
Jack Hea355e5e2017-08-22 16:06:54 -070061 public static final int STATE_ERROR = -1;
Matthew Xiefe3807a2013-07-18 17:31:50 -070062
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080063 /** @hide */
Matthew Xiefe3807a2013-07-18 17:31:50 -070064 public static final int RESULT_FAILURE = 0;
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080065 /** @hide */
Matthew Xiefe3807a2013-07-18 17:31:50 -070066 public static final int RESULT_SUCCESS = 1;
Rahul Sabniseccd5bd2020-01-08 11:08:42 -080067 /**
68 * Connection canceled before completion.
69 *
70 * @hide
71 */
Matthew Xiefe3807a2013-07-18 17:31:50 -070072 public static final int RESULT_CANCELED = 2;
73
Ugo Yud0115462019-03-26 21:38:08 +080074 private BluetoothAdapter mAdapter;
75 private final BluetoothProfileConnector<IBluetoothMap> mProfileConnector =
76 new BluetoothProfileConnector(this, BluetoothProfile.MAP,
77 "BluetoothMap", IBluetoothMap.class.getName()) {
78 @Override
79 public IBluetoothMap getServiceInterface(IBinder service) {
80 return IBluetoothMap.Stub.asInterface(Binder.allowBlocking(service));
Matthew Xiefe3807a2013-07-18 17:31:50 -070081 }
Ugo Yud0115462019-03-26 21:38:08 +080082 };
Matthew Xiefe3807a2013-07-18 17:31:50 -070083
84 /**
85 * Create a BluetoothMap proxy object.
86 */
Ugo Yud0115462019-03-26 21:38:08 +080087 /*package*/ BluetoothMap(Context context, ServiceListener listener) {
Kim Schulz0d376052013-08-22 11:18:02 +020088 if (DBG) Log.d(TAG, "Create BluetoothMap proxy object");
Matthew Xiefe3807a2013-07-18 17:31:50 -070089 mAdapter = BluetoothAdapter.getDefaultAdapter();
Ugo Yud0115462019-03-26 21:38:08 +080090 mProfileConnector.connect(context, listener);
Rahul Sabnis946bf882020-02-25 11:33:43 -080091 mCloseGuard = new CloseGuard();
92 mCloseGuard.open("close");
Matthew Xiefe3807a2013-07-18 17:31:50 -070093 }
94
Rahul Sabnis946bf882020-02-25 11:33:43 -080095 @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
96 protected void finalize() {
97 if (mCloseGuard != null) {
98 mCloseGuard.warnIfOpen();
Matthew Xiefe3807a2013-07-18 17:31:50 -070099 }
Rahul Sabnis946bf882020-02-25 11:33:43 -0800100 close();
Matthew Xiefe3807a2013-07-18 17:31:50 -0700101 }
102
103 /**
104 * Close the connection to the backing service.
105 * Other public functions of BluetoothMap will return default error
106 * results once close() has been called. Multiple invocations of close()
107 * are ok.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800108 *
109 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700110 */
Rahul Sabnis946bf882020-02-25 11:33:43 -0800111 @SystemApi
112 @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
113 public void close() {
114 if (VDBG) log("close()");
Ugo Yud0115462019-03-26 21:38:08 +0800115 mProfileConnector.disconnect();
116 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700117
Ugo Yud0115462019-03-26 21:38:08 +0800118 private IBluetoothMap getService() {
119 return mProfileConnector.getService();
Matthew Xiefe3807a2013-07-18 17:31:50 -0700120 }
121
122 /**
123 * Get the current state of the BluetoothMap service.
Jack Hea355e5e2017-08-22 16:06:54 -0700124 *
125 * @return One of the STATE_ return codes, or STATE_ERROR if this proxy object is currently not
126 * connected to the Map service.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800127 *
128 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700129 */
130 public int getState() {
131 if (VDBG) log("getState()");
Ugo Yud0115462019-03-26 21:38:08 +0800132 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700133 if (service != null) {
Matthew Xiefe3807a2013-07-18 17:31:50 -0700134 try {
Jack He16eeac32017-08-17 12:11:18 -0700135 return service.getState();
Jack Hea355e5e2017-08-22 16:06:54 -0700136 } catch (RemoteException e) {
137 Log.e(TAG, e.toString());
138 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700139 } else {
140 Log.w(TAG, "Proxy not attached to service");
141 if (DBG) log(Log.getStackTraceString(new Throwable()));
142 }
143 return BluetoothMap.STATE_ERROR;
144 }
145
146 /**
147 * Get the currently connected remote Bluetooth device (PCE).
Jack Hea355e5e2017-08-22 16:06:54 -0700148 *
149 * @return The remote Bluetooth device, or null if not in connected or connecting state, or if
150 * this proxy object is not connected to the Map service.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800151 *
152 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700153 */
154 public BluetoothDevice getClient() {
155 if (VDBG) log("getClient()");
Ugo Yud0115462019-03-26 21:38:08 +0800156 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700157 if (service != null) {
Matthew Xiefe3807a2013-07-18 17:31:50 -0700158 try {
Jack He16eeac32017-08-17 12:11:18 -0700159 return service.getClient();
Jack Hea355e5e2017-08-22 16:06:54 -0700160 } catch (RemoteException e) {
161 Log.e(TAG, e.toString());
162 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700163 } else {
164 Log.w(TAG, "Proxy not attached to service");
165 if (DBG) log(Log.getStackTraceString(new Throwable()));
166 }
167 return null;
168 }
169
170 /**
Kim Schulz0d376052013-08-22 11:18:02 +0200171 * Returns true if the specified Bluetooth device is connected.
172 * Returns false if not connected, or if this proxy object is not
173 * currently connected to the Map service.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800174 *
175 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700176 */
177 public boolean isConnected(BluetoothDevice device) {
178 if (VDBG) log("isConnected(" + device + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800179 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700180 if (service != null) {
Matthew Xiefe3807a2013-07-18 17:31:50 -0700181 try {
Jack He16eeac32017-08-17 12:11:18 -0700182 return service.isConnected(device);
Jack Hea355e5e2017-08-22 16:06:54 -0700183 } catch (RemoteException e) {
184 Log.e(TAG, e.toString());
185 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700186 } else {
187 Log.w(TAG, "Proxy not attached to service");
188 if (DBG) log(Log.getStackTraceString(new Throwable()));
189 }
190 return false;
191 }
192
193 /**
Kim Schulz0d376052013-08-22 11:18:02 +0200194 * Initiate connection. Initiation of outgoing connections is not
195 * supported for MAP server.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800196 *
197 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700198 */
Kim Schulz0d376052013-08-22 11:18:02 +0200199 public boolean connect(BluetoothDevice device) {
200 if (DBG) log("connect(" + device + ")" + "not supported for MAPS");
201 return false;
202 }
203
204 /**
205 * Initiate disconnect.
206 *
207 * @param device Remote Bluetooth Device
Jack Hea355e5e2017-08-22 16:06:54 -0700208 * @return false on error, true otherwise
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800209 *
210 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200211 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100212 @UnsupportedAppUsage
Kim Schulz0d376052013-08-22 11:18:02 +0200213 public boolean disconnect(BluetoothDevice device) {
214 if (DBG) log("disconnect(" + device + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800215 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700216 if (service != null && isEnabled() && isValidDevice(device)) {
Matthew Xiefe3807a2013-07-18 17:31:50 -0700217 try {
Jack He16eeac32017-08-17 12:11:18 -0700218 return service.disconnect(device);
Kim Schulz0d376052013-08-22 11:18:02 +0200219 } catch (RemoteException e) {
Jack Hea355e5e2017-08-22 16:06:54 -0700220 Log.e(TAG, Log.getStackTraceString(new Throwable()));
221 return false;
Kim Schulz0d376052013-08-22 11:18:02 +0200222 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700223 }
Jack He16eeac32017-08-17 12:11:18 -0700224 if (service == null) Log.w(TAG, "Proxy not attached to service");
Matthew Xiefe3807a2013-07-18 17:31:50 -0700225 return false;
226 }
227
228 /**
229 * Check class bits for possible Map support.
230 * This is a simple heuristic that tries to guess if a device with the
231 * given class bits might support Map. It is not accurate for all
232 * devices. It tries to err on the side of false positives.
Jack Hea355e5e2017-08-22 16:06:54 -0700233 *
Matthew Xiefe3807a2013-07-18 17:31:50 -0700234 * @return True if this device might support Map.
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800235 *
236 * @hide
Matthew Xiefe3807a2013-07-18 17:31:50 -0700237 */
238 public static boolean doesClassMatchSink(BluetoothClass btClass) {
239 // TODO optimize the rule
240 switch (btClass.getDeviceClass()) {
Jack Hea355e5e2017-08-22 16:06:54 -0700241 case BluetoothClass.Device.COMPUTER_DESKTOP:
242 case BluetoothClass.Device.COMPUTER_LAPTOP:
243 case BluetoothClass.Device.COMPUTER_SERVER:
244 case BluetoothClass.Device.COMPUTER_UNCATEGORIZED:
245 return true;
246 default:
247 return false;
Matthew Xiefe3807a2013-07-18 17:31:50 -0700248 }
249 }
250
Kim Schulz0d376052013-08-22 11:18:02 +0200251 /**
252 * Get the list of connected devices. Currently at most one.
253 *
254 * @return list of connected devices
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800255 *
256 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200257 */
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800258 @SystemApi
Rahul Sabnis946bf882020-02-25 11:33:43 -0800259 @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800260 public @NonNull List<BluetoothDevice> getConnectedDevices() {
Kim Schulz0d376052013-08-22 11:18:02 +0200261 if (DBG) log("getConnectedDevices()");
Ugo Yud0115462019-03-26 21:38:08 +0800262 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700263 if (service != null && isEnabled()) {
Kim Schulz0d376052013-08-22 11:18:02 +0200264 try {
Jack He16eeac32017-08-17 12:11:18 -0700265 return service.getConnectedDevices();
Kim Schulz0d376052013-08-22 11:18:02 +0200266 } catch (RemoteException e) {
267 Log.e(TAG, Log.getStackTraceString(new Throwable()));
268 return new ArrayList<BluetoothDevice>();
269 }
270 }
Jack He16eeac32017-08-17 12:11:18 -0700271 if (service == null) Log.w(TAG, "Proxy not attached to service");
Kim Schulz0d376052013-08-22 11:18:02 +0200272 return new ArrayList<BluetoothDevice>();
273 }
274
275 /**
276 * Get the list of devices matching specified states. Currently at most one.
277 *
278 * @return list of matching devices
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800279 *
280 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200281 */
282 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
283 if (DBG) log("getDevicesMatchingStates()");
Ugo Yud0115462019-03-26 21:38:08 +0800284 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700285 if (service != null && isEnabled()) {
Kim Schulz0d376052013-08-22 11:18:02 +0200286 try {
Jack He16eeac32017-08-17 12:11:18 -0700287 return service.getDevicesMatchingConnectionStates(states);
Kim Schulz0d376052013-08-22 11:18:02 +0200288 } catch (RemoteException e) {
289 Log.e(TAG, Log.getStackTraceString(new Throwable()));
290 return new ArrayList<BluetoothDevice>();
291 }
292 }
Jack He16eeac32017-08-17 12:11:18 -0700293 if (service == null) Log.w(TAG, "Proxy not attached to service");
Kim Schulz0d376052013-08-22 11:18:02 +0200294 return new ArrayList<BluetoothDevice>();
295 }
296
297 /**
298 * Get connection state of device
299 *
300 * @return device connection state
Rahul Sabniseccd5bd2020-01-08 11:08:42 -0800301 *
302 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200303 */
304 public int getConnectionState(BluetoothDevice device) {
305 if (DBG) log("getConnectionState(" + device + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800306 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700307 if (service != null && isEnabled() && isValidDevice(device)) {
Kim Schulz0d376052013-08-22 11:18:02 +0200308 try {
Jack He16eeac32017-08-17 12:11:18 -0700309 return service.getConnectionState(device);
Kim Schulz0d376052013-08-22 11:18:02 +0200310 } catch (RemoteException e) {
311 Log.e(TAG, Log.getStackTraceString(new Throwable()));
312 return BluetoothProfile.STATE_DISCONNECTED;
313 }
314 }
Jack He16eeac32017-08-17 12:11:18 -0700315 if (service == null) Log.w(TAG, "Proxy not attached to service");
Kim Schulz0d376052013-08-22 11:18:02 +0200316 return BluetoothProfile.STATE_DISCONNECTED;
317 }
318
319 /**
320 * Set priority of the profile
321 *
322 * <p> The device should already be paired.
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800323 * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF},
Kim Schulz0d376052013-08-22 11:18:02 +0200324 *
325 * @param device Paired bluetooth device
326 * @param priority
327 * @return true if priority is set, false on error
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800328 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200329 */
Rahul Sabnis2c71d162020-03-18 17:46:33 -0700330 @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
Kim Schulz0d376052013-08-22 11:18:02 +0200331 public boolean setPriority(BluetoothDevice device, int priority) {
332 if (DBG) log("setPriority(" + device + ", " + priority + ")");
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800333 return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority));
334 }
335
336 /**
337 * Set connection policy of the profile
338 *
339 * <p> The device should already be paired.
340 * Connection policy can be one of {@link #CONNECTION_POLICY_ALLOWED},
341 * {@link #CONNECTION_POLICY_FORBIDDEN}, {@link #CONNECTION_POLICY_UNKNOWN}
342 *
343 * @param device Paired bluetooth device
344 * @param connectionPolicy is the connection policy to set to for this profile
345 * @return true if connectionPolicy is set, false on error
346 * @hide
347 */
348 @SystemApi
Rahul Sabnis2c71d162020-03-18 17:46:33 -0700349 @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
350 public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
Rahul Sabnis30c597f2020-01-22 14:26:35 -0800351 @ConnectionPolicy int connectionPolicy) {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800352 if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800353 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700354 if (service != null && isEnabled() && isValidDevice(device)) {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800355 if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
356 && connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
Jack Hea355e5e2017-08-22 16:06:54 -0700357 return false;
Kim Schulz0d376052013-08-22 11:18:02 +0200358 }
359 try {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800360 return service.setConnectionPolicy(device, connectionPolicy);
Kim Schulz0d376052013-08-22 11:18:02 +0200361 } catch (RemoteException e) {
362 Log.e(TAG, Log.getStackTraceString(new Throwable()));
363 return false;
364 }
365 }
Jack He16eeac32017-08-17 12:11:18 -0700366 if (service == null) Log.w(TAG, "Proxy not attached to service");
Kim Schulz0d376052013-08-22 11:18:02 +0200367 return false;
368 }
369
370 /**
371 * Get the priority of the profile.
372 *
373 * <p> The priority can be any of:
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800374 * {@link #PRIORITY_OFF}, {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
Kim Schulz0d376052013-08-22 11:18:02 +0200375 *
376 * @param device Bluetooth device
377 * @return priority of the device
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800378 * @hide
Kim Schulz0d376052013-08-22 11:18:02 +0200379 */
Rahul Sabnis2c71d162020-03-18 17:46:33 -0700380 @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
Kim Schulz0d376052013-08-22 11:18:02 +0200381 public int getPriority(BluetoothDevice device) {
382 if (VDBG) log("getPriority(" + device + ")");
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800383 return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device));
384 }
385
386 /**
387 * Get the connection policy of the profile.
388 *
389 * <p> The connection policy can be any of:
390 * {@link #CONNECTION_POLICY_ALLOWED}, {@link #CONNECTION_POLICY_FORBIDDEN},
391 * {@link #CONNECTION_POLICY_UNKNOWN}
392 *
393 * @param device Bluetooth device
394 * @return connection policy of the device
395 * @hide
396 */
397 @SystemApi
Rahul Sabnis2c71d162020-03-18 17:46:33 -0700398 @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
399 public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800400 if (VDBG) log("getConnectionPolicy(" + device + ")");
Ugo Yud0115462019-03-26 21:38:08 +0800401 final IBluetoothMap service = getService();
Jack He16eeac32017-08-17 12:11:18 -0700402 if (service != null && isEnabled() && isValidDevice(device)) {
Kim Schulz0d376052013-08-22 11:18:02 +0200403 try {
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800404 return service.getConnectionPolicy(device);
Kim Schulz0d376052013-08-22 11:18:02 +0200405 } catch (RemoteException e) {
406 Log.e(TAG, Log.getStackTraceString(new Throwable()));
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800407 return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
Kim Schulz0d376052013-08-22 11:18:02 +0200408 }
409 }
Jack He16eeac32017-08-17 12:11:18 -0700410 if (service == null) Log.w(TAG, "Proxy not attached to service");
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800411 return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
Kim Schulz0d376052013-08-22 11:18:02 +0200412 }
413
Matthew Xiefe3807a2013-07-18 17:31:50 -0700414 private static void log(String msg) {
415 Log.d(TAG, msg);
416 }
Kim Schulz0d376052013-08-22 11:18:02 +0200417
Jack Hea355e5e2017-08-22 16:06:54 -0700418 private boolean isEnabled() {
Kim Schulz0d376052013-08-22 11:18:02 +0200419 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
420 if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON) return true;
421 log("Bluetooth is Not enabled");
422 return false;
423 }
Jack He16eeac32017-08-17 12:11:18 -0700424 private static boolean isValidDevice(BluetoothDevice device) {
425 return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress());
Kim Schulz0d376052013-08-22 11:18:02 +0200426 }
427
Matthew Xiefe3807a2013-07-18 17:31:50 -0700428}