universal7885: Merge LineageOS SamsungDAP

Change-Id: Ic8faa1b8b2c23ca1cd1add256c2229efef36cfd1
Signed-off-by: roynatech2544 <whiteshell2544@naver.com>
This commit is contained in:
roynatech2544 2022-03-22 21:59:09 +09:00
commit ad27f7c8f6
No known key found for this signature in database
GPG key ID: 9675C32163D88D30
8 changed files with 324 additions and 168 deletions

View file

@ -17,7 +17,7 @@
android:theme="@style/Theme.SubSettingsBase"
android:fullBackupOnly="true">
<activity
android:name="com.eurekateam.samsungextras.DeviceSettingsActivity"
android:name=".DeviceSettingsActivity"
android:exported="true"
android:excludeFromRecents="true"
android:launchMode="singleTask">
@ -45,7 +45,7 @@
android:resource="@drawable/ic_device" />
</activity>
<activity
android:name="com.eurekateam.samsungextras.speaker.ClearSpeakerActivity"
android:name=".speaker.ClearSpeakerActivity"
android:exported="true"
android:label="@string/clear_speaker_title">
<intent-filter>
@ -54,7 +54,7 @@
</intent-filter>
</activity>
<activity
android:name="com.eurekateam.samsungextras.flashlight.FlashLightActivity"
android:name=".flashlight.FlashLightActivity"
android:exported="true"
android:label="@string/flashlight_title">
<intent-filter>
@ -63,7 +63,7 @@
</intent-filter>
</activity>
<activity
android:name="com.eurekateam.samsungextras.dolby.DolbyActivity"
android:name=".dolby.DolbyActivity"
android:exported="true"
android:label="@string/dolby_title">
<intent-filter>
@ -71,8 +71,32 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<provider
android:name=".dolby.DolbySearchIndexablesProvider"
android:exported="true"
android:authorities="com.eurekateam.samsungextras"
android:multiprocess="false"
android:grantUriPermissions="true"
android:permission="android.permission.READ_SEARCH_INDEXABLES">
<intent-filter>
<action android:name="android.content.action.SEARCH_INDEXABLES_PROVIDER" />
</intent-filter>
</provider>
<service
android:name=".dolby.DolbyTile"
android:exported="true"
android:icon="@drawable/ic_dolby"
android:label="@string/dolby_title"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:enabled="true">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
<meta-data android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true"/>
</service>
<activity
android:name="com.eurekateam.samsungextras.battery.BatteryActivity"
android:name=".battery.BatteryActivity"
android:exported="true"
android:label="@string/fastcharge_title">
@ -81,25 +105,10 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name=".dolby.DolbyTile"
android:enabled="true"
android:icon="@drawable/ic_speaker_cleaner_icon"
android:label="@string/dolby_title"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:exported="true">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
<service
android:name=".fps.FPSInfoService"
android:exported="false">
</service>
<service
android:name=".dolby.DolbyCore"
android:exported="false">
</service>
<service
android:name=".fps.FPSTileService"
android:icon="@drawable/ic_fps_info"

View file

@ -33,20 +33,28 @@
<string name="clear_speaker_description">Run this feature once or twice if you find that your speaker is lightly blocked by dust. Set media volume to maximum.\n\nIf the speaker is blocked heavily, run this feature 25 times while shaking your device with the speaker facing downwards.</string>
<!-- Dolby -->
<string name="dolby_title">Dolby Atmos</string>
<string name="dolby_summary">Enable the Dolby Atmos audio effect</string>
<string name="dolby_description">Enable Dolby audio, just like in OneUI.</string>
<string name="dolby_modes_title">Available Dolby Modes</string>
<string name="dolby_modes_summary">Choose one of these</string>
<!-- Title -->
<string name="dolby_title" translatable="false">Dolby Atmos</string>
<!-- Switch bar -->
<string name="dolby_enable_title">Enable Dolby Atmos</string>
<!-- Intro -->
<string name="dolby_top_intro_summary">Experience breakthrough audio for media playback that flows above and around you</string>
<!-- Profiles -->
<string name="dolby_profile_auto">Auto Profile</string>
<string name="dolby_profile_movie">Movie Profile</string>
<string name="dolby_profile_music">Music Profile</string>
<string name="dolby_profile_voice">Voice Profile</string>
<string name="dolby_profile_game">Game Profile</string>
<string name="dolby_profile_off">No Profile</string>
<string name="dolby_profile_game_1">Game 1 Profile</string>
<string name="dolby_profile_game_2">Game 2 Profile</string>
<string name="dolby_profile_special_audio">Special Audio Profile</string>
<string name="dolby_profile_movie">Movie Profile</string>
<string name="dolby_profile_music">Music Profile</string>
<string name="dolby_profile_off">No Profile</string>
<string name="dolby_profile_spacial_audio">Spacial Audio Profile</string>
<string name="dolby_profile_voice">Voice Profile</string>
<!-- Eureka Kernel features category -->
<string name="eureka_kernel_features">Eureka Kernel Features</string>

