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

Commit 29986ccd authored by Ats Jenk's avatar Ats Jenk Committed by Automerger Merge Worker
Browse files

Merge "Create a Kotlin class for using protolog in wmshell" into udc-dev am:...

Merge "Create a Kotlin class for using protolog in wmshell" into udc-dev am: 58f9a599 am: 7025fd12

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23043736



Change-Id: Ifd0738b5f57c4271976dca65986566a764bbc78b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents fe12beb5 7025fd12
Loading
Loading
Loading
Loading
+14 −14
Original line number Original line Diff line number Diff line
@@ -39,7 +39,6 @@ import android.window.TransitionRequestInfo
import android.window.WindowContainerToken
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import android.window.WindowContainerTransaction
import androidx.annotation.BinderThread
import androidx.annotation.BinderThread
import com.android.internal.protolog.common.ProtoLog
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayController
@@ -56,6 +55,7 @@ import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.sysui.ShellSharedConstants
import com.android.wm.shell.sysui.ShellSharedConstants
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.util.KtProtoLog
import java.util.concurrent.Executor
import java.util.concurrent.Executor
import java.util.function.Consumer
import java.util.function.Consumer


@@ -91,7 +91,7 @@ class DesktopTasksController(
    }
    }


    private fun onInit() {
    private fun onInit() {
        ProtoLog.d(WM_SHELL_DESKTOP_MODE, "Initialize DesktopTasksController")
        KtProtoLog.d(WM_SHELL_DESKTOP_MODE, "Initialize DesktopTasksController")
        shellController.addExternalInterface(
        shellController.addExternalInterface(
            ShellSharedConstants.KEY_EXTRA_SHELL_DESKTOP_MODE,
            ShellSharedConstants.KEY_EXTRA_SHELL_DESKTOP_MODE,
            { createExternalInterface() },
            { createExternalInterface() },
@@ -102,7 +102,7 @@ class DesktopTasksController(


    /** Show all tasks, that are part of the desktop, on top of launcher */
    /** Show all tasks, that are part of the desktop, on top of launcher */
    fun showDesktopApps(displayId: Int) {
    fun showDesktopApps(displayId: Int) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "showDesktopApps")
        KtProtoLog.v(WM_SHELL_DESKTOP_MODE, "showDesktopApps")
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        // TODO(b/278084491): pass in display id
        // TODO(b/278084491): pass in display id
        bringDesktopAppsToFront(displayId, wct)
        bringDesktopAppsToFront(displayId, wct)
@@ -130,7 +130,7 @@ class DesktopTasksController(


    /** Move a task to desktop */
    /** Move a task to desktop */
    fun moveToDesktop(task: RunningTaskInfo) {
    fun moveToDesktop(task: RunningTaskInfo) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToDesktop: %d", task.taskId)
        KtProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToDesktop: %d", task.taskId)


        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        // Bring other apps to front first
        // Bring other apps to front first
@@ -190,7 +190,7 @@ class DesktopTasksController(


    /** Move a task to fullscreen */
    /** Move a task to fullscreen */
    fun moveToFullscreen(task: RunningTaskInfo) {
    fun moveToFullscreen(task: RunningTaskInfo) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToFullscreen: %d", task.taskId)
        KtProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToFullscreen: %d", task.taskId)


        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        addMoveToFullscreenChanges(wct, task.token)
        addMoveToFullscreenChanges(wct, task.token)
@@ -255,10 +255,10 @@ class DesktopTasksController(
    fun moveToNextDisplay(taskId: Int) {
    fun moveToNextDisplay(taskId: Int) {
        val task = shellTaskOrganizer.getRunningTaskInfo(taskId)
        val task = shellTaskOrganizer.getRunningTaskInfo(taskId)
        if (task == null) {
        if (task == null) {
            ProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToNextDisplay: taskId=%d not found", taskId)
            KtProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToNextDisplay: taskId=%d not found", taskId)
            return
            return
        }
        }
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToNextDisplay: taskId=%d taskDisplayId=%d",
        KtProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToNextDisplay: taskId=%d taskDisplayId=%d",
                taskId, task.displayId)
                taskId, task.displayId)


        val displayIds = rootTaskDisplayAreaOrganizer.displayIds.sorted()
        val displayIds = rootTaskDisplayAreaOrganizer.displayIds.sorted()
@@ -269,7 +269,7 @@ class DesktopTasksController(
            newDisplayId = displayIds.firstOrNull { displayId -> displayId < task.displayId }
            newDisplayId = displayIds.firstOrNull { displayId -> displayId < task.displayId }
        }
        }
        if (newDisplayId == null) {
        if (newDisplayId == null) {
            ProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToNextDisplay: next display not found")
            KtProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToNextDisplay: next display not found")
            return
            return
        }
        }
        moveToDisplay(task, newDisplayId)
        moveToDisplay(task, newDisplayId)
@@ -281,17 +281,17 @@ class DesktopTasksController(
     * No-op if task is already on that display per [RunningTaskInfo.displayId].
     * No-op if task is already on that display per [RunningTaskInfo.displayId].
     */
     */
    private fun moveToDisplay(task: RunningTaskInfo, displayId: Int) {
    private fun moveToDisplay(task: RunningTaskInfo, displayId: Int) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToDisplay: taskId=%d displayId=%d",
        KtProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToDisplay: taskId=%d displayId=%d",
                task.taskId, displayId)
                task.taskId, displayId)


        if (task.displayId == displayId) {
        if (task.displayId == displayId) {
            ProtoLog.d(WM_SHELL_DESKTOP_MODE, "moveToDisplay: task already on display")
            KtProtoLog.d(WM_SHELL_DESKTOP_MODE, "moveToDisplay: task already on display")
            return
            return
        }
        }


        val displayAreaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId)
        val displayAreaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId)
        if (displayAreaInfo == null) {
        if (displayAreaInfo == null) {
            ProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToDisplay: display not found")
            KtProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToDisplay: display not found")
            return
            return
        }
        }


@@ -316,7 +316,7 @@ class DesktopTasksController(
    }
    }


    private fun bringDesktopAppsToFront(displayId: Int, wct: WindowContainerTransaction) {
    private fun bringDesktopAppsToFront(displayId: Int, wct: WindowContainerTransaction) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "bringDesktopAppsToFront")
        KtProtoLog.v(WM_SHELL_DESKTOP_MODE, "bringDesktopAppsToFront")
        val activeTasks = desktopModeTaskRepository.getActiveTasks(displayId)
        val activeTasks = desktopModeTaskRepository.getActiveTasks(displayId)


        // First move home to front and then other tasks on top of it
        // First move home to front and then other tasks on top of it
@@ -397,7 +397,7 @@ class DesktopTasksController(
        if (task.windowingMode == WINDOWING_MODE_FULLSCREEN) {
        if (task.windowingMode == WINDOWING_MODE_FULLSCREEN) {
            // If there are any visible desktop tasks, switch the task to freeform
            // If there are any visible desktop tasks, switch the task to freeform
            if (activeTasks.any { desktopModeTaskRepository.isVisibleTask(it) }) {
            if (activeTasks.any { desktopModeTaskRepository.isVisibleTask(it) }) {
                ProtoLog.d(
                KtProtoLog.d(
                    WM_SHELL_DESKTOP_MODE,
                    WM_SHELL_DESKTOP_MODE,
                    "DesktopTasksController#handleRequest: switch fullscreen task to freeform," +
                    "DesktopTasksController#handleRequest: switch fullscreen task to freeform," +
                        " taskId=%d",
                        " taskId=%d",
@@ -414,7 +414,7 @@ class DesktopTasksController(
            // If no visible desktop tasks, switch this task to freeform as the transition came
            // If no visible desktop tasks, switch this task to freeform as the transition came
            // outside of this controller
            // outside of this controller
            if (activeTasks.none { desktopModeTaskRepository.isVisibleTask(it) }) {
            if (activeTasks.none { desktopModeTaskRepository.isVisibleTask(it) }) {
                ProtoLog.d(
                KtProtoLog.d(
                    WM_SHELL_DESKTOP_MODE,
                    WM_SHELL_DESKTOP_MODE,
                    "DesktopTasksController#handleRequest: switch freeform task to fullscreen," +
                    "DesktopTasksController#handleRequest: switch freeform task to fullscreen," +
                        " taskId=%d",
                        " taskId=%d",
+74 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 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.wm.shell.util

import android.util.Log
import com.android.internal.protolog.common.IProtoLogGroup
import com.android.wm.shell.protolog.ShellProtoLogImpl

/**
 * Log messages using an API similar to [com.android.internal.protolog.common.ProtoLog]. Useful for
 * logging from Kotlin classes as ProtoLog does not have support for Kotlin.
 *
 * All messages are logged to logcat if logging is enabled for that [IProtoLogGroup].
 */
// TODO(b/168581922): remove once ProtoLog adds support for Kotlin
class KtProtoLog {
    companion object {
        /** @see [com.android.internal.protolog.common.ProtoLog.d] */
        fun d(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
                Log.d(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.v] */
        fun v(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
                Log.v(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.i] */
        fun i(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
                Log.i(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.w] */
        fun w(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
                Log.w(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.e] */
        fun e(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
                Log.e(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.wtf] */
        fun wtf(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
                Log.wtf(group.tag, String.format(messageString, *args))
            }
        }
    }
}