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

Commit ad6bb95f authored by Jorge Gil's avatar Jorge Gil Committed by Android (Google) Code Review
Browse files

Merge "Desks: Let DesktopWallpaperActivity be focusable with empty desk" into main

parents a19bf0bc 12bdcf39
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ import android.app.Activity
import android.app.TaskInfo
import android.content.ComponentName
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
import android.window.DesktopExperienceFlags

/**
 * A transparent activity used in the desktop mode to show the wallpaper under the freeform windows.
@@ -35,11 +37,29 @@ class DesktopWallpaperActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        updateFocusableFlag(focusable = true)
    }

    override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) {
        if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) return
        Log.d(TAG, "onTopResumedActivityChanged: $isTopResumedActivity")
        // Let the activity be focusable when it is top-resumed (e.g. empty desk), otherwise input
        // events will result in an ANR because the focused app would have no focusable window.
        updateFocusableFlag(focusable = isTopResumedActivity)
    }

    private fun updateFocusableFlag(focusable: Boolean) {
        if (focusable) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
        } else {
            window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
        }
    }

    companion object {
        private const val TAG = "DesktopWallpaperActivity"
        private const val SYSTEM_UI_PACKAGE_NAME = "com.android.systemui"

        @JvmStatic
        val wallpaperActivityComponent =
            ComponentName(SYSTEM_UI_PACKAGE_NAME, DesktopWallpaperActivity::class.java.name)