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

Commit 8e5e69ab authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge changes Iacd348b6,Id8b8a793 into main

* changes:
  Reapply "AudioService: synchronize audio mode and focus for Telecom"
  Revert "AudioService: synchronize audio mode and focus for Telecom"
parents 79a64478 94a9fc58
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -693,6 +693,8 @@ public class AudioDeviceBroker {
                elapsed = System.currentTimeMillis() - start;
                if (elapsed >= SET_COMMUNICATION_DEVICE_TIMEOUT_MS) {
                    Log.e(TAG, "Timeout waiting for communication device update.");
                    // reset counter to avoid sticky out of sync condition
                    mCommunicationDeviceUpdateCount = 0;
                    break;
                }
            }
@@ -1342,8 +1344,8 @@ public class AudioDeviceBroker {
    }

    /*package*/ void postSetModeOwner(int mode, int pid, int uid, boolean signal) {
        sendILMsgNoDelay(MSG_IL_SET_MODE_OWNER, SENDMSG_REPLACE,
                signal ? 1 : 0, new AudioModeInfo(mode, pid, uid));
        sendLMsgNoDelay(signal ? MSG_L_SET_MODE_OWNER_SIGNAL : MSG_L_SET_MODE_OWNER,
                SENDMSG_REPLACE, new AudioModeInfo(mode, pid, uid));
    }

    /*package*/ void postBluetoothDeviceConfigChange(@NonNull BtDeviceInfo info) {
@@ -2026,7 +2028,8 @@ public class AudioDeviceBroker {
                        mBtHelper.setAvrcpAbsoluteVolumeIndex(msg.arg1);
                    }
                    break;
                case MSG_IL_SET_MODE_OWNER:
                case MSG_L_SET_MODE_OWNER:
                case MSG_L_SET_MODE_OWNER_SIGNAL:
                    synchronized (mSetModeLock) {
                        synchronized (mDeviceStateLock) {
                            mAudioModeOwner = (AudioModeInfo) msg.obj;
@@ -2037,7 +2040,7 @@ public class AudioDeviceBroker {
                            }
                        }
                    }
                    if (msg.arg1 == 1 /*signal*/) {
                    if (msg.what == MSG_L_SET_MODE_OWNER_SIGNAL) {
                        mAudioService.decrementAudioModeResetCount();
                    }
                    break;
@@ -2199,7 +2202,8 @@ public class AudioDeviceBroker {
    private static final int MSG_REPORT_NEW_ROUTES = 13;
    private static final int MSG_II_SET_HEARING_AID_VOLUME = 14;
    private static final int MSG_I_SET_AVRCP_ABSOLUTE_VOLUME = 15;
    private static final int MSG_IL_SET_MODE_OWNER = 16;
    private static final int MSG_L_SET_MODE_OWNER = 16;
    private static final int MSG_L_SET_MODE_OWNER_SIGNAL = 17;

    private static final int MSG_I_BT_SERVICE_DISCONNECTED_PROFILE = 22;
    private static final int MSG_IL_BT_SERVICE_CONNECTED_PROFILE = 23;
+19 −11
Original line number Diff line number Diff line
@@ -457,7 +457,7 @@ public class AudioService extends IAudioService.Stub
    private static final int MSG_UPDATE_AUDIO_MODE = 36;
    private static final int MSG_RECORDING_CONFIG_CHANGE = 37;
    private static final int MSG_BT_DEV_CHANGED = 38;
    private static final int MSG_UPDATE_AUDIO_MODE_SIGNAL = 39;
    private static final int MSG_DISPATCH_AUDIO_MODE = 40;
    private static final int MSG_ROUTING_UPDATED = 41;
    private static final int MSG_INIT_HEADTRACKING_SENSORS = 42;
@@ -4804,16 +4804,14 @@ public class AudioService extends IAudioService.Stub
    }
    static class UpdateAudioModeInfo {
        UpdateAudioModeInfo(int mode, int pid, String packageName, boolean signal) {
        UpdateAudioModeInfo(int mode, int pid, String packageName) {
            mMode = mode;
            mPid = pid;
            mPackageName = packageName;
            mSignal = signal;
        }
        private final int mMode;
        private final int mPid;
        private final String mPackageName;
        private final boolean mSignal;
        int getMode() {
            return mMode;
@@ -4824,9 +4822,6 @@ public class AudioService extends IAudioService.Stub
        String getPackageName() {
            return mPackageName;
        }
        boolean getSignal() {
            return mSignal;
        }
    }
    void postUpdateAudioMode(int msgPolicy, int mode, int pid, String packageName,
@@ -4835,8 +4830,8 @@ public class AudioService extends IAudioService.Stub
            if (signal) {
                mAudioModeResetCount++;
            }
            sendMsg(mAudioHandler, MSG_UPDATE_AUDIO_MODE, msgPolicy, 0, 0,
                new UpdateAudioModeInfo(mode, pid, packageName, signal), delay);
            sendMsg(mAudioHandler, signal ? MSG_UPDATE_AUDIO_MODE_SIGNAL : MSG_UPDATE_AUDIO_MODE,
                    msgPolicy, 0, 0, new UpdateAudioModeInfo(mode, pid, packageName), delay);
        }
    }
@@ -6654,6 +6649,9 @@ public class AudioService extends IAudioService.Stub
                // connections not started by the application changing the mode when pid changes
                mDeviceBroker.postSetModeOwner(mode, pid, uid, signal);
            } else {
                // reset here to avoid sticky out of sync condition (would have been reset
                // by AudioDeviceBroker processing MSG_L_SET_MODE_OWNER_SIGNAL message)
                resetAudioModeResetCount();
                Log.w(TAG, "onUpdateAudioMode: failed to set audio mode to: " + mode);
            }
        }
@@ -10420,10 +10418,11 @@ public class AudioService extends IAudioService.Stub
                    break;
                case MSG_UPDATE_AUDIO_MODE:
                case MSG_UPDATE_AUDIO_MODE_SIGNAL:
                    synchronized (mDeviceBroker.mSetModeLock) {
                        UpdateAudioModeInfo info = (UpdateAudioModeInfo) msg.obj;
                        onUpdateAudioMode(info.getMode(), info.getPid(), info.getPackageName(),
                                false /*force*/, info.getSignal());
                                false /*force*/, msg.what == MSG_UPDATE_AUDIO_MODE_SIGNAL);
                    }
                    break;
