xref: /aosp_15_r20/development/tools/winscope/src/parsers/window_manager/operations/operation_lists.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1/*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {assertDefined} from 'common/assert_utils';
18import {AddDefaults} from 'parsers/operations/add_defaults';
19import {SetFormatters} from 'parsers/operations/set_formatters';
20import {TranslateIntDef} from 'parsers/operations/translate_intdef';
21import {DENYLIST_PROPERTIES} from 'parsers/window_manager/denylist_properties';
22import {EAGER_PROPERTIES} from 'parsers/window_manager/eager_properties';
23import {ProtoType} from 'parsers/window_manager/proto_type';
24import {TamperedProtos} from 'parsers/window_manager/tampered_protos';
25import {RECT_FORMATTER} from 'trace/tree_node/formatters';
26import {Operation} from 'trace/tree_node/operations/operation';
27import {PropertyTreeNode} from 'trace/tree_node/property_tree_node';
28import {AddIsVisible} from './add_is_visible';
29import {AddWindowType} from './add_window_type';
30
31export interface OperationLists {
32  common: Array<Operation<PropertyTreeNode>>;
33  eager: Array<Operation<PropertyTreeNode>>;
34  lazy: Array<Operation<PropertyTreeNode>>;
35}
36
37export class WmOperationLists {
38  private readonly LISTS = new Map<ProtoType, OperationLists>([
39    [
40      ProtoType.WindowManagerService,
41      {
42        common: [
43          new SetFormatters(this.tamperedProtos.windowManagerServiceField),
44          new TranslateIntDef(this.tamperedProtos.windowManagerServiceField),
45        ],
46        eager: [
47          new AddDefaults(
48            this.tamperedProtos.windowManagerServiceField,
49            EAGER_PROPERTIES.get(ProtoType.WindowManagerService),
50          ),
51        ],
52        lazy: [
53          new AddDefaults(
54            this.tamperedProtos.windowManagerServiceField,
55            undefined,
56            DENYLIST_PROPERTIES,
57          ),
58        ],
59      },
60    ],
61
62    [
63      ProtoType.RootWindowContainer,
64      {
65        common: [
66          new SetFormatters(this.tamperedProtos.rootWindowContainerField),
67          new TranslateIntDef(this.tamperedProtos.rootWindowContainerField),
68        ],
69        eager: [
70          new AddDefaults(
71            this.tamperedProtos.rootWindowContainerField,
72            EAGER_PROPERTIES.get(ProtoType.RootWindowContainer),
73          ),
74        ],
75        lazy: [
76          new AddDefaults(
77            this.tamperedProtos.rootWindowContainerField,
78            undefined,
79            DENYLIST_PROPERTIES,
80          ),
81        ],
82      },
83    ],
84
85    [
86      ProtoType.WindowContainer,
87      {
88        common: [
89          new SetFormatters(this.tamperedProtos.windowContainerField),
90          new TranslateIntDef(this.tamperedProtos.windowContainerField),
91        ],
92        eager: [
93          new AddDefaults(
94            this.tamperedProtos.windowContainerField,
95            EAGER_PROPERTIES.get(ProtoType.WindowContainer),
96          ),
97          new AddIsVisible(),
98        ],
99        lazy: [
100          new AddDefaults(
101            this.tamperedProtos.windowContainerField,
102            undefined,
103            DENYLIST_PROPERTIES,
104          ),
105        ],
106      },
107    ],
108
109    [
110      ProtoType.DisplayContent,
111      {
112        common: [
113          new SetFormatters(this.tamperedProtos.displayContentField),
114          new TranslateIntDef(this.tamperedProtos.displayContentField),
115        ],
116        eager: [
117          new AddDefaults(
118            this.tamperedProtos.displayContentField,
119            EAGER_PROPERTIES.get(ProtoType.DisplayContent),
120          ),
121        ],
122        lazy: [
123          new AddDefaults(
124            this.tamperedProtos.displayContentField,
125            undefined,
126            DENYLIST_PROPERTIES,
127          ),
128        ],
129      },
130    ],
131
132    [
133      ProtoType.DisplayArea,
134      {
135        common: [
136          new SetFormatters(this.tamperedProtos.displayAreaField),
137          new TranslateIntDef(this.tamperedProtos.displayAreaField),
138        ],
139        eager: [
140          new AddDefaults(
141            this.tamperedProtos.displayAreaField,
142            EAGER_PROPERTIES.get(ProtoType.DisplayArea),
143          ),
144        ],
145        lazy: [
146          new AddDefaults(
147            this.tamperedProtos.displayAreaField,
148            undefined,
149            DENYLIST_PROPERTIES,
150          ),
151        ],
152      },
153    ],
154
155    [
156      ProtoType.Task,
157      {
158        common: [
159          new SetFormatters(this.tamperedProtos.taskField),
160          new TranslateIntDef(this.tamperedProtos.taskField),
161        ],
162        eager: [
163          new AddDefaults(
164            this.tamperedProtos.taskField,
165            EAGER_PROPERTIES.get(ProtoType.Task),
166          ),
167        ],
168        lazy: [
169          new AddDefaults(
170            this.tamperedProtos.taskField,
171            undefined,
172            DENYLIST_PROPERTIES,
173          ),
174        ],
175      },
176    ],
177
178    [
179      ProtoType.Activity,
180      {
181        common: [
182          new SetFormatters(this.tamperedProtos.activityField),
183          new TranslateIntDef(this.tamperedProtos.activityField),
184        ],
185        eager: [
186          new AddDefaults(
187            this.tamperedProtos.activityField,
188            EAGER_PROPERTIES.get(ProtoType.Activity),
189          ),
190          new AddIsVisible(),
191        ],
192        lazy: [
193          new AddDefaults(
194            this.tamperedProtos.activityField,
195            undefined,
196            DENYLIST_PROPERTIES,
197          ),
198        ],
199      },
200    ],
201
202    [
203      ProtoType.WindowToken,
204      {
205        common: [
206          new SetFormatters(this.tamperedProtos.windowTokenField),
207          new TranslateIntDef(this.tamperedProtos.windowTokenField),
208        ],
209        eager: [
210          new AddDefaults(
211            this.tamperedProtos.windowTokenField,
212            EAGER_PROPERTIES.get(ProtoType.WindowToken),
213          ),
214        ],
215        lazy: [
216          new AddDefaults(
217            this.tamperedProtos.windowTokenField,
218            undefined,
219            DENYLIST_PROPERTIES,
220          ),
221        ],
222      },
223    ],
224
225    [
226      ProtoType.WindowState,
227      {
228        common: [
229          new SetFormatters(
230            this.tamperedProtos.windowStateField,
231            new Map([
232              ['containingFrame', RECT_FORMATTER],
233              ['parentFrame', RECT_FORMATTER],
234            ]),
235          ),
236          new TranslateIntDef(this.tamperedProtos.windowStateField),
237        ],
238        eager: [
239          new AddDefaults(
240            this.tamperedProtos.windowStateField,
241            EAGER_PROPERTIES.get(ProtoType.WindowState),
242          ),
243          new AddWindowType(),
244          new AddIsVisible(),
245        ],
246        lazy: [
247          new AddDefaults(
248            this.tamperedProtos.windowStateField,
249            undefined,
250            DENYLIST_PROPERTIES,
251          ),
252        ],
253      },
254    ],
255
256    [
257      ProtoType.TaskFragment,
258      {
259        common: [
260          new SetFormatters(this.tamperedProtos.taskFragmentField),
261          new TranslateIntDef(this.tamperedProtos.taskFragmentField),
262        ],
263        eager: [
264          new AddDefaults(
265            this.tamperedProtos.taskFragmentField,
266            EAGER_PROPERTIES.get(ProtoType.TaskFragment),
267          ),
268        ],
269        lazy: [
270          new AddDefaults(
271            this.tamperedProtos.taskFragmentField,
272            undefined,
273            DENYLIST_PROPERTIES,
274          ),
275        ],
276      },
277    ],
278  ]);
279
280  constructor(private readonly tamperedProtos: TamperedProtos) {}
281
282  get(type: ProtoType): OperationLists {
283    return assertDefined(this.LISTS.get(type));
284  }
285}
286