自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
WindowManager
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
WindowManager 转储提供了特定时间的 WindowManager 快照。WindowManager 跟踪记录具有按时间顺序排列的状态,以便提供有价值的信息,让用户了解窗口为何显示在屏幕上、窗口配置、activity、任务、显示或 WindowManager 层次结构中的任何其他元素。这些信息对于排查问题(例如“为什么我的应用不可见”或“我在应用之间切换时遇到闪烁问题”)非常有用。
Winscope 的 WindowManager 查看器会针对跟踪记录和转储显示此信息。
如需详细了解跟踪记录收集,请参阅 WindowManager。
图 1. WindowManager 跟踪记录分析。
屏幕左侧显示的是窗口的 3D 视图。矩形视图会考虑窗口边界、Z 轴顺序和不透明度。
该标签页的中心部分显示窗口层次结构。除了窗口、activity 和任务之间的父子关系之外,此视图还包含以下信息:
屏幕右侧显示所有可用属性的 Proto 转储。如需详细了解 proto 转储部分的内容,请参阅属性。
@IntDef 转换
@IntDef
转换是 WindowManager 属性面板的关键属性。@IntDef
表示带注解的整数类型元素代表逻辑类型,并且其值必须是明确命名的常量之一。我们在 Android 代码库中使用 @IntDef
而不是枚举来缓解内存和性能影响。
以下示例展示了 @IntDef 的用法:
/**
* The modes to control how root task is moved to the front when calling {@link Task#reparent}.
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef({
REPARENT_MOVE_ROOT_TASK_TO_FRONT,
REPARENT_KEEP_ROOT_TASK_AT_FRONT,
REPARENT_LEAVE_ROOT_TASK_IN_PLACE
})
@interface ReparentMoveRootTaskMode {}
// Moves the root task to the front if it was not at the front
static final int REPARENT_MOVE_ROOT_TASK_TO_FRONT = 0;
// Only moves the root task to the front if it was focused or frontmost already
static final int REPARENT_KEEP_ROOT_TASK_AT_FRONT = 1;
// Do not move the root task as a part of reparenting
static final int REPARENT_LEAVE_ROOT_TASK_IN_PLACE = 2;
标志存储为整数,而不是使用人类可读的值,这可能会很难解读。Winscope 会使用 @IntDef
定义将这些标志转换为人类可读的值。在编译期间,Winscope 会收集一个 @IntDef
值字典,并使用此列表在运行时将 @IntDef
实例解码为人类可读的格式。例如,activityType
为 2
的 activity 会转换为 activityType
为 ACTIVITY_TYPE_HOME
。同样,具有 flags=2173763840
的窗口在 Winscope 中会转换为:
flags=FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | FLAG_HARDWARE_ACCELERATED |
FLAG_SPLIT_TOUCH | FLAG_SHOW_WALLPAPER | FLAG_LAYOUT_INSET_DECOR |
FLAG_LAYOUT_IN_SCREEN
如果 Winscope 无法正确转换 @IntDef
实例,请按照更新 @IntDef 映射中的步骤更新 Winscope 已知的 @IntDef
实例列表。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-09。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-09。"],[],[],null,["# WindowManager\n\n[WindowManager](/docs/core/graphics/surfaceflinger-windowmanager#windowmanager)\ndumps provide a snapshot of WindowManager at a specific time. WindowManager\ntraces feature a chronological sequence of states that provide valuable insights\ninto why a window appears on screen, its configuration, or that of its activity,\ntask, display or of any other element in the WindowManager hierarchy. This\ninformation is useful for troubleshooting issues like *why isn't my app\nvisible* or *I experienced flickering while changing between apps*.\n\nWinscope's WindowManager viewer displays this information for both traces\nand dumps.\n\nSee\n[WindowManager](/docs/core/graphics/winscope/capture/adb#capture-adb-wm)\nfor more information about trace collection.\n\n**Figure 1.** WindowManager trace analysis.\n\nThe left side of the screen features a 3D view of the windows. The rects view\nconsiders window bounds, z-order, and opacity.\n\nThe tab's central segment shows the window hierarchy. In addition to the\nparent-child relationships between windows, activities, and tasks, this view\nalso includes the following information:\n\n- **V:** Identifies visible windows.\n\nThe right side of the screen features a **proto dump** of all available\nproperties. For more information about the features of the proto dump section\nsee [Properties](/docs/core/graphics/winscope/analyze/overview#analyze-properties).\n\n@IntDef translation\n-------------------\n\n`@IntDef` translation is a key property of the WindowManager properties panel.\n`@IntDef` denotes that the annotated element of integer type represents a\nlogical type and that its value must be one of the explicitly named constants.\n`@IntDef` is used within the Android codebase instead of enums for mitigating\nmemory and performance impact.\n\nThe following is an example of @IntDef usage: \n\n /**\n * The modes to control how root task is moved to the front when calling {@link Task#reparent}.\n */\n @Retention(RetentionPolicy.SOURCE)\n @IntDef({\n REPARENT_MOVE_ROOT_TASK_TO_FRONT,\n REPARENT_KEEP_ROOT_TASK_AT_FRONT,\n REPARENT_LEAVE_ROOT_TASK_IN_PLACE\n })\n @interface ReparentMoveRootTaskMode {}\n\n // Moves the root task to the front if it was not at the front\n static final int REPARENT_MOVE_ROOT_TASK_TO_FRONT = 0;\n // Only moves the root task to the front if it was focused or frontmost already\n static final int REPARENT_KEEP_ROOT_TASK_AT_FRONT = 1;\n // Do not move the root task as a part of reparenting\n static final int REPARENT_LEAVE_ROOT_TASK_IN_PLACE = 2;\n\nFlags are stored as *integers* , instead of using\nhuman-readable values, which can be challenging to interpret. Winscope\ntranslates these flags into human-readable values using `@IntDef` definitions.\nDuring compilations, Winscope collects a dictionary of `@IntDef` values and uses\nthis list to decode `@IntDef` instances into a human-readable format at\nruntime. For example, an activity with `activityType` of `2` is translated into\n`activityType` of `ACTIVITY_TYPE_HOME`. Similarly, a window with\n`flags=2173763840` is translated in Winscope as:\n\n`flags=FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | FLAG_HARDWARE_ACCELERATED |\nFLAG_SPLIT_TOUCH | FLAG_SHOW_WALLPAPER | FLAG_LAYOUT_INSET_DECOR |\nFLAG_LAYOUT_IN_SCREEN`\n\nIf Winscope doesn't translate an `@IntDef` instance correctly,\nfollow the steps in [Update @IntDef mapping](/docs/core/graphics/winscope/run#update-intdef)\nto update the list of `@IntDef` instances known by Winscope."]]