1 /*
2  * Copyright (C) 2024 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.quickstep.util
17 
18 import com.android.systemui.shared.system.QuickStepContract
19 import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags
20 
21 /** Util class for holding and checking [SystemUiStateFlags] masks. */
22 object SystemUiFlagUtils {
23     const val KEYGUARD_SYSUI_FLAGS =
24         (QuickStepContract.SYSUI_STATE_BOUNCER_SHOWING or
25             QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING or
26             QuickStepContract.SYSUI_STATE_DEVICE_DOZING or
27             QuickStepContract.SYSUI_STATE_OVERVIEW_DISABLED or
28             QuickStepContract.SYSUI_STATE_HOME_DISABLED or
29             QuickStepContract.SYSUI_STATE_BACK_DISABLED or
30             QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED or
31             QuickStepContract.SYSUI_STATE_WAKEFULNESS_MASK)
32 
33     // If any of these SysUi flags (via QuickstepContract) is set, the device to be considered
34     // locked.
35     private const val MASK_ANY_SYSUI_LOCKED =
36         (QuickStepContract.SYSUI_STATE_BOUNCER_SHOWING or
37             QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING or
38             QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED or
39             QuickStepContract.SYSUI_STATE_DEVICE_DREAMING)
40 
41     /**
42      * Returns true iff the given [SystemUiStateFlags] imply that the device is considered locked.
43      */
44     @JvmStatic
isLockednull45     fun isLocked(@SystemUiStateFlags flags: Long): Boolean {
46         return hasAnyFlag(flags, MASK_ANY_SYSUI_LOCKED) &&
47             !hasAnyFlag(flags, QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_GOING_AWAY)
48     }
49 
50     /**
51      * Taskbar is hidden whenever the device is dreaming. The dreaming state includes the
52      * interactive dreams, AoD, screen off. Since the SYSUI_STATE_DEVICE_DREAMING only kicks in when
53      * the device is asleep, the second condition extends ensures that the transition from and to
54      * the WAKEFULNESS_ASLEEP state also hide the taskbar, and improves the taskbar hide/reveal
55      * animation timings. The Taskbar can show when dreaming if the glanceable hub is showing on
56      * top.
57      */
58     @JvmStatic
isTaskbarHiddennull59     fun isTaskbarHidden(@SystemUiStateFlags flags: Long): Boolean {
60         return ((hasAnyFlag(flags, QuickStepContract.SYSUI_STATE_DEVICE_DREAMING) &&
61             !hasAnyFlag(flags, QuickStepContract.SYSUI_STATE_COMMUNAL_HUB_SHOWING)) ||
62             (flags and QuickStepContract.SYSUI_STATE_WAKEFULNESS_MASK) !=
63                 QuickStepContract.WAKEFULNESS_AWAKE)
64     }
65 
hasAnyFlagnull66     private fun hasAnyFlag(@SystemUiStateFlags flags: Long, flagMask: Long): Boolean {
67         return (flags and flagMask) != 0L
68     }
69 }
70