blob: 2e4db5c4eef96ae5bef9614982667d64de1178d4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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 android.view;
18
Alan Viverette7c9746d4e2014-11-19 17:02:16 -080019import android.annotation.NonNull;
Mathew Inwooda570dee2018-08-17 14:56:00 +010020import android.annotation.UnsupportedAppUsage;
Clara Bayarri75e09792015-07-29 16:20:40 +010021import android.content.Context;
Albert Chaulk2ccb0b72017-06-20 14:39:29 -040022import android.graphics.Region;
Clara Bayarri75e09792015-07-29 16:20:40 +010023import android.os.Bundle;
Alan Viverette7c9746d4e2014-11-19 17:02:16 -080024import android.os.IBinder;
Clara Bayarri75e09792015-07-29 16:20:40 +010025import android.os.RemoteException;
26
27import com.android.internal.os.IResultReceiver;
Clara Bayarri75e09792015-07-29 16:20:40 +010028
29import java.util.List;
Alan Viverette7c9746d4e2014-11-19 17:02:16 -080030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031/**
Jeff Brown98365d72012-08-19 20:30:52 -070032 * Provides low-level communication with the system window manager for
33 * operations that are bound to a particular context, display or parent window.
34 * Instances of this object are sensitive to the compatibility info associated
35 * with the running application.
36 *
37 * This object implements the {@link ViewManager} interface,
38 * allowing you to add any View subclass as a top-level window on the screen.
39 * Additional window manager specific layout parameters are defined for
40 * control over how windows are displayed. It also implements the {@link WindowManager}
41 * interface, allowing you to control the displays attached to the device.
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070042 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 * <p>Applications will not normally use WindowManager directly, instead relying
44 * on the higher-level facilities in {@link android.app.Activity} and
45 * {@link android.app.Dialog}.
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070046 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 * <p>Even for low-level window manager access, it is almost never correct to use
48 * this class. For example, {@link android.app.Activity#getWindowManager}
Jeff Brown98365d72012-08-19 20:30:52 -070049 * provides a window manager for adding windows that are associated with that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 * activity -- the window manager will not normally allow you to add arbitrary
51 * windows that are not associated with an activity.
Jeff Brown98365d72012-08-19 20:30:52 -070052 *
53 * @see WindowManager
54 * @see WindowManagerGlobal
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 * @hide
56 */
Jeff Brown98365d72012-08-19 20:30:52 -070057public final class WindowManagerImpl implements WindowManager {
Mathew Inwooda570dee2018-08-17 14:56:00 +010058 @UnsupportedAppUsage
Jeff Brown98365d72012-08-19 20:30:52 -070059 private final WindowManagerGlobal mGlobal = WindowManagerGlobal.getInstance();
Adam Lesinski4ece3d62016-06-16 18:05:41 -070060 private final Context mContext;
Jeff Brownd32460c2012-07-20 16:15:36 -070061 private final Window mParentWindow;
Dianne Hackborna53de062012-05-08 18:53:51 -070062
Alan Viverette7c9746d4e2014-11-19 17:02:16 -080063 private IBinder mDefaultToken;
64
Adam Lesinski4ece3d62016-06-16 18:05:41 -070065 public WindowManagerImpl(Context context) {
66 this(context, null);
Jeff Brown98365d72012-08-19 20:30:52 -070067 }
68
Adam Lesinski4ece3d62016-06-16 18:05:41 -070069 private WindowManagerImpl(Context context, Window parentWindow) {
70 mContext = context;
Jeff Brownd32460c2012-07-20 16:15:36 -070071 mParentWindow = parentWindow;
Dianne Hackborn5be8de32011-05-24 18:11:57 -070072 }
73
Jeff Brown98365d72012-08-19 20:30:52 -070074 public WindowManagerImpl createLocalWindowManager(Window parentWindow) {
Adam Lesinski4ece3d62016-06-16 18:05:41 -070075 return new WindowManagerImpl(mContext, parentWindow);
Jeff Browna492c3a2012-08-23 19:48:44 -070076 }
77
Adam Lesinski4ece3d62016-06-16 18:05:41 -070078 public WindowManagerImpl createPresentationWindowManager(Context displayContext) {
79 return new WindowManagerImpl(displayContext, mParentWindow);
Jeff Brownd32460c2012-07-20 16:15:36 -070080 }
81
Alan Viverette7c9746d4e2014-11-19 17:02:16 -080082 /**
83 * Sets the window token to assign when none is specified by the client or
84 * available from the parent window.
85 *
86 * @param token The default token to assign.
87 */
88 public void setDefaultToken(IBinder token) {
89 mDefaultToken = token;
90 }
91
Jeff Brownd32460c2012-07-20 16:15:36 -070092 @Override
Alan Viverette7c9746d4e2014-11-19 17:02:16 -080093 public void addView(@NonNull View view, @NonNull ViewGroup.LayoutParams params) {
94 applyDefaultToken(params);
Adam Lesinski4ece3d62016-06-16 18:05:41 -070095 mGlobal.addView(view, params, mContext.getDisplay(), mParentWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 }
97
Jeff Brownd32460c2012-07-20 16:15:36 -070098 @Override
Alan Viverette7c9746d4e2014-11-19 17:02:16 -080099 public void updateViewLayout(@NonNull View view, @NonNull ViewGroup.LayoutParams params) {
100 applyDefaultToken(params);
Jeff Brown98365d72012-08-19 20:30:52 -0700101 mGlobal.updateViewLayout(view, params);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 }
103
Alan Viverette7c9746d4e2014-11-19 17:02:16 -0800104 private void applyDefaultToken(@NonNull ViewGroup.LayoutParams params) {
105 // Only use the default token if we don't have a parent window.
106 if (mDefaultToken != null && mParentWindow == null) {
107 if (!(params instanceof WindowManager.LayoutParams)) {
108 throw new IllegalArgumentException("Params must be WindowManager.LayoutParams");
109 }
110
111 // Only use the default token if we don't already have a token.
112 final WindowManager.LayoutParams wparams = (WindowManager.LayoutParams) params;
113 if (wparams.token == null) {
114 wparams.token = mDefaultToken;
115 }
116 }
117 }
118
Jeff Brownd32460c2012-07-20 16:15:36 -0700119 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 public void removeView(View view) {
Jeff Brown98365d72012-08-19 20:30:52 -0700121 mGlobal.removeView(view, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 }
123
Jeff Brownd32460c2012-07-20 16:15:36 -0700124 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 public void removeViewImmediate(View view) {
Jeff Brown98365d72012-08-19 20:30:52 -0700126 mGlobal.removeView(view, true);
Jeff Brown23e7c352012-07-20 12:45:47 -0700127 }
128
Jeff Brownd32460c2012-07-20 16:15:36 -0700129 @Override
Clara Bayarrifcd7e802016-03-10 12:58:18 +0000130 public void requestAppKeyboardShortcuts(
131 final KeyboardShortcutsReceiver receiver, int deviceId) {
Clara Bayarri75e09792015-07-29 16:20:40 +0100132 IResultReceiver resultReceiver = new IResultReceiver.Stub() {
133 @Override
134 public void send(int resultCode, Bundle resultData) throws RemoteException {
135 List<KeyboardShortcutGroup> result =
136 resultData.getParcelableArrayList(PARCEL_KEY_SHORTCUTS_ARRAY);
137 receiver.onKeyboardShortcutsReceived(result);
138 }
139 };
140 try {
141 WindowManagerGlobal.getWindowManagerService()
Clara Bayarrifcd7e802016-03-10 12:58:18 +0000142 .requestAppKeyboardShortcuts(resultReceiver, deviceId);
Clara Bayarri75e09792015-07-29 16:20:40 +0100143 } catch (RemoteException e) {
144 }
145 }
146
147 @Override
Jeff Brownd32460c2012-07-20 16:15:36 -0700148 public Display getDefaultDisplay() {
Adam Lesinski4ece3d62016-06-16 18:05:41 -0700149 return mContext.getDisplay();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 }
Albert Chaulk2ccb0b72017-06-20 14:39:29 -0400151
152 @Override
153 public Region getCurrentImeTouchRegion() {
154 try {
155 return WindowManagerGlobal.getWindowManagerService().getCurrentImeTouchRegion();
156 } catch (RemoteException e) {
157 }
158 return null;
159 }
Chilun8753ad32018-10-09 15:56:45 +0800160
161 @Override
162 public void setShouldShowWithInsecureKeyguard(int displayId, boolean shouldShow) {
163 try {
164 WindowManagerGlobal.getWindowManagerService()
165 .setShouldShowWithInsecureKeyguard(displayId, shouldShow);
166 } catch (RemoteException e) {
167 }
168 }
169
170 @Override
171 public void setShouldShowSystemDecors(int displayId, boolean shouldShow) {
172 try {
173 WindowManagerGlobal.getWindowManagerService()
174 .setShouldShowSystemDecors(displayId, shouldShow);
175 } catch (RemoteException e) {
176 }
177 }
178
179 @Override
Andrii Kuliandd989612019-02-21 12:13:28 -0800180 public boolean shouldShowSystemDecors(int displayId) {
181 try {
182 return WindowManagerGlobal.getWindowManagerService().shouldShowSystemDecors(displayId);
183 } catch (RemoteException e) {
184 }
185 return false;
186 }
187
188 @Override
Chilun8753ad32018-10-09 15:56:45 +0800189 public void setShouldShowIme(int displayId, boolean shouldShow) {
190 try {
191 WindowManagerGlobal.getWindowManagerService().setShouldShowIme(displayId, shouldShow);
192 } catch (RemoteException e) {
193 }
194 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195}