From 3ea8e7b6401a75c676e826b7f4ca0798dcc3b2f6 Mon Sep 17 00:00:00 2001 From: "siqi.wang" Date: Mon, 14 Feb 2022 13:42:12 +0800 Subject: [PATCH 1/2] [faceEnrollUX]Code update. 1.Code update. Signed-off-by: siqi.wang --- .../main/ets/default/common/Config/config.ets | 33 +-- .../common/manager/resourceManager.ets | 7 + .../common/model/FaceSettingsModel.ets | 20 +- .../default/common/model/userAuthModel.ets | 44 ++-- .../common/presenter/userAuthPresenter.ets | 50 +++- .../feature/faceSettings/build.gradle | 4 +- .../main/ets/default/pages/faceSettings.ets | 18 +- .../base/media/ic_settings_arrow.svg | 2 +- .../feature/faceSettingsPad/build.gradle | 4 +- .../src/main/ets/default/pages/index.ets | 50 ++-- .../base/media/ic_settings_arrow.svg | 2 +- .../feature/trustedDevice/build.gradle | 4 +- .../src/main/ets/default/pages/index.ets | 7 +- .../main/resources/base/media/into_arrow.svg | 2 +- .../feature/trusteddevicepad/build.gradle | 4 +- .../trusteddevicepad/src/main/config.json | 2 +- .../src/main/ets/default/pages/index.ets | 7 +- .../main/resources/base/media/into_arrow.svg | 2 +- ui/faceenroll/product/pad/build.gradle | 4 +- .../product/pad/src/main/config.json | 2 +- .../src/main/ets/default/pages/declare.ets | 218 ++++++++++++++---- .../src/main/ets/default/pages/enroll_2D.ets | 18 +- .../src/main/ets/default/pages/enroll_3D.ets | 18 +- .../src/main/ets/default/pages/entryView.ets | 22 +- .../pad/src/main/ets/default/pages/index.ets | 8 +- .../main/ets/default/pages/startViews_2D.ets | 14 +- .../main/ets/default/pages/startViews_3D.ets | 15 +- .../src/main/ets/default/pages/success.ets | 22 +- .../src/main/ets/default/pages/userAuth.ets | 69 +++--- .../main/ets/default/pages/userSettings.ets | 12 +- ui/faceenroll/product/phone/build.gradle | 4 +- .../phone/src/main/ets/default/app.ets | 3 +- .../src/main/ets/default/pages/enroll_2D.ets | 19 +- .../src/main/ets/default/pages/enroll_3D.ets | 19 +- .../src/main/ets/default/pages/entryView.ets | 14 +- .../src/main/ets/default/pages/index.ets | 8 +- .../main/ets/default/pages/startViews_2D.ets | 14 +- .../main/ets/default/pages/startViews_3D.ets | 14 +- .../src/main/ets/default/pages/success.ets | 21 +- .../src/main/ets/default/pages/userAuth.ets | 62 +++-- .../main/ets/default/pages/userSettings.ets | 12 +- 41 files changed, 544 insertions(+), 330 deletions(-) diff --git a/ui/faceenroll/common/src/main/ets/default/common/Config/config.ets b/ui/faceenroll/common/src/main/ets/default/common/Config/config.ets index 7230223..c68292b 100644 --- a/ui/faceenroll/common/src/main/ets/default/common/Config/config.ets +++ b/ui/faceenroll/common/src/main/ets/default/common/Config/config.ets @@ -13,29 +13,30 @@ * limitations under the License. */ export default class Config { - public static FACE_TOKEN: array = new Uint8Array([1,2,3,4,5,6]) - public static TRUSTED_DEVICE_CHECK = false - public static AUTH_TYPE = 2 - public static TYPE2D = "2D" + public static FACE_TOKEN = new Uint8Array([1,2,3,4,5,6]); + public static TRUSTED_DEVICE_CHECK = false; + public static AUTH_TYPE = 2; + public static TYPE2D = "2D"; public static AUTH = [ { - credentialId:new Uint8Array([1,2,3,4,5,6]), + credentialId:Math.random()*1000, authType:2, authSubType:20000, templateId:1 }, - { - credentialId:new Uint8Array([1,2,3,4,5,6]), - authType:2, - authSubType:20000, - templateId:2 - } - ] +// { +// credentialId:Math.random()*1000, +// authType:2, +// authSubType:20000, +// templateId:2 +// } + ]; public static FACE_DATA = { - credentialId: credentialId, + credentialId: Math.random()*1000, authType: 2, authSubType: 1, - templateId: 1 + templateId: 1, + name:'' } public static DEVICE_LIST = [ { @@ -54,7 +55,7 @@ export default class Config { name: "HuaWei p30", isLock: true } - ] + ]; public static ADD_LIST = [ { name: "HuaWei Mate40 add", @@ -72,5 +73,5 @@ export default class Config { name: "HuaWei p30 add", isLock: false } - ] + ]; } \ No newline at end of file diff --git a/ui/faceenroll/common/src/main/ets/default/common/manager/resourceManager.ets b/ui/faceenroll/common/src/main/ets/default/common/manager/resourceManager.ets index e239ae2..aa624f0 100644 --- a/ui/faceenroll/common/src/main/ets/default/common/manager/resourceManager.ets +++ b/ui/faceenroll/common/src/main/ets/default/common/manager/resourceManager.ets @@ -13,6 +13,7 @@ * limitations under the License. */ import Config from "../Config/Config.ets" +import FeatureAbility from '@ohos.ability.featureAbility'; export default class ResourceManager { @@ -45,4 +46,10 @@ export default class ResourceManager { // console.info("FaceEnroll resourceManager startApplicationForResult promise::catch : " + JSON.stringify(error)); // ); } + + public terminateSelf() { + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) + } } \ No newline at end of file diff --git a/ui/faceenroll/common/src/main/ets/default/common/model/FaceSettingsModel.ets b/ui/faceenroll/common/src/main/ets/default/common/model/FaceSettingsModel.ets index 1e75f9b..b3405bd 100644 --- a/ui/faceenroll/common/src/main/ets/default/common/model/FaceSettingsModel.ets +++ b/ui/faceenroll/common/src/main/ets/default/common/model/FaceSettingsModel.ets @@ -33,8 +33,13 @@ export default class FaceSettingsModel { */ NewFaceData(callback) { console.info("FaceEnroll FaceSettingsModel NewFaceData start"); - let credentialId = Math.random()*1000; - let faceData = Config.FACE_DATA + let faceData = { + credentialId: Math.random() * 1000, + authType: 2, + authSubType: 1, + templateId: 1, + name: '' + } callback(faceData); console.info("FaceEnroll FaceSettingsModel NewFaceData end"); } @@ -47,7 +52,8 @@ export default class FaceSettingsModel { */ chooseUnlockMethod(method) { console.info('FaceEnroll FaceSettingsModel chooseUnlockMethod start'); - console.info('FaceEnroll FaceSettingsModel chooseUnlockMethod method' + method); + AppStorage.SetOrCreate('unlock_num', method); + PersistentStorage.PersistProp("unlock_num", method); console.info('FaceEnroll FaceSettingsModel chooseUnlockMethod end '); } @@ -60,6 +66,7 @@ export default class FaceSettingsModel { console.info('FaceEnroll FaceSettingsModel activateAppLock start'); if (status === true) { AppStorage.SetOrCreate('appLock_isOn', true); + PersistentStorage.PersistProp("appLock_isOn", true); } else { console.info("FaceEnroll FaceSettingsModel close AppLock "); AppStorage.SetOrCreate('appLock_isOn', false); @@ -76,6 +83,7 @@ export default class FaceSettingsModel { console.info('FaceEnroll FaceSettingsModel activateSafeCabinet start'); if (status === true) { AppStorage.SetOrCreate('safeCabinet_isOn', true); + PersistentStorage.PersistProp("safeCabinet_isOn", true); } else { console.info("FaceEnroll FaceSettingsModel close activateSafeCabinet "); AppStorage.SetOrCreate('safeCabinet_isOn', false); @@ -93,6 +101,7 @@ export default class FaceSettingsModel { console.info("FaceEnroll FaceSettingsModel ScreenFillFightInLowLightEnvironment start"); if (status == true) { AppStorage.SetOrCreate('fillLight_isOn', true); + PersistentStorage.PersistProp("fillLight_isOn", true); } else { console.info("FaceEnroll FaceSettingsModel close ScreenFillFightInLowLightEnvironment "); AppStorage.SetOrCreate('fillLight_isOn', false); @@ -109,6 +118,7 @@ export default class FaceSettingsModel { console.info("FaceEnroll FaceSettingsModel SmartLockScreenNotifications start"); if (status === true) { AppStorage.SetOrCreate('smartDisplayLockScreen_isOn', true); + PersistentStorage.PersistProp("smartDisplayLockScreen_isOn", true); } else { console.info("FaceEnroll FaceSettingsModel close SmartLockScreenNotifications "); AppStorage.SetOrCreate('smartDisplayLockScreen_isOn', false); @@ -125,6 +135,7 @@ export default class FaceSettingsModel { console.info("faceSettingsModel FillInAccountPassword start"); if (status === true) { AppStorage.SetOrCreate('fillInAccount_isOn', true); + PersistentStorage.PersistProp("fillInAccount_isOn", true); } else { console.info("FaceEnroll FaceSettingsModel close FillInAccountPassword "); AppStorage.SetOrCreate('fillInAccount_isOn', false); @@ -141,6 +152,7 @@ export default class FaceSettingsModel { console.info("FaceEnroll FaceSettingsModel lookAtScreenDuringFaceRecognition start"); if (status === true) { AppStorage.SetOrCreate('lookAtScreenDuringFaceRecognition_isOn', true); + PersistentStorage.PersistProp("lookAtScreenDuringFaceRecognition_isOn", true); } else { console.info("FaceEnroll FaceSettingsModel close lookAtScreenDuringFaceRecognition "); AppStorage.SetOrCreate('lookAtScreenDuringFaceRecognition_isOn', false); @@ -157,6 +169,7 @@ export default class FaceSettingsModel { console.info("FaceEnroll FaceSettingsModel auxiliaryMode start"); if (status === true) { AppStorage.SetOrCreate('auxiliaryMode_isOn', true); + PersistentStorage.PersistProp("auxiliaryMode_isOn", true); } else { console.info("FaceEnroll FaceSettingsModel close auxiliaryMode "); AppStorage.SetOrCreate('auxiliaryMode_isOn', false); @@ -174,6 +187,7 @@ export default class FaceSettingsModel { console.info("FaceEnroll FaceSettingsModel BrightScreenOfThePhone start"); if (status === true) { AppStorage.SetOrCreate('BrightScreenOfThePhone_isOn', true); + PersistentStorage.PersistProp("BrightScreenOfThePhone_isOn", true); } else { console.info("FaceEnroll FaceSettingsModel close BrightScreenOfThePhone "); AppStorage.SetOrCreate('BrightScreenOfThePhone_isOn', false); diff --git a/ui/faceenroll/common/src/main/ets/default/common/model/userAuthModel.ets b/ui/faceenroll/common/src/main/ets/default/common/model/userAuthModel.ets index b4bcb6f..514abdd 100644 --- a/ui/faceenroll/common/src/main/ets/default/common/model/userAuthModel.ets +++ b/ui/faceenroll/common/src/main/ets/default/common/model/userAuthModel.ets @@ -38,18 +38,36 @@ export default class userAuthModel { * @param {function} callback - Callback function. * @param {function} getUserMode - Do after callback function. */ - public getUserAuthInfo(callback, getUserMode) { + public getUserAuthInfo(callback) { console.info("FaceEnroll userAuthModel getUserAuthInfo start"); - this.UserIDM.getAuthInfo(Config.AUTH_TYPE, (data) => { - try { - console.info('FaceEnroll userAuthModel getUserAuthInfo getAuthInfo success', JSON.stringify(data)); - callback(data,getUserMode); - } - catch (e) { - console.info('FaceEnroll userAuthModel getUserAuthInfo getAuthInfo error' + JSON.stringify(e)); - } - }) - console.info("FaceEnroll userAuthModel getUserAuthInfo end"); +// let authInfo = new Array(); +// for (let i = 0;i < Config.AUTH.length; i++) { +// let faceInfo = { +// credentialId: Config.AUTH[i].credentialId, +// authType:Config.AUTH[i].authType, +// authSubType:Config.AUTH[i].authSubType, +// templateId:Config.AUTH[i].templateId, +// name:'' +// }; +// authInfo.push(faceInfo); +// } +// AppStorage.SetOrCreate('faceInfo', authInfo); +// PersistentStorage.PersistProp("faceInfo", authInfo); +// callback(authInfo); + this.UserIDM.getAuthInfo(Config.AUTH_TYPE, (data) => { + try { + console.info('FaceEnroll userAuthModel getUserAuthInfo getAuthInfo success', JSON.stringify(data)); + for (let i = 0;i < data.length; i++) { + data[i].name = ''; + } + AppStorage.SetOrCreate('faceInfo',data); + PersistentStorage.PersistProp("faceInfo", data); + callback(data); + } + catch (e) { + console.info('FaceEnroll userAuthModel getUserAuthInfo getAuthInfo error' + JSON.stringify(e)); + } + }) } /** @@ -57,7 +75,7 @@ export default class userAuthModel { * @param callback */ public getUserMode(callback) { - callback(Config.TYPE2D); + callback(Config.TYPE2D); } /** @@ -91,6 +109,6 @@ export default class userAuthModel { * @param callback */ public getIsCheck(callback) { - callback(Config.TRUSTED_DEVICE_CHECK) + callback(Config.TRUSTED_DEVICE_CHECK) } } diff --git a/ui/faceenroll/common/src/main/ets/default/common/presenter/userAuthPresenter.ets b/ui/faceenroll/common/src/main/ets/default/common/presenter/userAuthPresenter.ets index 5ea58f6..0fafdb4 100644 --- a/ui/faceenroll/common/src/main/ets/default/common/presenter/userAuthPresenter.ets +++ b/ui/faceenroll/common/src/main/ets/default/common/presenter/userAuthPresenter.ets @@ -15,6 +15,14 @@ import ResourceManager from '../manager/resourceManager.ets' import router from '@system.router'; +import UserIdm from '@ohos.useridm'; +import PinAuth from '@ohos.pinauth'; +import UserAuth from '@ohos.userauth'; + +let UserIDM; +let PinAuthManager; +let UserAuthManager; +let challenge; export default class UserAuthPresenter { protected mResourceManager: ResourceManager; @@ -23,6 +31,12 @@ export default class UserAuthPresenter { protected constructor() { this.mResourceManager = ResourceManager.getInstance(); + UserIDM = UserIdm.constructor(); + console.info('FaceEnroll UserIDM = ' + UserIDM); + PinAuthManager = PinAuth.constructor(); + console.info('FaceEnroll PinAuthManager = ' + PinAuthManager); + UserAuthManager = UserAuth.constructor(); + console.info('FaceEnroll UserAuthManager = ' + UserAuthManager); } public static getInstance(): UserAuthPresenter{ @@ -46,11 +60,41 @@ export default class UserAuthPresenter { AppStorage.SetOrCreate('faceToken', token); getTokenCallback(); setTimeout(()=>{ - router.push({ - uri:'pages/entryView' - }); + this.mResourceManager.terminateSelf(); AppStorage.Delete('faceToken'); },600000); } + + public getFaceToken(callback) { + PinAuthManager.registerInputer({ + onGetData: (AuthSubType,IInputData)=>{ + IInputData.onSetData(10000,new Uint8Array([1,2,3])) + }}); + UserIDM.openSession((data)=> { + try{ + console.info('FaceEnroll openSession result data = ' + data); + UserAuthManager.auth(data,1,10000,{ + onResult: (result, extraInfo) => { + try{ + console.info('FaceEnroll pin.auth onResult result = ' + result); + console.info('FaceEnroll pin.auth onResult extraInfo = ' + JSON.stringify(extraInfo)); + AppStorage.SetOrCreate('faceToken',extraInfo.token); + callback(); + } + catch(e) { + console.info('FaceEnroll pin.auth onResult error = ' + e); + } + } + }) + } + catch(e) { + console.info('FaceEnroll openSession e= ' + e); + } + }) + } + +// public getChallenge(data) { +// this.challenge = data; +// } } diff --git a/ui/faceenroll/feature/faceSettings/build.gradle b/ui/faceenroll/feature/faceSettings/build.gradle index 9f3fbd4..c0614eb 100644 --- a/ui/faceenroll/feature/faceSettings/build.gradle +++ b/ui/faceenroll/feature/faceSettings/build.gradle @@ -1,9 +1,9 @@ apply plugin: 'com.huawei.ohos.library' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { - compatibleSdkVersion 7 + compatibleSdkVersion 8 } arkEnabled false buildTypes { diff --git a/ui/faceenroll/feature/faceSettings/src/main/ets/default/pages/faceSettings.ets b/ui/faceenroll/feature/faceSettings/src/main/ets/default/pages/faceSettings.ets index 7b6b920..62808ae 100644 --- a/ui/faceenroll/feature/faceSettings/src/main/ets/default/pages/faceSettings.ets +++ b/ui/faceenroll/feature/faceSettings/src/main/ets/default/pages/faceSettings.ets @@ -17,6 +17,7 @@ import DefaultConstants from '../common/DefaultConstants.ets'; import FaceSettingsPresenter from "../../../../../../../common/src/main/ets/default/common/presenter/FaceSettingsPresenter.ets"; import UserSettingsPresenter from '../../../../../../../common/src/main/ets/default/common/presenter/userSettingsPresenter.ets'; import router from '@system.router'; +import FeatureAbility from '@ohos.ability.featureAbility'; const FACELENGTH: number = 1; const USER_MODE: string = '3D'; @@ -105,9 +106,9 @@ export default struct faceSettings { } if (resultSucFlag == deleteRes.length) { this.deleteFaceDialogController.close(); - router.push({ - uri: 'pages/entryView' - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) } else { this.deleteFaceDialogController.close(); console.info('FaceEnroll faceSettings delete face fail'); @@ -132,9 +133,9 @@ export default struct faceSettings { .padding({ left: DefaultConstants.PADDING, right: DefaultConstants.PADDING }) .height(DefaultConstants.SINGLE_HEIGHT) .onClick(() => { - router.push({ - uri: 'pages/entryView' - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) }) Text($r('app.string.face_recognition_is_used')) @@ -305,6 +306,11 @@ export default struct faceSettings { .margin({ bottom: DefaultConstants.PADDING_16 }) .padding({ left: DefaultConstants.PADDING, right: DefaultConstants.PADDING }) .height(DefaultConstants.SINGLE_HEIGHT) + .onClick(()=>{ + router.push({ + uri: 'pages/index', + }) + }) Text($r('app.string.enroll_backup_face_summary')) .fontSize(DefaultConstants.MEDIUM_FONT_SIZE) diff --git a/ui/faceenroll/feature/faceSettings/src/main/resources/base/media/ic_settings_arrow.svg b/ui/faceenroll/feature/faceSettings/src/main/resources/base/media/ic_settings_arrow.svg index d7dd265..6aebbe7 100644 --- a/ui/faceenroll/feature/faceSettings/src/main/resources/base/media/ic_settings_arrow.svg +++ b/ui/faceenroll/feature/faceSettings/src/main/resources/base/media/ic_settings_arrow.svg @@ -3,7 +3,7 @@ + c0.6,0.6,1.4,0.9,2.1,0.9s1.5-0.3,2.1-0.9l22-22C38.3,48.9,38.3,47.1,37.1,45.9z"/> diff --git a/ui/faceenroll/feature/faceSettingsPad/build.gradle b/ui/faceenroll/feature/faceSettingsPad/build.gradle index 9f3fbd4..c0614eb 100644 --- a/ui/faceenroll/feature/faceSettingsPad/build.gradle +++ b/ui/faceenroll/feature/faceSettingsPad/build.gradle @@ -1,9 +1,9 @@ apply plugin: 'com.huawei.ohos.library' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { - compatibleSdkVersion 7 + compatibleSdkVersion 8 } arkEnabled false buildTypes { diff --git a/ui/faceenroll/feature/faceSettingsPad/src/main/ets/default/pages/index.ets b/ui/faceenroll/feature/faceSettingsPad/src/main/ets/default/pages/index.ets index fd03748..c4c5c40 100644 --- a/ui/faceenroll/feature/faceSettingsPad/src/main/ets/default/pages/index.ets +++ b/ui/faceenroll/feature/faceSettingsPad/src/main/ets/default/pages/index.ets @@ -16,6 +16,8 @@ import DefaultConstants from '../common/DefaultConstants.ets' import FaceSettingsPresenter from "../../../../../../../common/src/main/ets/default/common/presenter/FaceSettingsPresenter.ets" import UserSettingsPresenter from '../../../../../../../common/src/main/ets/default/common/presenter/userSettingsPresenter.ets' +import router from '@system.router'; +import FeatureAbility from '@ohos.ability.featureAbility'; let mFaceSettingsPresenter: FaceSettingsPresenter; let mUserSettingsPresenter: UserSettingsPresenter; @@ -34,19 +36,17 @@ export default struct FaceSettings { @State text: string = '面部1'; private removeFace ; @State faceNames: [] = []; - private name: [] = [{ isUsed:false }, { isUsed:false },{ isUsed:false },{ isUsed:false },{ isUsed:false }]; + private name: [] = [{ isUsed: false }, { isUsed: false }, { isUsed: false }, { isUsed: false }, { isUsed: false }]; private aboutToAppear(): void { console.info("FaceEnroll FaceSettings aboutToAppear start"); console.info('FaceEnroll FaceSettings faceLength = ' + this.faceLength); console.info('FaceEnroll FaceSettings userMode = ' + this.userMode); + mUserSettingsPresenter = UserSettingsPresenter.getInstance(); mFaceSettingsPresenter = FaceSettingsPresenter.getInstance(); mUserSettingsPresenter = UserSettingsPresenter.getInstance(); for (let i = 0; i < this.faceInfos.length; i++) { - this.faceNames.push({ - id: this.faceInfos[i].credentialId, - name: i+1 - }); + this.faceInfos[i].name = i + 1 this.name[i].isUsed = true; } console.info("FaceEnroll FaceSettings aboutToAppear end"); @@ -75,16 +75,9 @@ export default struct FaceSettings { deleteFaceSuccess() { if (this.faceInfos.length != 0) { -// let index = this.faceInfos.indexOf(this.removeFace) -// this.faceInfos.splice(index, 1) - for(let i =0;i { + ForEach(this.faceInfos, (item) => { Column() { Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { - Text(FACENAME + item.name) + Text(FACENAME + item.name + item.credentialId) .fontSize(DefaultConstants.LARGE_FONT_SIZE) } .height(DefaultConstants.SINGLE_HEIGHT_) .onClick(() => { this.text = FACENAME + item.name; - this.removeFace = item.id; + this.removeFace = item.credentialId; this.ReviseFaceController.open(); }) diff --git a/ui/faceenroll/feature/faceSettingsPad/src/main/resources/base/media/ic_settings_arrow.svg b/ui/faceenroll/feature/faceSettingsPad/src/main/resources/base/media/ic_settings_arrow.svg index d7dd265..6aebbe7 100644 --- a/ui/faceenroll/feature/faceSettingsPad/src/main/resources/base/media/ic_settings_arrow.svg +++ b/ui/faceenroll/feature/faceSettingsPad/src/main/resources/base/media/ic_settings_arrow.svg @@ -3,7 +3,7 @@ + c0.6,0.6,1.4,0.9,2.1,0.9s1.5-0.3,2.1-0.9l22-22C38.3,48.9,38.3,47.1,37.1,45.9z"/> diff --git a/ui/faceenroll/feature/trustedDevice/build.gradle b/ui/faceenroll/feature/trustedDevice/build.gradle index 9c61acd..0303984 100644 --- a/ui/faceenroll/feature/trustedDevice/build.gradle +++ b/ui/faceenroll/feature/trustedDevice/build.gradle @@ -1,9 +1,9 @@ apply plugin: 'com.huawei.ohos.library' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { - compatibleSdkVersion 7 + compatibleSdkVersion 8 } arkEnabled false buildTypes { diff --git a/ui/faceenroll/feature/trustedDevice/src/main/ets/default/pages/index.ets b/ui/faceenroll/feature/trustedDevice/src/main/ets/default/pages/index.ets index 5924af8..1de6c53 100644 --- a/ui/faceenroll/feature/trustedDevice/src/main/ets/default/pages/index.ets +++ b/ui/faceenroll/feature/trustedDevice/src/main/ets/default/pages/index.ets @@ -14,6 +14,7 @@ */ import trustedModel from "../../../../../../../common/src/main/ets/default/common/model/DeviceModel"; import userAuthModel from "../../../../../../../common/src/main/ets/default/common/model/userAuthModel"; +import FeatureAbility from '@ohos.ability.featureAbility'; import constants from "../common/DefaultConstants.ets"; import router from '@system.router'; @@ -285,9 +286,9 @@ export default struct trustedDevice { .height(constants.MAX_HEIGHT) .padding({ left: constants.BACK_PADDING, right: constants.BACK_PADDING }) .onClick(() => { - router.push({ - uri: 'pages/entryView' - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) }) Text($r("app.string.face_introdution_title")) .fontSize(constants.TEXT_FONT_SIZE) diff --git a/ui/faceenroll/feature/trustedDevice/src/main/resources/base/media/into_arrow.svg b/ui/faceenroll/feature/trustedDevice/src/main/resources/base/media/into_arrow.svg index af9aaad..d20cc39 100644 --- a/ui/faceenroll/feature/trustedDevice/src/main/resources/base/media/into_arrow.svg +++ b/ui/faceenroll/feature/trustedDevice/src/main/resources/base/media/into_arrow.svg @@ -3,7 +3,7 @@ + c0.6,0.6,1.4,0.9,2.1,0.9s1.5-0.3,2.1-0.9l22-22C38.3,48.9,38.3,47.1,37.1,45.9z"/> diff --git a/ui/faceenroll/feature/trusteddevicepad/build.gradle b/ui/faceenroll/feature/trusteddevicepad/build.gradle index 00fb1aa..b8dcf7c 100644 --- a/ui/faceenroll/feature/trusteddevicepad/build.gradle +++ b/ui/faceenroll/feature/trusteddevicepad/build.gradle @@ -1,9 +1,9 @@ apply plugin: 'com.huawei.ohos.hap' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { - compatibleSdkVersion 7 + compatibleSdkVersion 8 } buildTypes { release { diff --git a/ui/faceenroll/feature/trusteddevicepad/src/main/config.json b/ui/faceenroll/feature/trusteddevicepad/src/main/config.json index 12cfb7e..894bebf 100644 --- a/ui/faceenroll/feature/trusteddevicepad/src/main/config.json +++ b/ui/faceenroll/feature/trusteddevicepad/src/main/config.json @@ -15,7 +15,7 @@ ], "distro": { "deliveryWithInstall": true, - "moduleName": "trustedDevicePad", + "moduleName": "trusteddevicepad", "moduleType": "har" } } diff --git a/ui/faceenroll/feature/trusteddevicepad/src/main/ets/default/pages/index.ets b/ui/faceenroll/feature/trusteddevicepad/src/main/ets/default/pages/index.ets index 9d1677e..86cd39d 100644 --- a/ui/faceenroll/feature/trusteddevicepad/src/main/ets/default/pages/index.ets +++ b/ui/faceenroll/feature/trusteddevicepad/src/main/ets/default/pages/index.ets @@ -14,6 +14,7 @@ */ import trustedModel from "../../../../../../../common/src/main/ets/default/common/model/DeviceModel"; import userAuthModel from "../../../../../../../common/src/main/ets/default/common/model/userAuthModel"; +import FeatureAbility from '@ohos.ability.featureAbility'; import constants from "../common/DefaultConstants.ets"; import router from '@system.router'; @@ -308,9 +309,9 @@ export default struct trustedDevice { .width(constants.BACK_WIDTH) .height(constants.BACK_HEIGHT) .onClick(() => { - router.push({ - uri: 'pages/entryView' - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) }) Text($r("app.string.face_introdution_title")) .fontSize(constants.OPTION_FONT_SIZE) diff --git a/ui/faceenroll/feature/trusteddevicepad/src/main/resources/base/media/into_arrow.svg b/ui/faceenroll/feature/trusteddevicepad/src/main/resources/base/media/into_arrow.svg index af9aaad..d20cc39 100644 --- a/ui/faceenroll/feature/trusteddevicepad/src/main/resources/base/media/into_arrow.svg +++ b/ui/faceenroll/feature/trusteddevicepad/src/main/resources/base/media/into_arrow.svg @@ -3,7 +3,7 @@ + c0.6,0.6,1.4,0.9,2.1,0.9s1.5-0.3,2.1-0.9l22-22C38.3,48.9,38.3,47.1,37.1,45.9z"/> diff --git a/ui/faceenroll/product/pad/build.gradle b/ui/faceenroll/product/pad/build.gradle index 97db3b7..c300da0 100644 --- a/ui/faceenroll/product/pad/build.gradle +++ b/ui/faceenroll/product/pad/build.gradle @@ -1,9 +1,9 @@ apply plugin: 'com.huawei.ohos.hap' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { - compatibleSdkVersion 7 + compatibleSdkVersion 8 } arkEnabled false diff --git a/ui/faceenroll/product/pad/src/main/config.json b/ui/faceenroll/product/pad/src/main/config.json index d34306d..7ca9ca6 100644 --- a/ui/faceenroll/product/pad/src/main/config.json +++ b/ui/faceenroll/product/pad/src/main/config.json @@ -72,7 +72,7 @@ ], "name": "default", "window": { - "designWidth": 1280, + "designWidth": 720, "autoDesignWidth": false } } diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/declare.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/declare.ets index 08d56d7..d845020 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/declare.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/declare.ets @@ -14,54 +14,188 @@ */ import Constants from '../common/constant.ets'; +import router from '@system.router'; @Entry @Component +export default struct Declare { + Scroll: Scroller = new Scroller(); + pattern: string = "2D"; -export default + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Scroll(this.Scroll) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { + Image($r('app.media.back')) + .width(Constants.BACK_WIDTH) + .height(Constants.BACK_HEIGHT) + .onClick(() => { + router.back(); + }) -struct Aperture { + Text(this.pattern == "2D" ? $r('app.string.face_guide_2d_announce_link') : $r("app.string.face_guide_3d_announce_link")) + .fontSize(Constants.DECLARE_TITLE_FONT_SIZE) + .fontWeight(FontWeight.Bold) + } + .margin({ top: $r('app.float.back_margin') }) - @StorageLink('showAperture1') showAperture1:boolean = true; - @StorageLink('showAperture2') showAperture2:boolean = false; - @StorageLink('showAperture3') showAperture3:boolean = false; - @StorageLink('showAperture4') showAperture4:boolean = false; - @StorageLink('showAperture5') showAperture5:boolean = false; + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { + Text($r("app.string.face_feature_desc")) + .fontSize(Constants.DECLARE_SECONDARY_TITLE_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start) + .margin({ top: Constants.DECLARE_TITLE_MARGIN_TOP, bottom: Constants.DECLARE_TITLE_MARGIN_BOTTOM }) + Text(this.pattern == "2D" ? $r("app.string.face_recognize_annouce_message_01") : $r("app.string.face_3drecognize_annouce_message_01")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start) + .margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM}) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + Text($r("app.string.face_recognize_annouce_message_02")) + .fontSize(Constants.DECLARE_SECONDARY_TITLE_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start) + .margin({ top: Constants.DECLARE_TITLE_MARGIN_TOP, bottom: Constants.DECLARE_TITLE_MARGIN_BOTTOM }) + Text($r("app.string.face_recognize_annouce_message_03")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + Text($r("app.string.face_recognize_annouce_message_04")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + Text($r("app.string.face_recognize_annouce_message_05")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + Text($r("app.string.face_recognize_annouce_message_06")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + Text($r("app.string.face_recognize_annouce_message_07")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + Text($r("app.string.face_recognize_annouce_message_08")) + .fontSize(Constants.DECLARE_SECONDARY_TITLE_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ top: Constants.DECLARE_TITLE_MARGIN_TOP, bottom: Constants.DECLARE_TITLE_MARGIN_BOTTOM }) - build() { - Flex({ alignItems: ItemAlign.Center , justifyContent:FlexAlign.Center}) { - if (this.showAperture1) { - Image($r('app.media.aperture1')) - .width(Constants.APERTURE1_WIDTH) - .height(Constants.APERTURE1_WIDTH) - .align(Alignment.Center) - } - if (this.showAperture2) { - Image($r('app.media.aperture2')) - .width(Constants.APERTURE2_WIDTH) - .height(Constants.APERTURE2_WIDTH) - .align(Alignment.Center) - } - if (this.showAperture3) { - Image($r('app.media.aperture3')) - .width(Constants.APERTURE34_WIDTH) - .height(Constants.APERTURE34_WIDTH) - .align(Alignment.Center) - } - if (this.showAperture4) { - Image($r('app.media.aperture4')) - .width(Constants.APERTURE34_WIDTH) - .height(Constants.APERTURE34_WIDTH) - .align(Alignment.Center) - } - if (this.showAperture5) { - Image($r('app.media.aperture5')) - .width(Constants.APERTURE5_WIDTH) - .height(Constants.APERTURE5_WIDTH) - .align(Alignment.Center) + Text($r("app.string.face_recognize_annouce_message_09")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + if (this.pattern == "2D") { + Text($r("app.string.face_annouce_tip1_item2_3d")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + Text() { + Span(Constants.DECLARE_TITLE_3).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_10")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + } + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + + Text() { + Span(Constants.DECLARE_TITLE_4).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_11")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + } + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + + Text() { + Span(Constants.DECLARE_TITLE_5).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_12")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + } + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + } else if (this.pattern == "3D") { + Text() { + Span(Constants.DECLARE_TITLE_2).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_10")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + } + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + + Text() { + Span(Constants.DECLARE_TITLE_3).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_11")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + } + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + + Text() { + Span(Constants.DECLARE_TITLE_4).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_12")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + } + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start).margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + } + + + Text($r("app.string.face_recognize_annouce_message_13")) + .fontSize(Constants.DECLARE_SECONDARY_TITLE_FONT_SIZE) + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start) + .margin({ top: Constants.DECLARE_TITLE_MARGIN_TOP, bottom: Constants.DECLARE_TITLE_MARGIN_BOTTOM }) + + + Text() { + Span($r("app.string.face_recognize_annouce_message_14_1")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_14_3")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .fontWeight(FontWeight.Bold) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_14_2")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_14_3")) + .fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .fontWeight(FontWeight.Bold) + + } + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start) + .margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + + Text() { + Span($r("app.string.face_recognize_annouce_message_15_1")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_14_3")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .fontWeight(FontWeight.Bold) + Span($r("app.string.face_recognize_annouce_message_15_2")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + Span($r("app.string.face_recognize_annouce_message_15_3")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + .fontWeight(FontWeight.Bold) + Span($r("app.string.face_recognize_annouce_message_15_4")).fontSize(Constants.DECLARE_TEXT_FONT_SIZE) + } + .width(Constants.DECLARE_MAX_WIDTH) + .textAlign(TextAlign.Start) + .margin({ bottom: Constants.DECLARE_ITEM_MARGIN_BOTTOM }) + .lineHeight(Constants.DECLARE_TEXT_LINE_HEIGHT) + }.width(Constants.DECLARE_WIDTH) + + } } - }.position({x: $r('app.float.enroll_center_position_X'),y:Constants.ENROLL_CENTER_POSITION_Y}) - .width('100%') - .height(Constants.CENTER_HEIGHT) + .scrollBarWidth(Constants.DECLARE_SCROLL_BAR_WIDTH) + } + .backgroundColor(Constants.DECLARE_BACKGROUND_COLOR) + .width(Constants.DECLARE_MAX_WIDTH) } -} \ No newline at end of file +} + + diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/enroll_2D.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/enroll_2D.ets index 4808d29..2604e1f 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/enroll_2D.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/enroll_2D.ets @@ -16,15 +16,13 @@ import router from '@system.router'; import mFaceModel from "../model_2D.ets"; import Constants from '../common/constant.ets'; +import FeatureAbility from '@ohos.ability.featureAbility'; const SUBTYPE_FACE_2D = 20000; const AUTHTYPE_FACE = 2; async function route_back() { - let options = { - uri: 'pages/entryView' - } try { - await router.push(options); + await router.push({uri: 'pages/index'}); } catch (err) { console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`); } @@ -48,9 +46,9 @@ export default struct Enroll_2D { private aboutToAppear(): void { setTimeout(()=> { AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView' - }); + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) }, 180000) this.credentialInfo = { credType:AUTHTYPE_FACE, @@ -66,9 +64,9 @@ export default struct Enroll_2D { private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) } build() { diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/enroll_3D.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/enroll_3D.ets index 4aaa671..be8c73d 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/enroll_3D.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/enroll_3D.ets @@ -16,15 +16,13 @@ import router from '@system.router'; import mFaceModel from "../model_3D.ets"; import Constants from '../common/constant.ets'; +import FeatureAbility from '@ohos.ability.featureAbility'; const SUBTYPE_FACE_2D = 20000; const AUTHTYPE_FACE = 2; async function route_back() { - let options = { - uri: 'pages/entryView' - } try { - await router.push(options); + await router.push({uri: 'pages/index'}); } catch (err) { console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`); } @@ -48,9 +46,9 @@ export default struct Enroll_3D { private aboutToAppear(): void { setTimeout(()=> { AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView' - }); + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) }, 180000) this.credentialInfo = { credType:AUTHTYPE_FACE, @@ -66,9 +64,9 @@ export default struct Enroll_3D { private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) } build() { diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/entryView.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/entryView.ets index 4e8b9d3..9ea2ad5 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/entryView.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/entryView.ets @@ -20,25 +20,26 @@ let mUserAuthPresenter: UserAuthPresenter; @Entry @Component struct entryView { - @State open_userAuth: boolean = false; private aboutToAppear(): void { - AppStorage.Delete('faceInfo'); - AppStorage.Delete('authLength'); - AppStorage.Delete('userMode'); - AppStorage.Delete('faceToken'); mUserAuthPresenter = UserAuthPresenter.getInstance(); + mUserAuthPresenter.getFaceToken(this.getTokenCallBack.bind(this)); + mUserAuthPresenter.jumpToUserAuth(this.getTokenCallBack.bind(this)); } + build() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Button('人脸识别', { type: ButtonType.Normal, stateEffect: true}) - .onClick(() => { - mUserAuthPresenter.jumpToUserAuth(this.getTokenCallBack.bind(this)); - }) +// Button('人脸识别', { type: ButtonType.Normal, stateEffect: true }) +// .onClick(() => { +// mUserAuthPresenter.jumpToUserAuth(this.getTokenCallBack.bind(this)); +// }) } } +/** + * Get token callback. + */ public getTokenCallBack() { let faceToken = AppStorage.Get('faceToken'); if (faceToken != undefined) { @@ -46,6 +47,9 @@ struct entryView { } } +/** + * Jump to userAuth page. + */ private jumpToUserAuth() { router.push({ uri: 'pages/userAuth', diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/index.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/index.ets index 26b14d1..95a5013 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/index.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/index.ets @@ -16,7 +16,7 @@ import StartViews_2D from "./startViews_2D.ets"; import StartViews_3D from "./startViews_3D.ets"; import Constants from "../common/constant.ets"; -import router from '@system.router'; +import FeatureAbility from '@ohos.ability.featureAbility'; @Entry @Component @@ -24,9 +24,9 @@ struct Index { @StorageLink('show_startViews') show_startViews: string = Constants.SHOW_START_VIEWS_2D; private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateAbility promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateAbility promise::catch : " + error)) } build() { diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/startViews_2D.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/startViews_2D.ets index e8f5db2..bb31bd6 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/startViews_2D.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/startViews_2D.ets @@ -16,7 +16,9 @@ import router from '@system.router'; import Constants from '../common/constant.ets'; import mFaceModel from "../model_2D.ets"; +import ResMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' +let mResMgr; async function routeDeclare() { let options = { uri: 'pages/declare' @@ -45,22 +47,22 @@ struct StartViews_2D { @StorageLink('checkbox_color') checkbox_color : any = $r('app.color.startView_color'); private pageHideFlag: number = 0; + public aboutToAppear() { + mResMgr = ResMgr.getInstance(); + } + public openSessionCallBack() { routeEnroll_2D(); } private onPageHide(): void { if (this.pageHideFlag == 0) { - router.push({ - uri: 'pages/entryView' - }) + mResMgr.terminateSelf(); } } private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + mResMgr.terminateSelf(); } build() { diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/startViews_3D.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/startViews_3D.ets index db833ab..ae8564e 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/startViews_3D.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/startViews_3D.ets @@ -16,6 +16,9 @@ import router from '@system.router'; import Constants from '../common/constant.ets'; import mFaceModel from "../model_3D.ets"; +import ResMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' + +let mResMgr; async function routeEnroll_3D() { let options = { @@ -48,25 +51,23 @@ struct StartViews_3D { @StorageLink('checkbox_color') checkbox_color : any = $r('app.color.startView_color'); private pageHideFlag: number = 0; + public aboutToAppear() { + mResMgr = ResMgr.getInstance(); + } public openSessionCallBack() { routeEnroll_3D(); } private onPageHide(): void { if (this.pageHideFlag == 0) { - router.push({ - uri: 'pages/entryView' - }) + mResMgr.terminateSelf(); } } private onBackPress(): void{ console.info("FaceEnroll StartViews_3D onBackPress start"); AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) - console.info("FaceEnroll StartViews_3D onBackPress end"); + mResMgr.terminateSelf(); } build() { Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center}) { diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/success.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/success.ets index 2e6d620..62f1229 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/success.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/success.ets @@ -14,13 +14,15 @@ */ import router from '@system.router'; import Constants from '../common/constant.ets'; +import FeatureAbility from '@ohos.ability.featureAbility'; +import ResMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' +let mResMgr; async function routeCase() { - let options = { - uri: 'pages/entryView' - } try { - await router.push(options); + await FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) } catch (err) { console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`); } @@ -29,21 +31,19 @@ async function routeCase() { @Entry @Component struct Success { + public aboutToAppear() { + mResMgr = ResMgr.getInstance(); + } onPageShow(){ setTimeout(()=>{ - router.push({ - uri: 'pages/userAuth' - }) + mResMgr.terminateSelf(); },Constants.TIMEOUT_2000) } private onBackPress(): void{ console.info("FaceEnroll Success onBackPress start"); AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) - console.info("FaceEnroll Success onBackPress end"); + mResMgr.terminateSelf(); } diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/userAuth.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/userAuth.ets index b790f42..b1ddf45 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/userAuth.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/userAuth.ets @@ -14,6 +14,7 @@ */ import router from '@system.router'; import userAuthModel from '../../../../../../../common/src/main/ets/default/common/model/userAuthModel.ets'; +import ResourceMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' @Entry @Component @@ -21,74 +22,74 @@ struct userAuth { @State authLength: number = 0; @State userMode: string = ''; private mUserAuthModel: userAuthModel; + private mResourceMgr: ResourceMgr; private faceInfo ; - @State faceToken: string = ''; + public faceToken; @State getAllCallback: boolean = false; private aboutToAppear(): void { this.mUserAuthModel = userAuthModel.getInstance(); + this.mResourceMgr = ResourceMgr.getInstance(); this.faceToken = AppStorage.Get('faceToken'); if (this.mUserAuthModel != undefined) { - this.mUserAuthModel.getUserAuthInfo(this.getAuthInfoCallback.bind(this),this.getUserMode.bind(this)); + this.mUserAuthModel.getUserAuthInfo(this.getAuthInfoCallback.bind(this)); } } +/** + * Get phone mode(2D or 3D). + */ public getUserMode() { this.mUserAuthModel.getUserMode(this.getUserModeCallback.bind(this)); } onPageShow() { if (this.faceToken == '' || this.faceToken == undefined) { - router.push({ - uri: 'pages/entryView', - }) + console.info('FaceEnroll userAuth onPageShow token =' + this.faceToken); + this.mResourceMgr.terminateSelf(); + } + if(this.getAllCallback) { + if (this.authLength == 0) { + router.push({ + uri: 'pages/index', + }) + }else if(this.authLength > 0) { + router.push({ + uri: 'pages/userSettings', + }) + } } } - public getAuthInfoCallback(authInfo,getUserMode) { +/** + * Get authInfo callback. + * @param {object} authInfo - Callback data. + * @param {function} getUserMode - Do this function after callback. + */ + public getAuthInfoCallback(authInfo) { + console.info('FaceEnroll userAuth getAuthInfoCallback in'); this.faceInfo = authInfo; this.authLength = authInfo.length; AppStorage.SetOrCreate('authLength',this.authLength); AppStorage.SetOrCreate('faceInfo',this.faceInfo); AppStorage.SetOrCreate('facePageFlag',0); - getUserMode(); + this.mUserAuthModel.getUserMode(this.getUserModeCallback.bind(this)); } +/** + * Get phone mode(2D or 3D) callback. + * @param {string} userMode - Phone mode(2D or 3D). + */ public getUserModeCallback(userMode) { + console.info('FaceEnroll userAuth getUserModeCallback in'); this.userMode = userMode; AppStorage.SetOrCreate('userMode',this.userMode); this.getAllCallback = true; - + console.info('FaceEnroll userAuth getUserModeCallback getAllCallBack = ' + this.getAllCallback); } build() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - if (this.getAllCallback) { - getRouter({ - authLength: this.authLength - }) - - } - } - } -} - -@Component -struct getRouter{ - @Prop authLength: number; - public aboutToAppear() { - if (this.authLength == 0) { - router.push({ - uri: 'pages/index', - }) - }else if(this.authLength > 0) { - router.push({ - uri: 'pages/userSettings', - }) } } - - build() { - Column() {} - } } \ No newline at end of file diff --git a/ui/faceenroll/product/pad/src/main/ets/default/pages/userSettings.ets b/ui/faceenroll/product/pad/src/main/ets/default/pages/userSettings.ets index 80e36c7..6d7a5e5 100644 --- a/ui/faceenroll/product/pad/src/main/ets/default/pages/userSettings.ets +++ b/ui/faceenroll/product/pad/src/main/ets/default/pages/userSettings.ets @@ -15,8 +15,9 @@ import faceSettings from '../../../../../../../feature/faceSettingsPad/src/main/ets/default/pages/index.ets' import TrustedDevices from '../../../../../../../feature/trustedDevicePad/src/main/ets/default/pages/index.ets' -import router from '@system.router'; +import ResMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' +let mResMgr; @Entry @Component struct userSettings { @@ -30,18 +31,15 @@ struct userSettings { this.faceInfo = AppStorage.Get('faceInfo'); this.authLength = AppStorage.Get('authLength'); this.userMode = AppStorage.Get('userMode'); + mResMgr = ResMgr.getInstance(); } private onPageHide(): void { - router.push({ - uri: 'pages/entryView' - }) + mResMgr.terminateSelf(); } private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + mResMgr.terminateSelf(); } build() { diff --git a/ui/faceenroll/product/phone/build.gradle b/ui/faceenroll/product/phone/build.gradle index a78d2e3..b1bd3e0 100644 --- a/ui/faceenroll/product/phone/build.gradle +++ b/ui/faceenroll/product/phone/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.huawei.ohos.hap' ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { - compatibleSdkVersion 4 + compatibleSdkVersion 8 } arkEnabled false diff --git a/ui/faceenroll/product/phone/src/main/ets/default/app.ets b/ui/faceenroll/product/phone/src/main/ets/default/app.ets index 7536e16..c5b0b00 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/app.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/app.ets @@ -15,8 +15,9 @@ export default { onCreate() { - console.info('FaceEnroll entry Application onCreate') + console.info('FaceEnroll entry Application onCreate'); }, + onDestroy() { console.info('FaceEnroll entry Application onDestroy') }, diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/enroll_2D.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/enroll_2D.ets index a942b00..428c866 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/enroll_2D.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/enroll_2D.ets @@ -16,15 +16,14 @@ import router from '@system.router'; import mFaceModel from "../model_2D.ets"; import Constants from '../common/constant.ets'; +import FeatureAbility from '@ohos.ability.featureAbility'; + const SUBTYPE_FACE_2D = 20000; const AUTHTYPE_FACE = 2; async function route_back() { - let options = { - uri: 'pages/entryView' - } try { - await router.push(options); + await router.push({uri: 'pages/index'}); } catch (err) { console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`); } @@ -48,9 +47,9 @@ export default struct Enroll_2D { private aboutToAppear(): void { setTimeout(()=> { AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView' - }); + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) }, 180000) this.credentialInfo = { @@ -66,9 +65,9 @@ export default struct Enroll_2D { } private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) } build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/enroll_3D.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/enroll_3D.ets index d0d5e38..22eb7b1 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/enroll_3D.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/enroll_3D.ets @@ -17,15 +17,14 @@ import router from '@system.router'; import Aperture from './aperture.ets'; import mFaceModel from '../model_3D.ets'; import Constants from '../common/constant.ets'; +import FeatureAbility from '@ohos.ability.featureAbility'; + const SUBTYPE_FACE_2D = 20000; const AUTHTYPE_FACE = 2; async function route_back() { - let options = { - uri: 'pages/entryView' - } try { - await router.push(options); + await router.push({uri: 'pages/index'}); } catch (err) { console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`); } @@ -48,9 +47,9 @@ struct Enroll_3D { private aboutToAppear(): void { setTimeout(()=> { AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView' - }); + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) }, 180000) this.credentialInfo = { @@ -67,9 +66,9 @@ struct Enroll_3D { private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) } build() { diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/entryView.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/entryView.ets index ecb9c62..811fa37 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/entryView.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/entryView.ets @@ -23,19 +23,17 @@ struct entryView { @State open_userAuth: boolean = false; private aboutToAppear(): void { - AppStorage.Delete('faceInfo'); - AppStorage.Delete('authLength'); - AppStorage.Delete('userMode'); - AppStorage.Delete('faceToken'); mUserAuthPresenter = UserAuthPresenter.getInstance(); + mUserAuthPresenter.getFaceToken(this.getTokenCallBack.bind(this)); + mUserAuthPresenter.jumpToUserAuth(this.getTokenCallBack.bind(this)); } build() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Button('人脸识别', { type: ButtonType.Normal, stateEffect: true }) - .onClick(() => { - mUserAuthPresenter.jumpToUserAuth(this.getTokenCallBack.bind(this)); - }) +// Button('人脸识别', { type: ButtonType.Normal, stateEffect: true }) +// .onClick(() => { +// mUserAuthPresenter.jumpToUserAuth(this.getTokenCallBack.bind(this)); +// }) } } diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/index.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/index.ets index 9aa2659..290b643 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/index.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/index.ets @@ -16,7 +16,7 @@ import StartViews_2D from "./startViews_2D.ets"; import StartViews_3D from "./startViews_3D.ets"; import Constants from "../common/constant.ets"; -import router from '@system.router'; +import FeatureAbility from '@ohos.ability.featureAbility'; @Entry @Component @@ -24,9 +24,9 @@ struct Index { @StorageLink('show_startViews') show_startViews: string = Constants.SHOW_START_VIEWS_2D; private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) } build() { diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/startViews_2D.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/startViews_2D.ets index 07187dd..9b0fcc3 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/startViews_2D.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/startViews_2D.ets @@ -16,7 +16,9 @@ import router from '@system.router'; import Constants from '../common/constant.ets'; import mFaceModel from "../model_2D.ets"; +import ResMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' +let mResMgr; async function routeDeclare() { let options = { uri: 'pages/declare' @@ -45,22 +47,22 @@ struct StartViews_2D { @StorageLink('checkbox_color') checkbox_color : any = $r('app.color.startView_color'); private pageHideFlag: number = 0; + public aboutToAppear() { + mResMgr = ResMgr.getInstance(); + } + public openSessionCallBack() { routeEnroll_2D(); } private onPageHide(): void { if (this.pageHideFlag == 0) { - router.push({ - uri: 'pages/entryView' - }) + mResMgr.terminateSelf(); } } private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + mResMgr.terminateSelf(); } build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/startViews_3D.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/startViews_3D.ets index 78e4f6a..134dab0 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/startViews_3D.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/startViews_3D.ets @@ -16,6 +16,9 @@ import router from '@system.router'; import Constants from '../common/constant.ets'; import mFaceModel from "../model_3D.ets"; +import ResMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' + +let mResMgr; async function routeEnroll_3D() { let options = { @@ -45,22 +48,21 @@ struct StartViews_3D { private pageHideFlag: number = 0; @StorageLink('checkbox_color') checkbox_color : any = $r('app.color.startView_color'); + public aboutToAppear() { + mResMgr = ResMgr.getInstance(); + } public openSessionCallBack() { routeEnroll_3D(); } private onPageHide(): void { if (this.pageHideFlag == 0) { - router.push({ - uri: 'pages/entryView' - }) + mResMgr.terminateSelf(); } } private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + mResMgr.terminateSelf(); } build() { Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center}) { diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/success.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/success.ets index bc6df13..ea5882b 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/success.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/success.ets @@ -14,13 +14,15 @@ */ import router from '@system.router'; import Constants from '../common/constant.ets'; +import FeatureAbility from '@ohos.ability.featureAbility'; +import ResMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' +let mResMgr; async function routeCase() { - let options = { - uri: 'pages/entryView' - } try { - await router.push(options); + await FeatureAbility.terminateSelf() + .then(data => console.info("FaceEnroll terminateSelf promise::then : " + data)) + .catch(error => console.info("FaceEnroll terminateSelf promise::catch : " + error)) } catch (err) { console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`); } @@ -29,19 +31,18 @@ async function routeCase() { @Entry @Component struct Success { + public aboutToAppear() { + mResMgr = ResMgr.getInstance(); + } onPageShow(){ setTimeout(()=>{ - router.push({ - uri: 'pages/userAuth' - }) + mResMgr.terminateSelf(); },Constants.TIMEOUT_2000) } private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + mResMgr.terminateSelf(); } build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/userAuth.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/userAuth.ets index f6febc6..9f6a3fe 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/userAuth.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/userAuth.ets @@ -14,6 +14,7 @@ */ import router from '@system.router'; import userAuthModel from '../../../../../../../common/src/main/ets/default/common/model/userAuthModel.ets'; +import ResourceMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' @Entry @Component @@ -21,15 +22,19 @@ struct userAuth { @State authLength: number = 0; @State userMode: string = ''; private mUserAuthModel: userAuthModel; + private mResourceMgr: ResourceMgr; private faceInfo ; - @State faceToken: string = ''; + public faceToken; @State getAllCallback: boolean = false; private aboutToAppear(): void { + console.info('FaceEnroll userAuth aboutToAppear in'); this.mUserAuthModel = userAuthModel.getInstance(); + this.mResourceMgr = ResourceMgr.getInstance(); this.faceToken = AppStorage.Get('faceToken'); + console.info('FaceEnroll userAuth faceToken = ' + JSON.stringify(this.faceToken)); if (this.mUserAuthModel != undefined) { - this.mUserAuthModel.getUserAuthInfo(this.getAuthInfoCallback.bind(this),this.getUserMode.bind(this)); + this.mUserAuthModel.getUserAuthInfo(this.getAuthInfoCallback.bind(this)); } } @@ -41,10 +46,21 @@ struct userAuth { } onPageShow() { - if (this.faceToken == '' || this.faceToken == undefined) { - router.push({ - uri: 'pages/entryView', - }) + console.info('FaceEnroll userAuth onPageShow faceToken = ' + this.faceToken); + if (this.faceToken == {} || this.faceToken == undefined) { + console.info('FaceEnroll userAuth onPageShow token =' + this.faceToken); + this.mResourceMgr.terminateSelf(); + } + if(this.getAllCallback) { + if (this.authLength == 0) { + router.push({ + uri: 'pages/index', + }) + }else if(this.authLength > 0) { + router.push({ + uri: 'pages/userSettings', + }) + } } } @@ -53,13 +69,14 @@ struct userAuth { * @param {object} authInfo - Callback data. * @param {function} getUserMode - Do this function after callback. */ - public getAuthInfoCallback(authInfo,getUserMode) { + public getAuthInfoCallback(authInfo) { + console.info('FaceEnroll userAuth getAuthInfoCallback in'); this.faceInfo = authInfo; this.authLength = authInfo.length; AppStorage.SetOrCreate('authLength',this.authLength); AppStorage.SetOrCreate('faceInfo',this.faceInfo); AppStorage.SetOrCreate('facePageFlag',0); - getUserMode(); + this.mUserAuthModel.getUserMode(this.getUserModeCallback.bind(this)); } /** @@ -67,40 +84,15 @@ struct userAuth { * @param {string} userMode - Phone mode(2D or 3D). */ public getUserModeCallback(userMode) { + console.info('FaceEnroll userAuth getUserModeCallback in'); this.userMode = userMode; AppStorage.SetOrCreate('userMode',this.userMode); this.getAllCallback = true; - + console.info('FaceEnroll userAuth getUserModeCallback getAllCallBack = ' + this.getAllCallback); } build() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - if (this.getAllCallback) { - getRouter({ - authLength: this.authLength - }) - - } - } - } -} - -@Component -struct getRouter{ - @Prop authLength: number; - public aboutToAppear() { - if (this.authLength == 0) { - router.push({ - uri: 'pages/index', - }) - }else if(this.authLength > 0) { - router.push({ - uri: 'pages/userSettings', - }) } } - - build() { - Column() {} - } } \ No newline at end of file diff --git a/ui/faceenroll/product/phone/src/main/ets/default/pages/userSettings.ets b/ui/faceenroll/product/phone/src/main/ets/default/pages/userSettings.ets index 525a8e9..1b26134 100644 --- a/ui/faceenroll/product/phone/src/main/ets/default/pages/userSettings.ets +++ b/ui/faceenroll/product/phone/src/main/ets/default/pages/userSettings.ets @@ -15,8 +15,9 @@ import faceSettings from '../../../../../../../feature/faceSettings/src/main/ets/default/pages/faceSettings.ets'; import TrustedDevices from '../../../../../../../feature/trustedDevice/src/main/ets/default/pages/index.ets'; -import router from '@system.router'; +import ResMgr from '../../../../../../../common/src/main/ets/default/common/manager/resourceManager.ets' +let mResMgr; @Entry @Component struct userSettings { @@ -30,18 +31,15 @@ struct userSettings { this.faceInfo = AppStorage.Get('faceInfo'); this.authLength = AppStorage.Get('authLength'); this.userMode = AppStorage.Get('userMode'); + mResMgr = ResMgr.getInstance(); } private onPageHide(): void { - router.push({ - uri: 'pages/entryView' - }) + mResMgr.terminateSelf(); } private onBackPress(): void{ AppStorage.Delete('faceToken'); - router.push({ - uri: 'pages/entryView', - }) + mResMgr.terminateSelf(); } onPageShow() { -- Gitee From bdc6dd574273228f839271c307e866445e079981 Mon Sep 17 00:00:00 2001 From: "qianqian.shan" Date: Thu, 17 Feb 2022 15:28:41 +0800 Subject: [PATCH 2/2] faceauth 0217 Signed-off-by: qianqian.shan --- LICENSE | 0 bundle.json | 26 +- sa_profile/942.xml | 2 +- sa_profile/BUILD.gn | 2 +- sa_profile/face_auth_service.cfg | 3 +- sa_profile/face_auth_service.rc | 0 services/BUILD.gn | 32 +- .../include/adaptor_algorithm.h | 4 + services/{temp => ca_mock}/include/buffer.h | 1 + services/{temp => ca_mock}/include/defines.h | 0 .../{temp => ca_mock}/include/face_auth_ca.h | 75 +- .../include/face_auth_func.h | 5 +- .../src/adaptor_algorithm.cpp | 1 - services/{temp => ca_mock}/src/buffer.cpp | 2 +- services/ca_mock/src/face_auth_ca.cpp | 780 ++++++++++++++++++ .../{temp => ca_mock}/src/face_auth_func.cpp | 25 +- services/common/include/constant.h | 1 + services/common/include/face_auth_defines.h | 12 +- services/faceauth/include/face_auth_event.h | 7 +- .../include/face_auth_event_handler.h | 0 services/faceauth/include/face_auth_manager.h | 19 +- services/faceauth/include/face_auth_req.h | 4 +- services/faceauth/include/face_auth_service.h | 2 - services/faceauth/src/face_auth_camera.cpp | 4 + .../src/face_auth_camera_buffer_listener.cpp | 8 +- .../src/face_auth_common_event_subscriber.cpp | 2 + services/faceauth/src/face_auth_event.cpp | 29 +- .../faceauth/src/face_auth_event_handler.cpp | 0 .../src/face_auth_executor_callback.cpp | 44 +- services/faceauth/src/face_auth_manager.cpp | 319 ++++--- services/faceauth/src/face_auth_req.cpp | 62 +- services/faceauth/src/face_auth_service.cpp | 10 +- services/temp/src/face_auth_ca.cpp | 185 ----- useriam.gni | 0 34 files changed, 1225 insertions(+), 441 deletions(-) mode change 100755 => 100644 LICENSE mode change 100755 => 100644 sa_profile/942.xml mode change 100755 => 100644 sa_profile/BUILD.gn mode change 100755 => 100644 sa_profile/face_auth_service.rc mode change 100755 => 100644 services/BUILD.gn rename services/{temp => ca_mock}/include/adaptor_algorithm.h (95%) rename services/{temp => ca_mock}/include/buffer.h (98%) rename services/{temp => ca_mock}/include/defines.h (100%) rename services/{temp => ca_mock}/include/face_auth_ca.h (53%) rename services/{temp => ca_mock}/include/face_auth_func.h (96%) rename services/{temp => ca_mock}/src/adaptor_algorithm.cpp (99%) rename services/{temp => ca_mock}/src/buffer.cpp (99%) create mode 100644 services/ca_mock/src/face_auth_ca.cpp rename services/{temp => ca_mock}/src/face_auth_func.cpp (90%) mode change 100755 => 100644 services/faceauth/include/face_auth_event_handler.h mode change 100755 => 100644 services/faceauth/include/face_auth_service.h mode change 100755 => 100644 services/faceauth/src/face_auth_event_handler.cpp mode change 100755 => 100644 services/faceauth/src/face_auth_manager.cpp mode change 100755 => 100644 services/faceauth/src/face_auth_service.cpp delete mode 100644 services/temp/src/face_auth_ca.cpp mode change 100755 => 100644 useriam.gni diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/bundle.json b/bundle.json index 151ee28..f9a2de6 100644 --- a/bundle.json +++ b/bundle.json @@ -22,6 +22,8 @@ "ram": "16000KB", "deps": { "components": [ + "ability_base", + "ability_runtime", "hiviewdfx_hilog_native", "ipc", "aafwk_standard", @@ -29,36 +31,18 @@ "samgr_standard" ], "third_party": [ - "openssl" + "openssl" ] }, "build": { "sub_component": [ - "//base/user_iam/face_auth/common:faceauth_common", - "//base/user_iam/face_auth/interfaces/kits:faceauth_auth_kits", "//base/user_iam/face_auth/services:face_auth_service", - "//base/user_iam/face_auth/sa_profile:face_auth_sa_profile", - "//base/user_iam/face_auth/interfaces/kits/napi/faceauth_mgr:napi_packages" + "//base/user_iam/face_auth/sa_profile:face_auth_service.init", + "//base/user_iam/face_auth/sa_profile:face_auth_sa_profile" ], "inner_kits": [ - { - "type": "so", - "name": "//base/user_iam/face_auth/interfaces/innerkits/faceauth:face_auth_innerkits", - "header": { - "header_files": [ - "face_auth_client.h", - "face_auth_death_recipient.h", - "face_auth_innerkit.h", - "face_auth_proxy.h", - "face_auth_stub.h", - "iface_auth.h" - ], - "header_base": "//base/user_iam/face_auth/interfaces/innerkits/faceauth/include" - } - } ], "test": [ - "//base/user_iam/face_auth/services/faceauth/test:unittest" ] } } diff --git a/sa_profile/942.xml b/sa_profile/942.xml old mode 100755 new mode 100644 index d78474f..54d8c0e --- a/sa_profile/942.xml +++ b/sa_profile/942.xml @@ -16,7 +16,7 @@ face_service 942 - /system/lib64/libface_auth_services.z.so + libface_auth_service.z.so true false 1 diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn old mode 100755 new mode 100644 index 216207d..9b04e5a --- a/sa_profile/BUILD.gn +++ b/sa_profile/BUILD.gn @@ -20,7 +20,7 @@ ohos_sa_profile("face_auth_sa_profile") { part_name = "faceauth" } -ohos_prebuilt_etc("face_auth_service.rc") { +ohos_prebuilt_etc("face_auth_service.init") { if (use_musl) { source = "face_auth_service.cfg" } else { diff --git a/sa_profile/face_auth_service.cfg b/sa_profile/face_auth_service.cfg index fc18ef2..28b51af 100644 --- a/sa_profile/face_auth_service.cfg +++ b/sa_profile/face_auth_service.cfg @@ -11,7 +11,8 @@ "path" : ["/system/bin/sa_main", "/system/profile/face_service.xml"], "importance" : -20, "uid" : "system", - "gid" : ["system"] + "gid" : ["system"], + "secon" : "u:r:face_service:s0" } ] } diff --git a/sa_profile/face_auth_service.rc b/sa_profile/face_auth_service.rc old mode 100755 new mode 100644 diff --git a/services/BUILD.gn b/services/BUILD.gn old mode 100755 new mode 100644 index d1b72d5..4a1490e --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -16,17 +16,19 @@ import("//build/ohos.gni") ohos_shared_library("face_auth_service") { include_dirs = [ + "//foundation/multimedia/camera_standard/interfaces/inner_api/native/camera/include", "//base/user_iam/face_auth/services/faceauth/include", "//base/user_iam/face_auth/services/common/include", "//base/user_iam/face_auth/services/temp/include", "//base/user_iam/face_auth/services/common/log/include", + "//base/user_iam/face_auth/services/ca_mock/include", "//base/user_iam/auth_executor_mgr/interfaces/innerkits/include", "//base/user_iam/auth_executor_mgr/services/include", "//base/user_iam/auth_executor_mgr/frameworks/kitsimpl/include", "//base/user_iam/auth_executor_mgr/utils/native/include", "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", "//foundation/multimedia/camera_standard/interfaces/innerkits/native/camera/include", - "//foundation/multimedia/camera_standard/frameworks/innerkitsimpl/metadata/include", + "//foundation/multimedia/camera_standard/frameworks/native/metadata/include", "//foundation/multimedia/camera_standard/services/camera_service/binder/base/include", "//foundation/multimedia/camera_standard/services/camera_service/binder/client/include", "//foundation/multimedia/camera_standard/services/camera_service/binder/server/include", @@ -35,13 +37,14 @@ ohos_shared_library("face_auth_service") { "//third_party/openssl/include", "//base/notification/ces_standard/interfaces/innerkits/native/include", "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", - "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include" - ] + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + ] sources = [ "//base/user_iam/face_auth/services/common/src/constant.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_camera.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_camera_buffer_listener.cpp", + "//base/user_iam/face_auth/services/faceauth/src/face_auth_common_event_subscriber.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_event.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_event_handler.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_executor_callback.cpp", @@ -50,34 +53,33 @@ ohos_shared_library("face_auth_service") { "//base/user_iam/face_auth/services/faceauth/src/face_auth_req.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_service.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_thread_pool.cpp", - "//base/user_iam/face_auth/services/faceauth/src/face_auth_common_event_subscriber.cpp", - "//base/user_iam/face_auth/services/temp/src/face_auth_ca.cpp", - "//base/user_iam/face_auth/services/temp/src/adaptor_algorithm.cpp", - "//base/user_iam/face_auth/services/temp/src/buffer.cpp", - "//base/user_iam/face_auth/services/temp/src/face_auth_func.cpp" + "//base/user_iam/face_auth/services/ca_mock/src/adaptor_algorithm.cpp", + "//base/user_iam/face_auth/services/ca_mock/src/buffer.cpp", + "//base/user_iam/face_auth/services/ca_mock/src/face_auth_ca.cpp", + "//base/user_iam/face_auth/services/ca_mock/src/face_auth_func.cpp", ] - deps = [ + deps = [ "//base/user_iam/auth_executor_mgr/interfaces/innerkits:coauth_framework", "//base/user_iam/auth_executor_mgr/services:coauthservice", "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy", "//foundation/graphic/standard:libsurface", - "//foundation/multimedia/camera_standard/frameworks/innerkitsimpl/camera:camera_framework", - "//foundation/multimedia/camera_standard/frameworks/innerkitsimpl/metadata:metadata", + "//foundation/multimedia/camera_standard/frameworks/native/camera:camera_framework", + "//foundation/multimedia/camera_standard/frameworks/native/metadata:metadata", "//foundation/multimedia/camera_standard/services/camera_service:camera_service", "//third_party/openssl:libcrypto_static", "//utils/native/base:utils", ] external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "ability_runtime:want", - "ces_standard:cesfwk_innerkits", - "ability_runtime:app_manager", "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy" + "samgr_standard:samgr_proxy", ] subsystem_name = "useriam" part_name = "face_auth" diff --git a/services/temp/include/adaptor_algorithm.h b/services/ca_mock/include/adaptor_algorithm.h similarity index 95% rename from services/temp/include/adaptor_algorithm.h rename to services/ca_mock/include/adaptor_algorithm.h index 10e513f..1825c8a 100644 --- a/services/temp/include/adaptor_algorithm.h +++ b/services/ca_mock/include/adaptor_algorithm.h @@ -18,9 +18,13 @@ #include #include "buffer.h" +#include "stdint.h" namespace OHOS { namespace UserIAM { namespace FaceAuth { + +const uint32_t ED25519_FIX_SIGN_BUFFER_SIZE = 64; + typedef struct { Buffer *pubKey; Buffer *priKey; diff --git a/services/temp/include/buffer.h b/services/ca_mock/include/buffer.h similarity index 98% rename from services/temp/include/buffer.h rename to services/ca_mock/include/buffer.h index 7e896fc..49113ad 100644 --- a/services/temp/include/buffer.h +++ b/services/ca_mock/include/buffer.h @@ -17,6 +17,7 @@ #define COMMON_BUFFER_H #include "stdbool.h" +#include "stdint.h" #include "defines.h" namespace OHOS { namespace UserIAM { diff --git a/services/temp/include/defines.h b/services/ca_mock/include/defines.h similarity index 100% rename from services/temp/include/defines.h rename to services/ca_mock/include/defines.h diff --git a/services/temp/include/face_auth_ca.h b/services/ca_mock/include/face_auth_ca.h similarity index 53% rename from services/temp/include/face_auth_ca.h rename to services/ca_mock/include/face_auth_ca.h index 05f39c3..9a9f4c3 100644 --- a/services/temp/include/face_auth_ca.h +++ b/services/ca_mock/include/face_auth_ca.h @@ -18,8 +18,12 @@ #include #include #include +#include +#include +#include #include "face_auth_defines.h" #include "face_auth_log_wrapper.h" +#include "face_auth_defines.h" namespace OHOS { namespace UserIAM { namespace FaceAuth { @@ -29,32 +33,34 @@ typedef enum { } AlgorithmOperation; typedef struct { - uint64_t templateId; - uint64_t scheduleId; + uint64_t templateId = 0; + uint64_t scheduleId = 0; } AlgorithmParam; typedef struct { - uint8_t *image; - uint32_t imageSize; - uint32_t width; - uint32_t height; - uint32_t stride; - int64_t timestamp; + uint8_t *image = nullptr; + uint32_t imageSize = 0; + uint32_t width = 0; + uint32_t height = 0; + uint32_t stride = 0; + int64_t timestamp = 0; } CameraImage; typedef struct { - int32_t result; - int32_t remainTimes; - uint64_t templateId; + int32_t result = 0; + int32_t remainTimes = 0; + uint64_t templateId = 0; std::vector coauthMsg; // coauth signed msg } AlgorithmResult; -// temp code start -void GetAuthResult(int32_t &result); -// temp code end +typedef struct { + int32_t resultCode; + int32_t param[RESULT_MAX_SIZE]; +} ResultInfo; + class FaceAuthCA { public: static std::shared_ptr GetInstance(); - FaceAuthCA()=default; + FaceAuthCA(); ~FaceAuthCA()=default; int32_t Init(); int32_t Close(); @@ -65,16 +71,51 @@ public: void GetAlgorithmState(int32_t &retCode, std::vector &retCoauthMsg); int32_t GetExecutorInfo(std::vector &pubKey, uint32_t &esl, uint64_t &authAbility); int32_t FinishAlgorithmOperation(AlgorithmResult &retResult); - int32_t DeleteTemplete(uint64_t templateId); + int32_t DeleteTemplate(uint64_t templateId); int32_t VerifyTemplateData(std::vector templateIdList); int32_t GetRemainTimes(uint64_t templateId, int32_t &remainingTimes); int32_t ResetRemainTimes(uint64_t templateId); - int32_t CancelAlogrithmOperation(); + int32_t CancelAlgorithmOperation(); void SetAlgorithmParam(const AlgorithmParam ¶m); private: static std::shared_ptr faceAuthCA_; static std::mutex mutex_; + int32_t resultNum_ = 0; + uint64_t cancelReqId_ = 0; + bool isReturnFaceId_ = false; + bool isInitFail_ = false; + bool isCancel_ = false; + HWExeType type_; AlgorithmParam param_; + std::map resultInfos_; + std::map errorCode_; + std::vector templateIdList_; + std::map remainTimesMap_; +private: + void GetAuthResult(int32_t &result); + FIRetCode GetAuthState(int32_t &authErrorCode, FICode &code, uint64_t reqId); + FIRetCode GetState(int32_t &resultCode, int32_t param[RESULT_MAX_SIZE]); + void ReadFile(); + int32_t SwitchAuthErrorCode(int32_t param); + int32_t CheckIsCancel(int32_t &authErrorCode, FICode &code, uint64_t reqId); + FIRetCode Cancel(uint64_t reqId); + void InitErrorCode(); + void CheckFile(std::string s); + void GetEnrollAngleResult(); + void GetEnrollSuccessResult(); + void GetEnrollHasRegistered(); + void GetOverMaxFace(); + void GetCaremaFail(); + void GetAngleTimeout(); + void GetResultFail(); + void GetResultTimeOut(); + FIRetCode DynamicInit(); + FIRetCode DynamicRelease(); + void ReadInitFile(); + void ReadReleaseFile(); + void CheckInitFile(std::string s); + void CheckReleaseFile(std::string s); + FIRetCode Prepare(HWExeType type); }; } // namespace FaceAuth } // namespace UserIAM diff --git a/services/temp/include/face_auth_func.h b/services/ca_mock/include/face_auth_func.h similarity index 96% rename from services/temp/include/face_auth_func.h rename to services/ca_mock/include/face_auth_func.h index b2e8579..52434fc 100644 --- a/services/temp/include/face_auth_func.h +++ b/services/ca_mock/include/face_auth_func.h @@ -18,6 +18,7 @@ #include "defines.h" #include "buffer.h" +#include namespace OHOS { namespace UserIAM { namespace FaceAuth { @@ -34,8 +35,8 @@ namespace FaceAuth { #define ED25519_FIX_PRIKEY_BUFFER_SIZE 64 #define PIN_EXECUTOR_SECURITY_LEVEL 2 #define FACE_EXECUTOR_SECURITY_LEVEL 2 -#define PIN_AUTH_AIBNILITY 7 -#define FACE_AUTH_AIBNILITY 7 +#define PIN_AUTH_ABILITY 7 +#define FACE_AUTH_ABILITY 7 #define RESULT_TLV_LEN 160U #define CONST_PUB_KEY_LEN 32U diff --git a/services/temp/src/adaptor_algorithm.cpp b/services/ca_mock/src/adaptor_algorithm.cpp similarity index 99% rename from services/temp/src/adaptor_algorithm.cpp rename to services/ca_mock/src/adaptor_algorithm.cpp index 383c8c0..b6683c4 100644 --- a/services/temp/src/adaptor_algorithm.cpp +++ b/services/ca_mock/src/adaptor_algorithm.cpp @@ -26,7 +26,6 @@ namespace FaceAuth { const int OPENSSL_SUCCESS = 1; const uint32_t ED25519_FIX_PRIKEY_BUFFER_SIZE = 32; const uint32_t ED25519_FIX_PUBKEY_BUFFER_SIZE = 32; -const uint32_t ED25519_FIX_SIGN_BUFFER_SIZE = 64; const uint32_t SHA256_DIGEST_SIZE = 32; const uint32_t SHA512_DIGEST_SIZE = 64; diff --git a/services/temp/src/buffer.cpp b/services/ca_mock/src/buffer.cpp similarity index 99% rename from services/temp/src/buffer.cpp rename to services/ca_mock/src/buffer.cpp index 1d7a629..e75dc94 100644 --- a/services/temp/src/buffer.cpp +++ b/services/ca_mock/src/buffer.cpp @@ -54,7 +54,7 @@ Buffer *CreateBuffer(const uint32_t size) return nullptr; } - buffer->buf = (uint8_t *)Malloc(size); + buffer->buf = new uint8_t; if (buffer->buf == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "Get buffer error"); delete buffer; diff --git a/services/ca_mock/src/face_auth_ca.cpp b/services/ca_mock/src/face_auth_ca.cpp new file mode 100644 index 0000000..cb03616 --- /dev/null +++ b/services/ca_mock/src/face_auth_ca.cpp @@ -0,0 +1,780 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "face_auth_ca.h" +#include "defines.h" +#include "face_auth_func.h" +#include +#include +#include + +namespace OHOS { +namespace UserIAM { +namespace FaceAuth { +static const int32_t CA_RESULT_SUCCESS = 0; +static const int32_t CA_RESULT_FAILED = -1; +static const int32_t BUFF_MAX_LEN = 128; +static const int32_t CASE_NUM = 100; +static const int32_t CODE_NUM = 5; +static const int32_t RESULT_CODE = 6; +static const int32_t IFACE_OVER_MAX_FACES = 901; +static const int32_t IFACE_ENROLL_HAS_REGISTERED = 902; +static const int32_t IFACE_CAMERA_FAIL = 903; +static const int32_t IFACE_TIME_OUT = 904; +static const std::string TEST_ANGLE = "999"; +static const std::string TEST_ENROLL_SUCCESS = "998"; +static const std::string TEST_OVER_MAX_FACES = "901"; +static const std::string TEST_ENROLL_HAS_REGISTERED = "902"; +static const std::string TEST_CAMERA_FAIL = "903"; +static const std::string TEST_ANGLE_TIMEOUT = "905"; +static const int32_t FACE_AUTH_GETRESULT_FAIL = 1001; +static const int32_t FACE_AUTH_GETRESULT_TIMEOUT = 1002; +static const std::string FACE_AUTH_GETRESULT_FAIL_STRING = "1001"; +static const std::string FACE_AUTH_GETRESULT_TIMEOUT_STRING = "1002"; +static const std::string FACE_AUTH_FAIL_STRING = "1003"; +static const std::string FACE_AUTH_INIT_TIMEOUT_STRING = "1004"; +static const char *INIT_FILENAME("/data/useriam/init.dat"); +static const char *RELEASE_FILENAME("/data/useriam/release.dat"); +static const char *CONFIG_FILENAME("/data/useriam/config.dat"); +static const char *FACEID_FILENAME("/data/useriam/faceId.dat"); +static const char *AUTH_RESULT_FILENAME("/data/useriam/auth_result.dat"); +static const int32_t SLEEP_NUM = 2500; +static const int32_t SLEEP_LONG_NUM = 2000; +static const int32_t PARAM_RANGE = 10; +static const int32_t TEST_ANGLT_START_NUM = 1000; +static const int32_t TEST_ANGLE_MAX_NUM = 1013; +static const int32_t TEST_ANGLE_ADD_NUM = 4; +static const int32_t DEFAULT_REMAIN_TIMES = 3; +static const int32_t SLEEP_TIME = 5000; +static int32_t faceId_ = 1; +std::shared_ptr FaceAuthCA::faceAuthCA_ = nullptr; +std::mutex FaceAuthCA::mutex_; +FaceAuthCA::FaceAuthCA() + : resultNum_(0), cancelReqId_(0), isReturnFaceId_(false), isInitFail_(false), + isCancel_(false), type_(HW_EXEC_TYPE_LEARN) +{ + InitErrorCode(); +} + +std::shared_ptr FaceAuthCA::GetInstance() +{ + if (faceAuthCA_ == nullptr) { + std::lock_guard lock_l(mutex_); + if (faceAuthCA_ == nullptr) { + faceAuthCA_ = std::make_shared(); + } + } + return faceAuthCA_; +} + +int32_t FaceAuthCA::Init() +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + GenerateKeyPair(); + return CA_RESULT_SUCCESS; +} + +int32_t FaceAuthCA::Close() +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + return CA_RESULT_SUCCESS; +} + +int32_t FaceAuthCA::LoadAlgorithm() +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + if (DynamicInit() == FI_RC_OK) { + return CA_RESULT_SUCCESS; + } + else { + return CA_RESULT_FAILED; + } +} + +int32_t FaceAuthCA::ReleaseAlgorithm() +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + if (DynamicRelease() == FI_RC_OK) { + return CA_RESULT_SUCCESS; + } + else { + return CA_RESULT_FAILED; + } +} + +int32_t FaceAuthCA::StartAlgorithmOperation(AlgorithmOperation algorithmOperation, AlgorithmParam param) +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + SetAlgorithmParam(param); + if (algorithmOperation == Enroll) { + Prepare(HW_EXEC_TYPE_ENROOL); + templateIdList_.push_back(param.templateId); + remainTimesMap_[param.templateId] = DEFAULT_REMAIN_TIMES; + return CA_RESULT_SUCCESS; + } + else if (algorithmOperation == Auth) { + Prepare(HW_EXEC_TYPE_UNLOCK); + remainTimesMap_[param.templateId] = DEFAULT_REMAIN_TIMES; + return CA_RESULT_SUCCESS; + } + else { + return CA_RESULT_FAILED; + } +} + +int32_t FaceAuthCA::TransferImageToAlgorithm(CameraImage images) +{ + sleep(1); + (void)(images); + return CA_RESULT_SUCCESS; +} + +void FaceAuthCA::GetAlgorithmState(int32_t &retCode, std::vector &retCoauthMsg) +{ + retCoauthMsg.clear(); + int32_t authErrorCode = -1; + FICode code = CODE_CALLBACK_START; + GetAuthState(authErrorCode, code, param_.scheduleId); + FACEAUTH_HILOGI(MODULE_SERVICE, "authErrorCode = %{public}d.", authErrorCode); + retCoauthMsg.push_back(static_cast(authErrorCode)); + retCode = 1; +} + +int32_t FaceAuthCA::GetExecutorInfo(std::vector &pubKey, uint32_t &esl, uint64_t &authAbility) +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + if (DoGetExecutorInfo(pubKey, esl, authAbility) != RESULT_SUCCESS) { + FACEAUTH_HILOGE(MODULE_SERVICE, "DoGetExecutorInfo failed."); + return CA_RESULT_FAILED; + } + return CA_RESULT_SUCCESS; +} + +int32_t FaceAuthCA::FinishAlgorithmOperation(AlgorithmResult &retResult) +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + int32_t authResult = 0; + isCancel_ = false; + GetAuthResult(authResult); + FACEAUTH_HILOGI(MODULE_SERVICE, "get auth result = %{public}d.", authResult); + retResult.result = authResult; + retResult.templateId = param_.templateId; + retResult.remainTimes = remainTimesMap_[param_.templateId]; + if ((authResult != 0) && (remainTimesMap_[param_.templateId] > 0)) { + remainTimesMap_[param_.templateId]--; + } + Buffer *retTlv = CreateBuffer(RESULT_TLV_LEN); + if (retTlv == nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE, "CreateBuffer failed."); + return CA_RESULT_FAILED; + } + ResultCode result = GenerateRetTlv(RESULT_SUCCESS, param_.scheduleId, FACE_AUTH, param_.templateId, retTlv); + if (result != RESULT_SUCCESS) { + FACEAUTH_HILOGE(MODULE_SERVICE, "GenerateRetTlv failed."); + DestoryBuffer(retTlv); + return CA_RESULT_FAILED; + } + result = SetResultTlv(retTlv, retResult.coauthMsg); + if (result != RESULT_SUCCESS) { + FACEAUTH_HILOGE(MODULE_SERVICE, "SetResultTlv failed."); + DestoryBuffer(retTlv); + return CA_RESULT_FAILED; + } + DestoryBuffer(retTlv); + return CA_RESULT_SUCCESS; +} + +int32_t FaceAuthCA::DeleteTemplate(uint64_t templateId) +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + std::vector::const_iterator iter; + for (iter = templateIdList_.cbegin();iter != templateIdList_.cend();iter++) + { + if (*iter == templateId) { + templateIdList_.erase(iter); + remainTimesMap_.erase(templateId); + } + } + return CA_RESULT_SUCCESS; +} + +int32_t FaceAuthCA::VerifyTemplateData(std::vector templateIdList) +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + templateIdList_.assign(templateIdList.begin(),templateIdList.end()); + remainTimesMap_.clear(); + for (int32_t index = 0;index < templateIdList_.size();index++) { + remainTimesMap_[templateIdList_.at(index)] = DEFAULT_REMAIN_TIMES; + } + return CA_RESULT_SUCCESS; +} + +int32_t FaceAuthCA::GetRemainTimes(uint64_t templateId, int32_t &remainingTimes) +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + remainingTimes = remainTimesMap_[templateId]; + return CA_RESULT_SUCCESS; +} + +int32_t FaceAuthCA::ResetRemainTimes(uint64_t templateId) +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + remainTimesMap_[templateId] = DEFAULT_REMAIN_TIMES; + return CA_RESULT_SUCCESS; +} + +int32_t FaceAuthCA::CancelAlgorithmOperation() +{ + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + Cancel(param_.scheduleId); + return CA_RESULT_SUCCESS; +} +void FaceAuthCA::SetAlgorithmParam(const AlgorithmParam ¶m) +{ + param_ = param; +} + +void FaceAuthCA::GetAuthResult(int32_t &result) +{ + FILE* pFile = nullptr; + pFile = fopen(AUTH_RESULT_FILENAME, "r"); + if (pFile == nullptr) { + FACEAUTH_HILOGI(MODULE_SERVICE, "open file failed."); + return; + } + if (fseek(pFile, 0, SEEK_END) != 0) { + FACEAUTH_HILOGI(MODULE_SERVICE, "fseek failed."); + return; + } + if (ftell(pFile) < 0) { + fseek(pFile, 0, SEEK_SET); + char str[BUFF_MAX_LEN] = {0}; + fread((void*)str, sizeof(char), BUFF_MAX_LEN-1, pFile); + result = atoi(str); + } + if (fclose(pFile) != 0) { + FACEAUTH_HILOGI(MODULE_SERVICE, "fclose failed."); + } +} +FIRetCode FaceAuthCA::GetAuthState(int32_t &authErrorCode, FICode &code, uint64_t reqId) +{ + FACEAUTH_HILOGI(MODULE_SERVICE,"GetAuthState start"); + int32_t resultCode = 0; + int32_t params[ALO_GETRESULT_PARAM_LEN] = {0}; + if (!CheckIsCancel(authErrorCode, code, reqId)) { + return FI_RC_OK; + } + FIRetCode result = GetState(resultCode, params); + if (result != FI_RC_OK) { + FACEAUTH_HILOGE(MODULE_SERVICE,"GetState failed"); + } + FACEAUTH_HILOGI(MODULE_SERVICE,"params[0] is %{public}d", params[0]); + if (resultCode == FI_COMPARE_FAIL) { + authErrorCode = SwitchAuthErrorCode(params[0]); + code = CODE_CALLBACK_RESULT; + return result; + } + if (errorCode_.find(resultCode) != errorCode_.end()) { + authErrorCode = errorCode_[resultCode]; + } else { + authErrorCode = resultCode; + } + if (authErrorCode == FACE_AUTH_GETRESULT_FAIL) { + authErrorCode = ERRCODE_FAIL; + code = CODE_CALLBACK_RESULT; + return result; + } + if (authErrorCode == FACE_AUTH_GETRESULT_TIMEOUT) { + authErrorCode = ERRCODE_TIMEOUT; + code = CODE_CALLBACK_RESULT; + return result; + } + if (authErrorCode == IFACE_TIME_OUT) { + authErrorCode = ERRCODE_TIMEOUT; + code = CODE_CALLBACK_RESULT; + return result; + } + if (authErrorCode == IFACE_CAMERA_FAIL) { + authErrorCode = ERRCODE_CAMERA_FAIL; + } + if (authErrorCode == ERRCODE_SUCCESS || authErrorCode == ERRCODE_CAMERA_FAIL) { + code = CODE_CALLBACK_RESULT; + } else { + code = CODE_CALLBACK_ACQUIRE; + } + FACEAUTH_HILOGI(MODULE_SERVICE,"reqid_ is xxxx%04llu,code_ is %{public}d,errorcode_ is %{public}d ", reqId, code, + authErrorCode); + FACEAUTH_HILOGI(MODULE_SERVICE,"GetAuthState end"); + return result; +} + +FIRetCode FaceAuthCA::GetState(int32_t &resultCode, int32_t param[RESULT_MAX_SIZE]) +{ + std::mutex mt; + std::lock_guard lock_l(mt); + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_NUM)); + ReadFile(); + FACEAUTH_HILOGI(MODULE_SERVICE,"resultNum_ is %{public}d", resultNum_); + FACEAUTH_HILOGI(MODULE_SERVICE,"resultInfos_.size() is %{public}d", resultInfos_.size()); + if (resultNum_ < resultInfos_.size()) { + resultCode = resultInfos_[resultNum_].resultCode; + FACEAUTH_HILOGI(MODULE_SERVICE,"memcpy length is %{public}d", sizeof(int32_t) * RESULT_MAX_SIZE); + if (memcpy(param, resultInfos_[resultNum_].param, + sizeof(int32_t) * RESULT_MAX_SIZE) != nullptr) { + return FIRetCode::FI_RC_ERROR; + } + if (resultNum_ >= 1 && resultInfos_[resultNum_ - 1].resultCode == FACE_DETECTED) { + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_LONG_NUM)); + } + resultNum_++; + int32_t result = 0; + + if (resultCode == FI_COMPARE_FAIL || param[0] != 0) { + result = SwitchAuthErrorCode(param[0]); + } + int32_t num = 6; + if (resultCode == FI_COMPARE_FAIL && param[0] == num) { + resultCode = IFACE_TIME_OUT; + resultInfos_.clear(); + resultNum_ = 0; + remove(CONFIG_FILENAME); + return FIRetCode::FI_RC_OK; + } + if (resultCode == FI_ENROLL_SUCCESS && param[0] != 0 && isReturnFaceId_ == false) { + isReturnFaceId_ = true; + resultNum_--; + return FIRetCode::FI_RC_OK; + } + + if ((resultCode >= FI_ENROLL_SUCCESS && resultCode <= FI_COMPARE_FAIL) || resultCode == IFACE_OVER_MAX_FACES || + resultCode == IFACE_ENROLL_HAS_REGISTERED || resultCode == FACE_AUTH_GETRESULT_FAIL || + resultCode == FACE_AUTH_GETRESULT_TIMEOUT) { + if (result != FACE_MOVED) { + resultInfos_.clear(); + resultNum_ = 0; + remove(CONFIG_FILENAME); + } + } + FACEAUTH_HILOGI(MODULE_SERVICE,"authErrorCode is %{public}d", resultCode); + if (param[0] != 0) { + for (int32_t i = 0; i < RESULT_MAX_SIZE; i++) { + FACEAUTH_HILOGI(MODULE_SERVICE,"param[%{public}d] is %{public}d", i, param[i]); + } + } + } + return FIRetCode::FI_RC_OK; +} +void FaceAuthCA::ReadFile() +{ + FACEAUTH_HILOGI(MODULE_SERVICE,"ReadFile start"); + resultInfos_.clear(); + std::ifstream mystream(CONFIG_FILENAME); + + if (!mystream.is_open()) { + FACEAUTH_HILOGI(MODULE_SERVICE,"Prepare type is %{public}d", type_); + if (type_ == HW_EXEC_TYPE_ENROOL) { + resultInfos_[0].resultCode = FI_ENROLL_SUCCESS; + resultInfos_[1].resultCode = FI_FACE_SCALE_TOO_SMALL; + } else { + resultInfos_[0].resultCode = FI_COMPARE_SUCCESS; + resultInfos_[1].resultCode = FI_FACE_OFFSET_RIGHT; + } + FACEAUTH_HILOGI(MODULE_SERVICE,"ReadFile open fail"); + + return; + } + char casenum[CASE_NUM]; + mystream.getline(casenum, CASE_NUM); + std::string s = casenum; + FACEAUTH_HILOGI(MODULE_SERVICE,"casenum is %{public}s", s.c_str()); + CheckFile(s); + char buffer[CODE_NUM]; + mystream.getline(buffer, CODE_NUM); + char str[RESULT_CODE]; + int32_t num = atoi(buffer); + for (int32_t i = 0; i < num; i++) { + mystream >> str; + resultInfos_[i].resultCode = atoi(str); + FACEAUTH_HILOGI(MODULE_SERVICE,"authErrorCode is %{public}d", resultInfos_[i].resultCode); + for (int32_t j = 0; j < PARAM_NUM; j++) { + mystream >> str; + resultInfos_[i].param[j] = atoi(str); + } + } + mystream.close(); +} +int32_t FaceAuthCA::SwitchAuthErrorCode(int32_t param) +{ + int32_t authErrorCode = 0; + switch (param) { + case FI_FAIL_REASON_FACE_NOT_MATCH: + authErrorCode = ERRCODE_COMPARE_FAIL; + break; + case FI_FAIL_REASON_FACE_MOVED: + authErrorCode = FACE_MOVED; + break; + case FI_FAIL_REASON_NOT_GAZE: + authErrorCode = ERRCODE_NOT_GAZE; + break; + case FI_FAIL_REASON_TIME_OUT: + authErrorCode = ERRCODE_TIMEOUT; + break; + case FI_FAIL_REASON_FACE_OUT_OF_BOUNDS: + case FI_FAIL_REASON_FACE_NOT_FOUND: + case FI_FAIL_REASON_LIVENESS_FAILURE: + authErrorCode = ERRCODE_FAIL; + break; + default: + authErrorCode = ERRCODE_NO_FACE_DATA; + break; + } + return authErrorCode; +} +int32_t FaceAuthCA::CheckIsCancel(int32_t &authErrorCode, FICode &code, uint64_t reqId) +{ + if (isCancel_) { + if (cancelReqId_ != reqId) { + isCancel_ = false; + FACEAUTH_HILOGW(MODULE_SERVICE, + "cancelReqId_ and reqId are different. cancelReqId_ is :xxxx%04llu,reqId is :xxxx%04llu", cancelReqId_, + reqId); + } + authErrorCode = ERRCODE_CANCEL; + code = CODE_CALLBACK_RESULT; + isCancel_ = false; + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME)); + return FI_RC_OK; + } + return FI_RC_ERROR; +} +FIRetCode FaceAuthCA::Cancel(uint64_t reqId) +{ + isCancel_ = true; + cancelReqId_ = reqId; + remove(CONFIG_FILENAME); + return FI_RC_OK; +} +void FaceAuthCA::InitErrorCode() +{ + errorCode_[FI_COMPARE_SUCCESS] = ERRCODE_SUCCESS; + errorCode_[FI_FACE_NOT_FOUND] = FACE_NOT_FOUND; + errorCode_[FI_FACE_SCALE_TOO_SMALL] = FACE_SCALE_TOO_SMALL; + errorCode_[FI_FACE_SCALE_TOO_LARGE] = FACE_SCALE_TOO_LARGE; + errorCode_[FI_FACE_OFFSET_LEFT] = FACE_OFFSET_LEFT; + errorCode_[FI_FACE_OFFSET_TOP] = FACE_OFFSET_TOP; + errorCode_[FI_FACE_OFFSET_RIGHT] = FACE_OFFSET_RIGHT; + errorCode_[FI_FACE_OFFSET_BOTTOM] = FACE_OFFSET_BOTTOM; + errorCode_[MG_UNLOCK_ATTR_EYE_OCCLUSION] = FACE_EYE_OCCLUSION; + errorCode_[MG_UNLOCK_ATTR_EYE_CLOSE] = FACE_EYE_CLOSE; + errorCode_[MG_UNLOCK_ATTR_MOUTH_OCCLUSION] = FACE_EYE_MOUTH_OCCLUSION; + errorCode_[MG_UNLOCK_FACE_NOT_COMPLETE] = FACE_NOT_COMPLETE; + errorCode_[FI_FACE_TOO_DARK] = FACE_UNLOCK_FACE_DARKLIGHT; + errorCode_[MG_UNLOCK_HIGHLIGHT] = FACE_UNLOCK_FACE_HIGHTLIGHT; + errorCode_[MG_UNLOCK_HALF_SHADOW] = FACE_UNLOCK_FACE_HALF_SHADOW; + errorCode_[FI_NOT_GAZE] = FACE_NOT_GAZE; + errorCode_[FI_FACE_ROTATE_TOP_RIGHT] = FACE_ROTATE_TOP_RIGHT; + errorCode_[FI_FACE_ROTATE_TOP_LEFT] = FACE_ROTATE_TOP_LEFT; + errorCode_[FI_FACE_ROTATE_BOTTOM_RIGHT] = FACE_ROTATE_BOTTOM_RIGHT; + errorCode_[FI_FACE_ROTATE_BOTTOM_LEFT] = FACE_ROTATE_BOTTOM_LEFT; + errorCode_[FI_FACE_FACE_SHADE] = FACE_WITHOUT_MASK; + errorCode_[FI_FACE_INFO] = FACE_COVERED_WITH_MASK; + errorCode_[MG_UNLOCK_FACE_BAD_QUALITY] = FACE_BAD_QUALITY; + errorCode_[FI_COMPARE_FAIL] = FACE_LIVENESS_FAILURE; + errorCode_[FI_FACE_ROTATE_LEFT] = FACE_ROTATED_LEFT; + errorCode_[MG_UNLOCK_FACE_RISE] = FACE_RISE; + errorCode_[MG_UNLOCK_FACE_ROTATED_RIGHT] = FACE_ROTATED_RIGHT; + errorCode_[MG_UNLOCK_FACE_DOWN] = FACE_DOWN; + errorCode_[MG_UNLOCK_FACE_MULTI] = FACE_MULTI; + errorCode_[MG_UNLOCK_FACE_BLUR] = FACE_BLUR; + errorCode_[FI_ENROLL_FACE_ANGLE_OK] = FACE_ANGLE_BASE; + errorCode_[FI_FACE_INFO] = FACE_ENROLL_INFO_BEGIN; + errorCode_[FI_ENROLL_SUCCESS] = ERRCODE_SUCCESS; + errorCode_[FI_FACE_DETECTED] = FACE_DETECTED; + errorCode_[FI_FACE_OUT_OF_BOUNDS] = FACE_OUT_OF_BOUNDS; + errorCode_[FI_FACE_DARKPIC] = FACE_DARKPIC; + errorCode_[IFACE_ENROLL_HAS_REGISTERED] = ERRCODE_ENROLL_HAS_REGISTERED; +} +void FaceAuthCA::CheckFile(std::string s) +{ + if (s.compare(TEST_ANGLE) == 0) { + GetEnrollAngleResult(); + } + if (s.compare(TEST_ENROLL_SUCCESS) == 0) { + GetEnrollSuccessResult(); + } + if (s.compare(TEST_ENROLL_HAS_REGISTERED) == 0) { + GetEnrollHasRegistered(); + } + if (s.compare(TEST_OVER_MAX_FACES) == 0) { + GetOverMaxFace(); + } + if (s.compare(TEST_CAMERA_FAIL) == 0) { + GetCaremaFail(); + } + if (s.compare(TEST_ANGLE_TIMEOUT) == 0) { + GetAngleTimeout(); + } + if (s.compare(FACE_AUTH_GETRESULT_FAIL_STRING) == 0) { + GetResultFail(); + } + if (s.compare(FACE_AUTH_GETRESULT_TIMEOUT_STRING) == 0) { + GetResultTimeOut(); + } +} +void FaceAuthCA::GetEnrollAngleResult() +{ + FACEAUTH_HILOGI(MODULE_SERVICE,"GetEnrollAngleResult start"); + resultInfos_.clear(); + int mapNum = 0; + ResultInfo info; + info.resultCode = FACE_DETECTED; + for (int32_t j = 0; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + resultInfos_.insert(std::pair(mapNum, info)); + for (int32_t i = TEST_ANGLT_START_NUM; i < TEST_ANGLE_MAX_NUM; i += TEST_ANGLE_ADD_NUM) { + info.resultCode = i; + for (int32_t j = 0; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + resultInfos_.insert(std::pair(mapNum, info)); + mapNum++; + } + std::ofstream mystream(FACEID_FILENAME, std::ios::trunc); + if (mystream.is_open()) { + FACEAUTH_HILOGE(MODULE_SERVICE,"GetEnrollAngleResult open"); + mystream << (std::to_string(faceId_) + "\n"); + info.param[0] = faceId_; + faceId_++; + } else { + FACEAUTH_HILOGE(MODULE_SERVICE,"GetEnrollAngleResult exist"); + mystream << (std::to_string(1) + "\n"); + info.param[0] = 1; + } + mystream.close(); + for (int32_t j = 1; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + info.resultCode = FI_ENROLL_SUCCESS; + resultInfos_.insert(std::pair(mapNum, info)); +} +void FaceAuthCA::GetEnrollSuccessResult() +{ + resultInfos_.clear(); + ResultInfo info; + int mapNum = 0; + std::ofstream mystream(FACEID_FILENAME, std::ios::trunc); + info.resultCode = FI_FACE_DETECTED; + for (int32_t j = 0; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + resultInfos_.insert(std::pair(mapNum, info)); + mapNum++; + if (mystream.is_open()) { + FACEAUTH_HILOGE(MODULE_SERVICE,"GetEnrollSuccessResult open"); + mystream << (std::to_string(faceId_) + "\n"); + info.param[0] = faceId_; + faceId_++; + } else { + FACEAUTH_HILOGE(MODULE_SERVICE,"GetEnrollSuccessResult exist"); + mystream << (std::to_string(1) + "\n"); + info.param[0] = 1; + } + mystream.close(); + for (int32_t j = 1; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + info.resultCode = FI_ENROLL_SUCCESS; + resultInfos_.insert(std::pair(mapNum, info)); +} +void FaceAuthCA::GetEnrollHasRegistered() +{ + resultInfos_.clear(); + ResultInfo info; + info.resultCode = IFACE_ENROLL_HAS_REGISTERED; + resultInfos_.insert(std::pair(0, info)); +} + +void FaceAuthCA::GetOverMaxFace() +{ + resultInfos_.clear(); + ResultInfo info; + info.resultCode = IFACE_OVER_MAX_FACES; + resultInfos_.insert(std::pair(0, info)); +} + +void FaceAuthCA::GetCaremaFail() +{ + resultInfos_.clear(); + ResultInfo info; + info.resultCode = IFACE_CAMERA_FAIL; + resultInfos_.insert(std::pair(0, info)); + info.resultCode = FI_ENROLL_FAIL; + for (int32_t j = 0; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + resultInfos_.insert(std::pair(1, info)); +} +void FaceAuthCA::GetAngleTimeout() +{ + resultInfos_.clear(); + ResultInfo info; + info.resultCode = FI_FACE_DETECTED; + for (int32_t j = 0; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + resultInfos_.insert(std::pair(0, info)); + int32_t num = 1004; + info.resultCode = num; + for (int32_t j = 0; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + resultInfos_.insert(std::pair(1, info)); + + info.resultCode = FACE_HAS_REGISTERED; + for (int32_t j = 0; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + int32_t numTwo = 2; + resultInfos_.insert(std::pair(numTwo, info)); + + info.resultCode = FI_COMPARE_FAIL; + int32_t infoNum = 6; + info.param[0] = infoNum; + for (int32_t j = 1; j < PARAM_RANGE; j++) { + info.param[j] = 0; + } + int32_t num1 = 3; + resultInfos_.insert(std::pair(num1, info)); +} +void FaceAuthCA::GetResultFail() +{ + resultInfos_.clear(); + ResultInfo info; + info.resultCode = FACE_AUTH_GETRESULT_FAIL; + resultInfos_.insert(std::pair(0, info)); +} + +void FaceAuthCA::GetResultTimeOut() +{ + resultInfos_.clear(); + ResultInfo info; + info.resultCode = FACE_AUTH_GETRESULT_TIMEOUT; + resultInfos_.insert(std::pair(0, info)); +} +FIRetCode FaceAuthCA::DynamicInit() +{ + FACEAUTH_HILOGI(MODULE_SERVICE,"DynamicInit"); + ReadInitFile(); + FACEAUTH_HILOGI(MODULE_SERVICE,"DynamicInit isInitFail_ is %{public}d", isInitFail_); + if (isInitFail_) { + isInitFail_ = false; + remove(INIT_FILENAME); + return FIRetCode::FI_RC_ERROR; + } + return FIRetCode::FI_RC_OK; +} + +FIRetCode FaceAuthCA::DynamicRelease() +{ + FACEAUTH_HILOGI(MODULE_SERVICE,"DynamicRelease"); + ReadReleaseFile(); + FACEAUTH_HILOGI(MODULE_SERVICE,"DynamicInit isInitFail_ is %{public}d", isInitFail_); + if (isInitFail_) { + isInitFail_ = false; + remove(RELEASE_FILENAME); + return FIRetCode::FI_RC_ERROR; + } + return FIRetCode::FI_RC_OK; +} +void FaceAuthCA::ReadInitFile() +{ + FACEAUTH_HILOGI(MODULE_SERVICE,"ReadInitFile start"); + std::ifstream mystream(INIT_FILENAME); + if (!mystream.is_open()) { + FACEAUTH_HILOGI(MODULE_SERVICE,"ReadInitFile open fail"); + return; + } + char casenum[CASE_NUM]; + mystream.getline(casenum, CASE_NUM); + std::string s = casenum; + FACEAUTH_HILOGI(MODULE_SERVICE,"casenum is %{public}s", s.c_str()); + CheckInitFile(s); + mystream.close(); + return; +} + +void FaceAuthCA::ReadReleaseFile() +{ + FACEAUTH_HILOGI(MODULE_SERVICE,"ReadReleaseFile start"); + std::ifstream mystream(RELEASE_FILENAME); + if (!mystream.is_open()) { + FACEAUTH_HILOGI(MODULE_SERVICE,"ReadReleaseFile open fail"); + return; + } + char casenum[CASE_NUM]; + mystream.getline(casenum, CASE_NUM); + std::string s = casenum; + FACEAUTH_HILOGI(MODULE_SERVICE,"casenum is %{public}s", s.c_str()); + CheckReleaseFile(s); + mystream.close(); + return; +} +void FaceAuthCA::CheckInitFile(std::string s) +{ + if (s.compare(FACE_AUTH_FAIL_STRING) == 0) { + isInitFail_ = true; + } + if (s.compare(FACE_AUTH_INIT_TIMEOUT_STRING) == 0) { + isInitFail_ = true; + } + if (s.compare(FACE_AUTH_GETRESULT_FAIL_STRING) == 0) { + GetResultFail(); + } + if (s.compare(FACE_AUTH_GETRESULT_TIMEOUT_STRING) == 0) { + GetResultTimeOut(); + } +} + +void FaceAuthCA::CheckReleaseFile(std::string s) +{ + if (s.compare(FACE_AUTH_FAIL_STRING) == 0) { + isInitFail_ = true; + } + if (s.compare(FACE_AUTH_INIT_TIMEOUT_STRING) == 0) { + isInitFail_ = true; + } + if (s.compare(FACE_AUTH_GETRESULT_FAIL_STRING) == 0) { + GetResultFail(); + } + if (s.compare(FACE_AUTH_GETRESULT_TIMEOUT_STRING) == 0) { + GetResultTimeOut(); + } +} +FIRetCode FaceAuthCA::Prepare(HWExeType type) +{ + std::mutex mt; + std::lock_guard lock_l(mt); + FACEAUTH_HILOGI(MODULE_SERVICE,"FaceAuthAlgoImpl::Prepare"); + type_ = type; + resultNum_ = 0; + resultInfos_.clear(); + FACEAUTH_HILOGI(MODULE_SERVICE,"resultInfos_.size is %{public}d", resultInfos_.size()); + FACEAUTH_HILOGI(MODULE_SERVICE,"FaceAuthAlgoImpl::Prepare type is %{public}d", type_); + return FIRetCode::FI_RC_OK; +} +} // namespace FaceAuth +} // namespace UserIAM +} // namespace OHOS diff --git a/services/temp/src/face_auth_func.cpp b/services/ca_mock/src/face_auth_func.cpp similarity index 90% rename from services/temp/src/face_auth_func.cpp rename to services/ca_mock/src/face_auth_func.cpp index be7ff3f..f655a77 100644 --- a/services/temp/src/face_auth_func.cpp +++ b/services/ca_mock/src/face_auth_func.cpp @@ -89,8 +89,12 @@ static Buffer *GetDataTlvContent(uint32_t result, uint64_t scheduleId, uint64_t ResultCode GenerateRetTlv(uint32_t result, uint64_t scheduleId, uint64_t subType, uint64_t templatedId, Buffer *retTlv) { - if (!IsBufferValid(retTlv) || !IsEd25519KeyPairValid(g_keyPair)) { - FACEAUTH_HILOGE(MODULE_SERVICE, "param is invalid."); + if (!IsBufferValid(retTlv)) { + FACEAUTH_HILOGE(MODULE_SERVICE, "param(retTlv) is invalid."); + return RESULT_BAD_PARAM; + } + if (!IsEd25519KeyPairValid(g_keyPair)) { + FACEAUTH_HILOGE(MODULE_SERVICE, "param(g_keyPair) is invalid."); return RESULT_BAD_PARAM; } Buffer *dataContent = GetDataTlvContent(result, scheduleId, subType, templatedId); @@ -132,19 +136,14 @@ ResultCode DoGetExecutorInfo(std::vector &vPubKey, uint32_t &esl, uint6 FACEAUTH_HILOGE(MODULE_SERVICE, "key pair not init!"); return RESULT_NEED_INIT; } - uint32_t pubKeyLen = CONST_PUB_KEY_LEN; - uint8_t pubKey[CONST_PUB_KEY_LEN]; - if (GetBufferData(g_keyPair->pubKey, pubKey, &pubKeyLen) != RESULT_SUCCESS) { - FACEAUTH_HILOGE(MODULE_SERVICE, "GetBufferData fail!"); - return RESULT_UNKNOWN; - } - int index = 0; - vPubKey.clear(); - for (index = 0; index < CONST_PUB_KEY_LEN; index++) { - vPubKey.push_back(pubKey[index]); + Buffer *pubKey = g_keyPair->pubKey; + vPubKey.resize(pubKey->contentSize); + if (memcpy_s(&vPubKey[0], pubKey->contentSize, pubKey->buf, pubKey->contentSize) != EOK) { + FACEAUTH_HILOGE(MODULE_SERVICE, "copy public key fail!"); + return RESULT_GENERAL_ERROR; } esl = FACE_EXECUTOR_SECURITY_LEVEL; - authAbility = FACE_AUTH_AIBNILITY; + authAbility = FACE_AUTH_ABILITY; return RESULT_SUCCESS; } } // namespace FaceAuth diff --git a/services/common/include/constant.h b/services/common/include/constant.h index fc68ab3..b1be3e8 100644 --- a/services/common/include/constant.h +++ b/services/common/include/constant.h @@ -18,6 +18,7 @@ #include #include +#include namespace OHOS { namespace UserIAM { diff --git a/services/common/include/face_auth_defines.h b/services/common/include/face_auth_defines.h index 884d545..df7fbcf 100644 --- a/services/common/include/face_auth_defines.h +++ b/services/common/include/face_auth_defines.h @@ -37,6 +37,7 @@ typedef enum { FACE_OPERATE_TYPE_LOCAL_AUTH, FACE_OPERATE_TYPE_CO_AUTH, FACE_OPERATE_TYPE_DEL, + FACE_OPERATE_TYPE_WAIT_INIT_ALGORITHM, FACE_OPERATE_TYPE_MAX, } FaceOperateType; @@ -59,7 +60,7 @@ typedef struct faceReqType { } } FaceReqType; typedef struct faceInfo { - uint32_t eventId = 0; + int32_t eventId = -1; int32_t uId = 0; bool isCanceled = false; } FaceInfo; @@ -101,6 +102,8 @@ static const int32_t FACE_COMMAND_REMOVE = 0; static const int32_t FACE_COMMAND_QUERY_CREDENTIAL = 1; static const int32_t FACE_COMMAND_INIT_ALGORITHM = 5; static const int32_t FACE_COMMAND_RELEASE_ALGORITHM = 6; +// command from Co-Auth(OnGetProperty) +static const int32_t FACE_COMMAND_GET = 1; // alogrithm state from FaceAuth CA static const int32_t FACE_ALOGRITHM_OPERATION_CONTINUE = 0; static const int32_t FACE_ALOGRITHM_OPERATION_BREAK = 1; @@ -109,12 +112,14 @@ typedef struct { uint64_t scheduleID = 0; uint64_t templateID = 0; uint64_t callerUID = 0; + uint32_t eventID = 0; }AuthParam; typedef struct { uint64_t scheduleID = 0; uint64_t templateID = 0; uint64_t callerUID = 0; + uint32_t eventID = 0; }EnrollParam; typedef struct { @@ -347,11 +352,6 @@ typedef enum { AR_ADD_AGAIN, } AlgoResult; -typedef struct { - int32_t resultCode; - int32_t param[RESULT_MAX_SIZE]; -} ResultInfo; - typedef enum FIFailReason { FI_FAIL_REASON_FACE_NOT_MATCH = 0, FI_FAIL_REASON_FACE_MOVED = 1, diff --git a/services/faceauth/include/face_auth_event.h b/services/faceauth/include/face_auth_event.h index bded853..f4cdb27 100644 --- a/services/faceauth/include/face_auth_event.h +++ b/services/faceauth/include/face_auth_event.h @@ -27,9 +27,10 @@ public: virtual ~FaceAuthEvent(); static std::shared_ptr GetInstance(); void HandleTask(const AppExecFwk::InnerEvent::Pointer &event); - void AuthenticateTask(const AppExecFwk::InnerEvent::Pointer &event); - void EnrollTask(const AppExecFwk::InnerEvent::Pointer &event); - void RemoveTask(const AppExecFwk::InnerEvent::Pointer &event); + void ProcessAuthenticateTask(const AppExecFwk::InnerEvent::Pointer &event); + void ProcessEnrollTask(const AppExecFwk::InnerEvent::Pointer &event); + void ProcessRemoveTask(const AppExecFwk::InnerEvent::Pointer &event); + void ProcessWaitInitAlgorithmTask(const AppExecFwk::InnerEvent::Pointer &event); inline void SetEventHandler(const std::shared_ptr &handler) { eventHandler_ = handler; diff --git a/services/faceauth/include/face_auth_event_handler.h b/services/faceauth/include/face_auth_event_handler.h old mode 100755 new mode 100644 diff --git a/services/faceauth/include/face_auth_manager.h b/services/faceauth/include/face_auth_manager.h index 4dc1419..8156951 100644 --- a/services/faceauth/include/face_auth_manager.h +++ b/services/faceauth/include/face_auth_manager.h @@ -32,18 +32,19 @@ public: int32_t Release(); void RegisterExecutor(); // about authenticate - int32_t Authenticate(const AuthParam ¶m); - void HandleCallAuthenticate(const AuthParam ¶m); + int32_t AddAuthenticationRequest(const AuthParam ¶m); + void DoAuthenticate(const AuthParam ¶m); int32_t CancelAuth(const AuthParam ¶m); // about enroll - int32_t Enrollment(const EnrollParam ¶m); - void HandleCallEnroll(const EnrollParam ¶m); + int32_t AddEnrollmentRequest(const EnrollParam ¶m); + void DoEnroll(const EnrollParam ¶m); int32_t CancelEnrollment(const EnrollParam ¶m); // about remove - int32_t Remove(const RemoveParam ¶m); - void HandleCallRemove(const RemoveParam ¶m); + int32_t AddRemoveRequest(const RemoveParam ¶m); + void DoRemove(const RemoveParam ¶m); // about algorithm FIRetCode InitAlgorithm(std::string bundleName); + FIRetCode DoWaitInitAlgorithm(std::future futureobj); FIRetCode ReleaseAlgorithm(std::string bundleName); // about messager void SetExecutorMessenger(const sptr &messager); @@ -63,7 +64,7 @@ private: bool IsAlgorithmInited(); AlgoResult IsNeedAlgoLoad(std::string bundleName); AlgoResult IsNeedAlgoRelease(std::string bundleName); - uint32_t GenerateEventId(); + int32_t GenerateEventId(); void SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, @@ -76,7 +77,9 @@ private: FIRetCode OperForAlgorithm(uint64_t scheduleID); void HandleAlgoResult(uint64_t scheduleID); int32_t OpenCamera(); - int32_t GetAuthMessage(uint64_t scheduleID); + int32_t WaitAlgorithmProcessDone(uint64_t scheduleID); + bool GetRandomNum(int32_t *randomNum); + int32_t GetAuthToken(std::unique_ptr &authToken, uint32_t &len); }; } // namespace FaceAuth } // namespace UserIAM diff --git a/services/faceauth/include/face_auth_req.h b/services/faceauth/include/face_auth_req.h index 32f2006..c1842e8 100644 --- a/services/faceauth/include/face_auth_req.h +++ b/services/faceauth/include/face_auth_req.h @@ -33,10 +33,10 @@ public: void RemoveAllRequireInfo(); FaceOperateType GetOperateType(uint32_t eventId); uint32_t GetEventId(FaceReqType reqType); - bool SetCancelFlag(FaceReqType reqType, int32_t uId); + bool SetCancelFlagSuccess(FaceReqType reqType, int32_t uId); bool isCanceled(uint32_t eventId, int32_t uId); bool FindLocalAuth(); - + void PrintReqInfoList(); private: std::map reqInfoList_; static std::mutex mutex_; diff --git a/services/faceauth/include/face_auth_service.h b/services/faceauth/include/face_auth_service.h old mode 100755 new mode 100644 index ccd70b1..4af0721 --- a/services/faceauth/include/face_auth_service.h +++ b/services/faceauth/include/face_auth_service.h @@ -35,8 +35,6 @@ public: virtual void OnStop() override; void Start(); private: - static std::mutex mutex_; - static std::shared_ptr instance_; static std::shared_ptr manager_; }; } // namespace FaceAuth diff --git a/services/faceauth/src/face_auth_camera.cpp b/services/faceauth/src/face_auth_camera.cpp index 9c1e030..467a733 100644 --- a/services/faceauth/src/face_auth_camera.cpp +++ b/services/faceauth/src/face_auth_camera.cpp @@ -52,6 +52,10 @@ sptr FaceAuthCamera::CreatePreviewOutput( { FACEAUTH_HILOGI(MODULE_SERVICE, "CreatePreviewOutput."); sptr previewBuffer = Surface::CreateSurfaceAsConsumer(); + if (previewBuffer == nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE, "previewBuffer = nullptr."); + return nullptr; + } previewBuffer->SetDefaultWidthAndHeight(PREVIEW_DEFAULT_WIDTH, PREVIEW_DEFAULT_HEIGHT); sptr listener = new FaceAuthCameraBufferListener(); if (listener == nullptr) { diff --git a/services/faceauth/src/face_auth_camera_buffer_listener.cpp b/services/faceauth/src/face_auth_camera_buffer_listener.cpp index 679753d..2b8fd52 100644 --- a/services/faceauth/src/face_auth_camera_buffer_listener.cpp +++ b/services/faceauth/src/face_auth_camera_buffer_listener.cpp @@ -23,12 +23,7 @@ namespace UserIAM { namespace FaceAuth { int32_t FaceAuthCameraBufferListener::SendCameraImage(OHOS::sptr buffer, int64_t timestamp) { - CameraImage image; - int ret = 0; - ret = memcpy_s(&image, sizeof(image), 0, sizeof(CameraImage)); - if (ret < 0) { - return -1; - } + CameraImage image = {}; image.image = static_cast(buffer->GetVirAddr()); image.imageSize = buffer->GetSize(); BufferHandle *bufferHandle = buffer->GetBufferHandle(); @@ -38,6 +33,7 @@ int32_t FaceAuthCameraBufferListener::SendCameraImage(OHOS::sptr faceAuthCA = FaceAuthCA::GetInstance(); if (faceAuthCA == nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE, "faceAuthCA = nullptr."); return -1; } faceAuthCA->TransferImageToAlgorithm(image); diff --git a/services/faceauth/src/face_auth_common_event_subscriber.cpp b/services/faceauth/src/face_auth_common_event_subscriber.cpp index 96b1314..116101e 100644 --- a/services/faceauth/src/face_auth_common_event_subscriber.cpp +++ b/services/faceauth/src/face_auth_common_event_subscriber.cpp @@ -20,6 +20,8 @@ namespace OHOS { namespace UserIAM { namespace FaceAuth { +const std::string REGISTER_NOTIFICATION = "EXECUTOR_REGISTER_NOTIFICATION"; + FaceAuthCommonEventSubscriber::FaceAuthCommonEventSubscriber( const CommonEventSubscribeInfo &subscribeInfo, FaceAuthService* callback) : CommonEventSubscriber(subscribeInfo), callback_(callback) diff --git a/services/faceauth/src/face_auth_event.cpp b/services/faceauth/src/face_auth_event.cpp index d5057b4..0b4dc02 100644 --- a/services/faceauth/src/face_auth_event.cpp +++ b/services/faceauth/src/face_auth_event.cpp @@ -19,6 +19,7 @@ #include "face_auth_event_handler.h" #include "face_auth_manager.h" #include "face_auth_req.h" +#include namespace OHOS { namespace UserIAM { @@ -55,15 +56,19 @@ void FaceAuthEvent::HandleTask(const AppExecFwk::InnerEvent::Pointer &event) FACEAUTH_HILOGI(MODULE_SERVICE, "operateType is %{public}d", operateType); switch (operateType) { case FACE_OPERATE_TYPE_LOCAL_AUTH: { - AuthenticateTask(event); + ProcessAuthenticateTask(event); break; } case FACE_OPERATE_TYPE_ENROLL: { - EnrollTask(event); + ProcessEnrollTask(event); break; } case FACE_OPERATE_TYPE_DEL: { - RemoveTask(event); + ProcessRemoveTask(event); + break; + } + case FACE_OPERATE_TYPE_WAIT_INIT_ALGORITHM: { + ProcessWaitInitAlgorithmTask(event); break; } default: { @@ -73,7 +78,7 @@ void FaceAuthEvent::HandleTask(const AppExecFwk::InnerEvent::Pointer &event) } return; } -void FaceAuthEvent::EnrollTask(const AppExecFwk::InnerEvent::Pointer &event) +void FaceAuthEvent::ProcessEnrollTask(const AppExecFwk::InnerEvent::Pointer &event) { auto object = event->GetUniqueObject(); EnrollParam info = *object; @@ -87,10 +92,10 @@ void FaceAuthEvent::EnrollTask(const AppExecFwk::InnerEvent::Pointer &event) FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); return; } - FaceAuthManager::GetInstance()->HandleCallEnroll(info); + FaceAuthManager::GetInstance()->DoEnroll(info); return; } -void FaceAuthEvent::AuthenticateTask(const AppExecFwk::InnerEvent::Pointer &event) +void FaceAuthEvent::ProcessAuthenticateTask(const AppExecFwk::InnerEvent::Pointer &event) { auto object = event->GetUniqueObject(); AuthParam info = *object; @@ -104,14 +109,20 @@ void FaceAuthEvent::AuthenticateTask(const AppExecFwk::InnerEvent::Pointer &even FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); return; } - FaceAuthManager::GetInstance()->HandleCallAuthenticate(info); + FaceAuthManager::GetInstance()->DoAuthenticate(info); return; } -void FaceAuthEvent::RemoveTask(const AppExecFwk::InnerEvent::Pointer &event) +void FaceAuthEvent::ProcessRemoveTask(const AppExecFwk::InnerEvent::Pointer &event) { auto object = event->GetUniqueObject(); RemoveParam info = *object; - FaceAuthManager::GetInstance()->HandleCallRemove(info); + FaceAuthManager::GetInstance()->DoRemove(info); + return; +} +void FaceAuthEvent::ProcessWaitInitAlgorithmTask(const AppExecFwk::InnerEvent::Pointer &event) +{ + auto object = event->GetUniqueObject>(); + FaceAuthManager::GetInstance()->DoWaitInitAlgorithm(move(*object)); return; } } // namespace FaceAuth diff --git a/services/faceauth/src/face_auth_event_handler.cpp b/services/faceauth/src/face_auth_event_handler.cpp old mode 100755 new mode 100644 diff --git a/services/faceauth/src/face_auth_executor_callback.cpp b/services/faceauth/src/face_auth_executor_callback.cpp index 97e4cc9..e21ad26 100644 --- a/services/faceauth/src/face_auth_executor_callback.cpp +++ b/services/faceauth/src/face_auth_executor_callback.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "securec.h" #include "face_auth_manager.h" #include "face_auth_log_wrapper.h" #include "coauth_info_define.h" @@ -40,31 +41,27 @@ int32_t FaceAuthExecutorCallback::OnBeginExecute(uint64_t scheduleId, std::vecto commandAttrs->GetUint64Value(AUTH_TEMPLATE_ID, templateId); switch (command) { case FACE_COMMAND_ENROLL: { - EnrollParam data; - memset_s(&data, sizeof(EnrollParam), 0, sizeof(EnrollParam)); + EnrollParam data = {}; data.scheduleID = scheduleId; data.templateID = templateId; - manager->Enrollment(data); + manager->AddEnrollmentRequest(data); break; } case FACE_COMMAND_AUTH: { - AuthParam data; - memset_s(&data, sizeof(AuthParam), 0, sizeof(AuthParam)); + AuthParam data = {}; data.scheduleID = scheduleId; data.templateID = templateId; - manager->Authenticate(data); + manager->AddAuthenticationRequest(data); break; } case FACE_COMMAND_CANCEL_ENROLL: { - EnrollParam data; - memset_s(&data, sizeof(EnrollParam), 0, sizeof(EnrollParam)); + EnrollParam data = {}; data.scheduleID = scheduleId; manager->CancelEnrollment(data); break; } case FACE_COMMAND_CANCEL_AUTH: { - AuthParam data; - memset_s(&data, sizeof(AuthParam), 0, sizeof(AuthParam)); + AuthParam data = {}; data.scheduleID = scheduleId; manager->CancelAuth(data); break; @@ -118,11 +115,10 @@ int32_t FaceAuthExecutorCallback::OnSetProperty(pAuthAttributes properties) bundleName.assign(callerName.begin(), callerName.end()); switch (command) { case FACE_COMMAND_REMOVE: { - RemoveParam data; - memset_s(&data, sizeof(RemoveParam), 0, sizeof(RemoveParam)); + RemoveParam data = {}; data.scheduleID = scheduleID; data.templateID = templateID; - manager->Remove(data); + manager->AddRemoveRequest(data); break; } case FACE_COMMAND_INIT_ALGORITHM: @@ -145,13 +141,21 @@ int32_t FaceAuthExecutorCallback::OnGetProperty(std::shared_ptrGetUint64Value(AUTH_TEMPLATE_ID, templateID); - faceAuthCA->GetRemainTimes(templateID, remainingTimes); - values->SetUint64Value(AUTH_REMAIN_TIME, remainingTimes); - - return FA_RET_OK; + // get command + uint32_t command = 0; + conditions->GetUint32Value(AUTH_PROPERTY_MODE, command); + FACEAUTH_HILOGI(MODULE_SERVICE, "command = %{public}u.", command); + if (command == FACE_COMMAND_GET) { + uint64_t templateID = 0; + int32_t remainingTimes = 0; + conditions->GetUint64Value(AUTH_TEMPLATE_ID, templateID); + faceAuthCA->GetRemainTimes(templateID, remainingTimes); + values->SetUint64Value(AUTH_REMAIN_TIME, remainingTimes); + return FA_RET_OK; + } + else { + return FA_RET_ERROR; + } } } // namespace FaceAuth } // namespace UserIAM diff --git a/services/faceauth/src/face_auth_manager.cpp b/services/faceauth/src/face_auth_manager.cpp old mode 100755 new mode 100644 index e48c233..b734c3f --- a/services/faceauth/src/face_auth_manager.cpp +++ b/services/faceauth/src/face_auth_manager.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ #include "face_auth_manager.h" +#include +#include #include "face_auth_log_wrapper.h" #include "face_auth_event_handler.h" #include "auth_executor_registry.h" @@ -21,9 +23,20 @@ #include "face_auth_thread_pool.h" #include "face_auth_req.h" #include "face_auth_camera.h" +#include "face_auth_defines.h" +#include +#include +#include +#include + namespace OHOS { namespace UserIAM { namespace FaceAuth { +const int RAND_NUM_BITS = 32; +const int TOP = 0; +const int BOTTOM = 1; +const int INVALID_EVENT_ID = -1; +static const std::string FACE_LOCAL_INIT_ALGO_NAME = "face_auth_local_init"; std::shared_ptr FaceAuthManager::manager_ = nullptr; std::mutex FaceAuthManager::mutex_; sptr FaceAuthManager::executorMessenger_; @@ -31,6 +44,7 @@ std::shared_ptr FaceAuthManager::handler_ = nullptr; std::shared_ptr FaceAuthManager::runner_ = nullptr; std::shared_ptr FaceAuthManager::queryCallback_ = nullptr; std::shared_ptr FaceAuthManager::executorCallback_ = nullptr; +static void CheckSystemAbility(); std::shared_ptr FaceAuthManager::GetInstance() { @@ -49,13 +63,13 @@ int32_t FaceAuthManager::Init() // run event handler std::string threadName("FaceAuthEventRunner"); runner_ = AppExecFwk::EventRunner::Create(threadName); - if (!runner_) { + if (runner_ == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "failed to create a runner."); return FA_RET_ERROR; } runner_->Run(); handler_ = std::make_shared(runner_); - if (!handler_) { + if (handler_ == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "handler_ is nullpter."); return FA_RET_ERROR; } @@ -71,9 +85,39 @@ int32_t FaceAuthManager::Init() } FACEAUTH_HILOGE(MODULE_SERVICE, "FaceAuthManager::Init Success."); // check register state + std::thread checkThread(OHOS::UserIAM::FaceAuth::CheckSystemAbility); + checkThread.join(); QueryRegStatus(); return FA_RET_OK; } + +void CheckSystemAbility() +{ + const int CHECK_TIMES = 3; + const int SLEEP_TIME = 1; + sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (sam == nullptr) { + FACEAUTH_HILOGI(MODULE_SERVICE, "Failed to get system ability manager"); + return; + } + for (int i = 0; i < CHECK_TIMES; i++) { + bool isExist = false; + sam->CheckSystemAbility(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, isExist); + if (!isExist) { + FACEAUTH_HILOGI(MODULE_SERVICE, "AUTHEXECUTORMGR is not exist, start ability failed, to do next"); + } else { + FACEAUTH_HILOGI(MODULE_SERVICE, "AUTHEXECUTORMGR is exist, start AUTHEXECUTORMGR ability success"); + return; + } + if (i < CHECK_TIMES - 1) { + FACEAUTH_HILOGI(MODULE_SERVICE, "begin sleep"); + sleep(SLEEP_TIME); + FACEAUTH_HILOGI(MODULE_SERVICE, "end sleep"); + } + } + FACEAUTH_HILOGI(MODULE_SERVICE, "start AUTHEXECUTORMGR ability all failed"); +} + void FaceAuthManager::QueryRegStatus() { FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); @@ -87,16 +131,14 @@ void FaceAuthManager::QueryRegStatus() FACEAUTH_HILOGE(MODULE_SERVICE, "create FaceAuthCA instance failed."); return; } - int32_t iRet = faceAuthCA->GetExecutorInfo(pubKey, esl, authAbility); - if (FA_RET_OK != iRet) { + int32_t ret = faceAuthCA->GetExecutorInfo(pubKey, esl, authAbility); + if (FA_RET_OK != ret) { FACEAUTH_HILOGE(MODULE_SERVICE, "GetExecutorInfo failed."); return; } // set executor info - executorInfo->SetPublicKey(pubKey); - executorInfo->SetExecutorSecLevel(ESL0); - executorInfo->SetAuthAbility(authAbility); executorInfo->SetAuthType(FACE); + executorInfo->SetExecutorType(TYPE_ALL_IN_ONE); if (queryCallback_== nullptr) { queryCallback_ = std::make_shared(); @@ -115,8 +157,8 @@ void FaceAuthManager::RegisterExecutor() std::vector pubKey; uint32_t esl = 0; uint64_t authAbility = 0; - int32_t iRet = faceAuthCA->GetExecutorInfo(pubKey, esl, authAbility); - if (FA_RET_OK != iRet) { + int32_t ret = faceAuthCA->GetExecutorInfo(pubKey, esl, authAbility); + if (FA_RET_OK != ret) { FACEAUTH_HILOGE(MODULE_SERVICE, "GetExecutorInfo failed."); return; } @@ -126,11 +168,12 @@ void FaceAuthManager::RegisterExecutor() executorInfo->SetExecutorSecLevel(ESL0); executorInfo->SetAuthAbility(authAbility); executorInfo->SetAuthType(FACE); + executorInfo->SetExecutorType(TYPE_ALL_IN_ONE); executorCallback_ = std::make_shared(); // executorCallback_ release - uint64_t ret = AuthResPool::AuthExecutorRegistry::GetInstance().Register(executorInfo, executorCallback_); - if (ret != 0) { - FACEAUTH_HILOGI(MODULE_SERVICE, "FaceAuthInitSeq::RegisterExecutor successful.executor id = %{public}llu", ret); + uint64_t regRet = AuthResPool::AuthExecutorRegistry::GetInstance().Register(executorInfo, executorCallback_); + if (regRet != 0) { + FACEAUTH_HILOGI(MODULE_SERVICE, "FaceAuthInitSeq::RegisterExecutor successful.executor id = %{public}llu", regRet); } else { FACEAUTH_HILOGE(MODULE_SERVICE, "FaceAuthInitSeq::RegisterExecutor failed."); } @@ -149,7 +192,7 @@ int32_t FaceAuthManager::Release() return FA_RET_OK; } -int32_t FaceAuthManager::Authenticate(const AuthParam ¶m) +int32_t FaceAuthManager::AddAuthenticationRequest(const AuthParam ¶m) { FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); FACEAUTH_HILOGI(MODULE_SERVICE, "[DoAuth]scheduleID = %{public}llu.", param.scheduleID); @@ -159,12 +202,8 @@ int32_t FaceAuthManager::Authenticate(const AuthParam ¶m) FACEAUTH_HILOGI(MODULE_SERVICE, "Parameter check error."); return FA_RET_ERROR; } - // check algorithm init - if (IsAlgorithmInited()) { - FACEAUTH_HILOGE(MODULE_SERVICE, "FaceAuthManager::Auth Need Init."); - return FA_RET_ERROR; - } - FaceReqType reqType; + // check req info list is full + FaceReqType reqType = {}; reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; if (FaceAuthReq::GetInstance()->IsReqNumReachedMax(FACE_OPERATE_TYPE_LOCAL_AUTH)) { @@ -172,8 +211,12 @@ int32_t FaceAuthManager::Authenticate(const AuthParam ¶m) return FA_RET_ERROR; } // send event - FaceInfo faceInfo; + FaceInfo faceInfo = {}; faceInfo.eventId = GenerateEventId(); + if (faceInfo.eventId == INVALID_EVENT_ID) { + FACEAUTH_HILOGI(MODULE_SERVICE, "faceInfo.eventId is invalid."); + return FA_RET_ERROR; + } faceInfo.uId = param.callerUID; FaceAuthReq::GetInstance()->AddReqInfo(reqType, faceInfo); FaceAuthEventHandler::Priority priority = FaceAuthEventHandler::Priority::LOW; @@ -181,21 +224,18 @@ int32_t FaceAuthManager::Authenticate(const AuthParam ¶m) handler_->SendEvent(faceInfo.eventId, std::move(authInfo), priority); return FA_RET_OK; } -void FaceAuthManager::HandleCallAuthenticate(const AuthParam ¶m) +void FaceAuthManager::DoAuthenticate(const AuthParam ¶m) { - // remove require info - FaceReqType reqType; - reqType.reqId = param.scheduleID; - reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; - FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); // check param if (param.templateID < 0) { FACEAUTH_HILOGI(MODULE_SERVICE, "Parameter check error."); return; } + this->InitAlgorithm(FACE_LOCAL_INIT_ALGO_NAME); // open camera and send image to algorithm if (OpenCamera() != FA_RET_OK) { - return; + // RK3568 no support camera, temporary ignore error + FACEAUTH_HILOGI(MODULE_SERVICE, "Ignore open camera fail."); } // start algorithm operation std::shared_ptr faceAuthCA = FaceAuthCA::GetInstance(); @@ -207,13 +247,15 @@ void FaceAuthManager::HandleCallAuthenticate(const AuthParam ¶m) AlgorithmParam algorithmParam; algorithmParam.scheduleId = param.scheduleID; algorithmParam.templateId = param.templateID; - int32_t iRet = faceAuthCA->StartAlgorithmOperation(algorithmOperation, algorithmParam); - if (iRet != FA_RET_OK) { + int32_t ret = faceAuthCA->StartAlgorithmOperation(algorithmOperation, algorithmParam); + if (ret != FA_RET_OK) { FACEAUTH_HILOGE(MODULE_SERVICE, "StartAlgorithmOperation failed"); return; } - // receive algorithm message and handle algorithm result - if (GetAuthMessage(param.scheduleID) != FA_RET_OK) { + // wait authentication process done + ret = WaitAlgorithmProcessDone(param.scheduleID); + if (ret != FA_RET_OK) { + FACEAUTH_HILOGE(MODULE_SERVICE, "authentication process result is %{public}d.",ret); return; } // close camera @@ -222,8 +264,17 @@ void FaceAuthManager::HandleCallAuthenticate(const AuthParam ¶m) return; } faceAuthCamera->CloseCamera(); + this->ReleaseAlgorithm(FACE_LOCAL_INIT_ALGO_NAME); + // remove require info + bool isCanceled = FaceAuthReq::GetInstance()->isCanceled(param.eventID, param.callerUID); + if (isCanceled) { + FaceReqType reqType = {}; + reqType.reqId = param.scheduleID; + reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; + FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); + } } -int32_t FaceAuthManager::Enrollment(const EnrollParam ¶m) +int32_t FaceAuthManager::AddEnrollmentRequest(const EnrollParam ¶m) { FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); FACEAUTH_HILOGI(MODULE_SERVICE, "[DoEnroll]scheduleID = %{public}llu.", param.scheduleID); @@ -233,12 +284,8 @@ int32_t FaceAuthManager::Enrollment(const EnrollParam ¶m) FACEAUTH_HILOGI(MODULE_SERVICE, "Parameter check error."); return FA_RET_ERROR; } - // check algorithm init - if (IsAlgorithmInited()) { - FACEAUTH_HILOGE(MODULE_SERVICE, "FaceAuthManager::Enroll Need Init."); - return FA_RET_ERROR; - } - FaceReqType reqType; + // check req info list is full + FaceReqType reqType = {}; reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_ENROLL; if (FaceAuthReq::GetInstance()->IsReqNumReachedMax(FACE_OPERATE_TYPE_ENROLL)) { @@ -246,8 +293,12 @@ int32_t FaceAuthManager::Enrollment(const EnrollParam ¶m) return FA_RET_ERROR; } // send event - FaceInfo faceInfo; + FaceInfo faceInfo = {}; faceInfo.eventId = GenerateEventId(); + if (faceInfo.eventId == INVALID_EVENT_ID) { + FACEAUTH_HILOGI(MODULE_SERVICE, "faceInfo.eventId is invalid."); + return FA_RET_ERROR; + } faceInfo.uId = param.callerUID; FaceAuthReq::GetInstance()->AddReqInfo(reqType, faceInfo); FaceAuthEventHandler::Priority priority = FaceAuthEventHandler::Priority::HIGH; @@ -255,20 +306,22 @@ int32_t FaceAuthManager::Enrollment(const EnrollParam ¶m) handler_->SendEvent(faceInfo.eventId, std::move(authInfo), priority); return FA_RET_OK; } -void FaceAuthManager::HandleCallEnroll(const EnrollParam ¶m) +void FaceAuthManager::DoEnroll(const EnrollParam ¶m) { - // remove require info - FaceReqType reqType; - reqType.reqId = param.scheduleID; - reqType.operateType = FACE_OPERATE_TYPE_ENROLL; - FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); // check param if (param.templateID < 0) { FACEAUTH_HILOGI(MODULE_SERVICE, "Parameter check error."); return; } + this->InitAlgorithm(FACE_LOCAL_INIT_ALGO_NAME); // open camera and send image to algorithm if (OpenCamera() != FA_RET_OK) { + // RK3568 no support camera, temporary ignore error + FACEAUTH_HILOGI(MODULE_SERVICE, "Ignore open camera fail."); + } + // check algorithm init + if (IsAlgorithmInited()) { + FACEAUTH_HILOGE(MODULE_SERVICE, "FaceAuthManager::Enroll Need Init."); return; } // start algorithm operation @@ -281,13 +334,15 @@ void FaceAuthManager::HandleCallEnroll(const EnrollParam ¶m) AlgorithmParam algorithmParam; algorithmParam.scheduleId = param.scheduleID; algorithmParam.templateId = param.templateID; - int32_t iRet = faceAuthCA->StartAlgorithmOperation(algorithmOperation, algorithmParam); - if (iRet != FA_RET_OK) { + int32_t ret = faceAuthCA->StartAlgorithmOperation(algorithmOperation, algorithmParam); + if (ret != FA_RET_OK) { FACEAUTH_HILOGE(MODULE_SERVICE, "StartAlgorithmOperation failed"); return; } - // receive algorithm message and handle algorithm result - if (GetAuthMessage(param.scheduleID) != FA_RET_OK) { + // wait enroll process done + ret = WaitAlgorithmProcessDone(param.scheduleID); + if (ret != FA_RET_OK) { + FACEAUTH_HILOGE(MODULE_SERVICE, "authentication process result is %{public}d.",ret); return; } // close camera @@ -296,8 +351,17 @@ void FaceAuthManager::HandleCallEnroll(const EnrollParam ¶m) return; } faceAuthCamera->CloseCamera(); + this->ReleaseAlgorithm(FACE_LOCAL_INIT_ALGO_NAME); + // remove require info + bool isCanceled = FaceAuthReq::GetInstance()->isCanceled(param.eventID, param.callerUID); + if (isCanceled) { + FaceReqType reqType = {}; + reqType.reqId = param.scheduleID; + reqType.operateType = FACE_OPERATE_TYPE_ENROLL; + FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); + } } -int32_t FaceAuthManager::Remove(const RemoveParam ¶m) +int32_t FaceAuthManager::AddRemoveRequest(const RemoveParam ¶m) { FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); FACEAUTH_HILOGI(MODULE_SERVICE, "[DoRemove]scheduleID = %{public}llu.", param.scheduleID); @@ -307,12 +371,8 @@ int32_t FaceAuthManager::Remove(const RemoveParam ¶m) FACEAUTH_HILOGI(MODULE_SERVICE, "Parameter check error."); return FA_RET_ERROR; } - // check algorithm init - if (IsAlgorithmInited()) { - FACEAUTH_HILOGE(MODULE_SERVICE, "FaceAuthManager::Remove Need Init."); - return FA_RET_ERROR; - } - FaceReqType reqType; + // check req info list is full + FaceReqType reqType = {}; reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_DEL; if (FaceAuthReq::GetInstance()->IsReqNumReachedMax(FACE_OPERATE_TYPE_DEL)) { @@ -320,8 +380,12 @@ int32_t FaceAuthManager::Remove(const RemoveParam ¶m) return FA_RET_ERROR; } // send event - FaceInfo faceInfo; + FaceInfo faceInfo = {}; faceInfo.eventId = GenerateEventId(); + if (faceInfo.eventId == INVALID_EVENT_ID) { + FACEAUTH_HILOGI(MODULE_SERVICE, "faceInfo.eventId is invalid."); + return FA_RET_ERROR; + } faceInfo.uId = param.callerUID; FaceAuthReq::GetInstance()->AddReqInfo(reqType, faceInfo); FaceAuthEventHandler::Priority priority = FaceAuthEventHandler::Priority::IMMEDIATE; @@ -329,13 +393,8 @@ int32_t FaceAuthManager::Remove(const RemoveParam ¶m) handler_->SendEvent(faceInfo.eventId, std::move(authInfo), priority); return FA_RET_OK; } -void FaceAuthManager::HandleCallRemove(const RemoveParam ¶m) +void FaceAuthManager::DoRemove(const RemoveParam ¶m) { - // remove require info - FaceReqType reqType; - reqType.reqId = param.scheduleID; - reqType.operateType = FACE_OPERATE_TYPE_DEL; - FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); // check param if (param.templateID < 0) { FACEAUTH_HILOGI(MODULE_SERVICE, "Parameter check error."); @@ -346,12 +405,17 @@ void FaceAuthManager::HandleCallRemove(const RemoveParam ¶m) FACEAUTH_HILOGE(MODULE_SERVICE, "faceAuthCA instance is null."); return; } - int32_t iRet = faceAuthCA->DeleteTemplete(param.templateID); - if (FA_RET_OK == iRet) { + int32_t ret = faceAuthCA->DeleteTemplate(param.templateID); + if (FA_RET_OK == ret) { FACEAUTH_HILOGI(MODULE_SERVICE, "Remove success."); } else { FACEAUTH_HILOGE(MODULE_SERVICE, "Remove failed."); } + // remove require info + FaceReqType reqType = {}; + reqType.reqId = param.scheduleID; + reqType.operateType = FACE_OPERATE_TYPE_DEL; + FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); } FIRetCode FaceAuthManager::OperForAlgorithm(uint64_t scheduleID) { @@ -362,14 +426,25 @@ FIRetCode FaceAuthManager::OperForAlgorithm(uint64_t scheduleID) } int32_t retCode = 0; std::vector retCoauthMsg; - std::vector m_msg; - std::shared_ptr msgInstance = std::make_shared(m_msg); + std::vector msg; + std::shared_ptr msgInstance = std::make_shared(msg); if (msgInstance == nullptr) { return FI_RC_INVALID_ARGUMENT; } while (1) { faceAuthCA->GetAlgorithmState(retCode, retCoauthMsg); FACEAUTH_HILOGI(MODULE_SERVICE, "receive new co auth message."); + uint32_t len; + std::unique_ptr token_ptr = std::make_unique(TOKEN_NUM); + GetAuthToken(token_ptr, len); + uint8_t token[TOKEN_NUM]; + if (memcpy(token, token_ptr.get(), len) != nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE,"GetAuthToken memcpy fail"); + return FI_RC_ERROR; + } + for (size_t i = 0; i < TOKEN_NUM; i++) { + retCoauthMsg.push_back(token[i]); + } std::shared_ptr msg(msgInstance->FromUint8Array(retCoauthMsg)); if (msg != nullptr) { SendData(scheduleID, 0, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg); @@ -401,26 +476,26 @@ void FaceAuthManager::HandleAlgoResult(uint64_t scheduleID) int32_t FaceAuthManager::CancelAuth(const AuthParam ¶m) { int32_t result = FA_RET_OK; - FaceReqType reqType; + FaceReqType reqType = {}; reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; int32_t uId = param.callerUID; - bool isSuccess = FaceAuthReq::GetInstance()->SetCancelFlag(reqType, uId); + bool isSuccess = FaceAuthReq::GetInstance()->SetCancelFlagSuccess(reqType, uId); if (!isSuccess) { FACEAUTH_HILOGE(MODULE_SERVICE, "CancelAuth failed,reqId: xxxx%04llu, ", reqType.reqId); result = FA_RET_ERROR; } - if (isSuccess) { + else { std::shared_ptr faceAuthCA = FaceAuthCA::GetInstance(); if (faceAuthCA == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "FaceAuthCA instance is null"); return result; } - result = faceAuthCA->CancelAlogrithmOperation(); + result = faceAuthCA->CancelAlgorithmOperation(); if (result == FA_RET_OK) { - FACEAUTH_HILOGI(MODULE_SERVICE, "CancelAlogrithmOperation success"); + FACEAUTH_HILOGI(MODULE_SERVICE, "CancelAlgorithmOperation success"); } else { - FACEAUTH_HILOGE(MODULE_SERVICE, "CancelAlogrithmOperation failed"); + FACEAUTH_HILOGE(MODULE_SERVICE, "CancelAlgorithmOperation failed"); } } return result; @@ -429,26 +504,26 @@ int32_t FaceAuthManager::CancelAuth(const AuthParam ¶m) int32_t FaceAuthManager::CancelEnrollment(const EnrollParam ¶m) { int32_t result = FA_RET_OK; - FaceReqType reqType; + FaceReqType reqType = {}; reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_ENROLL; int32_t uId = param.callerUID; - bool isSuccess = FaceAuthReq::GetInstance()->SetCancelFlag(reqType, uId); + bool isSuccess = FaceAuthReq::GetInstance()->SetCancelFlagSuccess(reqType, uId); if (!isSuccess) { FACEAUTH_HILOGE(MODULE_SERVICE, "CancelEnrollment failed,reqId: xxxx%04llu, ", reqType.reqId); result = FA_RET_ERROR; } - if (isSuccess) { + else { std::shared_ptr faceAuthCA = FaceAuthCA::GetInstance(); if (faceAuthCA == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "FaceAuthCA instance is null"); return result; } - result = faceAuthCA->CancelAlogrithmOperation(); + result = faceAuthCA->CancelAlgorithmOperation(); if (result == FA_RET_OK) { - FACEAUTH_HILOGI(MODULE_SERVICE, "CancelAlogrithmOperation success"); + FACEAUTH_HILOGI(MODULE_SERVICE, "CancelAlgorithmOperation success"); } else { - FACEAUTH_HILOGE(MODULE_SERVICE, "CancelAlogrithmOperation failed"); + FACEAUTH_HILOGE(MODULE_SERVICE, "CancelAlgorithmOperation failed"); } } return result; @@ -492,12 +567,20 @@ FIRetCode FaceAuthManager::InitAlgorithm(std::string bundleName) std::future futureobj = promiseobj.get_future(); FaceAuthThreadPool::GetInstance()->AddTask( [&promiseobj]() { promiseobj.set_value(FaceAuthCA::GetInstance()->LoadAlgorithm()); }); - std::chrono::microseconds span(INIT_DYNAMIC_TIME_OUT); - while (futureobj.wait_for(span) == std::future_status::timeout) { - FACEAUTH_HILOGI(MODULE_SERVICE, "LoadAlgorithm TimeOut"); + //send request + FaceReqType reqType = {}; + reqType.operateType = FACE_OPERATE_TYPE_WAIT_INIT_ALGORITHM; + FaceInfo faceInfo = {}; + faceInfo.eventId = GenerateEventId(); + if (faceInfo.eventId == INVALID_EVENT_ID) { + FACEAUTH_HILOGI(MODULE_SERVICE, "faceInfo.eventId is invalid."); return FI_RC_ERROR; } - return static_cast(futureobj.get()); + FaceAuthReq::GetInstance()->AddReqInfo(reqType, faceInfo);\ + auto info = std::make_unique>(move(futureobj)); + FaceAuthEventHandler::Priority priority = FaceAuthEventHandler::Priority::IMMEDIATE; + handler_->SendEvent(faceInfo.eventId, std::move(info), priority); + return FI_RC_OK; } FACEAUTH_HILOGE(MODULE_SERVICE, "Init Fail %{public}d", result); return FI_RC_ERROR; @@ -507,9 +590,13 @@ FIRetCode FaceAuthManager::ReleaseAlgorithm(std::string bundleName) FACEAUTH_HILOGI(MODULE_SERVICE, "Release ,bundleName:%{public}s", bundleName.c_str()); AlgoResult result = IsNeedAlgoRelease(bundleName); if (result == AR_EMPTY) { - if (FA_RET_OK == FaceAuthCA::GetInstance()->ReleaseAlgorithm()) { - FACEAUTH_HILOGI(MODULE_SERVICE, "Release success"); - return FI_RC_OK; + std::promise promiseobj; + std::future futureobj = promiseobj.get_future(); + FaceAuthThreadPool::GetInstance()->AddTask( + [&promiseobj]() { promiseobj.set_value(FaceAuthCA::GetInstance()->ReleaseAlgorithm()); }); + if (futureobj.get() != FI_RC_OK) { + FACEAUTH_HILOGI(MODULE_SERVICE, "ReleaseAlgorithm Fail"); + return FI_RC_ERROR; } } FACEAUTH_HILOGE(MODULE_SERVICE, "Release Fail %{public}d", result); @@ -561,15 +648,14 @@ AlgoResult FaceAuthManager::IsNeedAlgoRelease(std::string bundleName) } return result; } -uint32_t FaceAuthManager::GenerateEventId() +int32_t FaceAuthManager::GenerateEventId() { - struct timespec t; - t.tv_sec = 0; - t.tv_nsec = 0; - clock_gettime(CLOCK_REALTIME, &t); - int64_t elapsedTime { ((t.tv_sec) * SEC_TO_NANOSEC + t.tv_nsec) }; - size_t elapsedHash = std::hash()(std::to_string(elapsedTime)); - uint32_t eventId = static_cast(elapsedHash); + int32_t randomNum = INVALID_EVENT_ID; + if (!GetRandomNum(&randomNum)) { + FACEAUTH_HILOGE(MODULE_SERVICE, "GetRandomNum error"); + return INVALID_EVENT_ID; + } + int32_t eventId = randomNum; FACEAUTH_HILOGI(MODULE_SERVICE, "GenerateEventId generate eventId %{public}u", eventId); return eventId; } @@ -591,7 +677,7 @@ int32_t FaceAuthManager::OpenCamera() } return FA_RET_OK; } -int32_t FaceAuthManager::GetAuthMessage(uint64_t scheduleID) +int32_t FaceAuthManager::WaitAlgorithmProcessDone(uint64_t scheduleID) { std::promise promiseobj; std::future futureobj = promiseobj.get_future(); @@ -611,6 +697,49 @@ int32_t FaceAuthManager::GetAuthMessage(uint64_t scheduleID) } return FA_RET_OK; } +bool FaceAuthManager::GetRandomNum(int32_t *randomNum) +{ + if (randomNum == nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE, "randomNum is nullptr."); + return false; + } + BIGNUM *bn = BN_new(); + if (bn == nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE, "BN_new fail."); + return false; + } + if (BN_rand(bn, RAND_NUM_BITS, TOP, BOTTOM) != 0) { + FACEAUTH_HILOGE(MODULE_SERVICE, "BN_rand fail."); + return false; + } + char *decVal = BN_bn2dec(bn); + if (decVal == nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE, "BN_bn2dec is nullptr."); + return false; + } + *randomNum = atoi(decVal); + BN_free(bn); + return true; +} +FIRetCode FaceAuthManager::DoWaitInitAlgorithm(std::future futureobj) +{ + std::chrono::microseconds span(INIT_DYNAMIC_TIME_OUT); + while (futureobj.wait_for(span) == std::future_status::timeout) { + FACEAUTH_HILOGI(MODULE_SERVICE, "LoadAlgorithm TimeOut"); + return FI_RC_ERROR; + } + return static_cast(futureobj.get()); +} +int32_t FaceAuthManager::GetAuthToken(std::unique_ptr &authToken, uint32_t &len) +{ + uint8_t at[] = {'A', 'u', 't', 'h', 'T', 'o', 'k', 'e', 'n', '\0'}; + if (memcpy(authToken.get(), at, sizeof(at)) != nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE,"GetAuthToken memcpy fail"); + return FA_RET_ERROR; + } + len = sizeof(at); + return FA_RET_OK; +} } // namespace FaceAuth } // namespace UserIAM } // namespace OHOS diff --git a/services/faceauth/src/face_auth_req.cpp b/services/faceauth/src/face_auth_req.cpp index e740bef..3d7ddcf 100644 --- a/services/faceauth/src/face_auth_req.cpp +++ b/services/faceauth/src/face_auth_req.cpp @@ -44,14 +44,9 @@ std::shared_ptr FaceAuthReq::GetInstance() bool FaceAuthReq::IsReqNumReachedMax(FaceOperateType type) { std::lock_guard lock_l(mutex_); - for (auto iterinfo = reqInfoList_.begin(); iterinfo != reqInfoList_.end(); ++iterinfo) { - FACEAUTH_HILOGI(MODULE_SERVICE, - "ListInfo:reqId:xxxx%04llu,Type:%{public}d,eventId:%{public}u,uId:%{public}d,isCanceled:%{public}d", - iterinfo->first.reqId, iterinfo->first.operateType, iterinfo->second.eventId, iterinfo->second.uId, - iterinfo->second.isCanceled); - } + PrintReqInfoList(); FACEAUTH_HILOGI(MODULE_SERVICE, "type is %{public}d", type); - if (type > FACE_OPERATE_TYPE_MAX || type < FACE_INVALID_OPERATE_TYPE) { + if (type > FACE_OPERATE_TYPE_MAX || type <= FACE_INVALID_OPERATE_TYPE) { FACEAUTH_HILOGE(MODULE_SERVICE, "Parameter check error.type is %{public}d", type); return true; } @@ -62,7 +57,7 @@ bool FaceAuthReq::IsReqNumReachedMax(FaceOperateType type) count++; } } - if (count >= CO_AUTH_MAX_NUM) { + if (count >= CO_AUTH_MAX_NUM - 1) { return true; } } else { @@ -80,34 +75,39 @@ bool FaceAuthReq::IsReqNumReachedMax(FaceOperateType type) void FaceAuthReq::AddReqInfo(FaceReqType reqType, FaceInfo reqInfo) { std::lock_guard lock_l(mutex_); - FACEAUTH_HILOGI(MODULE_SERVICE, "reqType.reqId is xxxx%04llu", reqType.reqId); - FACEAUTH_HILOGI(MODULE_SERVICE, "reqType.operateType is %{public}d", reqType.operateType); - FACEAUTH_HILOGI(MODULE_SERVICE, "reqInfo.eventId is %{public}u", reqInfo.eventId); - FACEAUTH_HILOGI(MODULE_SERVICE, "reqInfo.uId is %{public}d", reqInfo.uId); - FACEAUTH_HILOGI(MODULE_SERVICE, "reqInfo.isCanceled is %{public}d", reqInfo.isCanceled); - if (reqType.operateType < FACE_INVALID_OPERATE_TYPE || reqType.operateType > FACE_OPERATE_TYPE_MAX) { + FACEAUTH_HILOGI(MODULE_SERVICE, "reqType.reqId is xxxx%04llu," + "reqType.operateType is %{public}d," + "reqInfo.eventId is %{public}u," + "reqInfo.uId is %{public}d," + "reqInfo.isCanceled is %{public}d", + reqType.reqId,reqType.operateType,reqInfo.eventId,reqInfo.uId,reqInfo.isCanceled); + if (reqType.operateType <= FACE_INVALID_OPERATE_TYPE || reqType.operateType > FACE_OPERATE_TYPE_MAX) { FACEAUTH_HILOGE(MODULE_SERVICE, "Parameter check error.reqInfo.operateType is %{public}d", reqType.operateType); return; } - reqInfoList_.insert(std::pair(reqType, reqInfo)); + auto req2Rm = reqInfoList_.find(reqType); + if (req2Rm != reqInfoList_.end()) { + FACEAUTH_HILOGI(MODULE_SERVICE,"same key was found."); + } + else { + reqInfoList_.insert(std::pair(reqType, reqInfo)); + } return; } void FaceAuthReq::RemoveRequireInfo(FaceReqType reqType) { std::lock_guard lock_l(mutex_); - for (auto iter = reqInfoList_.begin(); iter != reqInfoList_.end(); ++iter) { - FACEAUTH_HILOGI(MODULE_SERVICE, - "Remove before reqId:xxxx%04llu,Type:%{public}d,eventId:%{public}d,uId:%{public}d,isCanceled:%{public}d", - iter->first.reqId, iter->first.operateType, iter->second.eventId, iter->second.uId, - iter->second.isCanceled); - } - FACEAUTH_HILOGI(MODULE_SERVICE, "Remove reqType.reqId is xxxx%04llu", reqType.reqId); - FACEAUTH_HILOGI(MODULE_SERVICE, "Remove reqType.operateType is %{public}d", reqType.operateType); - auto iterrm = reqInfoList_.find(reqType); - if (iterrm != reqInfoList_.end()) { + PrintReqInfoList(); + FACEAUTH_HILOGI(MODULE_SERVICE, "Remove reqType.reqId is xxxx%04llu," + "Remove reqType.operateType is %{public}d", reqType.reqId,reqType.operateType); + auto req2Rm = reqInfoList_.find(reqType); + if (req2Rm != reqInfoList_.end()) { reqInfoList_.erase(reqType); } + else { + FACEAUTH_HILOGI(MODULE_SERVICE,"no require info found."); + } return; } @@ -142,7 +142,7 @@ uint32_t FaceAuthReq::GetEventId(FaceReqType reqType) return 0; } -bool FaceAuthReq::SetCancelFlag(FaceReqType reqType, int32_t uId) +bool FaceAuthReq::SetCancelFlagSuccess(FaceReqType reqType, int32_t uId) { std::lock_guard lock_l(mutex_); FACEAUTH_HILOGI(MODULE_SERVICE, "reqType.reqId is xxxx%04llu", reqType.reqId); @@ -184,6 +184,16 @@ bool FaceAuthReq::FindLocalAuth() } return result; } + +void FaceAuthReq::PrintReqInfoList() +{ + for (auto iterinfo = reqInfoList_.begin(); iterinfo != reqInfoList_.end(); ++iterinfo) { + FACEAUTH_HILOGI(MODULE_SERVICE, + "ListInfo:reqId:xxxx%04llu,Type:%{public}d,eventId:%{public}u,uId:%{public}d,isCanceled:%{public}d", + iterinfo->first.reqId, iterinfo->first.operateType, iterinfo->second.eventId, iterinfo->second.uId, + iterinfo->second.isCanceled); + } +} } // namespace FaceAuth } // namespace UserIAM } // namespace OHOS diff --git a/services/faceauth/src/face_auth_service.cpp b/services/faceauth/src/face_auth_service.cpp old mode 100755 new mode 100644 index bea09bd..9944a1b --- a/services/faceauth/src/face_auth_service.cpp +++ b/services/faceauth/src/face_auth_service.cpp @@ -22,8 +22,7 @@ namespace OHOS { namespace UserIAM { namespace FaceAuth { -std::mutex FaceAuthService::mutex_; -std::shared_ptr FaceAuthService::instance_ = nullptr; +const std::string REGISTER_NOTIFICATION = "EXECUTOR_REGISTER_NOTIFICATION"; std::shared_ptr FaceAuthService::manager_ = nullptr; const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); @@ -48,7 +47,6 @@ void FaceAuthService::OnStart() bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberPtr); if (!subscribeResult) { FACEAUTH_HILOGE(MODULE_SERVICE, "SubscribeCommonEvent failed"); - return ; } } Start(); @@ -63,12 +61,12 @@ void FaceAuthService::OnStop() } void FaceAuthService::Start() { - int32_t iRet = FA_RET_ERROR; + int32_t ret = FA_RET_ERROR; manager_ = FaceAuthManager::GetInstance(); if (manager_ != nullptr) { - iRet = manager_->Init(); + ret = manager_->Init(); } - if (FA_RET_OK == iRet) { + if (FA_RET_OK == ret) { FACEAUTH_HILOGE(MODULE_SERVICE, "Init() result success."); } else { FACEAUTH_HILOGE(MODULE_SERVICE, "Init() result failed."); diff --git a/services/temp/src/face_auth_ca.cpp b/services/temp/src/face_auth_ca.cpp deleted file mode 100644 index 0d364c5..0000000 --- a/services/temp/src/face_auth_ca.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "face_auth_ca.h" -#include "defines.h" -#include "face_auth_func.h" - -namespace OHOS { -namespace UserIAM { -namespace FaceAuth { -std::shared_ptr FaceAuthCA::faceAuthCA_ = nullptr; -std::mutex FaceAuthCA::mutex_; -const int BUFF_MAX_LEN = 128; -std::shared_ptr FaceAuthCA::GetInstance() -{ - if (faceAuthCA_ == nullptr) { - std::lock_guard lock_l(mutex_); - if (faceAuthCA_ == nullptr) { - faceAuthCA_ = std::make_shared(); - } - } - return faceAuthCA_; -} - -int32_t FaceAuthCA::Init() -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - GenerateKeyPair(); - return 0; -} - -int32_t FaceAuthCA::Close() -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - return 0; -} - -int32_t FaceAuthCA::LoadAlgorithm() -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - return 0; -} - -int32_t FaceAuthCA::ReleaseAlgorithm() -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - return 0; -} - -int32_t FaceAuthCA::StartAlgorithmOperation(AlgorithmOperation algorithmOperation, AlgorithmParam param) -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - (void)(algorithmOperation); - SetAlgorithmParam(param); - return 0; -} - -int32_t FaceAuthCA::TransferImageToAlgorithm(CameraImage images) -{ - sleep(1); - (void)(images); - return 0; -} - -void FaceAuthCA::GetAlgorithmState(int32_t &retCode, std::vector &retCoauthMsg) -{ - retCode = 1; - (void)(retCoauthMsg); - return ; -} - -int32_t FaceAuthCA::GetExecutorInfo(std::vector &pubKey, uint32_t &esl, uint64_t &authAbility) -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - if (DoGetExecutorInfo(pubKey, esl, authAbility) != RESULT_SUCCESS) { - FACEAUTH_HILOGE(MODULE_SERVICE, "DoGetExecutorInfo failed."); - return -1; - } - return 0; -} - -int32_t FaceAuthCA::FinishAlgorithmOperation(AlgorithmResult &retResult) -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - int32_t authResult = 0; - GetAuthResult(authResult); - FACEAUTH_HILOGI(MODULE_SERVICE, "get auth result = %{public}d.", authResult); - retResult.result = authResult; - retResult.templateId = param_.templateId; - GetRemainTimes(param_.templateId, retResult.remainTimes); - Buffer *retTlv = CreateBuffer(RESULT_TLV_LEN); - if (retTlv == nullptr) { - FACEAUTH_HILOGE(MODULE_SERVICE, "CreateBuffer failed."); - return -1; - } - ResultCode result = GenerateRetTlv(RESULT_SUCCESS, param_.scheduleId, FACE_AUTH, param_.templateId, retTlv); - if (result != RESULT_SUCCESS) { - FACEAUTH_HILOGE(MODULE_SERVICE, "GenerateRetTlv failed."); - DestoryBuffer(retTlv); - return -1; - } - result = SetResultTlv(retTlv, retResult.coauthMsg); - if (result != RESULT_SUCCESS) { - FACEAUTH_HILOGE(MODULE_SERVICE, "SetResultTlv failed."); - DestoryBuffer(retTlv); - return -1; - } - DestoryBuffer(retTlv); - return 0; -} - -int32_t FaceAuthCA::DeleteTemplete(uint64_t templateId) -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - (void)(templateId); - return 0; -} - -int32_t FaceAuthCA::VerifyTemplateData(std::vector templateIdList) -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - (void)(templateIdList); - return 0; -} - -int32_t FaceAuthCA::GetRemainTimes(uint64_t templateId, int32_t &remainingTimes) -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - return 0; -} - -int32_t FaceAuthCA::ResetRemainTimes(uint64_t templateId) -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - return 0; -} - -int32_t FaceAuthCA::CancelAlogrithmOperation() -{ - FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); - return 0; -} -void FaceAuthCA::SetAlgorithmParam(const AlgorithmParam ¶m) -{ - param_ = param; -} -// temp code start -void GetAuthResult(int32_t &result) -{ - FILE* pFile = nullptr; - pFile = fopen("/data/useriam/auth_result.txt", "r"); - if (pFile == nullptr) { - FACEAUTH_HILOGI(MODULE_SERVICE, "open file failed."); - return; - } - if (fseek(pFile, 0, SEEK_END) != 0) { - FACEAUTH_HILOGI(MODULE_SERVICE, "fseek failed."); - return; - } - if (ftell(pFile) < 0) { - fseek(pFile, 0, SEEK_SET); - char str[BUFF_MAX_LEN] = {0}; - fread((void*)str, sizeof(char), BUFF_MAX_LEN-1, pFile); - result = atoi(str); - } - if (fclose(pFile) != 0) { - FACEAUTH_HILOGI(MODULE_SERVICE, "fclose failed."); - } -} -// temp code end -} // namespace FaceAuth -} // namespace UserIAM -} // namespace OHOS diff --git a/useriam.gni b/useriam.gni old mode 100755 new mode 100644 -- Gitee