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