1/*
2 * Copyright (C) 2011 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
17package com.android.server.wm;
18
19import android.os.IBinder;
20
21import java.io.PrintWriter;
22
23/**
24 * Container of a set of related windows in the window manager.  Often this
25 * is an AppWindowToken, which is the handle for an Activity that it uses
26 * to display windows.  For nested windows, there is a WindowToken created for
27 * the parent window to manage its children.
28 */
29class WindowToken {
30    // The window manager!
31    final WindowManagerService service;
32
33    // The actual token.
34    final IBinder token;
35
36    // The type of window this token is for, as per WindowManager.LayoutParams.
37    final int windowType;
38
39    // Set if this token was explicitly added by a client, so should
40    // not be removed when all windows are removed.
41    final boolean explicit;
42
43    // For printing.
44    String stringName;
45
46    // If this is an AppWindowToken, this is non-null.
47    AppWindowToken appWindowToken;
48
49    // All of the windows associated with this token.
50    final WindowList windows = new WindowList();
51
52    // Is key dispatching paused for this token?
53    boolean paused = false;
54
55    // Should this token's windows be hidden?
56    boolean hidden;
57
58    // Temporary for finding which tokens no longer have visible windows.
59    boolean hasVisible;
60
61    // Set to true when this token is in a pending transaction where it
62    // will be shown.
63    boolean waitingToShow;
64
65    // Set to true when this token is in a pending transaction where it
66    // will be hidden.
67    boolean waitingToHide;
68
69    // Set to true when this token is in a pending transaction where its
70    // windows will be put to the bottom of the list.
71    boolean sendingToBottom;
72
73    WindowToken(WindowManagerService _service, IBinder _token, int type, boolean _explicit) {
74        service = _service;
75        token = _token;
76        windowType = type;
77        explicit = _explicit;
78    }
79
80    void dump(PrintWriter pw, String prefix) {
81        pw.print(prefix); pw.print("windows="); pw.println(windows);
82        pw.print(prefix); pw.print("windowType="); pw.print(windowType);
83                pw.print(" hidden="); pw.print(hidden);
84                pw.print(" hasVisible="); pw.println(hasVisible);
85        if (waitingToShow || waitingToHide || sendingToBottom) {
86            pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
87                    pw.print(" waitingToHide="); pw.print(waitingToHide);
88                    pw.print(" sendingToBottom="); pw.print(sendingToBottom);
89        }
90    }
91
92    @Override
93    public String toString() {
94        if (stringName == null) {
95            StringBuilder sb = new StringBuilder();
96            sb.append("WindowToken{");
97            sb.append(Integer.toHexString(System.identityHashCode(this)));
98            sb.append(" "); sb.append(token); sb.append('}');
99            stringName = sb.toString();
100        }
101        return stringName;
102    }
103}