FingerprintEnrollFindSensor.java revision 2fef19dd16dac3b79ea5a0f3846b2ac8818662cf
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.content.Intent;
20import android.hardware.fingerprint.FingerprintManager;
21import android.os.Bundle;
22
23import com.android.settings.ChooseLockSettingsHelper;
24import com.android.settings.R;
25
26/**
27 * Activity explaining the fingerprint sensor location for fingerprint enrollment.
28 */
29public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
30
31    private static final int CONFIRM_REQUEST = 1;
32    private static final int ENROLLING = 2;
33
34    private FingerprintLocationAnimationView mAnimation;
35
36    @Override
37    protected void onCreate(Bundle savedInstanceState) {
38        super.onCreate(savedInstanceState);
39        setContentView(R.layout.fingerprint_enroll_find_sensor);
40        setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title);
41        if (mToken == null) {
42            launchConfirmLock();
43        }
44        mAnimation = (FingerprintLocationAnimationView) findViewById(
45                R.id.fingerprint_sensor_location_animation);
46    }
47
48    @Override
49    protected void onStart() {
50        super.onStart();
51        mAnimation.startAnimation();
52    }
53
54    @Override
55    protected void onStop() {
56        super.onStop();
57        mAnimation.stopAnimation();
58    }
59
60    @Override
61    protected void onNextButtonClick() {
62        startActivityForResult(getEnrollingIntent(), ENROLLING);
63    }
64
65    @Override
66    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
67        if (requestCode == CONFIRM_REQUEST) {
68            if (resultCode == RESULT_OK) {
69                mToken = data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
70                overridePendingTransition(R.anim.suw_slide_next_in, R.anim.suw_slide_next_out);
71            } else {
72                finish();
73            }
74        } else if (requestCode == ENROLLING) {
75            if (resultCode == RESULT_FINISHED) {
76                finish();
77            }
78        } else {
79            super.onActivityResult(requestCode, resultCode, data);
80        }
81    }
82
83    private void launchConfirmLock() {
84        long challenge = getSystemService(FingerprintManager.class).preEnroll();
85        ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
86        if (!helper.launchConfirmationActivity(CONFIRM_REQUEST,
87                getString(R.string.security_settings_fingerprint_preference_title),
88                null, null, challenge)) {
89
90            // This shouldn't happen, as we should only end up at this step if a lock thingy is
91            // already set.
92            finish();
93        }
94    }
95}
96