From 5ceaf6c56b415b049c2306f2fad6068a4a6091ec Mon Sep 17 00:00:00 2001 From: Beth Thibodeau Date: Wed, 24 May 2023 15:05:04 -0500 Subject: [PATCH] Keep smartspace session object The object was getting prematurely optimized out because it wasn't referenced in code later, but it is necessary to keep alive in order to get recommendation updates. Add annotation to make sure it's kept, and explicitly close when destroy is called Bug: 273739913 Bug: 283493228 Test: manual - verify session is not destroyed after restarting SysUI Change-Id: I98bd7ce5878f9f261e1c09673faaae35e954f173 --- .../systemui/media/controls/pipeline/MediaDataManager.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt index 1469d96dd3e8d..4320785ec7c83 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt @@ -52,6 +52,7 @@ import android.text.TextUtils import android.util.Log import android.util.Pair as APair import androidx.media.utils.MediaConstants +import com.android.internal.annotations.Keep import com.android.internal.logging.InstanceId import com.android.internal.statusbar.IStatusBarService import com.android.keyguard.KeyguardUpdateMonitor @@ -220,7 +221,7 @@ class MediaDataManager( private val mediaEntries: LinkedHashMap = LinkedHashMap() // There should ONLY be at most one Smartspace media recommendation. var smartspaceMediaData: SmartspaceMediaData = EMPTY_SMARTSPACE_MEDIA_DATA - private var smartspaceSession: SmartspaceSession? = null + @Keep private var smartspaceSession: SmartspaceSession? = null private var allowMediaRecommendations = allowMediaRecommendations(context) private val artworkWidth = @@ -380,6 +381,8 @@ class MediaDataManager( fun destroy() { smartspaceMediaDataProvider.unregisterListener(this) + smartspaceSession?.close() + smartspaceSession = null context.unregisterReceiver(appChangeReceiver) }