• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2020, 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 ObjectFormatter from "./ObjectFormatter"
18
19/**
20 * Get the properties of a WM object for display.
21 *
22 * @param entry WM hierarchy element
23 * @param proto Associated proto object
24 */
25export function getPropertiesForDisplay(proto: any, entry: any): any {
26    let obj = Object.assign({}, entry)
27    if (obj.children) delete obj.children
28    // obj = ObjectFormatter.format(obj)
29
30    obj.proto = Object.assign({}, proto)
31    if (obj.proto.children) delete obj.proto.children
32    if (obj.proto.childWindows) delete obj.proto.childWindows
33    if (obj.proto.childrenWindows) delete obj.proto.childrenWindows
34    if (obj.proto.childContainers) delete obj.proto.childContainers
35    if (obj.proto.windowToken) delete obj.proto.windowToken
36    if (obj.proto.rootDisplayArea) delete obj.proto.rootDisplayArea
37    if (obj.proto.rootWindowContainer) delete obj.proto.rootWindowContainer
38    if (obj.proto.windowContainer?.children) delete obj.proto.windowContainer.children
39    obj = ObjectFormatter.format(obj)
40
41    return obj
42}
43
44export function shortenName(name: any): string {
45    const classParts = (name + "").split(".")
46    if (classParts.length <= 3) {
47        return name
48    }
49    const className = classParts.slice(-1)[0] // last element
50    return `${classParts[0]}.${classParts[1]}.(...).${className}`
51}
52