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

Commit 66a66abd authored by Vlad Popa's avatar Vlad Popa
Browse files

Rename VolumeInfo hasMuteCommand to hasMuteState

Also deprecate the API hasMuteCommand and add a new one hasMuteState in
order to avoid ambiguity.

Test: atest VolumeInfoTest
Bug: 404313846
Bug: 396216663
Flag: android.media.audio.device_volume_apis
Change-Id: I13efaec9e0759f3db6e26de4058196293845b9e6
parent 5b68f436
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -7864,7 +7864,8 @@ package android.media {
    method public int getStreamType();
    method @NonNull public android.media.audiopolicy.AudioVolumeGroup getVolumeGroup();
    method public int getVolumeIndex();
    method public boolean hasMuteCommand();
    method @Deprecated @FlaggedApi("android.media.audio.device_volume_apis") public boolean hasMuteCommand();
    method @FlaggedApi("android.media.audio.device_volume_apis") public boolean hasMuteState();
    method public boolean hasStreamType();
    method public boolean hasVolumeGroup();
    method public boolean isMuted();
+29 −14
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.media;

import static android.media.audio.Flags.FLAG_DEVICE_VOLUME_APIS;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
@@ -44,7 +47,7 @@ public final class VolumeInfo implements Parcelable {
    private static final String TAG = "VolumeInfo";

    private final boolean mUsesStreamType; // false implies AudioVolumeGroup is used
    private final boolean mHasMuteCommand;
    private final boolean mHasMuteState;
    private final boolean mIsMuted;
    private final int mVolIndex;
    private final int mMinVolIndex;
@@ -55,11 +58,11 @@ public final class VolumeInfo implements Parcelable {
    private static IAudioService sService;
    private static VolumeInfo sDefaultVolumeInfo;

    private VolumeInfo(boolean usesStreamType, boolean hasMuteCommand, boolean isMuted,
    private VolumeInfo(boolean usesStreamType, boolean hasMuteState, boolean isMuted,
            int volIndex, int minVolIndex, int maxVolIndex,
            AudioVolumeGroup volGroup, int streamType) {
        mUsesStreamType = usesStreamType;
        mHasMuteCommand = hasMuteCommand;
        mHasMuteState = hasMuteState;
        mIsMuted = isMuted;
        mVolIndex = volIndex;
        mMinVolIndex = minVolIndex;
@@ -117,9 +120,21 @@ public final class VolumeInfo implements Parcelable {
    /**
     * Return whether this instance is conveying a mute state
     * @return true if the muted state was explicitly set for this instance
     * @deprecated use {@link #hasMuteState()} instead
     */
    @Deprecated
    @FlaggedApi(FLAG_DEVICE_VOLUME_APIS)
    public boolean hasMuteCommand() {
        return mHasMuteCommand;
        return mHasMuteState;
    }

    /**
     * Return whether this instance is conveying a mute state
     * @return true if the muted state was explicitly set for this instance
     */
    @FlaggedApi(FLAG_DEVICE_VOLUME_APIS)
    public boolean hasMuteState() {
        return mHasMuteState;
    }

    /**
@@ -192,7 +207,7 @@ public final class VolumeInfo implements Parcelable {
    public static final class Builder {
        private boolean mUsesStreamType = true; // false implies AudioVolumeGroup is used
        private @AudioManager.PublicStreamTypes int mStreamType = AudioManager.STREAM_MUSIC;
        private boolean mHasMuteCommand = false;
        private boolean mHasMuteState = false;
        private boolean mIsMuted = false;
        private int mVolIndex = INDEX_NOT_SET;
        private int mMinVolIndex = INDEX_NOT_SET;
@@ -228,7 +243,7 @@ public final class VolumeInfo implements Parcelable {
            Objects.requireNonNull(info);
            mUsesStreamType = info.mUsesStreamType;
            mStreamType = info.mStreamType;
            mHasMuteCommand = info.mHasMuteCommand;
            mHasMuteState = info.mHasMuteState;
            mIsMuted = info.mIsMuted;
            mVolIndex = info.mVolIndex;
            mMinVolIndex = info.mMinVolIndex;
@@ -242,7 +257,7 @@ public final class VolumeInfo implements Parcelable {
         * @return the same builder instance
         */
        public @NonNull Builder setMuted(boolean isMuted) {
            mHasMuteCommand = true;
            mHasMuteState = true;
            mIsMuted = isMuted;
            return this;
        }
@@ -306,7 +321,7 @@ public final class VolumeInfo implements Parcelable {
                throw new IllegalArgumentException("Min volume index:" + mMinVolIndex
                        + " greater than max index:" + mMaxVolIndex);
            }
            return new VolumeInfo(mUsesStreamType, mHasMuteCommand, mIsMuted,
            return new VolumeInfo(mUsesStreamType, mHasMuteState, mIsMuted,
                    mVolIndex, mMinVolIndex, mMaxVolIndex,
                    mVolGroup, mStreamType);
        }
@@ -316,7 +331,7 @@ public final class VolumeInfo implements Parcelable {
    // Parcelable
    @Override
    public int hashCode() {
        return Objects.hash(mUsesStreamType, mHasMuteCommand, mStreamType, mIsMuted,
        return Objects.hash(mUsesStreamType, mHasMuteState, mStreamType, mIsMuted,
                mVolIndex, mMinVolIndex, mMaxVolIndex, mVolGroup);
    }

@@ -328,7 +343,7 @@ public final class VolumeInfo implements Parcelable {
        VolumeInfo that = (VolumeInfo) o;
        return ((mUsesStreamType == that.mUsesStreamType)
                && (mStreamType == that.mStreamType)
                && (mHasMuteCommand == that.mHasMuteCommand)
                && (mHasMuteState == that.mHasMuteState)
                && (mIsMuted == that.mIsMuted)
                && (mVolIndex == that.mVolIndex)
                && (mMinVolIndex == that.mMinVolIndex)
@@ -341,7 +356,7 @@ public final class VolumeInfo implements Parcelable {
        return new String("VolumeInfo:"
                + (mUsesStreamType ? (" streamType:" + mStreamType)
                    : (" volGroup:" + mVolGroup))
                + (mHasMuteCommand ? (" muted:" + mIsMuted) : ("[no mute cmd]"))
                + (mHasMuteState ? (" muted:" + mIsMuted) : ("[no mute cmd]"))
                + ((mVolIndex != INDEX_NOT_SET) ? (" volIndex:" + mVolIndex) : "")
                + ((mMinVolIndex != INDEX_NOT_SET) ? (" min:" + mMinVolIndex) : "")
                + ((mMaxVolIndex != INDEX_NOT_SET) ? (" max:" + mMaxVolIndex) : ""));
@@ -356,7 +371,7 @@ public final class VolumeInfo implements Parcelable {
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeBoolean(mUsesStreamType);
        dest.writeInt(mStreamType);
        dest.writeBoolean(mHasMuteCommand);
        dest.writeBoolean(mHasMuteState);
        dest.writeBoolean(mIsMuted);
        dest.writeInt(mVolIndex);
        dest.writeInt(mMinVolIndex);
@@ -369,7 +384,7 @@ public final class VolumeInfo implements Parcelable {
    private VolumeInfo(@NonNull Parcel in) {
        mUsesStreamType = in.readBoolean();
        mStreamType = in.readInt();
        mHasMuteCommand = in.readBoolean();
        mHasMuteState = in.readBoolean();
        mIsMuted = in.readBoolean();
        mVolIndex = in.readInt();
        mMinVolIndex = in.readInt();
@@ -382,7 +397,7 @@ public final class VolumeInfo implements Parcelable {
    }

    public static final @NonNull Parcelable.Creator<VolumeInfo> CREATOR =
            new Parcelable.Creator<VolumeInfo>() {
            new Parcelable.Creator<>() {
                /**
                 * Rebuilds a VolumeInfo previously stored with writeToParcel().
                 * @param p Parcel object to read the VolumeInfo from
+5 −2
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import static android.media.audio.Flags.autoPublicVolumeApiHardening;
import static android.media.audio.Flags.cacheGetStreamMinMaxVolume;
import static android.media.audio.Flags.cacheGetStreamVolume;
import static android.media.audio.Flags.concurrentAudioRecordBypassPermission;
import static android.media.audio.Flags.deviceVolumeApis;
import static android.media.audio.Flags.featureSpatialAudioHeadtrackingLowLatency;
import static android.media.audio.Flags.focusFreezeTestApi;
import static android.media.audio.Flags.registerVolumeCallbackApiHardening;
@@ -4792,7 +4793,8 @@ public class AudioService extends IAudioService.Stub
        }
        int index = vi.getVolumeIndex();
        if (index == VolumeInfo.INDEX_NOT_SET && !vi.hasMuteCommand()) {
        boolean hasMuteState = deviceVolumeApis() ? vi.hasMuteState() : vi.hasMuteCommand();
        if (index == VolumeInfo.INDEX_NOT_SET && !hasMuteState) {
            throw new IllegalArgumentException(
                    "changing device volume requires a volume index or mute command");
        }
@@ -4805,7 +4807,8 @@ public class AudioService extends IAudioService.Stub
        int index = vi.getVolumeIndex();
        // if a stream is not muted but the VolumeInfo is for muting, set the volume index
        // for the device to min volume
        if (vi.hasMuteCommand() && vi.isMuted() && !isStreamMute(streamType)) {
        boolean hasMuteState = deviceVolumeApis() ? vi.hasMuteState() : vi.hasMuteCommand();
        if (hasMuteState && vi.isMuted() && !isStreamMute(streamType)) {
            setStreamVolumeWithAttributionInt(streamType,
                    vss.getMinIndex(),
                    flags,