19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 2bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Copyright (C) 2009 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.bluetooth; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 192d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbyeimport android.Manifest; 202d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbyeimport android.annotation.RequiresPermission; 21005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellyimport android.annotation.SdkConstant; 22005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellyimport android.annotation.SdkConstant.SdkConstantType; 232b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbachimport android.annotation.SystemApi; 24ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xieimport android.content.Context; 25bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcel; 26bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcelable; 27aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pellyimport android.os.ParcelUuid; 28044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstromimport android.os.Process; 299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException; 309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log; 319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 32bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport java.io.IOException; 339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.UnsupportedEncodingException; 341caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganeshimport java.util.UUID; 359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 379fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you 38f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * create a connection with the respective device or query information about 399fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * it, such as the name, address, class, and bonding state. 4045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * 4145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>This class is really just a thin wrapper for a Bluetooth hardware 4245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * address. Objects of this class are immutable. Operations on this class 4345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * are performed on the remote Bluetooth hardware address, using the 4445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link BluetoothAdapter} that was used to create this {@link 4545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * BluetoothDevice}. 469fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * 479fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>To get a {@link BluetoothDevice}, use 489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter#getRemoteDevice(String) 499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device 509fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * of a known MAC address (which you can get through device discovery with 519fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter}) or get one from the set of bonded devices 529fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * returned by {@link BluetoothAdapter#getBondedDevices() 539fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getBondedDevices()}. You can then open a 54f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * {@link BluetoothSocket} for communication with the remote device, using 559fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link #createRfcommSocketToServiceRecord(UUID)}. 569fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * 579fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p class="note"><strong>Note:</strong> 589fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Requires the {@link android.Manifest.permission#BLUETOOTH} permission. 599fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * 603aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference"> 613aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3> 6265813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * <p> 6365813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * For more information about using Bluetooth, read the <a href= 6465813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * "{@docRoot}guide/topics/connectivity/bluetooth.html">Bluetooth</a> developer 6565813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * guide. 6665813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * </p> 673aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div> 683aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * 699fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothAdapter} 709fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothSocket} 719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 72bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellypublic final class BluetoothDevice implements Parcelable { 73bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly private static final String TAG = "BluetoothDevice"; 747077272d8feed2f0172520d4fd3b4524e18d5ec1Ravi Nagarajan private static final boolean DBG = false; 759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 76b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly /** 772b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * Connection state bitmask as returned by getConnectionState. 782b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach */ 792b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach private static final int CONNECTION_STATE_DISCONNECTED = 0; 802b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach private static final int CONNECTION_STATE_CONNECTED = 1; 812b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach private static final int CONNECTION_STATE_ENCRYPTED_BREDR = 2; 822b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach private static final int CONNECTION_STATE_ENCRYPTED_LE = 4; 832b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach 842b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach /** 85b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly * Sentinel error value for this class. Guaranteed to not equal any other 86b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly * integer constant in this class. Provided as a convenience for functions 87b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly * that require a sentinel error value, for example: 88005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p><code>Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, 89005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * BluetoothDevice.ERROR)</code> 90005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 91005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int ERROR = Integer.MIN_VALUE; 92005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 93005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 94005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Remote device discovered. 95005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Sent when a remote device is found during discovery. 96005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link 97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_CLASS}. Can contain the extra fields {@link #EXTRA_NAME} and/or 98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #EXTRA_RSSI} if they are available. 9972f491dd8642e6854fd4c6d40d77c06312af6e3bFyodor Kupolov * <p>Requires {@link android.Manifest.permission#BLUETOOTH} and 10072f491dd8642e6854fd4c6d40d77c06312af6e3bFyodor Kupolov * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} to receive. 101005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 102005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // TODO: Change API to not broadcast RSSI if not available (incoming connection) 103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_FOUND = 105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.FOUND"; 106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 108005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Remote device disappeared. 109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Sent when a remote device that was found in the last discovery is not 110005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * found in the current discovery. 111005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 112005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 113005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @hide 114005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 115005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 116005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_DISAPPEARED = 117005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.DISAPPEARED"; 118005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 119005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 120005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Bluetooth class of a remote device has changed. 121005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link 122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_CLASS}. 123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 124b30f91e38c19f6728d836293446d4b9c76705e7fMatthew Xie * {@see BluetoothClass} 125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 126005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_CLASS_CHANGED = 128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.CLASS_CHANGED"; 129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 131005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a low level (ACL) connection has been 132005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * established with a remote device. 133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 134005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>ACL connections are managed automatically by the Android Bluetooth 135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stack. 136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 139005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_CONNECTED = 140005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_CONNECTED"; 141005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 143005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates that a low level (ACL) disconnection has 144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * been requested for a remote device, and it will soon be disconnected. 145005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>This is useful for graceful disconnection. Applications should use 146005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * this intent as a hint to immediately terminate higher level connections 147005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * (RFCOMM, L2CAP, or profile connections) to the remote device. 148005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 149005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 150005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 152005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_DISCONNECT_REQUESTED = 153005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED"; 154005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 155005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 156005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a low level (ACL) disconnection from a 157005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * remote device. 158005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 159005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>ACL connections are managed automatically by the Android Bluetooth 160005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stack. 161005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 162005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 163005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 164005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_DISCONNECTED = 165005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_DISCONNECTED"; 166005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 167005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 168005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates the friendly name of a remote device has 169005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * been retrieved for the first time, or changed since the last retrieval. 170005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link 171005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_NAME}. 172005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 173005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 174005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 175005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_NAME_CHANGED = 176005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.NAME_CHANGED"; 177005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 178005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 1795bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * Broadcast Action: Indicates the alias of a remote device has been 1805bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * changed. 1815bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 1825bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 1835bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * 1845bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * @hide 1855bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown */ 1865bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1875bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown public static final String ACTION_ALIAS_CHANGED = 1885bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown "android.bluetooth.device.action.ALIAS_CHANGED"; 1895bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown 1905bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown /** 191005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a change in the bond state of a remote 192005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * device. For example, if a device is bonded (paired). 193005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link 194005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}. 195005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 196005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 197005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also 198005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // contain a hidden extra field EXTRA_REASON with the result code. 199005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 200005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_BOND_STATE_CHANGED = 201005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.BOND_STATE_CHANGED"; 202005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 203005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 204005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as a Parcelable {@link BluetoothDevice} extra field in every intent 205005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * broadcast by this class. It contains the {@link BluetoothDevice} that 206005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * the intent applies to. 207005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 208005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE"; 209005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 210005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 211005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link 212005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #ACTION_FOUND} intents. It contains the friendly Bluetooth name. 213005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 214005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME"; 215005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 216005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 217005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an optional short extra field in {@link #ACTION_FOUND} intents. 218005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the RSSI value of the remote device as reported by the 219005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Bluetooth hardware. 220005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 221005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI"; 222005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 223005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 224f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * Used as a Parcelable {@link BluetoothClass} extra field in {@link 225005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents. 226005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 227005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS"; 228005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 229005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 230005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents. 231005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the bond state of the remote device. 232005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values are: 233005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 234005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 235005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 236091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 237005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE"; 238005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 239005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents. 240005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the previous bond state of the remote device. 241005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values are: 242005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 243005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 244005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 245091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 246005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_PREVIOUS_BOND_STATE = 247005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.extra.PREVIOUS_BOND_STATE"; 248005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 249005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates the remote device is not bonded (paired). 250005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>There is no shared link key with the remote device, so communication 251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * (if it is allowed at all) will be unauthenticated and unencrypted. 252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_NONE = 10; 254005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 255005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates bonding (pairing) is in progress with the remote device. 256005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 257005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_BONDING = 11; 258005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 259005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates the remote device is bonded (paired). 260005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>A shared link keys exists locally for the remote device, so 261005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * communication can be authenticated and encrypted. 262005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p><i>Being bonded (paired) with a remote device does not necessarily 263f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * mean the device is currently connected. It just means that the pending 264f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * procedure was completed at some earlier time, and the link key is still 265005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stored locally, ready to use on the next connection. 266005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * </i> 267005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 268005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_BONDED = 12; 269005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 270091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 271091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 272091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents for unbond reason. 273091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @hide 274091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 275005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON"; 276091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie 277091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 278091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 279091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents to indicate pairing method used. Possible values are: 280091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * {@link #PAIRING_VARIANT_PIN}, 281091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION}, 282091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 283005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_PAIRING_VARIANT = 284005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.extra.PAIRING_VARIANT"; 285091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie 286091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 287091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 288091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents as the value of passkey. 289091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 290c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY"; 291005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 292005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 29333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Unknown 29433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 29533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_UNKNOWN = 0; 29633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 29733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 29833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Classic - BR/EDR devices 29933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 30033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_CLASSIC = 1; 30133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 30233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 30333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Low Energy - LE-only 30433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 30533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_LE = 2; 30633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 30733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 30833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Dual Mode - BR/EDR/LE 30933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 31033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_DUAL = 3; 31133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 312238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 313238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 314238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 315238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String ACTION_SDP_RECORD = 316238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.action.SDP_RECORD"; 317238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 31833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 3191caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * Broadcast Action: This intent is used to broadcast the {@link UUID} 320aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * wrapped as a {@link android.os.ParcelUuid} of the remote device after it 321aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * has been fetched. This intent is sent only when the UUIDs of the remote 322aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * device are requested to be fetched using Service Discovery Protocol 3231caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * <p> Always contains the extra field {@link #EXTRA_DEVICE} 324ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p> Always contains the extra field {@link #EXTRA_UUID} 3251caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 3261caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 3271caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3281caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public static final String ACTION_UUID = 329ad2321027e9731711544b43378bd7b2f01890774Matthew Xie "android.bluetooth.device.action.UUID"; 3301caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 3318949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 3328949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3338949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final String ACTION_MAS_INSTANCE = 3348949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta "android.bluetooth.device.action.MAS_INSTANCE"; 3358949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 3361caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 337005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a failure to retrieve the name of a remote 338005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * device. 339005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 340005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 341005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @hide 342005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 343005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly //TODO: is this actually useful? 344005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 345005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_NAME_FAILED = 346005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.NAME_FAILED"; 347005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 348091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 349091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Broadcast Action: This intent is used to broadcast PAIRING REQUEST 350ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} to 351430e361b202ecff8a10a9258948ade99689fe6b1Edward Jee * receive. 352091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 353005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 354005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_PAIRING_REQUEST = 355005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.PAIRING_REQUEST"; 356005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** @hide */ 357005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 358005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_PAIRING_CANCEL = 359005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.PAIRING_CANCEL"; 360a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin 361a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 362a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 363a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_REQUEST = 364a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST"; 365a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 366a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 367a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 368a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_REPLY = 369a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY"; 370a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 371a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 372a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 373a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_CANCEL = 374a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL"; 375a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 376a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 377a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent. 378a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 379a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 380a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_ACCESS_REQUEST_TYPE = 381a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE"; 382a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 383a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 384a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1; 385a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 386a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 387a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2; 388a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 389fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie /**@hide*/ 390fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3; 391fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie 3922a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /**@hide*/ 3932a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public static final int REQUEST_TYPE_SIM_ACCESS = 4; 3942a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde 395a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 396a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents, 397a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains package name to return reply intent to. 398a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 399a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 400a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME"; 401a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 402a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 403a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents, 404a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains class name to return reply intent to. 405a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 406a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 407a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME"; 408a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 409a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 410a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent. 411a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 412a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 413a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_CONNECTION_ACCESS_RESULT = 414a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT"; 415a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 416a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 417a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int CONNECTION_ACCESS_YES = 1; 418a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 419a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 420a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int CONNECTION_ACCESS_NO = 2; 421a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 422a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 423a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents, 424a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains boolean to indicate if the allowed response is once-for-all so that 425a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * next request will be granted without asking user again. 426a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 427a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 428a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_ALWAYS_ALLOWED = 429a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.ALWAYS_ALLOWED"; 430a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 431c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 432c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt succeeded 433c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 434c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 435b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly public static final int BOND_SUCCESS = 0; 436c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 437c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 438c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because pins did not match, or remote device did 43932d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh * not respond to pin request in time 440c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 441c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_FAILED = 1; 443c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 444c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 445c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because the other side explicitly rejected 44645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * bonding 447c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 448c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_REJECTED = 2; 450c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 451c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 452c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we canceled the bonding process 453c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 454c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_CANCELED = 3; 456c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 457c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 458c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we could not contact the remote device 459c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 460c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4; 462c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 463c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 464c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because a discovery is in progress 465c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 466c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5; 468c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 469c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 470c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because of authentication timeout 471c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 472c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 47332d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int UNBOND_REASON_AUTH_TIMEOUT = 6; 474c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 475c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 476c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because of repeated attempts 477c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 478c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 47932d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7; 480c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 481c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 482c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we received an Authentication Cancel 483c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * by remote end 484c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 485c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 486e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8; 487c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 488c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 489c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * An existing bond was explicitly revoked 490c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 491c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 492e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh public static final int UNBOND_REASON_REMOVED = 9; 4939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 494c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 495091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * The user will be prompted to enter a pin or 496ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * an app will enter a pin for user. 497c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 498b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh public static final int PAIRING_VARIANT_PIN = 0; 499c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 500c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 501c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter a passkey 502c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 503c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 504b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh public static final int PAIRING_VARIANT_PASSKEY = 1; 505c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 506c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 507091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * The user will be prompted to confirm the passkey displayed on the screen or 508ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * an app will confirm the passkey for the user. 509c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 51032d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; 511c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 512c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 513c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to accept or deny the incoming pairing request 514c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 515c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 51632d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_CONSENT = 3; 517c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 518c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 519c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter the passkey displayed on remote device 520c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * This is used for Bluetooth 2.1 pairing. 521c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 522c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 52332d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4; 524c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 525c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 526c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter the PIN displayed on remote device. 527c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * This is used for Bluetooth 2.0 pairing. 528c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 529c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 530c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PAIRING_VARIANT_DISPLAY_PIN = 5; 531c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 532c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 533c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to accept or deny the OOB pairing request 534c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 535c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 536c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PAIRING_VARIANT_OOB_CONSENT = 6; 537c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 5381caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 5393b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * The user will be prompted to enter a 16 digit pin or 5403b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * an app will enter a 16 digit pin for user. 5413b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * @hide 5423b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde */ 5433b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde public static final int PAIRING_VARIANT_PIN_16_DIGITS = 7; 5443b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde 5453b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde /** 5461caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * Used as an extra field in {@link #ACTION_UUID} intents, 547aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * Contains the {@link android.os.ParcelUuid}s of the remote device which 548aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * is a parcelable version of {@link UUID}. 5491caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 5501caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID"; 5511caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 552238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 553238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String EXTRA_SDP_RECORD = 554238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.extra.SDP_RECORD"; 555238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 556238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 557238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String EXTRA_SDP_SEARCH_STATUS = 558238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.extra.SDP_SEARCH_STATUS"; 5598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5638dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5648dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_UNKNOWN = 0; 5658dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 5668dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5678dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5688dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5698dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5708dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5718dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_ALLOWED = 1; 5728dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 5738dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5748dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5758dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5768dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5778dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5788dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_REJECTED = 2; 5798dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 580b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 581b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * No preferrence of physical transport for GATT connections to remote dual-mode devices 582b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 583b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta public static final int TRANSPORT_AUTO = 0; 584b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 585b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 586b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Prefer BR/EDR transport for GATT connections to remote dual-mode devices 587b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 5888949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final int TRANSPORT_BREDR = 1; 589b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 590b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 591b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Prefer LE transport for GATT connections to remote dual-mode devices 592b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 5938949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final int TRANSPORT_LE = 2; 594b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 5958949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 5968949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final String EXTRA_MAS_INSTANCE = 5978949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta "android.bluetooth.device.extra.MAS_INSTANCE"; 598b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 59916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 60016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Lazy initialization. Guaranteed final after first object constructed, or 60116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * getService() called. 60216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * TODO: Unify implementation of sService amongst BluetoothFoo API's 60316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 60416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly private static IBluetooth sService; 605bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 606bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly private final String mAddress; 607d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh 60816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /*package*/ static IBluetooth getService() { 609bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly synchronized (BluetoothDevice.class) { 610bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly if (sService == null) { 6110f42037eb7b5118015c2caca635538324ccf0ccffredc BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 612903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc sService = adapter.getBluetoothService(mStateChangeCallback); 613bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 614bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 61516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return sService; 61616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly } 617bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 618903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() { 619903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc 620903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc public void onBluetoothServiceUp(IBluetooth bluetoothService) 621903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc throws RemoteException { 622903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc synchronized (BluetoothDevice.class) { 623d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (sService == null) { 624d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora sService = bluetoothService; 625d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 626903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 627903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 628903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc 629903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc public void onBluetoothServiceDown() 630903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc throws RemoteException { 631903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc synchronized (BluetoothDevice.class) { 632903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc sService = null; 633903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 634903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 635d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 636d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora public void onBrEdrDown() 637d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora { 638d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (DBG) Log.d(TAG, "onBrEdrDown: reached BLE ON state"); 639d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 640903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc }; 64116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 64216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Create a new BluetoothDevice 64316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB", 64416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * and is validated in this constructor. 64516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @param address valid Bluetooth MAC address 64616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws RuntimeException Bluetooth is not available on this platform 64716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws IllegalArgumentException address is invalid 64816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @hide 64916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 65016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /*package*/ BluetoothDevice(String address) { 65116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly getService(); // ensures sService is initialized 652005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (!BluetoothAdapter.checkBluetoothAddress(address)) { 653bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly throw new IllegalArgumentException(address + " is not a valid Bluetooth address"); 654bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 655bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 656bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly mAddress = address; 6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 659bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 660bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean equals(Object o) { 661bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly if (o instanceof BluetoothDevice) { 662bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress.equals(((BluetoothDevice)o).getAddress()); 663bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 6659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 667bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 668bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int hashCode() { 669bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress.hashCode(); 670105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project } 671105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project 67245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** 67345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Returns a string representation of this BluetoothDevice. 67445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>Currently this is the Bluetooth hardware address, for example 67545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress} 67645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * if you explicitly require the Bluetooth hardware address in case the 67745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link #toString} representation changes in the future. 67845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return string representation of this BluetoothDevice 67945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly */ 680bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 681bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public String toString() { 682bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress; 6839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 685bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int describeContents() { 686bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return 0; 687bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 688bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 689bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public static final Parcelable.Creator<BluetoothDevice> CREATOR = 690bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly new Parcelable.Creator<BluetoothDevice>() { 691bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothDevice createFromParcel(Parcel in) { 692bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return new BluetoothDevice(in.readString()); 693bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 694bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothDevice[] newArray(int size) { 695bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return new BluetoothDevice[size]; 696bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 697bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly }; 698bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 699bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public void writeToParcel(Parcel out, int flags) { 700bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly out.writeString(mAddress); 7019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 70345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** 70445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Returns the hardware address of this BluetoothDevice. 70545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p> For example, "00:11:22:AA:BB:CC". 70645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return Bluetooth hardware address as string 70745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly */ 7089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String getAddress() { 7090f42037eb7b5118015c2caca635538324ccf0ccffredc if (DBG) Log.d(TAG, "mAddress: " + mAddress); 710bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress; 7119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 71445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Get the friendly Bluetooth name of the remote device. 7159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 71645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>The local adapter will automatically retrieve remote names when 71745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * performing a device scan, and will cache them. This method just returns 71845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * the name for this device from the cache. 719de893f550301a60274e87aa8168225e7a7a42184Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 7209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the Bluetooth name, or null if there was a problem. 7229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7232d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 7249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String getName() { 7250f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7260f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Remote Device name"); 7270f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 7280f42037eb7b5118015c2caca635538324ccf0ccffredc } 7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 730e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteName(this); 7319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 7329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 7339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 73633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Get the Bluetooth device type of the remote device. 73733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * 73833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 73933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * 74033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE} 74133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * {@link #DEVICE_TYPE_DUAL}. 74233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * {@link #DEVICE_TYPE_UNKNOWN} if it's not available 74333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 7442d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 74533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public int getType() { 74633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie if (sService == null) { 74733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie Log.e(TAG, "BT not enabled. Cannot get Remote Device type"); 74833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return DEVICE_TYPE_UNKNOWN; 74933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } 75033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie try { 75133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return sService.getRemoteType(this); 75233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 75333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return DEVICE_TYPE_UNKNOWN; 75433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } 75533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 75633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 757269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Get the Bluetooth alias of the remote device. 758269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>Alias is the locally modified name of a remote device. 759269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 760269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return the Bluetooth alias, or null if no alias or there was a problem 761269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 762269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 763269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public String getAlias() { 7640f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7650f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias"); 7660f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 7670f42037eb7b5118015c2caca635538324ccf0ccffredc } 768269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie try { 769e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteAlias(this); 770269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 771269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return null; 772269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 773269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 774269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 775269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Set the Bluetooth alias of the remote device. 776269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>Alias is the locally modified name of a remote device. 777269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>This methoid overwrites the alias. The changed 778269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * alias is saved in the local storage so that the change 779269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * is preserved over power cycle. 780269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 781269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return true on success, false on error 782269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 783269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 784269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public boolean setAlias(String alias) { 7850f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7860f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set Remote Device name"); 7870f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 7880f42037eb7b5118015c2caca635538324ccf0ccffredc } 789269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie try { 790e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setRemoteAlias(this, alias); 791269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 792269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return false; 793269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 794269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 795269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 796269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Get the Bluetooth alias of the remote device. 797269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * If Alias is null, get the Bluetooth name instead. 798269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @see #getAlias() 799269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @see #getName() 800269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 801269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return the Bluetooth alias, or null if no alias or there was a problem 802269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 803269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 804269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public String getAliasName() { 805269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie String name = getAlias(); 806269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie if (name == null) { 807269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie name = getName(); 808269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 809269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return name; 810269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 811269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 812269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 813005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Start the bonding (pairing) process with the remote device. 814005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>This is an asynchronous call, it will return immediately. Register 815005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 816005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * the bonding process completes, and its result. 817005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Android system services will handle the necessary user interactions 818005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * to confirm and complete the bonding process. 819ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 8209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 821005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return false on immediate error, true if bonding will begin 8229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8232d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) 824bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean createBond() { 8250f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 8260f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device"); 8270f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 8280f42037eb7b5118015c2caca635538324ccf0ccffredc } 8299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 830044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom Log.i(TAG, "createBond() for device " + getAddress() + 831044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom " called by pid: " + Process.myPid() + 832044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom " tid: " + Process.myTid()); 83357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return sService.createBond(this, TRANSPORT_AUTO); 83457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } catch (RemoteException e) {Log.e(TAG, "", e);} 83557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return false; 83657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 83757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach 83857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach /** 83957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * Start the bonding (pairing) process with the remote device using the 84057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * specified transport. 84157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * 84257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>This is an asynchronous call, it will return immediately. Register 84357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 84457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * the bonding process completes, and its result. 84557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>Android system services will handle the necessary user interactions 84657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * to confirm and complete the bonding process. 84757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 84857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * 84957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @param transport The transport to use for the pairing procedure. 85057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @return false on immediate error, true if bonding will begin 85157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @throws IllegalArgumentException if an invalid transport was specified 85257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @hide 85357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach */ 85457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach public boolean createBond(int transport) { 85557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach if (sService == null) { 85657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device"); 85757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return false; 85857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 85957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE) 86057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach { 86157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport"); 86257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 86357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach try { 864044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom Log.i(TAG, "createBond() for device " + getAddress() + 865044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom " called by pid: " + Process.myPid() + 866044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom " tid: " + Process.myTid()); 86757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return sService.createBond(this, transport); 8689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 8699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 8709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 873cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Start the bonding (pairing) process with the remote device using the 874cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Out Of Band mechanism. 875cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 876cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>This is an asynchronous call, it will return immediately. Register 877cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 878cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * the bonding process completes, and its result. 879cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 880cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Android system services will handle the necessary user interactions 881cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * to confirm and complete the bonding process. 882cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 883cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 884cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 8852fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski * @param transport - Transport to use 8862fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski * @param oobData - Out Of Band data 887cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @return false on immediate error, true if bonding will begin 888cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 889cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @hide 890cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh */ 8912fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski public boolean createBondOutOfBand(int transport, OobData oobData) { 892cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 8932fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski return sService.createBondOutOfBand(this, transport, oobData); 8942fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski } catch (RemoteException e) {Log.e(TAG, "", e);} 895cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 896cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 897cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 898cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** 899cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Set the Out Of Band data for a remote device to be used later 900cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * in the pairing mechanism. Users can obtain this data through other 901cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * trusted channels 902cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 903cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 904cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 905cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param hash Simple Secure pairing hash 906cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param randomizer The random key obtained using OOB 907cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @return false on error; true otherwise 908cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 909cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @hide 910cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh */ 911cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) { 912e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh //TODO(BT) 913e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 914cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 915e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setDeviceOutOfBandData(this, hash, randomizer); 916e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);} */ 917cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 918cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 919cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 920cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** 921005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Cancel an in-progress bonding request started with {@link #createBond}. 922005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 923005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 924f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return true on success, false on error 92518b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly * @hide 9269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 927bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean cancelBondProcess() { 9280f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9290f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond"); 9300f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 9310f42037eb7b5118015c2caca635538324ccf0ccffredc } 9329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 933044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom Log.i(TAG, "cancelBondProcess() for device " + getAddress() + 934044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom " called by pid: " + Process.myPid() + 935044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom " tid: " + Process.myTid()); 936e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.cancelBondProcess(this); 9379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 9389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 9399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 942005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Remove bond (pairing) with the remote device. 943005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Delete the link key associated with the remote device, and 944005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * immediately terminate connections to that device that require 945005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * authentication and encryption. 946005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 9479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 948f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return true on success, false on error 94918b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly * @hide 9509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 951bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean removeBond() { 9520f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9530f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond"); 9540f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 9550f42037eb7b5118015c2caca635538324ccf0ccffredc } 9569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 957044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom Log.i(TAG, "removeBond() for device " + getAddress() + 958044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom " called by pid: " + Process.myPid() + 959044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom " tid: " + Process.myTid()); 960e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.removeBond(this); 9619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 962bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return false; 9639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 966005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Get the bond state of the remote device. 967005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values for the bond state are: 968005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 969005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 970005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 971005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 9729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 973005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return the bond state 9749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9752d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 976bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int getBondState() { 9770f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9780f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get bond state"); 9790f42037eb7b5118015c2caca635538324ccf0ccffredc return BOND_NONE; 9800f42037eb7b5118015c2caca635538324ccf0ccffredc } 9819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 982e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getBondState(this); 9839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 984305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M catch (NullPointerException npe) { 985305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M // Handle case where bluetooth service proxy 986305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M // is already null. 987305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M Log.e(TAG, "NullPointerException for getBondState() of device ("+ 988305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M getAddress()+")", npe); 989305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M } 990005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return BOND_NONE; 991005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 992005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 993005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 994174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * Returns whether there is an open connection to this device. 995174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 996174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * 997174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * @return True if there is at least one open connection to this device. 998174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * @hide 999174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli */ 10002b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach @SystemApi 1001174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli public boolean isConnected() { 1002174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli if (sService == null) { 1003174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli // BT is not enabled, we cannot be connected. 1004174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli return false; 1005174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 1006174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli try { 10072b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return sService.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED; 10082b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } catch (RemoteException e) { 10092b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach Log.e(TAG, "", e); 10102b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return false; 10112b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 10122b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 10132b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach 10142b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach /** 10152b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * Returns whether there is an open connection to this device 10162b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * that has been encrypted. 10172b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 10182b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * 10192b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * @return True if there is at least one encrypted connection to this device. 10202b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * @hide 10212b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach */ 10222b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach @SystemApi 10232b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach public boolean isEncrypted() { 10242b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach if (sService == null) { 10252b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach // BT is not enabled, we cannot be connected. 10262b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return false; 10272b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 10282b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach try { 10292b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return sService.getConnectionState(this) > CONNECTION_STATE_CONNECTED; 1030174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } catch (RemoteException e) { 1031174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli Log.e(TAG, "", e); 1032174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli return false; 1033174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 1034174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 1035174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli 1036174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli /** 1037005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Get the Bluetooth class of the remote device. 1038005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1039005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 1040005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return Bluetooth class object, or null on error 1041005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 10422d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 1043005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public BluetoothClass getBluetoothClass() { 10440f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 10450f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class"); 10460f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 10470f42037eb7b5118015c2caca635538324ccf0ccffredc } 1048005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly try { 1049e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh int classInt = sService.getRemoteClass(this); 1050005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (classInt == BluetoothClass.ERROR) return null; 1051005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return new BluetoothClass(classInt); 1052005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } catch (RemoteException e) {Log.e(TAG, "", e);} 1053005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return null; 10549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1056efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue /** 1057ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * Returns the supported features (UUIDs) of the remote device. 1058ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1059ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>This method does not start a service discovery procedure to retrieve the UUIDs 1060ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * from the remote device. Instead, the local cached copy of the service 1061ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * UUIDs are returned. 1062ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired. 1063ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1064ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1065ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * @return the supported features (UUIDs) of the remote device, 1066ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * or null on error 1067ad2321027e9731711544b43378bd7b2f01890774Matthew Xie */ 10682d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 1069dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh public ParcelUuid[] getUuids() { 1070d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (sService == null || isBluetoothEnabled() == false) { 10710f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get remote device Uuids"); 10720f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 10730f42037eb7b5118015c2caca635538324ccf0ccffredc } 10749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1075e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteUuids(this); 10769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 10779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 10789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1079d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh 10801caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 1081ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * Perform a service discovery on the remote device to get the UUIDs supported. 1082ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1083ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent, 1084ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * with the UUIDs supported by the remote end. If there is an error 1085ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * in getting the SDP records or if the process takes a long time, 1086ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently 1087ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * present in the cache. Clients should use the {@link #getUuids} to get UUIDs 1088ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * if service discovery is not to be performed. 1089ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 10901caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * 1091ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * @return False if the sanity check fails, True if the process 10921caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * of initiating an ACL connection to the remote device 10931caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * was started. 10941caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 10952d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 10961caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public boolean fetchUuidsWithSdp() { 10975d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu IBluetooth service = sService; 1098d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (service == null || isBluetoothEnabled() == false) { 10995d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp"); 11005d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu return false; 11015d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu } 11021caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh try { 11035d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu return service.fetchRemoteUuids(this); 11044c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc } catch (RemoteException e) {Log.e(TAG, "", e);} 11054c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc return false; 11061caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh } 11071caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 1108238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** 1109238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Perform a service discovery on the remote device to get the SDP records associated 1110238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * with the specified UUID. 1111238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1112238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent, 1113238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * with the SDP records found on the remote end. If there is an error 1114238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * in getting the SDP records or if the process takes a long time, 1115238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * {@link #ACTION_SDP_RECORD} intent is sent with an status value in 1116238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0. 1117238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Detailed status error codes can be found by members of the Bluetooth package in 1118238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * the AbstractionLayer class. 1119238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1120238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}. 1121238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * The object type will match one of the SdpXxxRecord types, depending on the UUID searched 1122238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * for. 1123238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1124238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @return False if the sanity check fails, True if the process 1125238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * of initiating an ACL connection to the remote device 1126238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * was started. 1127238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde */ 11288949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 1129238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public boolean sdpSearch(ParcelUuid uuid) { 11308949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta if (sService == null) { 1131238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde Log.e(TAG, "BT not enabled. Cannot query remote device sdp records"); 11328949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta return false; 11338949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } 11348949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta try { 1135238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde return sService.sdpSearch(this,uuid); 11368949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } catch (RemoteException e) {Log.e(TAG, "", e);} 11378949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta return false; 11388949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } 11398949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 1140091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 1141091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN} 1142ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 1143091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * 1144091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @return true pin has been set 1145091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * false for error 1146091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 1147bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPin(byte[] pin) { 11480f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 11490f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set Remote Device pin"); 11500f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 11510f42037eb7b5118015c2caca635538324ccf0ccffredc } 11529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1153e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPin(this, true, pin.length, pin); 11549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 11559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 11569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1157b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 115845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** @hide */ 1159bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPasskey(int passkey) { 1160e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh //TODO(BT) 1161e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 1162b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh try { 1163e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPasskey(this, true, 4, passkey); 1164e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 1165b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh return false; 1166b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } 1167b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 1168091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 1169091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing. 117093326cfd9fb8a20081baa9b975275772798cfd80Marie Janssen * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 1171091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * 1172091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @return true confirmation has been sent out 1173091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * false for error 1174091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 117593326cfd9fb8a20081baa9b975275772798cfd80Marie Janssen @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED) 1176bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPairingConfirmation(boolean confirm) { 11770f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 11780f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set pairing confirmation"); 11790f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 11800f42037eb7b5118015c2caca635538324ccf0ccffredc } 1181b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh try { 1182e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPairingConfirmation(this, confirm); 1183b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);} 1184b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh return false; 1185b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } 1186b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 118745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** @hide */ 1188cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh public boolean setRemoteOutOfBandData() { 1189e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh // TODO(BT) 1190e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 1191cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 1192e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setRemoteOutOfBandData(this); 1193e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 1194cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 1195cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 1196cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 1197cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** @hide */ 1198bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean cancelPairingUserInput() { 11990f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 12000f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot create pairing user input"); 12010f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 12020f42037eb7b5118015c2caca635538324ccf0ccffredc } 12039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1204919a4c6264b733585152ce1dc6f868c1093d368bRavi Nagarajan return sService.cancelBondProcess(this); 1205db44b20fe6aed65d5cd7e1f6d7c52e4322083039Priti Aghera } catch (RemoteException e) {Log.e(TAG, "", e);} 12069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 12079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12093fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh /** @hide */ 12103fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh public boolean isBluetoothDock() { 1211e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh // TODO(BT) 1212e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 12133fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh try { 1214e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.isBluetoothDock(this); 1215e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 12163fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh return false; 12173fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh } 12183fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh 1219d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora boolean isBluetoothEnabled() { 1220d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora boolean ret = false; 1221d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 1222d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (adapter != null && adapter.isEnabled() == true) { 1223d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora ret = true; 1224d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1225d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora return ret; 1226d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1227d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 12289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12298dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Requires {@link android.Manifest.permission#BLUETOOTH}. 12308dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the phonebook access is allowed to this device. Can be 12318dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 12328dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12338dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12348dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public int getPhonebookAccessPermission() { 12358dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12368dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12378dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12388dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12398dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.getPhonebookAccessPermission(this); 12408dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12418dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12428dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12438dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12448dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12458dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12468dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12478dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Sets whether the phonebook access is allowed to this device. 12488dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 12498dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 12508dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_REJECTED}. 12518dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the value has been successfully set. 12528dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12538dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12548dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public boolean setPhonebookAccessPermission(int value) { 12558dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12568dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12578dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12588dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.setPhonebookAccessPermission(this, value); 12608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12638dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12648dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12658dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12668dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12678dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Requires {@link android.Manifest.permission#BLUETOOTH}. 12688dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the message access is allowed to this device. Can be 12698dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 12708dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12718dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12728dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public int getMessageAccessPermission() { 12738dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12748dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12758dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12768dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12778dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.getMessageAccessPermission(this); 12788dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12798dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12808dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12818dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12828dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12838dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12848dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12858dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Sets whether the message access is allowed to this device. 12868dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 12878dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 12888dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_REJECTED}. 12898dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the value has been successfully set. 12908dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12918dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12928dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public boolean setMessageAccessPermission(int value) { 12938dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12948dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12958dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12968dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12978dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.setMessageAccessPermission(this, value); 12988dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12998dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 13008dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 13018dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 13028dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 13038dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 13048dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 13052a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * Requires {@link android.Manifest.permission#BLUETOOTH}. 13062a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @return Whether the Sim access is allowed to this device. Can be 13072a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 13082a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @hide 13092a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde */ 13102a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public int getSimAccessPermission() { 13112a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde if (sService == null) { 13122a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return ACCESS_UNKNOWN; 13132a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13142a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde try { 13152a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return sService.getSimAccessPermission(this); 13162a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } catch (RemoteException e) { 13172a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde Log.e(TAG, "", e); 13182a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13192a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return ACCESS_UNKNOWN; 13202a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13212a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde 13222a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /** 13232a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * Sets whether the Sim access is allowed to this device. 13242a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 13252a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 13262a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * {@link #ACCESS_REJECTED}. 13272a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @return Whether the value has been successfully set. 13282a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @hide 13292a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde */ 13302a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public boolean setSimAccessPermission(int value) { 13312a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde if (sService == null) { 13322a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return false; 13332a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13342a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde try { 13352a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return sService.setSimAccessPermission(this, value); 13362a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } catch (RemoteException e) { 13372a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde Log.e(TAG, "", e); 13382a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13392a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return false; 13403b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde } 13413b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde 13422a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /** 134345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Create an RFCOMM {@link BluetoothSocket} ready to start a secure 134416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * outgoing connection to this remote device on given channel. 134545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>The remote device will be authenticated and communication on this 134645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * socket will be encrypted. 1347c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p> Use this socket only if an authenticated socket link is possible. 1348c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Authentication refers to the authentication of the link key to 1349c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * prevent man-in-the-middle type of attacks. 1350c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For example, for Bluetooth 2.1 devices, if any of the devices does not 1351c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * have an input and output capability or just has the ability to 1352c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * display a numeric key, a secure socket connection is not possible. 1353c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * In such a case, use {#link createInsecureRfcommSocket}. 1354c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For more details, refer to the Security Model section 5.2 (vol 3) of 1355c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Bluetooth Core Specification version 2.1 + EDR. 1356f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 135745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * connection. 135845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>Valid RFCOMM channels are in range 1 to 30. 1359cf44059813539bf7f36dabd278cef93ba3122c56Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 1360de893f550301a60274e87aa8168225e7a7a42184Nick Pelly * 136145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @param channel RFCOMM channel to connect to 136245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 1363bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException on error, for example Bluetooth not available, or 136445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * insufficient permissions 136516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @hide 1366bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 136745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly public BluetoothSocket createRfcommSocket(int channel) throws IOException { 1368d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1369d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1370d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1371d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 137216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel, 137316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly null); 137416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly } 137516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly 137616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 1377238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Create an L2cap {@link BluetoothSocket} ready to start a secure 1378238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * outgoing connection to this remote device on given channel. 1379238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>The remote device will be authenticated and communication on this 1380238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * socket will be encrypted. 1381238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p> Use this socket only if an authenticated socket link is possible. 1382238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Authentication refers to the authentication of the link key to 1383238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * prevent man-in-the-middle type of attacks. 1384238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * For example, for Bluetooth 2.1 devices, if any of the devices does not 1385238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * have an input and output capability or just has the ability to 1386238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * display a numeric key, a secure socket connection is not possible. 1387238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * In such a case, use {#link createInsecureRfcommSocket}. 1388238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * For more details, refer to the Security Model section 5.2 (vol 3) of 1389238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Bluetooth Core Specification version 2.1 + EDR. 1390238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 1391238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * connection. 1392238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Valid L2CAP PSM channels are in range 1 to 2^16. 1393238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 1394238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1395238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @param channel L2cap PSM/channel to connect to 1396238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 1397238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @throws IOException on error, for example Bluetooth not available, or 1398238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * insufficient permissions 1399238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @hide 1400238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde */ 1401238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public BluetoothSocket createL2capSocket(int channel) throws IOException { 1402238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, true, true, this, channel, 1403238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde null); 1404238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde } 1405238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 1406238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** 140716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Create an RFCOMM {@link BluetoothSocket} ready to start a secure 140816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * outgoing connection to this remote device using SDP lookup of uuid. 140916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>This is designed to be used with {@link 141016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer 141116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Bluetooth applications. 1412f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 141316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * connection. This will also perform an SDP lookup of the given uuid to 141416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * determine which channel to connect to. 141516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>The remote device will be authenticated and communication on this 141616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * socket will be encrypted. 1417c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p> Use this socket only if an authenticated socket link is possible. 1418c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Authentication refers to the authentication of the link key to 1419c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * prevent man-in-the-middle type of attacks. 1420c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For example, for Bluetooth 2.1 devices, if any of the devices does not 1421c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * have an input and output capability or just has the ability to 1422c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * display a numeric key, a secure socket connection is not possible. 1423c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}. 1424c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For more details, refer to the Security Model section 5.2 (vol 3) of 1425c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Bluetooth Core Specification version 2.1 + EDR. 1426ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * <p>Hint: If you are connecting to a Bluetooth serial board then try 1427ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. 1428ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * However if you are connecting to an Android peer then please generate 1429ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * your own unique UUID. 143016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 143116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * 143216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @param uuid service record uuid to lookup RFCOMM channel 143316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 143416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws IOException on error, for example Bluetooth not available, or 143516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * insufficient permissions 143616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 14372d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 143816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException { 1439d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1440d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1441d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1442d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1443d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 144416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1, 144516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly new ParcelUuid(uuid)); 1446bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1447bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1448bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 14496eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure 14506eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * outgoing connection to this remote device using SDP lookup of uuid. 14516eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p> The communication channel will not have an authenticated link key 14526eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1 14536eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * devices, the link key will be encrypted, as encryption is mandatory. 14546eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * For legacy devices (pre Bluetooth 2.1 devices) the link key will 14556eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an 14566eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * encrypted and authenticated communication channel is desired. 14576eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>This is designed to be used with {@link 14586eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer 14596eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * Bluetooth applications. 14606eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 14616eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * connection. This will also perform an SDP lookup of the given uuid to 14626eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * determine which channel to connect to. 14636eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>The remote device will be authenticated and communication on this 14646eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * socket will be encrypted. 14656eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Hint: If you are connecting to a Bluetooth serial board then try 14666eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. 14676eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * However if you are connecting to an Android peer then please generate 14686eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * your own unique UUID. 14696eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 14706eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * 14716eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @param uuid service record uuid to lookup RFCOMM channel 14726eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 14736eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @throws IOException on error, for example Bluetooth not available, or 14746eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * insufficient permissions 14756eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh */ 14762d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 14776eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException { 1478d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1479d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1480d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1481d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 14826eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1, 14836eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh new ParcelUuid(uuid)); 14846eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh } 14856eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh 14866eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh /** 1487bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Construct an insecure RFCOMM socket ready to start an outgoing 1488bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * connection. 1489bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Call #connect on the returned #BluetoothSocket to begin the connection. 1490bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * The remote device will not be authenticated and communication on this 1491bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * socket will not be encrypted. 1492e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} 1493e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * 1494bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @param port remote port 1495bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @return An RFCOMM BluetoothSocket 1496bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException On error, for example Bluetooth not available, or 1497bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * insufficient permissions. 149845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 1499bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 1500bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException { 1501d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 1502d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1503d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1504d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1505d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 150616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port, 150716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly null); 1508bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1509bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1510bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 1511bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Construct a SCO socket ready to start an outgoing connection. 1512bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Call #connect on the returned #BluetoothSocket to begin the connection. 1513e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} 1514e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * 1515bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @return a SCO BluetoothSocket 1516bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException on error, for example Bluetooth not available, or 1517bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * insufficient permissions. 151845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 1519bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 1520bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothSocket createScoSocket() throws IOException { 1521d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 1522d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1523d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1524d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1525d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 152616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null); 1527bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1528bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1529bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 15309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Check that a pin is valid and convert to byte array. 15319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1532f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters. 15339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param pin pin as java String 1534f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return the pin code as a UTF-8 byte array, or null if it is an invalid 15359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Bluetooth pin. 153645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 15379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 15389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static byte[] convertPinToBytes(String pin) { 15399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (pin == null) { 15409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project byte[] pinBytes; 15439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1544f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby pinBytes = pin.getBytes("UTF-8"); 15459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (UnsupportedEncodingException uee) { 1546f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby Log.e(TAG, "UTF-8 not supported?!?"); // this should not happen 15479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (pinBytes.length <= 0 || pinBytes.length > 16) { 15509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return pinBytes; 15539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1555ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1556ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Connect to GATT Server hosted by this device. Caller acts as GATT client. 1557ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * The callback is used to deliver results to Caller, such as connection status as well 1558ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * as any further GATT client operations. 1559ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct 1560ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * GATT client operations. 1561ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param callback GATT callback handler that will receive asynchronous callbacks. 1562ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param autoConnect Whether to directly connect to the remote device (false) 1563ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * or to automatically connect as soon as the remote 1564ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * device becomes available (true). 1565ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @throws IllegalArgumentException if callback is null 1566ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 156733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public BluetoothGatt connectGatt(Context context, boolean autoConnect, 156833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie BluetoothGattCallback callback) { 1569b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO)); 1570b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta } 1571b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 1572b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 1573b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Connect to GATT Server hosted by this device. Caller acts as GATT client. 1574b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * The callback is used to deliver results to Caller, such as connection status as well 1575b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * as any further GATT client operations. 1576b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct 1577b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * GATT client operations. 1578b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param callback GATT callback handler that will receive asynchronous callbacks. 1579b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param autoConnect Whether to directly connect to the remote device (false) 1580b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * or to automatically connect as soon as the remote 1581b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * device becomes available (true). 1582b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param transport preferred transport for GATT connections to remote dual-mode devices 1583b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * {@link BluetoothDevice#TRANSPORT_AUTO} or 1584b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE} 1585b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @throws IllegalArgumentException if callback is null 1586b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 1587b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta public BluetoothGatt connectGatt(Context context, boolean autoConnect, 1588b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta BluetoothGattCallback callback, int transport) { 1589ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie // TODO(Bluetooth) check whether platform support BLE 1590ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie // Do the check here or in GattServer? 1591ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 1592ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie IBluetoothManager managerService = adapter.getBluetoothManager(); 1593ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie try { 1594ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie IBluetoothGatt iGatt = managerService.getBluetoothGatt(); 159532ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie if (iGatt == null) { 159632ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie // BLE is not supported 159732ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie return null; 159832ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie } 1599adc26ec1b4060358d918d1bdf491f5192b35c2d3Jeremy Klein BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport); 1600ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie gatt.connect(autoConnect, callback); 1601ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return gatt; 1602ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 1603ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return null; 1604ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 16059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 1606