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

Commit 9a34d538 authored by Anton Potapov's avatar Anton Potapov
Browse files

Add Volume Panel spatial audio UI

Flag: aconfig new_volume_panel TEAMFOOD
Test: atest SpatialAudioAvailabilityCriteriaTest
Test: manual on phone with compatible headphones
Bug: 327186808
Change-Id: I53ca078c246e24121fd3c593c24a12e8a13b3d88
parent 80b15219
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -88,5 +88,6 @@
        <permission name="android.permission.SET_UNRESTRICTED_KEEP_CLEAR_AREAS" />
        <permission name="android.permission.READ_SEARCH_INDEXABLES" />
        <permission name="android.permission.ACCESS_AMBIENT_CONTEXT_EVENT"/>
        <permission name="android.permission.MODIFY_DEFAULT_AUDIO_EFFECTS" />
    </privapp-permissions>
</permissions>
+12 −25
Original line number Diff line number Diff line
@@ -18,23 +18,18 @@ package com.android.settingslib.media.data.repository

import android.media.AudioDeviceAttributes
import android.media.Spatializer
import androidx.concurrent.futures.DirectExecutor
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

interface SpatializerRepository {

    /** Returns true when head tracking is enabled and false the otherwise. */
    val isHeadTrackingAvailable: StateFlow<Boolean>
    /**
     * Returns true when head tracking is available for the [audioDeviceAttributes] and false the
     * otherwise.
     */
    suspend fun isHeadTrackingAvailableForDevice(
        audioDeviceAttributes: AudioDeviceAttributes
    ): Boolean

    /**
     * Returns true when Spatial audio feature is supported for the [audioDeviceAttributes] and
@@ -65,22 +60,14 @@ interface SpatializerRepository {

class SpatializerRepositoryImpl(
    private val spatializer: Spatializer,
    coroutineScope: CoroutineScope,
    private val backgroundContext: CoroutineContext,
) : SpatializerRepository {

    override val isHeadTrackingAvailable: StateFlow<Boolean> =
        callbackFlow {
                val listener =
                    Spatializer.OnHeadTrackerAvailableListener { _, available ->
                        launch { send(available) }
                    }
                spatializer.addOnHeadTrackerAvailableListener(DirectExecutor.INSTANCE, listener)
                awaitClose { spatializer.removeOnHeadTrackerAvailableListener(listener) }
    override suspend fun isHeadTrackingAvailableForDevice(
        audioDeviceAttributes: AudioDeviceAttributes
    ): Boolean {
        return withContext(backgroundContext) { spatializer.hasHeadTracker(audioDeviceAttributes) }
    }
            .onStart { emit(spatializer.isHeadTrackerAvailable) }
            .flowOn(backgroundContext)
            .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), false)

    override suspend fun isSpatialAudioAvailableForDevice(
        audioDeviceAttributes: AudioDeviceAttributes
+5 −5
Original line number Diff line number Diff line
@@ -18,17 +18,17 @@ package com.android.settingslib.media.domain.interactor

import android.media.AudioDeviceAttributes
import com.android.settingslib.media.data.repository.SpatializerRepository
import kotlinx.coroutines.flow.StateFlow

class SpatializerInteractor(private val repository: SpatializerRepository) {

    /** Checks if head tracking is available. */
    val isHeadTrackingAvailable: StateFlow<Boolean>
        get() = repository.isHeadTrackingAvailable

    /** Checks if spatial audio is available. */
    suspend fun isSpatialAudioAvailable(audioDeviceAttributes: AudioDeviceAttributes): Boolean =
        repository.isSpatialAudioAvailableForDevice(audioDeviceAttributes)

    /** Checks if head tracking is available. */
    suspend fun isHeadTrackingAvailable(audioDeviceAttributes: AudioDeviceAttributes): Boolean =
        repository.isHeadTrackingAvailableForDevice(audioDeviceAttributes)

    /** Checks if spatial audio is enabled for the [audioDeviceAttributes]. */
    suspend fun isSpatialAudioEnabled(audioDeviceAttributes: AudioDeviceAttributes): Boolean =
        repository.getSpatialAudioCompatibleDevices().contains(audioDeviceAttributes)
+3 −0
Original line number Diff line number Diff line
@@ -273,6 +273,9 @@
    <!-- to control accessibility volume -->
    <uses-permission android:name="android.permission.CHANGE_ACCESSIBILITY_VOLUME" />

    <!-- to change spatial audio -->
    <uses-permission android:name="android.permission.MODIFY_DEFAULT_AUDIO_EFFECTS" />

    <!-- to access ResolverRankerServices -->
    <uses-permission android:name="android.permission.BIND_RESOLVER_RANKER_SERVICE" />

+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.panel.component.spatialaudio

import dagger.Module

@Module interface SpatialAudioModule
Loading