OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 Log.e(TAG, "BT SCO connection fails - no headset available"); | 322 Log.e(TAG, "BT SCO connection fails - no headset available"); |
323 return false; | 323 return false; |
324 } | 324 } |
325 // Start BT SCO channel and wait for ACTION_AUDIO_STATE_CHANGED. | 325 // Start BT SCO channel and wait for ACTION_AUDIO_STATE_CHANGED. |
326 Log.d(TAG, "Starting Bluetooth SCO and waits for ACTION_AUDIO_STATE_CHANGED.
.."); | 326 Log.d(TAG, "Starting Bluetooth SCO and waits for ACTION_AUDIO_STATE_CHANGED.
.."); |
327 // The SCO connection establishment can take several seconds, hence we canno
t rely on the | 327 // The SCO connection establishment can take several seconds, hence we canno
t rely on the |
328 // connection to be available when the method returns but instead register t
o receive the | 328 // connection to be available when the method returns but instead register t
o receive the |
329 // intent ACTION_SCO_AUDIO_STATE_UPDATED and wait for the state to be SCO_AU
DIO_STATE_CONNECTED. | 329 // intent ACTION_SCO_AUDIO_STATE_UPDATED and wait for the state to be SCO_AU
DIO_STATE_CONNECTED. |
330 bluetoothState = State.SCO_CONNECTING; | 330 bluetoothState = State.SCO_CONNECTING; |
331 audioManager.startBluetoothSco(); | 331 audioManager.startBluetoothSco(); |
| 332 audioManager.setBluetoothScoOn(true); |
332 scoConnectionAttempts++; | 333 scoConnectionAttempts++; |
333 startTimer(); | 334 startTimer(); |
334 Log.d(TAG, "startScoAudio done: BT state=" + bluetoothState); | 335 Log.d(TAG, "startScoAudio done: BT state=" + bluetoothState + ", " |
| 336 + "SCO is on: " + isScoOn()); |
335 return true; | 337 return true; |
336 } | 338 } |
337 | 339 |
338 /** Stops Bluetooth SCO connection with remote device. */ | 340 /** Stops Bluetooth SCO connection with remote device. */ |
339 public void stopScoAudio() { | 341 public void stopScoAudio() { |
340 ThreadUtils.checkIsOnMainThread(); | 342 ThreadUtils.checkIsOnMainThread(); |
341 Log.d(TAG, "stopScoAudio: BT state=" + bluetoothState + ", " | 343 Log.d(TAG, "stopScoAudio: BT state=" + bluetoothState + ", " |
342 + "SCO is on: " + isScoOn()); | 344 + "SCO is on: " + isScoOn()); |
343 if (bluetoothState != State.SCO_CONNECTING && bluetoothState != State.SCO_CO
NNECTED) { | 345 if (bluetoothState != State.SCO_CONNECTING && bluetoothState != State.SCO_CO
NNECTED) { |
344 return; | 346 return; |
345 } | 347 } |
346 cancelTimer(); | 348 cancelTimer(); |
347 audioManager.stopBluetoothSco(); | 349 audioManager.stopBluetoothSco(); |
| 350 audioManager.setBluetoothScoOn(false); |
348 bluetoothState = State.SCO_DISCONNECTING; | 351 bluetoothState = State.SCO_DISCONNECTING; |
349 Log.d(TAG, "stopScoAudio done: BT state=" + bluetoothState); | 352 Log.d(TAG, "stopScoAudio done: BT state=" + bluetoothState + ", " |
| 353 + "SCO is on: " + isScoOn()); |
350 } | 354 } |
351 | 355 |
352 /** | 356 /** |
353 * Use the BluetoothHeadset proxy object (controls the Bluetooth Headset | 357 * Use the BluetoothHeadset proxy object (controls the Bluetooth Headset |
354 * Service via IPC) to update the list of connected devices for the HEADSET | 358 * Service via IPC) to update the list of connected devices for the HEADSET |
355 * profile. The internal state will change to HEADSET_UNAVAILABLE or to | 359 * profile. The internal state will change to HEADSET_UNAVAILABLE or to |
356 * HEADSET_AVAILABLE and |bluetoothDevice| will be mapped to the connected | 360 * HEADSET_AVAILABLE and |bluetoothDevice| will be mapped to the connected |
357 * device if available. | 361 * device if available. |
358 */ | 362 */ |
359 public void updateDevice() { | 363 public void updateDevice() { |
360 if (bluetoothState == State.UNINITIALIZED || bluetoothHeadset == null) { | 364 if (bluetoothState == State.UNINITIALIZED || bluetoothHeadset == null) { |
361 return; | 365 return; |
362 } | 366 } |
363 Log.d(TAG, "updateDevice"); | 367 Log.d(TAG, "updateDevice"); |
364 // Get connected devices for the headset profile. Returns the set of | 368 // Get connected devices for the headset profile. Returns the set of |
365 // devices which are in state STATE_CONNECTED. The BluetoothDevice class | 369 // devices which are in state STATE_CONNECTED. The BluetoothDevice class |
366 // is just a thin wrapper for a Bluetooth hardware address. | 370 // is just a thin wrapper for a Bluetooth hardware address. |
367 List<BluetoothDevice> devices = bluetoothHeadset.getConnectedDevices(); | 371 List<BluetoothDevice> devices = bluetoothHeadset.getConnectedDevices(); |
368 if (devices.isEmpty()) { | 372 if (devices.isEmpty()) { |
369 bluetoothDevice = null; | 373 bluetoothDevice = null; |
370 bluetoothState = State.HEADSET_UNAVAILABLE; | 374 bluetoothState = State.HEADSET_UNAVAILABLE; |
371 Log.d(TAG, "No connected bluetooth headset"); | 375 Log.d(TAG, "No connected bluetooth headset"); |
372 } else { | 376 } else { |
373 // Always use first device is list. Android only supports one device. | 377 // Always use first device in list. Android only supports one device. |
374 bluetoothDevice = devices.get(0); | 378 bluetoothDevice = devices.get(0); |
375 bluetoothState = State.HEADSET_AVAILABLE; | 379 bluetoothState = State.HEADSET_AVAILABLE; |
376 Log.d(TAG, "Connected bluetooth headset: " | 380 Log.d(TAG, "Connected bluetooth headset: " |
377 + "name=" + bluetoothDevice.getName() + ", " | 381 + "name=" + bluetoothDevice.getName() + ", " |
378 + "state=" + stateToString(bluetoothHeadset.getConnectionState(blu
etoothDevice)) | 382 + "state=" + stateToString(bluetoothHeadset.getConnectionState(blu
etoothDevice)) |
379 + ", SCO audio=" + bluetoothHeadset.isAudioConnected(bluetoothDevi
ce)); | 383 + ", SCO audio=" + bluetoothHeadset.isAudioConnected(bluetoothDevi
ce)); |
380 } | 384 } |
381 Log.d(TAG, "updateDevice done: BT state=" + bluetoothState); | 385 Log.d(TAG, "updateDevice done: BT state=" + bluetoothState); |
382 } | 386 } |
383 | 387 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 return "TURNING_OFF"; | 515 return "TURNING_OFF"; |
512 case BluetoothAdapter.STATE_TURNING_ON: | 516 case BluetoothAdapter.STATE_TURNING_ON: |
513 // Indicates the local Bluetooth adapter is turning on. However local cl
ients should wait | 517 // Indicates the local Bluetooth adapter is turning on. However local cl
ients should wait |
514 // for STATE_ON before attempting to use the adapter. | 518 // for STATE_ON before attempting to use the adapter. |
515 return "TURNING_ON"; | 519 return "TURNING_ON"; |
516 default: | 520 default: |
517 return "INVALID"; | 521 return "INVALID"; |
518 } | 522 } |
519 } | 523 } |
520 } | 524 } |
OLD | NEW |