From 707aadb98af9abf6690eddbfeffcf28f0c287bb2 Mon Sep 17 00:00:00 2001 From: Nataniel Borges Date: Mon, 19 Dec 2022 11:28:23 +0000 Subject: [PATCH] Use display cutout from proto dump Bug: 262390300 Test: atest FlickerLibTest Change-Id: I03a7f85ee34fcbbe88df693e5787ba93709db716 --- .../trace/flickerlib/ObjectFormatter.ts | 59 ++++++++++--------- .../src/common/trace/flickerlib/common.js | 26 ++++++++ .../flickerlib/windows/DisplayContent.ts | 20 ++++++- .../flickerlib/windows/WindowManagerState.ts | 3 +- 4 files changed, 77 insertions(+), 31 deletions(-) diff --git a/tools/winscope-ng/src/common/trace/flickerlib/ObjectFormatter.ts b/tools/winscope-ng/src/common/trace/flickerlib/ObjectFormatter.ts index 89d5c8393..31d7578d2 100644 --- a/tools/winscope-ng/src/common/trace/flickerlib/ObjectFormatter.ts +++ b/tools/winscope-ng/src/common/trace/flickerlib/ObjectFormatter.ts @@ -14,12 +14,13 @@ * limitations under the License. */ -import {toSize, toActiveBuffer, toColor, toColor3, toPoint, toPointF, toRect, - toRectF, toRegion, toMatrix22, toTransform} from './common'; +import { + toSize, toActiveBuffer, toColor, toColor3, toPoint, toPointF, toRect, + toRectF, toRegion, toMatrix22, toTransform, toInsets +} from './common'; import { PropertiesDump } from "viewers/common/ui_tree_utils"; - import intDefMapping from - '../../../../../../../prebuilts/misc/common/winscope/intDefMapping.json'; + '../../../../../../../prebuilts/misc/common/winscope/intDefMapping.json'; import config from './Configuration.json' function readIntdefMap(): Map { @@ -60,7 +61,7 @@ export default class ObjectFormatter { do { const properties = Object.getOwnPropertyNames(obj).filter(it => { // filter out functions - if (typeof(entry[it]) === 'function') return false; + if (typeof (entry[it]) === 'function') return false; // internal propertires from kotlinJs if (it.includes(`$`)) return false; // private kotlin variables from kotlin @@ -75,7 +76,7 @@ export default class ObjectFormatter { return !(value?.stableId); }); properties.forEach(function (prop) { - if (typeof(entry[prop]) !== 'function' && props.indexOf(prop) === -1) { + if (typeof (entry[prop]) !== 'function' && props.indexOf(prop) === -1) { props.push(prop); } }); @@ -110,7 +111,7 @@ export default class ObjectFormatter { // raw values (e.g., false or 0) if (!value) { result[key] = value - // flicker obj + // flicker obj } else if (value.prettyPrint) { const isEmpty = value.isEmpty === true; if (!isEmpty || this.displayDefaults) { @@ -118,23 +119,23 @@ export default class ObjectFormatter { } } else { // converted proto to flicker - const translatedObject = this.translateObject(value); + const translatedObject = this.translateObject(key, value); if (translatedObject) { if (translatedObject.prettyPrint) { - result[key] = translatedObject.prettyPrint(); + result[key] = translatedObject.prettyPrint(); } else { - result[key] = translatedObject; + result[key] = translatedObject; } - // objects - recursive call - } else if (value && typeof(value) == `object`) { + // objects - recursive call + } else if (value && typeof (value) == `object`) { const childObj = this.format(value) as any; const isEmpty = Object.entries(childObj).length == 0 || childObj.isEmpty; if (!isEmpty || this.displayDefaults) { result[key] = childObj; } } else { - // values + // values result[key] = this.translateIntDef(obj, key, value); } } @@ -152,9 +153,9 @@ export default class ObjectFormatter { * * @param obj Object to translate */ - private static translateObject(obj: any) { + private static translateObject(key: string, obj: any) { const type = obj?.$type?.name ?? obj?.constructor?.name; - switch(type) { + switch (type) { case `SizeProto`: return toSize(obj); case `ActiveBufferProto`: return toActiveBuffer(obj); case `Color3`: return toColor3(obj); @@ -162,7 +163,9 @@ export default class ObjectFormatter { case `Long`: return obj?.toString(); case `PointProto`: return toPoint(obj); case `PositionProto`: return toPointF(obj); - case `RectProto`: return toRect(obj); + // It is necessary to check for a keyword insets because the proto + // definition of insets and rects uses the same object type + case `RectProto`: return key.toLowerCase().includes("insets") ? toInsets(obj) : toRect(obj); case `Matrix22`: return toMatrix22(obj); case `FloatRectProto`: return toRectF(obj); case `RegionProto`: return toRegion(obj); @@ -193,7 +196,7 @@ export default class ObjectFormatter { * @param obj Proto object * @param propertyName Property to search */ - private static getTypeDefSpec(obj: any, propertyName: string): string|null { + private static getTypeDefSpec(obj: any, propertyName: string): string | null { const fields = obj?.$type?.fields; if (!fields) { return null; @@ -224,7 +227,7 @@ export default class ObjectFormatter { // Parse Flicker objects (no intdef annotation supported) if (this.FLICKER_INTDEF_MAP.has(propertyPath)) { translatedValue = this.getIntFlagsAsStrings(value, - this.FLICKER_INTDEF_MAP.get(propertyPath)); + this.FLICKER_INTDEF_MAP.get(propertyPath)); } else { // If it's a proto, search on the proto definition for the intdef type const typeDefSpec = this.getTypeDefSpec(parentObj, propertyName); @@ -258,25 +261,25 @@ export default class ObjectFormatter { let leftOver = parsedIntFlags; for (const flagValue of knownFlagValues) { - if (((leftOver & flagValue) && ((intFlags & flagValue) === flagValue)) + if (((leftOver & flagValue) && ((intFlags & flagValue) === flagValue)) || (parsedIntFlags === 0 && flagValue === 0)) { - flags.push(mapping[flagValue]); + flags.push(mapping[flagValue]); - leftOver = leftOver & ~flagValue; - } + leftOver = leftOver & ~flagValue; + } } if (flags.length === 0) { - console.error('No valid flag mappings found for ', - intFlags, 'of type', annotationType); + console.error('No valid flag mappings found for ', + intFlags, 'of type', annotationType); } if (leftOver) { - // If 0 is a valid flag value that isn't in the intDefMapping - // it will be ignored - flags.push(leftOver); + // If 0 is a valid flag value that isn't in the intDefMapping + // it will be ignored + flags.push(leftOver); } return flags.join(' | '); - } + } } diff --git a/tools/winscope-ng/src/common/trace/flickerlib/common.js b/tools/winscope-ng/src/common/trace/flickerlib/common.js index af6376fa4..f3cfbcf58 100644 --- a/tools/winscope-ng/src/common/trace/flickerlib/common.js +++ b/tools/winscope-ng/src/common/trace/flickerlib/common.js @@ -36,6 +36,8 @@ const DisplayArea = require('flicker').com.android.server.wm.traces.common. windowmanager.windows.DisplayArea; const DisplayContent = require('flicker').com.android.server.wm.traces.common. windowmanager.windows.DisplayContent; +const DisplayCutout = require('flicker').com.android.server.wm.traces.common. + windowmanager.windows.DisplayCutout; const KeyguardControllerState = require('flicker').com.android.server.wm. traces.common.windowmanager.windows.KeyguardControllerState; const RootWindowContainer = require('flicker').com.android.server.wm.traces. @@ -85,6 +87,9 @@ const ActiveBuffer = require('flicker').com.android.server.wm.traces.common .ActiveBuffer; const Color3 = require('flicker').com.android.server.wm.traces.common.Color3; const Color = require('flicker').com.android.server.wm.traces.common.Color; +const Insets = require('flicker').com.android.server.wm.traces.common.Insets; +const PlatformConsts = require('flicker').com.android.server.wm.traces.common + .service.PlatformConsts; const Point = require('flicker').com.android.server.wm.traces.common.Point; const PointF = require('flicker').com.android.server.wm.traces.common.PointF; const Rect = require('flicker').com.android.server.wm.traces.common.Rect; @@ -97,6 +102,7 @@ const TaggingEngine = require('flicker').com.android.server.wm.traces.common.ser const EMPTY_BUFFER = ActiveBuffer.Companion.EMPTY; const EMPTY_COLOR3 = Color3.Companion.EMPTY; const EMPTY_COLOR = Color.Companion.EMPTY; +const EMPTY_INSETS = Insets.Companion.EMPTY; const EMPTY_RECT = Rect.Companion.EMPTY; const EMPTY_RECTF = RectF.Companion.EMPTY; const EMPTY_POINT = Point.Companion.EMPTY; @@ -180,6 +186,22 @@ function toPointF(proto) { return EMPTY_POINTF; } +function toInsets(proto) { + if (proto == null) { + return EMPTY_INSETS; + } + + const left = proto?.left ?? 0; + const top = proto?.top ?? 0; + const right = proto?.right ?? 0; + const bottom = proto?.bottom ?? 0; + if (left || top || right || bottom) { + return new Insets(left, top, right, bottom); + } + return EMPTY_INSETS; +} + + function toRect(proto) { if (proto == null) { return EMPTY_RECT; @@ -270,6 +292,7 @@ export { DisplayArea, DisplayContent, KeyguardControllerState, + DisplayCutout, RootWindowContainer, Task, TaskFragment, @@ -298,6 +321,8 @@ export { ActiveBuffer, Color, Color3, + Insets, + PlatformConsts, Point, Rect, RectF, @@ -308,6 +333,7 @@ export { toActiveBuffer, toColor, toColor3, + toInsets, toPoint, toPointF, toRect, diff --git a/tools/winscope-ng/src/common/trace/flickerlib/windows/DisplayContent.ts b/tools/winscope-ng/src/common/trace/flickerlib/windows/DisplayContent.ts index 06abbda74..efc751919 100644 --- a/tools/winscope-ng/src/common/trace/flickerlib/windows/DisplayContent.ts +++ b/tools/winscope-ng/src/common/trace/flickerlib/windows/DisplayContent.ts @@ -15,7 +15,7 @@ */ import { shortenName } from '../mixin' -import { toRect, DisplayContent, Rect } from "../common" +import { toInsets, toRect, DisplayContent, DisplayCutout, PlatformConsts, Rect } from "../common" import WindowContainer from "./WindowContainer" DisplayContent.fromProto = function (proto: any, isActivityInTree: Boolean, nextSeq: () => number): DisplayContent { @@ -52,8 +52,9 @@ DisplayContent.fromProto = function (proto: any, isActivityInTree: Boolean, next proto.focusedApp, proto.appTransition?.lastUsedAppTransition ?? "", proto.appTransition?.appTransitionState ?? "", - proto.displayRotation?.rotation ?? 0, + PlatformConsts.Rotation.Companion.getByValue(proto.displayRotation?.rotation ?? 0), proto.displayRotation?.lastOrientation ?? 0, + createDisplayCutout(proto.displayInfo?.cutout), windowContainer ); @@ -62,6 +63,21 @@ DisplayContent.fromProto = function (proto: any, isActivityInTree: Boolean, next } } +function createDisplayCutout(proto: any | null): DisplayCutout | null { + if(proto == null) { + return null; + } else { + return new DisplayCutout( + toInsets(proto?.insets), + toRect(proto?.boundLeft), + toRect(proto?.boundTop), + toRect(proto?.boundRight), + toRect(proto?.boundBottom), + toInsets(proto?.waterfallInsets) + ); + } +} + function addAttributes(entry: DisplayContent, proto: any) { entry.proto = proto; entry.kind = entry.constructor.name; diff --git a/tools/winscope-ng/src/common/trace/flickerlib/windows/WindowManagerState.ts b/tools/winscope-ng/src/common/trace/flickerlib/windows/WindowManagerState.ts index b9b5ef722..9dc407e5b 100644 --- a/tools/winscope-ng/src/common/trace/flickerlib/windows/WindowManagerState.ts +++ b/tools/winscope-ng/src/common/trace/flickerlib/windows/WindowManagerState.ts @@ -18,6 +18,7 @@ import { ElapsedTimestamp, RealTimestamp } from "common/trace/timestamp"; import { TimeUtils } from "common/utils/time_utils"; import { KeyguardControllerState, + PlatformConsts, RootWindowContainer, WindowManagerPolicy, WindowManagerState, @@ -92,7 +93,7 @@ function createWindowManagerPolicy(proto: any): WindowManagerPolicy { proto.keyguardOccludedPending, proto.lastSystemUiFlags, proto.orientation, - proto.rotation, + PlatformConsts.Rotation.Companion.getByValue(proto.rotation), proto.rotationMode, proto.screenOnFully, proto.windowManagerDrawComplete