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
This commit is contained in:
Eric Laurent
2014-11-03 18:26:32 -08:00
parent 0c189ca5c4
commit adbe8bf85f

View File

@@ -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;
}