BluetoothDevice.java revision d055adbe2c1c65d9346e65209fa8790190bc239e
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
2bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly * Copyright (C) 2009 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.bluetooth;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellyimport android.annotation.SdkConstant;
20005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellyimport android.annotation.SdkConstant.SdkConstantType;
212b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbachimport android.annotation.SystemApi;
22ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xieimport android.content.Context;
23bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcel;
24bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport android.os.Parcelable;
25aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pellyimport android.os.ParcelUuid;
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException;
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log;
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellyimport java.io.IOException;
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.UnsupportedEncodingException;
311caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganeshimport java.util.UUID;
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
349fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you
35f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * create a connection with the respective device or query information about
369fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * it, such as the name, address, class, and bonding state.
3745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly *
3845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * <p>This class is really just a thin wrapper for a Bluetooth hardware
3945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * address. Objects of this class are immutable. Operations on this class
4045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * are performed on the remote Bluetooth hardware address, using the
4145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * {@link BluetoothAdapter} that was used to create this {@link
4245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly * BluetoothDevice}.
439fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
449fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>To get a {@link BluetoothDevice}, use
459fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter#getRemoteDevice(String)
469fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getRemoteDevice(String)} to create one representing a device
479fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * of a known MAC address (which you can get through device discovery with
489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothAdapter}) or get one from the set of bonded devices
499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * returned by {@link BluetoothAdapter#getBondedDevices()
509fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothAdapter.getBondedDevices()}. You can then open a
51f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * {@link BluetoothSocket} for communication with the remote device, using
529fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link #createRfcommSocketToServiceRecord(UUID)}.
539fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
549fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p class="note"><strong>Note:</strong>
559fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Requires the {@link android.Manifest.permission#BLUETOOTH} permission.
569fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main *
573aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference">
583aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3>
593aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about using Bluetooth, read the
603aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/wireless/bluetooth.html">Bluetooth</a> developer guide.</p>
613aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div>
623aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez *
639fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothAdapter}
649fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@see BluetoothSocket}
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
66bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pellypublic final class BluetoothDevice implements Parcelable {
67bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private static final String TAG = "BluetoothDevice";
687077272d8feed2f0172520d4fd3b4524e18d5ec1Ravi Nagarajan    private static final boolean DBG = false;
699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
70b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    /**
712b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * Connection state bitmask as returned by getConnectionState.
722b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     */
732b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_DISCONNECTED = 0;
742b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_CONNECTED = 1;
752b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_ENCRYPTED_BREDR = 2;
762b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    private static final int CONNECTION_STATE_ENCRYPTED_LE = 4;
772b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach
782b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    /**
79b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * Sentinel error value for this class. Guaranteed to not equal any other
80b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * integer constant in this class. Provided as a convenience for functions
81b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly     * that require a sentinel error value, for example:
82005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><code>Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
83005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * BluetoothDevice.ERROR)</code>
84005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
85005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int ERROR = Integer.MIN_VALUE;
86005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
87005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
88005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device discovered.
89005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device is found during discovery.
90005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
91005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}. Can contain the extra fields {@link #EXTRA_NAME} and/or
92005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #EXTRA_RSSI} if they are available.
93005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
94005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
95005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     // TODO: Change API to not broadcast RSSI if not available (incoming connection)
96005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_FOUND =
98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.FOUND";
99005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
100005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
101005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Remote device disappeared.
102005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Sent when a remote device that was found in the last discovery is not
103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * found in the current discovery.
104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
107005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
108005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
109005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_DISAPPEARED =
110005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.DISAPPEARED";
111005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
112005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
113005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Bluetooth class of a remote device has changed.
114005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
115005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_CLASS}.
116005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
117b30f91e38c19f6728d836293446d4b9c76705e7fMatthew Xie     * {@see BluetoothClass}
118005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
119005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
120005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_CLASS_CHANGED =
121005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.CLASS_CHANGED";
122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
124005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) connection has been
125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * established with a remote device.
126005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
131005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
132005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_CONNECTED =
133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_CONNECTED";
134005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates that a low level (ACL) disconnection has
137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been requested for a remote device, and it will soon be disconnected.
138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is useful for graceful disconnection. Applications should use
139005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * this intent as a hint to immediately terminate higher level connections
140005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (RFCOMM, L2CAP, or profile connections) to the remote device.
141005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
143005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
145005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECT_REQUESTED =
146005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED";
147005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
148005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
149005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a low level (ACL) disconnection from a
150005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * remote device.
151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
152005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>ACL connections are managed automatically by the Android Bluetooth
153005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stack.
154005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
155005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
156005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
157005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_ACL_DISCONNECTED =
158005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.ACL_DISCONNECTED";
159005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
160005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
161005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates the friendly name of a remote device has
162005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * been retrieved for the first time, or changed since the last retrieval.
163005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
164005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_NAME}.
165005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
166005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
167005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
168005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_CHANGED =
169005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_CHANGED";
170005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
171005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
1725bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * Broadcast Action: Indicates the alias of a remote device has been
1735bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * changed.
1745bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
1755bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
1765bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     *
1775bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     * @hide
1785bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown     */
1795bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1805bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    public static final String ACTION_ALIAS_CHANGED =
1815bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown            "android.bluetooth.device.action.ALIAS_CHANGED";
1825bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown
1835bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    /**
184005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a change in the bond state of a remote
185005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device. For example, if a device is bonded (paired).
186005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra fields {@link #EXTRA_DEVICE}, {@link
187005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #EXTRA_BOND_STATE} and {@link #EXTRA_PREVIOUS_BOND_STATE}.
188005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
189005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
190005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // Note: When EXTRA_BOND_STATE is BOND_NONE then this will also
191005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    // contain a hidden extra field EXTRA_REASON with the result code.
192005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
193005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_BOND_STATE_CHANGED =
194005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.BOND_STATE_CHANGED";
195005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
196005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
197005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a Parcelable {@link BluetoothDevice} extra field in every intent
198005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * broadcast by this class. It contains the {@link BluetoothDevice} that
199005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the intent applies to.
200005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
201005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
202005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
203005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
204005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as a String extra field in {@link #ACTION_NAME_CHANGED} and {@link
205005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} intents. It contains the friendly Bluetooth name.
206005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
207005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME";
208005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
209005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
210005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an optional short extra field in {@link #ACTION_FOUND} intents.
211005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the RSSI value of the remote device as reported by the
212005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Bluetooth hardware.
213005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
214005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_RSSI = "android.bluetooth.device.extra.RSSI";
215005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
216005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
217f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa     * Used as a Parcelable {@link BluetoothClass} extra field in {@link
218005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents.
219005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
220005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS";
221005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
222005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
223005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
224005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the bond state of the remote device.
225005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values are:
226005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
227005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
228005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
229091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
230005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE";
231005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
232005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Used as an int extra field in {@link #ACTION_BOND_STATE_CHANGED} intents.
233005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Contains the previous bond state of the remote device.
234005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values are:
235005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
236005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
237005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
238091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
239005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_PREVIOUS_BOND_STATE =
240005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PREVIOUS_BOND_STATE";
241005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
242005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is not bonded (paired).
243005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>There is no shared link key with the remote device, so communication
244005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * (if it is allowed at all) will be unauthenticated and unencrypted.
245005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
246005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_NONE = 10;
247005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
248005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates bonding (pairing) is in progress with the remote device.
249005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
250005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDING = 11;
251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Indicates the remote device is bonded (paired).
253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>A shared link keys exists locally for the remote device, so
254005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * communication can be authenticated and encrypted.
255005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p><i>Being bonded (paired) with a remote device does not necessarily
256f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * mean the device is currently connected. It just means that the pending
257f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * procedure was completed at some earlier time, and the link key is still
258005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * stored locally, ready to use on the next connection.
259005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * </i>
260005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
261005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final int BOND_BONDED = 12;
262005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
263091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
264091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
265091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents for unbond reason.
266091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @hide
267091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
268005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON";
269091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie
270091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
271091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
272091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents to indicate pairing method used. Possible values are:
273091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * {@link #PAIRING_VARIANT_PIN},
274091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION},
275091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
276005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String EXTRA_PAIRING_VARIANT =
277005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.extra.PAIRING_VARIANT";
278091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie
279091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
280091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
281091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * intents as the value of passkey.
282091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
283c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY";
284005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
285005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
28633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Unknown
28733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
28833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_UNKNOWN = 0;
28933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
29033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
29133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Classic - BR/EDR devices
29233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
29333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_CLASSIC = 1;
29433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
29533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
29633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Low Energy - LE-only
29733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
29833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_LE = 2;
29933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
30033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
30133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Bluetooth device type, Dual Mode - BR/EDR/LE
30233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
30333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public static final int DEVICE_TYPE_DUAL = 3;
30433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
305238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde
306238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    /** @hide */
307238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
308238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    public static final String ACTION_SDP_RECORD =
309238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde            "android.bluetooth.device.action.SDP_RECORD";
310238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde
31133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
3121caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Broadcast Action: This intent is used to broadcast the {@link UUID}
313aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * wrapped as a {@link android.os.ParcelUuid} of the remote device after it
314aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * has been fetched. This intent is sent only when the UUIDs of the remote
315aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * device are requested to be fetched using Service Discovery Protocol
3161caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p> Always contains the extra field {@link #EXTRA_DEVICE}
317ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p> Always contains the extra field {@link #EXTRA_UUID}
3181caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
3191caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
3201caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3211caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String ACTION_UUID =
322ad2321027e9731711544b43378bd7b2f01890774Matthew Xie            "android.bluetooth.device.action.UUID";
3231caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
3248949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    /** @hide */
3258949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3268949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final String ACTION_MAS_INSTANCE =
3278949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta            "android.bluetooth.device.action.MAS_INSTANCE";
3288949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta
3291caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
330005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Broadcast Action: Indicates a failure to retrieve the name of a remote
331005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * device.
332005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
333005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
334005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @hide
335005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
336005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    //TODO: is this actually useful?
337005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
338005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_NAME_FAILED =
339005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.NAME_FAILED";
340005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
341091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
342091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Broadcast Action: This intent is used to broadcast PAIRING REQUEST
343ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} to
344430e361b202ecff8a10a9258948ade99689fe6b1Edward Jee     * receive.
345091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
346005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
347005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_REQUEST =
348005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_REQUEST";
349005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /** @hide */
350005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
351005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public static final String ACTION_PAIRING_CANCEL =
352005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            "android.bluetooth.device.action.PAIRING_CANCEL";
353a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin
354a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
355a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
356a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REQUEST =
357a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST";
358a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
359a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
360a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
361a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_REPLY =
362a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_REPLY";
363a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
364a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /** @hide */
365a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
366a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String ACTION_CONNECTION_ACCESS_CANCEL =
367a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie            "android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL";
368a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
369a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
370a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent.
371a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
372a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
373a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ACCESS_REQUEST_TYPE =
374a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE";
375a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
376a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
377a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1;
378a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
379a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
380a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2;
381a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
382fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie    /**@hide*/
383fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie    public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3;
384fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie
385a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
386a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
387a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains package name to return reply intent to.
388a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
389a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
390a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME";
391a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
392a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
393a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
394a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains class name to return reply intent to.
395a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
396a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
397a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME";
398a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
399a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
400a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent.
401a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
402a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
403a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_CONNECTION_ACCESS_RESULT =
404a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT";
405a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
406a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
407a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_YES = 1;
408a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
409a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**@hide*/
410a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final int CONNECTION_ACCESS_NO = 2;
411a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
412a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    /**
413a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents,
414a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * Contains boolean to indicate if the allowed response is once-for-all so that
415a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * next request will be granted without asking user again.
416a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     * @hide
417a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie     */
418a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie    public static final String EXTRA_ALWAYS_ALLOWED =
419a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie        "android.bluetooth.device.extra.ALWAYS_ALLOWED";
420a0c680393f2dd03a937c598b2cb9abf98a58152cMatthew Xie
421c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
422c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt succeeded
423c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
424c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
425b24e11baac589fe16426f2d243b460ab84991c7bNick Pelly    public static final int BOND_SUCCESS = 0;
426c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
427c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
428c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because pins did not match, or remote device did
42932d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh     * not respond to pin request in time
430c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
431c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_FAILED = 1;
433c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
434c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
435c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because the other side explicitly rejected
43645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * bonding
437c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
438c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_REJECTED = 2;
440c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
441c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
442c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we canceled the bonding process
443c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
444c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_AUTH_CANCELED = 3;
446c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
447c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
448c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we could not contact the remote device
449c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
450c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4;
452c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
453c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
454c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because a discovery is in progress
455c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
456c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
4579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5;
458c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
459c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
460c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of authentication timeout
461c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
462c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
46332d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_AUTH_TIMEOUT = 6;
464c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
465c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
466c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because of repeated attempts
467c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
468c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
46932d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7;
470c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
471c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
472c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * A bond attempt failed because we received an Authentication Cancel
473c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * by remote end
474c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
475c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
476e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8;
477c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
478c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
479c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * An existing bond was explicitly revoked
480c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
481c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
482e5d93b7ed983f98855555d560faf060836f1a52fJaikumar Ganesh    public static final int UNBOND_REASON_REMOVED = 9;
4839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
484c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
485091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * The user will be prompted to enter a pin or
486ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * an app will enter a pin for user.
487c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
488b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PIN = 0;
489c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
490c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
491c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter a passkey
492c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
493c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
494b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY = 1;
495c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
496c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
497091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * The user will be prompted to confirm the passkey displayed on the screen or
498ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * an app will confirm the passkey for the user.
499c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
50032d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION = 2;
501c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
502c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
503c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the incoming pairing request
504c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
505c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
50632d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_CONSENT = 3;
507c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
508c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
509c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the passkey displayed on remote device
510c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.1 pairing.
511c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
512c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
51332d8571f509c392dca732c243e9b2138c15daecfJaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4;
514c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
515c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
516c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to enter the PIN displayed on remote device.
517c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * This is used for Bluetooth 2.0 pairing.
518c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
519c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
520c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_DISPLAY_PIN = 5;
521c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
522c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    /**
523c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * The user will be prompted to accept or deny the OOB pairing request
524c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     * @hide
525c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh     */
526c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh    public static final int PAIRING_VARIANT_OOB_CONSENT = 6;
527c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh
5281caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    /**
5291caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     * Used as an extra field in {@link #ACTION_UUID} intents,
530aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * Contains the {@link android.os.ParcelUuid}s of the remote device which
531aef439e6f825c0cb99a2ac08c8207f48b7a9fe10Nick Pelly     * is a parcelable version of {@link UUID}.
5321caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     */
5331caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
5341caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
535238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    /** @hide */
536238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    public static final String EXTRA_SDP_RECORD =
537238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde        "android.bluetooth.device.extra.SDP_RECORD";
538238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde
539238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    /** @hide */
540238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    public static final String EXTRA_SDP_SEARCH_STATUS =
541238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde            "android.bluetooth.device.extra.SDP_SEARCH_STATUS";
5428dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
5438dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
5448dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
5458dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
5468dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
5478dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public static final int ACCESS_UNKNOWN = 0;
5488dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
5498dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
5508dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
5518dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
5528dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
5538dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
5548dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public static final int ACCESS_ALLOWED = 1;
5558dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
5568dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
5578dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
5588dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
5598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
5608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
5618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public static final int ACCESS_REJECTED = 2;
5628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
563b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     /**
564b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      * No preferrence of physical transport for GATT connections to remote dual-mode devices
565b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      * @hide
566b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta      */
567b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    public static final int TRANSPORT_AUTO = 0;
568b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
569b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
570b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Prefer BR/EDR transport for GATT connections to remote dual-mode devices
571b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
572b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
5738949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final int TRANSPORT_BREDR = 1;
574b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
575b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
576b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Prefer LE transport for GATT connections to remote dual-mode devices
577b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
578b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
5798949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final int TRANSPORT_LE = 2;
580b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
5818949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    /** @hide */
5828949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta    public static final String EXTRA_MAS_INSTANCE =
5838949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta        "android.bluetooth.device.extra.MAS_INSTANCE";
584b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
58516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
58616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Lazy initialization. Guaranteed final after first object constructed, or
58716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * getService() called.
58816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * TODO: Unify implementation of sService amongst BluetoothFoo API's
58916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
59016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    private static IBluetooth sService;
591bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
592bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    private final String mAddress;
593d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
59416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ static IBluetooth getService() {
595bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        synchronized (BluetoothDevice.class) {
596bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            if (sService == null) {
5970f42037eb7b5118015c2caca635538324ccf0ccffredc                BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
598903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = adapter.getBluetoothService(mStateChangeCallback);
599bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            }
600bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
60116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return sService;
60216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
603bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
604903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() {
605903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
606903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceUp(IBluetooth bluetoothService)
607903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                throws RemoteException {
608903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
609d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora                if (sService == null) {
610d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora                    sService = bluetoothService;
611d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora                }
612903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
613903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
614903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc
615903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        public void onBluetoothServiceDown()
616903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            throws RemoteException {
617903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            synchronized (BluetoothDevice.class) {
618903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc                sService = null;
619903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc            }
620903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc        }
621d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
622d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        public void onBrEdrDown()
623d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        {
624d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            if (DBG) Log.d(TAG, "onBrEdrDown: reached BLE ON state");
625d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
626903ac6f399dcd4f574bf388daa7b5f5907d448d3fredc    };
62716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
62816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create a new BluetoothDevice
62916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB",
63016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * and is validated in this constructor.
63116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param address valid Bluetooth MAC address
63216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws RuntimeException Bluetooth is not available on this platform
63316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IllegalArgumentException address is invalid
63416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
63516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
63616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /*package*/ BluetoothDevice(String address) {
63716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        getService();  // ensures sService is initialized
638005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        if (!BluetoothAdapter.checkBluetoothAddress(address)) {
639bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            throw new IllegalArgumentException(address + " is not a valid Bluetooth address");
640bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
641bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
642bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        mAddress = address;
6439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
645bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
646bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean equals(Object o) {
647bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        if (o instanceof BluetoothDevice) {
648bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return mAddress.equals(((BluetoothDevice)o).getAddress());
649bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
6509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
6519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
653bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
654bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int hashCode() {
655bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress.hashCode();
656105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project    }
657105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project
65845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
65945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns a string representation of this BluetoothDevice.
66045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Currently this is the Bluetooth hardware address, for example
66145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress}
66245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * if you explicitly require the Bluetooth hardware address in case the
66345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * {@link #toString} representation changes in the future.
66445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return string representation of this BluetoothDevice
66545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
666bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    @Override
667bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public String toString() {
668bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
6699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
671bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int describeContents() {
672bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return 0;
673bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
674bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
675bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public static final Parcelable.Creator<BluetoothDevice> CREATOR =
676bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            new Parcelable.Creator<BluetoothDevice>() {
677bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice createFromParcel(Parcel in) {
678bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice(in.readString());
679bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
680bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        public BluetoothDevice[] newArray(int size) {
681bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly            return new BluetoothDevice[size];
682bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        }
683bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    };
684bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
685bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public void writeToParcel(Parcel out, int flags) {
686bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        out.writeString(mAddress);
6879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
68945e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /**
69045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Returns the hardware address of this BluetoothDevice.
69145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p> For example, "00:11:22:AA:BB:CC".
69245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return Bluetooth hardware address as string
69345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     */
6949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getAddress() {
6950f42037eb7b5118015c2caca635538324ccf0ccffredc        if (DBG) Log.d(TAG, "mAddress: " + mAddress);
696bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return mAddress;
6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
70045e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Get the friendly Bluetooth name of the remote device.
7019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
70245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The local adapter will automatically retrieve remote names when
70345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * performing a device scan, and will cache them. This method just returns
70445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * the name for this device from the cache.
705de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
7069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
7079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the Bluetooth name, or null if there was a problem.
7089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getName() {
7100f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7110f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device name");
7120f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
7130f42037eb7b5118015c2caca635538324ccf0ccffredc        }
7149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
715e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteName(this);
7169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
7189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
72133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * Get the Bluetooth device type of the remote device.
72233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *
72333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
72433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *
72533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE}
72633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *                         {@link #DEVICE_TYPE_DUAL}.
72733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     *         {@link #DEVICE_TYPE_UNKNOWN} if it's not available
72833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie     */
72933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public int getType() {
73033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        if (sService == null) {
73133ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            Log.e(TAG, "BT not enabled. Cannot get Remote Device type");
73233ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            return DEVICE_TYPE_UNKNOWN;
73333ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        }
73433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        try {
73533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie            return sService.getRemoteType(this);
73633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
73733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie        return DEVICE_TYPE_UNKNOWN;
73833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    }
73933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie
74033ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    /**
741269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
742269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
743269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
744269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
745269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
746269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
747269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAlias() {
7480f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7490f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Remote Device Alias");
7500f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
7510f42037eb7b5118015c2caca635538324ccf0ccffredc        }
752269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
753e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteAlias(this);
754269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
755269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return null;
756269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
757269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
758269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
759269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Set the Bluetooth alias of the remote device.
760269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>Alias is the locally modified name of a remote device.
761269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * <p>This methoid overwrites the alias. The changed
762269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * alias is saved in the local storage so that the change
763269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * is preserved over power cycle.
764269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
765269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return true on success, false on error
766269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
767269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
768269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public boolean setAlias(String alias) {
7690f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
7700f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device name");
7710f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
7720f42037eb7b5118015c2caca635538324ccf0ccffredc        }
773269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        try {
774e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setRemoteAlias(this, alias);
775269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
776269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return false;
777269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
778269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
779269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
780269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * Get the Bluetooth alias of the remote device.
781269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * If Alias is null, get the Bluetooth name instead.
782269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getAlias()
783269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @see #getName()
784269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     *
785269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @return the Bluetooth alias, or null if no alias or there was a problem
786269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     * @hide
787269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie     */
788269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    public String getAliasName() {
789269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        String name = getAlias();
790269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        if (name == null) {
791269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie            name = getName();
792269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        }
793269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie        return name;
794269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    }
795269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie
796269e81a563cfe080d7f241d0d46411d3c946c111Matthew Xie    /**
797005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Start the bonding (pairing) process with the remote device.
798005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>This is an asynchronous call, it will return immediately. Register
799005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
800005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * the bonding process completes, and its result.
801005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Android system services will handle the necessary user interactions
802005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * to confirm and complete the bonding process.
803ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
8049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
805005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return false on immediate error, true if bonding will begin
8069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
807bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean createBond() {
8080f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
8090f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
8100f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
8110f42037eb7b5118015c2caca635538324ccf0ccffredc        }
8129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
81357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return sService.createBond(this, TRANSPORT_AUTO);
81457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        } catch (RemoteException e) {Log.e(TAG, "", e);}
81557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        return false;
81657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    }
81757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach
81857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    /**
81957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * Start the bonding (pairing) process with the remote device using the
82057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * specified transport.
82157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     *
82257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>This is an asynchronous call, it will return immediately. Register
82357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
82457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * the bonding process completes, and its result.
82557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>Android system services will handle the necessary user interactions
82657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * to confirm and complete the bonding process.
82757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
82857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     *
82957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @param transport The transport to use for the pairing procedure.
83057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @return false on immediate error, true if bonding will begin
83157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @throws IllegalArgumentException if an invalid transport was specified
83257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     * @hide
83357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach     */
83457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach    public boolean createBond(int transport) {
83557210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        if (sService == null) {
83657210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
83757210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return false;
83857210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        }
83957210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE)
84057210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        {
84157210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport");
84257210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        }
84357210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach        try {
84457210c7a1aebb86d091dee0af49b45649ca47f87Andre Eisenbach            return sService.createBond(this, transport);
8459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
8469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
8479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
850cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Start the bonding (pairing) process with the remote device using the
851cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Out Of Band mechanism.
852cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
853cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>This is an asynchronous call, it will return immediately. Register
854cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
855cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * the bonding process completes, and its result.
856cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
857cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Android system services will handle the necessary user interactions
858cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * to confirm and complete the bonding process.
859cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
860cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
861cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
862cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash - Simple Secure pairing hash
863cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer - The random key obtained using OOB
864cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on immediate error, true if bonding will begin
865cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
866cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
867cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
868cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean createBondOutOfBand(byte[] hash, byte[] randomizer) {
869e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
870e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
871cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
872e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.createBondOutOfBand(this, hash, randomizer);
873e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
874cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        return false;
875cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
876cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
877cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
878cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * Set the Out Of Band data for a remote device to be used later
879cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * in the pairing mechanism. Users can obtain this data through other
880cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * trusted channels
881cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
882cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
883cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
884cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param hash Simple Secure pairing hash
885cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @param randomizer The random key obtained using OOB
886cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @return false on error; true otherwise
887cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     *
888cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     * @hide
889cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh     */
890cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) {
891e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      //TODO(BT)
892e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      /*
893cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      try {
894e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        return sService.setDeviceOutOfBandData(this, hash, randomizer);
895e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);} */
896cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
897cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
898cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
899cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /**
900005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Cancel an in-progress bonding request started with {@link #createBond}.
901005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
902005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
903f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
90418b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
9059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
906bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelBondProcess() {
9070f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9080f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond");
9090f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
9100f42037eb7b5118015c2caca635538324ccf0ccffredc        }
9119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
912e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.cancelBondProcess(this);
9139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
9149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
9159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
918005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Remove bond (pairing) with the remote device.
919005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Delete the link key associated with the remote device, and
920005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * immediately terminate connections to that device that require
921005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * authentication and encryption.
922005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
9239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
924f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return true on success, false on error
92518b1e79a123b979d25bfa5d0b0ee5d0382dbd64bNick Pelly     * @hide
9269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
927bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean removeBond() {
9280f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9290f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot remove Remote Device bond");
9300f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
9310f42037eb7b5118015c2caca635538324ccf0ccffredc        }
9329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
933e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.removeBond(this);
9349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
935bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly        return false;
9369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
939005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the bond state of the remote device.
940005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Possible values for the bond state are:
941005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_NONE},
942005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDING},
943005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * {@link #BOND_BONDED}.
944005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
9459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
946005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return the bond state
9479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
948bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public int getBondState() {
9490f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
9500f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get bond state");
9510f42037eb7b5118015c2caca635538324ccf0ccffredc            return BOND_NONE;
9520f42037eb7b5118015c2caca635538324ccf0ccffredc        }
9539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
954e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getBondState(this);
9559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
956305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        catch (NullPointerException npe) {
957305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // Handle case where bluetooth service proxy
958305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            // is already null.
959305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M            Log.e(TAG, "NullPointerException for getBondState() of device ("+
960305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M                getAddress()+")", npe);
961305f240dc12325af4fa267e7c4f52c680bb05280Syed Ibrahim M        }
962005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return BOND_NONE;
963005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    }
964005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly
965005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    /**
966174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * Returns whether there is an open connection to this device.
967174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
968174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     *
969174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * @return True if there is at least one open connection to this device.
970174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     * @hide
971174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli     */
9722b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    @SystemApi
973174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    public boolean isConnected() {
974174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        if (sService == null) {
975174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            // BT is not enabled, we cannot be connected.
976174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return false;
977174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        }
978174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        try {
9792b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return sService.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED;
9802b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        } catch (RemoteException e) {
9812b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            Log.e(TAG, "", e);
9822b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return false;
9832b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        }
9842b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    }
9852b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach
9862b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    /**
9872b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * Returns whether there is an open connection to this device
9882b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * that has been encrypted.
9892b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
9902b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     *
9912b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * @return True if there is at least one encrypted connection to this device.
9922b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     * @hide
9932b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach     */
9942b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    @SystemApi
9952b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach    public boolean isEncrypted() {
9962b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        if (sService == null) {
9972b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            // BT is not enabled, we cannot be connected.
9982b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return false;
9992b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        }
10002b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach        try {
10012b8696e3a91194db0bfd876b8cc68843a7ccd080Andre Eisenbach            return sService.getConnectionState(this) > CONNECTION_STATE_CONNECTED;
1002174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        } catch (RemoteException e) {
1003174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            Log.e(TAG, "", e);
1004174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli            return false;
1005174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli        }
1006174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    }
1007174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli
1008174928c0aaf020de4514a5c02799299c6e56e4c0Jay Civelli    /**
1009005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * Get the Bluetooth class of the remote device.
1010005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
1011005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     *
1012005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     * @return Bluetooth class object, or null on error
1013005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly     */
1014005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly    public BluetoothClass getBluetoothClass() {
10150f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
10160f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class");
10170f42037eb7b5118015c2caca635538324ccf0ccffredc            return null;
10180f42037eb7b5118015c2caca635538324ccf0ccffredc        }
1019005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        try {
1020e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            int classInt = sService.getRemoteClass(this);
1021005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            if (classInt == BluetoothClass.ERROR) return null;
1022005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly            return new BluetoothClass(classInt);
1023005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        } catch (RemoteException e) {Log.e(TAG, "", e);}
1024005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly        return null;
10259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1027efa1dd716da3372cc74a201d11de5e0ef1a9fe9aLixin Yue    /**
1028ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * Returns the supported features (UUIDs) of the remote device.
1029ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
1030ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>This method does not start a service discovery procedure to retrieve the UUIDs
1031ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * from the remote device. Instead, the local cached copy of the service
1032ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * UUIDs are returned.
1033ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired.
1034ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
1035ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *
1036ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     * @return the supported features (UUIDs) of the remote device,
1037ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     *         or null on error
1038ad2321027e9731711544b43378bd7b2f01890774Matthew Xie     */
1039dd0463aef18d251c741bfc9dc7a2787443ef36f1Jaikumar Ganesh     public ParcelUuid[] getUuids() {
1040d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         if (sService == null || isBluetoothEnabled() == false) {
10410f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
10420f42037eb7b5118015c2caca635538324ccf0ccffredc             return null;
10430f42037eb7b5118015c2caca635538324ccf0ccffredc         }
10449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1045e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.getRemoteUuids(this);
10469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
10479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return null;
10489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1049d5ac1ae36b4e096eb97984334f86d0c68abea2f7Jaikumar Ganesh
10501caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     /**
1051ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * Perform a service discovery on the remote device to get the UUIDs supported.
1052ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      *
1053ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>This API is asynchronous and {@link #ACTION_UUID} intent is sent,
1054ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * with the UUIDs supported by the remote end. If there is an error
1055ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * in getting the SDP records or if the process takes a long time,
1056ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently
1057ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * present in the cache. Clients should use the {@link #getUuids} to get UUIDs
1058ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * if service discovery is not to be performed.
1059ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
10601caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *
1061ad2321027e9731711544b43378bd7b2f01890774Matthew Xie      * @return False if the sanity check fails, True if the process
10621caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               of initiating an ACL connection to the remote device
10631caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      *               was started.
10641caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh      */
10651caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh     public boolean fetchUuidsWithSdp() {
10665d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        IBluetooth service = sService;
1067d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (service == null || isBluetoothEnabled() == false) {
10685d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp");
10695d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            return false;
10705d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu        }
10711caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh        try {
10725d04f1c9d9390579c9205d2faf09b954cbcc1aeaZhihai Xu            return service.fetchRemoteUuids(this);
10734c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc        } catch (RemoteException e) {Log.e(TAG, "", e);}
10744c9cacadcc7ab20e06763746bbb41d0acdc106b5fredc            return false;
10751caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh    }
10761caa6d111eff6814760ec156b14adc29aa3aae6cJaikumar Ganesh
1077238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     /**
1078238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * Perform a service discovery on the remote device to get the SDP records associated
1079238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * with the specified UUID.
1080238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      *
1081238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * <p>This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent,
1082238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * with the SDP records found on the remote end. If there is an error
1083238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * in getting the SDP records or if the process takes a long time,
1084238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * {@link #ACTION_SDP_RECORD} intent is sent with an status value in
1085238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0.
1086238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * Detailed status error codes can be found by members of the Bluetooth package in
1087238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * the AbstractionLayer class.
1088238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
1089238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}.
1090238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * The object type will match one of the SdpXxxRecord types, depending on the UUID searched
1091238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * for.
1092238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      *
1093238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      * @return False if the sanity check fails, True if the process
1094238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      *               of initiating an ACL connection to the remote device
1095238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      *               was started.
1096238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde      */
10978949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     /** @hide */
1098238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     public boolean sdpSearch(ParcelUuid uuid) {
10998949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         if (sService == null) {
1100238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde             Log.e(TAG, "BT not enabled. Cannot query remote device sdp records");
11018949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta             return false;
11028949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         }
11038949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         try {
1104238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde             return sService.sdpSearch(this,uuid);
11058949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         } catch (RemoteException e) {Log.e(TAG, "", e);}
11068949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta         return false;
11078949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta     }
11088949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta
1109091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
1110091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN}
1111ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
1112091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *
1113091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @return true pin has been set
1114091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *         false for error
1115091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
1116bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPin(byte[] pin) {
11170f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
11180f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set Remote Device pin");
11190f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
11200f42037eb7b5118015c2caca635538324ccf0ccffredc        }
11219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1122e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPin(this, true, pin.length, pin);
11239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {Log.e(TAG, "", e);}
11249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
11259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1126b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
112745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1128bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPasskey(int passkey) {
1129e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        //TODO(BT)
1130e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1131b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
1132e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPasskey(this, true, 4, passkey);
1133e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1134b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
1135b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
1136b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
1137091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie    /**
1138091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing.
1139ac2c6c3a16a69053596b350e94fee52ce85eeacfMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
1140091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *
1141091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     * @return true confirmation has been sent out
1142091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     *         false for error
1143091fc2ba7a4441b9985dfd9ebe25cb7c99a7324bMatthew Xie     */
1144bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean setPairingConfirmation(boolean confirm) {
11450f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
11460f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot set pairing confirmation");
11470f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
11480f42037eb7b5118015c2caca635538324ccf0ccffredc        }
1149b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        try {
1150e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.setPairingConfirmation(this, confirm);
1151b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}
1152b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh        return false;
1153b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh    }
1154b0eca41de0bb6747d8648b134912782e45e4cbefJaikumar Ganesh
115545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    /** @hide */
1156cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    public boolean setRemoteOutOfBandData() {
1157e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
1158e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
1159cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh        try {
1160e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh          return sService.setRemoteOutOfBandData(this);
1161e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh      } catch (RemoteException e) {Log.e(TAG, "", e);}*/
1162cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh      return false;
1163cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    }
1164cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh
1165cc5494c9996f809e36539b24e8b6b67683383d29Jaikumar Ganesh    /** @hide */
1166bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public boolean cancelPairingUserInput() {
11670f42037eb7b5118015c2caca635538324ccf0ccffredc        if (sService == null) {
11680f42037eb7b5118015c2caca635538324ccf0ccffredc            Log.e(TAG, "BT not enabled. Cannot create pairing user input");
11690f42037eb7b5118015c2caca635538324ccf0ccffredc            return false;
11700f42037eb7b5118015c2caca635538324ccf0ccffredc        }
11719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1172919a4c6264b733585152ce1dc6f868c1093d368bRavi Nagarajan            return sService.cancelBondProcess(this);
1173db44b20fe6aed65d5cd7e1f6d7c52e4322083039Priti Aghera        } catch (RemoteException e) {Log.e(TAG, "", e);}
11749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return false;
11759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
11769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11773fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    /** @hide */
11783fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    public boolean isBluetoothDock() {
1179e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        // TODO(BT)
1180e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        /*
11813fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        try {
1182e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh            return sService.isBluetoothDock(this);
1183e4caddbb7a3b39fd6a1ccf107c7dbf09bc8978e8Jaikumar Ganesh        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
11843fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh        return false;
11853fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh    }
11863fbf7b62bb48b10316353087d09cc3720af00642Jaikumar Ganesh
1187d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora     boolean isBluetoothEnabled() {
1188d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         boolean ret = false;
1189d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
1190d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         if (adapter != null && adapter.isEnabled() == true) {
1191d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora             ret = true;
1192d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         }
1193d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora         return ret;
1194d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora     }
1195d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
11969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
11978dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Requires {@link android.Manifest.permission#BLUETOOTH}.
11988dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the phonebook access is allowed to this device. Can be
11998dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *         {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
12008dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
12018dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
12028dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public int getPhonebookAccessPermission() {
12038dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
12048dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return ACCESS_UNKNOWN;
12058dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12068dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
12078dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.getPhonebookAccessPermission(this);
12088dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
12098dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
12108dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12118dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return ACCESS_UNKNOWN;
12128dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
12138dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
12148dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
12158dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Sets whether the phonebook access is allowed to this device.
12168dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
12178dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
12188dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *              {@link #ACCESS_REJECTED}.
12198dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the value has been successfully set.
12208dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
12218dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
12228dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public boolean setPhonebookAccessPermission(int value) {
12238dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
12248dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return false;
12258dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12268dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
12278dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.setPhonebookAccessPermission(this, value);
12288dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
12298dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
12308dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12318dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return false;
12328dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
12338dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
12348dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
12358dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Requires {@link android.Manifest.permission#BLUETOOTH}.
12368dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the message access is allowed to this device. Can be
12378dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *         {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
12388dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
12398dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
12408dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public int getMessageAccessPermission() {
12418dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
12428dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return ACCESS_UNKNOWN;
12438dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12448dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
12458dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.getMessageAccessPermission(this);
12468dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
12478dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
12488dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12498dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return ACCESS_UNKNOWN;
12508dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
12518dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
12528dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
12538dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * Sets whether the message access is allowed to this device.
12548dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
12558dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
12568dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     *              {@link #ACCESS_REJECTED}.
12578dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @return Whether the value has been successfully set.
12588dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     * @hide
12598dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee     */
12608dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    public boolean setMessageAccessPermission(int value) {
12618dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        if (sService == null) {
12628dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return false;
12638dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12648dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        try {
12658dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            return sService.setMessageAccessPermission(this, value);
12668dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        } catch (RemoteException e) {
12678dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee            Log.e(TAG, "", e);
12688dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        }
12698dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee        return false;
12708dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    }
12718dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee
12728dd30aadaf133fe1b8974847efdd5b8cf285136dEdward Jee    /**
127345e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
127416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device on given channel.
127545e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>The remote device will be authenticated and communication on this
127645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * socket will be encrypted.
1277c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1278c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1279c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1280c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1281c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1282c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1283c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocket}.
1284c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1285c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1286f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
128745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * connection.
128845e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * <p>Valid RFCOMM channels are in range 1 to 30.
1289cf44059813539bf7f36dabd278cef93ba3122c56Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
1290de893f550301a60274e87aa8168225e7a7a42184Nick Pelly     *
129145e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @param channel RFCOMM channel to connect to
129245e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
1293bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
129445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     *                     insufficient permissions
129516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @hide
1296bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
129745e2704ff512d41e22af2801d76e96955469ce8dNick Pelly    public BluetoothSocket createRfcommSocket(int channel) throws IOException {
1298d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1299d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1300d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1301d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
130216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel,
130316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
130416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    }
130516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly
130616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    /**
1307238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * Create an L2cap {@link BluetoothSocket} ready to start a secure
1308238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * outgoing connection to this remote device on given channel.
1309238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p>The remote device will be authenticated and communication on this
1310238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * socket will be encrypted.
1311238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p> Use this socket only if an authenticated socket link is possible.
1312238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * Authentication refers to the authentication of the link key to
1313238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * prevent man-in-the-middle type of attacks.
1314238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1315238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * have an input and output capability or just has the ability to
1316238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * display a numeric key, a secure socket connection is not possible.
1317238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * In such a case, use {#link createInsecureRfcommSocket}.
1318238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * For more details, refer to the Security Model section 5.2 (vol 3) of
1319238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * Bluetooth Core Specification version 2.1 + EDR.
1320238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
1321238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * connection.
1322238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p>Valid L2CAP PSM channels are in range 1 to 2^16.
1323238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
1324238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     *
1325238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * @param channel L2cap PSM/channel to connect to
1326238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
1327238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * @throws IOException on error, for example Bluetooth not available, or
1328238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     *                     insufficient permissions
1329238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     * @hide
1330238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde     */
1331238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    public BluetoothSocket createL2capSocket(int channel) throws IOException {
1332238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde        return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, -1, true, true, this, channel,
1333238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde                null);
1334238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    }
1335238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde
1336238e0f934f1f47263b384bc745ae0678c777130dCasper Bonde    /**
133716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Create an RFCOMM {@link BluetoothSocket} ready to start a secure
133816fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * outgoing connection to this remote device using SDP lookup of uuid.
133916fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>This is designed to be used with {@link
134016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * BluetoothAdapter#listenUsingRfcommWithServiceRecord} for peer-peer
134116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * Bluetooth applications.
1342f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
134316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * connection. This will also perform an SDP lookup of the given uuid to
134416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * determine which channel to connect to.
134516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>The remote device will be authenticated and communication on this
134616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * socket will be encrypted.
1347c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * <p> Use this socket only if an authenticated socket link is possible.
1348c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Authentication refers to the authentication of the link key to
1349c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * prevent man-in-the-middle type of attacks.
1350c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For example, for Bluetooth 2.1 devices, if any of the devices does not
1351c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * have an input and output capability or just has the ability to
1352c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * display a numeric key, a secure socket connection is not possible.
1353c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * In such a case, use {#link createInsecureRfcommSocketToServiceRecord}.
1354c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * For more details, refer to the Security Model section 5.2 (vol 3) of
1355c8fa4ff838a0c3d2c67db65540fa751e5abe27edJaikumar Ganesh     * Bluetooth Core Specification version 2.1 + EDR.
1356ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * <p>Hint: If you are connecting to a Bluetooth serial board then try
1357ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
1358ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * However if you are connecting to an Android peer then please generate
1359ea5056e5a705048f8495131ab0dcf087a2633fedNick Pelly     * your own unique UUID.
136016fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
136116fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *
136216fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @param uuid service record uuid to lookup RFCOMM channel
136316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
136416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
136516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     *                     insufficient permissions
136616fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly     */
136716fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly    public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException {
1368d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1369d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1370d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1371d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
1372d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
137316fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1,
137416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                new ParcelUuid(uuid));
1375bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1376bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1377bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
13786eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Create an RFCOMM {@link BluetoothSocket} socket ready to start an insecure
13796eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * outgoing connection to this remote device using SDP lookup of uuid.
13806eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p> The communication channel will not have an authenticated link key
13816eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1
13826eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * devices, the link key will be encrypted, as encryption is mandatory.
13836eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * For legacy devices (pre Bluetooth 2.1 devices) the link key will
13846eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * be not be encrypted. Use {@link #createRfcommSocketToServiceRecord} if an
13856eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * encrypted and authenticated communication channel is desired.
13866eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>This is designed to be used with {@link
13876eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * BluetoothAdapter#listenUsingInsecureRfcommWithServiceRecord} for peer-peer
13886eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * Bluetooth applications.
13896eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Use {@link BluetoothSocket#connect} to initiate the outgoing
13906eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * connection. This will also perform an SDP lookup of the given uuid to
13916eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * determine which channel to connect to.
13926eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>The remote device will be authenticated and communication on this
13936eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * socket will be encrypted.
13946eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Hint: If you are connecting to a Bluetooth serial board then try
13956eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
13966eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * However if you are connecting to an Android peer then please generate
13976eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * your own unique UUID.
13986eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
13996eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *
14006eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @param uuid service record uuid to lookup RFCOMM channel
14016eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
14026eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     * @throws IOException on error, for example Bluetooth not available, or
14036eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     *                     insufficient permissions
14046eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh     */
14056eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException {
1406d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1407d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1408d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1409d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
14106eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1,
14116eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh                new ParcelUuid(uuid));
14126eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    }
14136eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh
14146eef14a7fcf6b6338f21f760830abf369ca0137dJaikumar Ganesh    /**
1415bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct an insecure RFCOMM socket ready to start an outgoing
1416bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * connection.
1417bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1418bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * The remote device will not be authenticated and communication on this
1419bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * socket will not be encrypted.
1420e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1421e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1422bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @param port    remote port
1423bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return An RFCOMM BluetoothSocket
1424bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException On error, for example Bluetooth not available, or
1425bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
142645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1427bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1428bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException {
1429d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
1430d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1431d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1432d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1433d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
143416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port,
143516fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly                null);
1436bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1437bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1438bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
1439bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Construct a SCO socket ready to start an outgoing connection.
1440bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * Call #connect on the returned #BluetoothSocket to begin the connection.
1441e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
1442e6ee3be1c254404dad842298f6f56c11cc6c7ac8Nick Pelly     *
1443bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @return a SCO BluetoothSocket
1444bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     * @throws IOException on error, for example Bluetooth not available, or
1445bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     *                     insufficient permissions.
144645e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
1447bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly     */
1448bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    public BluetoothSocket createScoSocket() throws IOException {
1449d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora
1450d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        if (isBluetoothEnabled() == false) {
1451d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            Log.e(TAG, "Bluetooth is not enabled");
1452d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora            throw new IOException();
1453d055adbe2c1c65d9346e65209fa8790190bc239eNitin Arora        }
145416fb88a673c41b93c5d57ccb28c2697e7d87701aNick Pelly        return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null);
1455bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    }
1456bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly
1457bd022f423a33f0794bb53e5b0720da2d67e4631cNick Pelly    /**
14589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Check that a pin is valid and convert to byte array.
14599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
1460f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * Bluetooth pin's are 1 to 16 bytes of UTF-8 characters.
14619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param pin pin as java String
1462f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby     * @return the pin code as a UTF-8 byte array, or null if it is an invalid
14639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         Bluetooth pin.
146445e2704ff512d41e22af2801d76e96955469ce8dNick Pelly     * @hide
14659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
14669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static byte[] convertPinToBytes(String pin) {
14679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pin == null) {
14689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
14699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
14709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        byte[] pinBytes;
14719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
1472f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            pinBytes = pin.getBytes("UTF-8");
14739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (UnsupportedEncodingException uee) {
1474f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby            Log.e(TAG, "UTF-8 not supported?!?");  // this should not happen
14759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
14769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
14779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (pinBytes.length <= 0 || pinBytes.length > 16) {
14789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
14799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
14809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return pinBytes;
14819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
14829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1483ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
1484ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1485ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * The callback is used to deliver results to Caller, such as connection status as well
1486ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * as any further GATT client operations.
1487ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1488ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * GATT client operations.
1489ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param callback GATT callback handler that will receive asynchronous callbacks.
1490ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param autoConnect Whether to directly connect to the remote device (false)
1491ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *                    or to automatically connect as soon as the remote
1492ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *                    device becomes available (true).
1493ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @throws IllegalArgumentException if callback is null
1494ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
149533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
149633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie                                     BluetoothGattCallback callback) {
1497b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta        return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO));
1498b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    }
1499b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta
1500b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    /**
1501b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * Connect to GATT Server hosted by this device. Caller acts as GATT client.
1502b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * The callback is used to deliver results to Caller, such as connection status as well
1503b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * as any further GATT client operations.
1504b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
1505b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * GATT client operations.
1506b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param callback GATT callback handler that will receive asynchronous callbacks.
1507b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param autoConnect Whether to directly connect to the remote device (false)
1508b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *                    or to automatically connect as soon as the remote
1509b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *                    device becomes available (true).
1510b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @param transport preferred transport for GATT connections to remote dual-mode devices
1511b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *             {@link BluetoothDevice#TRANSPORT_AUTO} or
1512b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     *             {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
1513b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @throws IllegalArgumentException if callback is null
1514b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     * @hide
1515b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta     */
1516b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta    public BluetoothGatt connectGatt(Context context, boolean autoConnect,
1517b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta                                     BluetoothGattCallback callback, int transport) {
1518ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        // TODO(Bluetooth) check whether platform support BLE
1519ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        //     Do the check here or in GattServer?
1520ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
1521ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        IBluetoothManager managerService = adapter.getBluetoothManager();
1522ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        try {
1523ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            IBluetoothGatt iGatt = managerService.getBluetoothGatt();
152432ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie            if (iGatt == null) {
152532ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie                // BLE is not supported
152632ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie                return null;
152732ab77b4c52db78aea22cb32824c7fd68d6f8c21Matthew Xie            }
1528b88fa824ab6337684de9aa8437c4952df4f1a75eGanesh Ganapathi Batta            BluetoothGatt gatt = new BluetoothGatt(context, iGatt, this, transport);
1529ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            gatt.connect(autoConnect, callback);
1530ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie            return gatt;
1531ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        } catch (RemoteException e) {Log.e(TAG, "", e);}
1532ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        return null;
1533ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
15349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1535