Skip to content

Commit

Permalink
Add additional logging around legacy source connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhanniballake committed Jun 29, 2019
1 parent 3e7aa15 commit dae0b77
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Expand Up @@ -116,28 +116,46 @@ class LegacySourceService : Service(), LifecycleOwner {
Messenger(Handler { message ->
when (message.what) {
LegacySourceServiceProtocol.WHAT_REGISTER_REPLY_TO -> {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Registered")
}
replyToMessenger = message.replyTo
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
}
LegacySourceServiceProtocol.WHAT_NEXT_ARTWORK -> lifecycleScope.launch(singleThreadContext) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Got next artwork command")
}
val database = LegacyDatabase.getInstance(applicationContext)
val source = database.sourceDao().getCurrentSource()
if (source?.supportsNextArtwork == true) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Sending next artwork command to ${source.componentName}")
}
source.sendAction(this@LegacySourceService,
MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK)
}
}
LegacySourceServiceProtocol.WHAT_ALLOWS_NEXT_ARTWORK -> {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Got allows next artwork")
}
val replyMessenger = message.replyTo
lifecycleScope.launch(singleThreadContext) {
val allowsNextArtwork = LegacyDatabase.getInstance(applicationContext)
.sourceDao().getCurrentSource()?.supportsNextArtwork == true
if (BuildConfig.DEBUG) {
Log.d(TAG, "Sending allows next artwork of $allowsNextArtwork")
}
replyMessenger.send(Message.obtain().apply {
arg1 = if (allowsNextArtwork) 1 else 0
})
}
}
LegacySourceServiceProtocol.WHAT_UNREGISTER_REPLY_TO -> {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Unregistered")
}
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
replyToMessenger = null
}
Expand Down
Expand Up @@ -54,11 +54,17 @@ internal class LegacySourceServiceConnection(
when (message.what) {
LegacySourceServiceProtocol.WHAT_REPLY_TO_REPLACEMENT -> {
val authority = message.obj as String
if (BuildConfig.DEBUG) {
Log.d(TAG, "Got replacement message for $authority")
}
GlobalScope.launch {
ProviderManager.select(applicationContext, authority)
}
}
LegacySourceServiceProtocol.WHAT_REPLY_TO_NO_SELECTED_SOURCE -> GlobalScope.launch {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Got no selected source message")
}
ProviderManager.select(applicationContext, FEATURED_ART_AUTHORITY)
}
}
Expand Down Expand Up @@ -108,6 +114,9 @@ internal class LegacySourceServiceConnection(
val messenger = this.messenger ?: return
if (!registered) {
registered = true
if (BuildConfig.DEBUG) {
Log.d(TAG, "Sending register message")
}
messenger.send(Message.obtain().apply {
what = LegacySourceServiceProtocol.WHAT_REGISTER_REPLY_TO
replyTo = replyToMessenger
Expand All @@ -128,9 +137,15 @@ internal class LegacySourceServiceConnection(
when(val messenger = this.messenger) {
null -> cont.resume(false)
else -> {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Sending allows next artwork message")
}
messenger.send(Message.obtain().apply {
what = LegacySourceServiceProtocol.WHAT_ALLOWS_NEXT_ARTWORK
replyTo = Messenger(Handler(Looper.getMainLooper()) { message ->
if (BuildConfig.DEBUG) {
Log.d(TAG, "Answered allows next artwork ${message.arg1 == 1}")
}
cont.resume(message.arg1 == 1)
true
})
Expand All @@ -143,6 +158,9 @@ internal class LegacySourceServiceConnection(
// Only unregister if we're connected
val messenger = this.messenger ?: return
if (registered) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Sending unregister message")
}
messenger.send(Message.obtain().apply {
what = LegacySourceServiceProtocol.WHAT_UNREGISTER_REPLY_TO
})
Expand Down

0 comments on commit dae0b77

Please sign in to comment.