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

Commit 197a79fe authored by Michael Mikhail's avatar Michael Mikhail
Browse files

Add media model and interface for media repository.

This CL adds a smaller version for media data. Fields used in sorting are not needed in MediaInteractor.

Flag: com.android.systemui.media_controls_in_compose
Bug: 397989775
Test: build.
Change-Id: I0bf0d70e6b374da986740e742a98f11b152e537d
parent 6114bde6
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.media.remedia.data.model

import android.app.PendingIntent
import android.media.session.MediaController
import com.android.internal.logging.InstanceId
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.media.controls.shared.model.MediaButton
import com.android.systemui.media.controls.shared.model.MediaDeviceData
import com.android.systemui.media.controls.shared.model.MediaNotificationAction

/** Data model representing a media data. */
data class MediaDataModel(
    /** Instance ID for logging purposes */
    val instanceId: InstanceId,
    /** The UID of the app, used for logging. */
    val appUid: Int,
    /** Package name of the app that's posting the media, used for logging. */
    val packageName: String,
    val appName: String,
    val appIcon: Icon,
    val background: Icon?,
    val title: String,
    val subtitle: String,
    /** List of generic action buttons for the media player, based on notification actions */
    val notificationActions: List<MediaNotificationAction>,
    /**
     * Semantic actions buttons, based on the PlaybackState of the media session. If present, these
     * actions will be preferred in the UI over [notificationActions]
     */
    val playbackStateActions: MediaButton,
    /** Where the media is playing: phone, headphones, ear buds, remote session. */
    val outputDevice: MediaDeviceData,
    /** Action to perform when the media player is tapped. */
    val clickIntent: PendingIntent?,
    val controller: MediaController,
    val canBeDismissed: Boolean,
    /**
     * An active player represents a current media session that has not timed out or been swiped
     * away by the user.
     */
    val isActive: Boolean,
    /**
     * Indicates that this player is a resumption player (ie. It only shows a play actions which
     * will start the app and start playing).
     */
    val isResume: Boolean,
    /** Action that should be performed to restart a non active session. */
    val resumeAction: Runnable?,
    val isExplicit: Boolean,
)
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.media.remedia.data.repository

import com.android.internal.logging.InstanceId
import com.android.systemui.media.controls.shared.model.MediaData
import com.android.systemui.media.remedia.data.model.MediaDataModel
import kotlinx.coroutines.flow.StateFlow

interface MediaRepository {
    /** Current sorted media sessions. */
    val currentMedia: StateFlow<List<MediaDataModel>>

    fun addMediaEntry(key: String, data: MediaData)

    /**
     * Removes the media entry corresponding to the given [key].
     *
     * @return media data if an entry is actually removed, `null` otherwise.
     */
    fun removeMediaEntry(key: String): MediaData?

    /** @return whether the added media data already exists. */
    fun addCurrentUserMediaEntry(data: MediaData): Boolean

    /**
     * Removes current user media entry given the corresponding [key].
     *
     * @return media data if an entry is actually removed, `null` otherwise.
     */
    fun removeCurrentUserMediaEntry(key: InstanceId): MediaData?

    fun clearCurrentUserMedia()

    /** Seek to [to], in milliseconds on the media session with the given [sessionKey]. */
    fun seek(sessionKey: InstanceId, to: Long)
}