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 21 import android.app.WindowConfiguration; 22 import android.graphics.Rect; 23 import android.os.Handler; 24 import android.os.RemoteException; 25 import android.util.Log; 26 import android.view.WindowManager; 27 import android.view.WindowManagerGlobal; 28 29 import static android.view.WindowManagerPolicyConstants.NAV_BAR_RIGHT; 30 import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM; 31 import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT; 32 33 import com.android.systemui.shared.recents.view.AppTransitionAnimationSpecsFuture; 34 import com.android.systemui.shared.recents.view.RecentsTransition; 35 36 public class WindowManagerWrapper { 37 38 private static final String TAG = "WindowManagerWrapper"; 39 40 public static final int TRANSIT_UNSET = WindowManager.TRANSIT_UNSET; 41 public static final int TRANSIT_NONE = WindowManager.TRANSIT_NONE; 42 public static final int TRANSIT_ACTIVITY_OPEN = WindowManager.TRANSIT_ACTIVITY_OPEN; 43 public static final int TRANSIT_ACTIVITY_CLOSE = WindowManager.TRANSIT_ACTIVITY_CLOSE; 44 public static final int TRANSIT_TASK_OPEN = WindowManager.TRANSIT_TASK_OPEN; 45 public static final int TRANSIT_TASK_CLOSE = WindowManager.TRANSIT_TASK_CLOSE; 46 public static final int TRANSIT_TASK_TO_FRONT = WindowManager.TRANSIT_TASK_TO_FRONT; 47 public static final int TRANSIT_TASK_TO_BACK = WindowManager.TRANSIT_TASK_TO_BACK; 48 public static final int TRANSIT_WALLPAPER_CLOSE = WindowManager.TRANSIT_WALLPAPER_CLOSE; 49 public static final int TRANSIT_WALLPAPER_OPEN = WindowManager.TRANSIT_WALLPAPER_OPEN; 50 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 51 WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN; 52 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 53 WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE; 54 public static final int TRANSIT_TASK_OPEN_BEHIND = WindowManager.TRANSIT_TASK_OPEN_BEHIND; 55 public static final int TRANSIT_TASK_IN_PLACE = WindowManager.TRANSIT_TASK_IN_PLACE; 56 public static final int TRANSIT_ACTIVITY_RELAUNCH = WindowManager.TRANSIT_ACTIVITY_RELAUNCH; 57 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 58 WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; 59 public static final int TRANSIT_KEYGUARD_GOING_AWAY = WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; 60 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 61 WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER; 62 public static final int TRANSIT_KEYGUARD_OCCLUDE = WindowManager.TRANSIT_KEYGUARD_OCCLUDE; 63 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; 64 65 public static final int NAV_BAR_POS_INVALID = -1; 66 public static final int NAV_BAR_POS_LEFT = NAV_BAR_LEFT; 67 public static final int NAV_BAR_POS_RIGHT = NAV_BAR_RIGHT; 68 public static final int NAV_BAR_POS_BOTTOM = NAV_BAR_BOTTOM; 69 70 public static final int ACTIVITY_TYPE_STANDARD = WindowConfiguration.ACTIVITY_TYPE_STANDARD; 71 72 public static final int WINDOWING_MODE_UNDEFINED = WindowConfiguration.WINDOWING_MODE_UNDEFINED; 73 public static final int WINDOWING_MODE_FULLSCREEN = 74 WindowConfiguration.WINDOWING_MODE_FULLSCREEN; 75 public static final int WINDOWING_MODE_PINNED = WindowConfiguration.WINDOWING_MODE_PINNED; 76 public static final int WINDOWING_MODE_SPLIT_SCREEN_PRIMARY = 77 WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; 78 public static final int WINDOWING_MODE_SPLIT_SCREEN_SECONDARY = 79 WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; 80 public static final int WINDOWING_MODE_FREEFORM = WindowConfiguration.WINDOWING_MODE_FREEFORM; 81 82 private static final WindowManagerWrapper sInstance = new WindowManagerWrapper(); 83 getInstance()84 public static WindowManagerWrapper getInstance() { 85 return sInstance; 86 } 87 88 /** 89 * @return the stable insets for the primary display. 90 */ getStableInsets(Rect outStableInsets)91 public void getStableInsets(Rect outStableInsets) { 92 try { 93 WindowManagerGlobal.getWindowManagerService().getStableInsets(DEFAULT_DISPLAY, 94 outStableInsets); 95 } catch (RemoteException e) { 96 Log.e(TAG, "Failed to get stable insets", e); 97 } 98 } 99 100 /** 101 * Overrides a pending app transition. 102 */ overridePendingAppTransitionMultiThumbFuture( AppTransitionAnimationSpecsFuture animationSpecFuture, Runnable animStartedCallback, Handler animStartedCallbackHandler, boolean scaleUp)103 public void overridePendingAppTransitionMultiThumbFuture( 104 AppTransitionAnimationSpecsFuture animationSpecFuture, 105 Runnable animStartedCallback, Handler animStartedCallbackHandler, boolean scaleUp) { 106 try { 107 WindowManagerGlobal.getWindowManagerService() 108 .overridePendingAppTransitionMultiThumbFuture(animationSpecFuture.getFuture(), 109 RecentsTransition.wrapStartedListener(animStartedCallbackHandler, 110 animStartedCallback), scaleUp); 111 } catch (RemoteException e) { 112 Log.w(TAG, "Failed to override pending app transition (multi-thumbnail future): ", e); 113 } 114 } 115 overridePendingAppTransitionRemote( RemoteAnimationAdapterCompat remoteAnimationAdapter)116 public void overridePendingAppTransitionRemote( 117 RemoteAnimationAdapterCompat remoteAnimationAdapter) { 118 try { 119 WindowManagerGlobal.getWindowManagerService().overridePendingAppTransitionRemote( 120 remoteAnimationAdapter.getWrapped()); 121 } catch (RemoteException e) { 122 Log.w(TAG, "Failed to override pending app transition (remote): ", e); 123 } 124 } 125 126 /** 127 * Enable or disable haptic feedback on the navigation bar buttons. 128 */ setNavBarVirtualKeyHapticFeedbackEnabled(boolean enabled)129 public void setNavBarVirtualKeyHapticFeedbackEnabled(boolean enabled) { 130 try { 131 WindowManagerGlobal.getWindowManagerService() 132 .setNavBarVirtualKeyHapticFeedbackEnabled(enabled); 133 } catch (RemoteException e) { 134 Log.w(TAG, "Failed to enable or disable navigation bar button haptics: ", e); 135 } 136 } 137 setShelfHeight(boolean visible, int shelfHeight)138 public void setShelfHeight(boolean visible, int shelfHeight) { 139 try { 140 WindowManagerGlobal.getWindowManagerService().setShelfHeight(visible, shelfHeight); 141 } catch (RemoteException e) { 142 Log.w(TAG, "Failed to set shelf height"); 143 } 144 } 145 setRecentsVisibility(boolean visible)146 public void setRecentsVisibility(boolean visible) { 147 try { 148 WindowManagerGlobal.getWindowManagerService().setRecentsVisibility(visible); 149 } catch (RemoteException e) { 150 Log.w(TAG, "Failed to set recents visibility"); 151 } 152 } 153 154 /** 155 * @return The side of the screen where navigation bar is positioned. 156 * @see #NAV_BAR_POS_RIGHT 157 * @see #NAV_BAR_POS_LEFT 158 * @see #NAV_BAR_POS_BOTTOM 159 * @see #NAV_BAR_POS_INVALID 160 */ getNavBarPosition()161 public int getNavBarPosition() { 162 try { 163 return WindowManagerGlobal.getWindowManagerService().getNavBarPosition(); 164 } catch (RemoteException e) { 165 Log.w(TAG, "Failed to get nav bar position"); 166 } 167 return NAV_BAR_POS_INVALID; 168 } 169 } 170