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;
25b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowskiimport android.os.Handler;
26b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowskiimport android.os.Looper;
27bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcel;
28bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcelable;
29aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pellyimport android.os.ParcelUuid;
30044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstromimport android.os.Process;
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException;
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log;
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
34bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport java.io.IOException;
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.UnsupportedEncodingException;
361caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganeshimport java.util.UUID;
379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
399fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you
40f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * create a connection with the respective device or query information about
419fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * it, such as the name, address, class, and bonding state.
4245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly *
4345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>This class is really just a thin wrapper for a Bluetooth hardware
4445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * address. Objects of this class are immutable. Operations on this class
4545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * are performed on the remote Bluetooth hardware address, using the
4645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link BluetoothAdapter} that was used to create this {@link
4745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * BluetoothDevice}.
489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>To get a {@link BluetoothDevice}, use
509fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter#getRemoteDevice(String)
519fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device
529fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * of a known MAC address (which you can get through device discovery with
539fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter}) or get one from the set of bonded devices
549fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * returned by {@link BluetoothAdapter#getBondedDevices()
559fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getBondedDevices()}. You can then open a
56f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * {@link BluetoothSocket} for communication with the remote device, using
579fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link #createRfcommSocketToServiceRecord(UUID)}.
589fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
599fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p class="note"><strong>Note:</strong>
609fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Requires the {@link android.Manifest.permission#BLUETOOTH} permission.
619fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
623aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference">
633aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3>
6465813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * <p>
6565813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * For more information about using Bluetooth, read the <a href=
6665813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * "{@docRoot}guide/topics/connectivity/bluetooth.html">Bluetooth</a> developer
6765813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * guide.
6865813dff148d18028415fbf6682f3c35f49d5462Hemal Patel * </p>
693aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div>
703aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez *
719fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothAdapter}
729fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothSocket}
739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
74bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellypublic final class BluetoothDevice implements Parcelable {
75bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private static final String TAG = "BluetoothDevice";
767077272d8feed2f0172520d4fd3b4524e18d5ec1Ravi Nagarajan    private static final boolean DBG = false;
779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
78b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    /**
792b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * Connection state bitmask as returned by getConnectionState.
802b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     */
812b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_DISCONNECTED = 0;
822b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_CONNECTED = 1;
832b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_ENCRYPTED_BREDR = 2;
842b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_ENCRYPTED_LE = 4;
852b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach
862b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    /**
87b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * Sentinel error value for this class. Guaranteed to not equal any other
88b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * integer constant in this class. Provided as a convenience for functions
89b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * that require a sentinel error value, for example:
90005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><code>Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
91005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * BluetoothDevice.ERROR)</code>
92005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
93005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int ERROR = Integer.MIN_VALUE;
94005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
95005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
96005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device discovered.
97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device is found during discovery.
98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
99005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}. Can contain the extra fields {@link #EXTRA_NAME} and/or
100005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #EXTRA_RSSI} if they are available.
10172f491dd8642e6854fd4c6d40d77c06312af6e3bFyodor Kupolov     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} and
10272f491dd8642e6854fd4c6d40d77c06312af6e3bFyodor Kupolov     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} to receive.
103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     // TODO: Change API to not broadcast RSSI if not available (incoming connection)
105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_FOUND =
107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.FOUND";
108005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
110005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device disappeared.
111005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device that was found in the last discovery is not
112005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * found in the current discovery.
113005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
114005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
115005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
116005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
117005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
118005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_DISAPPEARED =
119005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.DISAPPEARED";
120005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
121005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Bluetooth class of a remote device has changed.
123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
124005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}.
125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
126b30f91e38c19f6728d836293446d4b9c76705e7fMatthew Xie     * {@see BluetoothClass}
127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_CLASS_CHANGED =
130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.CLASS_CHANGED";
131005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
132005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) connection has been
134005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * established with a remote device.
135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
139005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
140005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
141005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_CONNECTED =
142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_CONNECTED";
143005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
145005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates that a low level (ACL) disconnection has
146005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been requested for a remote device, and it will soon be disconnected.
147005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is useful for graceful disconnection. Applications should use
148005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * this intent as a hint to immediately terminate higher level connections
149005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (RFCOMM, L2CAP, or profile connections) to the remote device.
150005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
152005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
153005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
154005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECT_REQUESTED =
155005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED";
156005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
157005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
158005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) disconnection from a
159005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * remote device.
160005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
161005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
162005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
163005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
164005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
165005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
166005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECTED =
167005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECTED";
168005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
169005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
170005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates the friendly name of a remote device has
171005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been retrieved for the first time, or changed since the last retrieval.
172005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
173005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_NAME}.
174005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
175005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
176005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
177005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_CHANGED =
178005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_CHANGED";
179005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
180005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
1815bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * Broadcast Action: Indicates the alias of a remote device has been
1825bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * changed.
1835bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
1845bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
1855bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     *
1865bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * @hide
1875bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     */
1885bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1895bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    public static final String ACTION_ALIAS_CHANGED =
1905bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown            "android.bluetooth.device.action.ALIAS_CHANGED";
1915bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown
1925bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    /**
193005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a change in the bond state of a remote
194005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device. For example, if a device is bonded (paired).
195005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link
196005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}.
197005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
198005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
199005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also
200005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // contain a hidden extra field EXTRA_REASON with the result code.
201005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
202005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_BOND_STATE_CHANGED =
203005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.BOND_STATE_CHANGED";
204005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
205005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
206005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a Parcelable {@link BluetoothDevice} extra field in every intent
207005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * broadcast by this class. It contains the {@link BluetoothDevice} that
208005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the intent applies to.
209005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
210005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
211005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
212005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
213005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link
214005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} intents. It contains the friendly Bluetooth name.
215005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
216005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME";
217005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
218005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
219005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an optional short extra field in {@link #ACTION_FOUND} intents.
220005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the RSSI value of the remote device as reported by the
221005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Bluetooth hardware.
222005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
223005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI";
224005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
225005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
226f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa     * Used as a Parcelable {@link BluetoothClass} extra field in {@link
227005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents.
228005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
229005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS";
230005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
231005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
232005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
233005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the bond state of the remote device.
234005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values are:
235005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
236005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
237005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
238091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
239005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE";
240005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
241005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
242005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the previous bond state of the remote device.
243005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values are:
244005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
245005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
246005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
247091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
248005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_PREVIOUS_BOND_STATE =
249005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PREVIOUS_BOND_STATE";
250005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is not bonded (paired).
252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>There is no shared link key with the remote device, so communication
253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (if it is allowed at all) will be unauthenticated and unencrypted.
254005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
255005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_NONE = 10;
256005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
257005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates bonding (pairing) is in progress with the remote device.
258005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
259005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDING = 11;
260005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
261005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is bonded (paired).
262005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>A shared link keys exists locally for the remote device, so
263005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * communication can be authenticated and encrypted.
264005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><i>Being bonded (paired) with a remote device does not necessarily
265f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * mean the device is currently connected. It just means that the pending
266f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * procedure was completed at some earlier time, and the link key is still
267005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stored locally, ready to use on the next connection.
268005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * </i>
269005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
270005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDED = 12;
271005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
272091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
273091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
274091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents for unbond reason.
275091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @hide
276091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
277005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON";
278091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie
279091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
280091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
281091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents to indicate pairing method used. Possible values are:
282091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * {@link #PAIRING_VARIANT_PIN},
283091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION},
284091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
285005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_PAIRING_VARIANT =
286005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PAIRING_VARIANT";
287091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie
288091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
289091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
290091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents as the value of passkey.
291091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
292c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY";
293005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
294005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
29533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Unknown
29633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
29733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_UNKNOWN = 0;
29833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
29933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
30033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Classic - BR/EDR devices
30133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
30233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_CLASSIC = 1;
30333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
30433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
30533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Low Energy - LE-only
30633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
30733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_LE = 2;
30833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
30933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
31033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Dual Mode - BR/EDR/LE
31133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
31233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_DUAL = 3;
31333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
314238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde
315238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    /** @hide */
316238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
317238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    public static final String ACTION_SDP_RECORD =
318238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde            "android.bluetooth.device.action.SDP_RECORD";
319238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde
32033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
3211caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Broadcast Action: This intent is used to broadcast the {@link UUID}
322aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * wrapped as a {@link android.os.ParcelUuid} of the remote device after it
323aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * has been fetched. This intent is sent only when the UUIDs of the remote
324aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * device are requested to be fetched using Service Discovery Protocol
3251caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p> Always contains the extra field {@link #EXTRA_DEVICE}
326ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p> Always contains the extra field {@link #EXTRA_UUID}
3271caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
3281caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
3291caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3301caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String ACTION_UUID =
331ad2321027e9731711544b43378bd7b2f01890774Matthew Xie            "android.bluetooth.device.action.UUID";
3321caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
3338949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    /** @hide */
3348949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3358949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final String ACTION_MAS_INSTANCE =
3368949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta            "android.bluetooth.device.action.MAS_INSTANCE";
3378949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta
3381caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
339005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a failure to retrieve the name of a remote
340005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device.
341005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
342005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
343005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
344005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
345005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    //TODO: is this actually useful?
346005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
347005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_FAILED =
348005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_FAILED";
349005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
350091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
351091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Broadcast Action: This intent is used to broadcast PAIRING REQUEST
352ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} to
353430e361b202ecff8a10a9258948ade99689fe6b1Edward Jee     * receive.
354091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
355005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
356005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_REQUEST =
357005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_REQUEST";
358005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
359005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
360005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_CANCEL =
361005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_CANCEL";
362a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin
363a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
364a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
365a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REQUEST =
366a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST";
367a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
368a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
369a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
370a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REPLY =
371a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY";
372a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
373a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
374a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
375a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_CANCEL =
376a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL";
377a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
378a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
379a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent.
380a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
381a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
382a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ACCESS_REQUEST_TYPE =
383a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE";
384a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
385a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
386a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1;
387a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
388a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
389a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2;
390a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
391fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie    /**@hide*/
392fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie    public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3;
393fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie
3942a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde    /**@hide*/
3952a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde    public static final int REQUEST_TYPE_SIM_ACCESS = 4;
3962a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde
397a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
398a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
399a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains package name to return reply intent to.
400a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
401a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
402a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME";
403a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
404a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
405a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
406a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains class name to return reply intent to.
407a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
408a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
409a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME";
410a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
411a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
412a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent.
413a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
414a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
415a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CONNECTION_ACCESS_RESULT =
416a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT";
417a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
418a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
419a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_YES = 1;
420a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
421a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
422a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_NO = 2;
423a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
424a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
425a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents,
426a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains boolean to indicate if the allowed response is once-for-all so that
427a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * next request will be granted without asking user again.
428a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
429a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
430a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ALWAYS_ALLOWED =
431a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ALWAYS_ALLOWED";
432a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
433c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
434c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt succeeded
435c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
436c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
437b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    public static final int BOND_SUCCESS = 0;
438c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
439c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
440c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because pins did not match, or remote device did
44132d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh     * not respond to pin request in time
442c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
443c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_FAILED = 1;
445c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
446c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
447c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because the other side explicitly rejected
44845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * bonding
449c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
450c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_REJECTED = 2;
452c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
453c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
454c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we canceled the bonding process
455c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
456c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_CANCELED = 3;
458c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
459c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
460c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we could not contact the remote device
461c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
462c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4;
464c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
465c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
466c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because a discovery is in progress
467c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
468c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5;
470c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
471c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
472c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of authentication timeout
473c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
474c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
47532d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_AUTH_TIMEOUT = 6;
476c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
477c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
478c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of repeated attempts
479c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
480c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
48132d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7;
482c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
483c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
484c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we received an Authentication Cancel
485c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * by remote end
486c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
487c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
488e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8;
489c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
490c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
491c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * An existing bond was explicitly revoked
492c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
493c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
494e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOVED = 9;
4959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
496c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
497091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * The user will be prompted to enter a pin or
498ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * an app will enter a pin for user.
499c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
500b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PIN = 0;
501c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
502c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
503c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter a passkey
504c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
505c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
506b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY = 1;
507c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
508c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
509091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * The user will be prompted to confirm the passkey displayed on the screen or
510ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * an app will confirm the passkey for the user.
511c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
51232d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2;
513c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
514c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
515c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the incoming pairing request
516c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
517c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
51832d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_CONSENT = 3;
519c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
520c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
521c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the passkey displayed on remote device
522c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.1 pairing.
523c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
524c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
52532d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4;
526c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
527c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
528c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the PIN displayed on remote device.
529c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.0 pairing.
530c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
531c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
532c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PIN = 5;
533c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
534c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
535c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the OOB pairing request
536c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
537c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
538c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_OOB_CONSENT = 6;
539c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
5401caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
5413b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde     * The user will be prompted to enter a 16 digit pin or
5423b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde     * an app will enter a 16 digit pin for user.
5433b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde     * @hide
5443b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde     */
5453b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde    public static final int PAIRING_VARIANT_PIN_16_DIGITS = 7;
5463b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde
5473b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde    /**
5481caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Used as an extra field in {@link #ACTION_UUID} intents,
549aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * Contains the {@link android.os.ParcelUuid}s of the remote device which
550aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * is a parcelable version of {@link UUID}.
5511caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
5521caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
5531caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
554238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    /** @hide */
555238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    public static final String EXTRA_SDP_RECORD =
556238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde        "android.bluetooth.device.extra.SDP_RECORD";
557238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde
558238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    /** @hide */
559238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    public static final String EXTRA_SDP_SEARCH_STATUS =
560238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde            "android.bluetooth.device.extra.SDP_SEARCH_STATUS";
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_UNKNOWN = 0;
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_ALLOWED = 1;
5748dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
5758dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
5768dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
5778dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
5788dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
5798dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
5808dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public static final int ACCESS_REJECTED = 2;
5818dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
582b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     /**
583b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      * No preferrence of physical transport for GATT connections to remote dual-mode devices
584b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      */
585b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    public static final int TRANSPORT_AUTO = 0;
586b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
587b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
588b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Prefer BR/EDR transport for GATT connections to remote dual-mode devices
589b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
5908949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final int TRANSPORT_BREDR = 1;
591b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
592b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
593b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Prefer LE transport for GATT connections to remote dual-mode devices
594b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
5958949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final int TRANSPORT_LE = 2;
596b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
597409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    /**
59891fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * Bluetooth LE 1M PHY. Used to refer to LE 1M Physical Channel for advertising, scanning or
59991fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * connection.
600409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     */
601409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    public static final int PHY_LE_1M = 1;
602409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
603409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    /**
60491fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * Bluetooth LE 2M PHY. Used to refer to LE 2M Physical Channel for advertising, scanning or
60591fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * connection.
606409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     */
607409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    public static final int PHY_LE_2M = 2;
608409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
609409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    /**
61091fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * Bluetooth LE Coded PHY. Used to refer to LE Coded Physical Channel for advertising, scanning
61191fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * or connection.
612409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     */
613a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski    public static final int PHY_LE_CODED = 3;
614409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
615409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    /**
61691fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * Bluetooth LE 1M PHY mask. Used to specify LE 1M Physical Channel as one of many available
61791fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * options in a bitmask.
618409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     */
619a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski    public static final int PHY_LE_1M_MASK = 1;
620a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski
621a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski    /**
62291fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * Bluetooth LE 2M PHY mask. Used to specify LE 2M Physical Channel as one of many available
62391fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * options in a bitmask.
624a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski     */
625a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski    public static final int PHY_LE_2M_MASK = 2;
626a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski
627a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski    /**
62891fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * Bluetooth LE Coded PHY mask. Used to specify LE Coded Physical Channel as one of many
62991fe3080e7a27868f40b04dd7a42bb3136149970Jakub Pawlowski     * available options in a bitmask.
630a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski     */
631a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski    public static final int PHY_LE_CODED_MASK = 4;
632409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
633409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    /**
634409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * No preferred coding when transmitting on the LE Coded PHY.
635409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     */
636409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    public static final int PHY_OPTION_NO_PREFERRED = 0;
637409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
638409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    /**
639409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * Prefer the S=2 coding to be used when transmitting on the LE Coded PHY.
640409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     */
641409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    public static final int PHY_OPTION_S2 = 1;
642409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
643409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    /**
644409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * Prefer the S=8 coding to be used when transmitting on the LE Coded PHY.
645409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     */
646409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    public static final int PHY_OPTION_S8 = 2;
647409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
648409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
6498949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    /** @hide */
6508949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final String EXTRA_MAS_INSTANCE =
6518949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta        "android.bluetooth.device.extra.MAS_INSTANCE";
652b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
65316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
65416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Lazy initialization. Guaranteed final after first object constructed, or
65516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * getService() called.
65616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * TODO: Unify implementation of sService amongst BluetoothFoo API's
65716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
65816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    private static IBluetooth sService;
659bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
660bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private final String mAddress;
661d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
66216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ static IBluetooth getService() {
663bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        synchronized (BluetoothDevice.class) {
664bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            if (sService == null) {
6650f42037eb7b5118015c2caca635538324ccf0ccffredc                BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
666903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = adapter.getBluetoothService(mStateChangeCallback);
667bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            }
668bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
66916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return sService;
67016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
671bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
672903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() {
673903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
674903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceUp(IBluetooth bluetoothService)
675903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                throws RemoteException {
676903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
677d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora                if (sService == null) {
678d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora                    sService = bluetoothService;
679d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora                }
680903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
681903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
682903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
683903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceDown()
684903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            throws RemoteException {
685903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
686903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = null;
687903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
688903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
689d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
690d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        public void onBrEdrDown()
691d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        {
692d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            if (DBG) Log.d(TAG, "onBrEdrDown: reached BLE ON state");
693d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
694903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    };
69516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
69616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create a new BluetoothDevice
69716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB",
69816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * and is validated in this constructor.
69916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param address valid Bluetooth MAC address
70016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws RuntimeException Bluetooth is not available on this platform
70116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IllegalArgumentException address is invalid
70216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
70316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
70416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ BluetoothDevice(String address) {
70516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        getService();  // ensures sService is initialized
706005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        if (!BluetoothAdapter.checkBluetoothAddress(address)) {
707bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            throw new IllegalArgumentException(address + " is not a valid Bluetooth address");
708bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
709bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
710bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        mAddress = address;
7119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
713bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
714bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean equals(Object o) {
715bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        if (o instanceof BluetoothDevice) {
716bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return mAddress.equals(((BluetoothDevice)o).getAddress());
717bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
7189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
7199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
721bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
722bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int hashCode() {
723bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress.hashCode();
724105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    }
725105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project
72645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
72745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns a string representation of this BluetoothDevice.
72845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Currently this is the Bluetooth hardware address, for example
72945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress}
73045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * if you explicitly require the Bluetooth hardware address in case the
73145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * {@link #toString} representation changes in the future.
73245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return string representation of this BluetoothDevice
73345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
734bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
735bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public String toString() {
736bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
7379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
739bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int describeContents() {
740bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return 0;
741bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
742bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
743bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public static final Parcelable.Creator<BluetoothDevice> CREATOR =
744bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            new Parcelable.Creator<BluetoothDevice>() {
745bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice createFromParcel(Parcel in) {
746bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice(in.readString());
747bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
748bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice[] newArray(int size) {
749bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice[size];
750bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
751bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    };
752bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
753bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public void writeToParcel(Parcel out, int flags) {
754bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        out.writeString(mAddress);
7559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
75745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
75845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns the hardware address of this BluetoothDevice.
75945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p> For example, "00:11:22:AA:BB:CC".
76045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return Bluetooth hardware address as string
76145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
7629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getAddress() {
7630f42037eb7b5118015c2caca635538324ccf0ccffredc        if (DBG) Log.d(TAG, "mAddress: " + mAddress);
764bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
7659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
76845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Get the friendly Bluetooth name of the remote device.
7699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
77045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The local adapter will automatically retrieve remote names when
77145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * performing a device scan, and will cache them. This method just returns
77245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * the name for this device from the cache.
7739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
7749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the Bluetooth name, or null if there was a problem.
7759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7762d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye    @RequiresPermission(Manifest.permission.BLUETOOTH)
7779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getName() {
7780f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7790f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device name");
7800f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
7810f42037eb7b5118015c2caca635538324ccf0ccffredc        }
7829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
783e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteName(this);
7849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
7859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
78933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Get the Bluetooth device type of the remote device.
79033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *
79133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE}
79233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *                         {@link #DEVICE_TYPE_DUAL}.
79333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *         {@link #DEVICE_TYPE_UNKNOWN} if it's not available
79433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
7952d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye    @RequiresPermission(Manifest.permission.BLUETOOTH)
79633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public int getType() {
79733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        if (sService == null) {
79833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            Log.e(TAG, "BT not enabled. Cannot get Remote Device type");
79933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            return DEVICE_TYPE_UNKNOWN;
80033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        }
80133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        try {
80233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            return sService.getRemoteType(this);
80333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
80433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        return DEVICE_TYPE_UNKNOWN;
80533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    }
80633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
80733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
808269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
809269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
810269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
811269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
812269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
813269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
814269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAlias() {
8150f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8160f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias");
8170f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
8180f42037eb7b5118015c2caca635538324ccf0ccffredc        }
819269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
820e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteAlias(this);
821269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
822269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return null;
823269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
824269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
825269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
826269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Set the Bluetooth alias of the remote device.
827269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
828269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>This methoid overwrites the alias. The changed
829269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * alias is saved in the local storage so that the change
830269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * is preserved over power cycle.
831269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
832269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return true on success, false on error
833269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
834269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
835269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public boolean setAlias(String alias) {
8360f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8370f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device name");
8380f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
8390f42037eb7b5118015c2caca635538324ccf0ccffredc        }
840269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
841e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setRemoteAlias(this, alias);
842269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
843269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return false;
844269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
845269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
846269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
847269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
848269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * If Alias is null, get the Bluetooth name instead.
849269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getAlias()
850269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getName()
851269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
852269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
853269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
854269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
855269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAliasName() {
856269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        String name = getAlias();
857269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        if (name == null) {
858269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie            name = getName();
859269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        }
860269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return name;
861269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
862269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
863269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
864005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Start the bonding (pairing) process with the remote device.
865005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is an asynchronous call, it will return immediately. Register
866005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
867005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the bonding process completes, and its result.
868005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Android system services will handle the necessary user interactions
869005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * to confirm and complete the bonding process.
8709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
871005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return false on immediate error, true if bonding will begin
8729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8732d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
874bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean createBond() {
8750f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8760f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
8770f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
8780f42037eb7b5118015c2caca635538324ccf0ccffredc        }
8799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
880044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom            Log.i(TAG, "createBond() for device " + getAddress() +
881044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom                    " called by pid: " + Process.myPid() +
882044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom                    " tid: " + Process.myTid());
88357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return sService.createBond(this, TRANSPORT_AUTO);
88457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        } catch (RemoteException e) {Log.e(TAG, "", e);}
88557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        return false;
88657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    }
88757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach
88857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    /**
88957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * Start the bonding (pairing) process with the remote device using the
89057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * specified transport.
89157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     *
89257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>This is an asynchronous call, it will return immediately. Register
89357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
89457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * the bonding process completes, and its result.
89557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>Android system services will handle the necessary user interactions
89657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * to confirm and complete the bonding process.
89757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
89857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     *
89957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @param transport The transport to use for the pairing procedure.
90057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @return false on immediate error, true if bonding will begin
90157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @throws IllegalArgumentException if an invalid transport was specified
90257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @hide
90357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     */
90457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    public boolean createBond(int transport) {
90557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        if (sService == null) {
90657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
90757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return false;
90857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        }
90957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE)
91057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        {
91157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport");
91257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        }
91357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        try {
914044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom            Log.i(TAG, "createBond() for device " + getAddress() +
915044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom                    " called by pid: " + Process.myPid() +
916044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom                    " tid: " + Process.myTid());
91757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return sService.createBond(this, transport);
9189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
9199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
9209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
923cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Start the bonding (pairing) process with the remote device using the
924cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Out Of Band mechanism.
925cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
926cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>This is an asynchronous call, it will return immediately. Register
927cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
928cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * the bonding process completes, and its result.
929cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
930cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Android system services will handle the necessary user interactions
931cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * to confirm and complete the bonding process.
932cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
933cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
934cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
9352fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski     * @param transport - Transport to use
9362fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski     * @param oobData - Out Of Band data
937cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on immediate error, true if bonding will begin
938cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
939cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
940cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
9412fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski    public boolean createBondOutOfBand(int transport, OobData oobData) {
942cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
9432fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski            return sService.createBondOutOfBand(this, transport, oobData);
9442fc6e6bfd280b6391ed1533c443bde301765a3beJakub Pawlowski        } catch (RemoteException e) {Log.e(TAG, "", e);}
945cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        return false;
946cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
947cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
9480278ab957a8c4a658953532997074e3297d197f5Jakub Pawlowski    /** @hide */
9490278ab957a8c4a658953532997074e3297d197f5Jakub Pawlowski    public boolean isBondingInitiatedLocally() {
9500278ab957a8c4a658953532997074e3297d197f5Jakub Pawlowski        try {
9510278ab957a8c4a658953532997074e3297d197f5Jakub Pawlowski            return sService.isBondingInitiatedLocally(this);
9520278ab957a8c4a658953532997074e3297d197f5Jakub Pawlowski        } catch (RemoteException e) {Log.e(TAG, "", e);}
9530278ab957a8c4a658953532997074e3297d197f5Jakub Pawlowski        return false;
9540278ab957a8c4a658953532997074e3297d197f5Jakub Pawlowski    }
9550278ab957a8c4a658953532997074e3297d197f5Jakub Pawlowski
956cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
957cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Set the Out Of Band data for a remote device to be used later
958cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * in the pairing mechanism. Users can obtain this data through other
959cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * trusted channels
960cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
961cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
962cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
963cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash Simple Secure pairing hash
964cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer The random key obtained using OOB
965cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on error; true otherwise
966cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
967cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
968cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
969cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) {
970e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      //TODO(BT)
971e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      /*
972cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      try {
973e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        return sService.setDeviceOutOfBandData(this, hash, randomizer);
974e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);} */
975cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
976cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
977cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
978cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
979005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Cancel an in-progress bonding request started with {@link #createBond}.
980005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
981005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
982f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
98318b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
9849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
985bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelBondProcess() {
9860f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9870f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond");
9880f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
9890f42037eb7b5118015c2caca635538324ccf0ccffredc        }
9909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
991044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom            Log.i(TAG, "cancelBondProcess() for device " + getAddress() +
992044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom                    " called by pid: " + Process.myPid() +
993044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom                    " tid: " + Process.myTid());
994e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.cancelBondProcess(this);
9959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
9969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
9979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1000005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Remove bond (pairing) with the remote device.
1001005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Delete the link key associated with the remote device, and
1002005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * immediately terminate connections to that device that require
1003005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * authentication and encryption.
1004005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
10059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1006f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
100718b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
10089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1009bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean removeBond() {
10100f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
10110f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond");
10120f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
10130f42037eb7b5118015c2caca635538324ccf0ccffredc        }
10149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1015044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom            Log.i(TAG, "removeBond() for device " + getAddress() +
1016044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom                    " called by pid: " + Process.myPid() +
1017044b8f3f032e8dde6fd34baf08ff3c4610d8c2a1Christine Hallstrom                    " tid: " + Process.myTid());
1018e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.removeBond(this);
10199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
1020bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return false;
10219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1024005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the bond state of the remote device.
1025005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values for the bond state are:
1026005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
1027005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
1028005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
10299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1030005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return the bond state
10319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
10322d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye    @RequiresPermission(Manifest.permission.BLUETOOTH)
1033bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int getBondState() {
10340f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
10350f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get bond state");
10360f42037eb7b5118015c2caca635538324ccf0ccffredc            return BOND_NONE;
10370f42037eb7b5118015c2caca635538324ccf0ccffredc        }
10389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1039e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getBondState(this);
10409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
1041305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        catch (NullPointerException npe) {
1042305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // Handle case where bluetooth service proxy
1043305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // is already null.
1044305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            Log.e(TAG, "NullPointerException for getBondState() of device ("+
1045305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M                getAddress()+")", npe);
1046305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        }
1047005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return BOND_NONE;
1048005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    }
1049005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
1050005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
1051174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * Returns whether there is an open connection to this device.
1052174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
1053174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     *
1054174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * @return True if there is at least one open connection to this device.
1055174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * @hide
1056174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     */
10572b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    @SystemApi
1058174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    public boolean isConnected() {
1059174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        if (sService == null) {
1060174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            // BT is not enabled, we cannot be connected.
1061174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return false;
1062174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        }
1063174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        try {
10642b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return sService.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED;
10652b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        } catch (RemoteException e) {
10662b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            Log.e(TAG, "", e);
10672b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return false;
10682b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        }
10692b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    }
10702b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach
10712b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    /**
10722b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * Returns whether there is an open connection to this device
10732b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * that has been encrypted.
10742b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
10752b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     *
10762b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * @return True if there is at least one encrypted connection to this device.
10772b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * @hide
10782b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     */
10792b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    @SystemApi
10802b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    public boolean isEncrypted() {
10812b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        if (sService == null) {
10822b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            // BT is not enabled, we cannot be connected.
10832b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return false;
10842b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        }
10852b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        try {
10862b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return sService.getConnectionState(this) > CONNECTION_STATE_CONNECTED;
1087174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        } catch (RemoteException e) {
1088174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            Log.e(TAG, "", e);
1089174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return false;
1090174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        }
1091174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    }
1092174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli
1093174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    /**
1094005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the Bluetooth class of the remote device.
1095005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
1096005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return Bluetooth class object, or null on error
1097005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
10982d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye    @RequiresPermission(Manifest.permission.BLUETOOTH)
1099005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public BluetoothClass getBluetoothClass() {
11000f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
11010f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class");
11020f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
11030f42037eb7b5118015c2caca635538324ccf0ccffredc        }
1104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        try {
1105e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            int classInt = sService.getRemoteClass(this);
1106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            if (classInt == BluetoothClass.ERROR) return null;
1107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            return new BluetoothClass(classInt);
1108005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        } catch (RemoteException e) {Log.e(TAG, "", e);}
1109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return null;
11109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
11119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1112efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    /**
1113ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * Returns the supported features (UUIDs) of the remote device.
1114ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
1115ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>This method does not start a service discovery procedure to retrieve the UUIDs
1116ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * from the remote device. Instead, the local cached copy of the service
1117ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * UUIDs are returned.
1118ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired.
1119ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
1120ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * @return the supported features (UUIDs) of the remote device,
1121ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *         or null on error
1122ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     */
11232d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye    @RequiresPermission(Manifest.permission.BLUETOOTH)
1124dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh     public ParcelUuid[] getUuids() {
1125d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         if (sService == null || isBluetoothEnabled() == false) {
11260f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
11270f42037eb7b5118015c2caca635538324ccf0ccffredc             return null;
11280f42037eb7b5118015c2caca635538324ccf0ccffredc         }
11299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1130e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteUuids(this);
11319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
11329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
11339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1134d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
11351caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     /**
1136ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * Perform a service discovery on the remote device to get the UUIDs supported.
1137ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      *
1138ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent,
1139ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * with the UUIDs supported by the remote end. If there is an error
1140ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * in getting the SDP records or if the process takes a long time,
1141ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently
1142ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * present in the cache. Clients should use the {@link #getUuids} to get UUIDs
1143ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * if service discovery is not to be performed.
11441caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *
1145ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * @return False if the sanity check fails, True if the process
11461caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               of initiating an ACL connection to the remote device
11471caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               was started.
11481caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      */
11492d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye     @RequiresPermission(Manifest.permission.BLUETOOTH)
11501caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     public boolean fetchUuidsWithSdp() {
11515d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        IBluetooth service = sService;
1152d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (service == null || isBluetoothEnabled() == false) {
11535d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp");
11545d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            return false;
11555d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        }
11561caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh        try {
11575d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            return service.fetchRemoteUuids(this);
11584c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc        } catch (RemoteException e) {Log.e(TAG, "", e);}
11594c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc            return false;
11601caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    }
11611caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
1162238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     /**
1163238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * Perform a service discovery on the remote device to get the SDP records associated
1164238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * with the specified UUID.
1165238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      *
1166238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * <p>This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent,
1167238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * with the SDP records found on the remote end. If there is an error
1168238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * in getting the SDP records or if the process takes a long time,
1169238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * {@link #ACTION_SDP_RECORD} intent is sent with an status value in
1170238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0.
1171238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * Detailed status error codes can be found by members of the Bluetooth package in
1172238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * the AbstractionLayer class.
1173238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
1174238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}.
1175238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * The object type will match one of the SdpXxxRecord types, depending on the UUID searched
1176238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * for.
1177238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      *
1178238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * @return False if the sanity check fails, True if the process
1179238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      *               of initiating an ACL connection to the remote device
1180238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      *               was started.
1181238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      */
11828949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     /** @hide */
1183238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     public boolean sdpSearch(ParcelUuid uuid) {
11848949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         if (sService == null) {
1185238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde             Log.e(TAG, "BT not enabled. Cannot query remote device sdp records");
11868949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta             return false;
11878949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         }
11888949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         try {
1189238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde             return sService.sdpSearch(this,uuid);
11908949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         } catch (RemoteException e) {Log.e(TAG, "", e);}
11918949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         return false;
11928949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     }
11938949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta
1194091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
1195091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN}
1196ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
1197091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *
1198091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @return true pin has been set
1199091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *         false for error
1200091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
1201bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPin(byte[] pin) {
12020f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
12030f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device pin");
12040f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
12050f42037eb7b5118015c2caca635538324ccf0ccffredc        }
12069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1207e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPin(this, true, pin.length, pin);
12089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
12099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
12109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1211b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
121245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1213bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPasskey(int passkey) {
1214e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
1215e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1216b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
1217e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPasskey(this, true, 4, passkey);
1218e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1219b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
1220b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
1221b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
1222091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
1223091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing.
1224091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *
1225091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @return true confirmation has been sent out
1226091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *         false for error
1227091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
122893326cfd9fb8a20081baa9b975275772798cfd80Marie Janssen    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
1229bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPairingConfirmation(boolean confirm) {
12300f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
12310f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set pairing confirmation");
12320f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
12330f42037eb7b5118015c2caca635538324ccf0ccffredc        }
1234b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
1235e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPairingConfirmation(this, confirm);
1236b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}
1237b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
1238b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
1239b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
124045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1241cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setRemoteOutOfBandData() {
1242e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
1243e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1244cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
1245e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh          return sService.setRemoteOutOfBandData(this);
1246e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1247cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
1248cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
1249cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
1250cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /** @hide */
1251bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelPairingUserInput() {
12520f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
12530f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create pairing user input");
12540f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
12550f42037eb7b5118015c2caca635538324ccf0ccffredc        }
12569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1257919a4c6264b733585152ce1dc6f868c1093d368bRavi Nagarajan            return sService.cancelBondProcess(this);
1258db44b20fe6aed65d5cd7e1f6d7c52e4322083039Priti Aghera        } catch (RemoteException e) {Log.e(TAG, "", e);}
12599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
12609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
12619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
12623fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    /** @hide */
12633fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    public boolean isBluetoothDock() {
1264e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
1265e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
12663fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        try {
1267e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.isBluetoothDock(this);
1268e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
12693fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        return false;
12703fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    }
12713fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh
1272d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora     boolean isBluetoothEnabled() {
1273d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         boolean ret = false;
1274d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
1275d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         if (adapter != null && adapter.isEnabled() == true) {
1276d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora             ret = true;
1277d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         }
1278d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         return ret;
1279d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora     }
1280d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
12819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
12828dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Requires {@link android.Manifest.permission#BLUETOOTH}.
12838dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the phonebook access is allowed to this device. Can be
12848dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *         {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
12858dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
12868dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
12878dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public int getPhonebookAccessPermission() {
12888dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
12898dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return ACCESS_UNKNOWN;
12908dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12918dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
12928dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.getPhonebookAccessPermission(this);
12938dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
12948dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
12958dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12968dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return ACCESS_UNKNOWN;
12978dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
12988dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
12998dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
13008dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Sets whether the phonebook access is allowed to this device.
13018dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
13028dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
13038dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *              {@link #ACCESS_REJECTED}.
13048dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the value has been successfully set.
13058dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
13068dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
13078dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public boolean setPhonebookAccessPermission(int value) {
13088dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
13098dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return false;
13108dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
13118dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
13128dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.setPhonebookAccessPermission(this, value);
13138dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
13148dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
13158dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
13168dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return false;
13178dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
13188dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
13198dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
13208dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Requires {@link android.Manifest.permission#BLUETOOTH}.
13218dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the message access is allowed to this device. Can be
13228dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *         {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
13238dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
13248dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
13258dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public int getMessageAccessPermission() {
13268dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
13278dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return ACCESS_UNKNOWN;
13288dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
13298dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
13308dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.getMessageAccessPermission(this);
13318dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
13328dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
13338dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
13348dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return ACCESS_UNKNOWN;
13358dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
13368dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
13378dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
13388dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Sets whether the message access is allowed to this device.
13398dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
13408dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
13418dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *              {@link #ACCESS_REJECTED}.
13428dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the value has been successfully set.
13438dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
13448dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
13458dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public boolean setMessageAccessPermission(int value) {
13468dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
13478dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return false;
13488dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
13498dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
13508dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.setMessageAccessPermission(this, value);
13518dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
13528dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
13538dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
13548dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return false;
13558dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
13568dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
13578dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
13582a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     * Requires {@link android.Manifest.permission#BLUETOOTH}.
13592a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     * @return Whether the Sim access is allowed to this device. Can be
13602a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     *         {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
13612a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     * @hide
13622a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     */
13632a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde    public int getSimAccessPermission() {
13642a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        if (sService == null) {
13652a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde            return ACCESS_UNKNOWN;
13662a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        }
13672a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        try {
13682a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde            return sService.getSimAccessPermission(this);
13692a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        } catch (RemoteException e) {
13702a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde            Log.e(TAG, "", e);
13712a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        }
13722a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        return ACCESS_UNKNOWN;
13732a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde    }
13742a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde
13752a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde    /**
13762a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     * Sets whether the Sim access is allowed to this device.
13772a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
13782a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
13792a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     *              {@link #ACCESS_REJECTED}.
13802a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     * @return Whether the value has been successfully set.
13812a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     * @hide
13822a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde     */
13832a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde    public boolean setSimAccessPermission(int value) {
13842a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        if (sService == null) {
13852a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde            return false;
13862a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        }
13872a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        try {
13882a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde            return sService.setSimAccessPermission(this, value);
13892a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        } catch (RemoteException e) {
13902a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde            Log.e(TAG, "", e);
13912a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        }
13922a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde        return false;
13933b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde    }
13943b3d1fea94318a4892fbd4353269749af417a81aCasper Bonde
13952a5f608e7a5765db3b91165dac5b6280b26da26cCasper Bonde    /**
139645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
139716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device on given channel.
139845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The remote device will be authenticated and communication on this
139945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * socket will be encrypted.
1400c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1401c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1402c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1403c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1404c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1405c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1406c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocket}.
1407c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1408c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1409f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
141045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * connection.
141145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Valid RFCOMM channels are in range 1 to 30.
1412cf44059813539bf7f36dabd278cef93ba3122c56Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
1413de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     *
141445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @param channel RFCOMM channel to connect to
141545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
1416bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
141745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     *                     insufficient permissions
141816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
1419bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
142045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    public BluetoothSocket createRfcommSocket(int channel) throws IOException {
1421d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1422d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1423d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1424d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
142516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel,
142616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
142716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
142816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly
142916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
1430238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * Create an L2cap {@link BluetoothSocket} ready to start a secure
1431238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * outgoing connection to this remote device on given channel.
1432238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p>The remote device will be authenticated and communication on this
1433238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * socket will be encrypted.
1434238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p> Use this socket only if an authenticated socket link is possible.
1435238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * Authentication refers to the authentication of the link key to
1436238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * prevent man-in-the-middle type of attacks.
1437238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1438238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * have an input and output capability or just has the ability to
1439238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * display a numeric key, a secure socket connection is not possible.
1440238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * In such a case, use {#link createInsecureRfcommSocket}.
1441238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * For more details, refer to the Security Model section 5.2 (vol 3) of
1442238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * Bluetooth Core Specification version 2.1 + EDR.
1443238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
1444238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * connection.
1445238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p>Valid L2CAP PSM channels are in range 1 to 2^16.
1446238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
1447238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     *
1448238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * @param channel L2cap PSM/channel to connect to
1449238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
1450238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * @throws IOException on error, for example Bluetooth not available, or
1451238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     *                     insufficient permissions
1452238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * @hide
1453238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     */
1454238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    public BluetoothSocket createL2capSocket(int channel) throws IOException {
1455238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde        return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, true, true, this, channel,
1456238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde                null);
1457238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    }
1458238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde
1459238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    /**
1460ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * Create an L2cap {@link BluetoothSocket} ready to start an insecure
1461ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * outgoing connection to this remote device on given channel.
1462ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * <p>The remote device will be not authenticated and communication on this
1463ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * socket will not be encrypted.
1464ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
1465ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * connection.
1466ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * <p>Valid L2CAP PSM channels are in range 1 to 2^16.
1467ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
1468ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     *
1469ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * @param channel L2cap PSM/channel to connect to
1470ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
1471ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * @throws IOException on error, for example Bluetooth not available, or
1472ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     *                     insufficient permissions
1473ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     * @hide
1474ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta     */
1475ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta    public BluetoothSocket createInsecureL2capSocket(int channel) throws IOException {
1476ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta        return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, false, false, this, channel,
1477ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta                null);
1478ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta    }
1479ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta
1480ef3e0dbf003b881ded3dd8993f136fffc2d3b069Hemant Gupta    /**
148116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
148216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device using SDP lookup of uuid.
148316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>This is designed to be used with {@link
148416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer
148516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth applications.
1486f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
148716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * connection. This will also perform an SDP lookup of the given uuid to
148816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * determine which channel to connect to.
148916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>The remote device will be authenticated and communication on this
149016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * socket will be encrypted.
1491c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1492c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1493c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1494c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1495c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1496c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1497c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}.
1498c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1499c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1500ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * <p>Hint: If you are connecting to a Bluetooth serial board then try
1501ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
1502ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * However if you are connecting to an Android peer then please generate
1503ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * your own unique UUID.
150416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *
150516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param uuid service record uuid to lookup RFCOMM channel
150616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
150716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
150816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *                     insufficient permissions
150916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
15102d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye    @RequiresPermission(Manifest.permission.BLUETOOTH)
151116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException {
1512d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1513d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1514d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1515d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
1516d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
151716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1,
151816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                new ParcelUuid(uuid));
1519bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1520bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1521bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
15226eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure
15236eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * outgoing connection to this remote device using SDP lookup of uuid.
15246eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p> The communication channel will not have an authenticated link key
15256eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1
15266eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * devices, the link key will be encrypted, as encryption is mandatory.
15276eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * For legacy devices (pre Bluetooth 2.1 devices) the link key will
15286eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an
15296eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * encrypted and authenticated communication channel is desired.
15306eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>This is designed to be used with {@link
15316eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer
15326eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Bluetooth applications.
15336eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
15346eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * connection. This will also perform an SDP lookup of the given uuid to
15356eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * determine which channel to connect to.
15366eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>The remote device will be authenticated and communication on this
15376eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * socket will be encrypted.
15386eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Hint: If you are connecting to a Bluetooth serial board then try
15396eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
15406eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * However if you are connecting to an Android peer then please generate
15416eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * your own unique UUID.
15426eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *
15436eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @param uuid service record uuid to lookup RFCOMM channel
15446eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
15456eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @throws IOException on error, for example Bluetooth not available, or
15466eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *                     insufficient permissions
15476eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     */
15482d49752ee050ab7f1cd848933f6c62a73707e2d9Tor Norbye    @RequiresPermission(Manifest.permission.BLUETOOTH)
15496eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException {
1550d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1551d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1552d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1553d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
15546eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1,
15556eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh                new ParcelUuid(uuid));
15566eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    }
15576eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh
15586eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    /**
1559bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct an insecure RFCOMM socket ready to start an outgoing
1560bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * connection.
1561bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1562bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * The remote device will not be authenticated and communication on this
1563bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * socket will not be encrypted.
1564e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1565e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1566bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @param port    remote port
1567bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return An RFCOMM BluetoothSocket
1568bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException On error, for example Bluetooth not available, or
1569bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
157045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1571bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1572bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException {
1573d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
1574d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1575d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1576d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1577d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
157816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port,
157916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
1580bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1581bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1582bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
1583bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct a SCO socket ready to start an outgoing connection.
1584bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1585e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1586e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1587bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return a SCO BluetoothSocket
1588bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
1589bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
159045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1591bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1592bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createScoSocket() throws IOException {
1593d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
1594d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1595d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1596d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1597d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
159816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null);
1599bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1600bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1601bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
16029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Check that a pin is valid and convert to byte array.
16039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1604f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters.
16059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param pin pin as java String
1606f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return the pin code as a UTF-8 byte array, or null if it is an invalid
16079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         Bluetooth pin.
160845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
16099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
16109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static byte[] convertPinToBytes(String pin) {
16119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pin == null) {
16129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
16139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
16149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        byte[] pinBytes;
16159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1616f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            pinBytes = pin.getBytes("UTF-8");
16179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (UnsupportedEncodingException uee) {
1618f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            Log.e(TAG, "UTF-8 not supported?!?");  // this should not happen
16199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
16209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
16219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pinBytes.length <= 0 || pinBytes.length > 16) {
16229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
16239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
16249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return pinBytes;
16259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
16269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1627ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
1628ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1629ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * The callback is used to deliver results to Caller, such as connection status as well
1630ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * as any further GATT client operations.
1631ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1632ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * GATT client operations.
1633ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param callback GATT callback handler that will receive asynchronous callbacks.
1634ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param autoConnect Whether to directly connect to the remote device (false)
1635ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *                    or to automatically connect as soon as the remote
1636ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *                    device becomes available (true).
1637ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @throws IllegalArgumentException if callback is null
1638ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
163933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
164033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie                                     BluetoothGattCallback callback) {
1641b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta        return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO));
1642b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    }
1643b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
1644b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
1645b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1646b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * The callback is used to deliver results to Caller, such as connection status as well
1647b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * as any further GATT client operations.
1648b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1649b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * GATT client operations.
1650b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param callback GATT callback handler that will receive asynchronous callbacks.
1651b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param autoConnect Whether to directly connect to the remote device (false)
1652b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *                    or to automatically connect as soon as the remote
1653b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *                    device becomes available (true).
1654b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param transport preferred transport for GATT connections to remote dual-mode devices
1655b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *             {@link BluetoothDevice#TRANSPORT_AUTO} or
1656b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *             {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
1657b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @throws IllegalArgumentException if callback is null
1658b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
1659b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
1660b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta                                     BluetoothGattCallback callback, int transport) {
1661dbf5a0a20b4f47b87613d84887dec07cb5cf0662Jakub Pawlowski        return (connectGatt(context, autoConnect,callback, transport, PHY_LE_1M_MASK));
1662409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    }
1663409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski
1664409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    /**
1665409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1666409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * The callback is used to deliver results to Caller, such as connection status as well
1667409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * as any further GATT client operations.
1668409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1669409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * GATT client operations.
1670409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * @param callback GATT callback handler that will receive asynchronous callbacks.
1671409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * @param autoConnect Whether to directly connect to the remote device (false)
1672409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     *                    or to automatically connect as soon as the remote
1673409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     *                    device becomes available (true).
1674409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * @param transport preferred transport for GATT connections to remote dual-mode devices
1675409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     *             {@link BluetoothDevice#TRANSPORT_AUTO} or
1676409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     *             {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
1677409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of
1678a51513747aee764628871d2919f434dcbe38b67cJakub Pawlowski     *             {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
1679b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *             and {@link BluetoothDevice#PHY_LE_CODED_MASK}. This option does not take effect
1680b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *             if {@code autoConnect} is set to true.
1681b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * @throws NullPointerException if callback is null
1682409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski     */
1683409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
1684d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski                                     BluetoothGattCallback callback, int transport, int phy) {
1685dbf5a0a20b4f47b87613d84887dec07cb5cf0662Jakub Pawlowski        return connectGatt(context, autoConnect,callback, transport, phy, null);
1686b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski    }
1687b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski
1688b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski    /**
1689b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1690b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * The callback is used to deliver results to Caller, such as connection status as well
1691b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * as any further GATT client operations.
1692b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1693b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * GATT client operations.
1694b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * @param callback GATT callback handler that will receive asynchronous callbacks.
1695b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * @param autoConnect Whether to directly connect to the remote device (false)
1696b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *                    or to automatically connect as soon as the remote
1697b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *                    device becomes available (true).
1698b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * @param transport preferred transport for GATT connections to remote dual-mode devices
1699b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *             {@link BluetoothDevice#TRANSPORT_AUTO} or
1700b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *             {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
1701b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of
1702b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *             {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
1703b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *             an d{@link BluetoothDevice#PHY_LE_CODED_MASK}. This option does not take effect
1704b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     *             if {@code autoConnect} is set to true.
1705b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * @param handler The handler to use for the callback. If {@code null}, callbacks will happen
17066bdc550e27e2c4e7b32bb91085eaac898d7d1156Ruben Brunk     *             on an un-specified background thread.
1707b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     * @throws NullPointerException if callback is null
1708b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski     */
1709b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
1710b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski                                     BluetoothGattCallback callback, int transport, int phy,
1711b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski                                     Handler handler) {
1712b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski        if (callback == null)
1713b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski            throw new NullPointerException("callback is null");
1714b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski
1715ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        // TODO(Bluetooth) check whether platform support BLE
1716ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        //     Do the check here or in GattServer?
1717ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
1718ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        IBluetoothManager managerService = adapter.getBluetoothManager();
1719ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        try {
1720ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            IBluetoothGatt iGatt = managerService.getBluetoothGatt();
172132ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie            if (iGatt == null) {
172232ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie                // BLE is not supported
172332ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie                return null;
172432ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie            }
1725409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski            BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport, phy);
1726b0f647492f6d262d13825b14bbada140effe8394Jakub Pawlowski            gatt.connect(autoConnect, callback, handler);
1727ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            return gatt;
1728ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
1729ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        return null;
1730ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
17319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1732