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 its
67     // windows will be put to the bottom of the list.
68     boolean sendingToBottom;
69 
WindowToken(WindowManagerService _service, IBinder _token, int type, boolean _explicit)70     WindowToken(WindowManagerService _service, IBinder _token, int type, boolean _explicit) {
71         service = _service;
72         token = _token;
73         windowType = type;
74         explicit = _explicit;
75     }
76 
removeAllWindows()77     void removeAllWindows() {
78         for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
79             WindowState win = windows.get(winNdx);
80             if (WindowManagerService.DEBUG_WINDOW_MOVEMENT) Slog.w(WindowManagerService.TAG,
81                     "removeAllWindows: removing win=" + win);
82             win.mService.removeWindowLocked(win);
83         }
84         windows.clear();
85     }
86 
dump(PrintWriter pw, String prefix)87     void dump(PrintWriter pw, String prefix) {
88         pw.print(prefix); pw.print("windows="); pw.println(windows);
89         pw.print(prefix); pw.print("windowType="); pw.print(windowType);
90                 pw.print(" hidden="); pw.print(hidden);
91                 pw.print(" hasVisible="); pw.println(hasVisible);
92         if (waitingToShow || sendingToBottom) {
93             pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
94                     pw.print(" sendingToBottom="); pw.print(sendingToBottom);
95         }
96     }
97 
98     @Override
toString()99     public String toString() {
100         if (stringName == null) {
101             StringBuilder sb = new StringBuilder();
102             sb.append("WindowToken{");
103             sb.append(Integer.toHexString(System.identityHashCode(this)));
104             sb.append(" "); sb.append(token); sb.append('}');
105             stringName = sb.toString();
106         }
107         return stringName;
108     }
109 }