Loading services/core/java/com/android/server/audio/AudioDeviceBroker.java +1 −1 Original line number Diff line number Diff line Loading @@ -1473,7 +1473,7 @@ public class AudioDeviceBroker { } /*package*/ int getVolumeForDeviceIgnoreMute(int streamType, int device) { return mAudioService.getVolumeForDeviceIgnoreMute(streamType, device); return mAudioService.getVolumeForDevice(streamType, device).first; } /*package*/ int getMaxVssVolumeForStream(int streamType) { Loading services/core/java/com/android/server/audio/AudioService.java +28 −16 Original line number Diff line number Diff line Loading @@ -246,6 +246,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.IntArray; import android.util.Log; import android.util.Pair; import android.util.PrintWriterPrinter; import android.util.Slog; import android.util.SparseArray; Loading Loading @@ -542,9 +543,13 @@ public class AudioService extends IAudioService.Stub */ private InputDeviceVolumeHelper mInputDeviceVolumeHelper; /*package*/ int getVolumeForDeviceIgnoreMute(int stream, int device) { /** Returns a pair of volume and mute state for the given stream and device. */ /*package*/ Pair<Integer, Boolean> getVolumeForDevice(int stream, int device) { final VolumeStreamState streamState = mStreamStates.get(stream); return streamState != null ? streamState.getIndex(device) : -1; if (streamState == null) { return new Pair<>(-1, false); } return new Pair<>(streamState.getIndex(device), streamState.mIsMuted); } /** Loading Loading @@ -4260,9 +4265,9 @@ public class AudioService extends IAudioService.Stub 0); } handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, getVssForStreamOrDefault(streamType).getIndex(deviceType), flags); final boolean muted = streamState.mIsMuted; final int index = streamState.getIndex(deviceType); handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, muted, flags); } final int newIndex = getVssForStreamOrDefault(streamType).getIndex(deviceType); Loading Loading @@ -4336,7 +4341,7 @@ public class AudioService extends IAudioService.Stub } private boolean handleAbsoluteVolume(int streamType, int streamTypeAlias, @NonNull AudioDeviceAttributes ada, int newIndex, int flags) { @NonNull AudioDeviceAttributes ada, int newIndex, boolean muted, int flags) { // Check if volume update should be handled by an external volume controller boolean registeredAsAbsoluteVolume = false; boolean volumeHandled = false; Loading @@ -4351,7 +4356,7 @@ public class AudioService extends IAudioService.Stub info = getAbsoluteVolumeDeviceInfo(deviceType); } if (info != null) { dispatchAbsoluteVolumeChanged(streamType, info, newIndex); dispatchAbsoluteVolumeChanged(streamType, info, newIndex, muted); registeredAsAbsoluteVolume = true; volumeHandled = true; } Loading Loading @@ -5344,8 +5349,10 @@ public class AudioService extends IAudioService.Stub final AudioDeviceAttributes device = absVolumeDevices.toArray( new AudioDeviceAttributes[0])[0]; final int index = (getVolumeForDeviceIgnoreMute(streamType, device.getInternalType()) + 5) / 10; final Pair<Integer, Boolean> volumePair = getVolumeForDevice(streamType, device.getInternalType()); final int index = (volumePair.first + 5) / 10; final boolean muted = volumePair.second; if (DEBUG_VOL) { Slog.i(TAG, "onUpdateContextualVolumes streamType: " + streamType Loading @@ -5355,7 +5362,8 @@ public class AudioService extends IAudioService.Stub final int streamTypeAlias = sStreamVolumeAlias.get(streamType, /*valueIfKeyNotFound*/ streamType); if (!handleAbsoluteVolume(streamType, streamTypeAlias, device, index * 10, /*flags=*/0)) { if (!handleAbsoluteVolume(streamType, streamTypeAlias, device, index * 10, muted, /*flags=*/ 0)) { return; } Loading Loading @@ -5446,16 +5454,17 @@ public class AudioService extends IAudioService.Stub } } final boolean muted = streamState.mIsMuted; if (!mSoundDoseHelper.willDisplayWarningAfterCheckVolume(streamType, index, deviceType, flags)) { onSetStreamVolume(streamType, index, flags, deviceType, caller, hasModifyAudioSettings, // ada is non-null when called from setDeviceVolume, // which shouldn't update the mute state canChangeMuteAndUpdateController /*canChangeMute*/); index = getVssForStreamOrDefault(streamType).getIndex(deviceType); index = streamState.getIndex(deviceType); } handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, flags); handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, muted, flags); synchronized (mHdmiClientLock) { if (streamTypeAlias == AudioSystem.STREAM_MUSIC Loading @@ -5471,14 +5480,17 @@ public class AudioService extends IAudioService.Stub } private void dispatchAbsoluteVolumeChanged(int streamType, AbsoluteVolumeDeviceInfo deviceInfo, int index) { int index, boolean muted) { VolumeInfo volumeInfo = deviceInfo.getMatchingVolumeInfoForStream(streamType); if (volumeInfo != null) { try { VolumeInfo.Builder volInfoBuilder = new VolumeInfo.Builder(volumeInfo) .setVolumeIndex(rescaleIndex(index, streamType, volumeInfo)); if (unifyAbsoluteVolumeManagement()) { volInfoBuilder.setMuted(muted); } deviceInfo.mCallback.dispatchDeviceVolumeChanged(deviceInfo.mDevice, new VolumeInfo.Builder(volumeInfo) .setVolumeIndex(rescaleIndex(index, streamType, volumeInfo)) .build()); volInfoBuilder.build()); } catch (RemoteException e) { Log.w(TAG, "Couldn't dispatch absolute volume behavior volume change"); } Loading services/core/java/com/android/server/audio/SoundDoseHelper.java +4 −2 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import android.util.MathUtils; import android.util.Pair; import android.util.SparseIntArray; import com.android.internal.R; Loading Loading @@ -724,8 +725,9 @@ public class SoundDoseHelper { int device = mAudioService.getDeviceForStream(AudioSystem.STREAM_MUSIC); if (safeDevicesContains(device) && isStreamActive) { scheduleMusicActiveCheck(); int index = mAudioService.getVolumeForDeviceIgnoreMute(AudioSystem.STREAM_MUSIC, device); final Pair<Integer, Boolean> volumePair = mAudioService.getVolumeForDevice( AudioSystem.STREAM_MUSIC, device); final int index = volumePair.second ? 0 : volumePair.first; if (index > safeMediaVolumeIndex(device)) { // Approximate cumulative active music time long curTimeMs = SystemClock.elapsedRealtime(); Loading services/tests/servicestests/src/com/android/server/audio/AbsoluteVolumeBehaviorTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -253,7 +253,7 @@ public class AbsoluteVolumeBehaviorTest { // Dispatched volume index is scaled to the range in the initial VolumeInfo verify(mMockDispatcher).dispatchDeviceVolumeChanged(DEVICE_SPEAKER_OUT, new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).build()); new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).setMuted(false).build()); } @Test Loading Loading @@ -401,6 +401,7 @@ public class AbsoluteVolumeBehaviorTest { verify(mMockDispatcher, never()).dispatchDeviceVolumeChanged(eq(DEVICE_SPEAKER_OUT), any()); // Volume changed dispatched for adjust-only absolute volume listener verify(mMockAdjustOnlyAbsoluteVolumeDispatcher).dispatchDeviceVolumeChanged( DEVICE_SPEAKER_OUT, new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).build()); DEVICE_SPEAKER_OUT, new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).setMuted( false).build()); } } Loading
services/core/java/com/android/server/audio/AudioDeviceBroker.java +1 −1 Original line number Diff line number Diff line Loading @@ -1473,7 +1473,7 @@ public class AudioDeviceBroker { } /*package*/ int getVolumeForDeviceIgnoreMute(int streamType, int device) { return mAudioService.getVolumeForDeviceIgnoreMute(streamType, device); return mAudioService.getVolumeForDevice(streamType, device).first; } /*package*/ int getMaxVssVolumeForStream(int streamType) { Loading
services/core/java/com/android/server/audio/AudioService.java +28 −16 Original line number Diff line number Diff line Loading @@ -246,6 +246,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.IntArray; import android.util.Log; import android.util.Pair; import android.util.PrintWriterPrinter; import android.util.Slog; import android.util.SparseArray; Loading Loading @@ -542,9 +543,13 @@ public class AudioService extends IAudioService.Stub */ private InputDeviceVolumeHelper mInputDeviceVolumeHelper; /*package*/ int getVolumeForDeviceIgnoreMute(int stream, int device) { /** Returns a pair of volume and mute state for the given stream and device. */ /*package*/ Pair<Integer, Boolean> getVolumeForDevice(int stream, int device) { final VolumeStreamState streamState = mStreamStates.get(stream); return streamState != null ? streamState.getIndex(device) : -1; if (streamState == null) { return new Pair<>(-1, false); } return new Pair<>(streamState.getIndex(device), streamState.mIsMuted); } /** Loading Loading @@ -4260,9 +4265,9 @@ public class AudioService extends IAudioService.Stub 0); } handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, getVssForStreamOrDefault(streamType).getIndex(deviceType), flags); final boolean muted = streamState.mIsMuted; final int index = streamState.getIndex(deviceType); handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, muted, flags); } final int newIndex = getVssForStreamOrDefault(streamType).getIndex(deviceType); Loading Loading @@ -4336,7 +4341,7 @@ public class AudioService extends IAudioService.Stub } private boolean handleAbsoluteVolume(int streamType, int streamTypeAlias, @NonNull AudioDeviceAttributes ada, int newIndex, int flags) { @NonNull AudioDeviceAttributes ada, int newIndex, boolean muted, int flags) { // Check if volume update should be handled by an external volume controller boolean registeredAsAbsoluteVolume = false; boolean volumeHandled = false; Loading @@ -4351,7 +4356,7 @@ public class AudioService extends IAudioService.Stub info = getAbsoluteVolumeDeviceInfo(deviceType); } if (info != null) { dispatchAbsoluteVolumeChanged(streamType, info, newIndex); dispatchAbsoluteVolumeChanged(streamType, info, newIndex, muted); registeredAsAbsoluteVolume = true; volumeHandled = true; } Loading Loading @@ -5344,8 +5349,10 @@ public class AudioService extends IAudioService.Stub final AudioDeviceAttributes device = absVolumeDevices.toArray( new AudioDeviceAttributes[0])[0]; final int index = (getVolumeForDeviceIgnoreMute(streamType, device.getInternalType()) + 5) / 10; final Pair<Integer, Boolean> volumePair = getVolumeForDevice(streamType, device.getInternalType()); final int index = (volumePair.first + 5) / 10; final boolean muted = volumePair.second; if (DEBUG_VOL) { Slog.i(TAG, "onUpdateContextualVolumes streamType: " + streamType Loading @@ -5355,7 +5362,8 @@ public class AudioService extends IAudioService.Stub final int streamTypeAlias = sStreamVolumeAlias.get(streamType, /*valueIfKeyNotFound*/ streamType); if (!handleAbsoluteVolume(streamType, streamTypeAlias, device, index * 10, /*flags=*/0)) { if (!handleAbsoluteVolume(streamType, streamTypeAlias, device, index * 10, muted, /*flags=*/ 0)) { return; } Loading Loading @@ -5446,16 +5454,17 @@ public class AudioService extends IAudioService.Stub } } final boolean muted = streamState.mIsMuted; if (!mSoundDoseHelper.willDisplayWarningAfterCheckVolume(streamType, index, deviceType, flags)) { onSetStreamVolume(streamType, index, flags, deviceType, caller, hasModifyAudioSettings, // ada is non-null when called from setDeviceVolume, // which shouldn't update the mute state canChangeMuteAndUpdateController /*canChangeMute*/); index = getVssForStreamOrDefault(streamType).getIndex(deviceType); index = streamState.getIndex(deviceType); } handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, flags); handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, muted, flags); synchronized (mHdmiClientLock) { if (streamTypeAlias == AudioSystem.STREAM_MUSIC Loading @@ -5471,14 +5480,17 @@ public class AudioService extends IAudioService.Stub } private void dispatchAbsoluteVolumeChanged(int streamType, AbsoluteVolumeDeviceInfo deviceInfo, int index) { int index, boolean muted) { VolumeInfo volumeInfo = deviceInfo.getMatchingVolumeInfoForStream(streamType); if (volumeInfo != null) { try { VolumeInfo.Builder volInfoBuilder = new VolumeInfo.Builder(volumeInfo) .setVolumeIndex(rescaleIndex(index, streamType, volumeInfo)); if (unifyAbsoluteVolumeManagement()) { volInfoBuilder.setMuted(muted); } deviceInfo.mCallback.dispatchDeviceVolumeChanged(deviceInfo.mDevice, new VolumeInfo.Builder(volumeInfo) .setVolumeIndex(rescaleIndex(index, streamType, volumeInfo)) .build()); volInfoBuilder.build()); } catch (RemoteException e) { Log.w(TAG, "Couldn't dispatch absolute volume behavior volume change"); } Loading
services/core/java/com/android/server/audio/SoundDoseHelper.java +4 −2 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import android.util.MathUtils; import android.util.Pair; import android.util.SparseIntArray; import com.android.internal.R; Loading Loading @@ -724,8 +725,9 @@ public class SoundDoseHelper { int device = mAudioService.getDeviceForStream(AudioSystem.STREAM_MUSIC); if (safeDevicesContains(device) && isStreamActive) { scheduleMusicActiveCheck(); int index = mAudioService.getVolumeForDeviceIgnoreMute(AudioSystem.STREAM_MUSIC, device); final Pair<Integer, Boolean> volumePair = mAudioService.getVolumeForDevice( AudioSystem.STREAM_MUSIC, device); final int index = volumePair.second ? 0 : volumePair.first; if (index > safeMediaVolumeIndex(device)) { // Approximate cumulative active music time long curTimeMs = SystemClock.elapsedRealtime(); Loading
services/tests/servicestests/src/com/android/server/audio/AbsoluteVolumeBehaviorTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -253,7 +253,7 @@ public class AbsoluteVolumeBehaviorTest { // Dispatched volume index is scaled to the range in the initial VolumeInfo verify(mMockDispatcher).dispatchDeviceVolumeChanged(DEVICE_SPEAKER_OUT, new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).build()); new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).setMuted(false).build()); } @Test Loading Loading @@ -401,6 +401,7 @@ public class AbsoluteVolumeBehaviorTest { verify(mMockDispatcher, never()).dispatchDeviceVolumeChanged(eq(DEVICE_SPEAKER_OUT), any()); // Volume changed dispatched for adjust-only absolute volume listener verify(mMockAdjustOnlyAbsoluteVolumeDispatcher).dispatchDeviceVolumeChanged( DEVICE_SPEAKER_OUT, new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).build()); DEVICE_SPEAKER_OUT, new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).setMuted( false).build()); } }