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.systemui.screenshot.data.repository 18 19 import android.annotation.SuppressLint 20 import android.app.ActivityTaskManager 21 import android.app.IActivityTaskManager 22 import com.android.systemui.dagger.qualifiers.Background 23 import com.android.systemui.screenshot.data.model.DisplayContentModel 24 import com.android.systemui.screenshot.data.model.SystemUiState 25 import com.android.systemui.screenshot.proxy.SystemUiProxy 26 import javax.inject.Inject 27 import kotlinx.coroutines.CoroutineDispatcher 28 import kotlinx.coroutines.withContext 29 30 /** 31 * Implements DisplayTaskRepository using [IActivityTaskManager], along with [ProfileTypeRepository] 32 * and [SystemUiProxy]. 33 */ 34 @SuppressLint("MissingPermission") 35 class DisplayContentRepositoryImpl 36 @Inject 37 constructor( 38 private val atmService: IActivityTaskManager, 39 private val systemUiProxy: SystemUiProxy, 40 @Background private val background: CoroutineDispatcher, 41 ) : DisplayContentRepository { 42 getDisplayContentnull43 override suspend fun getDisplayContent(displayId: Int): DisplayContentModel { 44 return withContext(background) { 45 val rootTasks = atmService.getAllRootTaskInfosOnDisplay(displayId) 46 toDisplayTasksModel(displayId, rootTasks) 47 } 48 } 49 toDisplayTasksModelnull50 private suspend fun toDisplayTasksModel( 51 displayId: Int, 52 rootTasks: List<ActivityTaskManager.RootTaskInfo>, 53 ): DisplayContentModel { 54 return DisplayContentModel( 55 displayId, 56 SystemUiState(systemUiProxy.isNotificationShadeExpanded()), 57 rootTasks 58 ) 59 } 60 } 61