SamsungDAP: Make audioEffect variable nullable

Prevents us from crashing hard in case one decided to boot up without
swdap in audio_effects.xml.

Change-Id: I38f4e2e9a17188feebd3821e25c751d8f17c8dca
tirimbino
LuK1337 3 years ago
parent d8a3e3d52f
commit 366adc924a
  1. 16
      dap/src/org/lineageos/dap/DolbyCore.kt

@ -24,6 +24,8 @@ object DolbyCore {
private const val EFFECT_PARAM_PROFILE = 0 private const val EFFECT_PARAM_PROFILE = 0
private const val EFFECT_PARAM_EFF_ENAB = 19 private const val EFFECT_PARAM_EFF_ENAB = 19
private val EFFECT_TYPE_DAP = UUID.fromString("46d279d9-9be7-453d-9d7c-ef937f675587")
const val PROFILE_AUTO = 0 const val PROFILE_AUTO = 0
const val PROFILE_MOVIE = 1 const val PROFILE_MOVIE = 1
const val PROFILE_MUSIC = 2 const val PROFILE_MUSIC = 2
@ -34,18 +36,18 @@ object DolbyCore {
const val PROFILE_GAME_2 = 7 const val PROFILE_GAME_2 = 7
const val PROFILE_SPACIAL_AUDIO = 8 const val PROFILE_SPACIAL_AUDIO = 8
private val audioEffect = AudioEffect( private val audioEffect = runCatching {
UUID.fromString("46d279d9-9be7-453d-9d7c-ef937f675587"), AudioEffect.EFFECT_TYPE_NULL, 0, 0 AudioEffect(EFFECT_TYPE_DAP, AudioEffect.EFFECT_TYPE_NULL, 0, 0)
) }.getOrNull()
fun setProfile(profile: Int) { fun setProfile(profile: Int) {
audioEffect.setParameter(EFFECT_PARAM_EFF_ENAB, 1) audioEffect?.setParameter(EFFECT_PARAM_EFF_ENAB, 1)
audioEffect.setParameter(EFFECT_PARAM_PROFILE, profile) audioEffect?.setParameter(EFFECT_PARAM_PROFILE, profile)
} }
fun setEnabled(enabled: Boolean) { fun setEnabled(enabled: Boolean) {
audioEffect.enabled = enabled audioEffect?.enabled = enabled
} }
fun isEnabled() = audioEffect.enabled fun isEnabled() = audioEffect?.enabled ?: false
} }

Loading…
Cancel
Save