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

Commit 778f1a1c authored by Mark Renouf's avatar Mark Renouf
Browse files

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
parent e533d851
Loading
Loading
Loading
Loading
+29 −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.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<RootTaskInfo>,
)
+20 −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.screenshot.data.model

/** Information about SystemUI state relevant to screenshot policy. */
data class SystemUiState(val shadeExpanded: Boolean)
+24 −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.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
}
+60 −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.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<ActivityTaskManager.RootTaskInfo>,
    ): DisplayContentModel {
        return DisplayContentModel(
            displayId,
            SystemUiState(systemUiProxy.isNotificationShadeExpanded()),
            rootTasks
        )
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -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
}