View file

@ -3,22 +3,50 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/dolby_title">
<SwitchPreference
android:key="dolby_pref"
android:title="@string/dolby_title"
android:icon="@drawable/ic_speaker_cleaner_icon"
android:summary="@string/dolby_summary"/>
<com.android.settingslib.widget.MainSwitchPreference
android:defaultValue="false"
android:key="dolby_enable"
android:title="@string/dolby_enable_title" />
<ListPreference
android:key="dolby_modes"
android:title="@string/dolby_modes_title"
android:summary="@string/dolby_modes_summary"
android:icon="@drawable/ic_settings"
android:entries="@array/dolby_modes"/>
<com.android.settingslib.widget.TopIntroPreference
android:key="dolby_top_intro"
android:title="@string/dolby_top_intro_summary" />
<com.android.settingslib.widget.FooterPreference
android:key="footer_preference"
android:title="@string/dolby_description"
android:selectable="false" />
<com.android.settingslib.widget.RadioButtonPreference
android:defaultValue="true"
android:key="dolby_profile_auto"
android:title="@string/dolby_profile_auto" />
<com.android.settingslib.widget.RadioButtonPreference
android:key="dolby_profile_game"
android:title="@string/dolby_profile_game" />
<com.android.settingslib.widget.RadioButtonPreference
android:key="dolby_profile_game_1"
android:title="@string/dolby_profile_game_1" />
<com.android.settingslib.widget.RadioButtonPreference
android:key="dolby_profile_game_2"
android:title="@string/dolby_profile_game_2" />
<com.android.settingslib.widget.RadioButtonPreference
android:key="dolby_profile_movie"
android:title="@string/dolby_profile_movie" />
<com.android.settingslib.widget.RadioButtonPreference
android:key="dolby_profile_music"
android:title="@string/dolby_profile_music" />
<com.android.settingslib.widget.RadioButtonPreference
android:key="dolby_profile_off"
android:title="@string/dolby_profile_off" />
<com.android.settingslib.widget.RadioButtonPreference
android:key="dolby_profile_spacial_audio"
android:title="@string/dolby_profile_spacial_audio" />
<com.android.settingslib.widget.RadioButtonPreference
android:key="dolby_profile_voice"
android:title="@string/dolby_profile_voice" />
</PreferenceScreen>

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Paranoid Android
* 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.
@ -13,32 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.eurekateam.samsungextras.dolby
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.FragmentActivity
import com.android.internal.R.id.content
import com.android.internal.R.id.home
class DolbyActivity : FragmentActivity() {
override fun onCreate(savedInstanceState: 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)
val fragment = this.supportFragmentManager.findFragmentById(content)
val dolbyFragment: DolbyFragment
if (fragment == null) {
dolbyFragment = DolbyFragment()
this.supportFragmentManager.beginTransaction()
.add(content, dolbyFragment)
.commit()
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == home) {
finish()
return true
}
return super.onOptionsItemSelected(item)
fragmentManager.beginTransaction().replace(
R.id.content_frame,
DolbyFragment()
).commit()
}
}

View file

