2015年6月7日日曜日

[android]Fingerprint Dialog

Android M Developer Previewの話です。
Fingerprint Dialog Sample を読んでみます。

・このサンプルはInjectを使って変数の初期化をしています
・com.example.android.fingerprintdialog.MainActivity#onCreateではまず、requestPermissions(new String[]{Manifest.permission.USE_FINGERPRINT}, 0);を使って指紋認証パーミッションの許可を取得しています
・com.example.android.fingerprintdialog.MainActivity#onRequestPermissionsResult
では指紋認証の許可が取れていた場合、android.app.KeyguardManager#isKeyguardSecureで設定がされているかどうかをチェックしています。設定されていなければ「"Secure lock screen hasn't set up.\nGo to 'Settings -> Security -> Fingerprint' to set up a fingerprint"」をToast表示して終了です。
・まず、Settings -> Security -> Fingerprintで設定をしています。指示通り進めていくと、指紋センサーに触るように言われるのでエミュレータの場合は、「$ adb -e emu finger touch <finger_id>」で指紋センサーにさわったことにします。具体的には、「$ adb -e emu finger touch 1234」みたいな感じです。
・再びFingerprint アプリを起動します
・PURCHASEボタンを押すと下図のようなダイアログが表示されるので、指紋センサーに触ります。エミュレータの場合は「$ adb -e emu finger touch 1234」みたいな感じです。
 ・ダイアログはcom.example.android.fingerprintdialog.FingerprintAuthenticationDialogFragmentです
 ・com.example.android.fingerprintdialog.FingerprintUiHelperで指紋認証のコールバックを受け取っています
 ・指紋認証の成功コールバックは、com.example.android.fingerprintdialog.FingerprintUiHelper#onAuthenticationSucceededです。
 ・com.example.android.fingerprintdialog.FingerprintAuthenticationDialogFragment#onAuthenticated -> com.example.android.fingerprintdialog.MainActivity#onPurchased -> com.example.android.fingerprintdialog.MainActivity#tryEncryptcom.example.android.fingerprintdialog.MainActivity#tryEncrypt へと連鎖します。私のエミュレータでは、この最後のtryEncryptメソッドで例外発生のルートへ突入します。そもそもこのタイミングでjavax.crypto.Cipher#doFinal(byte[])をしている理由がいまいちよくわからないです。
・指紋認証が使えないときの代替手段として、パスワード認証が用意されています。こちらはサンプルですので何を入力しても成功となっています。
・指紋認証関係のAPIをメモしておきます。
 ・android.app.Activity#requestPermissions : 指紋認証のパーミッションを要求します
 ・android.app.Activity#onRequestPermissionsResult: 指紋認証のパーミッションの結果がコールバックされます
 ・android.hardware.fingerprint.FingerprintManager#isHardwareDetected : 指紋認証のセンサーがあるかどうか
 ・android.hardware.fingerprint.FingerprintManager#hasEnrolledFingerprints : 指紋が登録されているかどうか
 ・android.hardware.fingerprint.FingerprintManager#authenticate(FingerprintManager.CryptoObject crypto, CancellationSignal cancel, FingerprintManager.AuthenticationCallback callback, int flags) で指紋センサーからの入力をコールバックしてもらうオブジェクトを登録しておきます
・FingerprintManager.AuthenticationCallbackはabstractクラスで4つのコールバックがあります。指紋認証に成功したときのコールバックは、onAuthenticationSucceededです。








0 件のコメント:

コメントを投稿