Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.bluetooth; |
| 18 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 21 | import android.os.Binder; |
| 22 | import android.os.IBinder; |
| 23 | import android.os.RemoteException; |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 24 | import android.util.Log; |
| 25 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 29 | /** |
| 30 | * This class provides the APIs to control the Bluetooth MAP |
| 31 | * Profile. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 32 | * |
| 33 | * @hide |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 34 | */ |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 35 | public final class BluetoothMap implements BluetoothProfile { |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 36 | |
| 37 | private static final String TAG = "BluetoothMap"; |
| 38 | private static final boolean DBG = true; |
| 39 | private static final boolean VDBG = false; |
| 40 | |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 41 | public static final String ACTION_CONNECTION_STATE_CHANGED = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 42 | "android.bluetooth.map.profile.action.CONNECTION_STATE_CHANGED"; |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 43 | |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 44 | /** There was an error trying to obtain the state */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 45 | public static final int STATE_ERROR = -1; |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 46 | |
| 47 | public static final int RESULT_FAILURE = 0; |
| 48 | public static final int RESULT_SUCCESS = 1; |
| 49 | /** Connection canceled before completion. */ |
| 50 | public static final int RESULT_CANCELED = 2; |
| 51 | |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 52 | private BluetoothAdapter mAdapter; |
| 53 | private final BluetoothProfileConnector<IBluetoothMap> mProfileConnector = |
| 54 | new BluetoothProfileConnector(this, BluetoothProfile.MAP, |
| 55 | "BluetoothMap", IBluetoothMap.class.getName()) { |
| 56 | @Override |
| 57 | public IBluetoothMap getServiceInterface(IBinder service) { |
| 58 | return IBluetoothMap.Stub.asInterface(Binder.allowBlocking(service)); |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 59 | } |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 60 | }; |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Create a BluetoothMap proxy object. |
| 64 | */ |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 65 | /*package*/ BluetoothMap(Context context, ServiceListener listener) { |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 66 | if (DBG) Log.d(TAG, "Create BluetoothMap proxy object"); |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 67 | mAdapter = BluetoothAdapter.getDefaultAdapter(); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 68 | mProfileConnector.connect(context, listener); |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | protected void finalize() throws Throwable { |
| 72 | try { |
| 73 | close(); |
| 74 | } finally { |
| 75 | super.finalize(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Close the connection to the backing service. |
| 81 | * Other public functions of BluetoothMap will return default error |
| 82 | * results once close() has been called. Multiple invocations of close() |
| 83 | * are ok. |
| 84 | */ |
| 85 | public synchronized void close() { |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 86 | mProfileConnector.disconnect(); |
| 87 | } |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 88 | |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 89 | private IBluetoothMap getService() { |
| 90 | return mProfileConnector.getService(); |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get the current state of the BluetoothMap service. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 95 | * |
| 96 | * @return One of the STATE_ return codes, or STATE_ERROR if this proxy object is currently not |
| 97 | * connected to the Map service. |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 98 | */ |
| 99 | public int getState() { |
| 100 | if (VDBG) log("getState()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 101 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 102 | if (service != null) { |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 103 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 104 | return service.getState(); |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 105 | } catch (RemoteException e) { |
| 106 | Log.e(TAG, e.toString()); |
| 107 | } |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 108 | } else { |
| 109 | Log.w(TAG, "Proxy not attached to service"); |
| 110 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 111 | } |
| 112 | return BluetoothMap.STATE_ERROR; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get the currently connected remote Bluetooth device (PCE). |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 117 | * |
| 118 | * @return The remote Bluetooth device, or null if not in connected or connecting state, or if |
| 119 | * this proxy object is not connected to the Map service. |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 120 | */ |
| 121 | public BluetoothDevice getClient() { |
| 122 | if (VDBG) log("getClient()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 123 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 124 | if (service != null) { |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 125 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 126 | return service.getClient(); |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 127 | } catch (RemoteException e) { |
| 128 | Log.e(TAG, e.toString()); |
| 129 | } |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 130 | } else { |
| 131 | Log.w(TAG, "Proxy not attached to service"); |
| 132 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 133 | } |
| 134 | return null; |
| 135 | } |
| 136 | |
| 137 | /** |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 138 | * Returns true if the specified Bluetooth device is connected. |
| 139 | * Returns false if not connected, or if this proxy object is not |
| 140 | * currently connected to the Map service. |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 141 | */ |
| 142 | public boolean isConnected(BluetoothDevice device) { |
| 143 | if (VDBG) log("isConnected(" + device + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 144 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 145 | if (service != null) { |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 146 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 147 | return service.isConnected(device); |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 148 | } catch (RemoteException e) { |
| 149 | Log.e(TAG, e.toString()); |
| 150 | } |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 151 | } else { |
| 152 | Log.w(TAG, "Proxy not attached to service"); |
| 153 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 154 | } |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | /** |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 159 | * Initiate connection. Initiation of outgoing connections is not |
| 160 | * supported for MAP server. |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 161 | */ |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 162 | public boolean connect(BluetoothDevice device) { |
| 163 | if (DBG) log("connect(" + device + ")" + "not supported for MAPS"); |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Initiate disconnect. |
| 169 | * |
| 170 | * @param device Remote Bluetooth Device |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 171 | * @return false on error, true otherwise |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 172 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 173 | @UnsupportedAppUsage |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 174 | public boolean disconnect(BluetoothDevice device) { |
| 175 | if (DBG) log("disconnect(" + device + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 176 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 177 | if (service != null && isEnabled() && isValidDevice(device)) { |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 178 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 179 | return service.disconnect(device); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 180 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 181 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 182 | return false; |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 183 | } |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 184 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 185 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 186 | return false; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Check class bits for possible Map support. |
| 191 | * This is a simple heuristic that tries to guess if a device with the |
| 192 | * given class bits might support Map. It is not accurate for all |
| 193 | * devices. It tries to err on the side of false positives. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 194 | * |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 195 | * @return True if this device might support Map. |
| 196 | */ |
| 197 | public static boolean doesClassMatchSink(BluetoothClass btClass) { |
| 198 | // TODO optimize the rule |
| 199 | switch (btClass.getDeviceClass()) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 200 | case BluetoothClass.Device.COMPUTER_DESKTOP: |
| 201 | case BluetoothClass.Device.COMPUTER_LAPTOP: |
| 202 | case BluetoothClass.Device.COMPUTER_SERVER: |
| 203 | case BluetoothClass.Device.COMPUTER_UNCATEGORIZED: |
| 204 | return true; |
| 205 | default: |
| 206 | return false; |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 210 | /** |
| 211 | * Get the list of connected devices. Currently at most one. |
| 212 | * |
| 213 | * @return list of connected devices |
| 214 | */ |
| 215 | public List<BluetoothDevice> getConnectedDevices() { |
| 216 | if (DBG) log("getConnectedDevices()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 217 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 218 | if (service != null && isEnabled()) { |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 219 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 220 | return service.getConnectedDevices(); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 221 | } catch (RemoteException e) { |
| 222 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 223 | return new ArrayList<BluetoothDevice>(); |
| 224 | } |
| 225 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 226 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 227 | return new ArrayList<BluetoothDevice>(); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Get the list of devices matching specified states. Currently at most one. |
| 232 | * |
| 233 | * @return list of matching devices |
| 234 | */ |
| 235 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { |
| 236 | if (DBG) log("getDevicesMatchingStates()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 237 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 238 | if (service != null && isEnabled()) { |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 239 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 240 | return service.getDevicesMatchingConnectionStates(states); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 241 | } catch (RemoteException e) { |
| 242 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 243 | return new ArrayList<BluetoothDevice>(); |
| 244 | } |
| 245 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 246 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 247 | return new ArrayList<BluetoothDevice>(); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Get connection state of device |
| 252 | * |
| 253 | * @return device connection state |
| 254 | */ |
| 255 | public int getConnectionState(BluetoothDevice device) { |
| 256 | if (DBG) log("getConnectionState(" + device + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 257 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 258 | if (service != null && isEnabled() && isValidDevice(device)) { |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 259 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 260 | return service.getConnectionState(device); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 261 | } catch (RemoteException e) { |
| 262 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 263 | return BluetoothProfile.STATE_DISCONNECTED; |
| 264 | } |
| 265 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 266 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 267 | return BluetoothProfile.STATE_DISCONNECTED; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Set priority of the profile |
| 272 | * |
| 273 | * <p> The device should already be paired. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 274 | * Priority can be one of {@link #PRIORITY_ON} or |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 275 | * {@link #PRIORITY_OFF}, |
| 276 | * |
| 277 | * @param device Paired bluetooth device |
| 278 | * @param priority |
| 279 | * @return true if priority is set, false on error |
| 280 | */ |
| 281 | public boolean setPriority(BluetoothDevice device, int priority) { |
| 282 | if (DBG) log("setPriority(" + device + ", " + priority + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 283 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 284 | if (service != null && isEnabled() && isValidDevice(device)) { |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 285 | if (priority != BluetoothProfile.PRIORITY_OFF |
| 286 | && priority != BluetoothProfile.PRIORITY_ON) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 287 | return false; |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 288 | } |
| 289 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 290 | return service.setPriority(device, priority); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 291 | } catch (RemoteException e) { |
| 292 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 293 | return false; |
| 294 | } |
| 295 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 296 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 297 | return false; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Get the priority of the profile. |
| 302 | * |
| 303 | * <p> The priority can be any of: |
| 304 | * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF}, |
| 305 | * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED} |
| 306 | * |
| 307 | * @param device Bluetooth device |
| 308 | * @return priority of the device |
| 309 | */ |
| 310 | public int getPriority(BluetoothDevice device) { |
| 311 | if (VDBG) log("getPriority(" + device + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 312 | final IBluetoothMap service = getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 313 | if (service != null && isEnabled() && isValidDevice(device)) { |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 314 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 315 | return service.getPriority(device); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 316 | } catch (RemoteException e) { |
| 317 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 318 | return PRIORITY_OFF; |
| 319 | } |
| 320 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 321 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 322 | return PRIORITY_OFF; |
| 323 | } |
| 324 | |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 325 | private static void log(String msg) { |
| 326 | Log.d(TAG, msg); |
| 327 | } |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 328 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 329 | private boolean isEnabled() { |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 330 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
| 331 | if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON) return true; |
| 332 | log("Bluetooth is Not enabled"); |
| 333 | return false; |
| 334 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 335 | private static boolean isValidDevice(BluetoothDevice device) { |
| 336 | return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 339 | } |