The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 2 | * Copyright (C) 2009 The Android Open Source Project |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 19 | import android.Manifest; |
| 20 | import android.annotation.RequiresPermission; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 21 | import android.annotation.SdkConstant; |
| 22 | import android.annotation.SdkConstant.SdkConstantType; |
Andre Eisenbach | 2b8696e | 2015-02-05 20:06:33 -0800 | [diff] [blame] | 23 | import android.annotation.SystemApi; |
Matthew Xie | ddf7e47 | 2013-03-01 18:41:02 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 25 | import android.os.Parcel; |
| 26 | import android.os.Parcelable; |
Nick Pelly | aef439e | 2009-09-28 12:33:17 -0700 | [diff] [blame] | 27 | import android.os.ParcelUuid; |
Christine Hallstrom | 044b8f3 | 2015-11-17 12:24:07 -0800 | [diff] [blame] | 28 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.os.RemoteException; |
| 30 | import android.util.Log; |
| 31 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 32 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import java.io.UnsupportedEncodingException; |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 34 | import java.util.UUID; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 37 | * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 38 | * create a connection with the respective device or query information about |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 39 | * it, such as the name, address, class, and bonding state. |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 40 | * |
| 41 | * <p>This class is really just a thin wrapper for a Bluetooth hardware |
| 42 | * address. Objects of this class are immutable. Operations on this class |
| 43 | * are performed on the remote Bluetooth hardware address, using the |
| 44 | * {@link BluetoothAdapter} that was used to create this {@link |
| 45 | * BluetoothDevice}. |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 46 | * |
| 47 | * <p>To get a {@link BluetoothDevice}, use |
| 48 | * {@link BluetoothAdapter#getRemoteDevice(String) |
| 49 | * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device |
| 50 | * of a known MAC address (which you can get through device discovery with |
| 51 | * {@link BluetoothAdapter}) or get one from the set of bonded devices |
| 52 | * returned by {@link BluetoothAdapter#getBondedDevices() |
| 53 | * BluetoothAdapter.getBondedDevices()}. You can then open a |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 54 | * {@link BluetoothSocket} for communication with the remote device, using |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 55 | * {@link #createRfcommSocketToServiceRecord(UUID)}. |
| 56 | * |
| 57 | * <p class="note"><strong>Note:</strong> |
| 58 | * Requires the {@link android.Manifest.permission#BLUETOOTH} permission. |
| 59 | * |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 60 | * <div class="special reference"> |
| 61 | * <h3>Developer Guides</h3> |
Hemal Patel | 65813df | 2016-08-17 13:18:14 -0700 | [diff] [blame] | 62 | * <p> |
| 63 | * For more information about using Bluetooth, read the <a href= |
| 64 | * "{@docRoot}guide/topics/connectivity/bluetooth.html">Bluetooth</a> developer |
| 65 | * guide. |
| 66 | * </p> |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 67 | * </div> |
| 68 | * |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 69 | * {@see BluetoothAdapter} |
| 70 | * {@see BluetoothSocket} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | */ |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 72 | public final class BluetoothDevice implements Parcelable { |
| 73 | private static final String TAG = "BluetoothDevice"; |
Ravi Nagarajan | 7077272 | 2012-04-23 04:06:49 -0700 | [diff] [blame] | 74 | private static final boolean DBG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 76 | /** |
Andre Eisenbach | 2b8696e | 2015-02-05 20:06:33 -0800 | [diff] [blame] | 77 | * Connection state bitmask as returned by getConnectionState. |
| 78 | */ |
| 79 | private static final int CONNECTION_STATE_DISCONNECTED = 0; |
| 80 | private static final int CONNECTION_STATE_CONNECTED = 1; |
| 81 | private static final int CONNECTION_STATE_ENCRYPTED_BREDR = 2; |
| 82 | private static final int CONNECTION_STATE_ENCRYPTED_LE = 4; |
| 83 | |
| 84 | /** |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 85 | * Sentinel error value for this class. Guaranteed to not equal any other |
| 86 | * integer constant in this class. Provided as a convenience for functions |
| 87 | * that require a sentinel error value, for example: |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 88 | * <p><code>Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, |
| 89 | * BluetoothDevice.ERROR)</code> |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 90 | */ |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 91 | public static final int ERROR = Integer.MIN_VALUE; |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 92 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 93 | /** |
| 94 | * Broadcast Action: Remote device discovered. |
| 95 | * <p>Sent when a remote device is found during discovery. |
| 96 | * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link |
| 97 | * #EXTRA_CLASS}. Can contain the extra fields {@link #EXTRA_NAME} and/or |
| 98 | * {@link #EXTRA_RSSI} if they are available. |
Fyodor Kupolov | 72f491d | 2015-07-14 11:38:58 -0700 | [diff] [blame] | 99 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} and |
| 100 | * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} to receive. |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 101 | */ |
| 102 | // TODO: Change API to not broadcast RSSI if not available (incoming connection) |
| 103 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 104 | public static final String ACTION_FOUND = |
| 105 | "android.bluetooth.device.action.FOUND"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 107 | /** |
| 108 | * Broadcast Action: Remote device disappeared. |
| 109 | * <p>Sent when a remote device that was found in the last discovery is not |
| 110 | * found in the current discovery. |
| 111 | * <p>Always contains the extra field {@link #EXTRA_DEVICE}. |
| 112 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 113 | * @hide |
| 114 | */ |
| 115 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 116 | public static final String ACTION_DISAPPEARED = |
| 117 | "android.bluetooth.device.action.DISAPPEARED"; |
| 118 | |
| 119 | /** |
| 120 | * Broadcast Action: Bluetooth class of a remote device has changed. |
| 121 | * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link |
| 122 | * #EXTRA_CLASS}. |
| 123 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
Matthew Xie | b30f91e | 2013-05-29 10:19:06 -0700 | [diff] [blame] | 124 | * {@see BluetoothClass} |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 125 | */ |
| 126 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 127 | public static final String ACTION_CLASS_CHANGED = |
| 128 | "android.bluetooth.device.action.CLASS_CHANGED"; |
| 129 | |
| 130 | /** |
| 131 | * Broadcast Action: Indicates a low level (ACL) connection has been |
| 132 | * established with a remote device. |
| 133 | * <p>Always contains the extra field {@link #EXTRA_DEVICE}. |
| 134 | * <p>ACL connections are managed automatically by the Android Bluetooth |
| 135 | * stack. |
| 136 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 137 | */ |
| 138 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 139 | public static final String ACTION_ACL_CONNECTED = |
| 140 | "android.bluetooth.device.action.ACL_CONNECTED"; |
| 141 | |
| 142 | /** |
| 143 | * Broadcast Action: Indicates that a low level (ACL) disconnection has |
| 144 | * been requested for a remote device, and it will soon be disconnected. |
| 145 | * <p>This is useful for graceful disconnection. Applications should use |
| 146 | * this intent as a hint to immediately terminate higher level connections |
| 147 | * (RFCOMM, L2CAP, or profile connections) to the remote device. |
| 148 | * <p>Always contains the extra field {@link #EXTRA_DEVICE}. |
| 149 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 150 | */ |
| 151 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 152 | public static final String ACTION_ACL_DISCONNECT_REQUESTED = |
| 153 | "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED"; |
| 154 | |
| 155 | /** |
| 156 | * Broadcast Action: Indicates a low level (ACL) disconnection from a |
| 157 | * remote device. |
| 158 | * <p>Always contains the extra field {@link #EXTRA_DEVICE}. |
| 159 | * <p>ACL connections are managed automatically by the Android Bluetooth |
| 160 | * stack. |
| 161 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 162 | */ |
| 163 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 164 | public static final String ACTION_ACL_DISCONNECTED = |
| 165 | "android.bluetooth.device.action.ACL_DISCONNECTED"; |
| 166 | |
| 167 | /** |
| 168 | * Broadcast Action: Indicates the friendly name of a remote device has |
| 169 | * been retrieved for the first time, or changed since the last retrieval. |
| 170 | * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link |
| 171 | * #EXTRA_NAME}. |
| 172 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 173 | */ |
| 174 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 175 | public static final String ACTION_NAME_CHANGED = |
| 176 | "android.bluetooth.device.action.NAME_CHANGED"; |
| 177 | |
| 178 | /** |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 179 | * Broadcast Action: Indicates the alias of a remote device has been |
| 180 | * changed. |
| 181 | * <p>Always contains the extra field {@link #EXTRA_DEVICE}. |
| 182 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 183 | * |
| 184 | * @hide |
| 185 | */ |
| 186 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 187 | public static final String ACTION_ALIAS_CHANGED = |
| 188 | "android.bluetooth.device.action.ALIAS_CHANGED"; |
| 189 | |
| 190 | /** |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 191 | * Broadcast Action: Indicates a change in the bond state of a remote |
| 192 | * device. For example, if a device is bonded (paired). |
| 193 | * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link |
| 194 | * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}. |
| 195 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 196 | */ |
| 197 | // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also |
| 198 | // contain a hidden extra field EXTRA_REASON with the result code. |
| 199 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 200 | public static final String ACTION_BOND_STATE_CHANGED = |
| 201 | "android.bluetooth.device.action.BOND_STATE_CHANGED"; |
| 202 | |
| 203 | /** |
| 204 | * Used as a Parcelable {@link BluetoothDevice} extra field in every intent |
| 205 | * broadcast by this class. It contains the {@link BluetoothDevice} that |
| 206 | * the intent applies to. |
| 207 | */ |
| 208 | public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE"; |
| 209 | |
| 210 | /** |
| 211 | * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link |
| 212 | * #ACTION_FOUND} intents. It contains the friendly Bluetooth name. |
| 213 | */ |
| 214 | public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME"; |
| 215 | |
| 216 | /** |
| 217 | * Used as an optional short extra field in {@link #ACTION_FOUND} intents. |
| 218 | * Contains the RSSI value of the remote device as reported by the |
| 219 | * Bluetooth hardware. |
| 220 | */ |
| 221 | public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI"; |
| 222 | |
| 223 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 224 | * Used as a Parcelable {@link BluetoothClass} extra field in {@link |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 225 | * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents. |
| 226 | */ |
| 227 | public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS"; |
| 228 | |
| 229 | /** |
| 230 | * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents. |
| 231 | * Contains the bond state of the remote device. |
| 232 | * <p>Possible values are: |
| 233 | * {@link #BOND_NONE}, |
| 234 | * {@link #BOND_BONDING}, |
| 235 | * {@link #BOND_BONDED}. |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 236 | */ |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 237 | public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE"; |
| 238 | /** |
| 239 | * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents. |
| 240 | * Contains the previous bond state of the remote device. |
| 241 | * <p>Possible values are: |
| 242 | * {@link #BOND_NONE}, |
| 243 | * {@link #BOND_BONDING}, |
| 244 | * {@link #BOND_BONDED}. |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 245 | */ |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 246 | public static final String EXTRA_PREVIOUS_BOND_STATE = |
| 247 | "android.bluetooth.device.extra.PREVIOUS_BOND_STATE"; |
| 248 | /** |
| 249 | * Indicates the remote device is not bonded (paired). |
| 250 | * <p>There is no shared link key with the remote device, so communication |
| 251 | * (if it is allowed at all) will be unauthenticated and unencrypted. |
| 252 | */ |
| 253 | public static final int BOND_NONE = 10; |
| 254 | /** |
| 255 | * Indicates bonding (pairing) is in progress with the remote device. |
| 256 | */ |
| 257 | public static final int BOND_BONDING = 11; |
| 258 | /** |
| 259 | * Indicates the remote device is bonded (paired). |
| 260 | * <p>A shared link keys exists locally for the remote device, so |
| 261 | * communication can be authenticated and encrypted. |
| 262 | * <p><i>Being bonded (paired) with a remote device does not necessarily |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 263 | * mean the device is currently connected. It just means that the pending |
| 264 | * procedure was completed at some earlier time, and the link key is still |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 265 | * stored locally, ready to use on the next connection. |
| 266 | * </i> |
| 267 | */ |
| 268 | public static final int BOND_BONDED = 12; |
| 269 | |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 270 | /** |
| 271 | * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} |
| 272 | * intents for unbond reason. |
| 273 | * @hide |
| 274 | */ |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 275 | public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON"; |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} |
| 279 | * intents to indicate pairing method used. Possible values are: |
| 280 | * {@link #PAIRING_VARIANT_PIN}, |
| 281 | * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION}, |
| 282 | */ |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 283 | public static final String EXTRA_PAIRING_VARIANT = |
| 284 | "android.bluetooth.device.extra.PAIRING_VARIANT"; |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 285 | |
| 286 | /** |
| 287 | * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} |
| 288 | * intents as the value of passkey. |
| 289 | */ |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 290 | public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY"; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
Matthew Xie | 33ec984 | 2013-04-03 00:29:27 -0700 | [diff] [blame] | 293 | * Bluetooth device type, Unknown |
| 294 | */ |
| 295 | public static final int DEVICE_TYPE_UNKNOWN = 0; |
| 296 | |
| 297 | /** |
| 298 | * Bluetooth device type, Classic - BR/EDR devices |
| 299 | */ |
| 300 | public static final int DEVICE_TYPE_CLASSIC = 1; |
| 301 | |
| 302 | /** |
| 303 | * Bluetooth device type, Low Energy - LE-only |
| 304 | */ |
| 305 | public static final int DEVICE_TYPE_LE = 2; |
| 306 | |
| 307 | /** |
| 308 | * Bluetooth device type, Dual Mode - BR/EDR/LE |
| 309 | */ |
| 310 | public static final int DEVICE_TYPE_DUAL = 3; |
| 311 | |
Casper Bonde | 238e0f9 | 2015-04-09 09:24:48 +0200 | [diff] [blame] | 312 | |
| 313 | /** @hide */ |
| 314 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 315 | public static final String ACTION_SDP_RECORD = |
| 316 | "android.bluetooth.device.action.SDP_RECORD"; |
| 317 | |
Matthew Xie | 33ec984 | 2013-04-03 00:29:27 -0700 | [diff] [blame] | 318 | /** |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 319 | * Broadcast Action: This intent is used to broadcast the {@link UUID} |
Nick Pelly | aef439e | 2009-09-28 12:33:17 -0700 | [diff] [blame] | 320 | * wrapped as a {@link android.os.ParcelUuid} of the remote device after it |
| 321 | * has been fetched. This intent is sent only when the UUIDs of the remote |
| 322 | * device are requested to be fetched using Service Discovery Protocol |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 323 | * <p> Always contains the extra field {@link #EXTRA_DEVICE} |
Matthew Xie | ad23210 | 2011-11-08 10:58:12 -0800 | [diff] [blame] | 324 | * <p> Always contains the extra field {@link #EXTRA_UUID} |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 325 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 326 | */ |
| 327 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 328 | public static final String ACTION_UUID = |
Matthew Xie | ad23210 | 2011-11-08 10:58:12 -0800 | [diff] [blame] | 329 | "android.bluetooth.device.action.UUID"; |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 330 | |
Hemant Gupta | 8949bfb | 2013-08-16 14:57:55 +0530 | [diff] [blame] | 331 | /** @hide */ |
| 332 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 333 | public static final String ACTION_MAS_INSTANCE = |
| 334 | "android.bluetooth.device.action.MAS_INSTANCE"; |
| 335 | |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 336 | /** |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 337 | * Broadcast Action: Indicates a failure to retrieve the name of a remote |
| 338 | * device. |
| 339 | * <p>Always contains the extra field {@link #EXTRA_DEVICE}. |
| 340 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 341 | * @hide |
| 342 | */ |
| 343 | //TODO: is this actually useful? |
| 344 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 345 | public static final String ACTION_NAME_FAILED = |
| 346 | "android.bluetooth.device.action.NAME_FAILED"; |
| 347 | |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 348 | /** |
| 349 | * Broadcast Action: This intent is used to broadcast PAIRING REQUEST |
Matthew Xie | ac2c6c3 | 2013-10-21 14:56:33 -0700 | [diff] [blame] | 350 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} to |
Edward Jee | 430e361 | 2013-10-07 18:12:15 -0700 | [diff] [blame] | 351 | * receive. |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 352 | */ |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 353 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 354 | public static final String ACTION_PAIRING_REQUEST = |
| 355 | "android.bluetooth.device.action.PAIRING_REQUEST"; |
| 356 | /** @hide */ |
| 357 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 358 | public static final String ACTION_PAIRING_CANCEL = |
| 359 | "android.bluetooth.device.action.PAIRING_CANCEL"; |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 360 | |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 361 | /** @hide */ |
| 362 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 363 | public static final String ACTION_CONNECTION_ACCESS_REQUEST = |
| 364 | "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST"; |
| 365 | |
| 366 | /** @hide */ |
| 367 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 368 | public static final String ACTION_CONNECTION_ACCESS_REPLY = |
| 369 | "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY"; |
| 370 | |
| 371 | /** @hide */ |
| 372 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 373 | public static final String ACTION_CONNECTION_ACCESS_CANCEL = |
| 374 | "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL"; |
| 375 | |
| 376 | /** |
| 377 | * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent. |
| 378 | * @hide |
| 379 | */ |
| 380 | public static final String EXTRA_ACCESS_REQUEST_TYPE = |
| 381 | "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE"; |
| 382 | |
| 383 | /**@hide*/ |
| 384 | public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1; |
| 385 | |
| 386 | /**@hide*/ |
| 387 | public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2; |
| 388 | |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 389 | /**@hide*/ |
| 390 | public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3; |
| 391 | |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 392 | /**@hide*/ |
| 393 | public static final int REQUEST_TYPE_SIM_ACCESS = 4; |
| 394 | |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 395 | /** |
| 396 | * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents, |
| 397 | * Contains package name to return reply intent to. |
| 398 | * @hide |
| 399 | */ |
| 400 | public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME"; |
| 401 | |
| 402 | /** |
| 403 | * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents, |
| 404 | * Contains class name to return reply intent to. |
| 405 | * @hide |
| 406 | */ |
| 407 | public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME"; |
| 408 | |
| 409 | /** |
| 410 | * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent. |
| 411 | * @hide |
| 412 | */ |
| 413 | public static final String EXTRA_CONNECTION_ACCESS_RESULT = |
| 414 | "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT"; |
| 415 | |
| 416 | /**@hide*/ |
| 417 | public static final int CONNECTION_ACCESS_YES = 1; |
| 418 | |
| 419 | /**@hide*/ |
| 420 | public static final int CONNECTION_ACCESS_NO = 2; |
| 421 | |
| 422 | /** |
| 423 | * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents, |
| 424 | * Contains boolean to indicate if the allowed response is once-for-all so that |
| 425 | * next request will be granted without asking user again. |
| 426 | * @hide |
| 427 | */ |
| 428 | public static final String EXTRA_ALWAYS_ALLOWED = |
| 429 | "android.bluetooth.device.extra.ALWAYS_ALLOWED"; |
| 430 | |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 431 | /** |
| 432 | * A bond attempt succeeded |
| 433 | * @hide |
| 434 | */ |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 435 | public static final int BOND_SUCCESS = 0; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 436 | |
| 437 | /** |
| 438 | * A bond attempt failed because pins did not match, or remote device did |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 439 | * not respond to pin request in time |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 440 | * @hide |
| 441 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | public static final int UNBOND_REASON_AUTH_FAILED = 1; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 443 | |
| 444 | /** |
| 445 | * A bond attempt failed because the other side explicitly rejected |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 446 | * bonding |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 447 | * @hide |
| 448 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | public static final int UNBOND_REASON_AUTH_REJECTED = 2; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 450 | |
| 451 | /** |
| 452 | * A bond attempt failed because we canceled the bonding process |
| 453 | * @hide |
| 454 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | public static final int UNBOND_REASON_AUTH_CANCELED = 3; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 456 | |
| 457 | /** |
| 458 | * A bond attempt failed because we could not contact the remote device |
| 459 | * @hide |
| 460 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 462 | |
| 463 | /** |
| 464 | * A bond attempt failed because a discovery is in progress |
| 465 | * @hide |
| 466 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 468 | |
| 469 | /** |
| 470 | * A bond attempt failed because of authentication timeout |
| 471 | * @hide |
| 472 | */ |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 473 | public static final int UNBOND_REASON_AUTH_TIMEOUT = 6; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 474 | |
| 475 | /** |
| 476 | * A bond attempt failed because of repeated attempts |
| 477 | * @hide |
| 478 | */ |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 479 | public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 480 | |
| 481 | /** |
| 482 | * A bond attempt failed because we received an Authentication Cancel |
| 483 | * by remote end |
| 484 | * @hide |
| 485 | */ |
Jaikumar Ganesh | e5d93b7 | 2009-10-08 02:27:52 -0700 | [diff] [blame] | 486 | public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 487 | |
| 488 | /** |
| 489 | * An existing bond was explicitly revoked |
| 490 | * @hide |
| 491 | */ |
Jaikumar Ganesh | e5d93b7 | 2009-10-08 02:27:52 -0700 | [diff] [blame] | 492 | public static final int UNBOND_REASON_REMOVED = 9; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 494 | /** |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 495 | * The user will be prompted to enter a pin or |
Matthew Xie | ac2c6c3 | 2013-10-21 14:56:33 -0700 | [diff] [blame] | 496 | * an app will enter a pin for user. |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 497 | */ |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 498 | public static final int PAIRING_VARIANT_PIN = 0; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 499 | |
| 500 | /** |
| 501 | * The user will be prompted to enter a passkey |
| 502 | * @hide |
| 503 | */ |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 504 | public static final int PAIRING_VARIANT_PASSKEY = 1; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 505 | |
| 506 | /** |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 507 | * The user will be prompted to confirm the passkey displayed on the screen or |
Matthew Xie | ac2c6c3 | 2013-10-21 14:56:33 -0700 | [diff] [blame] | 508 | * an app will confirm the passkey for the user. |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 509 | */ |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 510 | public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 511 | |
| 512 | /** |
| 513 | * The user will be prompted to accept or deny the incoming pairing request |
| 514 | * @hide |
| 515 | */ |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 516 | public static final int PAIRING_VARIANT_CONSENT = 3; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 517 | |
| 518 | /** |
| 519 | * The user will be prompted to enter the passkey displayed on remote device |
| 520 | * This is used for Bluetooth 2.1 pairing. |
| 521 | * @hide |
| 522 | */ |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 523 | public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 524 | |
| 525 | /** |
| 526 | * The user will be prompted to enter the PIN displayed on remote device. |
| 527 | * This is used for Bluetooth 2.0 pairing. |
| 528 | * @hide |
| 529 | */ |
| 530 | public static final int PAIRING_VARIANT_DISPLAY_PIN = 5; |
| 531 | |
| 532 | /** |
| 533 | * The user will be prompted to accept or deny the OOB pairing request |
| 534 | * @hide |
| 535 | */ |
| 536 | public static final int PAIRING_VARIANT_OOB_CONSENT = 6; |
| 537 | |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 538 | /** |
Casper Bonde | 3b3d1fe | 2015-05-08 14:32:24 +0200 | [diff] [blame] | 539 | * The user will be prompted to enter a 16 digit pin or |
| 540 | * an app will enter a 16 digit pin for user. |
| 541 | * @hide |
| 542 | */ |
| 543 | public static final int PAIRING_VARIANT_PIN_16_DIGITS = 7; |
| 544 | |
| 545 | /** |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 546 | * Used as an extra field in {@link #ACTION_UUID} intents, |
Nick Pelly | aef439e | 2009-09-28 12:33:17 -0700 | [diff] [blame] | 547 | * Contains the {@link android.os.ParcelUuid}s of the remote device which |
| 548 | * is a parcelable version of {@link UUID}. |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 549 | */ |
| 550 | public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID"; |
| 551 | |
Casper Bonde | 238e0f9 | 2015-04-09 09:24:48 +0200 | [diff] [blame] | 552 | /** @hide */ |
| 553 | public static final String EXTRA_SDP_RECORD = |
| 554 | "android.bluetooth.device.extra.SDP_RECORD"; |
| 555 | |
| 556 | /** @hide */ |
| 557 | public static final String EXTRA_SDP_SEARCH_STATUS = |
| 558 | "android.bluetooth.device.extra.SDP_SEARCH_STATUS"; |
Edward Jee | 8dd30aa | 2014-09-05 00:29:14 -0700 | [diff] [blame] | 559 | /** |
| 560 | * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, |
| 561 | * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. |
| 562 | * @hide |
| 563 | */ |
| 564 | public static final int ACCESS_UNKNOWN = 0; |
| 565 | |
| 566 | /** |
| 567 | * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, |
| 568 | * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. |
| 569 | * @hide |
| 570 | */ |
| 571 | public static final int ACCESS_ALLOWED = 1; |
| 572 | |
| 573 | /** |
| 574 | * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, |
| 575 | * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. |
| 576 | * @hide |
| 577 | */ |
| 578 | public static final int ACCESS_REJECTED = 2; |
| 579 | |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 580 | /** |
| 581 | * No preferrence of physical transport for GATT connections to remote dual-mode devices |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 582 | */ |
| 583 | public static final int TRANSPORT_AUTO = 0; |
| 584 | |
| 585 | /** |
| 586 | * Prefer BR/EDR transport for GATT connections to remote dual-mode devices |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 587 | */ |
Hemant Gupta | 8949bfb | 2013-08-16 14:57:55 +0530 | [diff] [blame] | 588 | public static final int TRANSPORT_BREDR = 1; |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 589 | |
| 590 | /** |
| 591 | * Prefer LE transport for GATT connections to remote dual-mode devices |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 592 | */ |
Hemant Gupta | 8949bfb | 2013-08-16 14:57:55 +0530 | [diff] [blame] | 593 | public static final int TRANSPORT_LE = 2; |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 594 | |
Hemant Gupta | 8949bfb | 2013-08-16 14:57:55 +0530 | [diff] [blame] | 595 | /** @hide */ |
| 596 | public static final String EXTRA_MAS_INSTANCE = |
| 597 | "android.bluetooth.device.extra.MAS_INSTANCE"; |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 598 | |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 599 | /** |
| 600 | * Lazy initialization. Guaranteed final after first object constructed, or |
| 601 | * getService() called. |
| 602 | * TODO: Unify implementation of sService amongst BluetoothFoo API's |
| 603 | */ |
| 604 | private static IBluetooth sService; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 605 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 606 | private final String mAddress; |
| 607 | |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 608 | /*package*/ static IBluetooth getService() { |
| 609 | synchronized (BluetoothDevice.class) { |
| 610 | if (sService == null) { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 611 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
fredc | 903ac6f | 2012-04-24 03:59:57 -0700 | [diff] [blame] | 612 | sService = adapter.getBluetoothService(mStateChangeCallback); |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | return sService; |
| 616 | } |
| 617 | |
fredc | 903ac6f | 2012-04-24 03:59:57 -0700 | [diff] [blame] | 618 | static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() { |
| 619 | |
| 620 | public void onBluetoothServiceUp(IBluetooth bluetoothService) |
| 621 | throws RemoteException { |
| 622 | synchronized (BluetoothDevice.class) { |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 623 | if (sService == null) { |
| 624 | sService = bluetoothService; |
| 625 | } |
fredc | 903ac6f | 2012-04-24 03:59:57 -0700 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
| 629 | public void onBluetoothServiceDown() |
| 630 | throws RemoteException { |
| 631 | synchronized (BluetoothDevice.class) { |
| 632 | sService = null; |
| 633 | } |
| 634 | } |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 635 | |
| 636 | public void onBrEdrDown() |
| 637 | { |
| 638 | if (DBG) Log.d(TAG, "onBrEdrDown: reached BLE ON state"); |
| 639 | } |
fredc | 903ac6f | 2012-04-24 03:59:57 -0700 | [diff] [blame] | 640 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | /** |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 642 | * Create a new BluetoothDevice |
| 643 | * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB", |
| 644 | * and is validated in this constructor. |
| 645 | * @param address valid Bluetooth MAC address |
| 646 | * @throws RuntimeException Bluetooth is not available on this platform |
| 647 | * @throws IllegalArgumentException address is invalid |
| 648 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | */ |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 650 | /*package*/ BluetoothDevice(String address) { |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 651 | getService(); // ensures sService is initialized |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 652 | if (!BluetoothAdapter.checkBluetoothAddress(address)) { |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 653 | throw new IllegalArgumentException(address + " is not a valid Bluetooth address"); |
| 654 | } |
| 655 | |
| 656 | mAddress = address; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 659 | @Override |
| 660 | public boolean equals(Object o) { |
| 661 | if (o instanceof BluetoothDevice) { |
| 662 | return mAddress.equals(((BluetoothDevice)o).getAddress()); |
| 663 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 664 | return false; |
| 665 | } |
| 666 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 667 | @Override |
| 668 | public int hashCode() { |
| 669 | return mAddress.hashCode(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 672 | /** |
| 673 | * Returns a string representation of this BluetoothDevice. |
| 674 | * <p>Currently this is the Bluetooth hardware address, for example |
| 675 | * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress} |
| 676 | * if you explicitly require the Bluetooth hardware address in case the |
| 677 | * {@link #toString} representation changes in the future. |
| 678 | * @return string representation of this BluetoothDevice |
| 679 | */ |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 680 | @Override |
| 681 | public String toString() { |
| 682 | return mAddress; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | } |
| 684 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 685 | public int describeContents() { |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | public static final Parcelable.Creator<BluetoothDevice> CREATOR = |
| 690 | new Parcelable.Creator<BluetoothDevice>() { |
| 691 | public BluetoothDevice createFromParcel(Parcel in) { |
| 692 | return new BluetoothDevice(in.readString()); |
| 693 | } |
| 694 | public BluetoothDevice[] newArray(int size) { |
| 695 | return new BluetoothDevice[size]; |
| 696 | } |
| 697 | }; |
| 698 | |
| 699 | public void writeToParcel(Parcel out, int flags) { |
| 700 | out.writeString(mAddress); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | } |
| 702 | |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 703 | /** |
| 704 | * Returns the hardware address of this BluetoothDevice. |
| 705 | * <p> For example, "00:11:22:AA:BB:CC". |
| 706 | * @return Bluetooth hardware address as string |
| 707 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | public String getAddress() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 709 | if (DBG) Log.d(TAG, "mAddress: " + mAddress); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 710 | return mAddress; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /** |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 714 | * Get the friendly Bluetooth name of the remote device. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | * |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 716 | * <p>The local adapter will automatically retrieve remote names when |
| 717 | * performing a device scan, and will cache them. This method just returns |
| 718 | * the name for this device from the cache. |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 719 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | * |
| 721 | * @return the Bluetooth name, or null if there was a problem. |
| 722 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 723 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | public String getName() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 725 | if (sService == null) { |
| 726 | Log.e(TAG, "BT not enabled. Cannot get Remote Device name"); |
| 727 | return null; |
| 728 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 730 | return sService.getRemoteName(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 732 | return null; |
| 733 | } |
| 734 | |
| 735 | /** |
Matthew Xie | 33ec984 | 2013-04-03 00:29:27 -0700 | [diff] [blame] | 736 | * Get the Bluetooth device type of the remote device. |
| 737 | * |
| 738 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
| 739 | * |
| 740 | * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE} |
| 741 | * {@link #DEVICE_TYPE_DUAL}. |
| 742 | * {@link #DEVICE_TYPE_UNKNOWN} if it's not available |
| 743 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 744 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Matthew Xie | 33ec984 | 2013-04-03 00:29:27 -0700 | [diff] [blame] | 745 | public int getType() { |
| 746 | if (sService == null) { |
| 747 | Log.e(TAG, "BT not enabled. Cannot get Remote Device type"); |
| 748 | return DEVICE_TYPE_UNKNOWN; |
| 749 | } |
| 750 | try { |
| 751 | return sService.getRemoteType(this); |
| 752 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 753 | return DEVICE_TYPE_UNKNOWN; |
| 754 | } |
| 755 | |
| 756 | /** |
Matthew Xie | 269e81a | 2011-07-26 18:36:49 -0700 | [diff] [blame] | 757 | * Get the Bluetooth alias of the remote device. |
| 758 | * <p>Alias is the locally modified name of a remote device. |
| 759 | * |
| 760 | * @return the Bluetooth alias, or null if no alias or there was a problem |
| 761 | * @hide |
| 762 | */ |
| 763 | public String getAlias() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 764 | if (sService == null) { |
| 765 | Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias"); |
| 766 | return null; |
| 767 | } |
Matthew Xie | 269e81a | 2011-07-26 18:36:49 -0700 | [diff] [blame] | 768 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 769 | return sService.getRemoteAlias(this); |
Matthew Xie | 269e81a | 2011-07-26 18:36:49 -0700 | [diff] [blame] | 770 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 771 | return null; |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * Set the Bluetooth alias of the remote device. |
| 776 | * <p>Alias is the locally modified name of a remote device. |
| 777 | * <p>This methoid overwrites the alias. The changed |
| 778 | * alias is saved in the local storage so that the change |
| 779 | * is preserved over power cycle. |
| 780 | * |
| 781 | * @return true on success, false on error |
| 782 | * @hide |
| 783 | */ |
| 784 | public boolean setAlias(String alias) { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 785 | if (sService == null) { |
| 786 | Log.e(TAG, "BT not enabled. Cannot set Remote Device name"); |
| 787 | return false; |
| 788 | } |
Matthew Xie | 269e81a | 2011-07-26 18:36:49 -0700 | [diff] [blame] | 789 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 790 | return sService.setRemoteAlias(this, alias); |
Matthew Xie | 269e81a | 2011-07-26 18:36:49 -0700 | [diff] [blame] | 791 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 792 | return false; |
| 793 | } |
| 794 | |
| 795 | /** |
| 796 | * Get the Bluetooth alias of the remote device. |
| 797 | * If Alias is null, get the Bluetooth name instead. |
| 798 | * @see #getAlias() |
| 799 | * @see #getName() |
| 800 | * |
| 801 | * @return the Bluetooth alias, or null if no alias or there was a problem |
| 802 | * @hide |
| 803 | */ |
| 804 | public String getAliasName() { |
| 805 | String name = getAlias(); |
| 806 | if (name == null) { |
| 807 | name = getName(); |
| 808 | } |
| 809 | return name; |
| 810 | } |
| 811 | |
| 812 | /** |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 813 | * Start the bonding (pairing) process with the remote device. |
| 814 | * <p>This is an asynchronous call, it will return immediately. Register |
| 815 | * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when |
| 816 | * the bonding process completes, and its result. |
| 817 | * <p>Android system services will handle the necessary user interactions |
| 818 | * to confirm and complete the bonding process. |
Matthew Xie | ac2c6c3 | 2013-10-21 14:56:33 -0700 | [diff] [blame] | 819 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | * |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 821 | * @return false on immediate error, true if bonding will begin |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 823 | @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 824 | public boolean createBond() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 825 | if (sService == null) { |
| 826 | Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device"); |
| 827 | return false; |
| 828 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | try { |
Christine Hallstrom | 044b8f3 | 2015-11-17 12:24:07 -0800 | [diff] [blame] | 830 | Log.i(TAG, "createBond() for device " + getAddress() + |
| 831 | " called by pid: " + Process.myPid() + |
| 832 | " tid: " + Process.myTid()); |
Andre Eisenbach | 57210c7 | 2014-08-04 17:51:43 -0700 | [diff] [blame] | 833 | return sService.createBond(this, TRANSPORT_AUTO); |
| 834 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 835 | return false; |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Start the bonding (pairing) process with the remote device using the |
| 840 | * specified transport. |
| 841 | * |
| 842 | * <p>This is an asynchronous call, it will return immediately. Register |
| 843 | * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when |
| 844 | * the bonding process completes, and its result. |
| 845 | * <p>Android system services will handle the necessary user interactions |
| 846 | * to confirm and complete the bonding process. |
| 847 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. |
| 848 | * |
| 849 | * @param transport The transport to use for the pairing procedure. |
| 850 | * @return false on immediate error, true if bonding will begin |
| 851 | * @throws IllegalArgumentException if an invalid transport was specified |
| 852 | * @hide |
| 853 | */ |
| 854 | public boolean createBond(int transport) { |
| 855 | if (sService == null) { |
| 856 | Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device"); |
| 857 | return false; |
| 858 | } |
| 859 | if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE) |
| 860 | { |
| 861 | throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport"); |
| 862 | } |
| 863 | try { |
Christine Hallstrom | 044b8f3 | 2015-11-17 12:24:07 -0800 | [diff] [blame] | 864 | Log.i(TAG, "createBond() for device " + getAddress() + |
| 865 | " called by pid: " + Process.myPid() + |
| 866 | " tid: " + Process.myTid()); |
Andre Eisenbach | 57210c7 | 2014-08-04 17:51:43 -0700 | [diff] [blame] | 867 | return sService.createBond(this, transport); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 869 | return false; |
| 870 | } |
| 871 | |
| 872 | /** |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 873 | * Start the bonding (pairing) process with the remote device using the |
| 874 | * Out Of Band mechanism. |
| 875 | * |
| 876 | * <p>This is an asynchronous call, it will return immediately. Register |
| 877 | * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when |
| 878 | * the bonding process completes, and its result. |
| 879 | * |
| 880 | * <p>Android system services will handle the necessary user interactions |
| 881 | * to confirm and complete the bonding process. |
| 882 | * |
| 883 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. |
| 884 | * |
Jakub Pawlowski | 2fc6e6b | 2015-12-29 13:19:21 -0800 | [diff] [blame] | 885 | * @param transport - Transport to use |
| 886 | * @param oobData - Out Of Band data |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 887 | * @return false on immediate error, true if bonding will begin |
| 888 | * |
| 889 | * @hide |
| 890 | */ |
Jakub Pawlowski | 2fc6e6b | 2015-12-29 13:19:21 -0800 | [diff] [blame] | 891 | public boolean createBondOutOfBand(int transport, OobData oobData) { |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 892 | try { |
Jakub Pawlowski | 2fc6e6b | 2015-12-29 13:19:21 -0800 | [diff] [blame] | 893 | return sService.createBondOutOfBand(this, transport, oobData); |
| 894 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 895 | return false; |
| 896 | } |
| 897 | |
| 898 | /** |
| 899 | * Set the Out Of Band data for a remote device to be used later |
| 900 | * in the pairing mechanism. Users can obtain this data through other |
| 901 | * trusted channels |
| 902 | * |
| 903 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. |
| 904 | * |
| 905 | * @param hash Simple Secure pairing hash |
| 906 | * @param randomizer The random key obtained using OOB |
| 907 | * @return false on error; true otherwise |
| 908 | * |
| 909 | * @hide |
| 910 | */ |
| 911 | public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 912 | //TODO(BT) |
| 913 | /* |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 914 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 915 | return sService.setDeviceOutOfBandData(this, hash, randomizer); |
| 916 | } catch (RemoteException e) {Log.e(TAG, "", e);} */ |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 917 | return false; |
| 918 | } |
| 919 | |
| 920 | /** |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 921 | * Cancel an in-progress bonding request started with {@link #createBond}. |
| 922 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. |
| 923 | * |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 924 | * @return true on success, false on error |
Nick Pelly | 18b1e79 | 2009-09-24 11:14:15 -0700 | [diff] [blame] | 925 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | */ |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 927 | public boolean cancelBondProcess() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 928 | if (sService == null) { |
| 929 | Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond"); |
| 930 | return false; |
| 931 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | try { |
Christine Hallstrom | 044b8f3 | 2015-11-17 12:24:07 -0800 | [diff] [blame] | 933 | Log.i(TAG, "cancelBondProcess() for device " + getAddress() + |
| 934 | " called by pid: " + Process.myPid() + |
| 935 | " tid: " + Process.myTid()); |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 936 | return sService.cancelBondProcess(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 938 | return false; |
| 939 | } |
| 940 | |
| 941 | /** |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 942 | * Remove bond (pairing) with the remote device. |
| 943 | * <p>Delete the link key associated with the remote device, and |
| 944 | * immediately terminate connections to that device that require |
| 945 | * authentication and encryption. |
| 946 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | * |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 948 | * @return true on success, false on error |
Nick Pelly | 18b1e79 | 2009-09-24 11:14:15 -0700 | [diff] [blame] | 949 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | */ |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 951 | public boolean removeBond() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 952 | if (sService == null) { |
| 953 | Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond"); |
| 954 | return false; |
| 955 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | try { |
Christine Hallstrom | 044b8f3 | 2015-11-17 12:24:07 -0800 | [diff] [blame] | 957 | Log.i(TAG, "removeBond() for device " + getAddress() + |
| 958 | " called by pid: " + Process.myPid() + |
| 959 | " tid: " + Process.myTid()); |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 960 | return sService.removeBond(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 962 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | /** |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 966 | * Get the bond state of the remote device. |
| 967 | * <p>Possible values for the bond state are: |
| 968 | * {@link #BOND_NONE}, |
| 969 | * {@link #BOND_BONDING}, |
| 970 | * {@link #BOND_BONDED}. |
| 971 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | * |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 973 | * @return the bond state |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 975 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 976 | public int getBondState() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 977 | if (sService == null) { |
| 978 | Log.e(TAG, "BT not enabled. Cannot get bond state"); |
| 979 | return BOND_NONE; |
| 980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 982 | return sService.getBondState(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
Syed Ibrahim M | 305f240 | 2012-06-19 10:14:25 -0700 | [diff] [blame] | 984 | catch (NullPointerException npe) { |
| 985 | // Handle case where bluetooth service proxy |
| 986 | // is already null. |
| 987 | Log.e(TAG, "NullPointerException for getBondState() of device ("+ |
| 988 | getAddress()+")", npe); |
| 989 | } |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 990 | return BOND_NONE; |
| 991 | } |
| 992 | |
| 993 | /** |
Jay Civelli | 174928c | 2014-05-08 09:24:08 -0700 | [diff] [blame] | 994 | * Returns whether there is an open connection to this device. |
| 995 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 996 | * |
| 997 | * @return True if there is at least one open connection to this device. |
| 998 | * @hide |
| 999 | */ |
Andre Eisenbach | 2b8696e | 2015-02-05 20:06:33 -0800 | [diff] [blame] | 1000 | @SystemApi |
Jay Civelli | 174928c | 2014-05-08 09:24:08 -0700 | [diff] [blame] | 1001 | public boolean isConnected() { |
| 1002 | if (sService == null) { |
| 1003 | // BT is not enabled, we cannot be connected. |
| 1004 | return false; |
| 1005 | } |
| 1006 | try { |
Andre Eisenbach | 2b8696e | 2015-02-05 20:06:33 -0800 | [diff] [blame] | 1007 | return sService.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED; |
| 1008 | } catch (RemoteException e) { |
| 1009 | Log.e(TAG, "", e); |
| 1010 | return false; |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * Returns whether there is an open connection to this device |
| 1016 | * that has been encrypted. |
| 1017 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 1018 | * |
| 1019 | * @return True if there is at least one encrypted connection to this device. |
| 1020 | * @hide |
| 1021 | */ |
| 1022 | @SystemApi |
| 1023 | public boolean isEncrypted() { |
| 1024 | if (sService == null) { |
| 1025 | // BT is not enabled, we cannot be connected. |
| 1026 | return false; |
| 1027 | } |
| 1028 | try { |
| 1029 | return sService.getConnectionState(this) > CONNECTION_STATE_CONNECTED; |
Jay Civelli | 174928c | 2014-05-08 09:24:08 -0700 | [diff] [blame] | 1030 | } catch (RemoteException e) { |
| 1031 | Log.e(TAG, "", e); |
| 1032 | return false; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | /** |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1037 | * Get the Bluetooth class of the remote device. |
| 1038 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 1039 | * |
| 1040 | * @return Bluetooth class object, or null on error |
| 1041 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 1042 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1043 | public BluetoothClass getBluetoothClass() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 1044 | if (sService == null) { |
| 1045 | Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class"); |
| 1046 | return null; |
| 1047 | } |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1048 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1049 | int classInt = sService.getRemoteClass(this); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1050 | if (classInt == BluetoothClass.ERROR) return null; |
| 1051 | return new BluetoothClass(classInt); |
| 1052 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 1053 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 1056 | /** |
Matthew Xie | ad23210 | 2011-11-08 10:58:12 -0800 | [diff] [blame] | 1057 | * Returns the supported features (UUIDs) of the remote device. |
| 1058 | * |
| 1059 | * <p>This method does not start a service discovery procedure to retrieve the UUIDs |
| 1060 | * from the remote device. Instead, the local cached copy of the service |
| 1061 | * UUIDs are returned. |
| 1062 | * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired. |
| 1063 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 1064 | * |
| 1065 | * @return the supported features (UUIDs) of the remote device, |
| 1066 | * or null on error |
| 1067 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 1068 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 1069 | public ParcelUuid[] getUuids() { |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 1070 | if (sService == null || isBluetoothEnabled() == false) { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 1071 | Log.e(TAG, "BT not enabled. Cannot get remote device Uuids"); |
| 1072 | return null; |
| 1073 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1075 | return sService.getRemoteUuids(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 1077 | return null; |
| 1078 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1079 | |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1080 | /** |
Matthew Xie | ad23210 | 2011-11-08 10:58:12 -0800 | [diff] [blame] | 1081 | * Perform a service discovery on the remote device to get the UUIDs supported. |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1082 | * |
Matthew Xie | ad23210 | 2011-11-08 10:58:12 -0800 | [diff] [blame] | 1083 | * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent, |
| 1084 | * with the UUIDs supported by the remote end. If there is an error |
| 1085 | * in getting the SDP records or if the process takes a long time, |
| 1086 | * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently |
| 1087 | * present in the cache. Clients should use the {@link #getUuids} to get UUIDs |
| 1088 | * if service discovery is not to be performed. |
| 1089 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 1090 | * |
| 1091 | * @return False if the sanity check fails, True if the process |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1092 | * of initiating an ACL connection to the remote device |
| 1093 | * was started. |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1094 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 1095 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1096 | public boolean fetchUuidsWithSdp() { |
Zhihai Xu | 5d04f1c | 2014-01-13 16:54:38 -0800 | [diff] [blame] | 1097 | IBluetooth service = sService; |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 1098 | if (service == null || isBluetoothEnabled() == false) { |
Zhihai Xu | 5d04f1c | 2014-01-13 16:54:38 -0800 | [diff] [blame] | 1099 | Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp"); |
| 1100 | return false; |
| 1101 | } |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1102 | try { |
Zhihai Xu | 5d04f1c | 2014-01-13 16:54:38 -0800 | [diff] [blame] | 1103 | return service.fetchRemoteUuids(this); |
fredc | 4c9caca | 2012-04-06 02:08:46 -0700 | [diff] [blame] | 1104 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 1105 | return false; |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Casper Bonde | 238e0f9 | 2015-04-09 09:24:48 +0200 | [diff] [blame] | 1108 | /** |
| 1109 | * Perform a service discovery on the remote device to get the SDP records associated |
| 1110 | * with the specified UUID. |
| 1111 | * |
| 1112 | * <p>This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent, |
| 1113 | * with the SDP records found on the remote end. If there is an error |
| 1114 | * in getting the SDP records or if the process takes a long time, |
| 1115 | * {@link #ACTION_SDP_RECORD} intent is sent with an status value in |
| 1116 | * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0. |
| 1117 | * Detailed status error codes can be found by members of the Bluetooth package in |
| 1118 | * the AbstractionLayer class. |
| 1119 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 1120 | * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}. |
| 1121 | * The object type will match one of the SdpXxxRecord types, depending on the UUID searched |
| 1122 | * for. |
| 1123 | * |
| 1124 | * @return False if the sanity check fails, True if the process |
| 1125 | * of initiating an ACL connection to the remote device |
| 1126 | * was started. |
| 1127 | */ |
Hemant Gupta | 8949bfb | 2013-08-16 14:57:55 +0530 | [diff] [blame] | 1128 | /** @hide */ |
Casper Bonde | 238e0f9 | 2015-04-09 09:24:48 +0200 | [diff] [blame] | 1129 | public boolean sdpSearch(ParcelUuid uuid) { |
Hemant Gupta | 8949bfb | 2013-08-16 14:57:55 +0530 | [diff] [blame] | 1130 | if (sService == null) { |
Casper Bonde | 238e0f9 | 2015-04-09 09:24:48 +0200 | [diff] [blame] | 1131 | Log.e(TAG, "BT not enabled. Cannot query remote device sdp records"); |
Hemant Gupta | 8949bfb | 2013-08-16 14:57:55 +0530 | [diff] [blame] | 1132 | return false; |
| 1133 | } |
| 1134 | try { |
Casper Bonde | 238e0f9 | 2015-04-09 09:24:48 +0200 | [diff] [blame] | 1135 | return sService.sdpSearch(this,uuid); |
Hemant Gupta | 8949bfb | 2013-08-16 14:57:55 +0530 | [diff] [blame] | 1136 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 1137 | return false; |
| 1138 | } |
| 1139 | |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 1140 | /** |
| 1141 | * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN} |
Matthew Xie | ac2c6c3 | 2013-10-21 14:56:33 -0700 | [diff] [blame] | 1142 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 1143 | * |
| 1144 | * @return true pin has been set |
| 1145 | * false for error |
| 1146 | */ |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1147 | public boolean setPin(byte[] pin) { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 1148 | if (sService == null) { |
| 1149 | Log.e(TAG, "BT not enabled. Cannot set Remote Device pin"); |
| 1150 | return false; |
| 1151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1153 | return sService.setPin(this, true, pin.length, pin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 1155 | return false; |
| 1156 | } |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 1157 | |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1158 | /** @hide */ |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1159 | public boolean setPasskey(int passkey) { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1160 | //TODO(BT) |
| 1161 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1162 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1163 | return sService.setPasskey(this, true, 4, passkey); |
| 1164 | } catch (RemoteException e) {Log.e(TAG, "", e);}*/ |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 1165 | return false; |
| 1166 | } |
| 1167 | |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 1168 | /** |
| 1169 | * Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing. |
Marie Janssen | 93326cf | 2016-08-09 13:23:39 -0700 | [diff] [blame] | 1170 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. |
Matthew Xie | 091fc2b | 2013-09-23 23:23:13 -0700 | [diff] [blame] | 1171 | * |
| 1172 | * @return true confirmation has been sent out |
| 1173 | * false for error |
| 1174 | */ |
Marie Janssen | 93326cf | 2016-08-09 13:23:39 -0700 | [diff] [blame] | 1175 | @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED) |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1176 | public boolean setPairingConfirmation(boolean confirm) { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 1177 | if (sService == null) { |
| 1178 | Log.e(TAG, "BT not enabled. Cannot set pairing confirmation"); |
| 1179 | return false; |
| 1180 | } |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 1181 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1182 | return sService.setPairingConfirmation(this, confirm); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 1183 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 1184 | return false; |
| 1185 | } |
| 1186 | |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1187 | /** @hide */ |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 1188 | public boolean setRemoteOutOfBandData() { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1189 | // TODO(BT) |
| 1190 | /* |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 1191 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1192 | return sService.setRemoteOutOfBandData(this); |
| 1193 | } catch (RemoteException e) {Log.e(TAG, "", e);}*/ |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 1194 | return false; |
| 1195 | } |
| 1196 | |
| 1197 | /** @hide */ |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1198 | public boolean cancelPairingUserInput() { |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 1199 | if (sService == null) { |
| 1200 | Log.e(TAG, "BT not enabled. Cannot create pairing user input"); |
| 1201 | return false; |
| 1202 | } |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 1203 | try { |
Ravi Nagarajan | 919a4c6 | 2012-04-13 21:18:16 +0530 | [diff] [blame] | 1204 | return sService.cancelBondProcess(this); |
Priti Aghera | db44b20 | 2012-03-13 10:41:41 -0700 | [diff] [blame] | 1205 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | return false; |
| 1207 | } |
| 1208 | |
Jaikumar Ganesh | 3fbf7b6 | 2009-12-02 17:28:38 -0800 | [diff] [blame] | 1209 | /** @hide */ |
| 1210 | public boolean isBluetoothDock() { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1211 | // TODO(BT) |
| 1212 | /* |
Jaikumar Ganesh | 3fbf7b6 | 2009-12-02 17:28:38 -0800 | [diff] [blame] | 1213 | try { |
Jaikumar Ganesh | e4caddb | 2012-01-25 16:16:48 -0800 | [diff] [blame] | 1214 | return sService.isBluetoothDock(this); |
| 1215 | } catch (RemoteException e) {Log.e(TAG, "", e);}*/ |
Jaikumar Ganesh | 3fbf7b6 | 2009-12-02 17:28:38 -0800 | [diff] [blame] | 1216 | return false; |
| 1217 | } |
| 1218 | |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 1219 | boolean isBluetoothEnabled() { |
| 1220 | boolean ret = false; |
| 1221 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
| 1222 | if (adapter != null && adapter.isEnabled() == true) { |
| 1223 | ret = true; |
| 1224 | } |
| 1225 | return ret; |
| 1226 | } |
| 1227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | /** |
Edward Jee | 8dd30aa | 2014-09-05 00:29:14 -0700 | [diff] [blame] | 1229 | * Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 1230 | * @return Whether the phonebook access is allowed to this device. Can be |
| 1231 | * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. |
| 1232 | * @hide |
| 1233 | */ |
| 1234 | public int getPhonebookAccessPermission() { |
| 1235 | if (sService == null) { |
| 1236 | return ACCESS_UNKNOWN; |
| 1237 | } |
| 1238 | try { |
| 1239 | return sService.getPhonebookAccessPermission(this); |
| 1240 | } catch (RemoteException e) { |
| 1241 | Log.e(TAG, "", e); |
| 1242 | } |
| 1243 | return ACCESS_UNKNOWN; |
| 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * Sets whether the phonebook access is allowed to this device. |
| 1248 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. |
| 1249 | * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or |
| 1250 | * {@link #ACCESS_REJECTED}. |
| 1251 | * @return Whether the value has been successfully set. |
| 1252 | * @hide |
| 1253 | */ |
| 1254 | public boolean setPhonebookAccessPermission(int value) { |
| 1255 | if (sService == null) { |
| 1256 | return false; |
| 1257 | } |
| 1258 | try { |
| 1259 | return sService.setPhonebookAccessPermission(this, value); |
| 1260 | } catch (RemoteException e) { |
| 1261 | Log.e(TAG, "", e); |
| 1262 | } |
| 1263 | return false; |
| 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 1268 | * @return Whether the message access is allowed to this device. Can be |
| 1269 | * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. |
| 1270 | * @hide |
| 1271 | */ |
| 1272 | public int getMessageAccessPermission() { |
| 1273 | if (sService == null) { |
| 1274 | return ACCESS_UNKNOWN; |
| 1275 | } |
| 1276 | try { |
| 1277 | return sService.getMessageAccessPermission(this); |
| 1278 | } catch (RemoteException e) { |
| 1279 | Log.e(TAG, "", e); |
| 1280 | } |
| 1281 | return ACCESS_UNKNOWN; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * Sets whether the message access is allowed to this device. |
| 1286 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. |
| 1287 | * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or |
| 1288 | * {@link #ACCESS_REJECTED}. |
| 1289 | * @return Whether the value has been successfully set. |
| 1290 | * @hide |
| 1291 | */ |
| 1292 | public boolean setMessageAccessPermission(int value) { |
| 1293 | if (sService == null) { |
| 1294 | return false; |
| 1295 | } |
| 1296 | try { |
| 1297 | return sService.setMessageAccessPermission(this, value); |
| 1298 | } catch (RemoteException e) { |
| 1299 | Log.e(TAG, "", e); |
| 1300 | } |
| 1301 | return false; |
| 1302 | } |
| 1303 | |
| 1304 | /** |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 1305 | * Requires {@link android.Manifest.permission#BLUETOOTH}. |
| 1306 | * @return Whether the Sim access is allowed to this device. Can be |
| 1307 | * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. |
| 1308 | * @hide |
| 1309 | */ |
| 1310 | public int getSimAccessPermission() { |
| 1311 | if (sService == null) { |
| 1312 | return ACCESS_UNKNOWN; |
| 1313 | } |
| 1314 | try { |
| 1315 | return sService.getSimAccessPermission(this); |
| 1316 | } catch (RemoteException e) { |
| 1317 | Log.e(TAG, "", e); |
| 1318 | } |
| 1319 | return ACCESS_UNKNOWN; |
| 1320 | } |
| 1321 | |
| 1322 | /** |
| 1323 | * Sets whether the Sim access is allowed to this device. |
| 1324 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. |
| 1325 | * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or |
| 1326 | * {@link #ACCESS_REJECTED}. |
| 1327 | * @return Whether the value has been successfully set. |
| 1328 | * @hide |
| 1329 | */ |
| 1330 | public boolean setSimAccessPermission(int value) { |
| 1331 | if (sService == null) { |
| 1332 | return false; |
| 1333 | } |
| 1334 | try { |
| 1335 | return sService.setSimAccessPermission(this, value); |
| 1336 | } catch (RemoteException e) { |
| 1337 | Log.e(TAG, "", e); |
| 1338 | } |
| 1339 | return false; |
Casper Bonde | 3b3d1fe | 2015-05-08 14:32:24 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 1342 | /** |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1343 | * Create an RFCOMM {@link BluetoothSocket} ready to start a secure |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1344 | * outgoing connection to this remote device on given channel. |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1345 | * <p>The remote device will be authenticated and communication on this |
| 1346 | * socket will be encrypted. |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 1347 | * <p> Use this socket only if an authenticated socket link is possible. |
| 1348 | * Authentication refers to the authentication of the link key to |
| 1349 | * prevent man-in-the-middle type of attacks. |
| 1350 | * For example, for Bluetooth 2.1 devices, if any of the devices does not |
| 1351 | * have an input and output capability or just has the ability to |
| 1352 | * display a numeric key, a secure socket connection is not possible. |
| 1353 | * In such a case, use {#link createInsecureRfcommSocket}. |
| 1354 | * For more details, refer to the Security Model section 5.2 (vol 3) of |
| 1355 | * Bluetooth Core Specification version 2.1 + EDR. |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 1356 | * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1357 | * connection. |
| 1358 | * <p>Valid RFCOMM channels are in range 1 to 30. |
Nick Pelly | cf44059 | 2009-09-08 10:12:06 -0700 | [diff] [blame] | 1359 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 1360 | * |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1361 | * @param channel RFCOMM channel to connect to |
| 1362 | * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1363 | * @throws IOException on error, for example Bluetooth not available, or |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1364 | * insufficient permissions |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1365 | * @hide |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1366 | */ |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1367 | public BluetoothSocket createRfcommSocket(int channel) throws IOException { |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 1368 | if (isBluetoothEnabled() == false) { |
| 1369 | Log.e(TAG, "Bluetooth is not enabled"); |
| 1370 | throw new IOException(); |
| 1371 | } |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1372 | return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel, |
| 1373 | null); |
| 1374 | } |
| 1375 | |
| 1376 | /** |
Casper Bonde | 238e0f9 | 2015-04-09 09:24:48 +0200 | [diff] [blame] | 1377 | * Create an L2cap {@link BluetoothSocket} ready to start a secure |
| 1378 | * outgoing connection to this remote device on given channel. |
| 1379 | * <p>The remote device will be authenticated and communication on this |
| 1380 | * socket will be encrypted. |
| 1381 | * <p> Use this socket only if an authenticated socket link is possible. |
| 1382 | * Authentication refers to the authentication of the link key to |
| 1383 | * prevent man-in-the-middle type of attacks. |
| 1384 | * For example, for Bluetooth 2.1 devices, if any of the devices does not |
| 1385 | * have an input and output capability or just has the ability to |
| 1386 | * display a numeric key, a secure socket connection is not possible. |
| 1387 | * In such a case, use {#link createInsecureRfcommSocket}. |
| 1388 | * For more details, refer to the Security Model section 5.2 (vol 3) of |
| 1389 | * Bluetooth Core Specification version 2.1 + EDR. |
| 1390 | * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing |
| 1391 | * connection. |
| 1392 | * <p>Valid L2CAP PSM channels are in range 1 to 2^16. |
| 1393 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
| 1394 | * |
| 1395 | * @param channel L2cap PSM/channel to connect to |
| 1396 | * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection |
| 1397 | * @throws IOException on error, for example Bluetooth not available, or |
| 1398 | * insufficient permissions |
| 1399 | * @hide |
| 1400 | */ |
| 1401 | public BluetoothSocket createL2capSocket(int channel) throws IOException { |
| 1402 | return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, true, true, this, channel, |
| 1403 | null); |
| 1404 | } |
| 1405 | |
| 1406 | /** |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1407 | * Create an RFCOMM {@link BluetoothSocket} ready to start a secure |
| 1408 | * outgoing connection to this remote device using SDP lookup of uuid. |
| 1409 | * <p>This is designed to be used with {@link |
| 1410 | * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer |
| 1411 | * Bluetooth applications. |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 1412 | * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1413 | * connection. This will also perform an SDP lookup of the given uuid to |
| 1414 | * determine which channel to connect to. |
| 1415 | * <p>The remote device will be authenticated and communication on this |
| 1416 | * socket will be encrypted. |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 1417 | * <p> Use this socket only if an authenticated socket link is possible. |
| 1418 | * Authentication refers to the authentication of the link key to |
| 1419 | * prevent man-in-the-middle type of attacks. |
| 1420 | * For example, for Bluetooth 2.1 devices, if any of the devices does not |
| 1421 | * have an input and output capability or just has the ability to |
| 1422 | * display a numeric key, a secure socket connection is not possible. |
| 1423 | * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}. |
| 1424 | * For more details, refer to the Security Model section 5.2 (vol 3) of |
| 1425 | * Bluetooth Core Specification version 2.1 + EDR. |
Nick Pelly | ea5056e | 2010-02-24 11:19:10 -0800 | [diff] [blame] | 1426 | * <p>Hint: If you are connecting to a Bluetooth serial board then try |
| 1427 | * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. |
| 1428 | * However if you are connecting to an Android peer then please generate |
| 1429 | * your own unique UUID. |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1430 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
| 1431 | * |
| 1432 | * @param uuid service record uuid to lookup RFCOMM channel |
| 1433 | * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection |
| 1434 | * @throws IOException on error, for example Bluetooth not available, or |
| 1435 | * insufficient permissions |
| 1436 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 1437 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1438 | public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException { |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 1439 | if (isBluetoothEnabled() == false) { |
| 1440 | Log.e(TAG, "Bluetooth is not enabled"); |
| 1441 | throw new IOException(); |
| 1442 | } |
| 1443 | |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1444 | return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1, |
| 1445 | new ParcelUuid(uuid)); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /** |
Jaikumar Ganesh | 6eef14a | 2010-12-23 12:57:02 -0800 | [diff] [blame] | 1449 | * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure |
| 1450 | * outgoing connection to this remote device using SDP lookup of uuid. |
| 1451 | * <p> The communication channel will not have an authenticated link key |
| 1452 | * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1 |
| 1453 | * devices, the link key will be encrypted, as encryption is mandatory. |
| 1454 | * For legacy devices (pre Bluetooth 2.1 devices) the link key will |
| 1455 | * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an |
| 1456 | * encrypted and authenticated communication channel is desired. |
| 1457 | * <p>This is designed to be used with {@link |
| 1458 | * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer |
| 1459 | * Bluetooth applications. |
| 1460 | * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing |
| 1461 | * connection. This will also perform an SDP lookup of the given uuid to |
| 1462 | * determine which channel to connect to. |
| 1463 | * <p>The remote device will be authenticated and communication on this |
| 1464 | * socket will be encrypted. |
| 1465 | * <p>Hint: If you are connecting to a Bluetooth serial board then try |
| 1466 | * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. |
| 1467 | * However if you are connecting to an Android peer then please generate |
| 1468 | * your own unique UUID. |
| 1469 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
| 1470 | * |
| 1471 | * @param uuid service record uuid to lookup RFCOMM channel |
| 1472 | * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection |
| 1473 | * @throws IOException on error, for example Bluetooth not available, or |
| 1474 | * insufficient permissions |
| 1475 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 1476 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Jaikumar Ganesh | 6eef14a | 2010-12-23 12:57:02 -0800 | [diff] [blame] | 1477 | public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException { |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 1478 | if (isBluetoothEnabled() == false) { |
| 1479 | Log.e(TAG, "Bluetooth is not enabled"); |
| 1480 | throw new IOException(); |
| 1481 | } |
Jaikumar Ganesh | 6eef14a | 2010-12-23 12:57:02 -0800 | [diff] [blame] | 1482 | return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1, |
| 1483 | new ParcelUuid(uuid)); |
| 1484 | } |
| 1485 | |
| 1486 | /** |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1487 | * Construct an insecure RFCOMM socket ready to start an outgoing |
| 1488 | * connection. |
| 1489 | * Call #connect on the returned #BluetoothSocket to begin the connection. |
| 1490 | * The remote device will not be authenticated and communication on this |
| 1491 | * socket will not be encrypted. |
Nick Pelly | e6ee3be | 2009-10-08 23:27:28 +0200 | [diff] [blame] | 1492 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 1493 | * |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1494 | * @param port remote port |
| 1495 | * @return An RFCOMM BluetoothSocket |
| 1496 | * @throws IOException On error, for example Bluetooth not available, or |
| 1497 | * insufficient permissions. |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1498 | * @hide |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1499 | */ |
| 1500 | public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException { |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 1501 | |
| 1502 | if (isBluetoothEnabled() == false) { |
| 1503 | Log.e(TAG, "Bluetooth is not enabled"); |
| 1504 | throw new IOException(); |
| 1505 | } |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1506 | return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port, |
| 1507 | null); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * Construct a SCO socket ready to start an outgoing connection. |
| 1512 | * Call #connect on the returned #BluetoothSocket to begin the connection. |
Nick Pelly | e6ee3be | 2009-10-08 23:27:28 +0200 | [diff] [blame] | 1513 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 1514 | * |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1515 | * @return a SCO BluetoothSocket |
| 1516 | * @throws IOException on error, for example Bluetooth not available, or |
| 1517 | * insufficient permissions. |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1518 | * @hide |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1519 | */ |
| 1520 | public BluetoothSocket createScoSocket() throws IOException { |
Nitin Arora | d055adb | 2015-03-02 15:03:51 -0800 | [diff] [blame] | 1521 | |
| 1522 | if (isBluetoothEnabled() == false) { |
| 1523 | Log.e(TAG, "Bluetooth is not enabled"); |
| 1524 | throw new IOException(); |
| 1525 | } |
Nick Pelly | 16fb88a | 2009-10-07 07:44:03 +0200 | [diff] [blame] | 1526 | return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | * Check that a pin is valid and convert to byte array. |
| 1531 | * |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 1532 | * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | * @param pin pin as java String |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 1534 | * @return the pin code as a UTF-8 byte array, or null if it is an invalid |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1535 | * Bluetooth pin. |
Nick Pelly | 45e2704 | 2009-08-19 11:00:00 -0700 | [diff] [blame] | 1536 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | */ |
| 1538 | public static byte[] convertPinToBytes(String pin) { |
| 1539 | if (pin == null) { |
| 1540 | return null; |
| 1541 | } |
| 1542 | byte[] pinBytes; |
| 1543 | try { |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 1544 | pinBytes = pin.getBytes("UTF-8"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | } catch (UnsupportedEncodingException uee) { |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 1546 | Log.e(TAG, "UTF-8 not supported?!?"); // this should not happen |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | return null; |
| 1548 | } |
| 1549 | if (pinBytes.length <= 0 || pinBytes.length > 16) { |
| 1550 | return null; |
| 1551 | } |
| 1552 | return pinBytes; |
| 1553 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1554 | |
Matthew Xie | ddf7e47 | 2013-03-01 18:41:02 -0800 | [diff] [blame] | 1555 | /** |
| 1556 | * Connect to GATT Server hosted by this device. Caller acts as GATT client. |
| 1557 | * The callback is used to deliver results to Caller, such as connection status as well |
| 1558 | * as any further GATT client operations. |
| 1559 | * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct |
| 1560 | * GATT client operations. |
| 1561 | * @param callback GATT callback handler that will receive asynchronous callbacks. |
| 1562 | * @param autoConnect Whether to directly connect to the remote device (false) |
| 1563 | * or to automatically connect as soon as the remote |
| 1564 | * device becomes available (true). |
| 1565 | * @throws IllegalArgumentException if callback is null |
| 1566 | */ |
Matthew Xie | 33ec984 | 2013-04-03 00:29:27 -0700 | [diff] [blame] | 1567 | public BluetoothGatt connectGatt(Context context, boolean autoConnect, |
| 1568 | BluetoothGattCallback callback) { |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 1569 | return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO)); |
| 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * Connect to GATT Server hosted by this device. Caller acts as GATT client. |
| 1574 | * The callback is used to deliver results to Caller, such as connection status as well |
| 1575 | * as any further GATT client operations. |
| 1576 | * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct |
| 1577 | * GATT client operations. |
| 1578 | * @param callback GATT callback handler that will receive asynchronous callbacks. |
| 1579 | * @param autoConnect Whether to directly connect to the remote device (false) |
| 1580 | * or to automatically connect as soon as the remote |
| 1581 | * device becomes available (true). |
| 1582 | * @param transport preferred transport for GATT connections to remote dual-mode devices |
| 1583 | * {@link BluetoothDevice#TRANSPORT_AUTO} or |
| 1584 | * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE} |
| 1585 | * @throws IllegalArgumentException if callback is null |
Ganesh Ganapathi Batta | b88fa82 | 2014-04-18 10:00:40 -0700 | [diff] [blame] | 1586 | */ |
| 1587 | public BluetoothGatt connectGatt(Context context, boolean autoConnect, |
| 1588 | BluetoothGattCallback callback, int transport) { |
Matthew Xie | ddf7e47 | 2013-03-01 18:41:02 -0800 | [diff] [blame] | 1589 | // TODO(Bluetooth) check whether platform support BLE |
| 1590 | // Do the check here or in GattServer? |
| 1591 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
| 1592 | IBluetoothManager managerService = adapter.getBluetoothManager(); |
| 1593 | try { |
| 1594 | IBluetoothGatt iGatt = managerService.getBluetoothGatt(); |
Matthew Xie | 32ab77b | 2013-05-08 19:26:57 -0700 | [diff] [blame] | 1595 | if (iGatt == null) { |
| 1596 | // BLE is not supported |
| 1597 | return null; |
| 1598 | } |
Jeremy Klein | adc26ec | 2016-09-27 14:34:33 -0700 | [diff] [blame] | 1599 | BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport); |
Matthew Xie | ddf7e47 | 2013-03-01 18:41:02 -0800 | [diff] [blame] | 1600 | gatt.connect(autoConnect, callback); |
| 1601 | return gatt; |
| 1602 | } catch (RemoteException e) {Log.e(TAG, "", e);} |
| 1603 | return null; |
| 1604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | } |