Make broadcasts unique

Prevent broadcasts from Auxio builds being registered by other, different Auxio instances.
This commit is contained in:
OxygenCobalt 2020-12-20 12:59:29 -07:00
parent e85bdd0643
commit dc26d70088
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 12 additions and 6 deletions

View file

@ -46,10 +46,12 @@ class MusicLoader(
private fun findMusic(): MusicLoaderResponse {
try {
val start = System.currentTimeMillis()
loadGenres()
loadArtists()
loadAlbums()
loadSongs()
logD("Done in ${System.currentTimeMillis() - start}ms")
} catch (error: Exception) {
logE("Something went horribly wrong.")
error.printStackTrace()

View file

@ -10,6 +10,7 @@ import android.os.Build
import android.support.v4.media.session.MediaSessionCompat
import androidx.core.app.NotificationCompat
import androidx.media.app.NotificationCompat.MediaStyle
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.MainActivity
import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.Song
@ -23,12 +24,14 @@ object NotificationUtils {
const val NOTIFICATION_ID = 0xA0A0
const val REQUEST_CODE = 0xA0C0
const val ACTION_LOOP = "ACTION_AUXIO_LOOP"
const val ACTION_SHUFFLE = "ACTION_AUXIO_SHUFFLE"
const val ACTION_SKIP_PREV = "ACTION_AUXIO_SKIP_PREV"
const val ACTION_PLAY_PAUSE = "ACTION_AUXIO_PLAY_PAUSE"
const val ACTION_SKIP_NEXT = "ACTION_AUXIO_SKIP_NEXT"
const val ACTION_EXIT = "ACTION_AUXIO_EXIT"
// Strings for each action, version name is applied so that broadcasts will only reach
// one instance of Auxio.
const val ACTION_LOOP = "ACTION_AUXIO_LOOP_" + BuildConfig.VERSION_NAME
const val ACTION_SHUFFLE = "ACTION_AUXIO_SHUFFLE_" + BuildConfig.VERSION_NAME
const val ACTION_SKIP_PREV = "ACTION_AUXIO_SKIP_PREV_" + BuildConfig.VERSION_NAME
const val ACTION_PLAY_PAUSE = "ACTION_AUXIO_PLAY_PAUSE_" + BuildConfig.VERSION_NAME
const val ACTION_SKIP_NEXT = "ACTION_AUXIO_SKIP_NEXT_" + BuildConfig.VERSION_NAME
const val ACTION_EXIT = "ACTION_AUXIO_EXIT_" + BuildConfig.VERSION_NAME
}
/**
@ -130,6 +133,7 @@ fun NotificationCompat.Builder.updatePlaying(context: Context) {
/**
* Update the extra action on the media notification [E.G the Loop/Shuffle button]
* @param context The context required to refresh the action
* @param useAltAction Whether to use the shuffle action or not, true if yes, false if no
*/
@SuppressLint("RestrictedApi")
fun NotificationCompat.Builder.updateExtraAction(context: Context, useAltAction: Boolean) {