BluetoothDevice.java revision 8949bfb90c415629dbd0e30d25003fb3e0375fb5
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;
21ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xieimport android.content.Context;
22bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcel;
23bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcelable;
24aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pellyimport android.os.ParcelUuid;
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException;
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log;
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
28bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport java.io.IOException;
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.UnsupportedEncodingException;
301caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganeshimport java.util.UUID;
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
339fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you
34f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * create a connection with the respective device or query information about
359fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * it, such as the name, address, class, and bonding state.
3645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly *
3745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>This class is really just a thin wrapper for a Bluetooth hardware
3845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * address. Objects of this class are immutable. Operations on this class
3945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * are performed on the remote Bluetooth hardware address, using the
4045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link BluetoothAdapter} that was used to create this {@link
4145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * BluetoothDevice}.
429fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
439fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>To get a {@link BluetoothDevice}, use
449fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter#getRemoteDevice(String)
459fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device
469fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * of a known MAC address (which you can get through device discovery with
479fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter}) or get one from the set of bonded devices
489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * returned by {@link BluetoothAdapter#getBondedDevices()
499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getBondedDevices()}. You can then open a
50f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * {@link BluetoothSocket} for communication with the remote device, using
519fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link #createRfcommSocketToServiceRecord(UUID)}.
529fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
539fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p class="note"><strong>Note:</strong>
549fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Requires the {@link android.Manifest.permission#BLUETOOTH} permission.
559fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
563aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference">
573aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3>
583aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about using Bluetooth, read the
593aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/wireless/bluetooth.html">Bluetooth</a> developer guide.</p>
603aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div>
613aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez *
629fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothAdapter}
639fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothSocket}
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
65bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellypublic final class BluetoothDevice implements Parcelable {
66bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private static final String TAG = "BluetoothDevice";
677077272d8feed2f0172520d4fd3b4524e18d5ec1Ravi Nagarajan    private static final boolean DBG = false;
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
69b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    /**
70b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * Sentinel error value for this class. Guaranteed to not equal any other
71b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * integer constant in this class. Provided as a convenience for functions
72b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * that require a sentinel error value, for example:
73005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><code>Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
74005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * BluetoothDevice.ERROR)</code>
75005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
76005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int ERROR = Integer.MIN_VALUE;
77005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
78005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
79005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device discovered.
80005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device is found during discovery.
81005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
82005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}. Can contain the extra fields {@link #EXTRA_NAME} and/or
83005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #EXTRA_RSSI} if they are available.
84005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
85005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
86005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     // TODO: Change API to not broadcast RSSI if not available (incoming connection)
87005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
88005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_FOUND =
89005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.FOUND";
90005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
91005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
92005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device disappeared.
93005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device that was found in the last discovery is not
94005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * found in the current discovery.
95005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
96005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
99005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
100005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_DISAPPEARED =
101005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.DISAPPEARED";
102005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Bluetooth class of a remote device has changed.
105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}.
107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
108b30f91e38c19f6728d836293446d4b9c76705e7fMatthew Xie     * {@see BluetoothClass}
109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
110005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
111005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_CLASS_CHANGED =
112005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.CLASS_CHANGED";
113005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
114005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
115005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) connection has been
116005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * established with a remote device.
117005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
118005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
119005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
120005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
121005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_CONNECTED =
124005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_CONNECTED";
125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
126005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates that a low level (ACL) disconnection has
128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been requested for a remote device, and it will soon be disconnected.
129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is useful for graceful disconnection. Applications should use
130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * this intent as a hint to immediately terminate higher level connections
131005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (RFCOMM, L2CAP, or profile connections) to the remote device.
132005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
134005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECT_REQUESTED =
137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED";
138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
139005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
140005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) disconnection from a
141005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * remote device.
142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
143005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
145005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
146005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
147005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
148005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECTED =
149005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECTED";
150005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
152005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates the friendly name of a remote device has
153005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been retrieved for the first time, or changed since the last retrieval.
154005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
155005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_NAME}.
156005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
157005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
158005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
159005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_CHANGED =
160005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_CHANGED";
161005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
162005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
1635bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * Broadcast Action: Indicates the alias of a remote device has been
1645bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * changed.
1655bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
1665bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
1675bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     *
1685bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * @hide
1695bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     */
1705bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1715bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    public static final String ACTION_ALIAS_CHANGED =
1725bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown            "android.bluetooth.device.action.ALIAS_CHANGED";
1735bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown
1745bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    /**
175005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a change in the bond state of a remote
176005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device. For example, if a device is bonded (paired).
177005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link
178005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}.
179005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
180005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
181005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also
182005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // contain a hidden extra field EXTRA_REASON with the result code.
183005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
184005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_BOND_STATE_CHANGED =
185005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.BOND_STATE_CHANGED";
186005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
187005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
188005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a Parcelable {@link BluetoothDevice} extra field in every intent
189005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * broadcast by this class. It contains the {@link BluetoothDevice} that
190005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the intent applies to.
191005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
192005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
193005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
194005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
195005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link
196005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} intents. It contains the friendly Bluetooth name.
197005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
198005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME";
199005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
200005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
201005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an optional short extra field in {@link #ACTION_FOUND} intents.
202005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the RSSI value of the remote device as reported by the
203005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Bluetooth hardware.
204005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
205005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI";
206005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
207005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
208f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa     * Used as a Parcelable {@link BluetoothClass} extra field in {@link
209005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents.
210005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
211005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS";
212005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
213005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
214005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
215005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the bond state of the remote device.
216005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values are:
217005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
218005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
219005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
220091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
221005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE";
222005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
223005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
224005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the previous 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_PREVIOUS_BOND_STATE =
231005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PREVIOUS_BOND_STATE";
232005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
233005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is not bonded (paired).
234005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>There is no shared link key with the remote device, so communication
235005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (if it is allowed at all) will be unauthenticated and unencrypted.
236005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
237005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_NONE = 10;
238005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
239005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates bonding (pairing) is in progress with the remote device.
240005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
241005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDING = 11;
242005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
243005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is bonded (paired).
244005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>A shared link keys exists locally for the remote device, so
245005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * communication can be authenticated and encrypted.
246005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><i>Being bonded (paired) with a remote device does not necessarily
247f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * mean the device is currently connected. It just means that the pending
248f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * procedure was completed at some earlier time, and the link key is still
249005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stored locally, ready to use on the next connection.
250005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * </i>
251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDED = 12;
253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
254091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
255091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
256091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents for unbond reason.
257091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @hide
258091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
259005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON";
260091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie
261091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
262091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
263091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents to indicate pairing method used. Possible values are:
264091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * {@link #PAIRING_VARIANT_PIN},
265091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION},
266091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
267005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_PAIRING_VARIANT =
268005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PAIRING_VARIANT";
269091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie
270091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
271091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
272091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents as the value of passkey.
273091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
274c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY";
275005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
276005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
27733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Unknown
27833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
27933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_UNKNOWN = 0;
28033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
28133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
28233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Classic - BR/EDR devices
28333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
28433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_CLASSIC = 1;
28533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
28633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
28733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Low Energy - LE-only
28833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
28933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_LE = 2;
29033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
29133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
29233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Dual Mode - BR/EDR/LE
29333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
29433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_DUAL = 3;
29533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
29633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
2971caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Broadcast Action: This intent is used to broadcast the {@link UUID}
298aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * wrapped as a {@link android.os.ParcelUuid} of the remote device after it
299aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * has been fetched. This intent is sent only when the UUIDs of the remote
300aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * device are requested to be fetched using Service Discovery Protocol
3011caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p> Always contains the extra field {@link #EXTRA_DEVICE}
302ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p> Always contains the extra field {@link #EXTRA_UUID}
3031caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
3041caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
3051caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3061caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String ACTION_UUID =
307ad2321027e9731711544b43378bd7b2f01890774Matthew Xie            "android.bluetooth.device.action.UUID";
3081caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
3098949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    /** @hide */
3108949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3118949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final String ACTION_MAS_INSTANCE =
3128949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta            "android.bluetooth.device.action.MAS_INSTANCE";
3138949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta
3141caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
315005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a failure to retrieve the name of a remote
316005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device.
317005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
318005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
319005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
320005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
321005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    //TODO: is this actually useful?
322005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
323005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_FAILED =
324005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_FAILED";
325005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
326091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
327091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Broadcast Action: This intent is used to broadcast PAIRING REQUEST
328ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} to
329430e361b202ecff8a10a9258948ade99689fe6b1Edward Jee     * receive.
330091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
331005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
332005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_REQUEST =
333005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_REQUEST";
334005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
335005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
336005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_CANCEL =
337005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_CANCEL";
338a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin
339a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
340a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
341a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REQUEST =
342a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST";
343a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
344a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
345a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
346a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REPLY =
347a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY";
348a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
349a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
350a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
351a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_CANCEL =
352a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL";
353a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
354a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
355a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent.
356a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
357a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
358a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ACCESS_REQUEST_TYPE =
359a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE";
360a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
361a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
362a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1;
363a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
364a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
365a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2;
366a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
367fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie    /**@hide*/
368fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie    public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3;
369fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie
370a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
371a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
372a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains package name to return reply intent to.
373a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
374a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
375a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME";
376a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
377a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
378a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
379a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains class name to return reply intent to.
380a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
381a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
382a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME";
383a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
384a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
385a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent.
386a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
387a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
388a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CONNECTION_ACCESS_RESULT =
389a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT";
390a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
391a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
392a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_YES = 1;
393a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
394a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
395a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_NO = 2;
396a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
397a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
398a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents,
399a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains boolean to indicate if the allowed response is once-for-all so that
400a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * next request will be granted without asking user again.
401a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
402a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
403a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ALWAYS_ALLOWED =
404a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ALWAYS_ALLOWED";
405a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
406c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
407c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt succeeded
408c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
409c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
410b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    public static final int BOND_SUCCESS = 0;
411c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
412c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
413c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because pins did not match, or remote device did
41432d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh     * not respond to pin request in time
415c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
416c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_FAILED = 1;
418c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
419c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
420c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because the other side explicitly rejected
42145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * bonding
422c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
423c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_REJECTED = 2;
425c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
426c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
427c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we canceled the bonding process
428c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
429c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_CANCELED = 3;
431c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
432c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
433c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we could not contact the remote device
434c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
435c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4;
437c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
438c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
439c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because a discovery is in progress
440c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
441c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5;
443c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
444c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
445c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of authentication timeout
446c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
447c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
44832d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_AUTH_TIMEOUT = 6;
449c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
450c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
451c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of repeated attempts
452c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
453c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
45432d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7;
455c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
456c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
457c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we received an Authentication Cancel
458c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * by remote end
459c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
460c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
461e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8;
462c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
463c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
464c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * An existing bond was explicitly revoked
465c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
466c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
467e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOVED = 9;
4689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
469c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
470091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * The user will be prompted to enter a pin or
471ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * an app will enter a pin for user.
472c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
473b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PIN = 0;
474c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
475c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
476c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter a passkey
477c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
478c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
479b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY = 1;
480c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
481c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
482091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * The user will be prompted to confirm the passkey displayed on the screen or
483ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * an app will confirm the passkey for the user.
484c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
48532d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2;
486c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
487c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
488c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the incoming pairing request
489c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
490c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
49132d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_CONSENT = 3;
492c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
493c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
494c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the passkey displayed on remote device
495c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.1 pairing.
496c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
497c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
49832d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4;
499c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
500c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
501c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the PIN displayed on remote device.
502c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.0 pairing.
503c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
504c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
505c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PIN = 5;
506c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
507c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
508c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the OOB pairing request
509c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
510c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
511c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_OOB_CONSENT = 6;
512c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
5131caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
5141caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Used as an extra field in {@link #ACTION_UUID} intents,
515aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * Contains the {@link android.os.ParcelUuid}s of the remote device which
516aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * is a parcelable version of {@link UUID}.
5171caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
5181caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
5191caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
520b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     /**
521b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      * No preferrence of physical transport for GATT connections to remote dual-mode devices
522b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      * @hide
523b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      */
524b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    public static final int TRANSPORT_AUTO = 0;
525b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
526b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
527b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Prefer BR/EDR transport for GATT connections to remote dual-mode devices
528b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
529b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
5308949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final int TRANSPORT_BREDR = 1;
531b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
532b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
533b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Prefer LE transport for GATT connections to remote dual-mode devices
534b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
535b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
5368949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final int TRANSPORT_LE = 2;
537b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
5388949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    /** @hide */
5398949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final String EXTRA_MAS_INSTANCE =
5408949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta        "android.bluetooth.device.extra.MAS_INSTANCE";
541b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
54216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
54316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Lazy initialization. Guaranteed final after first object constructed, or
54416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * getService() called.
54516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * TODO: Unify implementation of sService amongst BluetoothFoo API's
54616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
54716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    private static IBluetooth sService;
548bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
549bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private final String mAddress;
550d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
55116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ static IBluetooth getService() {
552bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        synchronized (BluetoothDevice.class) {
553bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            if (sService == null) {
5540f42037eb7b5118015c2caca635538324ccf0ccffredc                BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
555903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = adapter.getBluetoothService(mStateChangeCallback);
556bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            }
557bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
55816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return sService;
55916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
560bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
561903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() {
562903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
563903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceUp(IBluetooth bluetoothService)
564903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                throws RemoteException {
565903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
566903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = bluetoothService;
567903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
568903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
569903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
570903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceDown()
571903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            throws RemoteException {
572903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
573903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = null;
574903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
575903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
576903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    };
57716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
57816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create a new BluetoothDevice
57916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB",
58016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * and is validated in this constructor.
58116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param address valid Bluetooth MAC address
58216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws RuntimeException Bluetooth is not available on this platform
58316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IllegalArgumentException address is invalid
58416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
58516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
58616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ BluetoothDevice(String address) {
58716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        getService();  // ensures sService is initialized
588005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        if (!BluetoothAdapter.checkBluetoothAddress(address)) {
589bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            throw new IllegalArgumentException(address + " is not a valid Bluetooth address");
590bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
591bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
592bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        mAddress = address;
5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
595bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
596bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean equals(Object o) {
597bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        if (o instanceof BluetoothDevice) {
598bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return mAddress.equals(((BluetoothDevice)o).getAddress());
599bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
6009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
6019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
603bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
604bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int hashCode() {
605bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress.hashCode();
606105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    }
607105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project
60845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
60945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns a string representation of this BluetoothDevice.
61045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Currently this is the Bluetooth hardware address, for example
61145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress}
61245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * if you explicitly require the Bluetooth hardware address in case the
61345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * {@link #toString} representation changes in the future.
61445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return string representation of this BluetoothDevice
61545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
616bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
617bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public String toString() {
618bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
6199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
621bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int describeContents() {
622bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return 0;
623bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
624bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
625bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public static final Parcelable.Creator<BluetoothDevice> CREATOR =
626bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            new Parcelable.Creator<BluetoothDevice>() {
627bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice createFromParcel(Parcel in) {
628bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice(in.readString());
629bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
630bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice[] newArray(int size) {
631bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice[size];
632bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
633bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    };
634bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
635bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public void writeToParcel(Parcel out, int flags) {
636bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        out.writeString(mAddress);
6379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
63945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
64045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns the hardware address of this BluetoothDevice.
64145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p> For example, "00:11:22:AA:BB:CC".
64245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return Bluetooth hardware address as string
64345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
6449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getAddress() {
6450f42037eb7b5118015c2caca635538324ccf0ccffredc        if (DBG) Log.d(TAG, "mAddress: " + mAddress);
646bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
6479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
65045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Get the friendly Bluetooth name of the remote device.
6519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
65245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The local adapter will automatically retrieve remote names when
65345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * performing a device scan, and will cache them. This method just returns
65445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * the name for this device from the cache.
655de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
6569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the Bluetooth name, or null if there was a problem.
6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getName() {
6600f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
6610f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device name");
6620f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
6630f42037eb7b5118015c2caca635538324ccf0ccffredc        }
6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
665e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteName(this);
6669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
6679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
67133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Get the Bluetooth device type of the remote device.
67233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *
67333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
67433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *
67533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE}
67633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *                         {@link #DEVICE_TYPE_DUAL}.
67733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *         {@link #DEVICE_TYPE_UNKNOWN} if it's not available
67833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
67933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public int getType() {
68033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        if (sService == null) {
68133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            Log.e(TAG, "BT not enabled. Cannot get Remote Device type");
68233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            return DEVICE_TYPE_UNKNOWN;
68333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        }
68433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        try {
68533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            return sService.getRemoteType(this);
68633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
68733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        return DEVICE_TYPE_UNKNOWN;
68833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    }
68933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
69033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
691269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
692269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
693269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
694269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
695269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
696269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
697269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAlias() {
6980f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
6990f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias");
7000f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
7010f42037eb7b5118015c2caca635538324ccf0ccffredc        }
702269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
703e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteAlias(this);
704269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
705269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return null;
706269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
707269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
708269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
709269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Set the Bluetooth alias of the remote device.
710269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
711269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>This methoid overwrites the alias. The changed
712269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * alias is saved in the local storage so that the change
713269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * is preserved over power cycle.
714269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
715269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return true on success, false on error
716269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
717269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
718269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public boolean setAlias(String alias) {
7190f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7200f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device name");
7210f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
7220f42037eb7b5118015c2caca635538324ccf0ccffredc        }
723269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
724e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setRemoteAlias(this, alias);
725269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
726269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return false;
727269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
728269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
729269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
730269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
731269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * If Alias is null, get the Bluetooth name instead.
732269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getAlias()
733269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getName()
734269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
735269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
736269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
737269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
738269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAliasName() {
739269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        String name = getAlias();
740269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        if (name == null) {
741269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie            name = getName();
742269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        }
743269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return name;
744269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
745269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
746269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
747005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Start the bonding (pairing) process with the remote device.
748005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is an asynchronous call, it will return immediately. Register
749005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
750005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the bonding process completes, and its result.
751005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Android system services will handle the necessary user interactions
752005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * to confirm and complete the bonding process.
753ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
7549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
755005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return false on immediate error, true if bonding will begin
7569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
757bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean createBond() {
7580f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7590f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
7600f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
7610f42037eb7b5118015c2caca635538324ccf0ccffredc        }
7629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
763e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.createBond(this);
7649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
7659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
7669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
769cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Start the bonding (pairing) process with the remote device using the
770cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Out Of Band mechanism.
771cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
772cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>This is an asynchronous call, it will return immediately. Register
773cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
774cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * the bonding process completes, and its result.
775cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
776cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Android system services will handle the necessary user interactions
777cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * to confirm and complete the bonding process.
778cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
779cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
780cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
781cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash - Simple Secure pairing hash
782cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer - The random key obtained using OOB
783cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on immediate error, true if bonding will begin
784cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
785cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
786cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
787cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean createBondOutOfBand(byte[] hash, byte[] randomizer) {
788e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
789e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
790cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
791e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.createBondOutOfBand(this, hash, randomizer);
792e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
793cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        return false;
794cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
795cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
796cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
797cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Set the Out Of Band data for a remote device to be used later
798cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * in the pairing mechanism. Users can obtain this data through other
799cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * trusted channels
800cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
801cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
802cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
803cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash Simple Secure pairing hash
804cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer The random key obtained using OOB
805cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on error; true otherwise
806cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
807cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
808cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
809cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) {
810e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      //TODO(BT)
811e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      /*
812cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      try {
813e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        return sService.setDeviceOutOfBandData(this, hash, randomizer);
814e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);} */
815cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
816cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
817cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
818cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
819005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Cancel an in-progress bonding request started with {@link #createBond}.
820005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
821005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
822f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
82318b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
8249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
825bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelBondProcess() {
8260f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8270f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond");
8280f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
8290f42037eb7b5118015c2caca635538324ccf0ccffredc        }
8309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
831e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.cancelBondProcess(this);
8329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
8339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
8349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
837005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Remove bond (pairing) with the remote device.
838005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Delete the link key associated with the remote device, and
839005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * immediately terminate connections to that device that require
840005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * authentication and encryption.
841005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
8429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
843f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
84418b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
8459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
846bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean removeBond() {
8470f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8480f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond");
8490f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
8500f42037eb7b5118015c2caca635538324ccf0ccffredc        }
8519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
852e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.removeBond(this);
8539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
854bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return false;
8559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
858005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the bond state of the remote device.
859005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values for the bond state are:
860005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
861005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
862005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
863005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
8649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
865005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return the bond state
8669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
867bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int getBondState() {
8680f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8690f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get bond state");
8700f42037eb7b5118015c2caca635538324ccf0ccffredc            return BOND_NONE;
8710f42037eb7b5118015c2caca635538324ccf0ccffredc        }
8729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
873e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getBondState(this);
8749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
875305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        catch (NullPointerException npe) {
876305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // Handle case where bluetooth service proxy
877305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // is already null.
878305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            Log.e(TAG, "NullPointerException for getBondState() of device ("+
879305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M                getAddress()+")", npe);
880305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        }
881005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return BOND_NONE;
882005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    }
883005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
884005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
885174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * Returns whether there is an open connection to this device.
886174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
887174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     *
888174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * @return True if there is at least one open connection to this device.
889174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * @hide
890174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     */
891174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    public boolean isConnected() {
892174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        if (sService == null) {
893174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            // BT is not enabled, we cannot be connected.
894174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return false;
895174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        }
896174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        try {
897174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return sService.isConnected(this);
898174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        } catch (RemoteException e) {
899174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            Log.e(TAG, "", e);
900174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return false;
901174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        }
902174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    }
903174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli
904174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    /**
905005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the Bluetooth class of the remote device.
906005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
907005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
908005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return Bluetooth class object, or null on error
909005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
910005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public BluetoothClass getBluetoothClass() {
9110f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9120f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class");
9130f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
9140f42037eb7b5118015c2caca635538324ccf0ccffredc        }
915005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        try {
916e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            int classInt = sService.getRemoteClass(this);
917005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            if (classInt == BluetoothClass.ERROR) return null;
918005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            return new BluetoothClass(classInt);
919005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        } catch (RemoteException e) {Log.e(TAG, "", e);}
920005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return null;
9219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
923efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    /**
924efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * Get trust state of a remote device.
925e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
926efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * @hide
927efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     */
928efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    public boolean getTrustState() {
929e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
930e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
931efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        try {
932e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getTrustState(this);
933efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        } catch (RemoteException e) {
934efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue            Log.e(TAG, "", e);
935e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        }*/
936efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        return false;
937efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    }
938efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue
939efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    /**
940efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * Set trust state for a remote device.
941e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
942efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * @param value the trust state value (true or false)
943efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * @hide
944efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     */
945efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    public boolean setTrust(boolean value) {
946e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
947e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
948efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        try {
949e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setTrust(this, value);
950efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        } catch (RemoteException e) {
951efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue            Log.e(TAG, "", e);
952e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        }*/
953efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        return false;
954efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    }
955efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue
956ad2321027e9731711544b43378bd7b2f01890774Matthew Xie    /**
957ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * Returns the supported features (UUIDs) of the remote device.
958ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
959ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>This method does not start a service discovery procedure to retrieve the UUIDs
960ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * from the remote device. Instead, the local cached copy of the service
961ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * UUIDs are returned.
962ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired.
963ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
964ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
965ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * @return the supported features (UUIDs) of the remote device,
966ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *         or null on error
967ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     */
968dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh     public ParcelUuid[] getUuids() {
9690f42037eb7b5118015c2caca635538324ccf0ccffredc         if (sService == null) {
9700f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
9710f42037eb7b5118015c2caca635538324ccf0ccffredc             return null;
9720f42037eb7b5118015c2caca635538324ccf0ccffredc         }
9739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
974e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteUuids(this);
9759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
9769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
9779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
978d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
9791caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     /**
980ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * Perform a service discovery on the remote device to get the UUIDs supported.
981ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      *
982ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent,
983ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * with the UUIDs supported by the remote end. If there is an error
984ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * in getting the SDP records or if the process takes a long time,
985ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently
986ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * present in the cache. Clients should use the {@link #getUuids} to get UUIDs
987ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * if service discovery is not to be performed.
988ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
9891caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *
990ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * @return False if the sanity check fails, True if the process
9911caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               of initiating an ACL connection to the remote device
9921caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               was started.
9931caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      */
9941caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     public boolean fetchUuidsWithSdp() {
9955d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        IBluetooth service = sService;
9965d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        if (service == null) {
9975d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp");
9985d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            return false;
9995d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        }
10001caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh        try {
10015d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            return service.fetchRemoteUuids(this);
10024c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc        } catch (RemoteException e) {Log.e(TAG, "", e);}
10034c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc            return false;
10041caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    }
10051caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
10068949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     /** @hide */
10078949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     public boolean fetchMasInstances() {
10088949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         if (sService == null) {
10098949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta             Log.e(TAG, "BT not enabled. Cannot query remote device for MAS instances");
10108949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta             return false;
10118949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         }
10128949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         try {
10138949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta             return sService.fetchRemoteMasInstances(this);
10148949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         } catch (RemoteException e) {Log.e(TAG, "", e);}
10158949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         return false;
10168949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     }
10178949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta
101845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1019dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh    public int getServiceChannel(ParcelUuid uuid) {
1020e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
1021e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1022d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh         try {
1023e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh             return sService.getRemoteServiceChannel(this, uuid);
1024e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh         } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1025b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly         return BluetoothDevice.ERROR;
10269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1028091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
1029091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN}
1030ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
1031091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *
1032091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @return true pin has been set
1033091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *         false for error
1034091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
1035bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPin(byte[] pin) {
10360f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
10370f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device pin");
10380f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
10390f42037eb7b5118015c2caca635538324ccf0ccffredc        }
10409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1041e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPin(this, true, pin.length, pin);
10429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
10439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
10449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1045b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
104645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1047bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPasskey(int passkey) {
1048e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
1049e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1050b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
1051e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPasskey(this, true, 4, passkey);
1052e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1053b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
1054b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
1055b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
1056091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
1057091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing.
1058ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
1059091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *
1060091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @return true confirmation has been sent out
1061091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *         false for error
1062091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
1063bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPairingConfirmation(boolean confirm) {
10640f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
10650f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set pairing confirmation");
10660f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
10670f42037eb7b5118015c2caca635538324ccf0ccffredc        }
1068b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
1069e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPairingConfirmation(this, confirm);
1070b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}
1071b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
1072b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
1073b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
107445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1075cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setRemoteOutOfBandData() {
1076e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
1077e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1078cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
1079e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh          return sService.setRemoteOutOfBandData(this);
1080e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1081cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
1082cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
1083cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
1084cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /** @hide */
1085bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelPairingUserInput() {
10860f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
10870f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create pairing user input");
10880f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
10890f42037eb7b5118015c2caca635538324ccf0ccffredc        }
10909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1091919a4c6264b733585152ce1dc6f868c1093d368bRavi Nagarajan            return sService.cancelBondProcess(this);
1092db44b20fe6aed65d5cd7e1f6d7c52e4322083039Priti Aghera        } catch (RemoteException e) {Log.e(TAG, "", e);}
10939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
10949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10963fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    /** @hide */
10973fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    public boolean isBluetoothDock() {
1098e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
1099e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
11003fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        try {
1101e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.isBluetoothDock(this);
1102e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
11033fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        return false;
11043fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    }
11053fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh
11069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
110745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
110816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device on given channel.
110945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The remote device will be authenticated and communication on this
111045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * socket will be encrypted.
1111c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1112c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1113c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1114c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1115c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1116c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1117c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocket}.
1118c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1119c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1120f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
112145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * connection.
112245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Valid RFCOMM channels are in range 1 to 30.
1123cf44059813539bf7f36dabd278cef93ba3122c56Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
1124de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     *
112545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @param channel RFCOMM channel to connect to
112645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
1127bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
112845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     *                     insufficient permissions
112916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
1130bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
113145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    public BluetoothSocket createRfcommSocket(int channel) throws IOException {
113216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel,
113316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
113416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
113516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly
113616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
113716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
113816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device using SDP lookup of uuid.
113916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>This is designed to be used with {@link
114016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer
114116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth applications.
1142f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
114316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * connection. This will also perform an SDP lookup of the given uuid to
114416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * determine which channel to connect to.
114516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>The remote device will be authenticated and communication on this
114616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * socket will be encrypted.
1147c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1148c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1149c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1150c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1151c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1152c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1153c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}.
1154c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1155c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1156ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * <p>Hint: If you are connecting to a Bluetooth serial board then try
1157ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
1158ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * However if you are connecting to an Android peer then please generate
1159ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * your own unique UUID.
116016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
116116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *
116216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param uuid service record uuid to lookup RFCOMM channel
116316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
116416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
116516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *                     insufficient permissions
116616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
116716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException {
116816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1,
116916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                new ParcelUuid(uuid));
1170bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1171bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1172bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
11736eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure
11746eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * outgoing connection to this remote device using SDP lookup of uuid.
11756eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p> The communication channel will not have an authenticated link key
11766eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1
11776eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * devices, the link key will be encrypted, as encryption is mandatory.
11786eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * For legacy devices (pre Bluetooth 2.1 devices) the link key will
11796eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an
11806eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * encrypted and authenticated communication channel is desired.
11816eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>This is designed to be used with {@link
11826eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer
11836eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Bluetooth applications.
11846eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
11856eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * connection. This will also perform an SDP lookup of the given uuid to
11866eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * determine which channel to connect to.
11876eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>The remote device will be authenticated and communication on this
11886eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * socket will be encrypted.
11896eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Hint: If you are connecting to a Bluetooth serial board then try
11906eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
11916eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * However if you are connecting to an Android peer then please generate
11926eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * your own unique UUID.
11936eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
11946eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *
11956eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @param uuid service record uuid to lookup RFCOMM channel
11966eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
11976eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @throws IOException on error, for example Bluetooth not available, or
11986eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *                     insufficient permissions
11996eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     */
12006eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException {
12016eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1,
12026eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh                new ParcelUuid(uuid));
12036eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    }
12046eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh
12056eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    /**
1206bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct an insecure RFCOMM socket ready to start an outgoing
1207bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * connection.
1208bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1209bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * The remote device will not be authenticated and communication on this
1210bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * socket will not be encrypted.
1211e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1212e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1213bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @param port    remote port
1214bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return An RFCOMM BluetoothSocket
1215bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException On error, for example Bluetooth not available, or
1216bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
121745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1218bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1219bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException {
122016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port,
122116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
1222bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1223bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1224bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
1225bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct a SCO socket ready to start an outgoing connection.
1226bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1227e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1228e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1229bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return a SCO BluetoothSocket
1230bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
1231bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
123245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1233bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1234bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createScoSocket() throws IOException {
123516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null);
1236bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1237bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1238bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
12399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Check that a pin is valid and convert to byte array.
12409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1241f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters.
12429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param pin pin as java String
1243f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return the pin code as a UTF-8 byte array, or null if it is an invalid
12449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         Bluetooth pin.
124545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
12469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
12479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static byte[] convertPinToBytes(String pin) {
12489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pin == null) {
12499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
12509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
12519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        byte[] pinBytes;
12529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1253f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            pinBytes = pin.getBytes("UTF-8");
12549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (UnsupportedEncodingException uee) {
1255f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            Log.e(TAG, "UTF-8 not supported?!?");  // this should not happen
12569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
12579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
12589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pinBytes.length <= 0 || pinBytes.length > 16) {
12599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
12609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
12619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return pinBytes;
12629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
12639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1264ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
1265ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1266ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * The callback is used to deliver results to Caller, such as connection status as well
1267ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * as any further GATT client operations.
1268ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1269ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * GATT client operations.
1270ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param callback GATT callback handler that will receive asynchronous callbacks.
1271ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param autoConnect Whether to directly connect to the remote device (false)
1272ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *                    or to automatically connect as soon as the remote
1273ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *                    device becomes available (true).
1274ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @throws IllegalArgumentException if callback is null
1275ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
127633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
127733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie                                     BluetoothGattCallback callback) {
1278b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta        return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO));
1279b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    }
1280b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
1281b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
1282b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1283b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * The callback is used to deliver results to Caller, such as connection status as well
1284b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * as any further GATT client operations.
1285b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1286b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * GATT client operations.
1287b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param callback GATT callback handler that will receive asynchronous callbacks.
1288b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param autoConnect Whether to directly connect to the remote device (false)
1289b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *                    or to automatically connect as soon as the remote
1290b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *                    device becomes available (true).
1291b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param transport preferred transport for GATT connections to remote dual-mode devices
1292b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *             {@link BluetoothDevice#TRANSPORT_AUTO} or
1293b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *             {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
1294b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @throws IllegalArgumentException if callback is null
1295b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
1296b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
1297b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
1298b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta                                     BluetoothGattCallback callback, int transport) {
1299ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        // TODO(Bluetooth) check whether platform support BLE
1300ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        //     Do the check here or in GattServer?
1301ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
1302ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        IBluetoothManager managerService = adapter.getBluetoothManager();
1303ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        try {
1304ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            IBluetoothGatt iGatt = managerService.getBluetoothGatt();
130532ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie            if (iGatt == null) {
130632ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie                // BLE is not supported
130732ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie                return null;
130832ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie            }
1309b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta            BluetoothGatt gatt = new BluetoothGatt(context, iGatt, this, transport);
1310ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            gatt.connect(autoConnect, callback);
1311ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            return gatt;
1312ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
1313ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        return null;
1314ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
1315b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
13169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1317