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 <targetSdkVersion>26</targetSdkVersion> 29 <compileSdkVersion>26</compileSdkVersion> 30 31 <strings> 32 <intro> 33 <![CDATA[ 34This sample demonstrates how you can use registered fingerprints to authenticate the user 35before proceeding some actions such as purchasing an item. 36 ]]> 37 </intro> 38 </strings> 39 40 <template src="base" /> 41 42 <metadata> 43 <!-- Values: {DRAFT | PUBLISHED | INTERNAL | DEPRECATED | SUPERCEDED} --> 44 <status>PUBLISHED</status> 45 <categories>security</categories> 46 <technologies>Android</technologies> 47 <languages>Java</languages> 48 <solutions>Mobile</solutions> 49 <level>INTERMEDIATE</level> 50 <icon>screenshots/big-icon.png</icon> 51 <screenshots> 52 <img>screenshots/1-purchase-screen.png</img> 53 <img>screenshots/2-fingerprint-dialog.png</img> 54 <img>screenshots/3-fingerprint-authenticated.png</img> 55 <img>screenshots/4-new-fingerprint-enrolled.png</img> 56 </screenshots> 57 58 <api_refs> 59 <android>android.hardware.fingerprint.FingerprintManager</android> 60 <android>android.hardware.fingerprint.FingerprintManager.AuthenticationCallback</android> 61 <android>android.hardware.fingerprint.FingerprintManager.CryptoObject</android> 62 <android>android.security.KeyGenParameterSpec</android> 63 <android>java.security.KeyStore</android> 64 <android>javax.crypto.Cipher</android> 65 <android>javax.crypto.KeyGenerator</android> 66 </api_refs> 67 68 <description> 69<![CDATA[ 70A sample that demonstrates to use registered fingerprints to authenticate the user in your app 71]]> 72 </description> 73 74 <intro> 75<![CDATA[ 76This sample demonstrates how you can use registered fingerprints in your app to authenticate the user 77before proceeding some actions such as purchasing an item. 78 79First you need to create a symmetric key in the Android Key Store using [KeyGenerator][1] 80which can be only be used after the user has authenticated with fingerprint and pass 81a [KeyGenParameterSpec][2]. 82 83By setting [KeyGenParameterSpec.Builder.setUserAuthenticationRequired][3] to true, you can permit the 84use of the key only after the user authenticate it including when authenticated with the user's 85fingerprint. 86 87Then start listening to a fingerprint on the fingerprint sensor by calling 88[FingerprintManager.authenticate][4] with a [Cipher][5] initialized with the symmetric key created. 89Or alternatively you can fall back to server-side verified password as an authenticator. 90 91Once the fingerprint (or password) is verified, the 92[FingerprintManager.AuthenticationCallback#onAuthenticationSucceeded()][6] callback is called. 93 94[1]: https://developer.android.com/reference/javax/crypto/KeyGenerator.html 95[2]: https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.html 96[3]: https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder.html#setUserAuthenticationRequired%28boolean%29 97[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 98[5]: https://developer.android.com/reference/javax/crypto/Cipher.html 99[6]: https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.AuthenticationCallback.html#onAuthenticationSucceeded%28android.hardware.fingerprint.FingerprintManager.AuthenticationResult%29 100]]> 101 </intro> 102 </metadata> 103</sample> 104