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

Commit 91f85e13 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge changes Ic3ce1b9d,I5f4b9817 into main

* changes:
  [SB][Screen Chips] Add share-to-app and cast-to-other-device chips.
  [SB][Screen Chips] Hook up new chip flow to CollapsedStatusBarFragment.
parents 0cef8ce9 6b2e287b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@

        <ImageView
            android:src="@*android:drawable/ic_phone"
            android:id="@+id/ongoing_activity_chip_icon"
            android:layout_width="@dimen/ongoing_activity_chip_icon_size"
            android:layout_height="@dimen/ongoing_activity_chip_icon_size"
            android:tint="?android:attr/colorPrimary"
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.statusbar.chips.mediaprojection.domain.interactor

import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.mediaprojection.data.model.MediaProjectionState
import com.android.systemui.mediaprojection.data.repository.MediaProjectionRepository
import com.android.systemui.res.R
import com.android.systemui.statusbar.chips.domain.interactor.OngoingActivityChipInteractor
import com.android.systemui.statusbar.chips.domain.model.OngoingActivityChipModel
import com.android.systemui.util.time.SystemClock
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn

/**
 * Interactor for media-projection-related chips in the status bar.
 *
 * There are two kinds of media projection events that will show chips in the status bar:
 * 1) Share-to-app: Sharing your phone screen content to another app on the same device. (Triggered
 *    from within each individual app.)
 * 2) Cast-to-other-device: Sharing your phone screen content to a different device. (Triggered from
 *    the Quick Settings Cast tile or from the Settings app.) This interactor handles both of those
 *    event types (though maybe not audio-only casting -- see b/342169876).
 */
@SysUISingleton
class MediaProjectionChipInteractor
@Inject
constructor(
    @Application scope: CoroutineScope,
    mediaProjectionRepository: MediaProjectionRepository,
    val systemClock: SystemClock,
) : OngoingActivityChipInteractor {
    override val chip: StateFlow<OngoingActivityChipModel> =
        mediaProjectionRepository.mediaProjectionState
            .map { state ->
                when (state) {
                    is MediaProjectionState.NotProjecting -> OngoingActivityChipModel.Hidden
                    is MediaProjectionState.EntireScreen,
                    is MediaProjectionState.SingleTask -> {
                        // TODO(b/332662551): Distinguish between cast-to-other-device and
                        // share-to-app.
                        OngoingActivityChipModel.Shown(
                            icon =
                                Icon.Resource(
                                    R.drawable.ic_cast_connected,
                                    ContentDescription.Resource(R.string.accessibility_casting)
                                ),
                            // TODO(b/332662551): See if we can use a MediaProjection API to fetch
                            // this time.
                            startTimeMs = systemClock.elapsedRealtime()
                        ) {
                            // TODO(b/332662551): Implement the pause dialog.
                        }
                    }
                }
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), OngoingActivityChipModel.Hidden)
}
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import kotlinx.coroutines.flow.stateIn

/** Interactor for the screen recording chip shown in the status bar. */
@SysUISingleton
open class ScreenRecordChipInteractor
class ScreenRecordChipInteractor
@Inject
constructor(
    @Application scope: CoroutineScope,
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.statusbar.chips.ui.binder

import com.android.systemui.statusbar.chips.ui.view.ChipChronometer

object ChipChronometerBinder {
    /**
     * Updates the given [view] chronometer with a new start time and starts it.
     *
     * @param startTimeMs the time this event started, relative to
     *   [com.android.systemui.util.time.SystemClock.elapsedRealtime]. See
     *   [android.widget.Chronometer.setBase].
     */
    fun bind(startTimeMs: Long, view: ChipChronometer) {
        view.base = startTimeMs
        view.start()
    }
}
+12 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.chips.call.domain.interactor.CallChipInteractor
import com.android.systemui.statusbar.chips.domain.model.OngoingActivityChipModel
import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractor
import com.android.systemui.statusbar.chips.screenrecord.domain.interactor.ScreenRecordChipInteractor
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -40,6 +41,7 @@ class OngoingActivityChipsViewModel
constructor(
    @Application scope: CoroutineScope,
    screenRecordChipInteractor: ScreenRecordChipInteractor,
    mediaProjectionChipInteractor: MediaProjectionChipInteractor,
    callChipInteractor: CallChipInteractor,
) {

@@ -51,10 +53,19 @@ constructor(
     * actually displaying the chip.
     */
    val chip: StateFlow<OngoingActivityChipModel> =
        combine(screenRecordChipInteractor.chip, callChipInteractor.chip) { screenRecord, call ->
        combine(
                screenRecordChipInteractor.chip,
                mediaProjectionChipInteractor.chip,
                callChipInteractor.chip
            ) { screenRecord, mediaProjection, call ->
                // This `when` statement shows the priority order of the chips
                when {
                    // Screen recording also activates the media projection APIs, so whenever the
                    // screen recording chip is active, the media projection chip would also be
                    // active. We want the screen-recording-specific chip shown in this case, so we
                    // give the screen recording chip priority. See b/296461748.
                    screenRecord is OngoingActivityChipModel.Shown -> screenRecord
                    mediaProjection is OngoingActivityChipModel.Shown -> mediaProjection
                    else -> call
                }
            }
Loading