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

Commit 50b1abc2 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "renault-non-api-change"

* changes:
  Get volume indexes from Audio Policy Service
  Use AudioProductStrategies within AudioAttributes
parents d711ed30 e220d3b5
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage;
import android.media.audiopolicy.AudioProductStrategies;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
@@ -794,6 +795,13 @@ public final class AudioAttributes implements Parcelable {
         */
        @UnsupportedAppUsage
        public Builder setInternalLegacyStreamType(int streamType) {
            final AudioProductStrategies ps = new AudioProductStrategies();
            if (ps.size() > 0) {
                AudioAttributes attributes = ps.getAudioAttributesForLegacyStreamType(streamType);
                if (attributes != null) {
                    return new Builder(attributes);
                }
            }
            switch(streamType) {
                case AudioSystem.STREAM_VOICE_CALL:
                    mContentType = CONTENT_TYPE_SPEECH;
@@ -1169,6 +1177,10 @@ public final class AudioAttributes implements Parcelable {
                    AudioSystem.STREAM_MUSIC : AudioSystem.STREAM_TTS;
        }

        final AudioProductStrategies ps = new AudioProductStrategies();
        if (ps.size() > 0) {
            return ps.getLegacyStreamTypeForAudioAttributes(aa);
        }
        // usage to stream type mapping
        switch (aa.getUsage()) {
            case USAGE_MEDIA:
+25 −0
Original line number Diff line number Diff line
@@ -640,6 +640,26 @@ public class AudioService extends IAudioService.Stub
        sAudioVolumeGroups = new AudioVolumeGroups();

        // Initialize volume
        // Priority 1 - Android Property
        // Priority 2 - Audio Policy Service
        // Priority 3 - Default Value
        if (sAudioProductStrategies.size() > 0) {
            int numStreamTypes = AudioSystem.getNumStreamTypes();

            for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) {
                AudioAttributes attr =
                        sAudioProductStrategies.getAudioAttributesForLegacyStreamType(streamType);
                int maxVolume = AudioSystem.getMaxVolumeIndexForAttributes(attr);
                if (maxVolume != -1) {
                    MAX_STREAM_VOLUME[streamType] = maxVolume;
                }
                int minVolume = AudioSystem.getMinVolumeIndexForAttributes(attr);
                if (minVolume != -1) {
                    MIN_STREAM_VOLUME[streamType] = minVolume;
                }
            }
        }

        int maxCallVolume = SystemProperties.getInt("ro.config.vc_call_vol_steps", -1);
        if (maxCallVolume != -1) {
            MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = maxCallVolume;
@@ -1468,6 +1488,11 @@ public class AudioService extends IAudioService.Stub
    }

    private int rescaleIndex(int index, int srcStream, int dstStream) {
        int max = mStreamStates[srcStream].getMaxIndex();
        if (max == 0) {
            Log.e(TAG, "rescaleIndex : Max index should not be zero");
            return mStreamStates[srcStream].getMinIndex();
        }
        final int rescaled =
                (index * mStreamStates[dstStream].getMaxIndex()
                        + mStreamStates[srcStream].getMaxIndex() / 2)