• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 package com.android.launcher3.taskbar;
17 
18 import static com.android.launcher3.util.FlagDebugUtils.appendFlag;
19 
20 import androidx.annotation.IntDef;
21 
22 import com.android.quickstep.SystemUiProxy;
23 
24 import java.io.PrintWriter;
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 import java.util.StringJoiner;
28 
29 /**
30  * Normally Taskbar will auto-hide when entering immersive (fullscreen) apps. This controller allows
31  * us to suspend that behavior in certain cases (e.g. opening a Folder or dragging an icon).
32  */
33 public class TaskbarAutohideSuspendController implements
34         TaskbarControllers.LoggableTaskbarController {
35 
36     // Taskbar window is fullscreen.
37     public static final int FLAG_AUTOHIDE_SUSPEND_FULLSCREEN = 1 << 0;
38     // User is dragging item.
39     public static final int FLAG_AUTOHIDE_SUSPEND_DRAGGING = 1 << 1;
40     // User has touched down but has not lifted finger.
41     public static final int FLAG_AUTOHIDE_SUSPEND_TOUCHING = 1 << 2;
42     // Taskbar EDU overlay is open above the Taskbar. */
43     public static final int FLAG_AUTOHIDE_SUSPEND_EDU_OPEN = 1 << 3;
44     // Taskbar in immersive mode in overview
45     public static final int FLAG_AUTOHIDE_SUSPEND_IN_LAUNCHER = 1 << 4;
46 
47     @IntDef(flag = true, value = {
48             FLAG_AUTOHIDE_SUSPEND_FULLSCREEN,
49             FLAG_AUTOHIDE_SUSPEND_DRAGGING,
50             FLAG_AUTOHIDE_SUSPEND_TOUCHING,
51             FLAG_AUTOHIDE_SUSPEND_EDU_OPEN,
52             FLAG_AUTOHIDE_SUSPEND_IN_LAUNCHER,
53     })
54     @Retention(RetentionPolicy.SOURCE)
55     public @interface AutohideSuspendFlag {}
56 
57     private final TaskbarActivityContext mActivity;
58     private final SystemUiProxy mSystemUiProxy;
59 
60     private @AutohideSuspendFlag int mAutohideSuspendFlags = 0;
61 
TaskbarAutohideSuspendController(TaskbarActivityContext activity)62     public TaskbarAutohideSuspendController(TaskbarActivityContext activity) {
63         mActivity = activity;
64         mSystemUiProxy = SystemUiProxy.INSTANCE.get(activity);
65     }
66 
onDestroy()67     public void onDestroy() {
68         mSystemUiProxy.notifyTaskbarAutohideSuspend(false);
69     }
70 
71     /**
72      * Adds or removes the given flag, then notifies system UI proxy whether to suspend auto-hide.
73      */
updateFlag(@utohideSuspendFlag int flag, boolean enabled)74     public void updateFlag(@AutohideSuspendFlag int flag, boolean enabled) {
75         int flagsBefore = mAutohideSuspendFlags;
76         if (enabled) {
77             mAutohideSuspendFlags |= flag;
78         } else {
79             mAutohideSuspendFlags &= ~flag;
80         }
81         if (flagsBefore == mAutohideSuspendFlags) {
82             // Nothing has changed, no need to notify.
83             return;
84         }
85 
86         boolean isSuspended = isSuspended();
87         mSystemUiProxy.notifyTaskbarAutohideSuspend(isSuspended);
88         mActivity.onTransientAutohideSuspendFlagChanged(isSuspended);
89     }
90 
91     /**
92      * Returns true iff taskbar autohide is currently suspended.
93      */
isSuspended()94     public boolean isSuspended() {
95         return mAutohideSuspendFlags != 0;
96     }
97 
isSuspendedForTransientTaskbarInOverview()98     public boolean isSuspendedForTransientTaskbarInOverview() {
99         return (mAutohideSuspendFlags & FLAG_AUTOHIDE_SUSPEND_IN_LAUNCHER) != 0;
100     }
101 
102     @Override
dumpLogs(String prefix, PrintWriter pw)103     public void dumpLogs(String prefix, PrintWriter pw) {
104         pw.println(prefix + "TaskbarAutohideSuspendController:");
105 
106         pw.println(prefix + "\tmAutohideSuspendFlags=" + getStateString(mAutohideSuspendFlags));
107     }
108 
getStateString(int flags)109     private static String getStateString(int flags) {
110         StringJoiner str = new StringJoiner("|");
111         appendFlag(str, flags, FLAG_AUTOHIDE_SUSPEND_FULLSCREEN,
112                 "FLAG_AUTOHIDE_SUSPEND_FULLSCREEN");
113         appendFlag(str, flags, FLAG_AUTOHIDE_SUSPEND_DRAGGING, "FLAG_AUTOHIDE_SUSPEND_DRAGGING");
114         appendFlag(str, flags, FLAG_AUTOHIDE_SUSPEND_TOUCHING, "FLAG_AUTOHIDE_SUSPEND_TOUCHING");
115         appendFlag(str, flags, FLAG_AUTOHIDE_SUSPEND_EDU_OPEN, "FLAG_AUTOHIDE_SUSPEND_EDU_OPEN");
116         appendFlag(str, flags, FLAG_AUTOHIDE_SUSPEND_IN_LAUNCHER,
117                 "FLAG_AUTOHIDE_SUSPEND_IN_LAUNCHER");
118         return str.toString();
119     }
120 }
121