summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jake Hamby <jhamby@google.com> 2011-06-30 19:20:30 -0700
committer Jake Hamby <jhamby@google.com> 2011-06-30 19:40:21 -0700
commit24ca01d262f0e8563b09b3c7b4574a2bb8036f12 (patch)
tree19f152eb41d9b25dc4f32649d8ce0ce2e778d84b
parent9c902c1aa3ecaa7e601aae81ca812743eb6488f3 (diff)
Fix IllegalStateException when A2DP connects before boot completes.
Under some circumstances, the broadcast intent BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED can be sent before the system is ready, triggering an IllegalStateException, "Cannot broadcast before boot completed" and runtime crash. Fixed the race condition by adding the Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT flag to the broadcast intent. All system receivers of this intent are registered with registerReceiver() rather than as components in the manifest, so nothing should change in the event that the A2DP connection state change is broadcast before boot completion. Any apps that define a receiver for either BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED or BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED in their manifest will not receive these broadcasts in the case where they are sent before the system has finished booting. Normally, user applications should not care about these events anyway and should let the audio manager take care of audio routing on their behalf. In the event that an app does care about A2DP state changes, it should either register for these intents with registerReceiver(), or it can add an intent filter for ACTION_BOOT_COMPLETED and test the state of Bluetooth and A2DP at that time. Apps which care about the state of the Bluetooth adapter should do this also, because BluetoothAdapter.ACTION_STATE_CHANGED is already being sent with FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT. Bug: 4982088 Change-Id: I10e55713f9d07d6dc88b4480b45b1aeb3aaf170b
-rw-r--r--core/java/android/server/BluetoothA2dpService.java2
1 files changed, 2 insertions, 0 deletions
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index ca2212cda581..8a6fdb4fb325 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -517,6 +517,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
intent.putExtra(BluetoothProfile.EXTRA_STATE, state);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
if (DBG) log("A2DP state : device: " + device + " State:" + prevState + "->" + state);
@@ -530,6 +531,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
intent.putExtra(BluetoothProfile.EXTRA_STATE, state);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
if (DBG) log("A2DP Playing state : device: " + device + " State:" + prevState + "->" + state);