Enable overriding density for desktop tasks

Add a new API to WindowContainerTransaction to support updating the
container density.
This allows us to update the configuration object with a new density
value that would get applied by the WindowOrganizerController.
Allow list density changes in WindowOrganizerController as an allowed
configuration change.
Update DesktopTasksController to change the density value when moving a
task to desktop or back to fullscreen (if enabled).
Use system property persist.wm.desktop_mode_density to override the
density for desktop tasks. Allowed range for the density override is 100
to 1000.

Bug: 272529050
Test: atest DesktopTasksControllerTest
Change-Id: I96539176252fdd5b69b02e3bd1b6a4231990decb
This commit is contained in:
Ats Jenk
2023-03-09 09:15:48 -08:00
parent 4f4d7d3a08
commit 6a3d39104b
3 changed files with 62 additions and 12 deletions

View File

@@ -121,6 +121,19 @@ public final class WindowContainerTransaction implements Parcelable {
return this;
}
/**
* Sets the densityDpi value in the configuration for the given container.
* @hide
*/
@NonNull
public WindowContainerTransaction setDensityDpi(@NonNull WindowContainerToken container,
int densityDpi) {
Change chg = getOrCreateChange(container.asBinder());
chg.mConfiguration.densityDpi = densityDpi;
chg.mConfigSetMask |= ActivityInfo.CONFIG_DENSITY;
return this;
}
/**
* Notify {@link com.android.server.wm.PinnedTaskController} that the picture-in-picture task
* has finished the enter animation with the given bounds.

View File

@@ -25,6 +25,7 @@ import android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED
import android.app.WindowConfiguration.WindowingMode
import android.content.Context
import android.os.IBinder
import android.os.SystemProperties
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CHANGE
import android.view.WindowManager.TRANSIT_NONE
@@ -32,6 +33,7 @@ import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_TO_FRONT
import android.window.TransitionInfo
import android.window.TransitionRequestInfo
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import androidx.annotation.BinderThread
import com.android.internal.protolog.common.ProtoLog
@@ -115,10 +117,7 @@ class DesktopTasksController(
val wct = WindowContainerTransaction()
// Bring other apps to front first
bringDesktopAppsToFront(wct)
wct.setWindowingMode(task.getToken(), WINDOWING_MODE_FREEFORM)
wct.reorder(task.getToken(), true /* onTop */)
addMoveToDesktopChanges(wct, task.token)
if (Transitions.ENABLE_SHELL_TRANSITIONS) {
transitions.startTransition(TRANSIT_CHANGE, wct, null /* handler */)
} else {
@@ -136,8 +135,7 @@ class DesktopTasksController(
ProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveToFullscreen: %d", task.taskId)
val wct = WindowContainerTransaction()
wct.setWindowingMode(task.getToken(), WINDOWING_MODE_FULLSCREEN)
wct.setBounds(task.getToken(), null)
addMoveToFullscreenChanges(wct, task.token)
if (Transitions.ENABLE_SHELL_TRANSITIONS) {
transitions.startTransition(TRANSIT_CHANGE, wct, null /* handler */)
} else {
@@ -234,8 +232,8 @@ class DesktopTasksController(
" taskId=%d",
task.taskId
)
return WindowContainerTransaction().apply {
setWindowingMode(task.token, WINDOWING_MODE_FREEFORM)
return WindowContainerTransaction().also { wct ->
addMoveToDesktopChanges(wct, task.token)
}
}
}
@@ -251,15 +249,48 @@ class DesktopTasksController(
" taskId=%d",
task.taskId
)
return WindowContainerTransaction().apply {
setWindowingMode(task.token, WINDOWING_MODE_FULLSCREEN)
setBounds(task.token, null)
return WindowContainerTransaction().also { wct ->
addMoveToFullscreenChanges(wct, task.token)
}
}
}
return null
}
private fun addMoveToDesktopChanges(
wct: WindowContainerTransaction,
token: WindowContainerToken
) {
wct.setWindowingMode(token, WINDOWING_MODE_FREEFORM)
wct.reorder(token, true /* onTop */)
if (isDesktopDensityOverrideSet()) {
wct.setDensityDpi(token, getDesktopDensityDpi())
}
}
private fun addMoveToFullscreenChanges(
wct: WindowContainerTransaction,
token: WindowContainerToken
) {
wct.setWindowingMode(token, WINDOWING_MODE_FULLSCREEN)
wct.setBounds(token, null)
if (isDesktopDensityOverrideSet()) {
wct.setDensityDpi(token, getFullscreenDensityDpi())
}
}
private fun isDesktopDensityOverrideSet(): Boolean {
return DESKTOP_DENSITY_OVERRIDE in DESKTOP_DENSITY_ALLOWED_RANGE
}
private fun getFullscreenDensityDpi(): Int {
return context.resources.displayMetrics.densityDpi
}
private fun getDesktopDensityDpi(): Int {
return DESKTOP_DENSITY_OVERRIDE
}
/** Creates a new instance of the external interface to pass to another process. */
private fun createExternalInterface(): ExternalInterfaceBinder {
return IDesktopModeImpl(this)
@@ -318,4 +349,10 @@ class DesktopTasksController(
return result[0]
}
}
companion object {
private val DESKTOP_DENSITY_OVERRIDE =
SystemProperties.getInt("persist.wm.debug.desktop_mode_density", 0)
private val DESKTOP_DENSITY_ALLOWED_RANGE = (100..1000)
}
}

View File

@@ -131,7 +131,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
*/
static final int CONTROLLABLE_CONFIGS = ActivityInfo.CONFIG_WINDOW_CONFIGURATION
| ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE | ActivityInfo.CONFIG_SCREEN_SIZE
| ActivityInfo.CONFIG_LAYOUT_DIRECTION;
| ActivityInfo.CONFIG_LAYOUT_DIRECTION | ActivityInfo.CONFIG_DENSITY;
static final int CONTROLLABLE_WINDOW_CONFIGS = WINDOW_CONFIG_BOUNDS
| WindowConfiguration.WINDOW_CONFIG_APP_BOUNDS;