diff --git a/dap/Android.bp b/dap/Android.bp
new file mode 100644
index 00000000..56e9e0b8
--- /dev/null
+++ b/dap/Android.bp
@@ -0,0 +1,25 @@
+//
+// Copyright (C) 2022 The LineageOS 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.
+//
+
+android_app {
+ name: "SamsungDAP",
+ defaults: ["SettingsLibDefaults"],
+ srcs: ["src/**/*.kt"],
+ certificate: "platform",
+ platform_apis: true,
+ static_libs: ["androidx.preference_preference"],
+ system_ext_specific: true,
+}
diff --git a/dap/AndroidManifest.xml b/dap/AndroidManifest.xml
new file mode 100644
index 00000000..f9cd0f2d
--- /dev/null
+++ b/dap/AndroidManifest.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dap/res/drawable/ic_dolby.xml b/dap/res/drawable/ic_dolby.xml
new file mode 100644
index 00000000..be73ff96
--- /dev/null
+++ b/dap/res/drawable/ic_dolby.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
diff --git a/dap/res/drawable/ic_settings.xml b/dap/res/drawable/ic_settings.xml
new file mode 100644
index 00000000..a8a9179f
--- /dev/null
+++ b/dap/res/drawable/ic_settings.xml
@@ -0,0 +1,11 @@
+
+
+
+
diff --git a/dap/res/values/strings.xml b/dap/res/values/strings.xml
new file mode 100644
index 00000000..295652fc
--- /dev/null
+++ b/dap/res/values/strings.xml
@@ -0,0 +1,22 @@
+
+
+
+ Dolby Atmos
+
+
+ Enable Dolby Atmos
+
+
+ Experience breakthrough audio for media playback that flows above and around you
+
+
+ Auto Profile
+ Game Profile
+ Game 1 Profile
+ Game 2 Profile
+ Movie Profile
+ Music Profile
+ No Profile
+ Spacial Audio Profile
+ Voice Profile
+
diff --git a/dap/res/xml/dolby_settings.xml b/dap/res/xml/dolby_settings.xml
new file mode 100644
index 00000000..a494eb6f
--- /dev/null
+++ b/dap/res/xml/dolby_settings.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dap/src/org/lineageos/dap/BootCompletedReceiver.kt b/dap/src/org/lineageos/dap/BootCompletedReceiver.kt
new file mode 100644
index 00000000..594253d4
--- /dev/null
+++ b/dap/src/org/lineageos/dap/BootCompletedReceiver.kt
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2022 The LineageOS 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 org.lineageos.dap
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+
+import androidx.preference.PreferenceManager
+
+import org.lineageos.dap.DolbyFragment.Companion.PREF_DOLBY_ENABLE
+import org.lineageos.dap.DolbyFragment.Companion.PREF_DOLBY_MODES
+
+class BootCompletedReceiver : BroadcastReceiver() {
+
+ override fun onReceive(context: Context, intent: Intent) {
+ val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)
+ for ((key, value) in PREF_DOLBY_MODES) {
+ if (sharedPrefs.getBoolean(key, false)) {
+ DolbyCore.setProfile(value)
+ break
+ }
+ }
+ DolbyCore.setEnabled(sharedPrefs.getBoolean(PREF_DOLBY_ENABLE, false))
+ }
+}
diff --git a/dap/src/org/lineageos/dap/DolbyActivity.kt b/dap/src/org/lineageos/dap/DolbyActivity.kt
new file mode 100644
index 00000000..619c51ea
--- /dev/null
+++ b/dap/src/org/lineageos/dap/DolbyActivity.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2022 The LineageOS 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 org.lineageos.dap
+
+import android.os.Bundle
+
+import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
+import com.android.settingslib.collapsingtoolbar.R
+
+class DolbyActivity : CollapsingToolbarBaseActivity() {
+ public override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ fragmentManager.beginTransaction().replace(
+ R.id.content_frame,
+ DolbyFragment()
+ ).commit()
+ }
+}
diff --git a/dap/src/org/lineageos/dap/DolbyCore.kt b/dap/src/org/lineageos/dap/DolbyCore.kt
new file mode 100644
index 00000000..d34e55e2
--- /dev/null
+++ b/dap/src/org/lineageos/dap/DolbyCore.kt
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2022 The LineageOS 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 org.lineageos.dap
+
+import android.media.audiofx.AudioEffect
+
+import java.util.UUID
+
+object DolbyCore {
+ private const val EFFECT_PARAM_PROFILE = 0
+ private const val EFFECT_PARAM_EFF_ENAB = 19
+
+ const val PROFILE_AUTO = 0
+ const val PROFILE_MOVIE = 1
+ const val PROFILE_MUSIC = 2
+ const val PROFILE_VOICE = 3
+ const val PROFILE_GAME = 4
+ const val PROFILE_OFF = 5
+ const val PROFILE_GAME_1 = 6
+ const val PROFILE_GAME_2 = 7
+ const val PROFILE_SPACIAL_AUDIO = 8
+
+ private val audioEffect = AudioEffect(
+ UUID.fromString("46d279d9-9be7-453d-9d7c-ef937f675587"), AudioEffect.EFFECT_TYPE_NULL, 0, 0
+ )
+
+ fun setProfile(profile: Int) {
+ audioEffect.setParameter(EFFECT_PARAM_EFF_ENAB, 1)
+ audioEffect.setParameter(EFFECT_PARAM_PROFILE, profile)
+ }
+
+ fun setEnabled(enabled: Boolean) {
+ audioEffect.enabled = enabled
+ }
+
+ fun isEnabled() = audioEffect.enabled
+}
diff --git a/dap/src/org/lineageos/dap/DolbyFragment.kt b/dap/src/org/lineageos/dap/DolbyFragment.kt
new file mode 100644
index 00000000..2331b65f
--- /dev/null
+++ b/dap/src/org/lineageos/dap/DolbyFragment.kt
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2022 The LineageOS 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 org.lineageos.dap
+
+import android.os.Bundle
+import android.widget.Switch
+
+import androidx.preference.PreferenceFragment
+
+import com.android.settingslib.widget.MainSwitchPreference
+import com.android.settingslib.widget.OnMainSwitchChangeListener
+import com.android.settingslib.widget.RadioButtonPreference
+
+import org.lineageos.dap.R
+
+class DolbyFragment : PreferenceFragment(), OnMainSwitchChangeListener {
+
+ private lateinit var switchBar: MainSwitchPreference
+
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ addPreferencesFromResource(R.xml.dolby_settings)
+
+ switchBar = findPreference(PREF_DOLBY_ENABLE)!!
+ switchBar.addOnSwitchChangeListener(this)
+ switchBar.isChecked = DolbyCore.isEnabled()
+
+ for ((key, value) in PREF_DOLBY_MODES) {
+ val preference = findPreference(key)!!
+ preference.setOnPreferenceClickListener {
+ setProfile(value)
+ true
+ }
+ }
+ }
+
+ override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) {
+ DolbyCore.setEnabled(isChecked)
+ }
+
+ private fun setProfile(profile: Int) {
+ DolbyCore.setProfile(profile)
+
+ for ((key, value) in PREF_DOLBY_MODES) {
+ val preference = findPreference(key)!!
+ preference.isChecked = value == profile
+ }
+ }
+
+ companion object {
+ const val PREF_DOLBY_ENABLE = "dolby_enable"
+
+ val PREF_DOLBY_MODES = mapOf(
+ "dolby_profile_auto" to DolbyCore.PROFILE_AUTO,
+ "dolby_profile_movie" to DolbyCore.PROFILE_MOVIE,
+ "dolby_profile_music" to DolbyCore.PROFILE_MUSIC,
+ "dolby_profile_voice" to DolbyCore.PROFILE_VOICE,
+ "dolby_profile_game" to DolbyCore.PROFILE_GAME,
+ "dolby_profile_off" to DolbyCore.PROFILE_OFF,
+ "dolby_profile_game_1" to DolbyCore.PROFILE_GAME_1,
+ "dolby_profile_game_2" to DolbyCore.PROFILE_GAME_2,
+ "dolby_profile_spacial_audio" to DolbyCore.PROFILE_SPACIAL_AUDIO,
+ )
+ }
+}
diff --git a/dap/src/org/lineageos/dap/DolbyTile.kt b/dap/src/org/lineageos/dap/DolbyTile.kt
new file mode 100644
index 00000000..a2abc0fc
--- /dev/null
+++ b/dap/src/org/lineageos/dap/DolbyTile.kt
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2022 The LineageOS 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 org.lineageos.dap
+
+import android.service.quicksettings.Tile
+import android.service.quicksettings.TileService
+
+import androidx.preference.PreferenceManager
+
+import org.lineageos.dap.DolbyFragment.Companion.PREF_DOLBY_ENABLE
+
+class DolbyTile : TileService() {
+ private var isEnabled = false
+ set(value) {
+ field = value
+ qsTile.state = if (value) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
+ qsTile.updateTile()
+ }
+
+ override fun onStartListening() {
+ super.onStartListening()
+ isEnabled = DolbyCore.isEnabled()
+ }
+
+ override fun onClick() {
+ isEnabled = !isEnabled
+ DolbyCore.setEnabled(isEnabled)
+ PreferenceManager.getDefaultSharedPreferences(this)
+ .edit()
+ .putBoolean(PREF_DOLBY_ENABLE, isEnabled)
+ .commit()
+ }
+}