From 778f1a1c2dfbfe253d02f36293a23a0d6d5b0aa4 Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Wed, 20 Mar 2024 21:12:22 -0400 Subject: DisplayContentRepository This is a replacement for the existing `ScreenshotPolicy` class: fun findPrimaryContent(displayId: Int): DisplayContentInfo The existing code was a little too narrow focused on a single policy, and returns only the top facing task/activity information. For flexibility, all root tasks are provided in DisplayContentModel as well as some support code for filtering and testing. This also incorporates SystemUiState which provides information fetched over binder from the main SystemUI process via SystemUiProxy Test: TODO Bug: 327613051 Flag: N/A; not used yet Change-Id: Ideee0d1891bfb28404127ba6428162a98eeb9b99 --- .../screenshot/data/model/DisplayContentModel.kt | 29 +++++++++++ .../screenshot/data/model/SystemUiState.kt | 20 ++++++++ .../data/repository/DisplayContentRepository.kt | 24 +++++++++ .../repository/DisplayContentRepositoryImpl.kt | 60 ++++++++++++++++++++++ .../screenshot/policy/ScreenshotPolicyModule.kt | 6 +++ 5 files changed, 139 insertions(+) create mode 100644 packages/SystemUI/src/com/android/systemui/screenshot/data/model/DisplayContentModel.kt create mode 100644 packages/SystemUI/src/com/android/systemui/screenshot/data/model/SystemUiState.kt create mode 100644 packages/SystemUI/src/com/android/systemui/screenshot/data/repository/DisplayContentRepository.kt create mode 100644 packages/SystemUI/src/com/android/systemui/screenshot/data/repository/DisplayContentRepositoryImpl.kt diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/data/model/DisplayContentModel.kt b/packages/SystemUI/src/com/android/systemui/screenshot/data/model/DisplayContentModel.kt new file mode 100644 index 000000000000..837a661230cb --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/screenshot/data/model/DisplayContentModel.kt @@ -0,0 +1,29 @@ +/* + * 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.screenshot.data.model + +import android.app.ActivityTaskManager.RootTaskInfo + +/** Information about the tasks on a display. */ +data class DisplayContentModel( + /** The id of the display. */ + val displayId: Int, + /** Information about the current System UI state which can affect capture. */ + val systemUiState: SystemUiState, + /** A list of root tasks on the display, ordered from bottom to top along the z-axis */ + val rootTasks: List, +) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/data/model/SystemUiState.kt b/packages/SystemUI/src/com/android/systemui/screenshot/data/model/SystemUiState.kt new file mode 100644 index 000000000000..78be6bdda292 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/screenshot/data/model/SystemUiState.kt @@ -0,0 +1,20 @@ +/* + * 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.screenshot.data.model + +/** Information about SystemUI state relevant to screenshot policy. */ +data class SystemUiState(val shadeExpanded: Boolean) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/data/repository/DisplayContentRepository.kt b/packages/SystemUI/src/com/android/systemui/screenshot/data/repository/DisplayContentRepository.kt new file mode 100644 index 000000000000..9c81b322a2b7 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/screenshot/data/repository/DisplayContentRepository.kt @@ -0,0 +1,24 @@ +/* + * 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.screenshot.data.repository + +import com.android.systemui.screenshot.data.model.DisplayContentModel + +/** Provides information about tasks related to a display. */ +interface DisplayContentRepository { + /** Provides information about the tasks and content presented on a given display. */ + suspend fun getDisplayContent(displayId: Int): DisplayContentModel +} diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/data/repository/DisplayContentRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/screenshot/data/repository/DisplayContentRepositoryImpl.kt new file mode 100644 index 000000000000..e9599dcb026d --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/screenshot/data/repository/DisplayContentRepositoryImpl.kt @@ -0,0 +1,60 @@ +/* + * 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.screenshot.data.repository + +import android.annotation.SuppressLint +import android.app.ActivityTaskManager +import android.app.IActivityTaskManager +import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.screenshot.data.model.DisplayContentModel +import com.android.systemui.screenshot.data.model.SystemUiState +import com.android.systemui.screenshot.proxy.SystemUiProxy +import javax.inject.Inject +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.withContext + +/** + * Implements DisplayTaskRepository using [IActivityTaskManager], along with [ProfileTypeRepository] + * and [SystemUiProxy]. + */ +@SuppressLint("MissingPermission") +class DisplayContentRepositoryImpl +@Inject +constructor( + private val atmService: IActivityTaskManager, + private val systemUiProxy: SystemUiProxy, + @Background private val background: CoroutineDispatcher, +) : DisplayContentRepository { + + override suspend fun getDisplayContent(displayId: Int): DisplayContentModel { + return withContext(background) { + val rootTasks = atmService.getAllRootTaskInfosOnDisplay(displayId) + toDisplayTasksModel(displayId, rootTasks) + } + } + + private suspend fun toDisplayTasksModel( + displayId: Int, + rootTasks: List, + ): DisplayContentModel { + return DisplayContentModel( + displayId, + SystemUiState(systemUiProxy.isNotificationShadeExpanded()), + rootTasks + ) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/policy/ScreenshotPolicyModule.kt b/packages/SystemUI/src/com/android/systemui/screenshot/policy/ScreenshotPolicyModule.kt index 39b07e3a396a..bc71ab71b626 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/policy/ScreenshotPolicyModule.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/policy/ScreenshotPolicyModule.kt @@ -21,6 +21,8 @@ import com.android.systemui.screenshot.ImageCapture import com.android.systemui.screenshot.RequestProcessor import com.android.systemui.screenshot.ScreenshotPolicy import com.android.systemui.screenshot.ScreenshotRequestProcessor +import com.android.systemui.screenshot.data.repository.DisplayContentRepository +import com.android.systemui.screenshot.data.repository.DisplayContentRepositoryImpl import com.android.systemui.screenshot.data.repository.ProfileTypeRepository import com.android.systemui.screenshot.data.repository.ProfileTypeRepositoryImpl import dagger.Binds @@ -45,4 +47,8 @@ interface ScreenshotPolicyModule { return RequestProcessor(imageCapture, policyProvider.get()) } } + + @Binds + @SysUISingleton + fun bindDisplayContentRepository(impl: DisplayContentRepositoryImpl): DisplayContentRepository } -- cgit v1.2.3-59-g8ed1b