1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 Copyright 2015 The Android Open Source Project 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16--> 17<!-- TODO(thagikura) Add tests for Activity and Fragment once InstrumentationTests can be run 18 on an emulator or a device. 19 At this moment, due to the different API between the image and the SDK, they can't be launched. 20 E.g. Skipping device 'Nexus 5 - MNC', due to different API preview 'MNC' and 'android-MNC' 21 --> 22<sample> 23 <name>FingerprintDialog</name> 24 <group>Security</group> 25 <package>com.example.android.fingerprintdialog</package> 26 27 <minSdk>23</minSdk> 28 29 <strings> 30 <intro> 31 <![CDATA[ 32This sample demonstrates how you can use registered fingerprints to authenticate the user 33before proceeding some actions such as purchasing an item. 34 ]]> 35 </intro> 36 </strings> 37 38 <template src="base" /> 39 40 <metadata> 41 <!-- Values: {DRAFT | PUBLISHED | INTERNAL | DEPRECATED | SUPERCEDED} --> 42 <status>PUBLISHED</status> 43 <categories>security</categories> 44 <technologies>Android</technologies> 45 <languages>Java</languages> 46 <solutions>Mobile</solutions> 47 <level>INTERMEDIATE</level> 48 <icon>screenshots/big-icon.png</icon> 49 <screenshots> 50 <img>screenshots/1-purchase-screen.png</img> 51 <img>screenshots/2-fingerprint-dialog.png</img> 52 <img>screenshots/3-fingerprint-authenticated.png</img> 53 <img>screenshots/4-new-fingerprint-enrolled.png</img> 54 </screenshots> 55 56 <api_refs> 57 <android>android.hardware.fingerprint.FingerprintManager</android> 58 <android>android.hardware.fingerprint.FingerprintManager.AuthenticationCallback</android> 59 <android>android.hardware.fingerprint.FingerprintManager.CryptoObject</android> 60 <android>android.security.KeyGenParameterSpec</android> 61 <android>java.security.KeyStore</android> 62 <android>javax.crypto.Cipher</android> 63 <android>javax.crypto.KeyGenerator</android> 64 </api_refs> 65 66 <description> 67<![CDATA[ 68A sample that demonstrates to use registered fingerprints to authenticate the user in your app 69]]> 70 </description> 71 72 <intro> 73<![CDATA[ 74This sample demonstrates how you can use registered fingerprints in your app to authenticate the user 75before proceeding some actions such as purchasing an item. 76 77First you need to create a symmetric key in the Android Key Store using [KeyGenerator][1] 78which can be only be used after the user has authenticated with fingerprint and pass 79a [KeyGenParameterSpec][2]. 80 81By setting [KeyGenParameterSpec.Builder.setUserAuthenticationRequired][3] to true, you can permit the 82use of the key only after the user authenticate it including when authenticated with the user's 83fingerprint. 84 85Then start listening to a fingerprint on the fingerprint sensor by calling 86[FingerprintManager.authenticate][4] with a [Cipher][5] initialized with the symmetric key created. 87Or alternatively you can fall back to server-side verified password as an authenticator. 88 89Once the fingerprint (or password) is verified, the 90[FingerprintManager.AuthenticationCallback#onAuthenticationSucceeded()][6] callback is called. 91 92[1]: https://developer.android.com/reference/javax/crypto/KeyGenerator.html 93[2]: https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.html 94[3]: https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder.html#setUserAuthenticationRequired%28boolean%29 95[4]: https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html#authenticate%28android.hardware.fingerprint.FingerprintManager.CryptoObject,%20android.os.CancellationSignal,%20int,%20android.hardware.fingerprint.FingerprintManager.AuthenticationCallback,%20android.os.Handler%29 96[5]: https://developer.android.com/reference/javax/crypto/Cipher.html 97[6]: https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.AuthenticationCallback.html#onAuthenticationSucceeded%28android.hardware.fingerprint.FingerprintManager.AuthenticationResult%29 98]]> 99 </intro> 100 </metadata> 101</sample> 102