1 package com.android.systemui.media 2 3 import android.app.smartspace.SmartspaceTarget 4 import com.android.systemui.plugins.BcSmartspaceDataPlugin 5 import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceTargetListener 6 import javax.inject.Inject 7 8 /** Provides SmartspaceTargets of media types for SystemUI media control. */ 9 class SmartspaceMediaDataProvider @Inject constructor() : BcSmartspaceDataPlugin { 10 11 private val smartspaceMediaTargetListeners: MutableList<SmartspaceTargetListener> = 12 mutableListOf() 13 private var smartspaceMediaTargets: List<SmartspaceTarget> = listOf() 14 registerListenernull15 override fun registerListener(smartspaceTargetListener: SmartspaceTargetListener) { 16 smartspaceMediaTargetListeners.add(smartspaceTargetListener) 17 } 18 unregisterListenernull19 override fun unregisterListener(smartspaceTargetListener: SmartspaceTargetListener?) { 20 smartspaceMediaTargetListeners.remove(smartspaceTargetListener) 21 } 22 23 /** Updates Smartspace data and propagates it to any listeners. */ onTargetsAvailablenull24 override fun onTargetsAvailable(targets: List<SmartspaceTarget>) { 25 // Filter out non-media targets. 26 val mediaTargets = mutableListOf<SmartspaceTarget>() 27 for (target in targets) { 28 val smartspaceTarget = target 29 if (smartspaceTarget.featureType == SmartspaceTarget.FEATURE_MEDIA) { 30 mediaTargets.add(smartspaceTarget) 31 } 32 } 33 34 smartspaceMediaTargets = mediaTargets 35 smartspaceMediaTargetListeners.forEach { 36 it.onSmartspaceTargetsUpdated(smartspaceMediaTargets) 37 } 38 } 39 } 40