1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.wm.shell.desktopmode 18 19 import android.app.ActivityManager.RunningTaskInfo 20 import android.graphics.Rect 21 import com.android.wm.shell.desktopmode.CaptionState.AppHandle 22 import com.android.wm.shell.desktopmode.CaptionState.AppHeader 23 import com.android.wm.shell.desktopmode.CaptionState.NoCaption 24 import kotlinx.coroutines.flow.MutableSharedFlow 25 import kotlinx.coroutines.flow.MutableStateFlow 26 import kotlinx.coroutines.flow.StateFlow 27 28 /** Repository to observe caption state. */ 29 class WindowDecorCaptionHandleRepository { 30 private val _captionStateFlow = MutableStateFlow<CaptionState>(CaptionState.NoCaption) 31 /** Observer for app handle state changes. */ 32 val captionStateFlow: StateFlow<CaptionState> = _captionStateFlow 33 private val _appToWebUsageFlow = MutableSharedFlow<Unit>() 34 /** Observer for App-to-Web usage. */ 35 val appToWebUsageFlow = _appToWebUsageFlow 36 37 /** Notifies [captionStateFlow] if there is a change to caption state. */ notifyCaptionChangednull38 fun notifyCaptionChanged(captionState: CaptionState) { 39 _captionStateFlow.value = captionState 40 } 41 42 /** Notifies [appToWebUsageFlow] if App-to-Web feature is used. */ onAppToWebUsagenull43 fun onAppToWebUsage() { 44 _appToWebUsageFlow.tryEmit(Unit) 45 } 46 } 47 48 /** 49 * Represents the current status of the caption. 50 * 51 * It can be one of three options: 52 * * [AppHandle]: Indicating that there is at least one visible app handle on the screen. 53 * * [AppHeader]: Indicating that there is at least one visible app chip on the screen. 54 * * [NoCaption]: Signifying that no caption handle is currently visible on the device. 55 */ 56 sealed class CaptionState { 57 data class AppHandle( 58 val runningTaskInfo: RunningTaskInfo, 59 val isHandleMenuExpanded: Boolean, 60 val globalAppHandleBounds: Rect, 61 val isCapturedLinkAvailable: Boolean, 62 ) : CaptionState() 63 64 data class AppHeader( 65 val runningTaskInfo: RunningTaskInfo, 66 val isHeaderMenuExpanded: Boolean, 67 val globalAppChipBounds: Rect, 68 val isCapturedLinkAvailable: Boolean, 69 ) : CaptionState() 70 71 data object NoCaption : CaptionState() 72 } 73