summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2010-01-22 07:50:58 -0800
committerEric Laurent <elaurent@google.com>2010-01-22 09:31:12 -0800
commit700aab67eb286b44663f885325f8db6b049cb638 (patch)
treecd2fb91856bda162bfa1c30dfe5035198c3e7d89
parent9a400fa4d3e89a3ab3669c0aa2ef6676020646d1 (diff)
downloadbase-700aab67eb286b44663f885325f8db6b049cb638.tar.gz
Fix issue 2388215: Audio not routed to 3.5mm Headset after removal/insertion.
The problem occurs if the delay between the headset removal and insertion is less than one second. In this case, as the headset disconnection intent is broadcast with a 1 second delay to allow music to pause before updating the route, the connection intent is broadcast before and is ignored, leaving the system in a state where the headset is considered disconnected. The fix consists in inserting a delay before broadcasting the connection intent if a disconnection intent is pending broadcast.
-rw-r--r--services/java/com/android/server/HeadsetObserver.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/services/java/com/android/server/HeadsetObserver.java b/services/java/com/android/server/HeadsetObserver.java
index a935131bd8c2..9d695649a60c 100644
--- a/services/java/com/android/server/HeadsetObserver.java
+++ b/services/java/com/android/server/HeadsetObserver.java
@@ -103,6 +103,7 @@ class HeadsetObserver extends UEventObserver {
// Retain only relevant bits
int headsetState = newState & SUPPORTED_HEADSETS;
int newOrOld = headsetState | mHeadsetState;
+ int delay = 0;
// reject all suspect transitions: only accept state changes from:
// - a: 0 heaset to 1 headset
// - b: 1 headset to 0 headset
@@ -117,21 +118,25 @@ class HeadsetObserver extends UEventObserver {
if (headsetState == 0) {
Intent intent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
mContext.sendBroadcast(intent);
-
// It can take hundreds of ms flush the audio pipeline after
// apps pause audio playback, but audio route changes are
// immediate, so delay the route change by 1000ms.
// This could be improved once the audio sub-system provides an
// interface to clear the audio pipeline.
- mWakeLock.acquire();
- mHandler.sendMessageDelayed(mHandler.obtainMessage(0,
- mHeadsetState,
- mPrevHeadsetState,
- mHeadsetName),
- 1000);
+ delay = 1000;
} else {
- sendIntents(mHeadsetState, mPrevHeadsetState, mHeadsetName);
+ // Insert the same delay for headset connection so that the connection event is not
+ // broadcast before the disconnection event in case of fast removal/insertion
+ if (mHandler.hasMessages(0)) {
+ delay = 1000;
+ }
}
+ mWakeLock.acquire();
+ mHandler.sendMessageDelayed(mHandler.obtainMessage(0,
+ mHeadsetState,
+ mPrevHeadsetState,
+ mHeadsetName),
+ delay);
}
private synchronized final void sendIntents(int headsetState, int prevHeadsetState, String headsetName) {