Make PlayerMediaBrowserService be activated/deactivated
This commit is contained in:
parent
34f4404329
commit
fa4fd276b3
2 changed files with 38 additions and 2 deletions
|
@ -94,7 +94,8 @@
|
|||
</service>
|
||||
|
||||
<service android:name=".service.PlayerMediaBrowserService"
|
||||
android:exported="true">
|
||||
android:exported="true"
|
||||
android:enabled="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.media.browse.MediaBrowserService"/>
|
||||
</intent-filter>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package it.vfsfitvnm.vimusic.ui.screens.settings
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
|
@ -26,6 +28,8 @@ import it.vfsfitvnm.vimusic.LocalPlayerAwareWindowInsets
|
|||
import androidx.compose.foundation.layout.WindowInsetsSides
|
||||
import androidx.compose.foundation.layout.asPaddingValues
|
||||
import androidx.compose.foundation.layout.only
|
||||
import androidx.compose.runtime.SnapshotMutationPolicy
|
||||
import it.vfsfitvnm.vimusic.service.PlayerMediaBrowserService
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.Header
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.isIgnoringBatteryOptimizations
|
||||
|
@ -38,6 +42,26 @@ fun OtherSettings() {
|
|||
val context = LocalContext.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
var isAndroidAutoEnabled by remember {
|
||||
val component = ComponentName(context, PlayerMediaBrowserService::class.java)
|
||||
val disabledFlag = PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||
val enabledFlag = PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
|
||||
mutableStateOf(
|
||||
value = context.packageManager.getComponentEnabledSetting(component) == enabledFlag,
|
||||
policy = object : SnapshotMutationPolicy<Boolean> {
|
||||
override fun equivalent(a: Boolean, b: Boolean): Boolean {
|
||||
context.packageManager.setComponentEnabledSetting(
|
||||
component,
|
||||
if (b) enabledFlag else disabledFlag,
|
||||
PackageManager.DONT_KILL_APP
|
||||
)
|
||||
return a == b
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
var isInvincibilityEnabled by rememberPreference(isInvincibilityEnabledKey, false)
|
||||
|
||||
var isIgnoringBatteryOptimizations by remember {
|
||||
|
@ -62,9 +86,20 @@ fun OtherSettings() {
|
|||
) {
|
||||
Header(title = "Other")
|
||||
|
||||
SettingsEntryGroupText(title = "ANDROID AUTO")
|
||||
|
||||
SwitchSettingEntry(
|
||||
title = "Android Auto",
|
||||
text = "Enable Android Auto support",
|
||||
isChecked = isAndroidAutoEnabled,
|
||||
onCheckedChange = { isAndroidAutoEnabled = it }
|
||||
)
|
||||
|
||||
SettingsGroupSpacer()
|
||||
|
||||
SettingsEntryGroupText(title = "SERVICE LIFETIME")
|
||||
|
||||
SettingsDescription(text = "If battery optimizations are applied, the playback notification can suddenly disappear when paused.")
|
||||
ImportantSettingsDescription(text = "If battery optimizations are applied, the playback notification can suddenly disappear when paused.")
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
SettingsDescription(text = "Since Android 12, disabling battery optimizations is required for the \"Invincible service\" option to take effect.")
|
||||
|
|
Loading…
Reference in a new issue