Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b46ac8c4 authored by Jernej Virag's avatar Jernej Virag Committed by Android (Google) Code Review
Browse files

Merge "Avoid bouncing user unlocked broadcast on main thread" into main

parents 7f95ae76 c1ac7060
Loading
Loading
Loading
Loading
+22 −19
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.media.controls.domain.resume

import android.annotation.WorkerThread
import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
@@ -41,6 +42,7 @@ import com.android.systemui.media.controls.util.MediaFlags
import com.android.systemui.settings.UserTracker
import com.android.systemui.tuner.TunerService
import com.android.systemui.util.Utils
import com.android.systemui.util.kotlin.logD
import com.android.systemui.util.time.SystemClock
import java.io.PrintWriter
import java.util.concurrent.ConcurrentLinkedQueue
@@ -86,11 +88,12 @@ constructor(
    @VisibleForTesting
    val userUnlockReceiver =
        object : BroadcastReceiver() {
            @WorkerThread
            override fun onReceive(context: Context, intent: Intent) {
                if (Intent.ACTION_USER_UNLOCKED == intent.action) {
                    val userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1)
                    if (userId == currentUserId) {
                        backgroundExecutor.execute { loadMediaResumptionControls() }
                        loadMediaResumptionControls()
                    }
                }
            }
@@ -109,7 +112,7 @@ constructor(
            override fun addTrack(
                desc: MediaDescription,
                component: ComponentName,
                browser: ResumeMediaBrowser
                browser: ResumeMediaBrowser,
            ) {
                val token = browser.token
                val appIntent = browser.appIntent
@@ -123,7 +126,7 @@ constructor(
                    Log.e(TAG, "Error getting package information", e)
                }

                Log.d(TAG, "Adding resume controls for ${browser.userId}: $desc")
                logD(TAG) { "Adding resume controls for ${browser.userId}: $desc" }
                mediaDataManager.addResumptionControls(
                    browser.userId,
                    desc,
@@ -131,7 +134,7 @@ constructor(
                    token,
                    appName.toString(),
                    appIntent,
                    component.packageName
                    component.packageName,
                )
            }
        }
@@ -144,8 +147,8 @@ constructor(
            broadcastDispatcher.registerReceiver(
                userUnlockReceiver,
                unlockFilter,
                null,
                UserHandle.ALL
                backgroundExecutor,
                UserHandle.ALL,
            )
            userTracker.addCallback(userTrackerCallback, mainExecutor)
            loadSavedComponents()
@@ -163,7 +166,7 @@ constructor(
                    mediaDataManager.setMediaResumptionEnabled(useMediaResumption)
                }
            },
            Settings.Secure.MEDIA_CONTROLS_RESUME
            Settings.Secure.MEDIA_CONTROLS_RESUME,
        )
    }

@@ -197,11 +200,11 @@ constructor(
                }
            resumeComponents.add(component to lastPlayed)
        }
        Log.d(
            TAG,

        logD(TAG) {
            "loaded resume components for $currentUserId: " +
                "${resumeComponents.toArray().contentToString()}"
        )
                resumeComponents.toArray().contentToString()
        }

        if (needsUpdate) {
            // Save any missing times that we had to fill in
@@ -228,7 +231,7 @@ constructor(
                        mediaBrowserFactory.create(mediaBrowserCallback, it.first, currentUserId)
                    browser.findRecentMedia()
                } else {
                    Log.d(TAG, "User $currentUserId does not have component ${it.first}")
                    logD(TAG) { "User $currentUserId does not have component ${it.first}" }
                }
            }
        }
@@ -240,7 +243,7 @@ constructor(
        data: MediaData,
        immediately: Boolean,
        receivedSmartspaceCardLatency: Int,
        isSsReactivated: Boolean
        isSsReactivated: Boolean,
    ) {
        if (useMediaResumption) {
            // If this had been started from a resume state, disconnect now that it's live
@@ -281,7 +284,7 @@ constructor(
            mediaBrowserFactory.create(
                object : ResumeMediaBrowser.Callback() {
                    override fun onConnected() {
                        Log.d(TAG, "Connected to $componentName")
                        logD(TAG) { "Connected to $componentName" }
                    }

                    override fun onError() {
@@ -292,20 +295,20 @@ constructor(
                    override fun addTrack(
                        desc: MediaDescription,
                        component: ComponentName,
                        browser: ResumeMediaBrowser
                        browser: ResumeMediaBrowser,
                    ) {
                        // Since this is a test, just save the component for later
                        Log.d(
                            TAG,
                        logD(TAG) {
                            "Can get resumable media for ${browser.userId} from $componentName"
                        )
                        }

                        mediaDataManager.setResumeAction(key, getResumeAction(componentName))
                        updateResumptionList(componentName)
                        mediaBrowser = null
                    }
                },
                componentName,
                currentUserId
                currentUserId,
            )
        mediaBrowser?.testConnection()
    }