From b837f7009d74a1ac6acff805eef29fce2a9d61fe Mon Sep 17 00:00:00 2001 From: zhi-min-huang Date: Wed, 20 Jul 2022 15:09:52 +0800 Subject: [PATCH] Add FaceAuth API Mock Signed-off-by: zhi-min-huang Change-Id: I02c6871c271f151f0b13570b039b1571a58d0965 --- .../main/extend/systemplugin/napi/index.js | 3 ++ .../napi/ohos_userIAM_faceAuth.js | 42 +++++++++++++++++++ .../napi/ohos_userIAM_userAuth.js | 19 +++++---- 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 runtime/main/extend/systemplugin/napi/ohos_userIAM_faceAuth.js diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 53aed7ae..ff34d52a 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -91,6 +91,7 @@ import { mockSecurityLabel } from './ohos_securitylabel' import { mockWorkScheduler } from './ohos_workScheduler' import { mockWorkSchedulerExtensionAbility } from './ohos_WorkSchedulerExtensionAbility' import { mockUserAuth } from './ohos_userIAM_userAuth' +import { mockFaceAuth } from './ohos_userIAM_faceAuth' import { mockArrayList } from './ohos_util_Arraylist' import { mockDeque } from './ohos_util_Deque' import { mockHashMap } from './ohos_util_HashMap' @@ -431,6 +432,8 @@ export function mockRequireNapiFun() { return mockWorkSchedulerExtensionAbility(); case "userIAM.userAuth": return mockUserAuth(); + case "userIAM.faceAuth": + return mockFaceAuth(); case "util.ArrayList": return mockArrayList(); case "util.Deque": diff --git a/runtime/main/extend/systemplugin/napi/ohos_userIAM_faceAuth.js b/runtime/main/extend/systemplugin/napi/ohos_userIAM_faceAuth.js new file mode 100644 index 00000000..0e0c5948 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_userIAM_faceAuth.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 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. + */ + +import { paramMock } from "../utils" + +export function mockFaceAuth() { + + const ResultCode = { + SUCCESS : 0, + FAIL : 1 + } + const FaceAuthManagerClass = class FaceAuthManager { + constructor() { + console.warn("faceAuth.constructor interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + + this.setSurfaceId = function (...args) { + console.warn("faceAuth.setSurfaceId interface mocked in the Previewer." + + " How this interface works on the Previewer may be different from that on a real device.") + return ResultCode.SUCCESS; + }; + } + } + + const faceAuth = { + ResultCode, + FaceAuthManager : FaceAuthManagerClass + } + return faceAuth; +} \ No newline at end of file diff --git a/runtime/main/extend/systemplugin/napi/ohos_userIAM_userAuth.js b/runtime/main/extend/systemplugin/napi/ohos_userIAM_userAuth.js index bb84f325..9f8b02aa 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_userIAM_userAuth.js +++ b/runtime/main/extend/systemplugin/napi/ohos_userIAM_userAuth.js @@ -32,7 +32,13 @@ export function mockUserAuth() { onAcquireInfo: function (...args) { console.warn("uerAuth.onAcquireInfo interface mocked in the Previewer. How this interface works" + " on the Previewer may be different from that on a real device.") - } + }, + } + + const AuthResult = { + token : paramMock.paramArrayMock, + remainTimes : "[PC Preview] unknown remainTimes", + freezingTime : "[PC Preview] unknown freezingTime", } const AuthenticatorClass = class Authenticator { @@ -84,11 +90,12 @@ export function mockUserAuth() { console.warn("uerAuth.cancelAuth interface mocked in the Previewer." + " How this interface works on the Previewer may be different from that on a real device.") return SUCCESS; - } + }; + } } - const result = { + const userAuth = { AuthenticationResult: { NO_SUPPORT : -1, SUCCESS : 0, @@ -151,14 +158,12 @@ export function mockUserAuth() { ATL3 : 30000, ATL4 : 40000 }, - - getAuthenticator: function (...args) { + getAuthenticator : function (...args) { console.warn("uerAuth.getAuthenticator interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") return new AuthenticatorClass; }, - UserAuth : UserAuthClass } - return result + return userAuth; } \ No newline at end of file