BluetoothDevice.java revision 305f240dc12325af4fa267e7c4f52c680bb05280
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;
21bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.IBinder;
22bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcel;
23bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcelable;
24aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pellyimport android.os.ParcelUuid;
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException;
26bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.ServiceManager;
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log;
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport java.io.IOException;
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.UnsupportedEncodingException;
311caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganeshimport java.util.UUID;
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
349fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you
35f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * create a connection with the respective device or query information about
369fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * it, such as the name, address, class, and bonding state.
3745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly *
3845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>This class is really just a thin wrapper for a Bluetooth hardware
3945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * address. Objects of this class are immutable. Operations on this class
4045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * are performed on the remote Bluetooth hardware address, using the
4145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link BluetoothAdapter} that was used to create this {@link
4245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * BluetoothDevice}.
439fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
449fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>To get a {@link BluetoothDevice}, use
459fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter#getRemoteDevice(String)
469fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device
479fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * of a known MAC address (which you can get through device discovery with
489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter}) or get one from the set of bonded devices
499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * returned by {@link BluetoothAdapter#getBondedDevices()
509fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getBondedDevices()}. You can then open a
51f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * {@link BluetoothSocket} for communication with the remote device, using
529fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link #createRfcommSocketToServiceRecord(UUID)}.
539fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
549fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p class="note"><strong>Note:</strong>
559fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Requires the {@link android.Manifest.permission#BLUETOOTH} permission.
569fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
573aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference">
583aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3>
593aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about using Bluetooth, read the
603aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/wireless/bluetooth.html">Bluetooth</a> developer guide.</p>
613aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div>
623aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez *
639fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothAdapter}
649fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothSocket}
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
66bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellypublic final class BluetoothDevice implements Parcelable {
67bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private static final String TAG = "BluetoothDevice";
687077272d8feed2f0172520d4fd3b4524e18d5ec1Ravi Nagarajan    private static final boolean DBG = false;
699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
70b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    /**
71b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * Sentinel error value for this class. Guaranteed to not equal any other
72b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * integer constant in this class. Provided as a convenience for functions
73b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * that require a sentinel error value, for example:
74005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><code>Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
75005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * BluetoothDevice.ERROR)</code>
76005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
77005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int ERROR = Integer.MIN_VALUE;
78005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
79005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
80005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device discovered.
81005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device is found during discovery.
82005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
83005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}. Can contain the extra fields {@link #EXTRA_NAME} and/or
84005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #EXTRA_RSSI} if they are available.
85005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
86005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
87005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     // TODO: Change API to not broadcast RSSI if not available (incoming connection)
88005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
89005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_FOUND =
90005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.FOUND";
91005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
92005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
93005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device disappeared.
94005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device that was found in the last discovery is not
95005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * found in the current discovery.
96005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
99005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
100005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
101005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_DISAPPEARED =
102005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.DISAPPEARED";
103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Bluetooth class of a remote device has changed.
106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}.
108005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @see {@link BluetoothClass}
110005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
111005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
112005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_CLASS_CHANGED =
113005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.CLASS_CHANGED";
114005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
115005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
116005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) connection has been
117005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * established with a remote device.
118005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
119005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
120005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
121005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
124005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_CONNECTED =
125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_CONNECTED";
126005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates that a low level (ACL) disconnection has
129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been requested for a remote device, and it will soon be disconnected.
130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is useful for graceful disconnection. Applications should use
131005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * this intent as a hint to immediately terminate higher level connections
132005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (RFCOMM, L2CAP, or profile connections) to the remote device.
133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
134005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECT_REQUESTED =
138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED";
139005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
140005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
141005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) disconnection from a
142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * remote device.
143005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
145005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
146005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
147005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
148005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
149005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECTED =
150005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECTED";
151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
152005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
153005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates the friendly name of a remote device has
154005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been retrieved for the first time, or changed since the last retrieval.
155005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
156005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_NAME}.
157005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
158005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
159005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
160005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_CHANGED =
161005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_CHANGED";
162005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
163005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
1645bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * Broadcast Action: Indicates the alias of a remote device has been
1655bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * changed.
1665bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
1675bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
1685bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     *
1695bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * @hide
1705bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     */
1715bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1725bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    public static final String ACTION_ALIAS_CHANGED =
1735bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown            "android.bluetooth.device.action.ALIAS_CHANGED";
1745bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown
1755bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    /**
176005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a change in the bond state of a remote
177005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device. For example, if a device is bonded (paired).
178005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link
179005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}.
180005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
181005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
182005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also
183005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // contain a hidden extra field EXTRA_REASON with the result code.
184005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
185005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_BOND_STATE_CHANGED =
186005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.BOND_STATE_CHANGED";
187005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
188005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
189005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a Parcelable {@link BluetoothDevice} extra field in every intent
190005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * broadcast by this class. It contains the {@link BluetoothDevice} that
191005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the intent applies to.
192005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
193005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
194005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
195005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
196005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link
197005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} intents. It contains the friendly Bluetooth name.
198005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
199005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME";
200005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
201005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
202005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an optional short extra field in {@link #ACTION_FOUND} intents.
203005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the RSSI value of the remote device as reported by the
204005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Bluetooth hardware.
205005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
206005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI";
207005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
208005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
209f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa     * Used as a Parcelable {@link BluetoothClass} extra field in {@link
210005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents.
211005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
212005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS";
213005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
214005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
215005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
216005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the bond state of the remote device.
217005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values are:
218005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
219005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
220005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
221005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly      */
222005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE";
223005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
224005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
225005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the previous bond state of the remote device.
226005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values are:
227005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
228005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
229005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
230005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly      */
231005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_PREVIOUS_BOND_STATE =
232005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PREVIOUS_BOND_STATE";
233005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
234005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is not bonded (paired).
235005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>There is no shared link key with the remote device, so communication
236005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (if it is allowed at all) will be unauthenticated and unencrypted.
237005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
238005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_NONE = 10;
239005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
240005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates bonding (pairing) is in progress with the remote device.
241005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
242005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDING = 11;
243005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
244005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is bonded (paired).
245005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>A shared link keys exists locally for the remote device, so
246005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * communication can be authenticated and encrypted.
247005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><i>Being bonded (paired) with a remote device does not necessarily
248f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * mean the device is currently connected. It just means that the pending
249f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * procedure was completed at some earlier time, and the link key is still
250005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stored locally, ready to use on the next connection.
251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * </i>
252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDED = 12;
254005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
255005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
256005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON";
257005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
258005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_PAIRING_VARIANT =
259005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PAIRING_VARIANT";
260005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
261c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY";
262005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
263005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
2641caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Broadcast Action: This intent is used to broadcast the {@link UUID}
265aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * wrapped as a {@link android.os.ParcelUuid} of the remote device after it
266aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * has been fetched. This intent is sent only when the UUIDs of the remote
267aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * device are requested to be fetched using Service Discovery Protocol
2681caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p> Always contains the extra field {@link #EXTRA_DEVICE}
269ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p> Always contains the extra field {@link #EXTRA_UUID}
2701caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
2711caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
2721caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2731caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String ACTION_UUID =
274ad2321027e9731711544b43378bd7b2f01890774Matthew Xie            "android.bluetooth.device.action.UUID";
2751caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
2761caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
277005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a failure to retrieve the name of a remote
278005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device.
279005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
280005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
281005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
282005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
283005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    //TODO: is this actually useful?
284005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
285005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_FAILED =
286005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_FAILED";
287005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
288005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
289005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
290005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_REQUEST =
291005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_REQUEST";
292005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
293005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
294005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_CANCEL =
295005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_CANCEL";
296a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin
297a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
298a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
299a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REQUEST =
300a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST";
301a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
302a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
303a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
304a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REPLY =
305a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY";
306a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
307a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
308a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
309a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_CANCEL =
310a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL";
311a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
312a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
313a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent.
314a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
315a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
316a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ACCESS_REQUEST_TYPE =
317a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE";
318a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
319a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
320a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1;
321a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
322a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
323a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2;
324a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
325a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
326a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
327a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains package name to return reply intent to.
328a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
329a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
330a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME";
331a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
332a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
333a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
334a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains class name to return reply intent to.
335a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
336a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
337a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME";
338a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
339a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
340a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent.
341a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
342a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
343a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CONNECTION_ACCESS_RESULT =
344a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT";
345a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
346a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
347a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_YES = 1;
348a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
349a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
350a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_NO = 2;
351a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
352a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
353a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents,
354a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains boolean to indicate if the allowed response is once-for-all so that
355a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * next request will be granted without asking user again.
356a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
357a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
358a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ALWAYS_ALLOWED =
359a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ALWAYS_ALLOWED";
360a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
361c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
362c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt succeeded
363c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
364c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
365b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    public static final int BOND_SUCCESS = 0;
366c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
367c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
368c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because pins did not match, or remote device did
36932d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh     * not respond to pin request in time
370c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
371c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
3729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_FAILED = 1;
373c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
374c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
375c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because the other side explicitly rejected
37645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * bonding
377c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
378c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
3799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_REJECTED = 2;
380c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
381c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
382c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we canceled the bonding process
383c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
384c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
3859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_CANCELED = 3;
386c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
387c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
388c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we could not contact the remote device
389c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
390c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4;
392c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
393c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
394c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because a discovery is in progress
395c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
396c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5;
398c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
399c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
400c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of authentication timeout
401c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
402c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
40332d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_AUTH_TIMEOUT = 6;
404c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
405c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
406c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of repeated attempts
407c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
408c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
40932d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7;
410c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
411c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
412c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we received an Authentication Cancel
413c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * by remote end
414c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
415c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
416e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8;
417c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
418c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
419c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * An existing bond was explicitly revoked
420c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
421c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
422e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOVED = 9;
4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
424c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
425c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter a pin
426c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
427c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
428b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PIN = 0;
429c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
430c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
431c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter a passkey
432c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
433c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
434b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY = 1;
435c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
436c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
437c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to confirm the passkey displayed on the screen
438c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
439c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
44032d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2;
441c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
442c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
443c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the incoming pairing request
444c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
445c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
44632d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_CONSENT = 3;
447c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
448c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
449c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the passkey displayed on remote device
450c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.1 pairing.
451c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
452c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
45332d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4;
454c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
455c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
456c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the PIN displayed on remote device.
457c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.0 pairing.
458c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
459c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
460c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PIN = 5;
461c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
462c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
463c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the OOB pairing request
464c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
465c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
466c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_OOB_CONSENT = 6;
467c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
4681caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
4691caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Used as an extra field in {@link #ACTION_UUID} intents,
470aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * Contains the {@link android.os.ParcelUuid}s of the remote device which
471aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * is a parcelable version of {@link UUID}.
4721caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
4731caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
4741caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
47516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
47616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Lazy initialization. Guaranteed final after first object constructed, or
47716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * getService() called.
47816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * TODO: Unify implementation of sService amongst BluetoothFoo API's
47916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
48016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    private static IBluetooth sService;
481bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
482bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private final String mAddress;
483d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
48416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ static IBluetooth getService() {
485bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        synchronized (BluetoothDevice.class) {
486bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            if (sService == null) {
4870f42037eb7b5118015c2caca635538324ccf0ccffredc                BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
488903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = adapter.getBluetoothService(mStateChangeCallback);
489bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            }
490bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
49116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return sService;
49216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
493bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
494903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() {
495903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
496903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceUp(IBluetooth bluetoothService)
497903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                throws RemoteException {
498903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
499903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = bluetoothService;
500903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
501903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
502903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
503903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceDown()
504903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            throws RemoteException {
505903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
506903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = null;
507903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
508903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
509903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    };
51016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
51116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create a new BluetoothDevice
51216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB",
51316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * and is validated in this constructor.
51416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param address valid Bluetooth MAC address
51516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws RuntimeException Bluetooth is not available on this platform
51616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IllegalArgumentException address is invalid
51716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
51816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
51916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ BluetoothDevice(String address) {
52016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        getService();  // ensures sService is initialized
521005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        if (!BluetoothAdapter.checkBluetoothAddress(address)) {
522bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            throw new IllegalArgumentException(address + " is not a valid Bluetooth address");
523bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
524bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
525bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        mAddress = address;
5269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
528bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
529bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean equals(Object o) {
530bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        if (o instanceof BluetoothDevice) {
531bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return mAddress.equals(((BluetoothDevice)o).getAddress());
532bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
5339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
5349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
536bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
537bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int hashCode() {
538bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress.hashCode();
539105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    }
540105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project
54145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
54245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns a string representation of this BluetoothDevice.
54345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Currently this is the Bluetooth hardware address, for example
54445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress}
54545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * if you explicitly require the Bluetooth hardware address in case the
54645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * {@link #toString} representation changes in the future.
54745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return string representation of this BluetoothDevice
54845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
549bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
550bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public String toString() {
551bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
5529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
554bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int describeContents() {
555bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return 0;
556bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
557bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
558bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public static final Parcelable.Creator<BluetoothDevice> CREATOR =
559bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            new Parcelable.Creator<BluetoothDevice>() {
560bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice createFromParcel(Parcel in) {
561bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice(in.readString());
562bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
563bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice[] newArray(int size) {
564bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice[size];
565bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
566bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    };
567bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
568bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public void writeToParcel(Parcel out, int flags) {
569bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        out.writeString(mAddress);
5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
57245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
57345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns the hardware address of this BluetoothDevice.
57445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p> For example, "00:11:22:AA:BB:CC".
57545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return Bluetooth hardware address as string
57645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
5779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getAddress() {
5780f42037eb7b5118015c2caca635538324ccf0ccffredc        if (DBG) Log.d(TAG, "mAddress: " + mAddress);
579bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
5809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
58345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Get the friendly Bluetooth name of the remote device.
5849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
58545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The local adapter will automatically retrieve remote names when
58645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * performing a device scan, and will cache them. This method just returns
58745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * the name for this device from the cache.
588de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the Bluetooth name, or null if there was a problem.
5919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getName() {
5930f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
5940f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device name");
5950f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
5960f42037eb7b5118015c2caca635538324ccf0ccffredc        }
5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
598e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteName(this);
5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
6009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
6019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
604269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
605269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
606269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
607269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
608269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
609269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
610269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAlias() {
6110f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
6120f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias");
6130f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
6140f42037eb7b5118015c2caca635538324ccf0ccffredc        }
615269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
616e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteAlias(this);
617269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
618269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return null;
619269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
620269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
621269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
622269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Set the Bluetooth alias of the remote device.
623269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
624269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>This methoid overwrites the alias. The changed
625269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * alias is saved in the local storage so that the change
626269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * is preserved over power cycle.
627269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
628269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return true on success, false on error
629269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
630269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
631269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public boolean setAlias(String alias) {
6320f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
6330f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device name");
6340f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
6350f42037eb7b5118015c2caca635538324ccf0ccffredc        }
636269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
637e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setRemoteAlias(this, alias);
638269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
639269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return false;
640269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
641269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
642269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
643269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
644269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * If Alias is null, get the Bluetooth name instead.
645269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getAlias()
646269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getName()
647269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
648269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
649269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
650269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
651269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAliasName() {
652269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        String name = getAlias();
653269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        if (name == null) {
654269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie            name = getName();
655269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        }
656269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return name;
657269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
658269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
659269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
660005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Start the bonding (pairing) process with the remote device.
661005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is an asynchronous call, it will return immediately. Register
662005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
663005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the bonding process completes, and its result.
664005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Android system services will handle the necessary user interactions
665005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * to confirm and complete the bonding process.
666005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
6679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
668005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return false on immediate error, true if bonding will begin
66918b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
6709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
671bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean createBond() {
6720f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
6730f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
6740f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
6750f42037eb7b5118015c2caca635538324ccf0ccffredc        }
6769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
677e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.createBond(this);
6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
683cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Start the bonding (pairing) process with the remote device using the
684cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Out Of Band mechanism.
685cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
686cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>This is an asynchronous call, it will return immediately. Register
687cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
688cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * the bonding process completes, and its result.
689cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
690cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Android system services will handle the necessary user interactions
691cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * to confirm and complete the bonding process.
692cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
693cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
694cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
695cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash - Simple Secure pairing hash
696cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer - The random key obtained using OOB
697cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on immediate error, true if bonding will begin
698cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
699cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
700cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
701cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean createBondOutOfBand(byte[] hash, byte[] randomizer) {
702e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
703e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
704cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
705e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.createBondOutOfBand(this, hash, randomizer);
706e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
707cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        return false;
708cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
709cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
710cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
711cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Set the Out Of Band data for a remote device to be used later
712cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * in the pairing mechanism. Users can obtain this data through other
713cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * trusted channels
714cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
715cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
716cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
717cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash Simple Secure pairing hash
718cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer The random key obtained using OOB
719cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on error; true otherwise
720cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
721cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
722cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
723cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) {
724e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      //TODO(BT)
725e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      /*
726cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      try {
727e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        return sService.setDeviceOutOfBandData(this, hash, randomizer);
728e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);} */
729cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
730cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
731cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
732cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
733005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Cancel an in-progress bonding request started with {@link #createBond}.
734005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
735005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
736f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
73718b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
7389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
739bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelBondProcess() {
7400f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7410f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond");
7420f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
7430f42037eb7b5118015c2caca635538324ccf0ccffredc        }
7449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
745e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.cancelBondProcess(this);
7469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
7479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
7489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
751005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Remove bond (pairing) with the remote device.
752005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Delete the link key associated with the remote device, and
753005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * immediately terminate connections to that device that require
754005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * authentication and encryption.
755005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
7569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
757f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
75818b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
7599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
760bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean removeBond() {
7610f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7620f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond");
7630f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
7640f42037eb7b5118015c2caca635538324ccf0ccffredc        }
7659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
766e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.removeBond(this);
7679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
768bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return false;
7699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
772005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the bond state of the remote device.
773005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values for the bond state are:
774005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
775005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
776005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
777005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
7789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
779005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return the bond state
7809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
781bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int getBondState() {
7820f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7830f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get bond state");
7840f42037eb7b5118015c2caca635538324ccf0ccffredc            return BOND_NONE;
7850f42037eb7b5118015c2caca635538324ccf0ccffredc        }
7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
787e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getBondState(this);
7889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
789305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        catch (NullPointerException npe) {
790305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // Handle case where bluetooth service proxy
791305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // is already null.
792305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            Log.e(TAG, "NullPointerException for getBondState() of device ("+
793305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M                getAddress()+")", npe);
794305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        }
795005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return BOND_NONE;
796005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    }
797005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
798005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
799005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the Bluetooth class of the remote device.
800005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
801005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
802005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return Bluetooth class object, or null on error
803005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
804005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public BluetoothClass getBluetoothClass() {
8050f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8060f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class");
8070f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
8080f42037eb7b5118015c2caca635538324ccf0ccffredc        }
809005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        try {
810e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            int classInt = sService.getRemoteClass(this);
811005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            if (classInt == BluetoothClass.ERROR) return null;
812005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            return new BluetoothClass(classInt);
813005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        } catch (RemoteException e) {Log.e(TAG, "", e);}
814005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return null;
8159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
817efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    /**
818efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * Get trust state of a remote device.
819e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
820efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * @hide
821efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     */
822efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    public boolean getTrustState() {
823e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
824e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
825efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        try {
826e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getTrustState(this);
827efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        } catch (RemoteException e) {
828efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue            Log.e(TAG, "", e);
829e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        }*/
830efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        return false;
831efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    }
832efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue
833efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    /**
834efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * Set trust state for a remote device.
835e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
836efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * @param value the trust state value (true or false)
837efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     * @hide
838efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue     */
839efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    public boolean setTrust(boolean value) {
840e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
841e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
842efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        try {
843e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setTrust(this, value);
844efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        } catch (RemoteException e) {
845efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue            Log.e(TAG, "", e);
846e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        }*/
847efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue        return false;
848efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    }
849efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue
850ad2321027e9731711544b43378bd7b2f01890774Matthew Xie    /**
851ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * Returns the supported features (UUIDs) of the remote device.
852ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
853ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>This method does not start a service discovery procedure to retrieve the UUIDs
854ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * from the remote device. Instead, the local cached copy of the service
855ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * UUIDs are returned.
856ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired.
857ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
858ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
859ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * @return the supported features (UUIDs) of the remote device,
860ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *         or null on error
861ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     */
862dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh     public ParcelUuid[] getUuids() {
8630f42037eb7b5118015c2caca635538324ccf0ccffredc         if (sService == null) {
8640f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
8650f42037eb7b5118015c2caca635538324ccf0ccffredc             return null;
8660f42037eb7b5118015c2caca635538324ccf0ccffredc         }
8679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
868e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteUuids(this);
8699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
8709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
8719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
872d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
8731caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     /**
874ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * Perform a service discovery on the remote device to get the UUIDs supported.
875ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      *
876ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent,
877ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * with the UUIDs supported by the remote end. If there is an error
878ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * in getting the SDP records or if the process takes a long time,
879ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently
880ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * present in the cache. Clients should use the {@link #getUuids} to get UUIDs
881ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * if service discovery is not to be performed.
882ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
8831caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *
884ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * @return False if the sanity check fails, True if the process
8851caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               of initiating an ACL connection to the remote device
8861caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               was started.
8871caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      */
8881caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     public boolean fetchUuidsWithSdp() {
8891caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh        try {
8904c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc            return sService.fetchRemoteUuids(this);
8914c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc        } catch (RemoteException e) {Log.e(TAG, "", e);}
8924c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc            return false;
8931caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    }
8941caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
89545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
896dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh    public int getServiceChannel(ParcelUuid uuid) {
897e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
898e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
899d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh         try {
900e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh             return sService.getRemoteServiceChannel(this, uuid);
901e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh         } catch (RemoteException e) {Log.e(TAG, "", e);}*/
902b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly         return BluetoothDevice.ERROR;
9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
90545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
906bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPin(byte[] pin) {
9070f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9080f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device pin");
9090f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
9100f42037eb7b5118015c2caca635538324ccf0ccffredc        }
9119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
912e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPin(this, true, pin.length, pin);
9139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
9149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
9159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
916b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
91745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
918bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPasskey(int passkey) {
919e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
920e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
921b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
922e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPasskey(this, true, 4, passkey);
923e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
924b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
925b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
926b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
92745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
928bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPairingConfirmation(boolean confirm) {
9290f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9300f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set pairing confirmation");
9310f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
9320f42037eb7b5118015c2caca635538324ccf0ccffredc        }
933b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
934e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPairingConfirmation(this, confirm);
935b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}
936b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
937b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
938b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
93945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
940cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setRemoteOutOfBandData() {
941e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
942e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
943cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
944e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh          return sService.setRemoteOutOfBandData(this);
945e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);}*/
946cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
947cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
948cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
949cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /** @hide */
950bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelPairingUserInput() {
9510f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9520f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create pairing user input");
9530f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
9540f42037eb7b5118015c2caca635538324ccf0ccffredc        }
9559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
956919a4c6264b733585152ce1dc6f868c1093d368bRavi Nagarajan            return sService.cancelBondProcess(this);
957db44b20fe6aed65d5cd7e1f6d7c52e4322083039Priti Aghera        } catch (RemoteException e) {Log.e(TAG, "", e);}
9589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
9599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9613fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    /** @hide */
9623fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    public boolean isBluetoothDock() {
963e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
964e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
9653fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        try {
966e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.isBluetoothDock(this);
967e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
9683fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        return false;
9693fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    }
9703fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh
9719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
97245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
97316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device on given channel.
97445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The remote device will be authenticated and communication on this
97545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * socket will be encrypted.
976c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
977c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
978c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
979c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
980c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
981c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
982c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocket}.
983c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
984c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
985f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
98645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * connection.
98745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Valid RFCOMM channels are in range 1 to 30.
988cf44059813539bf7f36dabd278cef93ba3122c56Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
989de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     *
99045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @param channel RFCOMM channel to connect to
99145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
992bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
99345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     *                     insufficient permissions
99416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
995bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
99645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    public BluetoothSocket createRfcommSocket(int channel) throws IOException {
99716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel,
99816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
99916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
100016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly
100116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
100216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
100316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device using SDP lookup of uuid.
100416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>This is designed to be used with {@link
100516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer
100616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth applications.
1007f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
100816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * connection. This will also perform an SDP lookup of the given uuid to
100916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * determine which channel to connect to.
101016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>The remote device will be authenticated and communication on this
101116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * socket will be encrypted.
1012c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1013c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1014c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1015c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1016c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1017c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1018c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}.
1019c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1020c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1021ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * <p>Hint: If you are connecting to a Bluetooth serial board then try
1022ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
1023ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * However if you are connecting to an Android peer then please generate
1024ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * your own unique UUID.
102516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
102616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *
102716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param uuid service record uuid to lookup RFCOMM channel
102816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
102916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
103016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *                     insufficient permissions
103116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
103216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException {
103316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1,
103416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                new ParcelUuid(uuid));
1035bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1036bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1037bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
10386eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure
10396eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * outgoing connection to this remote device using SDP lookup of uuid.
10406eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p> The communication channel will not have an authenticated link key
10416eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1
10426eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * devices, the link key will be encrypted, as encryption is mandatory.
10436eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * For legacy devices (pre Bluetooth 2.1 devices) the link key will
10446eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an
10456eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * encrypted and authenticated communication channel is desired.
10466eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>This is designed to be used with {@link
10476eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer
10486eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Bluetooth applications.
10496eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
10506eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * connection. This will also perform an SDP lookup of the given uuid to
10516eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * determine which channel to connect to.
10526eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>The remote device will be authenticated and communication on this
10536eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * socket will be encrypted.
10546eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Hint: If you are connecting to a Bluetooth serial board then try
10556eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
10566eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * However if you are connecting to an Android peer then please generate
10576eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * your own unique UUID.
10586eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
10596eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *
10606eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @param uuid service record uuid to lookup RFCOMM channel
10616eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
10626eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @throws IOException on error, for example Bluetooth not available, or
10636eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *                     insufficient permissions
10646eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     */
10656eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException {
10666eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1,
10676eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh                new ParcelUuid(uuid));
10686eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    }
10696eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh
10706eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    /**
1071bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct an insecure RFCOMM socket ready to start an outgoing
1072bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * connection.
1073bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1074bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * The remote device will not be authenticated and communication on this
1075bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * socket will not be encrypted.
1076e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1077e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1078bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @param port    remote port
1079bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return An RFCOMM BluetoothSocket
1080bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException On error, for example Bluetooth not available, or
1081bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
108245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1083bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1084bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException {
108516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port,
108616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
1087bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1088bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1089bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
1090bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct a SCO socket ready to start an outgoing connection.
1091bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1092e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1093e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1094bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return a SCO BluetoothSocket
1095bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
1096bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
109745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1098bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1099bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createScoSocket() throws IOException {
110016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null);
1101bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1102bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1103bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
11049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Check that a pin is valid and convert to byte array.
11059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1106f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters.
11079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param pin pin as java String
1108f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return the pin code as a UTF-8 byte array, or null if it is an invalid
11099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         Bluetooth pin.
111045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
11119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
11129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static byte[] convertPinToBytes(String pin) {
11139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pin == null) {
11149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
11159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
11169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        byte[] pinBytes;
11179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1118f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            pinBytes = pin.getBytes("UTF-8");
11199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (UnsupportedEncodingException uee) {
1120f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            Log.e(TAG, "UTF-8 not supported?!?");  // this should not happen
11219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
11229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
11239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pinBytes.length <= 0 || pinBytes.length > 16) {
11249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
11259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
11269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return pinBytes;
11279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
11289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1130