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

Commit 821a1efe authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "Show ui if device volume changes on current device" into main

parents 616fd282 97df34c1
Loading
Loading
Loading
Loading
+27 −10
Original line number Diff line number Diff line
@@ -4971,8 +4971,14 @@ public class AudioService extends IAudioService.Stub
                new DeviceVolumeEvent(streamType, vi.getVolumeIndex(), ada, callingPackage,
                        currDevIsAda));
        setDeviceVolumeInt(vi, vss, ada, callingPackage, FLAG_ABSOLUTE_VOLUME, /*changeMute=*/
                currDevIsAda, "notifyAbsoluteVolumeChanged");
        int flags = FLAG_ABSOLUTE_VOLUME;
        int index = rescaleVolumeInfoIndex(vi, vss);
        if (currDevIsAda && index != VolumeInfo.INDEX_NOT_SET && (vss.getIndex(
                ada.getInternalType()) + 5) / 10 != index) {
            flags |= AudioManager.FLAG_SHOW_UI;
        }
        setDeviceVolumeInt(vi, vss, ada, callingPackage, flags, /*changeMute=*/currDevIsAda,
                "notifyAbsoluteVolumeChanged");
    }
    private static boolean isVolumeInfoValid(VolumeInfo vi, boolean forAdjust) {
@@ -5040,6 +5046,20 @@ public class AudioService extends IAudioService.Stub
                        + " not between min/max for stream " + vi.getStreamType());
            }
        } else {
            index = rescaleVolumeInfoIndex(vi, vss);
        }
        setStreamVolumeWithAttributionInt(streamType, index, flags,
                ada, callingPackage, null,
                changeMute);
    }
    private int rescaleVolumeInfoIndex(VolumeInfo vi, VolumeStreamState vss) {
        int index = vi.getVolumeIndex();
        if (vi.getMinVolumeIndex() == VolumeInfo.INDEX_NOT_SET
                || vi.getMaxVolumeIndex() == VolumeInfo.INDEX_NOT_SET) {
            // no rescaling if the min max are not set
            return index;
        }
        // check if index needs to be rescaled
        final int min = (vss.getMinIndex() + 5) / 10;
        final int max = (vss.getMaxIndex() + 5) / 10;
@@ -5048,10 +5068,7 @@ public class AudioService extends IAudioService.Stub
                    /*srcMin*/ vi.getMinVolumeIndex(), /*srcMax*/ vi.getMaxVolumeIndex(),
                    /*dstMin*/ min, /*dstMax*/ max);
        }
        }
        setStreamVolumeWithAttributionInt(streamType, index, flags,
                ada, callingPackage, null,
                changeMute);
        return index;
    }
    /** Retain API for unsupported app usage */