Blocklist not working spotify custom actions

This commit is contained in:
MM20 2023-02-20 14:13:22 +01:00
parent 7dbe9d4d6f
commit 336be61521
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 9 additions and 14 deletions

View File

@ -396,7 +396,7 @@ internal class MusicServiceImpl(
send(SupportedActions())
return@collectLatest
}
send(SupportedActions(state.actions, state.customActions))
send(SupportedActions(lastPlayerPackage, state.actions, state.customActions))
}
}.shareIn(scope, SharingStarted.WhileSubscribed(), 1)

View File

@ -2,8 +2,6 @@ package de.mm20.launcher2.music
import android.media.session.PlaybackState
import android.media.session.PlaybackState.CustomAction
import android.os.Bundle
import android.util.Log
data class SupportedActions(
val stop: Boolean = false,
@ -16,7 +14,7 @@ data class SupportedActions(
val setRating: Boolean = false,
val customActions: List<CustomAction> = emptyList()
) {
constructor(actions: Long?, customActions: List<CustomAction>?) : this(
constructor(playerPackege: String?, actions: Long?, customActions: List<CustomAction>?) : this(
stop = actions?.and(PlaybackState.ACTION_STOP) == PlaybackState.ACTION_STOP,
skipToNext = actions?.and(PlaybackState.ACTION_SKIP_TO_NEXT) == PlaybackState.ACTION_SKIP_TO_NEXT,
skipToPrevious = actions?.and(PlaybackState.ACTION_SKIP_TO_PREVIOUS) == PlaybackState.ACTION_SKIP_TO_PREVIOUS,
@ -25,15 +23,12 @@ data class SupportedActions(
seekTo = actions?.and(PlaybackState.ACTION_SEEK_TO) == PlaybackState.ACTION_SEEK_TO,
setPlaybackSpeed = actions?.and(PlaybackState.ACTION_SET_PLAYBACK_SPEED) == PlaybackState.ACTION_SET_PLAYBACK_SPEED,
setRating = actions?.and(PlaybackState.ACTION_SET_RATING) == PlaybackState.ACTION_SET_RATING,
customActions = customActions ?: emptyList(),
) {
for (action in customActions ?: emptyList()) {
Log.d("MM20", action.action.toString())
val extras = action.extras ?: Bundle.EMPTY
val keySet = extras.keySet()
for (key in keySet) {
Log.d("MM20", "$key: ${extras.get(key)}")
customActions = customActions?.filter {
// Most of Spotify's custom actions are known to be broken, blocklist them in release builds
if (!BuildConfig.DEBUG && playerPackege == "com.spotify.music") {
return@filter (it.action == "REMOVE_FROM_COLLECTION" || it.action == "ADD_TO_COLLECTION")
}
}
}
true
} ?: emptyList(),
)
}