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 { getPropertiesForDisplay, shortenName } from '../mixin' 18import { asRawTreeViewObject } from '../../utils/diff.js' 19import { toRect, Bounds, WindowState, WindowLayoutParams } from "../common" 20import { VISIBLE_CHIP } from '../treeview/Chips' 21import WindowContainer from "./WindowContainer" 22 23 WindowState.fromProto = function (proto, isActivityInTree: Boolean): WindowState { 24 if (proto == null) { 25 return null 26 } else { 27 const identifierName = proto.windowContainer.identifier?.title ?? proto.identifier?.title ?? "" 28 var windowType = 0 29 if (identifierName.startsWith(WindowState.STARTING_WINDOW_PREFIX)) { 30 windowType = WindowState.WINDOW_TYPE_STARTING 31 } else if (proto.animatingExit) { 32 windowType = WindowState.WINDOW_TYPE_EXITING 33 } else if (identifierName.startsWith(WindowState.DEBUGGER_WINDOW_PREFIX)) { 34 windowType = WindowState.WINDOW_TYPE_STARTING 35 } 36 37 var nameOverride = identifierName 38 39 if (identifierName.startsWith(WindowState.STARTING_WINDOW_PREFIX)) { 40 nameOverride = identifierName.substring(WindowState.STARTING_WINDOW_PREFIX.length) 41 } else if (identifierName.startsWith(WindowState.DEBUGGER_WINDOW_PREFIX)) { 42 nameOverride = identifierName.substring(WindowState.DEBUGGER_WINDOW_PREFIX.length) 43 } 44 45 const children = proto.windowContainer.children.reverse() 46 .filter(it => it != null) 47 .map(it => WindowContainer.childrenFromProto(it, isActivityInTree)) 48 49 const windowContainer = WindowContainer.fromProto({ 50 proto: proto.windowContainer, 51 children: children, 52 nameOverride: nameOverride, 53 identifierOverride: proto.identifier}) 54 if (windowContainer == null) { 55 throw "Window container should not be null: " + JSON.stringify(proto) 56 } 57 58 const entry = new WindowState( 59 newWindowLayoutParams(proto.attributes), 60 proto.displayId, 61 proto.stackId, 62 proto.animator?.surface?.layer ?? 0, 63 proto.animator?.surface?.shown ?? false, 64 windowType, 65 new Bounds(proto.requestedWidth, proto.requestedHeight), 66 toRect(proto.surfacePosition), 67 toRect(proto.windowFrames?.frame ?? null), 68 toRect(proto.windowFrames?.containingFrame ?? null), 69 toRect(proto.windowFrames?.parentFrame ?? null), 70 toRect(proto.windowFrames?.contentFrame ?? null), 71 toRect(proto.windowFrames?.contentInsets ?? null), 72 toRect(proto.surfaceInsets), 73 toRect(proto.givenContentInsets), 74 toRect(proto.animator?.lastClipRect ?? null), 75 windowContainer, 76 /* isAppWindow */ isActivityInTree 77 ) 78 79 entry.kind = entry.constructor.name 80 entry.rect = entry.frame 81 entry.rect.ref = entry 82 entry.rect.label = entry.name 83 entry.obj = getPropertiesForDisplay(proto, entry) 84 entry.shortName = shortenName(entry.name) 85 entry.visible = entry.isVisible ?? false 86 entry.chips = entry.isVisible ? [VISIBLE_CHIP] : [] 87 entry.rawTreeViewObject = asRawTreeViewObject(entry) 88 return entry 89 } 90} 91 92function newWindowLayoutParams(proto): WindowLayoutParams { 93 return new WindowLayoutParams( 94 /* type */ proto?.type ?? 0, 95 /* x */ proto?.x ?? 0, 96 /* y */ proto?.y ?? 0, 97 /* width */ proto?.width ?? 0, 98 /* height */ proto?.height ?? 0, 99 /* horizontalMargin */ proto?.horizontalMargin ?? 0, 100 /* verticalMargin */ proto?.verticalMargin ?? 0, 101 /* gravity */ proto?.gravity ?? 0, 102 /* softInputMode */ proto?.softInputMode ?? 0, 103 /* format */ proto?.format ?? 0, 104 /* windowAnimations */ proto?.windowAnimations ?? 0, 105 /* alpha */ proto?.alpha ?? 0, 106 /* screenBrightness */ proto?.screenBrightness ?? 0, 107 /* buttonBrightness */ proto?.buttonBrightness ?? 0, 108 /* rotationAnimation */ proto?.rotationAnimation ?? 0, 109 /* preferredRefreshRate */ proto?.preferredRefreshRate ?? 0, 110 /* preferredDisplayModeId */ proto?.preferredDisplayModeId ?? 0, 111 /* hasSystemUiListeners */ proto?.hasSystemUiListeners ?? false, 112 /* inputFeatureFlags */ proto?.inputFeatureFlags ?? 0, 113 /* userActivityTimeout */ proto?.userActivityTimeout ?? 0, 114 /* colorMode */ proto?.colorMode ?? 0, 115 /* flags */ proto?.flags ?? 0, 116 /* privateFlags */ proto?.privateFlags ?? 0, 117 /* systemUiVisibilityFlags */ proto?.systemUiVisibilityFlags ?? 0, 118 /* subtreeSystemUiVisibilityFlags */ proto?.subtreeSystemUiVisibilityFlags ?? 0, 119 /* appearance */ proto?.appearance ?? 0, 120 /* behavior */ proto?.behavior ?? 0, 121 /* fitInsetsTypes */ proto?.fitInsetsTypes ?? 0, 122 /* fitInsetsSides */ proto?.fitInsetsSides ?? 0, 123 /* fitIgnoreVisibility */ proto?.fitIgnoreVisibility ?? false 124 ) 125} 126 127export default WindowState 128