1/*
2 * Copyright (C) 2015 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
17package com.android.settings.fingerprint;
18
19import android.app.KeyguardManager;
20import android.content.Intent;
21import android.content.res.Resources;
22import android.os.UserHandle;
23import android.widget.Button;
24import android.widget.TextView;
25
26import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
27import com.android.internal.widget.LockPatternUtils;
28import com.android.settings.R;
29import com.android.settings.SetupChooseLockGeneric;
30import com.android.settings.SetupWizardUtils;
31
32public class SetupFingerprintEnrollIntroduction extends FingerprintEnrollIntroduction {
33
34    @Override
35    protected Intent getChooseLockIntent() {
36        Intent intent = new Intent(this, SetupChooseLockGeneric.class);
37        SetupWizardUtils.copySetupExtras(getIntent(), intent);
38        return intent;
39    }
40
41    @Override
42    protected Intent getFindSensorIntent() {
43        final Intent intent = new Intent(this, SetupFingerprintEnrollFindSensor.class);
44        SetupWizardUtils.copySetupExtras(getIntent(), intent);
45        return intent;
46    }
47
48    @Override
49    protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
50        resid = SetupWizardUtils.getTheme(getIntent());
51        super.onApplyThemeResource(theme, resid, first);
52    }
53
54    @Override
55    protected void initViews() {
56        super.initViews();
57
58        TextView description = (TextView) findViewById(R.id.description_text);
59        description.setText(
60                R.string.security_settings_fingerprint_enroll_introduction_message_setup);
61
62        Button nextButton = getNextButton();
63        nextButton.setText(
64                R.string.security_settings_fingerprint_enroll_introduction_continue_setup);
65
66        final Button cancelButton = (Button) findViewById(R.id.fingerprint_cancel_button);
67        cancelButton.setText(
68                R.string.security_settings_fingerprint_enroll_introduction_cancel_setup);
69    }
70
71    @Override
72    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
73        if (requestCode == FINGERPRINT_FIND_SENSOR_REQUEST) {
74            if (data == null) {
75                data = new Intent();
76            }
77            LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
78            data.putExtra(SetupChooseLockGeneric.
79                    SetupChooseLockGenericFragment.EXTRA_PASSWORD_QUALITY,
80                    lockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId()));
81        }
82        super.onActivityResult(requestCode, resultCode, data);
83    }
84
85    @Override
86    protected void onCancelButtonClick() {
87        KeyguardManager keyguardManager = getSystemService(KeyguardManager.class);
88        if (keyguardManager.isKeyguardSecure()) {
89            // If the keyguard is already set up securely (maybe the user added a backup screen
90            // lock and skipped fingerprint), return RESULT_SKIP directly.
91            setResult(RESULT_SKIP);
92            finish();
93        } else {
94            SetupSkipDialog dialog = SetupSkipDialog.newInstance(
95                    getIntent().getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
96            dialog.show(getFragmentManager());
97        }
98    }
99
100    @Override
101    public int getMetricsCategory() {
102        return MetricsEvent.FINGERPRINT_ENROLL_INTRO_SETUP;
103    }
104}
105