summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Eric Laurent <elaurent@google.com> 2014-11-03 18:26:32 -0800
committer Eric Laurent <elaurent@google.com> 2014-11-03 18:26:57 -0800
commitadbe8bf85f3c8230d16ae5cb3f5d9736e09ed84a (patch)
tree7de59ce4c8576bdc252d20e1d31f00f207026f76
parent0c189ca5c4ee8a61c89d437ff22fd2628b353765 (diff)
AudioService: fix wired headset insertion delay.
Do not systematically delay a device connection message by 1 second if another message is still in the queue but calculate delay based on last message insertion time. Bug: 17882912. Change-Id: Id86c338488f41eebfa1dfd926032468be0294cec
-rw-r--r--media/java/android/media/AudioService.java20
1 files changed, 17 insertions, 3 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 6a695170f3c0..e8da80f8e668 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -528,6 +528,8 @@ public class AudioService extends IAudioService.Stub {
private AudioOrientationEventListener mOrientationListener;
+ private static Long mLastDeviceConnectMsgTime = new Long(0);
+
///////////////////////////////////////////////////////////////////////////
// Construction
///////////////////////////////////////////////////////////////////////////
@@ -3259,8 +3261,15 @@ public class AudioService extends IAudioService.Stub {
} else if (existingMsgPolicy == SENDMSG_NOOP && handler.hasMessages(msg)) {
return;
}
-
- handler.sendMessageDelayed(handler.obtainMessage(msg, arg1, arg2, obj), delay);
+ synchronized (mLastDeviceConnectMsgTime) {
+ long time = SystemClock.uptimeMillis() + delay;
+ handler.sendMessageAtTime(handler.obtainMessage(msg, arg1, arg2, obj), time);
+ if (msg == MSG_SET_WIRED_DEVICE_CONNECTION_STATE ||
+ msg == MSG_SET_A2DP_SRC_CONNECTION_STATE ||
+ msg == MSG_SET_A2DP_SINK_CONNECTION_STATE) {
+ mLastDeviceConnectMsgTime = time;
+ }
+ }
}
boolean checkAudioSettingsPermission(String method) {
@@ -4566,7 +4575,12 @@ public class AudioService extends IAudioService.Stub {
if (mAudioHandler.hasMessages(MSG_SET_A2DP_SRC_CONNECTION_STATE) ||
mAudioHandler.hasMessages(MSG_SET_A2DP_SINK_CONNECTION_STATE) ||
mAudioHandler.hasMessages(MSG_SET_WIRED_DEVICE_CONNECTION_STATE)) {
- delay = 1000;
+ synchronized (mLastDeviceConnectMsgTime) {
+ long time = SystemClock.uptimeMillis();
+ if (mLastDeviceConnectMsgTime > time) {
+ delay = (int)(mLastDeviceConnectMsgTime - time);
+ }
+ }
}
return delay;
}