Remove MediaData object reference
We don't need the entire data here, just the token and resumption status. Keeping the object will also retain a reference to the artwork which can take up a lot of memory. Bug: 234742314 Test: atest MediaTimeoutListenerTest Test: compare hprof after - no longer in MediaTimeoutListener Change-Id: Ic17dc19227f69c567624df225ac14d7490a9180d
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.android.systemui.media.controls.pipeline
|
||||
|
||||
import android.media.session.MediaController
|
||||
import android.media.session.MediaSession
|
||||
import android.media.session.PlaybackState
|
||||
import android.os.SystemProperties
|
||||
import com.android.internal.annotations.VisibleForTesting
|
||||
@@ -148,7 +149,7 @@ constructor(
|
||||
reusedListener?.let {
|
||||
val wasPlaying = it.isPlaying()
|
||||
logger.logUpdateListener(key, wasPlaying)
|
||||
it.mediaData = data
|
||||
it.setMediaData(data)
|
||||
it.key = key
|
||||
mediaListeners[key] = it
|
||||
if (wasPlaying != it.isPlaying()) {
|
||||
@@ -208,24 +209,7 @@ constructor(
|
||||
var resumption: Boolean? = null
|
||||
var destroyed = false
|
||||
var expiration = Long.MAX_VALUE
|
||||
|
||||
var mediaData: MediaData = data
|
||||
set(value) {
|
||||
destroyed = false
|
||||
mediaController?.unregisterCallback(this)
|
||||
field = value
|
||||
val token = field.token
|
||||
mediaController =
|
||||
if (token != null) {
|
||||
mediaControllerFactory.create(token)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
mediaController?.registerCallback(this)
|
||||
// Let's register the cancellations, but not dispatch events now.
|
||||
// Timeouts didn't happen yet and reentrant events are troublesome.
|
||||
processState(mediaController?.playbackState, dispatchEvents = false)
|
||||
}
|
||||
var sessionToken: MediaSession.Token? = null
|
||||
|
||||
// Resume controls may have null token
|
||||
private var mediaController: MediaController? = null
|
||||
@@ -236,7 +220,7 @@ constructor(
|
||||
fun isPlaying() = lastState?.state?.isPlaying() ?: false
|
||||
|
||||
init {
|
||||
mediaData = data
|
||||
setMediaData(data)
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
@@ -245,8 +229,28 @@ constructor(
|
||||
destroyed = true
|
||||
}
|
||||
|
||||
fun setMediaData(data: MediaData) {
|
||||
sessionToken = data.token
|
||||
destroyed = false
|
||||
mediaController?.unregisterCallback(this)
|
||||
mediaController =
|
||||
if (data.token != null) {
|
||||
mediaControllerFactory.create(data.token)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
mediaController?.registerCallback(this)
|
||||
// Let's register the cancellations, but not dispatch events now.
|
||||
// Timeouts didn't happen yet and reentrant events are troublesome.
|
||||
processState(
|
||||
mediaController?.playbackState,
|
||||
dispatchEvents = false,
|
||||
currentResumption = data.resumption,
|
||||
)
|
||||
}
|
||||
|
||||
override fun onPlaybackStateChanged(state: PlaybackState?) {
|
||||
processState(state, dispatchEvents = true)
|
||||
processState(state, dispatchEvents = true, currentResumption = resumption)
|
||||
}
|
||||
|
||||
override fun onSessionDestroyed() {
|
||||
@@ -263,14 +267,18 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun processState(state: PlaybackState?, dispatchEvents: Boolean) {
|
||||
private fun processState(
|
||||
state: PlaybackState?,
|
||||
dispatchEvents: Boolean,
|
||||
currentResumption: Boolean?,
|
||||
) {
|
||||
logger.logPlaybackState(key, state)
|
||||
|
||||
val playingStateSame = (state?.state?.isPlaying() == isPlaying())
|
||||
val actionsSame =
|
||||
(lastState?.actions == state?.actions) &&
|
||||
areCustomActionListsEqual(lastState?.customActions, state?.customActions)
|
||||
val resumptionChanged = resumption != mediaData.resumption
|
||||
val resumptionChanged = resumption != currentResumption
|
||||
|
||||
lastState = state
|
||||
|
||||
@@ -282,7 +290,7 @@ constructor(
|
||||
if (playingStateSame && !resumptionChanged) {
|
||||
return
|
||||
}
|
||||
resumption = mediaData.resumption
|
||||
resumption = currentResumption
|
||||
|
||||
val playing = isPlaying()
|
||||
if (!playing) {
|
||||
@@ -294,7 +302,7 @@ constructor(
|
||||
}
|
||||
expireMediaTimeout(key, "PLAYBACK STATE CHANGED - $state, $resumption")
|
||||
val timeout =
|
||||
if (mediaData.resumption) {
|
||||
if (currentResumption == true) {
|
||||
RESUME_MEDIA_TIMEOUT
|
||||
} else {
|
||||
PAUSED_MEDIA_TIMEOUT
|
||||
|
||||
Reference in New Issue
Block a user