• 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 { asRawTreeViewObject } from '../utils/diff.js'
18import { getPropertiesForDisplay } from './mixin'
19
20import {
21    KeyguardControllerState,
22    RootWindowContainer,
23    WindowManagerPolicy,
24    WindowManagerState
25} from "./common"
26
27import WindowContainer from "./windows/WindowContainer"
28
29WindowManagerState.fromProto = function ({proto, timestamp = 0, where = ""}): WindowManagerState {
30    var inputMethodWIndowAppToken = ""
31    if (proto.inputMethodWindow != null) {
32        proto.inputMethodWindow.hashCode.toString(16)
33    }
34    const rootWindowContainer = newRootWindowContainer(proto.rootWindowContainer)
35    const keyguardControllerState = newKeyguardControllerState(
36        proto.rootWindowContainer.keyguardController)
37    const entry = new WindowManagerState(
38        where,
39        newWindowManagerPolicy(proto.policy),
40        proto.focusedApp,
41        proto.focusedDisplayId,
42        proto.focusedWindow?.title ?? "",
43        inputMethodWIndowAppToken,
44        proto.rootWindowContainer.isHomeRecentsComponent,
45        proto.displayFrozen,
46        proto.rootWindowContainer.pendingActivities.map(it => it.title),
47        rootWindowContainer,
48        keyguardControllerState,
49        timestamp = timestamp
50    )
51
52    entry.kind = entry.constructor.name
53    entry.rects = entry.windowStates.reverse().map(it => it.rect)
54    if (!entry.isComplete()) {
55        entry.isIncompleteReason = entry.getIsIncompleteReason()
56    }
57    entry.obj = getPropertiesForDisplay(proto, entry)
58    entry.shortName = entry.name
59    entry.chips = []
60    entry.visible = true
61    entry.rawTreeViewObject = asRawTreeViewObject(entry)
62
63    console.warn("Created ", entry.kind, " stableId=", entry.stableId)
64    return entry
65}
66
67function newWindowManagerPolicy(proto): WindowManagerPolicy {
68    return new WindowManagerPolicy(
69        proto.focusedAppToken || "",
70        proto.forceStatusBar,
71        proto.forceStatusBarFromKeyguard,
72        proto.keyguardDrawComplete,
73        proto.keyguardOccluded,
74        proto.keyguardOccludedChanged,
75        proto.keyguardOccludedPending,
76        proto.lastSystemUiFlags,
77        proto.orientation,
78        proto.rotation,
79        proto.rotationMode,
80        proto.screenOnFully,
81        proto.windowManagerDrawComplete
82    )
83}
84
85function newRootWindowContainer(proto): RootWindowContainer {
86    const children = proto.windowContainer.children.reverse()
87        .filter(it => it != null)
88        .map(it => WindowContainer.childrenFromProto(it, /* isActivityInTree */ false))
89    const windowContainer = WindowContainer.fromProto(
90        {proto: proto.windowContainer, children: children})
91    if (windowContainer == null) {
92        throw "Window container should not be null: " + JSON.stringify(proto)
93    }
94    const entry = new RootWindowContainer(windowContainer)
95
96    return entry
97}
98
99function newKeyguardControllerState(proto): KeyguardControllerState {
100    const keyguardOccludedStates = {}
101
102    if (proto) {
103        proto.keyguardOccludedStates.forEach(it =>
104            keyguardOccludedStates[it.displayId] = it.keyguardOccluded)
105    }
106
107    return new KeyguardControllerState(
108        proto?.isAodShowing ?? false,
109        proto?.isKeyguardShowing ?? false,
110        keyguardOccludedStates
111    )
112}
113
114export default WindowManagerState;