Add a VectorFeatures to force usage of the library OpusEncoder

This commit is contained in:
Benoit Marty 2022-07-07 18:29:02 +02:00
parent e3b3617b1a
commit 9a059ead44
5 changed files with 16 additions and 2 deletions

View File

@ -19,6 +19,7 @@ package im.vector.app.features.voice
import android.os.Build import android.os.Build
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import im.vector.app.AndroidVersionTestOverrider import im.vector.app.AndroidVersionTestOverrider
import im.vector.app.features.DefaultVectorFeatures
import org.amshove.kluent.shouldBeInstanceOf import org.amshove.kluent.shouldBeInstanceOf
import org.junit.After import org.junit.After
import org.junit.Test import org.junit.Test
@ -26,7 +27,7 @@ import org.junit.Test
class VoiceRecorderProviderTests { class VoiceRecorderProviderTests {
private val context = InstrumentationRegistry.getInstrumentation().targetContext private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val provider = VoiceRecorderProvider(context) private val provider = VoiceRecorderProvider(context, DefaultVectorFeatures())
@After @After
fun tearDown() { fun tearDown() {

View File

@ -70,6 +70,11 @@ class DebugFeaturesStateFactory @Inject constructor(
key = DebugFeatureKeys.allowExternalUnifiedPushDistributors, key = DebugFeatureKeys.allowExternalUnifiedPushDistributors,
factory = VectorFeatures::allowExternalUnifiedPushDistributors factory = VectorFeatures::allowExternalUnifiedPushDistributors
), ),
createBooleanFeature(
label = "Force usage of OpusEncoder library",
key = DebugFeatureKeys.forceUsageOfOpusEncoder,
factory = VectorFeatures::forceUsageOfOpusEncoder
),
) )
) )
} }

View File

@ -66,6 +66,9 @@ class DebugVectorFeatures(
override fun isScreenSharingEnabled(): Boolean = read(DebugFeatureKeys.screenSharing) override fun isScreenSharingEnabled(): Boolean = read(DebugFeatureKeys.screenSharing)
?: vectorFeatures.isScreenSharingEnabled() ?: vectorFeatures.isScreenSharingEnabled()
override fun forceUsageOfOpusEncoder(): Boolean = read(DebugFeatureKeys.forceUsageOfOpusEncoder)
?: vectorFeatures.forceUsageOfOpusEncoder()
fun <T> override(value: T?, key: Preferences.Key<T>) = updatePreferences { fun <T> override(value: T?, key: Preferences.Key<T>) = updatePreferences {
if (value == null) { if (value == null) {
it.remove(key) it.remove(key)
@ -123,4 +126,5 @@ object DebugFeatureKeys {
val allowExternalUnifiedPushDistributors = booleanPreferencesKey("allow-external-unified-push-distributors") val allowExternalUnifiedPushDistributors = booleanPreferencesKey("allow-external-unified-push-distributors")
val liveLocationSharing = booleanPreferencesKey("live-location-sharing") val liveLocationSharing = booleanPreferencesKey("live-location-sharing")
val screenSharing = booleanPreferencesKey("screen-sharing") val screenSharing = booleanPreferencesKey("screen-sharing")
val forceUsageOfOpusEncoder = booleanPreferencesKey("force-usage-of-opus-encoder")
} }

View File

@ -30,6 +30,7 @@ interface VectorFeatures {
fun isOnboardingCombinedLoginEnabled(): Boolean fun isOnboardingCombinedLoginEnabled(): Boolean
fun allowExternalUnifiedPushDistributors(): Boolean fun allowExternalUnifiedPushDistributors(): Boolean
fun isScreenSharingEnabled(): Boolean fun isScreenSharingEnabled(): Boolean
fun forceUsageOfOpusEncoder(): Boolean
enum class OnboardingVariant { enum class OnboardingVariant {
LEGACY, LEGACY,
@ -48,4 +49,5 @@ class DefaultVectorFeatures : VectorFeatures {
override fun isOnboardingCombinedLoginEnabled() = false override fun isOnboardingCombinedLoginEnabled() = false
override fun allowExternalUnifiedPushDistributors(): Boolean = Config.ALLOW_EXTERNAL_UNIFIED_PUSH_DISTRIBUTORS override fun allowExternalUnifiedPushDistributors(): Boolean = Config.ALLOW_EXTERNAL_UNIFIED_PUSH_DISTRIBUTORS
override fun isScreenSharingEnabled(): Boolean = true override fun isScreenSharingEnabled(): Boolean = true
override fun forceUsageOfOpusEncoder(): Boolean = false
} }

View File

@ -18,14 +18,16 @@ package im.vector.app.features.voice
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import im.vector.app.features.VectorFeatures
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import javax.inject.Inject import javax.inject.Inject
class VoiceRecorderProvider @Inject constructor( class VoiceRecorderProvider @Inject constructor(
private val context: Context, private val context: Context,
private val vectorFeatures: VectorFeatures,
) { ) {
fun provideVoiceRecorder(): VoiceRecorder { fun provideVoiceRecorder(): VoiceRecorder {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && vectorFeatures.forceUsageOfOpusEncoder().not()) {
VoiceRecorderQ(context) VoiceRecorderQ(context)
} else { } else {
VoiceRecorderL(context, Dispatchers.IO) VoiceRecorderL(context, Dispatchers.IO)