• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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 {WindowManagerState} from 'trace/flickerlib/windows/WindowManagerState';
18import {Timestamp, TimestampType} from 'trace/timestamp';
19import {TraceFile} from 'trace/trace_file';
20import {TraceType} from 'trace/trace_type';
21import {AbstractParser} from './abstract_parser';
22import {WindowManagerServiceDumpProto} from './proto_types';
23
24class ParserWindowManagerDump extends AbstractParser {
25  constructor(trace: TraceFile) {
26    super(trace);
27  }
28
29  override getTraceType(): TraceType {
30    return TraceType.WINDOW_MANAGER;
31  }
32
33  override getMagicNumber(): undefined {
34    return undefined;
35  }
36
37  override decodeTrace(buffer: Uint8Array): any[] {
38    const entryProto = WindowManagerServiceDumpProto.decode(buffer);
39
40    // This parser is prone to accepting invalid inputs because it lacks a magic
41    // number. Let's reduce the chances of accepting invalid inputs by making
42    // sure that a trace entry can actually be created from the decoded proto.
43    // If the trace entry creation fails, an exception is thrown and the parser
44    // will be considered unsuited for this input data.
45    this.processDecodedEntry(0, TimestampType.ELAPSED /*irrelevant for dump*/, entryProto);
46
47    return [entryProto];
48  }
49
50  override getTimestamp(type: TimestampType, entryProto: any): undefined | Timestamp {
51    if (type === TimestampType.ELAPSED) {
52      return new Timestamp(TimestampType.ELAPSED, 0n);
53    } else if (type === TimestampType.REAL) {
54      return new Timestamp(TimestampType.REAL, 0n);
55    }
56    return undefined;
57  }
58
59  override processDecodedEntry(
60    index: number,
61    timestampType: TimestampType,
62    entryProto: any
63  ): WindowManagerState {
64    return WindowManagerState.fromProto(entryProto);
65  }
66}
67
68export {ParserWindowManagerDump};
69