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.authentication.shared.model
18 
19 import androidx.annotation.StringRes
20 import com.android.systemui.res.R
21 
22 /**
23  * Some users have a DevicePolicyManager that requests a user/profile to be wiped after N
24  * unsuccessful authentication attempts. This models the pre-wipe state, so that a warning can be
25  * shown.
26  */
27 data class AuthenticationWipeModel(
28     /** Indicates what part of the user data will be removed. */
29     val wipeTarget: WipeTarget,
30 
31     /** Unsuccessful authentication attempts since the last successful device entry. */
32     val failedAttempts: Int,
33 
34     /**
35      * Remaining failed authentication attempts before wipe is triggered. 0 indicates a wipe is
36      * imminent, no more authentication attempts are allowed.
37      */
38     val remainingAttempts: Int,
39 ) {
40     sealed class WipeTarget(
41         @StringRes val messageIdForAlmostWipe: Int,
42         @StringRes val messageIdForWipe: Int,
43     ) {
44         /** The work profile will be removed, which will delete all profile data. */
45         data object ManagedProfile :
46             WipeTarget(
47                 messageIdForAlmostWipe = R.string.kg_failed_attempts_almost_at_erase_profile,
48                 messageIdForWipe = R.string.kg_failed_attempts_now_erasing_profile,
49             )
50 
51         /** The user will be removed, which will delete all user data. */
52         data object User :
53             WipeTarget(
54                 messageIdForAlmostWipe = R.string.kg_failed_attempts_almost_at_erase_user,
55                 messageIdForWipe = R.string.kg_failed_attempts_now_erasing_user,
56             )
57 
58         /** The device will be reset and all data will be deleted. */
59         data object WholeDevice :
60             WipeTarget(
61                 messageIdForAlmostWipe = R.string.kg_failed_attempts_almost_at_wipe,
62                 messageIdForWipe = R.string.kg_failed_attempts_now_wiping,
63             )
64     }
65 }
66