The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.server; |
| 18 | |
| 19 | import android.bluetooth.BluetoothA2dp; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 20 | import android.bluetooth.BluetoothAdapter; |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothClass; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.bluetooth.BluetoothDevice; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 23 | import android.bluetooth.BluetoothUuid; |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 24 | import android.bluetooth.ParcelUuid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.os.Handler; |
| 28 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.util.Log; |
| 30 | |
| 31 | import java.util.HashMap; |
| 32 | |
| 33 | /** |
| 34 | * TODO: Move this to |
| 35 | * java/services/com/android/server/BluetoothEventLoop.java |
| 36 | * and make the contructor package private again. |
| 37 | * |
| 38 | * @hide |
| 39 | */ |
| 40 | class BluetoothEventLoop { |
| 41 | private static final String TAG = "BluetoothEventLoop"; |
| 42 | private static final boolean DBG = false; |
| 43 | |
| 44 | private int mNativeData; |
| 45 | private Thread mThread; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 46 | private boolean mStarted; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | private boolean mInterrupted; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 48 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 49 | private final HashMap<String, Integer> mPasskeyAgentRequestData; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 50 | private final BluetoothService mBluetoothService; |
| 51 | private final BluetoothAdapter mAdapter; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 52 | private final Context mContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
| 54 | private static final int EVENT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY = 1; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 55 | private static final int EVENT_RESTART_BLUETOOTH = 2; |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 56 | private static final int EVENT_PAIRING_CONSENT_DELAYED_ACCEPT = 3; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
| 58 | // The time (in millisecs) to delay the pairing attempt after the first |
| 59 | // auto pairing attempt fails. We use an exponential delay with |
| 60 | // INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY as the initial value and |
| 61 | // MAX_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY as the max value. |
| 62 | private static final long INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY = 3000; |
| 63 | private static final long MAX_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY = 12000; |
| 64 | |
| 65 | private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; |
| 66 | private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH; |
| 67 | |
| 68 | private final Handler mHandler = new Handler() { |
| 69 | @Override |
| 70 | public void handleMessage(Message msg) { |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 71 | String address = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | switch (msg.what) { |
| 73 | case EVENT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY: |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 74 | address = (String)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | if (address != null) { |
| 76 | mBluetoothService.createBond(address); |
| 77 | return; |
| 78 | } |
| 79 | break; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 80 | case EVENT_RESTART_BLUETOOTH: |
Nick Pelly | 37b5a10 | 2009-03-24 20:46:18 -0700 | [diff] [blame] | 81 | mBluetoothService.restart(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 82 | break; |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 83 | case EVENT_PAIRING_CONSENT_DELAYED_ACCEPT: |
| 84 | address = (String)msg.obj; |
| 85 | if (address != null) { |
| 86 | mBluetoothService.setPairingConfirmation(address, true); |
| 87 | } |
| 88 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | static { classInitNative(); } |
| 94 | private static native void classInitNative(); |
| 95 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 96 | /* pacakge */ BluetoothEventLoop(Context context, BluetoothAdapter adapter, |
| 97 | BluetoothService bluetoothService) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | mBluetoothService = bluetoothService; |
| 99 | mContext = context; |
| 100 | mPasskeyAgentRequestData = new HashMap(); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 101 | mAdapter = adapter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | initializeNativeDataNative(); |
| 103 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | |
| 105 | protected void finalize() throws Throwable { |
| 106 | try { |
| 107 | cleanupNativeDataNative(); |
| 108 | } finally { |
| 109 | super.finalize(); |
| 110 | } |
| 111 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 113 | /* package */ HashMap<String, Integer> getPasskeyAgentRequestData() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | return mPasskeyAgentRequestData; |
| 115 | } |
| 116 | |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 117 | /* package */ void start() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 119 | if (!isEventLoopRunningNative()) { |
| 120 | if (DBG) log("Starting Event Loop thread"); |
| 121 | startEventLoopNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 125 | public void stop() { |
| 126 | if (isEventLoopRunningNative()) { |
| 127 | if (DBG) log("Stopping Event Loop thread"); |
| 128 | stopEventLoopNative(); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | public boolean isEventLoopRunning() { |
| 133 | return isEventLoopRunningNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 136 | private void addDevice(String address, String[] properties) { |
| 137 | mBluetoothService.addRemoteDeviceProperties(address, properties); |
| 138 | String rssi = mBluetoothService.getRemoteDeviceProperty(address, "RSSI"); |
| 139 | String classValue = mBluetoothService.getRemoteDeviceProperty(address, "Class"); |
| 140 | String name = mBluetoothService.getRemoteDeviceProperty(address, "Name"); |
| 141 | short rssiValue; |
| 142 | // For incoming connections, we don't get the RSSI value. Use a default of MIN_VALUE. |
| 143 | // If we accept the pairing, we will automatically show it at the top of the list. |
| 144 | if (rssi != null) { |
| 145 | rssiValue = (short)Integer.valueOf(rssi).intValue(); |
| 146 | } else { |
| 147 | rssiValue = Short.MIN_VALUE; |
| 148 | } |
| 149 | if (classValue != null) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 150 | Intent intent = new Intent(BluetoothDevice.ACTION_FOUND); |
| 151 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 152 | intent.putExtra(BluetoothDevice.EXTRA_CLASS, |
| 153 | new BluetoothClass(Integer.valueOf(classValue))); |
| 154 | intent.putExtra(BluetoothDevice.EXTRA_RSSI, rssiValue); |
| 155 | intent.putExtra(BluetoothDevice.EXTRA_NAME, name); |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 156 | |
| 157 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 158 | } else { |
| 159 | log ("ClassValue: " + classValue + " for remote device: " + address + " is null"); |
| 160 | } |
| 161 | } |
| 162 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 163 | private void onDeviceFound(String address, String[] properties) { |
| 164 | if (properties == null) { |
| 165 | Log.e(TAG, "ERROR: Remote device properties are null"); |
| 166 | return; |
| 167 | } |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 168 | addDevice(address, properties); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 171 | private void onDeviceDisappeared(String address) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 172 | Intent intent = new Intent(BluetoothDevice.ACTION_DISAPPEARED); |
| 173 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 175 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | |
Jaikumar Ganesh | 5e59ca8 | 2009-09-11 12:16:19 -0700 | [diff] [blame] | 177 | private void onDeviceDisconnectRequested(String deviceObjectPath) { |
| 178 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 179 | if (address == null) { |
| 180 | Log.e(TAG, "onDeviceDisconnectRequested: Address of the remote device in null"); |
| 181 | return; |
| 182 | } |
| 183 | Intent intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED); |
| 184 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 185 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 186 | } |
| 187 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 188 | private void onCreatePairedDeviceResult(String address, int result) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | address = address.toUpperCase(); |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 190 | if (result == BluetoothDevice.BOND_SUCCESS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | mBluetoothService.getBondState().setBondState(address, BluetoothDevice.BOND_BONDED); |
| 192 | if (mBluetoothService.getBondState().isAutoPairingAttemptsInProgress(address)) { |
| 193 | mBluetoothService.getBondState().clearPinAttempts(address); |
| 194 | } |
| 195 | } else if (result == BluetoothDevice.UNBOND_REASON_AUTH_FAILED && |
| 196 | mBluetoothService.getBondState().getAttempt(address) == 1) { |
| 197 | mBluetoothService.getBondState().addAutoPairingFailure(address); |
| 198 | pairingAttempt(address, result); |
| 199 | } else if (result == BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN && |
| 200 | mBluetoothService.getBondState().isAutoPairingAttemptsInProgress(address)) { |
| 201 | pairingAttempt(address, result); |
| 202 | } else { |
| 203 | mBluetoothService.getBondState().setBondState(address, |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 204 | BluetoothDevice.BOND_NONE, result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | if (mBluetoothService.getBondState().isAutoPairingAttemptsInProgress(address)) { |
| 206 | mBluetoothService.getBondState().clearPinAttempts(address); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | private void pairingAttempt(String address, int result) { |
| 212 | // This happens when our initial guess of "0000" as the pass key |
| 213 | // fails. Try to create the bond again and display the pin dialog |
| 214 | // to the user. Use back-off while posting the delayed |
| 215 | // message. The initial value is |
| 216 | // INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY and the max value is |
| 217 | // MAX_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY. If the max value is |
| 218 | // reached, display an error to the user. |
| 219 | int attempt = mBluetoothService.getBondState().getAttempt(address); |
| 220 | if (attempt * INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY > |
| 221 | MAX_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY) { |
| 222 | mBluetoothService.getBondState().clearPinAttempts(address); |
| 223 | mBluetoothService.getBondState().setBondState(address, |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 224 | BluetoothDevice.BOND_NONE, result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | return; |
| 226 | } |
| 227 | |
| 228 | Message message = mHandler.obtainMessage(EVENT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY); |
| 229 | message.obj = address; |
| 230 | boolean postResult = mHandler.sendMessageDelayed(message, |
| 231 | attempt * INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY); |
| 232 | if (!postResult) { |
| 233 | mBluetoothService.getBondState().clearPinAttempts(address); |
| 234 | mBluetoothService.getBondState().setBondState(address, |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 235 | BluetoothDevice.BOND_NONE, result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | mBluetoothService.getBondState().attempt(address); |
| 239 | } |
| 240 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 241 | private void onDeviceCreated(String deviceObjectPath) { |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 242 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 243 | if (!mBluetoothService.isRemoteDeviceInCache(address)) { |
| 244 | // Incoming connection, we haven't seen this device, add to cache. |
| 245 | String[] properties = mBluetoothService.getRemoteDeviceProperties(address); |
| 246 | if (properties != null) { |
| 247 | addDevice(address, properties); |
| 248 | } |
| 249 | } |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 250 | mBluetoothService.getBondState().setBondState(address, BluetoothDevice.BOND_BONDING); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 251 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 254 | private void onDeviceRemoved(String deviceObjectPath) { |
| 255 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 256 | if (address != null) |
| 257 | mBluetoothService.getBondState().setBondState(address.toUpperCase(), |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 258 | BluetoothDevice.BOND_NONE, BluetoothDevice.UNBOND_REASON_REMOVED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 261 | /*package*/ void onPropertyChanged(String[] propValues) { |
Jaikumar Ganesh | 9519ce7 | 2009-09-08 21:37:32 -0700 | [diff] [blame] | 262 | if (mBluetoothService.isAdapterPropertiesEmpty()) { |
| 263 | // We have got a property change before |
| 264 | // we filled up our cache. |
| 265 | mBluetoothService.getAllProperties(); |
| 266 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 267 | String name = propValues[0]; |
| 268 | if (name.equals("Name")) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 269 | Intent intent = new Intent(BluetoothDevice.ACTION_NAME_CHANGED); |
| 270 | intent.putExtra(BluetoothDevice.EXTRA_NAME, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 271 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 272 | mBluetoothService.setProperty(name, propValues[1]); |
| 273 | } else if (name.equals("Pairable") || name.equals("Discoverable")) { |
| 274 | String pairable = name.equals("Pairable") ? propValues[1] : |
| 275 | mBluetoothService.getProperty("Pairable"); |
| 276 | String discoverable = name.equals("Discoverable") ? propValues[1] : |
| 277 | mBluetoothService.getProperty("Discoverable"); |
| 278 | |
| 279 | // This shouldn't happen, unless Adapter Properties are null. |
| 280 | if (pairable == null || discoverable == null) |
| 281 | return; |
| 282 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 283 | int mode = BluetoothService.bluezStringToScanMode( |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 284 | pairable.equals("true"), |
| 285 | discoverable.equals("true")); |
| 286 | if (mode >= 0) { |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 287 | Intent intent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED); |
| 288 | intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, mode); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 289 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 290 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 291 | } |
| 292 | mBluetoothService.setProperty(name, propValues[1]); |
| 293 | } else if (name.equals("Discovering")) { |
| 294 | Intent intent; |
| 295 | if (propValues[1].equals("true")) { |
| 296 | mBluetoothService.setIsDiscovering(true); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 297 | intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_STARTED); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 298 | } else { |
| 299 | // Stop the discovery. |
| 300 | mBluetoothService.cancelDiscovery(); |
| 301 | mBluetoothService.setIsDiscovering(false); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 302 | intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 303 | } |
| 304 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 305 | mBluetoothService.setProperty(name, propValues[1]); |
| 306 | } else if (name.equals("Devices")) { |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 307 | String value = null; |
| 308 | int len = Integer.valueOf(propValues[1]); |
| 309 | if (len > 0) { |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 310 | StringBuilder str = new StringBuilder(); |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 311 | for (int i = 2; i < propValues.length; i++) { |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 312 | str.append(propValues[i]); |
| 313 | str.append(","); |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 314 | } |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 315 | value = str.toString(); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 316 | } |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 317 | mBluetoothService.setProperty(name, value); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 318 | } else if (name.equals("Powered")) { |
| 319 | // bluetoothd has restarted, re-read all our properties. |
| 320 | // Note: bluez only sends this property change when it restarts. |
| 321 | if (propValues[1].equals("true")) |
| 322 | onRestartRequired(); |
| 323 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 326 | private void onDevicePropertyChanged(String deviceObjectPath, String[] propValues) { |
| 327 | String name = propValues[0]; |
| 328 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 329 | if (address == null) { |
| 330 | Log.e(TAG, "onDevicePropertyChanged: Address of the remote device in null"); |
| 331 | return; |
| 332 | } |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame^] | 333 | if (DBG) { |
| 334 | log("Device property changed:" + address + "property:" + name); |
| 335 | } |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 336 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 337 | if (name.equals("Name")) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 338 | Intent intent = new Intent(BluetoothDevice.ACTION_NAME_CHANGED); |
| 339 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); |
| 340 | intent.putExtra(BluetoothDevice.EXTRA_NAME, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 341 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 342 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
| 343 | } else if (name.equals("Class")) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 344 | Intent intent = new Intent(BluetoothDevice.ACTION_CLASS_CHANGED); |
| 345 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); |
| 346 | intent.putExtra(BluetoothDevice.EXTRA_CLASS, |
| 347 | new BluetoothClass(Integer.valueOf(propValues[1]))); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 348 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 349 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
| 350 | } else if (name.equals("Connected")) { |
| 351 | Intent intent = null; |
| 352 | if (propValues[1].equals("true")) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 353 | intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 354 | } else { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 355 | intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 356 | } |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 357 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 358 | mContext.sendBroadcast(intent, BLUETOOTH_PERM); |
| 359 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
| 360 | } else if (name.equals("UUIDs")) { |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 361 | String uuid = null; |
| 362 | int len = Integer.valueOf(propValues[1]); |
| 363 | if (len > 0) { |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 364 | StringBuilder str = new StringBuilder(); |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 365 | for (int i = 2; i < propValues.length; i++) { |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 366 | str.append(propValues[i]); |
| 367 | str.append(","); |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 368 | } |
Jaikumar Ganesh | efa3367 | 2009-08-28 13:48:55 -0700 | [diff] [blame] | 369 | uuid = str.toString(); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 370 | } |
Jaikumar Ganesh | 8bc8ce4 | 2009-06-24 16:42:51 -0700 | [diff] [blame] | 371 | mBluetoothService.setRemoteDeviceProperty(address, name, uuid); |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame^] | 372 | mBluetoothService.sendUuidIntent(address); |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 373 | } else if (name.equals("Paired")) { |
| 374 | if (propValues[1].equals("true")) { |
| 375 | mBluetoothService.getBondState().setBondState(address, BluetoothDevice.BOND_BONDED); |
| 376 | } else { |
| 377 | mBluetoothService.getBondState().setBondState(address, |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 378 | BluetoothDevice.BOND_NONE); |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 379 | mBluetoothService.setRemoteDeviceProperty(address, "Trusted", "false"); |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 380 | } |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 381 | } else if (name.equals("Trusted")) { |
| 382 | if (DBG) |
| 383 | log("set trust state succeded, value is " + propValues[1]); |
| 384 | mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 385 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 388 | private String checkPairingRequestAndGetAddress(String objectPath, int nativeData) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 389 | String address = mBluetoothService.getAddressFromObjectPath(objectPath); |
| 390 | if (address == null) { |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 391 | Log.e(TAG, "Unable to get device address in checkPairingRequestAndGetAddress, " + |
| 392 | "returning null"); |
| 393 | return null; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 394 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | address = address.toUpperCase(); |
| 396 | mPasskeyAgentRequestData.put(address, new Integer(nativeData)); |
| 397 | |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 398 | if (mBluetoothService.getBluetoothState() == BluetoothAdapter.STATE_TURNING_OFF) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 399 | // shutdown path |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 400 | mBluetoothService.cancelPairingUserInput(address); |
| 401 | return null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 402 | } |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 403 | return address; |
| 404 | } |
| 405 | |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 406 | private void onRequestPairingConsent(String objectPath, int nativeData) { |
| 407 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 408 | if (address == null) return; |
| 409 | |
| 410 | /* The link key will not be stored if the incoming request has MITM |
| 411 | * protection switched on. Unfortunately, some devices have MITM |
| 412 | * switched on even though their capabilities are NoInputNoOutput, |
| 413 | * so we may get this request many times. Also if we respond immediately, |
| 414 | * the other end is unable to handle it. Delay sending the message. |
| 415 | */ |
| 416 | if (mBluetoothService.getBondState().getBondState(address) == BluetoothDevice.BOND_BONDED) { |
| 417 | Message message = mHandler.obtainMessage(EVENT_PAIRING_CONSENT_DELAYED_ACCEPT); |
| 418 | message.obj = address; |
| 419 | mHandler.sendMessageDelayed(message, 1500); |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 424 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 425 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
| 426 | BluetoothDevice.PAIRING_VARIANT_CONSENT); |
| 427 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | private void onRequestPasskeyConfirmation(String objectPath, int passkey, int nativeData) { |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 432 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 433 | if (address == null) return; |
| 434 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 435 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 436 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 437 | intent.putExtra(BluetoothDevice.EXTRA_PASSKEY, passkey); |
| 438 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 439 | BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 440 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | private void onRequestPasskey(String objectPath, int nativeData) { |
| 445 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 446 | if (address == null) return; |
| 447 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 448 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 449 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 450 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
| 451 | BluetoothDevice.PAIRING_VARIANT_PASSKEY); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 452 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | private void onRequestPinCode(String objectPath, int nativeData) { |
| 457 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 458 | if (address == null) return; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | if (mBluetoothService.getBondState().getBondState(address) == |
| 461 | BluetoothDevice.BOND_BONDING) { |
| 462 | // we initiated the bonding |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 463 | BluetoothClass btClass = new BluetoothClass(mBluetoothService.getRemoteClass(address)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | |
| 465 | // try 0000 once if the device looks dumb |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 466 | switch (btClass.getDeviceClass()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET: |
| 468 | case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE: |
| 469 | case BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES: |
| 470 | case BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO: |
| 471 | case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO: |
| 472 | case BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO: |
| 473 | if (!mBluetoothService.getBondState().hasAutoPairingFailed(address) && |
| 474 | !mBluetoothService.getBondState().isAutoPairingBlacklisted(address)) { |
| 475 | mBluetoothService.getBondState().attempt(address); |
| 476 | mBluetoothService.setPin(address, BluetoothDevice.convertPinToBytes("0000")); |
| 477 | return; |
| 478 | } |
| 479 | } |
| 480 | } |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 481 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 482 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 483 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PIN); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 485 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 488 | private void onDisplayPasskey(String objectPath, int passkey, int nativeData) { |
| 489 | String address = checkPairingRequestAndGetAddress(objectPath, nativeData); |
| 490 | if (address == null) return; |
| 491 | |
| 492 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); |
| 493 | intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address)); |
| 494 | intent.putExtra(BluetoothDevice.EXTRA_PASSKEY, passkey); |
| 495 | intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, |
| 496 | BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY); |
| 497 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
| 498 | } |
| 499 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 500 | private boolean onAgentAuthorize(String objectPath, String deviceUuid) { |
| 501 | String address = mBluetoothService.getAddressFromObjectPath(objectPath); |
| 502 | if (address == null) { |
| 503 | Log.e(TAG, "Unable to get device address in onAuthAgentAuthorize"); |
| 504 | return false; |
| 505 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | boolean authorized = false; |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 508 | ParcelUuid uuid = ParcelUuid.fromString(deviceUuid); |
Nick Pelly | b23d445 | 2009-08-26 09:33:40 -0700 | [diff] [blame] | 509 | // Bluez sends the UUID of the local service being accessed, _not_ the |
| 510 | // remote service |
Jaikumar Ganesh | ade4052 | 2009-07-30 13:32:25 -0700 | [diff] [blame] | 511 | if (mBluetoothService.isEnabled() && |
Nick Pelly | b23d445 | 2009-08-26 09:33:40 -0700 | [diff] [blame] | 512 | (BluetoothUuid.isAudioSource(uuid) || BluetoothUuid.isAvrcpTarget(uuid) |
Jaikumar Ganesh | 9488cbd | 2009-08-03 17:17:37 -0700 | [diff] [blame] | 513 | || BluetoothUuid.isAdvAudioDist(uuid))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | BluetoothA2dp a2dp = new BluetoothA2dp(mContext); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 515 | BluetoothDevice device = mAdapter.getRemoteDevice(address); |
| 516 | authorized = a2dp.getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | if (authorized) { |
Jaikumar Ganesh | ade4052 | 2009-07-30 13:32:25 -0700 | [diff] [blame] | 518 | Log.i(TAG, "Allowing incoming A2DP / AVRCP connection from " + address); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | } else { |
Jaikumar Ganesh | ade4052 | 2009-07-30 13:32:25 -0700 | [diff] [blame] | 520 | Log.i(TAG, "Rejecting incoming A2DP / AVRCP connection from " + address); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | } |
| 522 | } else { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 523 | Log.i(TAG, "Rejecting incoming " + deviceUuid + " connection from " + address); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | } |
Nick Pelly | b23d445 | 2009-08-26 09:33:40 -0700 | [diff] [blame] | 525 | log("onAgentAuthorize(" + objectPath + ", " + deviceUuid + ") = " + authorized); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | return authorized; |
| 527 | } |
| 528 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 529 | private void onAgentCancel() { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 530 | Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_CANCEL); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 531 | mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); |
| 532 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame^] | 535 | private void onDiscoverServicesResult(String deviceObjectPath, boolean result) { |
| 536 | String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath); |
| 537 | // We don't parse the xml here, instead just query Bluez for the properties. |
| 538 | if (result) { |
| 539 | String[] properties = mBluetoothService.getRemoteDeviceProperties(address); |
| 540 | mBluetoothService.addRemoteDeviceProperties(address, properties); |
| 541 | } |
| 542 | mBluetoothService.sendUuidIntent(address); |
| 543 | } |
| 544 | |
| 545 | private void onCreateDeviceResult(String address, boolean result) { |
| 546 | if (DBG) { |
| 547 | log("Result of onCreateDeviceResult:" + result); |
| 548 | } |
| 549 | if (!result) { |
| 550 | mBluetoothService.sendUuidIntent(address); |
| 551 | } |
| 552 | } |
| 553 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 554 | private void onRestartRequired() { |
| 555 | if (mBluetoothService.isEnabled()) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 556 | Log.e(TAG, "*** A serious error occured (did bluetoothd crash?) - " + |
| 557 | "restarting Bluetooth ***"); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 558 | mHandler.sendEmptyMessage(EVENT_RESTART_BLUETOOTH); |
| 559 | } |
| 560 | } |
| 561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | private static void log(String msg) { |
| 563 | Log.d(TAG, msg); |
| 564 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 565 | |
| 566 | private native void initializeNativeDataNative(); |
| 567 | private native void startEventLoopNative(); |
| 568 | private native void stopEventLoopNative(); |
| 569 | private native boolean isEventLoopRunningNative(); |
| 570 | private native void cleanupNativeDataNative(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | } |