From 0bb308f2a8d60dd51265e923aec5016278e6197d Mon Sep 17 00:00:00 2001 From: Priyanka Date: Wed, 11 Aug 2021 14:22:56 +0000 Subject: [PATCH] Store transition types in enum Store transition types in enum so easier to type check in Typescript if necessary later on. Bug: b/196203538 Test: check that the tag trace attached to the bug still uploads correctly Change-Id: I2994f58ceb1d49bd82af54fb075369bd70dc1394 --- tools/winscope/src/flickerlib/tags/Tag.ts | 20 ++++++++++--- .../src/flickerlib/tags/TransitionType.ts | 28 +++++++++++++++++++ tools/winscope/src/mixins/Timeline.js | 17 +++++------ tools/winscope/src/utils/consts.js | 2 +- 4 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 tools/winscope/src/flickerlib/tags/TransitionType.ts diff --git a/tools/winscope/src/flickerlib/tags/Tag.ts b/tools/winscope/src/flickerlib/tags/Tag.ts index 283105d5e..8ecebc65c 100644 --- a/tools/winscope/src/flickerlib/tags/Tag.ts +++ b/tools/winscope/src/flickerlib/tags/Tag.ts @@ -15,18 +15,30 @@ */ -import { Tag } from "../common" +import { Tag } from "../common"; +import TransitionType from "./TransitionType"; + +const transitionTypeMap = new Map([ + ['ROTATION', TransitionType.ROTATION], + ['PIP_ENTER', TransitionType.PIP_ENTER], + ['PIP_RESIZE', TransitionType.PIP_RESIZE], + ['PIP_EXIT', TransitionType.PIP_EXIT], + ['APP_LAUNCH', TransitionType.APP_LAUNCH], + ['APP_CLOSE', TransitionType.APP_CLOSE], + ['IME_APPEAR', TransitionType.IME_APPEAR], + ['IME_DISAPPEAR', TransitionType.IME_DISAPPEAR], +]); Tag.fromProto = function (proto: any): Tag { const tag = new Tag( proto.id, - proto.transition, + transitionTypeMap.get(proto.transition), proto.isStartTag, proto.layerId, proto.windowToken, proto.taskId ); - return tag -} + return tag; +}; export default Tag; diff --git a/tools/winscope/src/flickerlib/tags/TransitionType.ts b/tools/winscope/src/flickerlib/tags/TransitionType.ts new file mode 100644 index 000000000..aebc72f57 --- /dev/null +++ b/tools/winscope/src/flickerlib/tags/TransitionType.ts @@ -0,0 +1,28 @@ +/* + * Copyright 2021, 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. + */ + +enum TransitionType { + ROTATION = 'ROTATION', + PIP_ENTER = 'PIP_ENTER', + PIP_RESIZE ='PIP_RESIZE', + PIP_EXIT = 'PIP_EXIT', + APP_LAUNCH = 'APP_LAUNCH', + APP_CLOSE = 'APP_CLOSE', + IME_APPEAR = 'IME_APPEAR', + IME_DISAPPEAR = 'IME_DISAPPEAR', +}; + +export default TransitionType; \ No newline at end of file diff --git a/tools/winscope/src/mixins/Timeline.js b/tools/winscope/src/mixins/Timeline.js index 40f7a385c..a915872ae 100644 --- a/tools/winscope/src/mixins/Timeline.js +++ b/tools/winscope/src/mixins/Timeline.js @@ -16,6 +16,7 @@ import _ from "lodash"; import { nanos_to_string } from "../transform"; +import TransitionType from "../flickerlib/tags/TransitionType"; /** * Represents a continuous section of the timeline that is rendered into the @@ -61,14 +62,14 @@ class Transition { * - An element in the template referenced as 'timeline' (this.$refs.timeline). */ const transitionMap = new Map([ - ['ROTATION', {desc: 'Rotation', color: '#9900ffff'}], - ['PIP_ENTER', {desc: 'Entering PIP mode', color: '#4a86e8ff'}], - ['PIP_RESIZE', {desc: 'Resizing PIP mode', color: '#2b9e94ff'}], - ['PIP_EXIT', {desc: 'Exiting PIP mode', color: 'darkblue'}], - ['APP_LAUNCH', {desc: 'Launching app', color: '#ef6befff'}], - ['APP_CLOSE', {desc: 'Closing app', color: '#d10ddfff'}], - ['IME_APPEAR', {desc: 'IME appearing', color: '#ff9900ff'}], - ['IME_DISAPPEAR', {desc: 'IME disappearing', color: '#ad6800ff'}], + [TransitionType.ROTATION, {desc: 'Rotation', color: '#9900ffff'}], + [TransitionType.PIP_ENTER, {desc: 'Entering PIP mode', color: '#4a86e8ff'}], + [TransitionType.PIP_RESIZE, {desc: 'Resizing PIP mode', color: '#2b9e94ff'}], + [TransitionType.PIP_EXIT, {desc: 'Exiting PIP mode', color: 'darkblue'}], + [TransitionType.APP_LAUNCH, {desc: 'Launching app', color: '#ef6befff'}], + [TransitionType.APP_CLOSE, {desc: 'Closing app', color: '#d10ddfff'}], + [TransitionType.IME_APPEAR, {desc: 'IME appearing', color: '#ff9900ff'}], + [TransitionType.IME_DISAPPEAR, {desc: 'IME disappearing', color: '#ad6800ff'}], ]); export default { diff --git a/tools/winscope/src/utils/consts.js b/tools/winscope/src/utils/consts.js index 4e0939d85..155cc36a7 100644 --- a/tools/winscope/src/utils/consts.js +++ b/tools/winscope/src/utils/consts.js @@ -39,6 +39,6 @@ const logLevel = { WARN: 'warn', ERROR: 'error', WTF: 'wtf', -} +}; export { WebContentScriptMessageType, NAVIGATION_STYLE, logLevel };