BluetoothDevice.java revision 2b8696e3a91194db0bfd876b8cc68843a7ccd080
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
19005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellyimport android.annotation.SdkConstant;
20005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellyimport android.annotation.SdkConstant.SdkConstantType;
212b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbachimport android.annotation.SystemApi;
22ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xieimport android.content.Context;
23bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcel;
24bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcelable;
25aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pellyimport android.os.ParcelUuid;
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException;
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log;
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport java.io.IOException;
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.UnsupportedEncodingException;
311caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganeshimport java.util.UUID;
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
349fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you
35f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * create a connection with the respective device or query information about
369fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * it, such as the name, address, class, and bonding state.
3745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly *
3845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>This class is really just a thin wrapper for a Bluetooth hardware
3945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * address. Objects of this class are immutable. Operations on this class
4045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * are performed on the remote Bluetooth hardware address, using the
4145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link BluetoothAdapter} that was used to create this {@link
4245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * BluetoothDevice}.
439fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
449fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>To get a {@link BluetoothDevice}, use
459fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter#getRemoteDevice(String)
469fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device
479fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * of a known MAC address (which you can get through device discovery with
489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter}) or get one from the set of bonded devices
499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * returned by {@link BluetoothAdapter#getBondedDevices()
509fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getBondedDevices()}. You can then open a
51f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * {@link BluetoothSocket} for communication with the remote device, using
529fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link #createRfcommSocketToServiceRecord(UUID)}.
539fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
549fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p class="note"><strong>Note:</strong>
559fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Requires the {@link android.Manifest.permission#BLUETOOTH} permission.
569fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
573aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference">
583aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3>
593aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about using Bluetooth, read the
603aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/wireless/bluetooth.html">Bluetooth</a> developer guide.</p>
613aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div>
623aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez *
639fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothAdapter}
649fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothSocket}
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
66bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellypublic final class BluetoothDevice implements Parcelable {
67bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private static final String TAG = "BluetoothDevice";
687077272d8feed2f0172520d4fd3b4524e18d5ec1Ravi Nagarajan    private static final boolean DBG = false;
699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
70b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    /**
712b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * Connection state bitmask as returned by getConnectionState.
722b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     */
732b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_DISCONNECTED = 0;
742b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_CONNECTED = 1;
752b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_ENCRYPTED_BREDR = 2;
762b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_ENCRYPTED_LE = 4;
772b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach
782b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    /**
79b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * Sentinel error value for this class. Guaranteed to not equal any other
80b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * integer constant in this class. Provided as a convenience for functions
81b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * that require a sentinel error value, for example:
82005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><code>Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
83005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * BluetoothDevice.ERROR)</code>
84005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
85005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int ERROR = Integer.MIN_VALUE;
86005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
87005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
88005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device discovered.
89005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device is found during discovery.
90005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
91005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}. Can contain the extra fields {@link #EXTRA_NAME} and/or
92005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #EXTRA_RSSI} if they are available.
93005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
94005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
95005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     // TODO: Change API to not broadcast RSSI if not available (incoming connection)
96005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_FOUND =
98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.FOUND";
99005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
100005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
101005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device disappeared.
102005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device that was found in the last discovery is not
103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * found in the current discovery.
104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
108005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_DISAPPEARED =
110005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.DISAPPEARED";
111005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
112005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
113005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Bluetooth class of a remote device has changed.
114005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
115005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}.
116005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
117b30f91e38c19f6728d836293446d4b9c76705e7fMatthew Xie     * {@see BluetoothClass}
118005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
119005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
120005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_CLASS_CHANGED =
121005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.CLASS_CHANGED";
122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
124005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) connection has been
125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * established with a remote device.
126005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
131005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
132005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_CONNECTED =
133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_CONNECTED";
134005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates that a low level (ACL) disconnection has
137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been requested for a remote device, and it will soon be disconnected.
138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is useful for graceful disconnection. Applications should use
139005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * this intent as a hint to immediately terminate higher level connections
140005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (RFCOMM, L2CAP, or profile connections) to the remote device.
141005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
143005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
145005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECT_REQUESTED =
146005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED";
147005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
148005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
149005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) disconnection from a
150005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * remote device.
151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
152005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
153005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
154005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
155005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
156005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
157005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECTED =
158005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECTED";
159005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
160005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
161005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates the friendly name of a remote device has
162005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been retrieved for the first time, or changed since the last retrieval.
163005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
164005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_NAME}.
165005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
166005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
167005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
168005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_CHANGED =
169005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_CHANGED";
170005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
171005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
1725bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * Broadcast Action: Indicates the alias of a remote device has been
1735bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * changed.
1745bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
1755bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
1765bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     *
1775bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * @hide
1785bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     */
1795bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1805bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    public static final String ACTION_ALIAS_CHANGED =
1815bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown            "android.bluetooth.device.action.ALIAS_CHANGED";
1825bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown
1835bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    /**
184005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a change in the bond state of a remote
185005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device. For example, if a device is bonded (paired).
186005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link
187005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}.
188005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
189005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
190005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also
191005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // contain a hidden extra field EXTRA_REASON with the result code.
192005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
193005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_BOND_STATE_CHANGED =
194005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.BOND_STATE_CHANGED";
195005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
196005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
197005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a Parcelable {@link BluetoothDevice} extra field in every intent
198005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * broadcast by this class. It contains the {@link BluetoothDevice} that
199005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the intent applies to.
200005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
201005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
202005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
203005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
204005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link
205005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} intents. It contains the friendly Bluetooth name.
206005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
207005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME";
208005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
209005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
210005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an optional short extra field in {@link #ACTION_FOUND} intents.
211005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the RSSI value of the remote device as reported by the
212005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Bluetooth hardware.
213005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
214005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI";
215005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
216005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
217f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa     * Used as a Parcelable {@link BluetoothClass} extra field in {@link
218005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents.
219005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
220005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS";
221005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
222005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
223005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
224005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the bond state of the remote device.
225005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values are:
226005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
227005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
228005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
229091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
230005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE";
231005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
232005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
233005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the previous 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_PREVIOUS_BOND_STATE =
240005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PREVIOUS_BOND_STATE";
241005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
242005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is not bonded (paired).
243005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>There is no shared link key with the remote device, so communication
244005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (if it is allowed at all) will be unauthenticated and unencrypted.
245005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
246005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_NONE = 10;
247005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
248005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates bonding (pairing) is in progress with the remote device.
249005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
250005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDING = 11;
251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is bonded (paired).
253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>A shared link keys exists locally for the remote device, so
254005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * communication can be authenticated and encrypted.
255005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><i>Being bonded (paired) with a remote device does not necessarily
256f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * mean the device is currently connected. It just means that the pending
257f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * procedure was completed at some earlier time, and the link key is still
258005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stored locally, ready to use on the next connection.
259005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * </i>
260005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
261005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDED = 12;
262005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
263091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
264091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
265091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents for unbond reason.
266091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @hide
267091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
268005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON";
269091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie
270091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
271091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
272091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents to indicate pairing method used. Possible values are:
273091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * {@link #PAIRING_VARIANT_PIN},
274091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION},
275091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
276005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_PAIRING_VARIANT =
277005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PAIRING_VARIANT";
278091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie
279091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
280091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
281091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents as the value of passkey.
282091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
283c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY";
284005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
285005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
28633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Unknown
28733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
28833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_UNKNOWN = 0;
28933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
29033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
29133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Classic - BR/EDR devices
29233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
29333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_CLASSIC = 1;
29433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
29533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
29633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Low Energy - LE-only
29733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
29833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_LE = 2;
29933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
30033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
30133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Dual Mode - BR/EDR/LE
30233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
30333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_DUAL = 3;
30433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
30533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
3061caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Broadcast Action: This intent is used to broadcast the {@link UUID}
307aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * wrapped as a {@link android.os.ParcelUuid} of the remote device after it
308aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * has been fetched. This intent is sent only when the UUIDs of the remote
309aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * device are requested to be fetched using Service Discovery Protocol
3101caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p> Always contains the extra field {@link #EXTRA_DEVICE}
311ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p> Always contains the extra field {@link #EXTRA_UUID}
3121caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
3131caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
3141caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3151caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String ACTION_UUID =
316ad2321027e9731711544b43378bd7b2f01890774Matthew Xie            "android.bluetooth.device.action.UUID";
3171caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
3188949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    /** @hide */
3198949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3208949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final String ACTION_MAS_INSTANCE =
3218949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta            "android.bluetooth.device.action.MAS_INSTANCE";
3228949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta
3231caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
324005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a failure to retrieve the name of a remote
325005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device.
326005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
327005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
328005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
329005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
330005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    //TODO: is this actually useful?
331005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
332005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_FAILED =
333005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_FAILED";
334005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
335091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
336091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Broadcast Action: This intent is used to broadcast PAIRING REQUEST
337ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} to
338430e361b202ecff8a10a9258948ade99689fe6b1Edward Jee     * receive.
339091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
340005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
341005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_REQUEST =
342005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_REQUEST";
343005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
344005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
345005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_CANCEL =
346005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_CANCEL";
347a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin
348a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
349a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
350a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REQUEST =
351a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST";
352a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
353a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
354a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
355a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REPLY =
356a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY";
357a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
358a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
359a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
360a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_CANCEL =
361a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL";
362a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
363a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
364a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent.
365a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
366a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
367a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ACCESS_REQUEST_TYPE =
368a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE";
369a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
370a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
371a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1;
372a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
373a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
374a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2;
375a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
376fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie    /**@hide*/
377fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie    public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3;
378fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie
379a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
380a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
381a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains package name to return reply intent to.
382a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
383a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
384a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME";
385a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
386a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
387a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
388a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains class name to return reply intent to.
389a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
390a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
391a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME";
392a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
393a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
394a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent.
395a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
396a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
397a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CONNECTION_ACCESS_RESULT =
398a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT";
399a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
400a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
401a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_YES = 1;
402a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
403a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
404a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_NO = 2;
405a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
406a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
407a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents,
408a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains boolean to indicate if the allowed response is once-for-all so that
409a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * next request will be granted without asking user again.
410a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
411a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
412a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ALWAYS_ALLOWED =
413a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ALWAYS_ALLOWED";
414a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
415c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
416c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt succeeded
417c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
418c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
419b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    public static final int BOND_SUCCESS = 0;
420c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
421c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
422c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because pins did not match, or remote device did
42332d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh     * not respond to pin request in time
424c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
425c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_FAILED = 1;
427c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
428c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
429c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because the other side explicitly rejected
43045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * bonding
431c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
432c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_REJECTED = 2;
434c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
435c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
436c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we canceled the bonding process
437c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
438c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_CANCELED = 3;
440c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
441c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
442c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we could not contact the remote device
443c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
444c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4;
446c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
447c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
448c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because a discovery is in progress
449c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
450c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5;
452c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
453c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
454c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of authentication timeout
455c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
456c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
45732d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_AUTH_TIMEOUT = 6;
458c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
459c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
460c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of repeated attempts
461c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
462c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
46332d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7;
464c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
465c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
466c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we received an Authentication Cancel
467c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * by remote end
468c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
469c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
470e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8;
471c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
472c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
473c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * An existing bond was explicitly revoked
474c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
475c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
476e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOVED = 9;
4779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
478c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
479091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * The user will be prompted to enter a pin or
480ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * an app will enter a pin for user.
481c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
482b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PIN = 0;
483c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
484c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
485c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter a passkey
486c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
487c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
488b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY = 1;
489c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
490c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
491091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * The user will be prompted to confirm the passkey displayed on the screen or
492ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * an app will confirm the passkey for the user.
493c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
49432d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2;
495c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
496c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
497c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the incoming pairing request
498c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
499c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
50032d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_CONSENT = 3;
501c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
502c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
503c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the passkey displayed on remote device
504c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.1 pairing.
505c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
506c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
50732d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4;
508c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
509c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
510c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the PIN displayed on remote device.
511c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.0 pairing.
512c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
513c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
514c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PIN = 5;
515c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
516c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
517c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the OOB pairing request
518c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
519c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
520c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_OOB_CONSENT = 6;
521c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
5221caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
5231caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Used as an extra field in {@link #ACTION_UUID} intents,
524aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * Contains the {@link android.os.ParcelUuid}s of the remote device which
525aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * is a parcelable version of {@link UUID}.
5261caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
5271caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
5281caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
5298dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
5308dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
5318dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
5328dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
5338dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
5348dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public static final int ACCESS_UNKNOWN = 0;
5358dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
5368dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
5378dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
5388dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
5398dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
5408dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
5418dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public static final int ACCESS_ALLOWED = 1;
5428dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
5438dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
5448dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
5458dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
5468dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
5478dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
5488dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public static final int ACCESS_REJECTED = 2;
5498dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
550b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     /**
551b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      * No preferrence of physical transport for GATT connections to remote dual-mode devices
552b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      * @hide
553b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      */
554b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    public static final int TRANSPORT_AUTO = 0;
555b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
556b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
557b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Prefer BR/EDR transport for GATT connections to remote dual-mode devices
558b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
559b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
5608949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final int TRANSPORT_BREDR = 1;
561b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
562b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
563b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Prefer LE transport for GATT connections to remote dual-mode devices
564b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
565b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
5668949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final int TRANSPORT_LE = 2;
567b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
5688949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    /** @hide */
5698949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final String EXTRA_MAS_INSTANCE =
5708949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta        "android.bluetooth.device.extra.MAS_INSTANCE";
571b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
57216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
57316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Lazy initialization. Guaranteed final after first object constructed, or
57416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * getService() called.
57516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * TODO: Unify implementation of sService amongst BluetoothFoo API's
57616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
57716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    private static IBluetooth sService;
578bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
579bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private final String mAddress;
580d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
58116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ static IBluetooth getService() {
582bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        synchronized (BluetoothDevice.class) {
583bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            if (sService == null) {
5840f42037eb7b5118015c2caca635538324ccf0ccffredc                BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
585903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = adapter.getBluetoothService(mStateChangeCallback);
586bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            }
587bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
58816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return sService;
58916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
590bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
591903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() {
592903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
593903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceUp(IBluetooth bluetoothService)
594903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                throws RemoteException {
595903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
596903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = bluetoothService;
597903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
598903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
599903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
600903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceDown()
601903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            throws RemoteException {
602903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
603903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = null;
604903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
605903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
606903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    };
60716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
60816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create a new BluetoothDevice
60916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB",
61016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * and is validated in this constructor.
61116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param address valid Bluetooth MAC address
61216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws RuntimeException Bluetooth is not available on this platform
61316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IllegalArgumentException address is invalid
61416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
61516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
61616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ BluetoothDevice(String address) {
61716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        getService();  // ensures sService is initialized
618005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        if (!BluetoothAdapter.checkBluetoothAddress(address)) {
619bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            throw new IllegalArgumentException(address + " is not a valid Bluetooth address");
620bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
621bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
622bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        mAddress = address;
6239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
625bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
626bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean equals(Object o) {
627bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        if (o instanceof BluetoothDevice) {
628bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return mAddress.equals(((BluetoothDevice)o).getAddress());
629bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
6309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
6319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
633bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
634bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int hashCode() {
635bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress.hashCode();
636105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    }
637105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project
63845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
63945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns a string representation of this BluetoothDevice.
64045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Currently this is the Bluetooth hardware address, for example
64145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress}
64245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * if you explicitly require the Bluetooth hardware address in case the
64345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * {@link #toString} representation changes in the future.
64445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return string representation of this BluetoothDevice
64545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
646bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
647bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public String toString() {
648bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
6499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
651bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int describeContents() {
652bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return 0;
653bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
654bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
655bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public static final Parcelable.Creator<BluetoothDevice> CREATOR =
656bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            new Parcelable.Creator<BluetoothDevice>() {
657bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice createFromParcel(Parcel in) {
658bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice(in.readString());
659bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
660bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice[] newArray(int size) {
661bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice[size];
662bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
663bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    };
664bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
665bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public void writeToParcel(Parcel out, int flags) {
666bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        out.writeString(mAddress);
6679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
66945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
67045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns the hardware address of this BluetoothDevice.
67145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p> For example, "00:11:22:AA:BB:CC".
67245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return Bluetooth hardware address as string
67345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getAddress() {
6750f42037eb7b5118015c2caca635538324ccf0ccffredc        if (DBG) Log.d(TAG, "mAddress: " + mAddress);
676bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
68045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Get the friendly Bluetooth name of the remote device.
6819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
68245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The local adapter will automatically retrieve remote names when
68345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * performing a device scan, and will cache them. This method just returns
68445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * the name for this device from the cache.
685de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
6869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
6879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the Bluetooth name, or null if there was a problem.
6889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getName() {
6900f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
6910f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device name");
6920f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
6930f42037eb7b5118015c2caca635538324ccf0ccffredc        }
6949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
695e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteName(this);
6969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
6989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
70133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Get the Bluetooth device type of the remote device.
70233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *
70333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
70433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *
70533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE}
70633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *                         {@link #DEVICE_TYPE_DUAL}.
70733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *         {@link #DEVICE_TYPE_UNKNOWN} if it's not available
70833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
70933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public int getType() {
71033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        if (sService == null) {
71133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            Log.e(TAG, "BT not enabled. Cannot get Remote Device type");
71233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            return DEVICE_TYPE_UNKNOWN;
71333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        }
71433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        try {
71533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            return sService.getRemoteType(this);
71633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
71733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        return DEVICE_TYPE_UNKNOWN;
71833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    }
71933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
72033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
721269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
722269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
723269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
724269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
725269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
726269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
727269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAlias() {
7280f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7290f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias");
7300f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
7310f42037eb7b5118015c2caca635538324ccf0ccffredc        }
732269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
733e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteAlias(this);
734269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
735269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return null;
736269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
737269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
738269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
739269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Set the Bluetooth alias of the remote device.
740269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
741269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>This methoid overwrites the alias. The changed
742269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * alias is saved in the local storage so that the change
743269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * is preserved over power cycle.
744269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
745269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return true on success, false on error
746269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
747269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
748269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public boolean setAlias(String alias) {
7490f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7500f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device name");
7510f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
7520f42037eb7b5118015c2caca635538324ccf0ccffredc        }
753269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
754e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setRemoteAlias(this, alias);
755269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
756269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return false;
757269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
758269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
759269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
760269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
761269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * If Alias is null, get the Bluetooth name instead.
762269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getAlias()
763269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getName()
764269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
765269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
766269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
767269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
768269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAliasName() {
769269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        String name = getAlias();
770269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        if (name == null) {
771269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie            name = getName();
772269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        }
773269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return name;
774269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
775269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
776269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
777005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Start the bonding (pairing) process with the remote device.
778005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is an asynchronous call, it will return immediately. Register
779005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
780005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the bonding process completes, and its result.
781005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Android system services will handle the necessary user interactions
782005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * to confirm and complete the bonding process.
783ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
7849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
785005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return false on immediate error, true if bonding will begin
7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
787bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean createBond() {
7880f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7890f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
7900f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
7910f42037eb7b5118015c2caca635538324ccf0ccffredc        }
7929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
79357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return sService.createBond(this, TRANSPORT_AUTO);
79457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        } catch (RemoteException e) {Log.e(TAG, "", e);}
79557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        return false;
79657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    }
79757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach
79857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    /**
79957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * Start the bonding (pairing) process with the remote device using the
80057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * specified transport.
80157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     *
80257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>This is an asynchronous call, it will return immediately. Register
80357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
80457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * the bonding process completes, and its result.
80557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>Android system services will handle the necessary user interactions
80657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * to confirm and complete the bonding process.
80757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
80857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     *
80957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @param transport The transport to use for the pairing procedure.
81057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @return false on immediate error, true if bonding will begin
81157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @throws IllegalArgumentException if an invalid transport was specified
81257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @hide
81357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     */
81457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    public boolean createBond(int transport) {
81557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        if (sService == null) {
81657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
81757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return false;
81857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        }
81957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE)
82057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        {
82157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport");
82257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        }
82357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        try {
82457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return sService.createBond(this, transport);
8259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
8269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
8279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
830cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Start the bonding (pairing) process with the remote device using the
831cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Out Of Band mechanism.
832cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
833cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>This is an asynchronous call, it will return immediately. Register
834cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
835cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * the bonding process completes, and its result.
836cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
837cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Android system services will handle the necessary user interactions
838cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * to confirm and complete the bonding process.
839cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
840cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
841cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
842cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash - Simple Secure pairing hash
843cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer - The random key obtained using OOB
844cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on immediate error, true if bonding will begin
845cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
846cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
847cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
848cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean createBondOutOfBand(byte[] hash, byte[] randomizer) {
849e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
850e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
851cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
852e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.createBondOutOfBand(this, hash, randomizer);
853e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
854cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        return false;
855cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
856cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
857cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
858cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Set the Out Of Band data for a remote device to be used later
859cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * in the pairing mechanism. Users can obtain this data through other
860cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * trusted channels
861cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
862cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
863cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
864cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash Simple Secure pairing hash
865cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer The random key obtained using OOB
866cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on error; true otherwise
867cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
868cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
869cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
870cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) {
871e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      //TODO(BT)
872e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      /*
873cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      try {
874e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        return sService.setDeviceOutOfBandData(this, hash, randomizer);
875e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);} */
876cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
877cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
878cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
879cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
880005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Cancel an in-progress bonding request started with {@link #createBond}.
881005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
882005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
883f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
88418b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
8859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
886bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelBondProcess() {
8870f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8880f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond");
8890f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
8900f42037eb7b5118015c2caca635538324ccf0ccffredc        }
8919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
892e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.cancelBondProcess(this);
8939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
8949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
8959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
898005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Remove bond (pairing) with the remote device.
899005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Delete the link key associated with the remote device, and
900005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * immediately terminate connections to that device that require
901005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * authentication and encryption.
902005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
904f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
90518b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
9069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
907bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean removeBond() {
9080f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9090f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond");
9100f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
9110f42037eb7b5118015c2caca635538324ccf0ccffredc        }
9129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
913e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.removeBond(this);
9149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
915bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return false;
9169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
919005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the bond state of the remote device.
920005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values for the bond state are:
921005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
922005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
923005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
924005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
9259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
926005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return the bond state
9279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
928bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int getBondState() {
9290f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9300f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get bond state");
9310f42037eb7b5118015c2caca635538324ccf0ccffredc            return BOND_NONE;
9320f42037eb7b5118015c2caca635538324ccf0ccffredc        }
9339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
934e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getBondState(this);
9359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
936305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        catch (NullPointerException npe) {
937305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // Handle case where bluetooth service proxy
938305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // is already null.
939305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            Log.e(TAG, "NullPointerException for getBondState() of device ("+
940305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M                getAddress()+")", npe);
941305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        }
942005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return BOND_NONE;
943005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    }
944005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
945005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
946174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * Returns whether there is an open connection to this device.
947174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
948174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     *
949174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * @return True if there is at least one open connection to this device.
950174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * @hide
951174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     */
9522b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    @SystemApi
953174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    public boolean isConnected() {
954174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        if (sService == null) {
955174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            // BT is not enabled, we cannot be connected.
956174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return false;
957174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        }
958174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        try {
9592b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return sService.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED;
9602b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        } catch (RemoteException e) {
9612b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            Log.e(TAG, "", e);
9622b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return false;
9632b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        }
9642b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    }
9652b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach
9662b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    /**
9672b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * Returns whether there is an open connection to this device
9682b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * that has been encrypted.
9692b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
9702b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     *
9712b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * @return True if there is at least one encrypted connection to this device.
9722b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * @hide
9732b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     */
9742b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    @SystemApi
9752b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    public boolean isEncrypted() {
9762b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        if (sService == null) {
9772b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            // BT is not enabled, we cannot be connected.
9782b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return false;
9792b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        }
9802b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        try {
9812b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return sService.getConnectionState(this) > CONNECTION_STATE_CONNECTED;
982174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        } catch (RemoteException e) {
983174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            Log.e(TAG, "", e);
984174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return false;
985174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        }
986174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    }
987174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli
988174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    /**
989005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the Bluetooth class of the remote device.
990005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
991005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
992005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return Bluetooth class object, or null on error
993005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
994005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public BluetoothClass getBluetoothClass() {
9950f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9960f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class");
9970f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
9980f42037eb7b5118015c2caca635538324ccf0ccffredc        }
999005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        try {
1000e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            int classInt = sService.getRemoteClass(this);
1001005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            if (classInt == BluetoothClass.ERROR) return null;
1002005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            return new BluetoothClass(classInt);
1003005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        } catch (RemoteException e) {Log.e(TAG, "", e);}
1004005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return null;
10059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1007efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    /**
1008ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * Returns the supported features (UUIDs) of the remote device.
1009ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
1010ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>This method does not start a service discovery procedure to retrieve the UUIDs
1011ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * from the remote device. Instead, the local cached copy of the service
1012ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * UUIDs are returned.
1013ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired.
1014ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
1015ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
1016ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * @return the supported features (UUIDs) of the remote device,
1017ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *         or null on error
1018ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     */
1019dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh     public ParcelUuid[] getUuids() {
10200f42037eb7b5118015c2caca635538324ccf0ccffredc         if (sService == null) {
10210f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
10220f42037eb7b5118015c2caca635538324ccf0ccffredc             return null;
10230f42037eb7b5118015c2caca635538324ccf0ccffredc         }
10249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1025e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteUuids(this);
10269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
10279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
10289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1029d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
10301caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     /**
1031ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * Perform a service discovery on the remote device to get the UUIDs supported.
1032ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      *
1033ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent,
1034ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * with the UUIDs supported by the remote end. If there is an error
1035ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * in getting the SDP records or if the process takes a long time,
1036ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently
1037ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * present in the cache. Clients should use the {@link #getUuids} to get UUIDs
1038ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * if service discovery is not to be performed.
1039ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
10401caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *
1041ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * @return False if the sanity check fails, True if the process
10421caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               of initiating an ACL connection to the remote device
10431caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               was started.
10441caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      */
10451caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     public boolean fetchUuidsWithSdp() {
10465d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        IBluetooth service = sService;
10475d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        if (service == null) {
10485d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp");
10495d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            return false;
10505d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        }
10511caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh        try {
10525d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            return service.fetchRemoteUuids(this);
10534c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc        } catch (RemoteException e) {Log.e(TAG, "", e);}
10544c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc            return false;
10551caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    }
10561caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
10578949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     /** @hide */
10588949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     public boolean fetchMasInstances() {
10598949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         if (sService == null) {
10608949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta             Log.e(TAG, "BT not enabled. Cannot query remote device for MAS instances");
10618949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta             return false;
10628949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         }
10638949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         try {
10648949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta             return sService.fetchRemoteMasInstances(this);
10658949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         } catch (RemoteException e) {Log.e(TAG, "", e);}
10668949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         return false;
10678949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     }
10688949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta
106945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1070dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh    public int getServiceChannel(ParcelUuid uuid) {
1071e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
1072e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1073d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh         try {
1074e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh             return sService.getRemoteServiceChannel(this, uuid);
1075e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh         } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1076b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly         return BluetoothDevice.ERROR;
10779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1079091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
1080091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN}
1081ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
1082091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *
1083091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @return true pin has been set
1084091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *         false for error
1085091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
1086bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPin(byte[] pin) {
10870f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
10880f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device pin");
10890f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
10900f42037eb7b5118015c2caca635538324ccf0ccffredc        }
10919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1092e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPin(this, true, pin.length, pin);
10939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
10949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
10959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1096b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
109745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1098bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPasskey(int passkey) {
1099e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
1100e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1101b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
1102e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPasskey(this, true, 4, passkey);
1103e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1104b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
1105b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
1106b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
1107091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
1108091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing.
1109ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
1110091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *
1111091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @return true confirmation has been sent out
1112091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *         false for error
1113091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
1114bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPairingConfirmation(boolean confirm) {
11150f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
11160f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set pairing confirmation");
11170f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
11180f42037eb7b5118015c2caca635538324ccf0ccffredc        }
1119b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
1120e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPairingConfirmation(this, confirm);
1121b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}
1122b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
1123b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
1124b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
112545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1126cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setRemoteOutOfBandData() {
1127e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
1128e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1129cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
1130e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh          return sService.setRemoteOutOfBandData(this);
1131e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1132cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
1133cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
1134cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
1135cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /** @hide */
1136bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelPairingUserInput() {
11370f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
11380f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create pairing user input");
11390f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
11400f42037eb7b5118015c2caca635538324ccf0ccffredc        }
11419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1142919a4c6264b733585152ce1dc6f868c1093d368bRavi Nagarajan            return sService.cancelBondProcess(this);
1143db44b20fe6aed65d5cd7e1f6d7c52e4322083039Priti Aghera        } catch (RemoteException e) {Log.e(TAG, "", e);}
11449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
11459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
11469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11473fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    /** @hide */
11483fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    public boolean isBluetoothDock() {
1149e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
1150e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
11513fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        try {
1152e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.isBluetoothDock(this);
1153e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
11543fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        return false;
11553fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    }
11563fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh
11579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
11588dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Requires {@link android.Manifest.permission#BLUETOOTH}.
11598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the phonebook access is allowed to this device. Can be
11608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *         {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
11618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
11628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
11638dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public int getPhonebookAccessPermission() {
11648dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
11658dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return ACCESS_UNKNOWN;
11668dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
11678dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
11688dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.getPhonebookAccessPermission(this);
11698dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
11708dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
11718dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
11728dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return ACCESS_UNKNOWN;
11738dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
11748dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
11758dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
11768dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Sets whether the phonebook access is allowed to this device.
11778dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
11788dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
11798dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *              {@link #ACCESS_REJECTED}.
11808dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the value has been successfully set.
11818dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
11828dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
11838dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public boolean setPhonebookAccessPermission(int value) {
11848dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
11858dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return false;
11868dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
11878dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
11888dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.setPhonebookAccessPermission(this, value);
11898dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
11908dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
11918dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
11928dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return false;
11938dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
11948dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
11958dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
11968dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Requires {@link android.Manifest.permission#BLUETOOTH}.
11978dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the message access is allowed to this device. Can be
11988dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *         {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
11998dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
12008dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
12018dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public int getMessageAccessPermission() {
12028dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
12038dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return ACCESS_UNKNOWN;
12048dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12058dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
12068dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.getMessageAccessPermission(this);
12078dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
12088dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
12098dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12108dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return ACCESS_UNKNOWN;
12118dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
12128dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
12138dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
12148dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Sets whether the message access is allowed to this device.
12158dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
12168dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
12178dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *              {@link #ACCESS_REJECTED}.
12188dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the value has been successfully set.
12198dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
12208dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
12218dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public boolean setMessageAccessPermission(int value) {
12228dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
12238dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return false;
12248dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12258dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
12268dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.setMessageAccessPermission(this, value);
12278dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
12288dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
12298dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12308dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return false;
12318dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
12328dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
12338dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
123445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
123516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device on given channel.
123645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The remote device will be authenticated and communication on this
123745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * socket will be encrypted.
1238c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1239c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1240c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1241c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1242c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1243c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1244c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocket}.
1245c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1246c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1247f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
124845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * connection.
124945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Valid RFCOMM channels are in range 1 to 30.
1250cf44059813539bf7f36dabd278cef93ba3122c56Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
1251de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     *
125245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @param channel RFCOMM channel to connect to
125345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
1254bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
125545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     *                     insufficient permissions
125616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
1257bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
125845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    public BluetoothSocket createRfcommSocket(int channel) throws IOException {
125916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel,
126016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
126116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
126216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly
126316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
126416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
126516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device using SDP lookup of uuid.
126616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>This is designed to be used with {@link
126716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer
126816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth applications.
1269f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
127016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * connection. This will also perform an SDP lookup of the given uuid to
127116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * determine which channel to connect to.
127216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>The remote device will be authenticated and communication on this
127316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * socket will be encrypted.
1274c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1275c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1276c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1277c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1278c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1279c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1280c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}.
1281c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1282c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1283ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * <p>Hint: If you are connecting to a Bluetooth serial board then try
1284ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
1285ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * However if you are connecting to an Android peer then please generate
1286ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * your own unique UUID.
128716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
128816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *
128916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param uuid service record uuid to lookup RFCOMM channel
129016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
129116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
129216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *                     insufficient permissions
129316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
129416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException {
129516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1,
129616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                new ParcelUuid(uuid));
1297bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1298bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1299bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
13006eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure
13016eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * outgoing connection to this remote device using SDP lookup of uuid.
13026eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p> The communication channel will not have an authenticated link key
13036eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1
13046eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * devices, the link key will be encrypted, as encryption is mandatory.
13056eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * For legacy devices (pre Bluetooth 2.1 devices) the link key will
13066eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an
13076eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * encrypted and authenticated communication channel is desired.
13086eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>This is designed to be used with {@link
13096eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer
13106eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Bluetooth applications.
13116eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
13126eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * connection. This will also perform an SDP lookup of the given uuid to
13136eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * determine which channel to connect to.
13146eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>The remote device will be authenticated and communication on this
13156eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * socket will be encrypted.
13166eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Hint: If you are connecting to a Bluetooth serial board then try
13176eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
13186eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * However if you are connecting to an Android peer then please generate
13196eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * your own unique UUID.
13206eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
13216eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *
13226eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @param uuid service record uuid to lookup RFCOMM channel
13236eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
13246eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @throws IOException on error, for example Bluetooth not available, or
13256eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *                     insufficient permissions
13266eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     */
13276eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException {
13286eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1,
13296eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh                new ParcelUuid(uuid));
13306eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    }
13316eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh
13326eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    /**
1333bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct an insecure RFCOMM socket ready to start an outgoing
1334bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * connection.
1335bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1336bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * The remote device will not be authenticated and communication on this
1337bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * socket will not be encrypted.
1338e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1339e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1340bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @param port    remote port
1341bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return An RFCOMM BluetoothSocket
1342bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException On error, for example Bluetooth not available, or
1343bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
134445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1345bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1346bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException {
134716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port,
134816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
1349bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1350bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1351bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
1352bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct a SCO socket ready to start an outgoing connection.
1353bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1354e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1355e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1356bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return a SCO BluetoothSocket
1357bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
1358bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
135945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1360bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1361bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createScoSocket() throws IOException {
136216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null);
1363bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1364bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1365bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
13669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Check that a pin is valid and convert to byte array.
13679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1368f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters.
13699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param pin pin as java String
1370f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return the pin code as a UTF-8 byte array, or null if it is an invalid
13719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         Bluetooth pin.
137245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
13739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
13749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static byte[] convertPinToBytes(String pin) {
13759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pin == null) {
13769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
13779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
13789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        byte[] pinBytes;
13799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1380f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            pinBytes = pin.getBytes("UTF-8");
13819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (UnsupportedEncodingException uee) {
1382f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            Log.e(TAG, "UTF-8 not supported?!?");  // this should not happen
13839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
13849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
13859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pinBytes.length <= 0 || pinBytes.length > 16) {
13869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
13879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
13889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return pinBytes;
13899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
13909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1391ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
1392ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1393ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * The callback is used to deliver results to Caller, such as connection status as well
1394ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * as any further GATT client operations.
1395ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1396ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * GATT client operations.
1397ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param callback GATT callback handler that will receive asynchronous callbacks.
1398ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param autoConnect Whether to directly connect to the remote device (false)
1399ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *                    or to automatically connect as soon as the remote
1400ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *                    device becomes available (true).
1401ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @throws IllegalArgumentException if callback is null
1402ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
140333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
140433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie                                     BluetoothGattCallback callback) {
1405b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta        return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO));
1406b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    }
1407b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
1408b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
1409b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1410b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * The callback is used to deliver results to Caller, such as connection status as well
1411b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * as any further GATT client operations.
1412b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1413b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * GATT client operations.
1414b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param callback GATT callback handler that will receive asynchronous callbacks.
1415b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param autoConnect Whether to directly connect to the remote device (false)
1416b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *                    or to automatically connect as soon as the remote
1417b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *                    device becomes available (true).
1418b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param transport preferred transport for GATT connections to remote dual-mode devices
1419b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *             {@link BluetoothDevice#TRANSPORT_AUTO} or
1420b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *             {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
1421b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @throws IllegalArgumentException if callback is null
1422b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
1423b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
1424b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
1425b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta                                     BluetoothGattCallback callback, int transport) {
1426ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        // TODO(Bluetooth) check whether platform support BLE
1427ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        //     Do the check here or in GattServer?
1428ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
1429ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        IBluetoothManager managerService = adapter.getBluetoothManager();
1430ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        try {
1431ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            IBluetoothGatt iGatt = managerService.getBluetoothGatt();
143232ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie            if (iGatt == null) {
143332ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie                // BLE is not supported
143432ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie                return null;
143532ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie            }
1436b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta            BluetoothGatt gatt = new BluetoothGatt(context, iGatt, this, transport);
1437ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            gatt.connect(autoConnect, callback);
1438ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            return gatt;
1439ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
1440ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        return null;
1441ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
14429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1443