/* * Copyright (C) 2025 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.settings.accessibility.hearingdevices.data import android.content.Context import android.media.AudioManager import com.android.settingslib.datastore.KeyValueStoreDelegate import com.android.settingslib.datastore.SettingsStore import com.android.settingslib.datastore.SettingsSystemStore class HearingAidCompatibilityDataStore( private val context: Context, private val settingsStore: SettingsStore = SettingsSystemStore.get(context), private var audioManager: AudioManager = context.getSystemService(AudioManager::class.java)!!, ) : KeyValueStoreDelegate { override val keyValueStoreDelegate get() = settingsStore override fun setValue(key: String, valueType: Class, value: T?) { super.setValue(key, valueType, value) setAudioParameterHacEnabled((value as Boolean?) ?: false) } private fun setAudioParameterHacEnabled(enabled: Boolean) { val value = if (enabled) HAC_VAL_ON else HAC_VAL_OFF audioManager.setParameters("$HAC_KEY=$value;") } companion object { const val HAC_KEY: String = "HACSetting" const val HAC_VAL_ON: String = "ON" const val HAC_VAL_OFF: String = "OFF" } }