• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.systemui.shared.system;
18 
19 import static android.view.Display.DEFAULT_DISPLAY;
20 import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM;
21 import static android.view.WindowManagerPolicyConstants.NAV_BAR_INVALID;
22 import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT;
23 import static android.view.WindowManagerPolicyConstants.NAV_BAR_RIGHT;
24 
25 import android.app.WindowConfiguration;
26 import android.graphics.Rect;
27 import android.os.Handler;
28 import android.os.RemoteException;
29 import android.util.Log;
30 import android.view.InsetsState;
31 import android.view.SurfaceControl;
32 import android.view.WindowManager;
33 import android.view.WindowManagerGlobal;
34 
35 import com.android.systemui.shared.recents.view.AppTransitionAnimationSpecsFuture;
36 import com.android.systemui.shared.recents.view.RecentsTransition;
37 
38 public class WindowManagerWrapper {
39 
40     private static final String TAG = "WindowManagerWrapper";
41 
42     public static final int TRANSIT_UNSET = WindowManager.TRANSIT_OLD_UNSET;
43     public static final int TRANSIT_NONE = WindowManager.TRANSIT_OLD_NONE;
44     public static final int TRANSIT_ACTIVITY_OPEN = WindowManager.TRANSIT_OLD_ACTIVITY_OPEN;
45     public static final int TRANSIT_ACTIVITY_CLOSE = WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE;
46     public static final int TRANSIT_TASK_OPEN = WindowManager.TRANSIT_OLD_TASK_OPEN;
47     public static final int TRANSIT_TASK_CLOSE = WindowManager.TRANSIT_OLD_TASK_CLOSE;
48     public static final int TRANSIT_TASK_TO_FRONT = WindowManager.TRANSIT_OLD_TASK_TO_FRONT;
49     public static final int TRANSIT_TASK_TO_BACK = WindowManager.TRANSIT_OLD_TASK_TO_BACK;
50     public static final int TRANSIT_WALLPAPER_CLOSE = WindowManager.TRANSIT_OLD_WALLPAPER_CLOSE;
51     public static final int TRANSIT_WALLPAPER_OPEN = WindowManager.TRANSIT_OLD_WALLPAPER_OPEN;
52     public static final int TRANSIT_WALLPAPER_INTRA_OPEN =
53             WindowManager.TRANSIT_OLD_WALLPAPER_INTRA_OPEN;
54     public static final int TRANSIT_WALLPAPER_INTRA_CLOSE =
55             WindowManager.TRANSIT_OLD_WALLPAPER_INTRA_CLOSE;
56     public static final int TRANSIT_TASK_OPEN_BEHIND = WindowManager.TRANSIT_OLD_TASK_OPEN_BEHIND;
57     public static final int TRANSIT_ACTIVITY_RELAUNCH = WindowManager.TRANSIT_OLD_ACTIVITY_RELAUNCH;
58     public static final int TRANSIT_KEYGUARD_GOING_AWAY =
59             WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY;
60     public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER =
61             WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
62     public static final int TRANSIT_KEYGUARD_OCCLUDE = WindowManager.TRANSIT_OLD_KEYGUARD_OCCLUDE;
63     public static final int TRANSIT_KEYGUARD_UNOCCLUDE =
64             WindowManager.TRANSIT_OLD_KEYGUARD_UNOCCLUDE;
65 
66     public static final int NAV_BAR_POS_INVALID = NAV_BAR_INVALID;
67     public static final int NAV_BAR_POS_LEFT = NAV_BAR_LEFT;
68     public static final int NAV_BAR_POS_RIGHT = NAV_BAR_RIGHT;
69     public static final int NAV_BAR_POS_BOTTOM = NAV_BAR_BOTTOM;
70 
71     public static final int ACTIVITY_TYPE_STANDARD = WindowConfiguration.ACTIVITY_TYPE_STANDARD;
72 
73     public static final int WINDOWING_MODE_UNDEFINED = WindowConfiguration.WINDOWING_MODE_UNDEFINED;
74     public static final int WINDOWING_MODE_FULLSCREEN =
75             WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
76     public static final int WINDOWING_MODE_MULTI_WINDOW =
77             WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
78 
79     public static final int WINDOWING_MODE_SPLIT_SCREEN_PRIMARY =
80             WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
81     public static final int WINDOWING_MODE_SPLIT_SCREEN_SECONDARY =
82             WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
83     public static final int WINDOWING_MODE_FREEFORM = WindowConfiguration.WINDOWING_MODE_FREEFORM;
84 
85     public static final int ITYPE_EXTRA_NAVIGATION_BAR = InsetsState.ITYPE_EXTRA_NAVIGATION_BAR;
86     public static final int ITYPE_LEFT_TAPPABLE_ELEMENT = InsetsState.ITYPE_LEFT_TAPPABLE_ELEMENT;
87     public static final int ITYPE_TOP_TAPPABLE_ELEMENT = InsetsState.ITYPE_TOP_TAPPABLE_ELEMENT;
88     public static final int ITYPE_RIGHT_TAPPABLE_ELEMENT = InsetsState.ITYPE_RIGHT_TAPPABLE_ELEMENT;
89     public static final int ITYPE_BOTTOM_TAPPABLE_ELEMENT =
90             InsetsState.ITYPE_BOTTOM_TAPPABLE_ELEMENT;
91 
92     private static final WindowManagerWrapper sInstance = new WindowManagerWrapper();
93 
getInstance()94     public static WindowManagerWrapper getInstance() {
95         return sInstance;
96     }
97 
98 
99     /**
100      * Sets {@param providesInsetsTypes} as the inset types provided by {@param params}.
101      * @param params The window layout params.
102      * @param providesInsetsTypes The inset types we would like this layout params to provide.
103      */
setProvidesInsetsTypes(WindowManager.LayoutParams params, int[] providesInsetsTypes)104     public void setProvidesInsetsTypes(WindowManager.LayoutParams params,
105             int[] providesInsetsTypes) {
106         params.providesInsetsTypes = providesInsetsTypes;
107     }
108 
109     /**
110      *  Sets if app requested fixed orientation should be ignored for given displayId.
111      */
setIgnoreOrientationRequest(int displayId, boolean ignoreOrientationRequest)112     public void setIgnoreOrientationRequest(int displayId, boolean ignoreOrientationRequest) {
113         try {
114             WindowManagerGlobal.getWindowManagerService().setIgnoreOrientationRequest(
115                     displayId, ignoreOrientationRequest);
116         } catch (RemoteException e) {
117             Log.e(TAG, "Failed to setIgnoreOrientationRequest()", e);
118         }
119     }
120 
121     /**
122      * @return the stable insets for the primary display.
123      */
getStableInsets(Rect outStableInsets)124     public void getStableInsets(Rect outStableInsets) {
125         try {
126             WindowManagerGlobal.getWindowManagerService().getStableInsets(DEFAULT_DISPLAY,
127                     outStableInsets);
128         } catch (RemoteException e) {
129             Log.e(TAG, "Failed to get stable insets", e);
130         }
131     }
132 
133     /**
134      * Overrides a pending app transition.
135      */
overridePendingAppTransitionMultiThumbFuture( AppTransitionAnimationSpecsFuture animationSpecFuture, Runnable animStartedCallback, Handler animStartedCallbackHandler, boolean scaleUp, int displayId)136     public void overridePendingAppTransitionMultiThumbFuture(
137             AppTransitionAnimationSpecsFuture animationSpecFuture, Runnable animStartedCallback,
138             Handler animStartedCallbackHandler, boolean scaleUp, int displayId) {
139         try {
140             WindowManagerGlobal.getWindowManagerService()
141                     .overridePendingAppTransitionMultiThumbFuture(animationSpecFuture.getFuture(),
142                             RecentsTransition.wrapStartedListener(animStartedCallbackHandler,
143                                     animStartedCallback), scaleUp, displayId);
144         } catch (RemoteException e) {
145             Log.w(TAG, "Failed to override pending app transition (multi-thumbnail future): ", e);
146         }
147     }
148 
overridePendingAppTransitionRemote( RemoteAnimationAdapterCompat remoteAnimationAdapter, int displayId)149     public void overridePendingAppTransitionRemote(
150             RemoteAnimationAdapterCompat remoteAnimationAdapter, int displayId) {
151         try {
152             WindowManagerGlobal.getWindowManagerService().overridePendingAppTransitionRemote(
153                     remoteAnimationAdapter.getWrapped(), displayId);
154         } catch (RemoteException e) {
155             Log.w(TAG, "Failed to override pending app transition (remote): ", e);
156         }
157     }
158 
159     /**
160      * Enable or disable haptic feedback on the navigation bar buttons.
161      */
setNavBarVirtualKeyHapticFeedbackEnabled(boolean enabled)162     public void setNavBarVirtualKeyHapticFeedbackEnabled(boolean enabled) {
163         try {
164             WindowManagerGlobal.getWindowManagerService()
165                     .setNavBarVirtualKeyHapticFeedbackEnabled(enabled);
166         } catch (RemoteException e) {
167             Log.w(TAG, "Failed to enable or disable navigation bar button haptics: ", e);
168         }
169     }
170 
setRecentsVisibility(boolean visible)171     public void setRecentsVisibility(boolean visible) {
172         try {
173             WindowManagerGlobal.getWindowManagerService().setRecentsVisibility(visible);
174         } catch (RemoteException e) {
175             Log.w(TAG, "Failed to set recents visibility");
176         }
177     }
178 
179     @Deprecated
setPipVisibility(final boolean visible)180     public void setPipVisibility(final boolean visible) {
181         // To be removed
182     }
183 
184     /**
185      * @param displayId the id of display to check if there is a software navigation bar.
186      *
187      * @return whether there is a soft nav bar on specific display.
188      */
hasSoftNavigationBar(int displayId)189     public boolean hasSoftNavigationBar(int displayId) {
190         try {
191             return WindowManagerGlobal.getWindowManagerService().hasNavigationBar(displayId);
192         } catch (RemoteException e) {
193             return false;
194         }
195     }
196 
197     /**
198      * @return The side of the screen where navigation bar is positioned.
199      * @see #NAV_BAR_POS_RIGHT
200      * @see #NAV_BAR_POS_LEFT
201      * @see #NAV_BAR_POS_BOTTOM
202      * @see #NAV_BAR_POS_INVALID
203      */
getNavBarPosition(int displayId)204     public int getNavBarPosition(int displayId) {
205         try {
206             return WindowManagerGlobal.getWindowManagerService().getNavBarPosition(displayId);
207         } catch (RemoteException e) {
208             Log.w(TAG, "Failed to get nav bar position");
209         }
210         return NAV_BAR_POS_INVALID;
211     }
212 
213     /**
214      * Mirrors a specified display. The SurfaceControl returned is the root of the mirrored
215      * hierarchy.
216      *
217      * @param displayId The id of the display to mirror
218      * @return The SurfaceControl for the root of the mirrored hierarchy.
219      */
mirrorDisplay(final int displayId)220     public SurfaceControl mirrorDisplay(final int displayId) {
221         try {
222             SurfaceControl outSurfaceControl = new SurfaceControl();
223             WindowManagerGlobal.getWindowManagerService().mirrorDisplay(displayId,
224                     outSurfaceControl);
225             return outSurfaceControl;
226         } catch (RemoteException e) {
227             Log.e(TAG, "Unable to reach window manager", e);
228         }
229         return null;
230     }
231 }
232