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 { shortenName } from '../mixin' 18import { toRect, DisplayContent, Rect } from "../common" 19import WindowContainer from "./WindowContainer" 20 21DisplayContent.fromProto = function (proto: any, isActivityInTree: Boolean): DisplayContent { 22 if (proto == null) { 23 return null; 24 } else { 25 const windowContainer = WindowContainer.fromProto( 26 /* proto */ proto.rootDisplayArea.windowContainer, 27 /* protoChildren */ proto.rootDisplayArea.windowContainer.children.reverse(), 28 /* isActivityInTree */ isActivityInTree, 29 /* nameOverride */ proto.displayInfo?.name ?? null 30 ); 31 const displayRectWidth = proto.displayInfo?.logicalWidth ?? 0; 32 const displayRectHeight = proto.displayInfo?.logicalHeight ?? 0; 33 const appRectWidth = proto.displayInfo?.appWidth ?? 0; 34 const appRectHeight = proto.displayInfo?.appHeight ?? 0; 35 const defaultBounds = proto.pinnedStackController?.defaultBounds ?? null; 36 const movementBounds = proto.pinnedStackController?.movementBounds ?? null; 37 38 const entry = new DisplayContent( 39 proto.id, 40 proto.focusedRootTaskId, 41 proto.resumedActivity?.title ?? "", 42 proto.singleTaskInstance, 43 toRect(defaultBounds), 44 toRect(movementBounds), 45 new Rect(0, 0, displayRectWidth, displayRectHeight), 46 new Rect(0, 0, appRectWidth, appRectHeight), 47 proto.dpi, 48 proto.displayInfo?.flags ?? 0, 49 toRect(proto.displayFrames?.stableBounds), 50 proto.surfaceSize, 51 proto.focusedApp, 52 proto.appTransition?.lastUsedAppTransition ?? "", 53 proto.appTransition?.appTransitionState ?? "", 54 proto.displayRotation?.rotation ?? 0, 55 proto.displayRotation?.lastOrientation ?? 0, 56 windowContainer 57 ); 58 59 addAttributes(entry, proto); 60 console.warn("Created ", entry.kind, " stableId=", entry.stableId); 61 return entry; 62 } 63} 64 65function addAttributes(entry: DisplayContent, proto: any) { 66 entry.proto = proto; 67 entry.kind = entry.constructor.name; 68 entry.shortName = shortenName(entry.name); 69} 70 71export default DisplayContent; 72