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

Commit fbc3ba8b authored by Mark Renouf's avatar Mark Renouf Committed by Android (Google) Code Review
Browse files

Merge "DisplayContentRepository" into main

parents f67efebd 778f1a1c
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
}