@ -1,52 +1,71 @@
/*
* 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 com.eurekateam.samsungextras.dolby
import android.media.audiofx.AudioEffect
import java.util.*
import android.content.Context
import android.media.AudioManager
import android.os.IBinder
import android.content.Intent
import android.app.Service
import android.media.audiofx.AudioEffect
class DolbyCore : Service() {
override fun onBind(intent: Intent?): IBinder? {
return null
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent != null){
if (intent.getBooleanExtra(DAP_ENABLED, false)){
val PROFILE = intent.getIntExtra(DAP_PROFILE, PROFILE_AUTO)
mAudioEffect.setParameter(EFFECT_PARAM_EFF_ENAB, 1)
mAudioEffect.setParameter(EFFECT_PARAM_PROFILE, PROFILE)
mCurrentProfile = PROFILE
mAudioEffect.enabled = true
(getSystemService(Context.AUDIO_SERVICE) as AudioManager).
setParameters("${HW_DOLBY_ENABLE}1;${HW_DOLBY_PROFILE}${PROFILE}")
} else {
mAudioEffect.setParameter(EFFECT_PARAM_EFF_ENAB, 0)
mAudioEffect.enabled = false
(getSystemService(Context.AUDIO_SERVICE) as AudioManager).
setParameters("${HW_DOLBY_ENABLE}0;${HW_DOLBY_PROFILE}" +
mCurrentProfile.toString())
}
}
return START_NOT_STICKY
}
companion object {
private val EFFECT_TYPE_DAP = UUID.fromString("46d279d9-9be7-453d-9d7c-ef937f675587")
import com.eurekateam.samsungextras.dolby.DolbyFragment.Companion.PREF_DOLBY_MODES
private const val EFFECT_PARAM_PROFILE = 0
private const val EFFECT_PARAM_EFF_ENAB = 19
const val DAP_ENABLED = "dap_enabled"
const val DAP_PROFILE = "dap_profile"
const val PROFILE_AUTO = 0
const val PROFILE_MOVIE = 1
const val PROFILE_MUSIC = 2
const val PROFILE_VOICE = 3
private const val HW_DOLBY_ENABLE = "g_effect_dolby_enable="
private const val HW_DOLBY_PROFILE = "g_effect_dolby_profile="
val mAudioEffect = AudioEffect(EFFECT_TYPE_DAP, AudioEffect.EFFECT_TYPE_NULL, 0, 0)
var mCurrentProfile = PROFILE_AUTO
import java.util.UUID
object DolbyCore {
private const val EFFECT_PARAM_PROFILE = 0
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_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 = runCatching {
AudioEffect(EFFECT_TYPE_DAP, AudioEffect.EFFECT_TYPE_NULL, 0, 0)
}.getOrNull()
fun getProfile(): Int {
val out = intArrayOf(PROFILE_AUTO)
audioEffect?.getParameter(EFFECT_PARAM_PROFILE, out)
return out.first()
}
fun getProfileName(context: Context): String {
val profile = getProfile()
val resourceName = PREF_DOLBY_MODES.filter { it.value == profile }.keys.first()
return context.resources.getString(context.resources.getIdentifier(
resourceName, "string", context.packageName
))
}
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 ?: false
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Paranoid Android
* 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.
@ -13,59 +13,66 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.eurekateam.samsungextras.dolby
import android.os.Bundle
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import com.eurekateam.samsungextras.R
import android.content.Intent
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 com.eurekateam.samsungextras.dolby.R
class DolbyFragment : PreferenceFragment(), OnMainSwitchChangeListener {
private lateinit var switchBar: MainSwitchPreference
class DolbyFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
private var DolbyModesPreference: ListPreference? = null
private var DolbyEnablePreference: SwitchPreference? = null
private lateinit var mIntent : Intent
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.dolby_settings)
DolbyModesPreference = findPreference(DOLBY_MODES)
DolbyEnablePreference = findPreference(PREF_DOLBY)
DolbyEnablePreference!!.isChecked = DolbyCore.mAudioEffect.enabled
DolbyEnablePreference!!.onPreferenceChangeListener = this
val items = arrayOf<CharSequence>(
"0", "1", "2", "3"
)
mIntent = Intent(requireContext(), DolbyCore::class.java)
DolbyModesPreference!!.entryValues = items
DolbyModesPreference!!.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
when ((newValue as String).toInt()) {
0 -> mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.PROFILE_AUTO)
1 -> mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.PROFILE_MOVIE)
2 -> mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.PROFILE_MUSIC)
3 -> mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.PROFILE_VOICE)
else -> {
}
}
mIntent.putExtra(DolbyCore.DAP_ENABLED, true)
requireContext().startService(mIntent)
switchBar = findPreference<MainSwitchPreference>(PREF_DOLBY_ENABLE)!!
switchBar.addOnSwitchChangeListener(this)
switchBar.isChecked = DolbyCore.isEnabled()
for ((key, value) in PREF_DOLBY_MODES) {
val preference = findPreference<RadioButtonPreference>(key)!!
preference.setOnPreferenceClickListener {
setProfile(value)
true
}
}
}
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
if (preference == DolbyEnablePreference) {
val value = newValue as Boolean
mIntent.putExtra(DolbyCore.DAP_ENABLED, value)
requireContext().startService(mIntent)
return 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<RadioButtonPreference>(key)!!
preference.isChecked = value == profile
}
return false
}
companion object {
private const val PREF_DOLBY = "dolby_pref"
private const val DOLBY_MODES = "dolby_modes"
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,
)
}
}

View file

@ -0,0 +1,74 @@
/*
* 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 com.eurekateam.samsungextras.dolby
import android.database.Cursor
import android.database.MatrixCursor
import android.provider.SearchIndexableResource
import android.provider.SearchIndexablesProvider
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID
import android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS
import android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS
import android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS
class DolbySearchIndexablesProvider : SearchIndexablesProvider() {
override fun onCreate(): Boolean = true
override fun queryXmlResources(projection: Array<String?>?): Cursor {
val cursor = MatrixCursor(INDEXABLES_XML_RES_COLUMNS)
INDEXABLE_RES.forEach {
cursor.addRow(generateResourceRef(it))
}
return cursor
}
override fun queryRawData(projection: Array<String?>?): Cursor {
return MatrixCursor(INDEXABLES_RAW_COLUMNS)
}
override fun queryNonIndexableKeys(projection: Array<String?>?): Cursor {
return MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS)
}
private fun generateResourceRef(sir: SearchIndexableResource): Array<Any?> {
val ref = arrayOfNulls<Any>(7)
ref[COLUMN_INDEX_XML_RES_RANK] = sir.rank
ref[COLUMN_INDEX_XML_RES_RESID] = sir.xmlResId
ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null
ref[COLUMN_INDEX_XML_RES_ICON_RESID] = sir.iconResId
ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "com.android.settings.action.EXTRA_SETTINGS"
ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "com.eurekateam.samsungextras.dolby"
ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = sir.className
return ref
}
companion object {
private const val TAG = "DolbySearchIndexablesProvider"
private val INDEXABLE_RES = arrayOf<SearchIndexableResource>(
SearchIndexableResource(
1, R.xml.dolby_settings, DolbyActivity::class.java.name, 0
)
)
}
}

View file

@ -1,25 +1,48 @@
/*
* 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 com.eurekateam.samsungextras.dolby
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import android.content.Intent
import androidx.preference.PreferenceManager
import com.eurekateam.samsungextras.dolby.DolbyFragment.Companion.PREF_DOLBY_ENABLE
class DolbyTile : TileService() {
override fun onClick() {
val mIntent = Intent(this, DolbyCore::class.java)
if (DolbyCore.mAudioEffect.enabled) {
mIntent.putExtra(DolbyCore.DAP_ENABLED, false)
} else {
mIntent.putExtra(DolbyCore.DAP_ENABLED, true)
mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.mCurrentProfile)
private var isEnabled = false
set(value) {
field = value
qsTile.state = if (value) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
qsTile.subtitle = DolbyCore.getProfileName(this)
qsTile.updateTile()
}
updateTile()
override fun onStartListening() {
super.onStartListening()
isEnabled = DolbyCore.isEnabled()
}
private fun updateTile() {
val tile = qsTile
tile.state =
if (DolbyCore.mAudioEffect.enabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
tile.updateTile()
override fun onClick() {
isEnabled = !isEnabled
DolbyCore.setEnabled(isEnabled)
PreferenceManager.getDefaultSharedPreferences(this)
.edit()
.putBoolean(PREF_DOLBY_ENABLE, isEnabled)
.commit()
}
}