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 isPrimaryAuthRequiredAfterDpmLockdown =
36 containsFlag(
37 flag,
38 LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW
39 )
40
41 val someAuthRequiredAfterUserRequest =
42 containsFlag(flag, LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST)
43
44 val someAuthRequiredAfterTrustAgentExpired =
45 containsFlag(
46 flag,
47 LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED
48 )
49
50 val primaryAuthRequiredForUnattendedUpdate =
51 containsFlag(
52 flag,
53 LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE
54 )
55
56 /** Either Class 3 biometrics or primary auth can be used to unlock the device. */
57 val strongerAuthRequiredAfterNonStrongBiometricsTimeout =
58 containsFlag(
59 flag,
60 LockPatternUtils.StrongAuthTracker
61 .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT
62 )
63 }
64
containsFlagnull65 private fun containsFlag(haystack: Int, needle: Int): Boolean {
66 return haystack and needle != 0
67 }
68