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

Commit 9726edbb authored by Wenyu Zhang's avatar Wenyu Zhang Committed by Android (Google) Code Review
Browse files

Merge "Make volume slider in volume panel consistent with settings app" into main

parents 8be2122b 54d16ada
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1507,3 +1507,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
   name: "only_show_media_stream_slider_in_single_volume_mode"
   namespace: "systemui"
   description: "When the device is in single volume mode, only show media stream slider and hide all other stream (e.g. call, notification, alarm, etc) sliders in volume panel"
   bug: "373729625"
   metadata {
       purpose: PURPOSE_BUGFIX
   }
}
+19 −0
Original line number Diff line number Diff line
@@ -17,16 +17,19 @@
package com.android.systemui.volume.panel.component.volume.domain.interactor

import android.media.AudioManager
import android.platform.test.annotations.EnableFlags
import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.settingslib.volume.shared.model.AudioStream
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.volume.data.repository.audioRepository
import com.android.systemui.volume.data.repository.audioSystemRepository
import com.android.systemui.volume.panel.component.volume.domain.model.SliderType
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -91,4 +94,20 @@ class AudioSlidersInteractorTest : SysuiTestCase() {
                    ).map { SliderType.Stream(AudioStream(it)) })
            }
        }


    @Test
    @EnableFlags(Flags.FLAG_ONLY_SHOW_MEDIA_STREAM_SLIDER_IN_SINGLE_VOLUME_MODE)
    fun shouldAddMusicStreamOnly_singleVolumeMode() =
        with(kosmos) {
            testScope.runTest {
                audioSystemRepository.setIsSingleVolume(true)

                val sliders by collectLastValue(underTest.volumePanelSliders)
                runCurrent()

                assertThat(sliders).isEqualTo(
                    mutableListOf(SliderType.Stream(AudioStream(AudioManager.STREAM_MUSIC))))
            }
        }
}
+8 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import com.android.settingslib.volume.data.repository.AudioRepositoryImpl
import com.android.settingslib.volume.data.repository.AudioSharingRepository
import com.android.settingslib.volume.data.repository.AudioSharingRepositoryEmptyImpl
import com.android.settingslib.volume.data.repository.AudioSharingRepositoryImpl
import com.android.settingslib.volume.data.repository.AudioSystemRepository
import com.android.settingslib.volume.data.repository.AudioSystemRepositoryImpl
import com.android.settingslib.volume.domain.interactor.AudioModeInteractor
import com.android.settingslib.volume.domain.interactor.AudioVolumeInteractor
import com.android.settingslib.volume.shared.AudioManagerEventsReceiver
@@ -106,5 +108,11 @@ interface AudioModule {
            notificationsSoundPolicyInteractor: NotificationsSoundPolicyInteractor,
        ): AudioVolumeInteractor =
            AudioVolumeInteractor(audioRepository, notificationsSoundPolicyInteractor)

        @Provides
        @SysUISingleton
        fun provideAudioSystemRepository(
            @Application context: Context,
        ): AudioSystemRepository = AudioSystemRepositoryImpl(context)
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.systemui.volume.panel.component.volume.domain.interactor

import android.media.AudioManager
import com.android.settingslib.volume.data.repository.AudioSystemRepository
import com.android.settingslib.volume.domain.interactor.AudioModeInteractor
import com.android.settingslib.volume.shared.model.AudioStream
import com.android.systemui.Flags
import com.android.systemui.volume.panel.component.mediaoutput.domain.interactor.MediaOutputInteractor
import com.android.systemui.volume.panel.component.mediaoutput.shared.model.MediaDeviceSession
import com.android.systemui.volume.panel.component.mediaoutput.shared.model.isTheSameSession
@@ -41,6 +43,7 @@ constructor(
    @VolumePanelScope scope: CoroutineScope,
    mediaOutputInteractor: MediaOutputInteractor,
    audioModeInteractor: AudioModeInteractor,
    private val audioSystemRepository: AudioSystemRepository,
) {

    val volumePanelSliders: StateFlow<List<SliderType>> =
@@ -83,6 +86,16 @@ constructor(
    }

    private fun MutableList<SliderType>.addStream(stream: Int) {
        // Hide other streams except STREAM_MUSIC if the isSingleVolume mode is on. This makes sure
        // the volume slider in volume panel is consistent with the volume slider inside system
        // settings app.
        if (Flags.onlyShowMediaStreamSliderInSingleVolumeMode() &&
            audioSystemRepository.isSingleVolume &&
            stream != AudioManager.STREAM_MUSIC
        ) {
            return
        }

        add(SliderType.Stream(AudioStream(stream)))
    }
}
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.volume.data.repository

import com.android.systemui.kosmos.Kosmos

val Kosmos.audioSystemRepository by Kosmos.Fixture { FakeAudioSystemRepository() }
Loading