Skip to content
Permalink
Browse files

Discover the LegacySourceService

Instead of having a direct class reference to the LegacySourceService, discover it via an action.
  • Loading branch information...
ianhanniballake committed Jun 3, 2019
1 parent f8b21cd commit 5eb2e41643b7a3f3e178047d54f53f8d8216f9b1
@@ -20,6 +20,8 @@ package com.google.android.apps.muzei.legacy
* Constants used as the protocol to communicate with the LegacySourceService.
*/
object LegacySourceServiceProtocol {
const val LEGACY_SOURCE_ACTION = "com.google.android.apps.muzei.legacy"

const val WHAT_REGISTER_REPLY_TO = 0
const val WHAT_UNREGISTER_REPLY_TO = 1
const val WHAT_NEXT_ARTWORK = 2
@@ -83,7 +83,13 @@
android:value="com.google.android.apps.muzei.legacy.SourceSetupActivity" />
</provider>

<service android:name="com.google.android.apps.muzei.legacy.LegacySourceService"/>
<service
android:name="com.google.android.apps.muzei.legacy.LegacySourceService"
android:permission="com.google.android.apps.muzei.api.ACCESS_PROVIDER">
<intent-filter>
<action android:name="com.google.android.apps.muzei.legacy"/>
</intent-filter>
</service>

<service
android:name="com.google.android.apps.muzei.sources.SourceSubscriberService"
@@ -30,7 +30,6 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.observe
import com.google.android.apps.muzei.featuredart.BuildConfig.FEATURED_ART_AUTHORITY
import com.google.android.apps.muzei.legacy.LegacySourceService
import com.google.android.apps.muzei.legacy.LegacySourceServiceProtocol
import com.google.android.apps.muzei.room.MuzeiDatabase
import com.google.android.apps.muzei.room.Provider
@@ -123,9 +122,24 @@ class LegacySourceManager(private val applicationContext: Context) : DefaultLife

private fun bindService() {
if (messenger == null) {
val pm = applicationContext.packageManager
val serviceInfo = pm.queryIntentServices(
Intent(LegacySourceServiceProtocol.LEGACY_SOURCE_ACTION), 0)
?.get(0)
?.serviceInfo
if (serviceInfo == null) {
if (BuildConfig.DEBUG) {
Log.e(TAG, "Could not find LegacySourceService")
}
return
}
val binding = applicationContext.bindService(
Intent(applicationContext, LegacySourceService::class.java),
serviceConnection, Context.BIND_AUTO_CREATE)
Intent().apply { component = ComponentName(
serviceInfo.packageName,
serviceInfo.name
)},
serviceConnection,
Context.BIND_AUTO_CREATE)
if (BuildConfig.DEBUG) {
if (binding) {
Log.d(TAG, "Binding to LegacySourceService")

0 comments on commit 5eb2e41

Please sign in to comment.
You can’t perform that action at this time.