BluetoothDevice.java revision 3b3d1fea94318a4892fbd4353269749af417a81a
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. 95005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 96005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // TODO: Change API to not broadcast RSSI if not available (incoming connection) 98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 99005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_FOUND = 100005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.FOUND"; 101005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 102005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Remote device disappeared. 104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Sent when a remote device that was found in the last discovery is not 105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * found in the current discovery. 106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 108005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @hide 109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 110005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 111005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_DISAPPEARED = 112005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.DISAPPEARED"; 113005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 114005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 115005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Bluetooth class of a remote device has changed. 116005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link 117005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_CLASS}. 118005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 119b30f91e38c19f6728d836293446d4b9c76705e7fMatthew Xie * {@see BluetoothClass} 120005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 121005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_CLASS_CHANGED = 123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.CLASS_CHANGED"; 124005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 126005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a low level (ACL) connection has been 127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * established with a remote device. 128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>ACL connections are managed automatically by the Android Bluetooth 130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stack. 131005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 132005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 134005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_CONNECTED = 135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_CONNECTED"; 136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates that a low level (ACL) disconnection has 139005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * been requested for a remote device, and it will soon be disconnected. 140005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>This is useful for graceful disconnection. Applications should use 141005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * this intent as a hint to immediately terminate higher level connections 142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * (RFCOMM, L2CAP, or profile connections) to the remote device. 143005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 145005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 146005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 147005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_DISCONNECT_REQUESTED = 148005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED"; 149005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 150005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a low level (ACL) disconnection from a 152005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * remote device. 153005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 154005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>ACL connections are managed automatically by the Android Bluetooth 155005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stack. 156005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 157005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 158005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 159005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_ACL_DISCONNECTED = 160005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.ACL_DISCONNECTED"; 161005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 162005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 163005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates the friendly name of a remote device has 164005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * been retrieved for the first time, or changed since the last retrieval. 165005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link 166005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_NAME}. 167005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 168005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 169005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 170005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_NAME_CHANGED = 171005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.NAME_CHANGED"; 172005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 173005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 1745bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * Broadcast Action: Indicates the alias of a remote device has been 1755bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * changed. 1765bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 1775bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 1785bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * 1795bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown * @hide 1805bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown */ 1815bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1825bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown public static final String ACTION_ALIAS_CHANGED = 1835bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown "android.bluetooth.device.action.ALIAS_CHANGED"; 1845bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown 1855bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown /** 186005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a change in the bond state of a remote 187005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * device. For example, if a device is bonded (paired). 188005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link 189005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}. 190005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 191005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 192005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also 193005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly // contain a hidden extra field EXTRA_REASON with the result code. 194005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 195005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_BOND_STATE_CHANGED = 196005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.BOND_STATE_CHANGED"; 197005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 198005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 199005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as a Parcelable {@link BluetoothDevice} extra field in every intent 200005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * broadcast by this class. It contains the {@link BluetoothDevice} that 201005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * the intent applies to. 202005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 203005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE"; 204005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 205005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 206005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link 207005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #ACTION_FOUND} intents. It contains the friendly Bluetooth name. 208005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 209005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME"; 210005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 211005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 212005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an optional short extra field in {@link #ACTION_FOUND} intents. 213005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the RSSI value of the remote device as reported by the 214005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Bluetooth hardware. 215005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 216005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI"; 217005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 218005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 219f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * Used as a Parcelable {@link BluetoothClass} extra field in {@link 220005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents. 221005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 222005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS"; 223005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 224005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 225005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents. 226005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the bond state of the remote device. 227005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values are: 228005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 229005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 230005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 231091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 232005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE"; 233005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 234005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents. 235005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Contains the previous bond state of the remote device. 236005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values are: 237005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 238005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 239005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 240091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 241005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_PREVIOUS_BOND_STATE = 242005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.extra.PREVIOUS_BOND_STATE"; 243005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 244005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates the remote device is not bonded (paired). 245005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>There is no shared link key with the remote device, so communication 246005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * (if it is allowed at all) will be unauthenticated and unencrypted. 247005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 248005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_NONE = 10; 249005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 250005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates bonding (pairing) is in progress with the remote device. 251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_BONDING = 11; 253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 254005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Indicates the remote device is bonded (paired). 255005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>A shared link keys exists locally for the remote device, so 256005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * communication can be authenticated and encrypted. 257005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p><i>Being bonded (paired) with a remote device does not necessarily 258f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * mean the device is currently connected. It just means that the pending 259f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * procedure was completed at some earlier time, and the link key is still 260005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * stored locally, ready to use on the next connection. 261005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * </i> 262005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 263005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int BOND_BONDED = 12; 264005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 265091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 266091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 267091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents for unbond reason. 268091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @hide 269091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 270005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON"; 271091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie 272091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 273091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 274091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents to indicate pairing method used. Possible values are: 275091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * {@link #PAIRING_VARIANT_PIN}, 276091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION}, 277091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 278005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String EXTRA_PAIRING_VARIANT = 279005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.extra.PAIRING_VARIANT"; 280091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie 281091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 282091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST} 283091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * intents as the value of passkey. 284091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 285c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY"; 286005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 287005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 28833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Unknown 28933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 29033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_UNKNOWN = 0; 29133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 29233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 29333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Classic - BR/EDR devices 29433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 29533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_CLASSIC = 1; 29633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 29733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 29833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Low Energy - LE-only 29933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 30033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_LE = 2; 30133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 30233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 30333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Bluetooth device type, Dual Mode - BR/EDR/LE 30433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 30533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public static final int DEVICE_TYPE_DUAL = 3; 30633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 307238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 308238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 309238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 310238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String ACTION_SDP_RECORD = 311238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.action.SDP_RECORD"; 312238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 31333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 3141caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * Broadcast Action: This intent is used to broadcast the {@link UUID} 315aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * wrapped as a {@link android.os.ParcelUuid} of the remote device after it 316aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * has been fetched. This intent is sent only when the UUIDs of the remote 317aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * device are requested to be fetched using Service Discovery Protocol 3181caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * <p> Always contains the extra field {@link #EXTRA_DEVICE} 319ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p> Always contains the extra field {@link #EXTRA_UUID} 3201caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 3211caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 3221caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3231caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public static final String ACTION_UUID = 324ad2321027e9731711544b43378bd7b2f01890774Matthew Xie "android.bluetooth.device.action.UUID"; 3251caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 3268949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 3278949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3288949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final String ACTION_MAS_INSTANCE = 3298949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta "android.bluetooth.device.action.MAS_INSTANCE"; 3308949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 3311caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 332005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Broadcast Action: Indicates a failure to retrieve the name of a remote 333005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * device. 334005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Always contains the extra field {@link #EXTRA_DEVICE}. 335005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. 336005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @hide 337005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 338005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly //TODO: is this actually useful? 339005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 340005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_NAME_FAILED = 341005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.NAME_FAILED"; 342005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 343091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 344091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Broadcast Action: This intent is used to broadcast PAIRING REQUEST 345ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} to 346430e361b202ecff8a10a9258948ade99689fe6b1Edward Jee * receive. 347091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 348005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 349005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_PAIRING_REQUEST = 350005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.PAIRING_REQUEST"; 351005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** @hide */ 352005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 353005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final String ACTION_PAIRING_CANCEL = 354005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly "android.bluetooth.device.action.PAIRING_CANCEL"; 355a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin 356a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 357a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 358a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_REQUEST = 359a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST"; 360a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 361a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 362a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 363a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_REPLY = 364a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY"; 365a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 366a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** @hide */ 367a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 368a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String ACTION_CONNECTION_ACCESS_CANCEL = 369a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL"; 370a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 371a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 372a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent. 373a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 374a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 375a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_ACCESS_REQUEST_TYPE = 376a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE"; 377a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 378a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 379a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1; 380a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 381a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 382a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2; 383a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 384fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie /**@hide*/ 385fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3; 386fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie 3872a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /**@hide*/ 3882a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public static final int REQUEST_TYPE_SIM_ACCESS = 4; 3892a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde 390a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 391a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents, 392a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains package name to return reply intent to. 393a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 394a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 395a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME"; 396a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 397a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 398a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents, 399a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains class name to return reply intent to. 400a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 401a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 402a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME"; 403a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 404a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 405a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent. 406a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 407a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 408a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_CONNECTION_ACCESS_RESULT = 409a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT"; 410a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 411a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 412a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int CONNECTION_ACCESS_YES = 1; 413a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 414a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /**@hide*/ 415a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final int CONNECTION_ACCESS_NO = 2; 416a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 417a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie /** 418a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents, 419a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * Contains boolean to indicate if the allowed response is once-for-all so that 420a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * next request will be granted without asking user again. 421a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie * @hide 422a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie */ 423a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie public static final String EXTRA_ALWAYS_ALLOWED = 424a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie "android.bluetooth.device.extra.ALWAYS_ALLOWED"; 425a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie 426c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 427c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt succeeded 428c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 429c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 430b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly public static final int BOND_SUCCESS = 0; 431c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 432c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 433c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because pins did not match, or remote device did 43432d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh * not respond to pin request in time 435c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 436c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_FAILED = 1; 438c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 439c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 440c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because the other side explicitly rejected 44145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * bonding 442c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 443c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_REJECTED = 2; 445c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 446c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 447c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we canceled the bonding process 448c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 449c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_AUTH_CANCELED = 3; 451c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 452c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 453c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we could not contact the remote device 454c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 455c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4; 457c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 458c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 459c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because a discovery is in progress 460c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 461c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 4629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5; 463c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 464c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 465c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because of authentication timeout 466c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 467c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 46832d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int UNBOND_REASON_AUTH_TIMEOUT = 6; 469c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 470c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 471c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because of repeated attempts 472c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 473c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 47432d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7; 475c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 476c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 477c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * A bond attempt failed because we received an Authentication Cancel 478c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * by remote end 479c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 480c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 481e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8; 482c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 483c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 484c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * An existing bond was explicitly revoked 485c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 486c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 487e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh public static final int UNBOND_REASON_REMOVED = 9; 4889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 489c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 490091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * The user will be prompted to enter a pin or 491ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * an app will enter a pin for user. 492c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 493b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh public static final int PAIRING_VARIANT_PIN = 0; 494c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 495c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 496c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter a passkey 497c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 498c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 499b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh public static final int PAIRING_VARIANT_PASSKEY = 1; 500c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 501c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 502091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * The user will be prompted to confirm the passkey displayed on the screen or 503ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * an app will confirm the passkey for the user. 504c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 50532d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2; 506c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 507c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 508c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to accept or deny the incoming pairing request 509c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 510c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 51132d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_CONSENT = 3; 512c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 513c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 514c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter the passkey displayed on remote device 515c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * This is used for Bluetooth 2.1 pairing. 516c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 517c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 51832d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4; 519c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 520c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 521c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to enter the PIN displayed on remote device. 522c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * This is used for Bluetooth 2.0 pairing. 523c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 524c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 525c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PAIRING_VARIANT_DISPLAY_PIN = 5; 526c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 527c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 528c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * The user will be prompted to accept or deny the OOB pairing request 529c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 530c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 531c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PAIRING_VARIANT_OOB_CONSENT = 6; 532c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 5331caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 5343b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * The user will be prompted to enter a 16 digit pin or 5353b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * an app will enter a 16 digit pin for user. 5363b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde * @hide 5373b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde */ 5383b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde public static final int PAIRING_VARIANT_PIN_16_DIGITS = 7; 5393b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde 5403b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde /** 5411caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * Used as an extra field in {@link #ACTION_UUID} intents, 542aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * Contains the {@link android.os.ParcelUuid}s of the remote device which 543aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly * is a parcelable version of {@link UUID}. 5441caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 5451caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID"; 5461caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 547238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 548238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String EXTRA_SDP_RECORD = 549238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.extra.SDP_RECORD"; 550238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 551238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** @hide */ 552238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public static final String EXTRA_SDP_SEARCH_STATUS = 553238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde "android.bluetooth.device.extra.SDP_SEARCH_STATUS"; 5548dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5558dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5568dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5578dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5588dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_UNKNOWN = 0; 5608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 5618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5638dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5648dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5658dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5668dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_ALLOWED = 1; 5678dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 5688dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 5698dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission}, 5708dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}. 5718dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 5728dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 5738dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public static final int ACCESS_REJECTED = 2; 5748dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 575b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 576b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * No preferrence of physical transport for GATT connections to remote dual-mode devices 577b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 578b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta public static final int TRANSPORT_AUTO = 0; 579b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 580b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 581b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Prefer BR/EDR transport for GATT connections to remote dual-mode devices 582b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 5838949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final int TRANSPORT_BREDR = 1; 584b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 585b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 586b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Prefer LE transport for GATT connections to remote dual-mode devices 587b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 5888949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final int TRANSPORT_LE = 2; 589b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 5908949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 5918949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public static final String EXTRA_MAS_INSTANCE = 5928949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta "android.bluetooth.device.extra.MAS_INSTANCE"; 593b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 59416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 59516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Lazy initialization. Guaranteed final after first object constructed, or 59616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * getService() called. 59716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * TODO: Unify implementation of sService amongst BluetoothFoo API's 59816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 59916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly private static IBluetooth sService; 600bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 601bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly private final String mAddress; 602d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh 60316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /*package*/ static IBluetooth getService() { 604bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly synchronized (BluetoothDevice.class) { 605bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly if (sService == null) { 6060f42037eb7b5118015c2caca635538324ccf0ccffredc BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 607903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc sService = adapter.getBluetoothService(mStateChangeCallback); 608bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 609bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 61016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return sService; 61116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly } 612bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 613903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() { 614903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc 615903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc public void onBluetoothServiceUp(IBluetooth bluetoothService) 616903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc throws RemoteException { 617903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc synchronized (BluetoothDevice.class) { 618d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (sService == null) { 619d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora sService = bluetoothService; 620d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 621903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 622903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 623903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc 624903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc public void onBluetoothServiceDown() 625903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc throws RemoteException { 626903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc synchronized (BluetoothDevice.class) { 627903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc sService = null; 628903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 629903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc } 630d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 631d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora public void onBrEdrDown() 632d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora { 633d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (DBG) Log.d(TAG, "onBrEdrDown: reached BLE ON state"); 634d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 635903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc }; 63616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 63716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Create a new BluetoothDevice 63816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB", 63916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * and is validated in this constructor. 64016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @param address valid Bluetooth MAC address 64116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws RuntimeException Bluetooth is not available on this platform 64216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws IllegalArgumentException address is invalid 64316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @hide 64416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 64516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /*package*/ BluetoothDevice(String address) { 64616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly getService(); // ensures sService is initialized 647005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (!BluetoothAdapter.checkBluetoothAddress(address)) { 648bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly throw new IllegalArgumentException(address + " is not a valid Bluetooth address"); 649bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 650bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 651bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly mAddress = address; 6529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 654bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 655bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean equals(Object o) { 656bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly if (o instanceof BluetoothDevice) { 657bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress.equals(((BluetoothDevice)o).getAddress()); 658bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 662bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 663bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int hashCode() { 664bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress.hashCode(); 665105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project } 666105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project 66745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** 66845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Returns a string representation of this BluetoothDevice. 66945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>Currently this is the Bluetooth hardware address, for example 67045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress} 67145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * if you explicitly require the Bluetooth hardware address in case the 67245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link #toString} representation changes in the future. 67345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return string representation of this BluetoothDevice 67445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly */ 675bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly @Override 676bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public String toString() { 677bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress; 6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 680bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int describeContents() { 681bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return 0; 682bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 683bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 684bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public static final Parcelable.Creator<BluetoothDevice> CREATOR = 685bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly new Parcelable.Creator<BluetoothDevice>() { 686bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothDevice createFromParcel(Parcel in) { 687bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return new BluetoothDevice(in.readString()); 688bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 689bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothDevice[] newArray(int size) { 690bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return new BluetoothDevice[size]; 691bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 692bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly }; 693bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 694bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public void writeToParcel(Parcel out, int flags) { 695bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly out.writeString(mAddress); 6969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 69845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** 69945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Returns the hardware address of this BluetoothDevice. 70045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p> For example, "00:11:22:AA:BB:CC". 70145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return Bluetooth hardware address as string 70245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly */ 7039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String getAddress() { 7040f42037eb7b5118015c2caca635538324ccf0ccffredc if (DBG) Log.d(TAG, "mAddress: " + mAddress); 705bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return mAddress; 7069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 70945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Get the friendly Bluetooth name of the remote device. 7109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 71145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>The local adapter will automatically retrieve remote names when 71245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * performing a device scan, and will cache them. This method just returns 71345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * the name for this device from the cache. 714de893f550301a60274e87aa8168225e7a7a42184Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 7159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the Bluetooth name, or null if there was a problem. 7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7182d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 7199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String getName() { 7200f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7210f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Remote Device name"); 7220f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 7230f42037eb7b5118015c2caca635538324ccf0ccffredc } 7249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 725e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteName(this); 7269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 7279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 7289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 73133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * Get the Bluetooth device type of the remote device. 73233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * 73333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 73433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * 73533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE} 73633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * {@link #DEVICE_TYPE_DUAL}. 73733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * {@link #DEVICE_TYPE_UNKNOWN} if it's not available 73833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie */ 7392d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 74033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public int getType() { 74133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie if (sService == null) { 74233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie Log.e(TAG, "BT not enabled. Cannot get Remote Device type"); 74333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return DEVICE_TYPE_UNKNOWN; 74433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } 74533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie try { 74633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return sService.getRemoteType(this); 74733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 74833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie return DEVICE_TYPE_UNKNOWN; 74933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie } 75033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie 75133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie /** 752269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Get the Bluetooth alias of the remote device. 753269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>Alias is the locally modified name of a remote device. 754269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 755269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return the Bluetooth alias, or null if no alias or there was a problem 756269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 757269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 758269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public String getAlias() { 7590f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7600f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias"); 7610f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 7620f42037eb7b5118015c2caca635538324ccf0ccffredc } 763269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie try { 764e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteAlias(this); 765269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 766269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return null; 767269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 768269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 769269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 770269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Set the Bluetooth alias of the remote device. 771269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>Alias is the locally modified name of a remote device. 772269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * <p>This methoid overwrites the alias. The changed 773269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * alias is saved in the local storage so that the change 774269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * is preserved over power cycle. 775269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 776269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return true on success, false on error 777269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 778269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 779269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public boolean setAlias(String alias) { 7800f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 7810f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set Remote Device name"); 7820f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 7830f42037eb7b5118015c2caca635538324ccf0ccffredc } 784269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie try { 785e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setRemoteAlias(this, alias); 786269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 787269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return false; 788269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 789269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 790269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 791269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * Get the Bluetooth alias of the remote device. 792269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * If Alias is null, get the Bluetooth name instead. 793269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @see #getAlias() 794269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @see #getName() 795269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * 796269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @return the Bluetooth alias, or null if no alias or there was a problem 797269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie * @hide 798269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie */ 799269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie public String getAliasName() { 800269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie String name = getAlias(); 801269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie if (name == null) { 802269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie name = getName(); 803269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 804269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie return name; 805269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie } 806269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie 807269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie /** 808005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Start the bonding (pairing) process with the remote device. 809005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>This is an asynchronous call, it will return immediately. Register 810005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 811005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * the bonding process completes, and its result. 812005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Android system services will handle the necessary user interactions 813005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * to confirm and complete the bonding process. 814ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 8159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 816005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return false on immediate error, true if bonding will begin 8179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8182d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) 819bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean createBond() { 8200f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 8210f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device"); 8220f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 8230f42037eb7b5118015c2caca635538324ccf0ccffredc } 8249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 82557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return sService.createBond(this, TRANSPORT_AUTO); 82657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } catch (RemoteException e) {Log.e(TAG, "", e);} 82757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return false; 82857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 82957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach 83057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach /** 83157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * Start the bonding (pairing) process with the remote device using the 83257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * specified transport. 83357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * 83457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>This is an asynchronous call, it will return immediately. Register 83557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 83657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * the bonding process completes, and its result. 83757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>Android system services will handle the necessary user interactions 83857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * to confirm and complete the bonding process. 83957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 84057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * 84157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @param transport The transport to use for the pairing procedure. 84257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @return false on immediate error, true if bonding will begin 84357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @throws IllegalArgumentException if an invalid transport was specified 84457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach * @hide 84557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach */ 84657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach public boolean createBond(int transport) { 84757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach if (sService == null) { 84857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device"); 84957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return false; 85057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 85157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE) 85257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach { 85357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport"); 85457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach } 85557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach try { 85657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach return sService.createBond(this, transport); 8579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 8589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 8599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 862cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Start the bonding (pairing) process with the remote device using the 863cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Out Of Band mechanism. 864cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 865cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>This is an asynchronous call, it will return immediately. Register 866cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when 867cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * the bonding process completes, and its result. 868cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 869cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Android system services will handle the necessary user interactions 870cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * to confirm and complete the bonding process. 871cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 872cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 873cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 874cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param hash - Simple Secure pairing hash 875cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param randomizer - The random key obtained using OOB 876cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @return false on immediate error, true if bonding will begin 877cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 878cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @hide 879cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh */ 880cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh public boolean createBondOutOfBand(byte[] hash, byte[] randomizer) { 881e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh //TODO(BT) 882e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 883cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 884e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.createBondOutOfBand(this, hash, randomizer); 885e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 886cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 887cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 888cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 889cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** 890cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * Set the Out Of Band data for a remote device to be used later 891cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * in the pairing mechanism. Users can obtain this data through other 892cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * trusted channels 893cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 894cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 895cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 896cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param hash Simple Secure pairing hash 897cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @param randomizer The random key obtained using OOB 898cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @return false on error; true otherwise 899cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * 900cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh * @hide 901cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh */ 902cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) { 903e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh //TODO(BT) 904e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 905cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 906e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setDeviceOutOfBandData(this, hash, randomizer); 907e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);} */ 908cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 909cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 910cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 911cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** 912005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Cancel an in-progress bonding request started with {@link #createBond}. 913005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 914005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 915f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return true on success, false on error 91618b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly * @hide 9179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 918bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean cancelBondProcess() { 9190f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9200f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond"); 9210f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 9220f42037eb7b5118015c2caca635538324ccf0ccffredc } 9239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 924e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.cancelBondProcess(this); 9259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 9269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 9279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 930005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Remove bond (pairing) with the remote device. 931005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Delete the link key associated with the remote device, and 932005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * immediately terminate connections to that device that require 933005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * authentication and encryption. 934005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 9359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 936f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return true on success, false on error 93718b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly * @hide 9389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 939bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean removeBond() { 9400f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9410f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond"); 9420f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 9430f42037eb7b5118015c2caca635538324ccf0ccffredc } 9449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 945e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.removeBond(this); 9469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 947bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly return false; 9489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 951005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Get the bond state of the remote device. 952005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Possible values for the bond state are: 953005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_NONE}, 954005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDING}, 955005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link #BOND_BONDED}. 956005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 9579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 958005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return the bond state 9599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9602d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 961bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public int getBondState() { 9620f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 9630f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get bond state"); 9640f42037eb7b5118015c2caca635538324ccf0ccffredc return BOND_NONE; 9650f42037eb7b5118015c2caca635538324ccf0ccffredc } 9669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 967e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getBondState(this); 9689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 969305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M catch (NullPointerException npe) { 970305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M // Handle case where bluetooth service proxy 971305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M // is already null. 972305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M Log.e(TAG, "NullPointerException for getBondState() of device ("+ 973305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M getAddress()+")", npe); 974305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M } 975005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return BOND_NONE; 976005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 977005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 978005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 979174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * Returns whether there is an open connection to this device. 980174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 981174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * 982174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * @return True if there is at least one open connection to this device. 983174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli * @hide 984174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli */ 9852b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach @SystemApi 986174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli public boolean isConnected() { 987174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli if (sService == null) { 988174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli // BT is not enabled, we cannot be connected. 989174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli return false; 990174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 991174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli try { 9922b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return sService.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED; 9932b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } catch (RemoteException e) { 9942b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach Log.e(TAG, "", e); 9952b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return false; 9962b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 9972b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 9982b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach 9992b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach /** 10002b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * Returns whether there is an open connection to this device 10012b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * that has been encrypted. 10022b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 10032b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * 10042b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * @return True if there is at least one encrypted connection to this device. 10052b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach * @hide 10062b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach */ 10072b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach @SystemApi 10082b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach public boolean isEncrypted() { 10092b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach if (sService == null) { 10102b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach // BT is not enabled, we cannot be connected. 10112b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return false; 10122b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach } 10132b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach try { 10142b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach return sService.getConnectionState(this) > CONNECTION_STATE_CONNECTED; 1015174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } catch (RemoteException e) { 1016174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli Log.e(TAG, "", e); 1017174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli return false; 1018174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 1019174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli } 1020174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli 1021174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli /** 1022005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Get the Bluetooth class of the remote device. 1023005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1024005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 1025005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return Bluetooth class object, or null on error 1026005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 10272d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 1028005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public BluetoothClass getBluetoothClass() { 10290f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 10300f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class"); 10310f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 10320f42037eb7b5118015c2caca635538324ccf0ccffredc } 1033005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly try { 1034e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh int classInt = sService.getRemoteClass(this); 1035005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (classInt == BluetoothClass.ERROR) return null; 1036005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return new BluetoothClass(classInt); 1037005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } catch (RemoteException e) {Log.e(TAG, "", e);} 1038005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return null; 10399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1041efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue /** 1042ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * Returns the supported features (UUIDs) of the remote device. 1043ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1044ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>This method does not start a service discovery procedure to retrieve the UUIDs 1045ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * from the remote device. Instead, the local cached copy of the service 1046ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * UUIDs are returned. 1047ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired. 1048ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1049ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1050ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * @return the supported features (UUIDs) of the remote device, 1051ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * or null on error 1052ad2321027e9731711544b43378bd7b2f01890774Matthew Xie */ 10532d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 1054dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh public ParcelUuid[] getUuids() { 1055d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (sService == null || isBluetoothEnabled() == false) { 10560f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot get remote device Uuids"); 10570f42037eb7b5118015c2caca635538324ccf0ccffredc return null; 10580f42037eb7b5118015c2caca635538324ccf0ccffredc } 10599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1060e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.getRemoteUuids(this); 10619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 10629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 10639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1064d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh 10651caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh /** 1066ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * Perform a service discovery on the remote device to get the UUIDs supported. 1067ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * 1068ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent, 1069ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * with the UUIDs supported by the remote end. If there is an error 1070ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * in getting the SDP records or if the process takes a long time, 1071ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently 1072ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * present in the cache. Clients should use the {@link #getUuids} to get UUIDs 1073ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * if service discovery is not to be performed. 1074ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 10751caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * 1076ad2321027e9731711544b43378bd7b2f01890774Matthew Xie * @return False if the sanity check fails, True if the process 10771caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * of initiating an ACL connection to the remote device 10781caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh * was started. 10791caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh */ 10802d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 10811caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh public boolean fetchUuidsWithSdp() { 10825d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu IBluetooth service = sService; 1083d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (service == null || isBluetoothEnabled() == false) { 10845d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp"); 10855d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu return false; 10865d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu } 10871caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh try { 10885d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu return service.fetchRemoteUuids(this); 10894c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc } catch (RemoteException e) {Log.e(TAG, "", e);} 10904c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc return false; 10911caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh } 10921caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh 1093238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** 1094238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Perform a service discovery on the remote device to get the SDP records associated 1095238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * with the specified UUID. 1096238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1097238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent, 1098238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * with the SDP records found on the remote end. If there is an error 1099238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * in getting the SDP records or if the process takes a long time, 1100238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * {@link #ACTION_SDP_RECORD} intent is sent with an status value in 1101238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0. 1102238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Detailed status error codes can be found by members of the Bluetooth package in 1103238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * the AbstractionLayer class. 1104238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH}. 1105238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}. 1106238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * The object type will match one of the SdpXxxRecord types, depending on the UUID searched 1107238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * for. 1108238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1109238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @return False if the sanity check fails, True if the process 1110238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * of initiating an ACL connection to the remote device 1111238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * was started. 1112238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde */ 11138949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** @hide */ 1114238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public boolean sdpSearch(ParcelUuid uuid) { 11158949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta if (sService == null) { 1116238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde Log.e(TAG, "BT not enabled. Cannot query remote device sdp records"); 11178949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta return false; 11188949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } 11198949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta try { 1120238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde return sService.sdpSearch(this,uuid); 11218949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } catch (RemoteException e) {Log.e(TAG, "", e);} 11228949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta return false; 11238949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } 11248949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 1125091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 1126091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN} 1127ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 1128091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * 1129091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @return true pin has been set 1130091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * false for error 1131091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 1132bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPin(byte[] pin) { 11330f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 11340f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set Remote Device pin"); 11350f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 11360f42037eb7b5118015c2caca635538324ccf0ccffredc } 11379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1138e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPin(this, true, pin.length, pin); 11399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException e) {Log.e(TAG, "", e);} 11409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 11419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1142b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 114345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** @hide */ 1144bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPasskey(int passkey) { 1145e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh //TODO(BT) 1146e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 1147b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh try { 1148e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPasskey(this, true, 4, passkey); 1149e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 1150b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh return false; 1151b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } 1152b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 1153091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie /** 1154091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing. 1155ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. 1156091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * 1157091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * @return true confirmation has been sent out 1158091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie * false for error 1159091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie */ 11602d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) 1161bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean setPairingConfirmation(boolean confirm) { 11620f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 11630f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot set pairing confirmation"); 11640f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 11650f42037eb7b5118015c2caca635538324ccf0ccffredc } 1166b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh try { 1167e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setPairingConfirmation(this, confirm); 1168b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);} 1169b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh return false; 1170b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh } 1171b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh 117245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly /** @hide */ 1173cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh public boolean setRemoteOutOfBandData() { 1174e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh // TODO(BT) 1175e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 1176cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh try { 1177e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.setRemoteOutOfBandData(this); 1178e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 1179cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh return false; 1180cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh } 1181cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh 1182cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh /** @hide */ 1183bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public boolean cancelPairingUserInput() { 11840f42037eb7b5118015c2caca635538324ccf0ccffredc if (sService == null) { 11850f42037eb7b5118015c2caca635538324ccf0ccffredc Log.e(TAG, "BT not enabled. Cannot create pairing user input"); 11860f42037eb7b5118015c2caca635538324ccf0ccffredc return false; 11870f42037eb7b5118015c2caca635538324ccf0ccffredc } 11889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1189919a4c6264b733585152ce1dc6f868c1093d368bRavi Nagarajan return sService.cancelBondProcess(this); 1190db44b20fe6aed65d5cd7e1f6d7c52e4322083039Priti Aghera } catch (RemoteException e) {Log.e(TAG, "", e);} 11919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return false; 11929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11943fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh /** @hide */ 11953fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh public boolean isBluetoothDock() { 1196e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh // TODO(BT) 1197e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh /* 11983fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh try { 1199e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh return sService.isBluetoothDock(this); 1200e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh } catch (RemoteException e) {Log.e(TAG, "", e);}*/ 12013fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh return false; 12023fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh } 12033fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh 1204d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora boolean isBluetoothEnabled() { 1205d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora boolean ret = false; 1206d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 1207d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (adapter != null && adapter.isEnabled() == true) { 1208d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora ret = true; 1209d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1210d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora return ret; 1211d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1212d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 12139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12148dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Requires {@link android.Manifest.permission#BLUETOOTH}. 12158dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the phonebook access is allowed to this device. Can be 12168dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 12178dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12188dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12198dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public int getPhonebookAccessPermission() { 12208dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12218dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12228dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12238dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12248dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.getPhonebookAccessPermission(this); 12258dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12268dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12278dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12288dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12298dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12308dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12318dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12328dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Sets whether the phonebook access is allowed to this device. 12338dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 12348dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 12358dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_REJECTED}. 12368dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the value has been successfully set. 12378dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12388dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12398dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public boolean setPhonebookAccessPermission(int value) { 12408dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12418dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12428dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12438dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12448dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.setPhonebookAccessPermission(this, value); 12458dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12468dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12478dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12488dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12498dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12508dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12518dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12528dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Requires {@link android.Manifest.permission#BLUETOOTH}. 12538dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the message access is allowed to this device. Can be 12548dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 12558dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12568dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12578dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public int getMessageAccessPermission() { 12588dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.getMessageAccessPermission(this); 12638dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12648dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12658dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12668dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return ACCESS_UNKNOWN; 12678dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12688dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12698dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12708dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * Sets whether the message access is allowed to this device. 12718dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 12728dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 12738dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * {@link #ACCESS_REJECTED}. 12748dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @return Whether the value has been successfully set. 12758dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee * @hide 12768dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee */ 12778dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee public boolean setMessageAccessPermission(int value) { 12788dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee if (sService == null) { 12798dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12808dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12818dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee try { 12828dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return sService.setMessageAccessPermission(this, value); 12838dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } catch (RemoteException e) { 12848dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee Log.e(TAG, "", e); 12858dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12868dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee return false; 12878dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee } 12888dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee 12898dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee /** 12902a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * Requires {@link android.Manifest.permission#BLUETOOTH}. 12912a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @return Whether the Sim access is allowed to this device. Can be 12922a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}. 12932a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @hide 12942a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde */ 12952a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public int getSimAccessPermission() { 12962a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde if (sService == null) { 12972a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return ACCESS_UNKNOWN; 12982a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 12992a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde try { 13002a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return sService.getSimAccessPermission(this); 13012a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } catch (RemoteException e) { 13022a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde Log.e(TAG, "", e); 13032a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13042a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return ACCESS_UNKNOWN; 13052a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13062a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde 13072a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /** 13082a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * Sets whether the Sim access is allowed to this device. 13092a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}. 13102a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or 13112a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * {@link #ACCESS_REJECTED}. 13122a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @return Whether the value has been successfully set. 13132a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde * @hide 13142a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde */ 13152a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde public boolean setSimAccessPermission(int value) { 13162a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde if (sService == null) { 13172a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return false; 13182a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13192a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde try { 13202a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return sService.setSimAccessPermission(this, value); 13212a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } catch (RemoteException e) { 13222a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde Log.e(TAG, "", e); 13232a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde } 13242a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde return false; 13253b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde } 13263b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde 13272a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde /** 132845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * Create an RFCOMM {@link BluetoothSocket} ready to start a secure 132916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * outgoing connection to this remote device on given channel. 133045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>The remote device will be authenticated and communication on this 133145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * socket will be encrypted. 1332c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p> Use this socket only if an authenticated socket link is possible. 1333c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Authentication refers to the authentication of the link key to 1334c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * prevent man-in-the-middle type of attacks. 1335c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For example, for Bluetooth 2.1 devices, if any of the devices does not 1336c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * have an input and output capability or just has the ability to 1337c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * display a numeric key, a secure socket connection is not possible. 1338c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * In such a case, use {#link createInsecureRfcommSocket}. 1339c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For more details, refer to the Security Model section 5.2 (vol 3) of 1340c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Bluetooth Core Specification version 2.1 + EDR. 1341f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 134245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * connection. 134345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>Valid RFCOMM channels are in range 1 to 30. 1344cf44059813539bf7f36dabd278cef93ba3122c56Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 1345de893f550301a60274e87aa8168225e7a7a42184Nick Pelly * 134645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @param channel RFCOMM channel to connect to 134745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 1348bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException on error, for example Bluetooth not available, or 134945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * insufficient permissions 135016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @hide 1351bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 135245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly public BluetoothSocket createRfcommSocket(int channel) throws IOException { 1353d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1354d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1355d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1356d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 135716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel, 135816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly null); 135916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly } 136016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly 136116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly /** 1362238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Create an L2cap {@link BluetoothSocket} ready to start a secure 1363238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * outgoing connection to this remote device on given channel. 1364238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>The remote device will be authenticated and communication on this 1365238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * socket will be encrypted. 1366238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p> Use this socket only if an authenticated socket link is possible. 1367238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Authentication refers to the authentication of the link key to 1368238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * prevent man-in-the-middle type of attacks. 1369238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * For example, for Bluetooth 2.1 devices, if any of the devices does not 1370238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * have an input and output capability or just has the ability to 1371238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * display a numeric key, a secure socket connection is not possible. 1372238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * In such a case, use {#link createInsecureRfcommSocket}. 1373238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * For more details, refer to the Security Model section 5.2 (vol 3) of 1374238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * Bluetooth Core Specification version 2.1 + EDR. 1375238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 1376238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * connection. 1377238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Valid L2CAP PSM channels are in range 1 to 2^16. 1378238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 1379238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * 1380238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @param channel L2cap PSM/channel to connect to 1381238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 1382238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @throws IOException on error, for example Bluetooth not available, or 1383238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * insufficient permissions 1384238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde * @hide 1385238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde */ 1386238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde public BluetoothSocket createL2capSocket(int channel) throws IOException { 1387238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, true, true, this, channel, 1388238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde null); 1389238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde } 1390238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde 1391238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde /** 139216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Create an RFCOMM {@link BluetoothSocket} ready to start a secure 139316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * outgoing connection to this remote device using SDP lookup of uuid. 139416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>This is designed to be used with {@link 139516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer 139616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * Bluetooth applications. 1397f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 139816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * connection. This will also perform an SDP lookup of the given uuid to 139916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * determine which channel to connect to. 140016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>The remote device will be authenticated and communication on this 140116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * socket will be encrypted. 1402c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * <p> Use this socket only if an authenticated socket link is possible. 1403c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Authentication refers to the authentication of the link key to 1404c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * prevent man-in-the-middle type of attacks. 1405c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For example, for Bluetooth 2.1 devices, if any of the devices does not 1406c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * have an input and output capability or just has the ability to 1407c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * display a numeric key, a secure socket connection is not possible. 1408c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}. 1409c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * For more details, refer to the Security Model section 5.2 (vol 3) of 1410c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh * Bluetooth Core Specification version 2.1 + EDR. 1411ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * <p>Hint: If you are connecting to a Bluetooth serial board then try 1412ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. 1413ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * However if you are connecting to an Android peer then please generate 1414ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly * your own unique UUID. 141516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 141616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * 141716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @param uuid service record uuid to lookup RFCOMM channel 141816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 141916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * @throws IOException on error, for example Bluetooth not available, or 142016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly * insufficient permissions 142116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly */ 14222d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 142316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException { 1424d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1425d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1426d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1427d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 1428d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 142916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1, 143016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly new ParcelUuid(uuid)); 1431bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1432bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1433bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 14346eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure 14356eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * outgoing connection to this remote device using SDP lookup of uuid. 14366eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p> The communication channel will not have an authenticated link key 14376eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1 14386eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * devices, the link key will be encrypted, as encryption is mandatory. 14396eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * For legacy devices (pre Bluetooth 2.1 devices) the link key will 14406eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an 14416eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * encrypted and authenticated communication channel is desired. 14426eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>This is designed to be used with {@link 14436eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer 14446eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * Bluetooth applications. 14456eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing 14466eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * connection. This will also perform an SDP lookup of the given uuid to 14476eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * determine which channel to connect to. 14486eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>The remote device will be authenticated and communication on this 14496eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * socket will be encrypted. 14506eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Hint: If you are connecting to a Bluetooth serial board then try 14516eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. 14526eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * However if you are connecting to an Android peer then please generate 14536eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * your own unique UUID. 14546eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * <p>Requires {@link android.Manifest.permission#BLUETOOTH} 14556eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * 14566eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @param uuid service record uuid to lookup RFCOMM channel 14576eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection 14586eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * @throws IOException on error, for example Bluetooth not available, or 14596eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh * insufficient permissions 14606eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh */ 14612d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye @RequiresPermission(Manifest.permission.BLUETOOTH) 14626eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException { 1463d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1464d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1465d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1466d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 14676eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1, 14686eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh new ParcelUuid(uuid)); 14696eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh } 14706eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh 14716eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh /** 1472bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Construct an insecure RFCOMM socket ready to start an outgoing 1473bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * connection. 1474bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Call #connect on the returned #BluetoothSocket to begin the connection. 1475bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * The remote device will not be authenticated and communication on this 1476bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * socket will not be encrypted. 1477e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} 1478e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * 1479bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @param port remote port 1480bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @return An RFCOMM BluetoothSocket 1481bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException On error, for example Bluetooth not available, or 1482bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * insufficient permissions. 148345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 1484bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 1485bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException { 1486d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 1487d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1488d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1489d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1490d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 149116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port, 149216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly null); 1493bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1494bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1495bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 1496bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Construct a SCO socket ready to start an outgoing connection. 1497bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Call #connect on the returned #BluetoothSocket to begin the connection. 1498e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} 1499e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly * 1500bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @return a SCO BluetoothSocket 1501bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * @throws IOException on error, for example Bluetooth not available, or 1502bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * insufficient permissions. 150345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 1504bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly */ 1505bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly public BluetoothSocket createScoSocket() throws IOException { 1506d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora 1507d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora if (isBluetoothEnabled() == false) { 1508d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora Log.e(TAG, "Bluetooth is not enabled"); 1509d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora throw new IOException(); 1510d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora } 151116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null); 1512bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly } 1513bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly 1514bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly /** 15159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Check that a pin is valid and convert to byte array. 15169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1517f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters. 15189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param pin pin as java String 1519f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * @return the pin code as a UTF-8 byte array, or null if it is an invalid 15209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Bluetooth pin. 152145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * @hide 15229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 15239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static byte[] convertPinToBytes(String pin) { 15249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (pin == null) { 15259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project byte[] pinBytes; 15289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 1529f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby pinBytes = pin.getBytes("UTF-8"); 15309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (UnsupportedEncodingException uee) { 1531f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby Log.e(TAG, "UTF-8 not supported?!?"); // this should not happen 15329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (pinBytes.length <= 0 || pinBytes.length > 16) { 15359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 15369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return pinBytes; 15389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1540ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1541ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Connect to GATT Server hosted by this device. Caller acts as GATT client. 1542ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * The callback is used to deliver results to Caller, such as connection status as well 1543ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * as any further GATT client operations. 1544ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct 1545ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * GATT client operations. 1546ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param callback GATT callback handler that will receive asynchronous callbacks. 1547ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param autoConnect Whether to directly connect to the remote device (false) 1548ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * or to automatically connect as soon as the remote 1549ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * device becomes available (true). 1550ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @throws IllegalArgumentException if callback is null 1551ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 155233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie public BluetoothGatt connectGatt(Context context, boolean autoConnect, 155333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie BluetoothGattCallback callback) { 1554b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO)); 1555b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta } 1556b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta 1557b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta /** 1558b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * Connect to GATT Server hosted by this device. Caller acts as GATT client. 1559b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * The callback is used to deliver results to Caller, such as connection status as well 1560b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * as any further GATT client operations. 1561b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct 1562b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * GATT client operations. 1563b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param callback GATT callback handler that will receive asynchronous callbacks. 1564b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param autoConnect Whether to directly connect to the remote device (false) 1565b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * or to automatically connect as soon as the remote 1566b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * device becomes available (true). 1567b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @param transport preferred transport for GATT connections to remote dual-mode devices 1568b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * {@link BluetoothDevice#TRANSPORT_AUTO} or 1569b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE} 1570b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta * @throws IllegalArgumentException if callback is null 1571b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta */ 1572b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta public BluetoothGatt connectGatt(Context context, boolean autoConnect, 1573b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta BluetoothGattCallback callback, int transport) { 1574ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie // TODO(Bluetooth) check whether platform support BLE 1575ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie // Do the check here or in GattServer? 1576ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 1577ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie IBluetoothManager managerService = adapter.getBluetoothManager(); 1578ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie try { 1579ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie IBluetoothGatt iGatt = managerService.getBluetoothGatt(); 158032ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie if (iGatt == null) { 158132ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie // BLE is not supported 158232ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie return null; 158332ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie } 1584b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta BluetoothGatt gatt = new BluetoothGatt(context, iGatt, this, transport); 1585ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie gatt.connect(autoConnect, callback); 1586ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return gatt; 1587ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } catch (RemoteException e) {Log.e(TAG, "", e);} 1588ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return null; 1589ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 15909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 1591