@@ -11164,6 +11163,8 @@ public class AudioService extends IAudioService.Stub
                    elapsed = java.lang.System.currentTimeMillis() - start;
                    if (elapsed >= AUDIO_MODE_RESET_TIMEOUT_MS) {
                        Log.e(TAG, "Timeout waiting for audio mode reset");
                        // reset count to avoid sticky out of sync state.
                        resetAudioModeResetCount();
                        break;
                    }
                }
@@ -11175,7 +11176,7 @@ public class AudioService extends IAudioService.Stub
        return mMediaFocusControl.abandonAudioFocus(fd, clientId, aa, callingPackageName);
    }
    /** synchronization between setMode(NORMAL) and abandonAudioFocus() frmo Telecom */
    /** synchronization between setMode(NORMAL) and abandonAudioFocus() from Telecom */
    private static final long AUDIO_MODE_RESET_TIMEOUT_MS = 3000;
    private final Object mAudioModeResetLock = new Object();
@@ -11194,6 +11195,13 @@ public class AudioService extends IAudioService.Stub
        }
    }
    private void resetAudioModeResetCount() {
        synchronized (mAudioModeResetLock) {
            mAudioModeResetCount = 0;
            mAudioModeResetLock.notify();
        }
    }
    /** see {@link AudioManager#abandonAudioFocusForTest(AudioFocusRequest, String)} */
    public int abandonAudioFocusForTest(IAudioFocusDispatcher fd, String clientId,
            AudioAttributes aa, String callingPackageName) {