From 36b39ffaf5d3eb8f9da4914d3ef7c11b84a8300c Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 16 Apr 2020 11:30:00 -0300 Subject: [PATCH] Auto lock option label --- app/utils/localAuthentication.js | 20 ++++++++++++++++++++ app/views/ScreenLockConfigView.js | 13 +++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/utils/localAuthentication.js b/app/utils/localAuthentication.js index 6c452cc6c..c571ff2a1 100644 --- a/app/utils/localAuthentication.js +++ b/app/utils/localAuthentication.js @@ -2,6 +2,7 @@ import * as LocalAuthentication from 'expo-local-authentication'; import moment from 'moment'; import database from '../lib/database'; +import { isIOS } from './deviceInfo'; export const saveLastLocalAuthenticationSession = async(server) => { console.log('saveLastLocalAuthenticationSession -> server', server); @@ -32,10 +33,13 @@ export const localAuthenticate = async(server) => { return Promise.reject(); } + console.log('localAuthenticate -> serverRecord', serverRecord); if (serverRecord?.autoLock) { const diffToLastSession = moment().diff(serverRecord?.lastLocalAuthenticatedSession, 'seconds'); + console.log('localAuthenticate -> diffToLastSession', diffToLastSession); if (diffToLastSession >= serverRecord?.autoLockTime) { const supported = await LocalAuthentication.supportedAuthenticationTypesAsync(); + console.log('localAuthenticate -> supported', supported); const authResult = await LocalAuthentication.authenticateAsync(); if (authResult?.success) { await saveLastLocalAuthenticationSession(server); @@ -47,3 +51,19 @@ export const localAuthenticate = async(server) => { } return Promise.resolve(true); }; + +export const supportedAuthenticationLabel = async() => { + const supported = await LocalAuthentication.supportedAuthenticationTypesAsync(); + console.log('supportedAuthenticationLabel -> supported', supported); + + const enrolled = await LocalAuthentication.isEnrolledAsync(); + console.log('supportedAuthenticationLabel -> enrolled', enrolled); + + if (supported.includes(LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION)) { + return isIOS ? 'FaceID' : 'facial recognition'; + } + if (supported.includes(LocalAuthentication.AuthenticationType.FINGERPRINT)) { + return isIOS ? 'TouchID' : 'fingerprint'; + } + return null; +}; diff --git a/app/views/ScreenLockConfigView.js b/app/views/ScreenLockConfigView.js index 6c88f9a95..d88b7b269 100644 --- a/app/views/ScreenLockConfigView.js +++ b/app/views/ScreenLockConfigView.js @@ -16,11 +16,12 @@ import Separator from '../containers/Separator'; import ListItem from '../containers/ListItem'; import { CustomIcon } from '../lib/Icons'; import database from '../lib/database'; +import { supportedAuthenticationLabel } from '../utils/localAuthentication'; const DEFAULT_AUTO_LOCK = [ { title: 'After 1 minute', - value: 60 + value: 0 }, { title: 'After 5 minutes', @@ -80,7 +81,8 @@ class ScreenLockConfigView extends React.Component { this.state = { autoLock: false, autoLockTime: null, - supported: [] + supported: [], + autoLockLabel: '' }; this.init(); } @@ -95,6 +97,9 @@ class ScreenLockConfigView extends React.Component { } catch (error) { // TODO: raise error in case server wasn't found and pop? } + + const autoLockLabel = await supportedAuthenticationLabel(); + this.setState({ autoLockLabel }); } save = async() => { @@ -175,7 +180,7 @@ class ScreenLockConfigView extends React.Component { } render() { - const { autoLock, supported } = this.state; + const { autoLock, supported, autoLockLabel } = this.state; const { theme } = this.props; return ( this.renderSwitch()} theme={theme} />