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

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

Merge "AudioService: fix LE Audio volume update after calls" into main

parents 4a506560 c1a88e0b
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -461,6 +461,7 @@ public class AudioService extends IAudioService.Stub
    private static final int MSG_DISPATCH_PREFERRED_MIXER_ATTRIBUTES = 52;
    private static final int MSG_CONFIGURATION_CHANGED = 54;
    private static final int MSG_BROADCAST_MASTER_MUTE = 55;
    private static final int MSG_UPDATE_CONTEXTUAL_VOLUMES = 56;
    /**
     * Messages handled by the {@link SoundDoseHelper}, do not exceed
@@ -4466,7 +4467,7 @@ public class AudioService extends IAudioService.Stub
            }
        }
        if (mVoicePlaybackActive.getAndSet(voiceActive) != voiceActive) {
            updateHearingAidVolumeOnVoiceActivityUpdate();
            postUpdateContextualVolumes();
        }
        if (mMediaPlaybackActive.getAndSet(mediaActive) != mediaActive && mediaActive) {
            mSoundDoseHelper.scheduleMusicActiveCheck();
@@ -4604,13 +4605,29 @@ public class AudioService extends IAudioService.Stub
        }
    }
    private void updateHearingAidVolumeOnVoiceActivityUpdate() {
    // delay between audio playback configuration update and checking
    // actual stream activity to take async playback stop into account
    private static final int UPDATE_CONTEXTUAL_VOLUME_DELAY_MS = 500;
    /*package*/ void postUpdateContextualVolumes() {
        sendMsg(mAudioHandler, MSG_UPDATE_CONTEXTUAL_VOLUMES, SENDMSG_REPLACE,
                /*arg1*/ 0, /*arg2*/ 0, TAG, UPDATE_CONTEXTUAL_VOLUME_DELAY_MS);
    }
    private void onUpdateContextualVolumes() {
        final int streamType = getBluetoothContextualVolumeStream();
        final int index = getStreamVolume(streamType);
        sVolumeLogger.enqueue(new VolumeEvent(VolumeEvent.VOL_VOICE_ACTIVITY_HEARING_AID,
                mVoicePlaybackActive.get(), streamType, index));
        mDeviceBroker.postSetHearingAidVolumeIndex(index * 10, streamType);
        final int device = getDeviceForStream(streamType);
        final int index = getStreamVolume(streamType, device);
        if (AudioSystem.isLeAudioDeviceType(device)) {
            mDeviceBroker.postSetLeAudioVolumeIndex(index * 10,
                    mStreamStates[streamType].getMaxIndex(), streamType);
        } else if (device == AudioSystem.DEVICE_OUT_HEARING_AID) {
            mDeviceBroker.postSetHearingAidVolumeIndex(index * 10, streamType);
        }
        sVolumeLogger.enqueue(new VolumeEvent(VolumeEvent.VOL_VOICE_ACTIVITY_CONTEXTUAL_VOLUME,
                mVoicePlaybackActive.get(), streamType, index, device));
    }
    /**
@@ -9812,6 +9829,10 @@ public class AudioService extends IAudioService.Stub
                    onConfigurationChanged();
                    break;
                case MSG_UPDATE_CONTEXTUAL_VOLUMES:
                    onUpdateContextualVolumes();
                    break;
                case MusicFxHelper.MSG_EFFECT_CLIENT_GONE:
                    mMusicFxHelper.handleMessage(msg);
                    break;
+11 −8
Original line number Diff line number Diff line
@@ -227,7 +227,7 @@ public class AudioServiceEvents {
        static final int VOL_SET_HEARING_AID_VOL = 3;
        static final int VOL_SET_AVRCP_VOL = 4;
        static final int VOL_ADJUST_VOL_UID = 5;
        static final int VOL_VOICE_ACTIVITY_HEARING_AID = 6;
        static final int VOL_VOICE_ACTIVITY_CONTEXTUAL_VOLUME = 6;
        static final int VOL_MODE_CHANGE_HEARING_AID = 7;
        static final int VOL_SET_GROUP_VOL = 8;
        static final int VOL_MUTE_STREAM_INT = 9;
@@ -299,14 +299,14 @@ public class AudioServiceEvents {
            logMetricEvent();
        }

        /** used for VOL_VOICE_ACTIVITY_HEARING_AID */
        VolumeEvent(int op, boolean voiceActive, int stream, int index) {
        /** used for VOL_VOICE_ACTIVITY_CONTEXTUAL_VOLUME */
        VolumeEvent(int op, boolean voiceActive, int stream, int index, int device) {
            mOp = op;
            mStream = stream;
            mVal1 = index;
            mVal2 = voiceActive ? 1 : 0;
            // unused
            mVal3 = -1;
            mVal3 = device;
            mCaller = null;
            mGroupName = null;
            logMetricEvent();
@@ -445,14 +445,16 @@ public class AudioServiceEvents {
                            .set(MediaMetrics.Property.INDEX, mVal1)
                            .record();
                    return;
                case VOL_VOICE_ACTIVITY_HEARING_AID:
                case VOL_VOICE_ACTIVITY_CONTEXTUAL_VOLUME:
                    new MediaMetrics.Item(mMetricsId)
                            .set(MediaMetrics.Property.EVENT, "voiceActivityHearingAid")
                            .set(MediaMetrics.Property.EVENT, "voiceActivityContextualVolume")
                            .set(MediaMetrics.Property.INDEX, mVal1)
                            .set(MediaMetrics.Property.STATE,
                                    mVal2 == 1 ? "active" : "inactive")
                            .set(MediaMetrics.Property.STREAM_TYPE,
                                    AudioSystem.streamToString(mStream))
                            .set(MediaMetrics.Property.DEVICE,
                                    AudioSystem.getOutputDeviceName(mVal3))
                            .record();
                    return;
                case VOL_MODE_CHANGE_HEARING_AID:
@@ -538,11 +540,12 @@ public class AudioServiceEvents {
                            .append(" flags:0x").append(Integer.toHexString(mVal2))
                            .append(") from ").append(mCaller)
                            .toString();
                case VOL_VOICE_ACTIVITY_HEARING_AID:
                case VOL_VOICE_ACTIVITY_CONTEXTUAL_VOLUME:
                    return new StringBuilder("Voice activity change (")
                            .append(mVal2 == 1 ? "active" : "inactive")
                            .append(") causes setting HEARING_AID volume to idx:").append(mVal1)
                            .append(") causes setting volume to idx:").append(mVal1)
                            .append(" stream:").append(AudioSystem.streamToString(mStream))
                            .append(" device:").append(AudioSystem.getOutputDeviceName(mVal3))
                            .toString();
                case VOL_MODE_CHANGE_HEARING_AID:
                    return new StringBuilder("setMode(")