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; 289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException; 299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log; 309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 31bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport java.io.IOException; 329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.UnsupportedEncodingException; 331caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganeshimport java.util.UUID; 349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 369fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you 37f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * create a connection with the respective device or query information about 389fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * it, such as the name, address, class, and bonding state. 3945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * 4045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>This class is really just a thin wrapper for a Bluetooth hardware 4145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * address. Objects of this class are immutable. Operations on this class 4245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * are performed on the remote Bluetooth hardware address, using the 4345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link BluetoothAdapter} that was used to create this {@link 4445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * BluetoothDevice}. 459fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * 469fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>To get a {@link BluetoothDevice}, use 479fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter#getRemoteDevice(String) 489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device 499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * of a known MAC address (which you can get through device discovery with 509fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter}) or get one from the set of bonded devices 519fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * returned by {@link BluetoothAdapter#getBondedDevices() 529fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getBondedDevices()}. You can then open a 53f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * {@link BluetoothSocket} for communication with the remote device, using 549fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link #createRfcommSocketToServiceRecord(UUID)}. 559fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * 569fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p class="note"><strong>Note:</strong> 579fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Requires the {@link android.Manifest.permission#BLUETOOTH} permission. 589fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * 593aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference"> 603aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3> 613aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about using Bluetooth, read the 623aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/wireless/bluetooth.html">Bluetooth</a> developer guide.</p> 633aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div> 643aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * 659fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothAdapter} 669fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothSocket} 679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 68bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellypublic final class BluetoothDevice implements Parcelable { 69bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly private static final String TAG = "BluetoothDevice"; 707077272d8feed2f0172520d4fd3b4524e18d5ec1Ravi Nagarajan private static final boolean DBG = false; 719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 72b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly /** 732b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * Connection state bitmask as returned by getConnectionState. 742b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach */ 752b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach private static final int CONNECTION_STATE_DISCONNECTED = 0; 762b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach private static final int CONNECTION_STATE_CONNECTED = 1; 772b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach private static final int CONNECTION_STATE_ENCRYPTED_BREDR = 2; 782b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach private static final int CONNECTION_STATE_ENCRYPTED_LE = 4; 792b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach 802b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach /** 81b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly * Sentinel error value for this class. Guaranteed to not equal any other 82b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly * integer constant in this class. Provided as a convenience for functions 83b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly * that require a sentinel error value, for example: 84005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p><code>Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, 85005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * BluetoothDevice.ERROR)</code> 86005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 87005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int ERROR = Integer.MIN_VALUE; 88005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 89005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 90005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Remote device discovered. 91005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Sent when a remote device is found during discovery. 92005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link 93005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_CLASS}. Can contain the extra fields {@link #EXTRA_NAME} and/or 94005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #EXTRA_RSSI} if they are available. 9572f491dd8642e6854fd4c6d40d77c06312af6e3bFyodor Kupolov * <p>Requires {@link android.Manifest.permission#BLUETOOTH} and 9672f491dd8642e6854fd4c6d40d77c06312af6e3bFyodor Kupolov * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} to receive. 97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // TODO: Change API to not broadcast RSSI if not available (incoming connection) 99005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 100005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_FOUND = 101005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.FOUND"; 102005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Remote device disappeared. 105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Sent when a remote device that was found in the last discovery is not 106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * found in the current discovery. 107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 108005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @hide 110005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 111005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 112005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_DISAPPEARED = 113005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.DISAPPEARED"; 114005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 115005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 116005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Bluetooth class of a remote device has changed. 117005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link 118005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_CLASS}. 119005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 120b30f91e38c19f6728d836293446d4b9c76705e7fMatthew Xie * {@see BluetoothClass} 121005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_CLASS_CHANGED = 124005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.CLASS_CHANGED"; 125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 126005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a low level (ACL) connection has been 128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * established with a remote device. 129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>ACL connections are managed automatically by the Android Bluetooth 131005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stack. 132005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 134005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_CONNECTED = 136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_CONNECTED"; 137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 139005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates that a low level (ACL) disconnection has 140005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * been requested for a remote device, and it will soon be disconnected. 141005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>This is useful for graceful disconnection. Applications should use 142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * this intent as a hint to immediately terminate higher level connections 143005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * (RFCOMM, L2CAP, or profile connections) to the remote device. 144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 145005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 146005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 147005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 148005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_DISCONNECT_REQUESTED = 149005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED"; 150005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 152005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a low level (ACL) disconnection from a 153005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * remote device. 154005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 155005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>ACL connections are managed automatically by the Android Bluetooth 156005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stack. 157005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 158005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 159005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 160005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_DISCONNECTED = 161005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_DISCONNECTED"; 162005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 163005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 164005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates the friendly name of a remote device has 165005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * been retrieved for the first time, or changed since the last retrieval. 166005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link 167005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_NAME}. 168005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 169005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 170005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 171005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_NAME_CHANGED = 172005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.NAME_CHANGED"; 173005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 174005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 1755bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * Broadcast Action: Indicates the alias of a remote device has been 1765bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * changed. 1775bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 1785bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 1795bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * 1805bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * @hide 1815bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown */ 1825bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1835bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown public static final String ACTION_ALIAS_CHANGED = 1845bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown "android.bluetooth.device.action.ALIAS_CHANGED"; 1855bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown 1865bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown /** 187005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a change in the bond state of a remote 188005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * device. For example, if a device is bonded (paired). 189005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link 190005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}. 191005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 192005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 193005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also 194005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // contain a hidden extra field EXTRA_REASON with the result code. 195005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 196005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_BOND_STATE_CHANGED = 197005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.BOND_STATE_CHANGED"; 198005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 199005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 200005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as a Parcelable {@link BluetoothDevice} extra field in every intent 201005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * broadcast by this class. It contains the {@link BluetoothDevice} that 202005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * the intent applies to. 203005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 204005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE"; 205005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 206005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 207005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link 208005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #ACTION_FOUND} intents. It contains the friendly Bluetooth name. 209005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 210005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME"; 211005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 212005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 213005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an optional short extra field in {@link #ACTION_FOUND} intents. 214005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the RSSI value of the remote device as reported by the 215005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Bluetooth hardware. 216005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 217005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI"; 218005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 219005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 220f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * Used as a Parcelable {@link BluetoothClass} extra field in {@link 221005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents. 222005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 223005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS"; 224005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 225005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 226005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents. 227005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the bond state of the remote device. 228005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values are: 229005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 230005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 231005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 232091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 233005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE"; 234005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 235005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents. 236005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the previous bond state of the remote device. 237005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values are: 238005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 239005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 240005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 241091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 242005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_PREVIOUS_BOND_STATE = 243005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.extra.PREVIOUS_BOND_STATE"; 244005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 245005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates the remote device is not bonded (paired). 246005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>There is no shared link key with the remote device, so communication 247005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * (if it is allowed at all) will be unauthenticated and unencrypted. 248005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 249005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_NONE = 10; 250005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates bonding (pairing) is in progress with the remote device. 252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_BONDING = 11; 254005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 255005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates the remote device is bonded (paired). 256005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>A shared link keys exists locally for the remote device, so 257005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * communication can be authenticated and encrypted. 258005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p><i>Being bonded (paired) with a remote device does not necessarily 259f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * mean the device is currently connected. It just means that the pending 260f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * procedure was completed at some earlier time, and the link key is still 261005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stored locally, ready to use on the next connection. 262005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * </i> 263005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 264005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_BONDED = 12; 265005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 266091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 267091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 268091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents for unbond reason. 269091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @hide 270091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 271005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON"; 272091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie 273091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 274091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 275091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents to indicate pairing method used. Possible values are: 276091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * {@link #PAIRING_VARIANT_PIN}, 277091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION}, 278091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 279005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_PAIRING_VARIANT = 280005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.extra.PAIRING_VARIANT"; 281091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie 282091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 283091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 284091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents as the value of passkey. 285091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 286c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY"; 287005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 288005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 28933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Unknown 29033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 29133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_UNKNOWN = 0; 29233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 29333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 29433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Classic - BR/EDR devices 29533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 29633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_CLASSIC = 1; 29733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 29833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 29933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Low Energy - LE-only 30033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 30133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_LE = 2; 30233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 30333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 30433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Dual Mode - BR/EDR/LE 30533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 30633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_DUAL = 3; 30733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 308238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 309238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 310238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 311238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String ACTION_SDP_RECORD = 312238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.action.SDP_RECORD"; 313238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 31433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 3151caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * Broadcast Action: This intent is used to broadcast the {@link UUID} 316aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * wrapped as a {@link android.os.ParcelUuid} of the remote device after it 317aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * has been fetched. This intent is sent only when the UUIDs of the remote 318aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * device are requested to be fetched using Service Discovery Protocol 3191caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * <p> Always contains the extra field {@link #EXTRA_DEVICE} 320ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p> Always contains the extra field {@link #EXTRA_UUID} 3211caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 3221caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 3231caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3241caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public static final String ACTION_UUID = 325ad2321027e9731711544b43378bd7b2f01890774Matthew Xie "android.bluetooth.device.action.UUID"; 3261caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 3278949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 3288949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3298949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final String ACTION_MAS_INSTANCE = 3308949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta "android.bluetooth.device.action.MAS_INSTANCE"; 3318949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 3321caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 333005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a failure to retrieve the name of a remote 334005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * device. 335005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 336005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 337005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @hide 338005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 339005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly //TODO: is this actually useful? 340005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 341005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_NAME_FAILED = 342005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.NAME_FAILED"; 343005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 344091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 345091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Broadcast Action: This intent is used to broadcast PAIRING REQUEST 346ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} to 347430e361b202ecff8a10a9258948ade99689fe6b1Edward Jee * receive. 348091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 349005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 350005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_PAIRING_REQUEST = 351005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.PAIRING_REQUEST"; 352005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** @hide */ 353005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 354005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_PAIRING_CANCEL = 355005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.PAIRING_CANCEL"; 356a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin 357a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 358a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 359a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_REQUEST = 360a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST"; 361a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 362a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 363a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 364a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_REPLY = 365a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY"; 366a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 367a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 368a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 369a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_CANCEL = 370a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL"; 371a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 372a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 373a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent. 374a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 375a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 376a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_ACCESS_REQUEST_TYPE = 377a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE"; 378a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 379a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 380a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1; 381a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 382a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 383a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2; 384a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 385fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie /**@hide*/ 386fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3; 387fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie 3882a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /**@hide*/ 3892a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public static final int REQUEST_TYPE_SIM_ACCESS = 4; 3902a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde 391a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 392a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents, 393a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains package name to return reply intent to. 394a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 395a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 396a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME"; 397a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 398a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 399a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents, 400a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains class name to return reply intent to. 401a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 402a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 403a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME"; 404a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 405a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 406a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent. 407a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 408a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 409a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_CONNECTION_ACCESS_RESULT = 410a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT"; 411a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 412a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 413a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int CONNECTION_ACCESS_YES = 1; 414a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 415a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 416a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int CONNECTION_ACCESS_NO = 2; 417a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 418a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 419a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents, 420a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains boolean to indicate if the allowed response is once-for-all so that 421a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * next request will be granted without asking user again. 422a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 423a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 424a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_ALWAYS_ALLOWED = 425a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.ALWAYS_ALLOWED"; 426a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 427c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 428c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt succeeded 429c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 430c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 431b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly public static final int BOND_SUCCESS = 0; 432c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 433c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 434c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because pins did not match, or remote device did 43532d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh * not respond to pin request in time 436c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 437c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_FAILED = 1; 439c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 440c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 441c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because the other side explicitly rejected 44245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * bonding 443c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 444c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_REJECTED = 2; 446c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 447c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 448c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we canceled the bonding process 449c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 450c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_CANCELED = 3; 452c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 453c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 454c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we could not contact the remote device 455c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 456c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4; 458c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 459c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 460c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because a discovery is in progress 461c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 462c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5; 464c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 465c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 466c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because of authentication timeout 467c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 468c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 46932d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int UNBOND_REASON_AUTH_TIMEOUT = 6; 470c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 471c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 472c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because of repeated attempts 473c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 474c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 47532d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7; 476c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 477c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 478c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we received an Authentication Cancel 479c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * by remote end 480c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 481c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 482e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8; 483c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 484c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 485c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * An existing bond was explicitly revoked 486c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 487c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 488e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh public static final int UNBOND_REASON_REMOVED = 9; 4899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 490c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 491091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * The user will be prompted to enter a pin or 492ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * an app will enter a pin for user. 493c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 494b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh public static final int PAIRING_VARIANT_PIN = 0; 495c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 496c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 497c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter a passkey 498c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 499c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 500b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh public static final int PAIRING_VARIANT_PASSKEY = 1; 501c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 502c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 503091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * The user will be prompted to confirm the passkey displayed on the screen or 504ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * an app will confirm the passkey for the user. 505c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 50632d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; 507c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 508c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 509c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to accept or deny the incoming pairing request 510c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 511c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 51232d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_CONSENT = 3; 513c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 514c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 515c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter the passkey displayed on remote device 516c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * This is used for Bluetooth 2.1 pairing. 517c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 518c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 51932d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4; 520c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 521c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 522c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter the PIN displayed on remote device. 523c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * This is used for Bluetooth 2.0 pairing. 524c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 525c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 526c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PAIRING_VARIANT_DISPLAY_PIN = 5; 527c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 528c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 529c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to accept or deny the OOB pairing request 530c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 531c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 532c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PAIRING_VARIANT_OOB_CONSENT = 6; 533c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 5341caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 5353b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * The user will be prompted to enter a 16 digit pin or 5363b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * an app will enter a 16 digit pin for user. 5373b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * @hide 5383b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde */ 5393b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde public static final int PAIRING_VARIANT_PIN_16_DIGITS = 7; 5403b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde 5413b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde /** 5421caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * Used as an extra field in {@link #ACTION_UUID} intents, 543aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * Contains the {@link android.os.ParcelUuid}s of the remote device which 544aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * is a parcelable version of {@link UUID}. 5451caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 5461caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID"; 5471caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 548238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 549238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String EXTRA_SDP_RECORD = 550238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.extra.SDP_RECORD"; 551238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 552238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 553238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String EXTRA_SDP_SEARCH_STATUS = 554238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.extra.SDP_SEARCH_STATUS"; 5558dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5568dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5578dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5588dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_UNKNOWN = 0; 5618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 5628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5638dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5648dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5658dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5668dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5678dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_ALLOWED = 1; 5688dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 5698dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5708dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5718dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5728dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5738dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5748dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_REJECTED = 2; 5758dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 576b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 577b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * No preferrence of physical transport for GATT connections to remote dual-mode devices 578b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 579b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta public static final int TRANSPORT_AUTO = 0; 580b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 581b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 582b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Prefer BR/EDR transport for GATT connections to remote dual-mode devices 583b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 5848949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final int TRANSPORT_BREDR = 1; 585b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 586b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 587b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Prefer LE transport for GATT connections to remote dual-mode devices 588b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 5898949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final int TRANSPORT_LE = 2; 590b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 5918949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 5928949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final String EXTRA_MAS_INSTANCE = 5938949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta "android.bluetooth.device.extra.MAS_INSTANCE"; 594b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 59516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 59616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Lazy initialization. Guaranteed final after first object constructed, or 59716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * getService() called. 59816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * TODO: Unify implementation of sService amongst BluetoothFoo API's 59916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 60016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly private static IBluetooth sService; 601bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 602bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly private final String mAddress; 603d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh 60416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /*package*/ static IBluetooth getService() { 605bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly synchronized (BluetoothDevice.class) { 606bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly if (sService == null) { 6070f42037eb7b5118015c2caca635538324ccf0ccffredc BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 608903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc sService = adapter.getBluetoothService(mStateChangeCallback); 609bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 610bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 61116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return sService; 61216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly } 613bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 614903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() { 615903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc 616903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc public void onBluetoothServiceUp(IBluetooth bluetoothService) 617903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc throws RemoteException { 618903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc synchronized (BluetoothDevice.class) { 619d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (sService == null) { 620d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora sService = bluetoothService; 621d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 622903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 623903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 624903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc 625903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc public void onBluetoothServiceDown() 626903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc throws RemoteException { 627903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc synchronized (BluetoothDevice.class) { 628903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc sService = null; 629903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 630903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 631d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 632d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora public void onBrEdrDown() 633d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora { 634d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (DBG) Log.d(TAG, "onBrEdrDown: reached BLE ON state"); 635d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 636903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc }; 63716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 63816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Create a new BluetoothDevice 63916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB", 64016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * and is validated in this constructor. 64116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @param address valid Bluetooth MAC address 64216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws RuntimeException Bluetooth is not available on this platform 64316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws IllegalArgumentException address is invalid 64416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @hide 64516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 64616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /*package*/ BluetoothDevice(String address) { 64716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly getService(); // ensures sService is initialized 648005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (!BluetoothAdapter.checkBluetoothAddress(address)) { 649bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly throw new IllegalArgumentException(address + " is not a valid Bluetooth address"); 650bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 651bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 652bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly mAddress = address; 6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 655bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 656bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean equals(Object o) { 657bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly if (o instanceof BluetoothDevice) { 658bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress.equals(((BluetoothDevice)o).getAddress()); 659bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 663bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 664bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int hashCode() { 665bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress.hashCode(); 666105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project } 667105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project 66845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** 66945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Returns a string representation of this BluetoothDevice. 67045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>Currently this is the Bluetooth hardware address, for example 67145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress} 67245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * if you explicitly require the Bluetooth hardware address in case the 67345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link #toString} representation changes in the future. 67445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return string representation of this BluetoothDevice 67545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly */ 676bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 677bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public String toString() { 678bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress; 6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 681bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int describeContents() { 682bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return 0; 683bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 684bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 685bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public static final Parcelable.Creator<BluetoothDevice> CREATOR = 686bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly new Parcelable.Creator<BluetoothDevice>() { 687bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothDevice createFromParcel(Parcel in) { 688bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return new BluetoothDevice(in.readString()); 689bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 690bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothDevice[] newArray(int size) { 691bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return new BluetoothDevice[size]; 692bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 693bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly }; 694bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 695bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public void writeToParcel(Parcel out, int flags) { 696bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly out.writeString(mAddress); 6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 69945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** 70045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Returns the hardware address of this BluetoothDevice. 70145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p> For example, "00:11:22:AA:BB:CC". 70245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return Bluetooth hardware address as string 70345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly */ 7049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String getAddress() { 7050f42037eb7b5118015c2caca635538324ccf0ccffredc if (DBG) Log.d(TAG, "mAddress: " + mAddress); 706bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress; 7079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 71045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Get the friendly Bluetooth name of the remote device. 7119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 71245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>The local adapter will automatically retrieve remote names when 71345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * performing a device scan, and will cache them. This method just returns 71445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * the name for this device from the cache. 715de893f550301a60274e87aa8168225e7a7a42184Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 7169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the Bluetooth name, or null if there was a problem. 7189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7192d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 7209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String getName() { 7210f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7220f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Remote Device name"); 7230f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 7240f42037eb7b5118015c2caca635538324ccf0ccffredc } 7259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 726e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteName(this); 7279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 7289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 73233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Get the Bluetooth device type of the remote device. 73333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * 73433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 73533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * 73633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE} 73733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * {@link #DEVICE_TYPE_DUAL}. 73833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * {@link #DEVICE_TYPE_UNKNOWN} if it's not available 73933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 7402d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 74133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public int getType() { 74233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie if (sService == null) { 74333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie Log.e(TAG, "BT not enabled. Cannot get Remote Device type"); 74433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return DEVICE_TYPE_UNKNOWN; 74533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } 74633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie try { 74733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return sService.getRemoteType(this); 74833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 74933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return DEVICE_TYPE_UNKNOWN; 75033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } 75133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 75233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 753269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Get the Bluetooth alias of the remote device. 754269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>Alias is the locally modified name of a remote device. 755269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 756269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return the Bluetooth alias, or null if no alias or there was a problem 757269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 758269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 759269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public String getAlias() { 7600f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7610f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias"); 7620f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 7630f42037eb7b5118015c2caca635538324ccf0ccffredc } 764269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie try { 765e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteAlias(this); 766269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 767269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return null; 768269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 769269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 770269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 771269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Set the Bluetooth alias of the remote device. 772269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>Alias is the locally modified name of a remote device. 773269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>This methoid overwrites the alias. The changed 774269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * alias is saved in the local storage so that the change 775269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * is preserved over power cycle. 776269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 777269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return true on success, false on error 778269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 779269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 780269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public boolean setAlias(String alias) { 7810f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7820f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set Remote Device name"); 7830f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 7840f42037eb7b5118015c2caca635538324ccf0ccffredc } 785269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie try { 786e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setRemoteAlias(this, alias); 787269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 788269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return false; 789269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 790269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 791269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 792269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Get the Bluetooth alias of the remote device. 793269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * If Alias is null, get the Bluetooth name instead. 794269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @see #getAlias() 795269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @see #getName() 796269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 797269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return the Bluetooth alias, or null if no alias or there was a problem 798269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 799269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 800269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public String getAliasName() { 801269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie String name = getAlias(); 802269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie if (name == null) { 803269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie name = getName(); 804269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 805269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return name; 806269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 807269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 808269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 809005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Start the bonding (pairing) process with the remote device. 810005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>This is an asynchronous call, it will return immediately. Register 811005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 812005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * the bonding process completes, and its result. 813005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Android system services will handle the necessary user interactions 814005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * to confirm and complete the bonding process. 815ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 8169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 817005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return false on immediate error, true if bonding will begin 8189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8192d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) 820bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean createBond() { 8210f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 8220f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device"); 8230f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 8240f42037eb7b5118015c2caca635538324ccf0ccffredc } 8259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 82657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return sService.createBond(this, TRANSPORT_AUTO); 82757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } catch (RemoteException e) {Log.e(TAG, "", e);} 82857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return false; 82957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 83057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach 83157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach /** 83257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * Start the bonding (pairing) process with the remote device using the 83357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * specified transport. 83457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * 83557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>This is an asynchronous call, it will return immediately. Register 83657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 83757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * the bonding process completes, and its result. 83857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>Android system services will handle the necessary user interactions 83957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * to confirm and complete the bonding process. 84057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 84157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * 84257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @param transport The transport to use for the pairing procedure. 84357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @return false on immediate error, true if bonding will begin 84457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @throws IllegalArgumentException if an invalid transport was specified 84557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @hide 84657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach */ 84757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach public boolean createBond(int transport) { 84857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach if (sService == null) { 84957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device"); 85057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return false; 85157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 85257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE) 85357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach { 85457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport"); 85557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 85657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach try { 85757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return sService.createBond(this, transport); 8589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 8599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 8609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 863cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Start the bonding (pairing) process with the remote device using the 864cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Out Of Band mechanism. 865cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 866cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>This is an asynchronous call, it will return immediately. Register 867cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 868cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * the bonding process completes, and its result. 869cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 870cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Android system services will handle the necessary user interactions 871cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * to confirm and complete the bonding process. 872cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 873cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 874cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 875cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param hash - Simple Secure pairing hash 876cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param randomizer - The random key obtained using OOB 877cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @return false on immediate error, true if bonding will begin 878cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 879cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @hide 880cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh */ 881cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh public boolean createBondOutOfBand(byte[] hash, byte[] randomizer) { 882e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh //TODO(BT) 883e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 884cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 885e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.createBondOutOfBand(this, hash, randomizer); 886e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 887cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 888cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 889cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 890cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** 891cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Set the Out Of Band data for a remote device to be used later 892cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * in the pairing mechanism. Users can obtain this data through other 893cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * trusted channels 894cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 895cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 896cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 897cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param hash Simple Secure pairing hash 898cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param randomizer The random key obtained using OOB 899cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @return false on error; true otherwise 900cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 901cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @hide 902cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh */ 903cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) { 904e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh //TODO(BT) 905e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 906cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 907e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setDeviceOutOfBandData(this, hash, randomizer); 908e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);} */ 909cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 910cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 911cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 912cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** 913005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Cancel an in-progress bonding request started with {@link #createBond}. 914005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 915005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 916f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return true on success, false on error 91718b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly * @hide 9189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 919bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean cancelBondProcess() { 9200f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9210f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond"); 9220f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 9230f42037eb7b5118015c2caca635538324ccf0ccffredc } 9249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 925e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.cancelBondProcess(this); 9269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 9279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 9289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 931005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Remove bond (pairing) with the remote device. 932005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Delete the link key associated with the remote device, and 933005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * immediately terminate connections to that device that require 934005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * authentication and encryption. 935005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 9369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 937f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return true on success, false on error 93818b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly * @hide 9399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 940bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean removeBond() { 9410f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9420f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond"); 9430f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 9440f42037eb7b5118015c2caca635538324ccf0ccffredc } 9459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 946e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.removeBond(this); 9479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 948bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return false; 9499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 952005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Get the bond state of the remote device. 953005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values for the bond state are: 954005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 955005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 956005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 957005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 9589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 959005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return the bond state 9609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9612d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 962bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int getBondState() { 9630f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9640f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get bond state"); 9650f42037eb7b5118015c2caca635538324ccf0ccffredc return BOND_NONE; 9660f42037eb7b5118015c2caca635538324ccf0ccffredc } 9679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 968e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getBondState(this); 9699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 970305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M catch (NullPointerException npe) { 971305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M // Handle case where bluetooth service proxy 972305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M // is already null. 973305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M Log.e(TAG, "NullPointerException for getBondState() of device ("+ 974305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M getAddress()+")", npe); 975305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M } 976005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return BOND_NONE; 977005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 978005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 979005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 980174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * Returns whether there is an open connection to this device. 981174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 982174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * 983174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * @return True if there is at least one open connection to this device. 984174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * @hide 985174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli */ 9862b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach @SystemApi 987174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli public boolean isConnected() { 988174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli if (sService == null) { 989174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli // BT is not enabled, we cannot be connected. 990174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli return false; 991174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 992174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli try { 9932b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return sService.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED; 9942b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } catch (RemoteException e) { 9952b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach Log.e(TAG, "", e); 9962b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return false; 9972b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 9982b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 9992b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach 10002b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach /** 10012b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * Returns whether there is an open connection to this device 10022b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * that has been encrypted. 10032b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 10042b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * 10052b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * @return True if there is at least one encrypted connection to this device. 10062b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * @hide 10072b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach */ 10082b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach @SystemApi 10092b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach public boolean isEncrypted() { 10102b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach if (sService == null) { 10112b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach // BT is not enabled, we cannot be connected. 10122b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return false; 10132b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 10142b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach try { 10152b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return sService.getConnectionState(this) > CONNECTION_STATE_CONNECTED; 1016174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } catch (RemoteException e) { 1017174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli Log.e(TAG, "", e); 1018174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli return false; 1019174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 1020174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 1021174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli 1022174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli /** 1023005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Get the Bluetooth class of the remote device. 1024005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1025005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 1026005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return Bluetooth class object, or null on error 1027005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 10282d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 1029005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public BluetoothClass getBluetoothClass() { 10300f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 10310f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class"); 10320f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 10330f42037eb7b5118015c2caca635538324ccf0ccffredc } 1034005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly try { 1035e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh int classInt = sService.getRemoteClass(this); 1036005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (classInt == BluetoothClass.ERROR) return null; 1037005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return new BluetoothClass(classInt); 1038005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } catch (RemoteException e) {Log.e(TAG, "", e);} 1039005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return null; 10409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1042efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue /** 1043ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * Returns the supported features (UUIDs) of the remote device. 1044ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1045ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>This method does not start a service discovery procedure to retrieve the UUIDs 1046ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * from the remote device. Instead, the local cached copy of the service 1047ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * UUIDs are returned. 1048ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired. 1049ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1050ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1051ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * @return the supported features (UUIDs) of the remote device, 1052ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * or null on error 1053ad2321027e9731711544b43378bd7b2f01890774Matthew Xie */ 10542d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 1055dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh public ParcelUuid[] getUuids() { 1056d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (sService == null || isBluetoothEnabled() == false) { 10570f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get remote device Uuids"); 10580f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 10590f42037eb7b5118015c2caca635538324ccf0ccffredc } 10609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1061e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteUuids(this); 10629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 10639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 10649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1065d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh 10661caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 1067ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * Perform a service discovery on the remote device to get the UUIDs supported. 1068ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1069ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent, 1070ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * with the UUIDs supported by the remote end. If there is an error 1071ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * in getting the SDP records or if the process takes a long time, 1072ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently 1073ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * present in the cache. Clients should use the {@link #getUuids} to get UUIDs 1074ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * if service discovery is not to be performed. 1075ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 10761caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * 1077ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * @return False if the sanity check fails, True if the process 10781caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * of initiating an ACL connection to the remote device 10791caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * was started. 10801caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 10812d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 10821caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public boolean fetchUuidsWithSdp() { 10835d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu IBluetooth service = sService; 1084d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (service == null || isBluetoothEnabled() == false) { 10855d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp"); 10865d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu return false; 10875d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu } 10881caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh try { 10895d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu return service.fetchRemoteUuids(this); 10904c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc } catch (RemoteException e) {Log.e(TAG, "", e);} 10914c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc return false; 10921caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh } 10931caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 1094238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** 1095238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Perform a service discovery on the remote device to get the SDP records associated 1096238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * with the specified UUID. 1097238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1098238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent, 1099238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * with the SDP records found on the remote end. If there is an error 1100238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * in getting the SDP records or if the process takes a long time, 1101238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * {@link #ACTION_SDP_RECORD} intent is sent with an status value in 1102238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0. 1103238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Detailed status error codes can be found by members of the Bluetooth package in 1104238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * the AbstractionLayer class. 1105238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1106238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}. 1107238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * The object type will match one of the SdpXxxRecord types, depending on the UUID searched 1108238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * for. 1109238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1110238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @return False if the sanity check fails, True if the process 1111238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * of initiating an ACL connection to the remote device 1112238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * was started. 1113238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde */ 11148949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 1115238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public boolean sdpSearch(ParcelUuid uuid) { 11168949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta if (sService == null) { 1117238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde Log.e(TAG, "BT not enabled. Cannot query remote device sdp records"); 11188949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta return false; 11198949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } 11208949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta try { 1121238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde return sService.sdpSearch(this,uuid); 11228949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } catch (RemoteException e) {Log.e(TAG, "", e);} 11238949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta return false; 11248949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } 11258949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 1126091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 1127091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN} 1128ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 1129091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * 1130091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @return true pin has been set 1131091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * false for error 1132091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 1133bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPin(byte[] pin) { 11340f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 11350f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set Remote Device pin"); 11360f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 11370f42037eb7b5118015c2caca635538324ccf0ccffredc } 11389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1139e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPin(this, true, pin.length, pin); 11409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 11419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 11429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1143b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 114445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** @hide */ 1145bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPasskey(int passkey) { 1146e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh //TODO(BT) 1147e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 1148b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh try { 1149e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPasskey(this, true, 4, passkey); 1150e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 1151b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh return false; 1152b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } 1153b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 1154091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 1155091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing. 1156ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 1157091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * 1158091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @return true confirmation has been sent out 1159091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * false for error 1160091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 11612d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) 1162bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPairingConfirmation(boolean confirm) { 11630f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 11640f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set pairing confirmation"); 11650f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 11660f42037eb7b5118015c2caca635538324ccf0ccffredc } 1167b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh try { 1168e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPairingConfirmation(this, confirm); 1169b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);} 1170b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh return false; 1171b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } 1172b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 117345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** @hide */ 1174cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh public boolean setRemoteOutOfBandData() { 1175e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh // TODO(BT) 1176e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 1177cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 1178e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setRemoteOutOfBandData(this); 1179e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 1180cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 1181cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 1182cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 1183cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** @hide */ 1184bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean cancelPairingUserInput() { 11850f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 11860f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot create pairing user input"); 11870f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 11880f42037eb7b5118015c2caca635538324ccf0ccffredc } 11899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1190919a4c6264b733585152ce1dc6f868c1093d368bRavi Nagarajan return sService.cancelBondProcess(this); 1191db44b20fe6aed65d5cd7e1f6d7c52e4322083039Priti Aghera } catch (RemoteException e) {Log.e(TAG, "", e);} 11929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 11939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11953fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh /** @hide */ 11963fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh public boolean isBluetoothDock() { 1197e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh // TODO(BT) 1198e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 11993fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh try { 1200e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.isBluetoothDock(this); 1201e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 12023fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh return false; 12033fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh } 12043fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh 1205d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora boolean isBluetoothEnabled() { 1206d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora boolean ret = false; 1207d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 1208d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (adapter != null && adapter.isEnabled() == true) { 1209d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora ret = true; 1210d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1211d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora return ret; 1212d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1213d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 12149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12158dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Requires {@link android.Manifest.permission#BLUETOOTH}. 12168dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the phonebook access is allowed to this device. Can be 12178dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 12188dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12198dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12208dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public int getPhonebookAccessPermission() { 12218dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12228dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12238dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12248dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12258dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.getPhonebookAccessPermission(this); 12268dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12278dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12288dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12298dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12308dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12318dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12328dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12338dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Sets whether the phonebook access is allowed to this device. 12348dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 12358dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 12368dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_REJECTED}. 12378dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the value has been successfully set. 12388dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12398dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12408dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public boolean setPhonebookAccessPermission(int value) { 12418dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12428dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12438dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12448dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12458dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.setPhonebookAccessPermission(this, value); 12468dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12478dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12488dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12498dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12508dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12518dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12528dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12538dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Requires {@link android.Manifest.permission#BLUETOOTH}. 12548dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the message access is allowed to this device. Can be 12558dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 12568dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12578dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12588dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public int getMessageAccessPermission() { 12598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12638dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.getMessageAccessPermission(this); 12648dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12658dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12668dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12678dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12688dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12698dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12708dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12718dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Sets whether the message access is allowed to this device. 12728dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 12738dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 12748dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_REJECTED}. 12758dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the value has been successfully set. 12768dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12778dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12788dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public boolean setMessageAccessPermission(int value) { 12798dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12808dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12818dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12828dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12838dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.setMessageAccessPermission(this, value); 12848dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12858dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12868dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12878dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12888dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12898dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12908dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12912a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * Requires {@link android.Manifest.permission#BLUETOOTH}. 12922a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @return Whether the Sim access is allowed to this device. Can be 12932a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 12942a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @hide 12952a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde */ 12962a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public int getSimAccessPermission() { 12972a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde if (sService == null) { 12982a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return ACCESS_UNKNOWN; 12992a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13002a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde try { 13012a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return sService.getSimAccessPermission(this); 13022a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } catch (RemoteException e) { 13032a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde Log.e(TAG, "", e); 13042a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13052a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return ACCESS_UNKNOWN; 13062a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13072a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde 13082a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /** 13092a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * Sets whether the Sim access is allowed to this device. 13102a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 13112a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 13122a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * {@link #ACCESS_REJECTED}. 13132a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @return Whether the value has been successfully set. 13142a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @hide 13152a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde */ 13162a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public boolean setSimAccessPermission(int value) { 13172a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde if (sService == null) { 13182a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return false; 13192a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13202a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde try { 13212a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return sService.setSimAccessPermission(this, value); 13222a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } catch (RemoteException e) { 13232a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde Log.e(TAG, "", e); 13242a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13252a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return false; 13263b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde } 13273b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde 13282a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /** 132945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Create an RFCOMM {@link BluetoothSocket} ready to start a secure 133016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * outgoing connection to this remote device on given channel. 133145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>The remote device will be authenticated and communication on this 133245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * socket will be encrypted. 1333c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p> Use this socket only if an authenticated socket link is possible. 1334c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Authentication refers to the authentication of the link key to 1335c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * prevent man-in-the-middle type of attacks. 1336c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For example, for Bluetooth 2.1 devices, if any of the devices does not 1337c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * have an input and output capability or just has the ability to 1338c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * display a numeric key, a secure socket connection is not possible. 1339c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * In such a case, use {#link createInsecureRfcommSocket}. 1340c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For more details, refer to the Security Model section 5.2 (vol 3) of 1341c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Bluetooth Core Specification version 2.1 + EDR. 1342f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 134345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * connection. 134445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>Valid RFCOMM channels are in range 1 to 30. 1345cf44059813539bf7f36dabd278cef93ba3122c56Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 1346de893f550301a60274e87aa8168225e7a7a42184Nick Pelly * 134745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @param channel RFCOMM channel to connect to 134845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 1349bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException on error, for example Bluetooth not available, or 135045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * insufficient permissions 135116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @hide 1352bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 135345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly public BluetoothSocket createRfcommSocket(int channel) throws IOException { 1354d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1355d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1356d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1357d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 135816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel, 135916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly null); 136016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly } 136116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly 136216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 1363238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Create an L2cap {@link BluetoothSocket} ready to start a secure 1364238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * outgoing connection to this remote device on given channel. 1365238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>The remote device will be authenticated and communication on this 1366238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * socket will be encrypted. 1367238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p> Use this socket only if an authenticated socket link is possible. 1368238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Authentication refers to the authentication of the link key to 1369238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * prevent man-in-the-middle type of attacks. 1370238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * For example, for Bluetooth 2.1 devices, if any of the devices does not 1371238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * have an input and output capability or just has the ability to 1372238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * display a numeric key, a secure socket connection is not possible. 1373238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * In such a case, use {#link createInsecureRfcommSocket}. 1374238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * For more details, refer to the Security Model section 5.2 (vol 3) of 1375238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Bluetooth Core Specification version 2.1 + EDR. 1376238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 1377238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * connection. 1378238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Valid L2CAP PSM channels are in range 1 to 2^16. 1379238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 1380238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1381238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @param channel L2cap PSM/channel to connect to 1382238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 1383238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @throws IOException on error, for example Bluetooth not available, or 1384238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * insufficient permissions 1385238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @hide 1386238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde */ 1387238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public BluetoothSocket createL2capSocket(int channel) throws IOException { 1388238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, true, true, this, channel, 1389238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde null); 1390238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde } 1391238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 1392238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** 139316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Create an RFCOMM {@link BluetoothSocket} ready to start a secure 139416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * outgoing connection to this remote device using SDP lookup of uuid. 139516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>This is designed to be used with {@link 139616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer 139716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Bluetooth applications. 1398f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 139916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * connection. This will also perform an SDP lookup of the given uuid to 140016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * determine which channel to connect to. 140116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>The remote device will be authenticated and communication on this 140216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * socket will be encrypted. 1403c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p> Use this socket only if an authenticated socket link is possible. 1404c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Authentication refers to the authentication of the link key to 1405c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * prevent man-in-the-middle type of attacks. 1406c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For example, for Bluetooth 2.1 devices, if any of the devices does not 1407c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * have an input and output capability or just has the ability to 1408c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * display a numeric key, a secure socket connection is not possible. 1409c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}. 1410c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For more details, refer to the Security Model section 5.2 (vol 3) of 1411c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Bluetooth Core Specification version 2.1 + EDR. 1412ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * <p>Hint: If you are connecting to a Bluetooth serial board then try 1413ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. 1414ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * However if you are connecting to an Android peer then please generate 1415ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * your own unique UUID. 141616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 141716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * 141816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @param uuid service record uuid to lookup RFCOMM channel 141916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 142016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws IOException on error, for example Bluetooth not available, or 142116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * insufficient permissions 142216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 14232d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 142416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException { 1425d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1426d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1427d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1428d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1429d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 143016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1, 143116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly new ParcelUuid(uuid)); 1432bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1433bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1434bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 14356eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure 14366eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * outgoing connection to this remote device using SDP lookup of uuid. 14376eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p> The communication channel will not have an authenticated link key 14386eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1 14396eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * devices, the link key will be encrypted, as encryption is mandatory. 14406eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * For legacy devices (pre Bluetooth 2.1 devices) the link key will 14416eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an 14426eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * encrypted and authenticated communication channel is desired. 14436eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>This is designed to be used with {@link 14446eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer 14456eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * Bluetooth applications. 14466eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 14476eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * connection. This will also perform an SDP lookup of the given uuid to 14486eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * determine which channel to connect to. 14496eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>The remote device will be authenticated and communication on this 14506eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * socket will be encrypted. 14516eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Hint: If you are connecting to a Bluetooth serial board then try 14526eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. 14536eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * However if you are connecting to an Android peer then please generate 14546eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * your own unique UUID. 14556eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 14566eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * 14576eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @param uuid service record uuid to lookup RFCOMM channel 14586eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 14596eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @throws IOException on error, for example Bluetooth not available, or 14606eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * insufficient permissions 14616eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh */ 14622d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 14636eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException { 1464d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1465d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1466d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1467d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 14686eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1, 14696eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh new ParcelUuid(uuid)); 14706eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh } 14716eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh 14726eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh /** 1473bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Construct an insecure RFCOMM socket ready to start an outgoing 1474bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * connection. 1475bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Call #connect on the returned #BluetoothSocket to begin the connection. 1476bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * The remote device will not be authenticated and communication on this 1477bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * socket will not be encrypted. 1478e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} 1479e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * 1480bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @param port remote port 1481bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @return An RFCOMM BluetoothSocket 1482bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException On error, for example Bluetooth not available, or 1483bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * insufficient permissions. 148445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 1485bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 1486bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException { 1487d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 1488d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1489d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1490d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1491d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 149216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port, 149316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly null); 1494bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1495bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1496bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 1497bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Construct a SCO socket ready to start an outgoing connection. 1498bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Call #connect on the returned #BluetoothSocket to begin the connection. 1499e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} 1500e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * 1501bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @return a SCO BluetoothSocket 1502bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException on error, for example Bluetooth not available, or 1503bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * insufficient permissions. 150445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 1505bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 1506bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothSocket createScoSocket() throws IOException { 1507d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 1508d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1509d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1510d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1511d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 151216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null); 1513bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1514bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1515bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 15169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Check that a pin is valid and convert to byte array. 15179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1518f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters. 15199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param pin pin as java String 1520f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return the pin code as a UTF-8 byte array, or null if it is an invalid 15219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Bluetooth pin. 152245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 15239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 15249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static byte[] convertPinToBytes(String pin) { 15259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (pin == null) { 15269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project byte[] pinBytes; 15299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1530f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby pinBytes = pin.getBytes("UTF-8"); 15319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (UnsupportedEncodingException uee) { 1532f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby Log.e(TAG, "UTF-8 not supported?!?"); // this should not happen 15339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (pinBytes.length <= 0 || pinBytes.length > 16) { 15369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return pinBytes; 15399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1541ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1542ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Connect to GATT Server hosted by this device. Caller acts as GATT client. 1543ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * The callback is used to deliver results to Caller, such as connection status as well 1544ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * as any further GATT client operations. 1545ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct 1546ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * GATT client operations. 1547ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param callback GATT callback handler that will receive asynchronous callbacks. 1548ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param autoConnect Whether to directly connect to the remote device (false) 1549ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * or to automatically connect as soon as the remote 1550ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * device becomes available (true). 1551ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @throws IllegalArgumentException if callback is null 1552ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 155333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public BluetoothGatt connectGatt(Context context, boolean autoConnect, 155433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie BluetoothGattCallback callback) { 1555b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO)); 1556b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta } 1557b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 1558b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 1559b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Connect to GATT Server hosted by this device. Caller acts as GATT client. 1560b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * The callback is used to deliver results to Caller, such as connection status as well 1561b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * as any further GATT client operations. 1562b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct 1563b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * GATT client operations. 1564b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param callback GATT callback handler that will receive asynchronous callbacks. 1565b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param autoConnect Whether to directly connect to the remote device (false) 1566b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * or to automatically connect as soon as the remote 1567b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * device becomes available (true). 1568b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param transport preferred transport for GATT connections to remote dual-mode devices 1569b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * {@link BluetoothDevice#TRANSPORT_AUTO} or 1570b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE} 1571b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @throws IllegalArgumentException if callback is null 1572b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 1573b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta public BluetoothGatt connectGatt(Context context, boolean autoConnect, 1574b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta BluetoothGattCallback callback, int transport) { 1575ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie // TODO(Bluetooth) check whether platform support BLE 1576ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie // Do the check here or in GattServer? 1577ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 1578ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie IBluetoothManager managerService = adapter.getBluetoothManager(); 1579ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie try { 1580ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie IBluetoothGatt iGatt = managerService.getBluetoothGatt(); 158132ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie if (iGatt == null) { 158232ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie // BLE is not supported 158332ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie return null; 158432ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie } 1585b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta BluetoothGatt gatt = new BluetoothGatt(context, iGatt, this, transport); 1586ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie gatt.connect(autoConnect, callback); 1587ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return gatt; 1588ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 1589ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return null; 1590ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 15919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 1592