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

Commit 447cbe9d authored by Eric Laurent's avatar Eric Laurent Committed by Automerger Merge Worker
Browse files

Merge "AudioService: add mute delay for Bluetooth codec switch" into 24D1-dev am: 8ba80187

parents dbb601a7 8ba80187
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1772,6 +1772,7 @@ public class AudioDeviceBroker {

        @Override
        public void handleMessage(Message msg) {
            int muteCheckDelayMs = BTA2DP_MUTE_CHECK_DELAY_MS;
            switch (msg.what) {
                case MSG_RESTORE_DEVICES:
                    synchronized (mSetModeLock) {
@@ -1870,7 +1871,7 @@ public class AudioDeviceBroker {
                            btInfo.mDevice, btInfo.mProfile, btInfo.mIsLeOutput,
                            "MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE");
                    synchronized (mDeviceStateLock) {
                        mDeviceInventory.onBluetoothDeviceConfigChange(btInfo,
                        muteCheckDelayMs += mDeviceInventory.onBluetoothDeviceConfigChange(btInfo,
                                codecAndChanged.first, codecAndChanged.second,
                                BtHelper.EVENT_DEVICE_CONFIG_CHANGE);
                    }
@@ -2060,7 +2061,7 @@ public class AudioDeviceBroker {
            // Give some time to Bluetooth service to post a connection message
            // in case of active device switch
            if (MESSAGES_MUTE_MUSIC.contains(msg.what)) {
                sendMsg(MSG_CHECK_MUTE_MUSIC, SENDMSG_REPLACE, BTA2DP_MUTE_CHECK_DELAY_MS);
                sendMsg(MSG_CHECK_MUTE_MUSIC, SENDMSG_REPLACE, muteCheckDelayMs);
            }

            if (isMessageHandledUnderWakelock(msg.what)) {
+23 −5
Original line number Diff line number Diff line
@@ -864,9 +864,25 @@ public class AudioDeviceInventory {
        }
    }

    // Additional delay added to the music mute duration when a codec config change is executed.
    static final int BT_CONFIG_CHANGE_MUTE_DELAY_MS = 500;

    /**
     * Handles a Bluetooth link codec configuration change communicated by the Bluetooth stack.
     * Called when either A2DP or LE Audio codec encoding or sampling rate changes:
     * the change is communicated to native audio policy to eventually reconfigure the audio
     * path.
     * Also used to notify a change in preferred mode (duplex or output) for Bluetooth profiles.
     *
     * @param btInfo contains all information on the Bluetooth device and profile
     * @param codec the requested audio encoding (e.g SBC)
     * @param codecChanged true if a codec parameter changed, false for preferred mode change
     * @param event currently only EVENT_DEVICE_CONFIG_CHANGE
     * @return an optional additional delay in milliseconds to add to the music mute period in
     * case of an actual codec reconfiguration.
     */
    @GuardedBy("mDeviceBroker.mDeviceStateLock")
    /*package*/ void onBluetoothDeviceConfigChange(
    /*package*/ int onBluetoothDeviceConfigChange(
            @NonNull AudioDeviceBroker.BtDeviceInfo btInfo,
            @AudioSystem.AudioFormatNativeEnumForBtCodec int codec,
            boolean codecChanged, int event) {
@@ -874,10 +890,11 @@ public class AudioDeviceInventory {
                + "onBluetoothDeviceConfigChange")
                .set(MediaMetrics.Property.EVENT, BtHelper.deviceEventToString(event));

        int delayMs = 0;
        final BluetoothDevice btDevice = btInfo.mDevice;
        if (btDevice == null) {
            mmi.set(MediaMetrics.Property.EARLY_RETURN, "btDevice null").record();
            return;
            return delayMs;
        }
        if (AudioService.DEBUG_DEVICES) {
            Log.d(TAG, "onBluetoothDeviceConfigChange btDevice=" + btDevice);
@@ -899,7 +916,7 @@ public class AudioDeviceInventory {
                        .printSlog(EventLogger.Event.ALOGI, TAG));
                mmi.set(MediaMetrics.Property.EARLY_RETURN, "A2dp config change ignored")
                        .record();
                return;
                return delayMs;
            }
            final String key = DeviceInfo.makeDeviceListKey(
                    AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, address);
@@ -907,7 +924,7 @@ public class AudioDeviceInventory {
            if (di == null) {
                Log.e(TAG, "invalid null DeviceInfo in onBluetoothDeviceConfigChange");
                mmi.set(MediaMetrics.Property.EARLY_RETURN, "null DeviceInfo").record();
                return;
                return delayMs;
            }

            mmi.set(MediaMetrics.Property.ADDRESS, address)
@@ -915,7 +932,6 @@ public class AudioDeviceInventory {
                    .set(MediaMetrics.Property.INDEX, volume)
                    .set(MediaMetrics.Property.NAME, di.mDeviceName);


            if (event == BtHelper.EVENT_DEVICE_CONFIG_CHANGE) {
                if (btInfo.mProfile == BluetoothProfile.A2DP
                        || btInfo.mProfile == BluetoothProfile.LE_AUDIO
@@ -943,6 +959,7 @@ public class AudioDeviceInventory {
                                            + address
                                            + " codec=" + AudioSystem.audioFormatToString(codec))
                                    .printSlog(EventLogger.Event.ALOGI, TAG));
                            delayMs = BT_CONFIG_CHANGE_MUTE_DELAY_MS;
                        }
                    }
                }
@@ -952,6 +969,7 @@ public class AudioDeviceInventory {
            }
        }
        mmi.record();
        return delayMs;
    }

    /*package*/ void onMakeA2dpDeviceUnavailableNow(String address, int a2dpCodec) {