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

Commit dd6ab19b authored by Beth Thibodeau's avatar Beth Thibodeau
Browse files

Check for progress info from resume controls

Progress information can be specified by apps using extra keys in their
MediaDescription. This checks those fields for progress data and sets
the seekbar for resume controls.

Fixes: 264691253
Test: atest MediaDataManagerTest MediaControlPanelTest
Test: manual with test app
Change-Id: I52617fe6007c8a60560724bb6672aa8ec8630c88
parent 121599e6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -369,6 +369,9 @@ object Flags {
    @JvmField
    val MEDIA_RECOMMENDATION_CARD_UPDATE = unreleasedFlag(914, "media_recommendation_card_update")

    // TODO(b/267007629): Tracking Bug
    val MEDIA_RESUME_PROGRESS = unreleasedFlag(915, "media_resume_progress")

    // 1000 - dock
    val SIMULATE_DOCK_THROUGH_CHARGING = releasedFlag(1000, "simulate_dock_through_charging")

+3 −0
Original line number Diff line number Diff line
@@ -92,6 +92,9 @@ data class MediaData(

    /** Whether explicit indicator exists */
    val isExplicit: Boolean = false,

    /** Track progress (0 - 1) to display for players where [resumption] is true */
    val resumeProgress: Double? = null,
) {
    companion object {
        /** Media is playing on the local device */
+18 −0
Original line number Diff line number Diff line
@@ -237,6 +237,24 @@ constructor(
        checkIfPollingNeeded()
    }

    /**
     * Set the progress to a fixed percentage value that cannot be changed by the user.
     *
     * @param percent value between 0 and 1
     */
    fun updateStaticProgress(percent: Double) {
        val position = (percent * 100).toInt()
        _data =
            Progress(
                enabled = true,
                seekAvailable = false,
                playing = false,
                scrubbing = false,
                elapsedTime = position,
                duration = 100,
            )
    }

    /**
     * Puts the seek bar into a resumption state.
     *
+7 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.systemui.media.controls.models.recommendation.SmartspaceMedia
import com.android.systemui.media.controls.models.recommendation.SmartspaceMediaDataProvider
import com.android.systemui.media.controls.resume.MediaResumeListener
import com.android.systemui.media.controls.util.MediaControllerFactory
import com.android.systemui.media.controls.util.MediaDataUtils
import com.android.systemui.media.controls.util.MediaFlags
import com.android.systemui.media.controls.util.MediaUiEventLogger
import com.android.systemui.plugins.ActivityStarter
@@ -667,6 +668,11 @@ class MediaDataManager(
                MediaConstants.METADATA_VALUE_ATTRIBUTE_PRESENT &&
                mediaFlags.isExplicitIndicatorEnabled()

        val progress =
            if (mediaFlags.isResumeProgressEnabled()) {
                MediaDataUtils.getDescriptionProgress(desc.extras)
            } else null

        val mediaAction = getResumeMediaAction(resumeAction)
        val lastActive = systemClock.elapsedRealtime()
        foregroundExecutor.execute {
@@ -697,6 +703,7 @@ class MediaDataManager(
                    instanceId = instanceId,
                    appUid = appUid,
                    isExplicit = isExplicit,
                    resumeProgress = progress,
                )
            )
        }
+8 −4
Original line number Diff line number Diff line
@@ -115,8 +115,6 @@ import com.android.systemui.util.animation.TransitionLayout;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.time.SystemClock;

import dagger.Lazy;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
@@ -124,6 +122,7 @@ import java.util.concurrent.Executor;

import javax.inject.Inject;

import dagger.Lazy;
import kotlin.Triple;
import kotlin.Unit;

@@ -523,8 +522,13 @@ public class MediaControlPanel {
        }

        // Seek Bar
        if (data.getResumption() && data.getResumeProgress() != null) {
            double progress = data.getResumeProgress();
            mSeekBarViewModel.updateStaticProgress(progress);
        } else {
            final MediaController controller = getController();
            mBackgroundExecutor.execute(() -> mSeekBarViewModel.updateController(controller));
        }

        // Show the broadcast dialog button only when the le audio is enabled.
        mShowBroadcastDialogButton =
Loading