From da0f9cb4a7da0d99e66d7ea53873a549727a8fbc Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 7 Jun 2016 11:19:25 -0300 Subject: [PATCH] fingerprint for Android 6.0+ --- cordova/build.sh | 3 ++ src/js/init.js | 9 ---- src/js/services/fingerprintService.js | 66 +++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/cordova/build.sh b/cordova/build.sh index 882ada2db..890253476 100755 --- a/cordova/build.sh +++ b/cordova/build.sh @@ -158,6 +158,9 @@ if [ ! -d $PROJECT ]; then cordova plugin add cordova-plugin-disable-bitcode checkOK + cordova plugin add cordova-plugin-android-fingerprint-auth + checkOK + fi if $DBGJS diff --git a/src/js/init.js b/src/js/init.js index 81c6594fc..5c95f7ca7 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -31,15 +31,6 @@ angular.element(document).ready(function() { window.plugins.webintent.onNewIntent(handleBitcoinURI); window.handleOpenURL = handleBitcoinURI; - window.plugins.touchid.isAvailable( - function(msg) { - window.touchidAvailable = true; - }, // success handler: TouchID available - function(msg) { - window.touchidAvailable = false; - } // error handler: no TouchID available - ); - startAngular(); }, false); diff --git a/src/js/services/fingerprintService.js b/src/js/services/fingerprintService.js index 91b18af46..f022b3423 100644 --- a/src/js/services/fingerprintService.js +++ b/src/js/services/fingerprintService.js @@ -1,8 +1,53 @@ 'use strict'; -angular.module('copayApp.services').factory('fingerprintService', function($log, gettextCatalog, configService) { +angular.module('copayApp.services').factory('fingerprintService', function($log, gettextCatalog, configService, platformInfo) { var root = {}; + var _isAvailable = false; + + if (platformInfo.isMobile) { + window.plugins.touchid = window.plugins.touchid || {}; + window.plugins.touchid.isAvailable( + function(msg) { + _isAvailable = 'IOS'; + }, + function(msg) { + FingerprintAuth.isAvailable(function() { + _isAvailable = 'ANDROID'; + }, function() { + _isAvailable = false; + }); + }); + }; + + var requestFinger = function(cb) { + console.log('[fingerprintService.js.26:requestFinger:]'); //TODO + try { + FingerprintAuth.show({ + clientId: 'Copay', + clientSecret: 'hVu1NvCZOyUuGgr46bFL', + }, + function(result) { + if (result.withFingerprint) { + $log.debug('Finger OK'); + return cb(); + } else if (result.withPassword) { + $log.debug("Finger: Authenticated with backup password"); + return cb(); + } + }, + function(msg) { + $log.debug('Finger Failed:' + JSON.stringify(msg)); + return cb(gettextCatalog.getString('Finger Scan Failed') + ': ' + msg.localizedDescription); + } + ); + } catch (e) { + $log.warn('Finger Scan Failed:' + JSON.stringify(e)); + return cb(gettextCatalog.getString('Finger Scan Failed')); + }; + }; + + var requestTouchId = function(cb) { try { window.plugins.touchid.verifyFingerprint( @@ -22,15 +67,26 @@ angular.module('copayApp.services').factory('fingerprintService', function($log, }; }; - root.isAvailable = function(client) { + var isNeeded = function(client) { + if (!_isAvailable) return false; + var config = configService.getSync(); config.touchIdFor = config.touchIdFor || {}; - return (window.touchidAvailable && config.touchIdFor[client.credentials.walletId]); + + return config.touchIdFor[client.credentials.walletId]; + }; + + root.isAvailable = function(client) { + return _isAvailable; }; root.check = function(client, cb) { - if (root.isAvailable(client)) { - requestTouchId(cb); + if (isNeeded(client)) { + console.log('[fingerprintService.js.82:_isAvailable:]', _isAvailable); //TODO + if (_isAvailable == 'IOS') + return requestTouchId(cb); + else + return requestFinger(cb); } else { return cb(); }