Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adbe8bf8 authored by Eric Laurent's avatar Eric Laurent
Browse files

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
parent 0c189ca5
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -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;
    }