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 
hasAnyFlagnull50     private fun hasAnyFlag(@SystemUiStateFlags flags: Long, flagMask: Long): Boolean {
51         return (flags and flagMask) != 0L
52     }
53 }
54