mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 16:19:33 +01:00
Implement new feature flag strategy for AEC selection.
This commit is contained in:
committed by
Alex Hart
parent
d935d1deca
commit
3ac63cc59d
@@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.service.webrtc
|
||||
|
||||
import android.os.Build
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import org.signal.ringrtc.CallManager.AudioProcessingMethod
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags
|
||||
@@ -10,24 +11,47 @@ import org.thoughtcrime.securesms.util.FeatureFlags
|
||||
*/
|
||||
object AudioProcessingMethodSelector {
|
||||
|
||||
private val hardwareModels: Set<String> by lazy {
|
||||
FeatureFlags.hardwareAecModels()
|
||||
.split(",")
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
.toSet()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun get(): AudioProcessingMethod {
|
||||
if (SignalStore.internalValues().audioProcessingMethod() != AudioProcessingMethod.Default) {
|
||||
return SignalStore.internalValues().audioProcessingMethod()
|
||||
}
|
||||
|
||||
val useAec3: Boolean = FeatureFlags.useAec3()
|
||||
|
||||
return when {
|
||||
FeatureFlags.forceDefaultAec() -> AudioProcessingMethod.Default
|
||||
hardwareModels.contains(Build.MODEL) -> AudioProcessingMethod.ForceHardware
|
||||
else -> AudioProcessingMethod.ForceSoftwareAecM
|
||||
isHardwareBlocklisted() && useAec3 -> AudioProcessingMethod.ForceSoftwareAec3
|
||||
isHardwareBlocklisted() -> AudioProcessingMethod.ForceSoftwareAecM
|
||||
isSoftwareBlocklisted() -> AudioProcessingMethod.ForceHardware
|
||||
Build.VERSION.SDK_INT < 29 && FeatureFlags.useHardwareAecIfOlderThanApi29() -> AudioProcessingMethod.ForceHardware
|
||||
Build.VERSION.SDK_INT < 29 && useAec3 -> AudioProcessingMethod.ForceSoftwareAec3
|
||||
Build.VERSION.SDK_INT < 29 -> AudioProcessingMethod.ForceSoftwareAecM
|
||||
else -> AudioProcessingMethod.ForceHardware
|
||||
}
|
||||
}
|
||||
|
||||
private fun isHardwareBlocklisted(): Boolean {
|
||||
return modelInList(Build.MODEL, FeatureFlags.hardwareAecBlocklistModels())
|
||||
}
|
||||
|
||||
private fun isSoftwareBlocklisted(): Boolean {
|
||||
return modelInList(Build.MODEL, FeatureFlags.softwareAecBlocklistModels())
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun modelInList(model: String, serializedList: String): Boolean {
|
||||
val items: List<String> = serializedList
|
||||
.split(",")
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
.toList()
|
||||
|
||||
val exactMatches = items.filter { it.last() != '*' }
|
||||
val prefixMatches = items.filter { it.last() == '*' }
|
||||
|
||||
return exactMatches.contains(model) ||
|
||||
prefixMatches
|
||||
.map { it.substring(0, it.length - 1) }
|
||||
.any { model.startsWith(it) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user