1 /*
2  * Copyright (C) 2023 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.keyguard.shared.model
18 
19 import com.android.internal.widget.LockPatternUtils
20 
21 /** Authentication flags corresponding to a user. */
22 data class AuthenticationFlags(val userId: Int, val flag: Int) {
23     val isInUserLockdown =
24         containsFlag(
25             flag,
26             LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN
27         )
28 
29     val isPrimaryAuthRequiredAfterReboot =
30         containsFlag(flag, LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT)
31 
32     val isPrimaryAuthRequiredAfterTimeout =
33         containsFlag(flag, LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT)
34 
35     val isPrimaryAuthRequiredAfterLockout =
36         containsFlag(flag, LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT)
37 
38     val isPrimaryAuthRequiredAfterDpmLockdown =
39         containsFlag(
40             flag,
41             LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW
42         )
43 
44     val someAuthRequiredAfterUserRequest =
45         containsFlag(flag, LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST)
46 
47     val someAuthRequiredAfterTrustAgentExpired =
48         containsFlag(
49             flag,
50             LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED
51         )
52 
53     val isPrimaryAuthRequiredForUnattendedUpdate =
54         containsFlag(
55             flag,
56             LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE
57         )
58 
59     /** Either Class 3 biometrics or primary auth can be used to unlock the device. */
60     val strongerAuthRequiredAfterNonStrongBiometricsTimeout =
61         containsFlag(
62             flag,
63             LockPatternUtils.StrongAuthTracker
64                 .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT
65         )
66 
67     val isSomeAuthRequiredAfterAdaptiveAuthRequest =
68         containsFlag(
69             flag,
70             LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_ADAPTIVE_AUTH_REQUEST
71         )
72 }
73 
containsFlagnull74 private fun containsFlag(haystack: Int, needle: Int): Boolean {
75     return haystack and needle != 0
76 }
77