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 {Chip} from './chip'; 18 19export type UiTreeNode = HierarchyTreeNode | PropertiesTreeNode; 20 21export class HierarchyTreeNode { 22 constructor( 23 public name: string, 24 public kind: string, 25 public stableId: string, 26 children?: HierarchyTreeNode[] 27 ) { 28 this.children = children ?? []; 29 } 30 31 children: HierarchyTreeNode[]; 32 shortName?: string; 33 type?: string; 34 id?: string | number; 35 layerId?: number; 36 displayId?: number; 37 stackId?: number; 38 isVisible?: boolean; 39 isMissing?: boolean; 40 hwcCompositionType?: number; 41 zOrderRelativeOfId?: number; 42 zOrderRelativeOf?: any; 43 zOrderRelativeParentOf?: any; 44 isRootLayer?: boolean; 45 showInFilteredView?: boolean; 46 showInOnlyVisibleView?: boolean; 47 simplifyNames?: boolean; 48 chips: Chip[] = []; 49 diffType?: string; 50 skip?: any; 51} 52 53export interface PropertiesDump { 54 [key: string]: any; 55} 56 57export interface PropertiesTreeNode { 58 properties?: any; 59 kind?: string; 60 stableId?: string; 61 children?: PropertiesTreeNode[]; 62 propertyKey?: string | Terminal | null; 63 propertyValue?: string | Terminal | null; 64 name?: string | Terminal; 65 diffType?: string; 66 combined?: boolean; 67} //TODO: make specific 68 69export const DiffType = { 70 NONE: 'none', 71 ADDED: 'added', 72 DELETED: 'deleted', 73 ADDED_MOVE: 'addedMove', 74 DELETED_MOVE: 'deletedMove', 75 MODIFIED: 'modified', 76}; 77 78export class Terminal {} 79 80export class UiTreeUtils { 81 static diffClass(item: UiTreeNode): string { 82 const diffType = item.diffType; 83 return diffType ?? ''; 84 } 85 86 static isHighlighted(item: UiTreeNode, highlightedItems: string[]) { 87 return item instanceof HierarchyTreeNode && highlightedItems.includes(`${item.stableId}`); 88 } 89 90 static isVisibleNode(kind: string, type?: string) { 91 return kind === 'WindowState' || kind === 'Activity' || type?.includes('Layer'); 92 } 93 94 static isParentNode(kind: string) { 95 return UiTreeUtils.PARENT_NODE_KINDS.includes(kind); 96 } 97 98 private static readonly PARENT_NODE_KINDS = [ 99 'entry', 100 'WindowManagerState', 101 'InputMethodClient entry', 102 'InputMethodService entry', 103 'InputMethodManagerService entry', 104 ]; 105} 106