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(entry: any): any { 26 if (!entry) { 27 return; 28 } 29 30 let obj: any = {}; 31 const properties = ObjectFormatter.getProperties(entry); 32 properties.forEach((prop) => (obj[prop] = entry[prop])); 33 34 // we remove the children property from the object to avoid it showing the 35 // the properties view of the element as we can always see those elements' 36 // properties by changing the target element in the hierarchy tree view. 37 if (obj.children) delete obj.children; 38 if (obj.proto) delete obj.proto; 39 40 obj.proto = Object.assign({}, entry.proto); 41 if (obj.proto.children) delete obj.proto.children; 42 if (obj.proto.childWindows) delete obj.proto.childWindows; 43 if (obj.proto.childrenWindows) delete obj.proto.childrenWindows; 44 if (obj.proto.childContainers) delete obj.proto.childContainers; 45 if (obj.proto.windowToken) delete obj.proto.windowToken; 46 if (obj.proto.rootDisplayArea) delete obj.proto.rootDisplayArea; 47 if (obj.proto.rootWindowContainer) delete obj.proto.rootWindowContainer; 48 if (obj.proto.windowContainer?.children) delete obj.proto.windowContainer.children; 49 obj = ObjectFormatter.format(obj); 50 51 return obj; 52} 53 54export function shortenName(name: any): string { 55 const classParts = (name + '').split('.'); 56 if (classParts.length <= 3) { 57 return name; 58 } 59 const className = classParts.slice(-1)[0]; // last element 60 return `${classParts[0]}.${classParts[1]}.(...).${className}`; 61} 62