blob: d98277703d0e1aea3367757dc19d99591f84783a [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.server;
18
19import android.bluetooth.BluetoothA2dp;
20import android.bluetooth.BluetoothClass;
21import android.bluetooth.BluetoothDevice;
22import android.bluetooth.BluetoothError;
23import android.bluetooth.BluetoothIntent;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -070024import android.bluetooth.BluetoothUuid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.Context;
26import android.content.Intent;
27import android.os.Handler;
28import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.util.Log;
30
31import java.util.HashMap;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -070032import java.util.UUID;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34/**
35 * TODO: Move this to
36 * java/services/com/android/server/BluetoothEventLoop.java
37 * and make the contructor package private again.
38 *
39 * @hide
40 */
41class BluetoothEventLoop {
42 private static final String TAG = "BluetoothEventLoop";
43 private static final boolean DBG = false;
44
45 private int mNativeData;
46 private Thread mThread;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070047 private boolean mStarted;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 private boolean mInterrupted;
The Android Open Source Project10592532009-03-18 17:39:46 -070049 private final HashMap<String, Integer> mPasskeyAgentRequestData;
The Android Open Source Project10592532009-03-18 17:39:46 -070050 private final BluetoothDeviceService mBluetoothService;
51 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53 private static final int EVENT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY = 1;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070054 private static final int EVENT_RESTART_BLUETOOTH = 2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
56 // The time (in millisecs) to delay the pairing attempt after the first
57 // auto pairing attempt fails. We use an exponential delay with
58 // INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY as the initial value and
59 // MAX_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY as the max value.
60 private static final long INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY = 3000;
61 private static final long MAX_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY = 12000;
62
63 private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN;
64 private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
65
66 private final Handler mHandler = new Handler() {
67 @Override
68 public void handleMessage(Message msg) {
69 switch (msg.what) {
70 case EVENT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY:
71 String address = (String)msg.obj;
72 if (address != null) {
73 mBluetoothService.createBond(address);
74 return;
75 }
76 break;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070077 case EVENT_RESTART_BLUETOOTH:
Nick Pelly37b5a102009-03-24 20:46:18 -070078 mBluetoothService.restart();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070079 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 }
81 }
82 };
83
84 static { classInitNative(); }
85 private static native void classInitNative();
86
87 /* pacakge */ BluetoothEventLoop(Context context, BluetoothDeviceService bluetoothService) {
88 mBluetoothService = bluetoothService;
89 mContext = context;
90 mPasskeyAgentRequestData = new HashMap();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 initializeNativeDataNative();
92 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
94 protected void finalize() throws Throwable {
95 try {
96 cleanupNativeDataNative();
97 } finally {
98 super.finalize();
99 }
100 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700102 /* package */ HashMap<String, Integer> getPasskeyAgentRequestData() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 return mPasskeyAgentRequestData;
104 }
105
Robert Greenwalt28d139f2009-04-02 22:41:08 -0700106 /* package */ void start() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107
Robert Greenwalt28d139f2009-04-02 22:41:08 -0700108 if (!isEventLoopRunningNative()) {
109 if (DBG) log("Starting Event Loop thread");
110 startEventLoopNative();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 }
112 }
113
Robert Greenwalt28d139f2009-04-02 22:41:08 -0700114 public void stop() {
115 if (isEventLoopRunningNative()) {
116 if (DBG) log("Stopping Event Loop thread");
117 stopEventLoopNative();
118 }
119 }
120
121 public boolean isEventLoopRunning() {
122 return isEventLoopRunningNative();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 }
124
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700125 private void onDeviceFound(String address, String[] properties) {
126 if (properties == null) {
127 Log.e(TAG, "ERROR: Remote device properties are null");
128 return;
129 }
130 mBluetoothService.addRemoteDeviceProperties(address, properties);
131 String rssi = mBluetoothService.getRemoteDeviceProperty(address, "RSSI");
132 String classValue = mBluetoothService.getRemoteDeviceProperty(address, "Class");
Jaikumar Ganesh395d1022009-06-19 16:12:31 -0700133 String name = mBluetoothService.getRemoteDeviceProperty(address, "Name");
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700134
135 if (rssi != null && classValue != null) {
136 Intent intent = new Intent(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION);
137 intent.putExtra(BluetoothIntent.ADDRESS, address);
Jaikumar Ganesh395d1022009-06-19 16:12:31 -0700138 intent.putExtra(BluetoothIntent.CLASS, Integer.valueOf(classValue));
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700139 intent.putExtra(BluetoothIntent.RSSI, (short)Integer.valueOf(rssi).intValue());
Jaikumar Ganesh395d1022009-06-19 16:12:31 -0700140 intent.putExtra(BluetoothIntent.NAME, name);
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700143 } else {
144 log ("RSSI: " + rssi + " or ClassValue: " + classValue +
145 " for remote device: " + address + " is null");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 }
147 }
148
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700149 private void onDeviceDisappeared(String address) {
150 mBluetoothService.removeRemoteDeviceProperties(address);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 Intent intent = new Intent(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION);
153 intent.putExtra(BluetoothIntent.ADDRESS, address);
154 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700157 private void onCreatePairedDeviceResult(String address, int result) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 address = address.toUpperCase();
159 if (result == BluetoothError.SUCCESS) {
160 mBluetoothService.getBondState().setBondState(address, BluetoothDevice.BOND_BONDED);
161 if (mBluetoothService.getBondState().isAutoPairingAttemptsInProgress(address)) {
162 mBluetoothService.getBondState().clearPinAttempts(address);
163 }
164 } else if (result == BluetoothDevice.UNBOND_REASON_AUTH_FAILED &&
165 mBluetoothService.getBondState().getAttempt(address) == 1) {
166 mBluetoothService.getBondState().addAutoPairingFailure(address);
167 pairingAttempt(address, result);
168 } else if (result == BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN &&
169 mBluetoothService.getBondState().isAutoPairingAttemptsInProgress(address)) {
170 pairingAttempt(address, result);
171 } else {
172 mBluetoothService.getBondState().setBondState(address,
173 BluetoothDevice.BOND_NOT_BONDED, result);
174 if (mBluetoothService.getBondState().isAutoPairingAttemptsInProgress(address)) {
175 mBluetoothService.getBondState().clearPinAttempts(address);
176 }
177 }
178 }
179
180 private void pairingAttempt(String address, int result) {
181 // This happens when our initial guess of "0000" as the pass key
182 // fails. Try to create the bond again and display the pin dialog
183 // to the user. Use back-off while posting the delayed
184 // message. The initial value is
185 // INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY and the max value is
186 // MAX_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY. If the max value is
187 // reached, display an error to the user.
188 int attempt = mBluetoothService.getBondState().getAttempt(address);
189 if (attempt * INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY >
190 MAX_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY) {
191 mBluetoothService.getBondState().clearPinAttempts(address);
192 mBluetoothService.getBondState().setBondState(address,
193 BluetoothDevice.BOND_NOT_BONDED, result);
194 return;
195 }
196
197 Message message = mHandler.obtainMessage(EVENT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY);
198 message.obj = address;
199 boolean postResult = mHandler.sendMessageDelayed(message,
200 attempt * INIT_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY);
201 if (!postResult) {
202 mBluetoothService.getBondState().clearPinAttempts(address);
203 mBluetoothService.getBondState().setBondState(address,
204 BluetoothDevice.BOND_NOT_BONDED, result);
205 return;
206 }
207 mBluetoothService.getBondState().attempt(address);
208 }
209
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700210 private void onDeviceCreated(String deviceObjectPath) {
211 // do nothing.
212 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 }
214
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700215 private void onDeviceRemoved(String deviceObjectPath) {
216 String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath);
217 if (address != null)
218 mBluetoothService.getBondState().setBondState(address.toUpperCase(),
219 BluetoothDevice.BOND_NOT_BONDED, BluetoothDevice.UNBOND_REASON_REMOVED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 }
221
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700222 /*package*/ void onPropertyChanged(String[] propValues) {
223 String name = propValues[0];
224 if (name.equals("Name")) {
225 Intent intent = new Intent(BluetoothIntent.NAME_CHANGED_ACTION);
226 intent.putExtra(BluetoothIntent.NAME, propValues[1]);
227 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
228 mBluetoothService.setProperty(name, propValues[1]);
229 } else if (name.equals("Pairable") || name.equals("Discoverable")) {
230 String pairable = name.equals("Pairable") ? propValues[1] :
231 mBluetoothService.getProperty("Pairable");
232 String discoverable = name.equals("Discoverable") ? propValues[1] :
233 mBluetoothService.getProperty("Discoverable");
234
235 // This shouldn't happen, unless Adapter Properties are null.
236 if (pairable == null || discoverable == null)
237 return;
238
239 int mode = BluetoothDeviceService.bluezStringToScanMode(
240 pairable.equals("true"),
241 discoverable.equals("true"));
242 if (mode >= 0) {
243 Intent intent = new Intent(BluetoothIntent.SCAN_MODE_CHANGED_ACTION);
244 intent.putExtra(BluetoothIntent.SCAN_MODE, mode);
245 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
246 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
247 }
248 mBluetoothService.setProperty(name, propValues[1]);
249 } else if (name.equals("Discovering")) {
250 Intent intent;
251 if (propValues[1].equals("true")) {
252 mBluetoothService.setIsDiscovering(true);
253 intent = new Intent(BluetoothIntent.DISCOVERY_STARTED_ACTION);
254 } else {
255 // Stop the discovery.
256 mBluetoothService.cancelDiscovery();
257 mBluetoothService.setIsDiscovering(false);
258 intent = new Intent(BluetoothIntent.DISCOVERY_COMPLETED_ACTION);
259 }
260 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
261 mBluetoothService.setProperty(name, propValues[1]);
262 } else if (name.equals("Devices")) {
Jaikumar Ganesh8bc8ce42009-06-24 16:42:51 -0700263 String value = null;
264 int len = Integer.valueOf(propValues[1]);
265 if (len > 0) {
266 value = "";
267 for (int i = 2; i < propValues.length; i++) {
268 value = value + propValues[i] + ',';
269 }
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700270 }
Jaikumar Ganesh8bc8ce42009-06-24 16:42:51 -0700271 mBluetoothService.setProperty(name, value);
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700272 } else if (name.equals("Powered")) {
273 // bluetoothd has restarted, re-read all our properties.
274 // Note: bluez only sends this property change when it restarts.
275 if (propValues[1].equals("true"))
276 onRestartRequired();
277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 }
279
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700280 private void onDevicePropertyChanged(String deviceObjectPath, String[] propValues) {
281 String name = propValues[0];
282 String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath);
283 if (address == null) {
284 Log.e(TAG, "onDevicePropertyChanged: Address of the remote device in null");
285 return;
286 }
287 if (name.equals("Name")) {
288 Intent intent = new Intent(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION);
289 intent.putExtra(BluetoothIntent.ADDRESS, address);
290 intent.putExtra(BluetoothIntent.NAME, propValues[1]);
291 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
292 mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
293 } else if (name.equals("Class")) {
294 Intent intent = new Intent(BluetoothIntent.REMOTE_DEVICE_CLASS_UPDATED_ACTION);
295 intent.putExtra(BluetoothIntent.ADDRESS, address);
296 intent.putExtra(BluetoothIntent.CLASS, propValues[1]);
297 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
298 mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
299 } else if (name.equals("Connected")) {
300 Intent intent = null;
301 if (propValues[1].equals("true")) {
302 intent = new Intent(BluetoothIntent.REMOTE_DEVICE_CONNECTED_ACTION);
303 } else {
304 intent = new Intent(BluetoothIntent.REMOTE_DEVICE_DISCONNECTED_ACTION);
305 }
306 intent.putExtra(BluetoothIntent.ADDRESS, address);
307 mContext.sendBroadcast(intent, BLUETOOTH_PERM);
308 mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
309 } else if (name.equals("UUIDs")) {
Jaikumar Ganesh8bc8ce42009-06-24 16:42:51 -0700310 String uuid = null;
311 int len = Integer.valueOf(propValues[1]);
312 if (len > 0) {
313 uuid = "";
314 for (int i = 2; i < propValues.length; i++) {
315 uuid = uuid + propValues[i] + ",";
316 }
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700317 }
Jaikumar Ganesh8bc8ce42009-06-24 16:42:51 -0700318 mBluetoothService.setRemoteDeviceProperty(address, name, uuid);
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700319 }
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700320 }
321
Jaikumar Ganeshb0eca412009-07-16 18:26:28 -0700322 private String checkPairingRequestAndGetAddress(String objectPath, int nativeData) {
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700323 String address = mBluetoothService.getAddressFromObjectPath(objectPath);
324 if (address == null) {
Jaikumar Ganeshb0eca412009-07-16 18:26:28 -0700325 Log.e(TAG, "Unable to get device address in checkPairingRequestAndGetAddress, " +
326 "returning null");
327 return null;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 address = address.toUpperCase();
330 mPasskeyAgentRequestData.put(address, new Integer(nativeData));
331
The Android Open Source Project10592532009-03-18 17:39:46 -0700332 if (mBluetoothService.getBluetoothState() == BluetoothDevice.BLUETOOTH_STATE_TURNING_OFF) {
333 // shutdown path
Jaikumar Ganeshb0eca412009-07-16 18:26:28 -0700334 mBluetoothService.cancelPairingUserInput(address);
335 return null;
The Android Open Source Project10592532009-03-18 17:39:46 -0700336 }
Jaikumar Ganeshb0eca412009-07-16 18:26:28 -0700337 return address;
338 }
339
340 private void onRequestConfirmation(String objectPath, int passkey, int nativeData) {
341 String address = checkPairingRequestAndGetAddress(objectPath, nativeData);
342 if (address == null) return;
343
344 Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION);
345 intent.putExtra(BluetoothIntent.ADDRESS, address);
346 intent.putExtra(BluetoothIntent.PASSKEY, passkey);
347 intent.putExtra(BluetoothIntent.PAIRING_VARIANT,
348 BluetoothDevice.PAIRING_VARIANT_CONFIRMATION);
349 mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM);
350 return;
351 }
352
353 private void onRequestPasskey(String objectPath, int nativeData) {
354 String address = checkPairingRequestAndGetAddress(objectPath, nativeData);
355 if (address == null) return;
356
357 Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION);
358 intent.putExtra(BluetoothIntent.ADDRESS, address);
359 intent.putExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PASSKEY);
360 mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM);
361 return;
362 }
363
364 private void onRequestPinCode(String objectPath, int nativeData) {
365 String address = checkPairingRequestAndGetAddress(objectPath, nativeData);
366 if (address == null) return;
The Android Open Source Project10592532009-03-18 17:39:46 -0700367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 if (mBluetoothService.getBondState().getBondState(address) ==
369 BluetoothDevice.BOND_BONDING) {
370 // we initiated the bonding
371 int btClass = mBluetoothService.getRemoteClass(address);
372
373 // try 0000 once if the device looks dumb
374 switch (BluetoothClass.Device.getDevice(btClass)) {
375 case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
376 case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
377 case BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES:
378 case BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO:
379 case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
380 case BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO:
381 if (!mBluetoothService.getBondState().hasAutoPairingFailed(address) &&
382 !mBluetoothService.getBondState().isAutoPairingBlacklisted(address)) {
383 mBluetoothService.getBondState().attempt(address);
384 mBluetoothService.setPin(address, BluetoothDevice.convertPinToBytes("0000"));
385 return;
386 }
387 }
388 }
389 Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION);
390 intent.putExtra(BluetoothIntent.ADDRESS, address);
Jaikumar Ganeshb0eca412009-07-16 18:26:28 -0700391 intent.putExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PIN);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM);
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700393 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 }
395
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700396 private boolean onAgentAuthorize(String objectPath, String deviceUuid) {
397 String address = mBluetoothService.getAddressFromObjectPath(objectPath);
398 if (address == null) {
399 Log.e(TAG, "Unable to get device address in onAuthAgentAuthorize");
400 return false;
401 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 boolean authorized = false;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700404 UUID uuid = UUID.fromString(deviceUuid);
Jaikumar Ganeshade40522009-07-30 13:32:25 -0700405 if (mBluetoothService.isEnabled() &&
406 (BluetoothUuid.isAudioSink(uuid) || BluetoothUuid.isAvrcpController(uuid))) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 BluetoothA2dp a2dp = new BluetoothA2dp(mContext);
408 authorized = a2dp.getSinkPriority(address) > BluetoothA2dp.PRIORITY_OFF;
409 if (authorized) {
Jaikumar Ganeshade40522009-07-30 13:32:25 -0700410 Log.i(TAG, "Allowing incoming A2DP / AVRCP connection from " + address);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 } else {
Jaikumar Ganeshade40522009-07-30 13:32:25 -0700412 Log.i(TAG, "Rejecting incoming A2DP / AVRCP connection from " + address);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
414 } else {
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700415 Log.i(TAG, "Rejecting incoming " + deviceUuid + " connection from " + address);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 }
417 return authorized;
418 }
419
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700420 private void onAgentCancel() {
Jaikumar Ganeshb0eca412009-07-16 18:26:28 -0700421 Intent intent = new Intent(BluetoothIntent.PAIRING_CANCEL_ACTION);
422 mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM);
423 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 }
425
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700426 private void onRestartRequired() {
427 if (mBluetoothService.isEnabled()) {
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700428 Log.e(TAG, "*** A serious error occured (did bluetoothd crash?) - " +
429 "restarting Bluetooth ***");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700430 mHandler.sendEmptyMessage(EVENT_RESTART_BLUETOOTH);
431 }
432 }
433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 private static void log(String msg) {
435 Log.d(TAG, msg);
436 }
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700437
438 private native void initializeNativeDataNative();
439 private native void startEventLoopNative();
440 private native void stopEventLoopNative();
441 private native boolean isEventLoopRunningNative();
442 private native void cleanupNativeDataNative();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443}