• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // Overview is disabled, either because the device is in lock task mode, or because the device
53     // policy has disabled the feature
54     public static final int SYSUI_STATE_SCREEN_PINNING = 1 << 0;
55     // The navigation bar is hidden due to immersive mode
56     public static final int SYSUI_STATE_NAV_BAR_HIDDEN = 1 << 1;
57     // The notification panel is expanded and interactive (either locked or unlocked), and the
58     // quick settings is not expanded
59     public static final int SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED = 1 << 2;
60     // The keyguard bouncer is showing
61     public static final int SYSUI_STATE_BOUNCER_SHOWING = 1 << 3;
62     // The navigation bar a11y button should be shown
63     public static final int SYSUI_STATE_A11Y_BUTTON_CLICKABLE = 1 << 4;
64     // The navigation bar a11y button shortcut is available
65     public static final int SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE = 1 << 5;
66     // The keyguard is showing and not occluded
67     public static final int SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING = 1 << 6;
68     // The recents feature is disabled (either by SUW/SysUI/device policy)
69     public static final int SYSUI_STATE_OVERVIEW_DISABLED = 1 << 7;
70     // The home feature is disabled (either by SUW/SysUI/device policy)
71     public static final int SYSUI_STATE_HOME_DISABLED = 1 << 8;
72     // The keyguard is showing, but occluded
73     public static final int SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED = 1 << 9;
74 
75     @Retention(RetentionPolicy.SOURCE)
76     @IntDef({SYSUI_STATE_SCREEN_PINNING,
77             SYSUI_STATE_NAV_BAR_HIDDEN,
78             SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED,
79             SYSUI_STATE_BOUNCER_SHOWING,
80             SYSUI_STATE_A11Y_BUTTON_CLICKABLE,
81             SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE,
82             SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING,
83             SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED,
84             SYSUI_STATE_OVERVIEW_DISABLED,
85             SYSUI_STATE_HOME_DISABLED
86     })
87     public @interface SystemUiStateFlags {}
88 
getSystemUiStateString(int flags)89     public static String getSystemUiStateString(int flags) {
90         StringJoiner str = new StringJoiner("|");
91         str.add((flags & SYSUI_STATE_SCREEN_PINNING) != 0 ? "screen_pinned" : "");
92         str.add((flags & SYSUI_STATE_OVERVIEW_DISABLED) != 0 ? "overview_disabled" : "");
93         str.add((flags & SYSUI_STATE_HOME_DISABLED) != 0 ? "home_disabled" : "");
94         str.add((flags & SYSUI_STATE_NAV_BAR_HIDDEN) != 0 ? "navbar_hidden" : "");
95         str.add((flags & SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED) != 0 ? "notif_visible" : "");
96         str.add((flags & SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING) != 0 ? "keygrd_visible" : "");
97         str.add((flags & SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED) != 0
98                 ? "keygrd_occluded" : "");
99         str.add((flags & SYSUI_STATE_BOUNCER_SHOWING) != 0 ? "bouncer_visible" : "");
100         str.add((flags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0 ? "a11y_click" : "");
101         str.add((flags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0 ? "a11y_long_click" : "");
102         return str.toString();
103     }
104 
105     /**
106      * Ratio of quickstep touch slop (when system takes over the touch) to view touch slop
107      */
108     public static final float QUICKSTEP_TOUCH_SLOP_RATIO = 3;
109 
110     /**
111      * Touch slop for quickstep gesture
112      */
getQuickStepTouchSlopPx(Context context)113     public static final float getQuickStepTouchSlopPx(Context context) {
114         return QUICKSTEP_TOUCH_SLOP_RATIO * ViewConfiguration.get(context).getScaledTouchSlop();
115     }
116 
117     /**
118      * Touch slopes and thresholds for quick step operations. Drag slop is the point where the
119      * home button press/long press over are ignored and will start to drag when exceeded and the
120      * touch slop is when the respected operation will occur when exceeded. Touch slop must be
121      * larger than the drag slop.
122      */
getQuickStepDragSlopPx()123     public static int getQuickStepDragSlopPx() {
124         return convertDpToPixel(10);
125     }
126 
getQuickStepTouchSlopPx()127     public static int getQuickStepTouchSlopPx() {
128         return convertDpToPixel(24);
129     }
130 
getQuickScrubTouchSlopPx()131     public static int getQuickScrubTouchSlopPx() {
132         return convertDpToPixel(24);
133     }
134 
convertDpToPixel(float dp)135     private static int convertDpToPixel(float dp) {
136         return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
137     }
138 
139     /**
140      * Returns whether the specified sysui state is such that the assistant gesture should be
141      * disabled.
142      */
isAssistantGestureDisabled(int sysuiStateFlags)143     public static boolean isAssistantGestureDisabled(int sysuiStateFlags) {
144         // Disable when in screen pinning, immersive, the bouncer is showing
145         int disableFlags = SYSUI_STATE_SCREEN_PINNING
146                 | SYSUI_STATE_NAV_BAR_HIDDEN
147                 | SYSUI_STATE_BOUNCER_SHOWING;
148         if ((sysuiStateFlags & disableFlags) != 0) {
149             return true;
150         }
151 
152         // Disable when notifications are showing (only if unlocked)
153         if ((sysuiStateFlags & SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED) != 0
154                 && (sysuiStateFlags & SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING) == 0) {
155             return true;
156         }
157 
158         return false;
159     }
160 
161     /**
162      * Returns whether the specified sysui state is such that the back gesture should be
163      * disabled.
164      */
isBackGestureDisabled(int sysuiStateFlags)165     public static boolean isBackGestureDisabled(int sysuiStateFlags) {
166         // Always allow when the bouncer is showing (even on top of the keyguard)
167         if ((sysuiStateFlags & SYSUI_STATE_BOUNCER_SHOWING) != 0) {
168             return false;
169         }
170         // Disable when in screen pinning, immersive, or the notifications are interactive
171         int disableFlags = SYSUI_STATE_SCREEN_PINNING
172                 | SYSUI_STATE_NAV_BAR_HIDDEN
173                 | SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED
174                 | SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING;
175         return (sysuiStateFlags & disableFlags) != 0;
176     }
177 
178     /**
179      * @return whether this nav bar mode is edge to edge
180      */
isGesturalMode(int mode)181     public static boolean isGesturalMode(int mode) {
182         return mode == NAV_BAR_MODE_GESTURAL;
183     }
184 
185     /**
186      * @return whether this nav bar mode is swipe up
187      */
isSwipeUpMode(int mode)188     public static boolean isSwipeUpMode(int mode) {
189         return mode == NAV_BAR_MODE_2BUTTON;
190     }
191 
192     /**
193      * @return whether this nav bar mode is 3 button
194      */
isLegacyMode(int mode)195     public static boolean isLegacyMode(int mode) {
196         return mode == NAV_BAR_MODE_3BUTTON;
197     }
198 
199     /**
200      * Corner radius that should be used on windows in order to cover the display.
201      * These values are expressed in pixels because they should not respect display or font
202      * scaling, this means that we don't have to reload them on config changes.
203      */
getWindowCornerRadius(Resources resources)204     public static float getWindowCornerRadius(Resources resources) {
205         return ScreenDecorationsUtils.getWindowCornerRadius(resources);
206     }
207 
208     /**
209      * If live rounded corners are supported on windows.
210      */
supportsRoundedCornersOnWindows(Resources resources)211     public static boolean supportsRoundedCornersOnWindows(Resources resources) {
212         return ScreenDecorationsUtils.supportsRoundedCornersOnWindows(resources);
213     }
214 }
215