1 /*
2  * Copyright (C) 2021 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.settings.biometrics.face;
18 
19 import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE;
20 
21 import android.app.settings.SettingsEnums;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.view.View;
25 
26 import androidx.annotation.Nullable;
27 import androidx.annotation.StringRes;
28 
29 import com.android.settings.R;
30 
31 /**
32  * Displays parental consent information for face authentication.
33  */
34 public class FaceEnrollParentalConsent extends FaceEnrollIntroduction {
35 
36     /**
37      * List of string resources to log when recording the result of this activity in gms.
38      * This must be updated when any strings are added/removed.
39      */
40     public static final int[] CONSENT_STRING_RESOURCES = new int[] {
41             R.string.security_settings_face_enroll_consent_introduction_title,
42             R.string.security_settings_face_enroll_introduction_consent_message,
43             R.string.security_settings_face_enroll_introduction_info_consent_glasses,
44             R.string.security_settings_face_enroll_introduction_info_consent_looking,
45             R.string.security_settings_face_enroll_introduction_info_consent_gaze,
46             R.string.security_settings_face_enroll_introduction_how_consent_message,
47             R.string.security_settings_face_enroll_introduction_control_consent_title,
48             R.string.security_settings_face_enroll_introduction_control_consent_message,
49             R.string.security_settings_face_enroll_introduction_consent_message_0,
50             R.string.security_settings_face_enroll_introduction_consent_message_0_class3,
51             R.string.security_settings_face_enroll_introduction_info_consent_less_secure
52     };
53 
54     @Override
onCreate(Bundle savedInstanceState)55     protected void onCreate(Bundle savedInstanceState) {
56         super.onCreate(savedInstanceState);
57         updateDescriptionText();
58     }
59 
60     @Override
onNextButtonClick(View view)61     protected void onNextButtonClick(View view) {
62         onConsentResult(true /* granted */);
63     }
64 
65     @Override
onSkipButtonClick(View view)66     protected void onSkipButtonClick(View view) {
67         onConsentResult(false /* granted */);
68     }
69 
70     @Override
onEnrollmentSkipped(@ullable Intent data)71     protected void onEnrollmentSkipped(@Nullable Intent data) {
72         onConsentResult(false /* granted */);
73     }
74 
75     @Override
onFinishedEnrolling(@ullable Intent data)76     protected void onFinishedEnrolling(@Nullable Intent data) {
77         onConsentResult(true /* granted */);
78     }
79 
onConsentResult(boolean granted)80     private void onConsentResult(boolean granted) {
81         final Intent result = new Intent();
82         result.putExtra(EXTRA_KEY_MODALITY, TYPE_FACE);
83         setResult(granted ? RESULT_CONSENT_GRANTED : RESULT_CONSENT_DENIED, result);
84         finish();
85     }
86 
87     @Override
onSetOrConfirmCredentials(@ullable Intent data)88     protected boolean onSetOrConfirmCredentials(@Nullable Intent data) {
89         // prevent challenge from being generated by default
90         return true;
91     }
92 
93     @Override
generateChallengeOnCreate()94     protected boolean generateChallengeOnCreate() {
95         return false;
96     }
97 
98     @Override
99     @StringRes
getInfoMessageGlasses()100     protected int getInfoMessageGlasses() {
101         return R.string.security_settings_face_enroll_introduction_info_consent_glasses;
102     }
103 
104     @Override
105     @StringRes
getInfoMessageLooking()106     protected int getInfoMessageLooking() {
107         return R.string.security_settings_face_enroll_introduction_info_consent_looking;
108     }
109 
110     @Override
111     @StringRes
getInfoMessageRequireEyes()112     protected int getInfoMessageRequireEyes() {
113         return R.string.security_settings_face_enroll_introduction_info_consent_gaze;
114     }
115 
116     @Override
117     @StringRes
getHowMessage()118     protected int getHowMessage() {
119         return R.string.security_settings_face_enroll_introduction_how_consent_message;
120     }
121 
122     @Override
123     @StringRes
getInControlTitle()124     protected int getInControlTitle() {
125         return R.string.security_settings_face_enroll_introduction_control_consent_title;
126     }
127 
128     @Override
129     @StringRes
getInControlMessage()130     protected int getInControlMessage() {
131         return R.string.security_settings_face_enroll_introduction_control_consent_message;
132     }
133 
134     @Override
getHeaderResDefault()135     protected int getHeaderResDefault() {
136         return R.string.security_settings_face_enroll_consent_introduction_title;
137     }
138 
139     @Override
getLessSecureMessage()140     protected int getLessSecureMessage() {
141         return R.string.security_settings_face_enroll_introduction_info_consent_less_secure;
142     }
143 
144     @Override
getMetricsCategory()145     public int getMetricsCategory() {
146         return SettingsEnums.FACE_PARENTAL_CONSENT;
147     }
148 
149     @Override
updateDescriptionText()150     protected void updateDescriptionText() {
151         super.updateDescriptionText();
152         if (isFaceStrong()) {
153             setDescriptionText(getString(
154                     R.string.security_settings_face_enroll_introduction_consent_message_0_class3));
155         } else {
156             setDescriptionText(
157                     R.string.security_settings_face_enroll_introduction_consent_message_0);
158         }
159     }
160 }
161