1 /* 2 * Copyright (C) 2019 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.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON; 20 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON; 21 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL; 22 23 import android.annotation.IntDef; 24 import android.content.Context; 25 import android.content.res.Resources; 26 import android.view.ViewConfiguration; 27 import android.view.WindowManagerPolicyConstants; 28 29 import com.android.internal.policy.ScreenDecorationsUtils; 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 import java.util.StringJoiner; 34 35 /** 36 * Various shared constants between Launcher and SysUI as part of quickstep 37 */ 38 public class QuickStepContract { 39 40 public static final String KEY_EXTRA_SYSUI_PROXY = "extra_sysui_proxy"; 41 public static final String KEY_EXTRA_INPUT_MONITOR = "extra_input_monitor"; 42 public static final String KEY_EXTRA_WINDOW_CORNER_RADIUS = "extra_window_corner_radius"; 43 public static final String KEY_EXTRA_SUPPORTS_WINDOW_CORNERS = "extra_supports_window_corners"; 44 45 public static final String NAV_BAR_MODE_2BUTTON_OVERLAY = 46 WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY; 47 public static final String NAV_BAR_MODE_3BUTTON_OVERLAY = 48 WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY; 49 public static final String NAV_BAR_MODE_GESTURAL_OVERLAY = 50 WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY; 51 52 // Action sent by a system app to switch to gesture nav 53 public static final String ACTION_ENABLE_GESTURE_NAV = 54 "com.android.systemui.ENABLE_GESTURE_NAV"; 55 // Action for the intent to receive the result 56 public static final String ACTION_ENABLE_GESTURE_NAV_RESULT = 57 "com.android.systemui.action.ENABLE_GESTURE_NAV_RESULT"; 58 // Extra containing the pending intent to receive the result 59 public static final String EXTRA_RESULT_INTENT = "com.android.systemui.EXTRA_RESULT_INTENT"; 60 61 // Overview is disabled, either because the device is in lock task mode, or because the device 62 // policy has disabled the feature 63 public static final int SYSUI_STATE_SCREEN_PINNING = 1 << 0; 64 // The navigation bar is hidden due to immersive mode 65 public static final int SYSUI_STATE_NAV_BAR_HIDDEN = 1 << 1; 66 // The notification panel is expanded and interactive (either locked or unlocked), and the 67 // quick settings is not expanded 68 public static final int SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED = 1 << 2; 69 // The keyguard bouncer is showing 70 public static final int SYSUI_STATE_BOUNCER_SHOWING = 1 << 3; 71 // The navigation bar a11y button should be shown 72 public static final int SYSUI_STATE_A11Y_BUTTON_CLICKABLE = 1 << 4; 73 // The navigation bar a11y button shortcut is available 74 public static final int SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE = 1 << 5; 75 // The keyguard is showing and not occluded 76 public static final int SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING = 1 << 6; 77 // The recents feature is disabled (either by SUW/SysUI/device policy) 78 public static final int SYSUI_STATE_OVERVIEW_DISABLED = 1 << 7; 79 // The home feature is disabled (either by SUW/SysUI/device policy) 80 public static final int SYSUI_STATE_HOME_DISABLED = 1 << 8; 81 // The keyguard is showing, but occluded 82 public static final int SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED = 1 << 9; 83 // The search feature is disabled (either by SUW/SysUI/device policy) 84 public static final int SYSUI_STATE_SEARCH_DISABLED = 1 << 10; 85 // The notification panel is expanded and interactive (either locked or unlocked), and the 86 // quick settings is not expanded 87 public static final int SYSUI_STATE_QUICK_SETTINGS_EXPANDED = 1 << 11; 88 // The Assistant gesture should be constrained. It is up to the launcher implementation to 89 // decide how to constrain it 90 public static final int SYSUI_STATE_ASSIST_GESTURE_CONSTRAINED = 1 << 12; 91 92 @Retention(RetentionPolicy.SOURCE) 93 @IntDef({SYSUI_STATE_SCREEN_PINNING, 94 SYSUI_STATE_NAV_BAR_HIDDEN, 95 SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED, 96 SYSUI_STATE_QUICK_SETTINGS_EXPANDED, 97 SYSUI_STATE_BOUNCER_SHOWING, 98 SYSUI_STATE_A11Y_BUTTON_CLICKABLE, 99 SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE, 100 SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING, 101 SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED, 102 SYSUI_STATE_OVERVIEW_DISABLED, 103 SYSUI_STATE_HOME_DISABLED, 104 SYSUI_STATE_SEARCH_DISABLED 105 }) 106 public @interface SystemUiStateFlags {} 107 getSystemUiStateString(int flags)108 public static String getSystemUiStateString(int flags) { 109 StringJoiner str = new StringJoiner("|"); 110 str.add((flags & SYSUI_STATE_SCREEN_PINNING) != 0 ? "screen_pinned" : ""); 111 str.add((flags & SYSUI_STATE_OVERVIEW_DISABLED) != 0 ? "overview_disabled" : ""); 112 str.add((flags & SYSUI_STATE_HOME_DISABLED) != 0 ? "home_disabled" : ""); 113 str.add((flags & SYSUI_STATE_SEARCH_DISABLED) != 0 ? "search_disabled" : ""); 114 str.add((flags & SYSUI_STATE_NAV_BAR_HIDDEN) != 0 ? "navbar_hidden" : ""); 115 str.add((flags & SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED) != 0 ? "notif_visible" : ""); 116 str.add((flags & SYSUI_STATE_QUICK_SETTINGS_EXPANDED) != 0 ? "qs_visible" : ""); 117 str.add((flags & SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING) != 0 ? "keygrd_visible" : ""); 118 str.add((flags & SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED) != 0 119 ? "keygrd_occluded" : ""); 120 str.add((flags & SYSUI_STATE_BOUNCER_SHOWING) != 0 ? "bouncer_visible" : ""); 121 str.add((flags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0 ? "a11y_click" : ""); 122 str.add((flags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0 ? "a11y_long_click" : ""); 123 str.add((flags & SYSUI_STATE_ASSIST_GESTURE_CONSTRAINED) != 0 124 ? "asst_gesture_constrain" : ""); 125 return str.toString(); 126 } 127 128 /** 129 * Ratio of quickstep touch slop (when system takes over the touch) to view touch slop 130 */ 131 public static final float QUICKSTEP_TOUCH_SLOP_RATIO = 3; 132 133 /** 134 * Touch slop for quickstep gesture 135 */ getQuickStepTouchSlopPx(Context context)136 public static final float getQuickStepTouchSlopPx(Context context) { 137 return QUICKSTEP_TOUCH_SLOP_RATIO * ViewConfiguration.get(context).getScaledTouchSlop(); 138 } 139 140 /** 141 * Touch slopes and thresholds for quick step operations. Drag slop is the point where the 142 * home button press/long press over are ignored and will start to drag when exceeded and the 143 * touch slop is when the respected operation will occur when exceeded. Touch slop must be 144 * larger than the drag slop. 145 */ getQuickStepDragSlopPx()146 public static int getQuickStepDragSlopPx() { 147 return convertDpToPixel(10); 148 } 149 getQuickStepTouchSlopPx()150 public static int getQuickStepTouchSlopPx() { 151 return convertDpToPixel(24); 152 } 153 getQuickScrubTouchSlopPx()154 public static int getQuickScrubTouchSlopPx() { 155 return convertDpToPixel(24); 156 } 157 convertDpToPixel(float dp)158 private static int convertDpToPixel(float dp) { 159 return (int) (dp * Resources.getSystem().getDisplayMetrics().density); 160 } 161 162 /** 163 * Returns whether the specified sysui state is such that the assistant gesture should be 164 * disabled. 165 */ isAssistantGestureDisabled(int sysuiStateFlags)166 public static boolean isAssistantGestureDisabled(int sysuiStateFlags) { 167 // Disable when in quick settings, screen pinning, immersive, the bouncer is showing, 168 // or search is disabled 169 int disableFlags = SYSUI_STATE_SCREEN_PINNING 170 | SYSUI_STATE_NAV_BAR_HIDDEN 171 | SYSUI_STATE_BOUNCER_SHOWING 172 | SYSUI_STATE_SEARCH_DISABLED 173 | SYSUI_STATE_QUICK_SETTINGS_EXPANDED; 174 if ((sysuiStateFlags & disableFlags) != 0) { 175 return true; 176 } 177 178 // Disable when notifications are showing (only if unlocked) 179 if ((sysuiStateFlags & SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED) != 0 180 && (sysuiStateFlags & SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING) == 0) { 181 return true; 182 } 183 184 return false; 185 } 186 187 /** 188 * Returns whether the specified sysui state is such that the back gesture should be 189 * disabled. 190 */ isBackGestureDisabled(int sysuiStateFlags)191 public static boolean isBackGestureDisabled(int sysuiStateFlags) { 192 // Always allow when the bouncer is showing (even on top of the keyguard) 193 if ((sysuiStateFlags & SYSUI_STATE_BOUNCER_SHOWING) != 0) { 194 return false; 195 } 196 // Disable when in immersive, or the notifications are interactive 197 int disableFlags = SYSUI_STATE_NAV_BAR_HIDDEN 198 | SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED 199 | SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING; 200 return (sysuiStateFlags & disableFlags) != 0; 201 } 202 203 /** 204 * @return whether this nav bar mode is edge to edge 205 */ isGesturalMode(int mode)206 public static boolean isGesturalMode(int mode) { 207 return mode == NAV_BAR_MODE_GESTURAL; 208 } 209 210 /** 211 * @return whether this nav bar mode is swipe up 212 */ isSwipeUpMode(int mode)213 public static boolean isSwipeUpMode(int mode) { 214 return mode == NAV_BAR_MODE_2BUTTON; 215 } 216 217 /** 218 * @return whether this nav bar mode is 3 button 219 */ isLegacyMode(int mode)220 public static boolean isLegacyMode(int mode) { 221 return mode == NAV_BAR_MODE_3BUTTON; 222 } 223 224 /** 225 * Corner radius that should be used on windows in order to cover the display. 226 * These values are expressed in pixels because they should not respect display or font 227 * scaling, this means that we don't have to reload them on config changes. 228 */ getWindowCornerRadius(Resources resources)229 public static float getWindowCornerRadius(Resources resources) { 230 return ScreenDecorationsUtils.getWindowCornerRadius(resources); 231 } 232 233 /** 234 * If live rounded corners are supported on windows. 235 */ supportsRoundedCornersOnWindows(Resources resources)236 public static boolean supportsRoundedCornersOnWindows(Resources resources) { 237 return ScreenDecorationsUtils.supportsRoundedCornersOnWindows(resources); 238 } 239 } 240