From d0bfb0d78fa688916a2677bd50f68da60455f0f0 Mon Sep 17 00:00:00 2001 From: lutao Date: Mon, 18 Jul 2022 20:20:33 +0800 Subject: [PATCH 1/3] hichecker api mock Signed-off-by: lutao --- .../main/extend/systemplugin/napi/index.js | 1 + .../systemplugin/napi/ohos_hichecker.js | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 runtime/main/extend/systemplugin/napi/ohos_hichecker.js diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 5d7c060e..5c1ee0a3 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -50,6 +50,7 @@ import { mockwebgl2 } from './webgl2' import { mockProcess } from './ohos_process' import { mockUrl } from './ohos_url' import { mockHiAppEvent } from './ohos_hiAppEvent' +import { mockHiChecker } from './ohos_hichecker' import { mockHilog } from './ohos_hilog' import { mockHiSysEvent } from './ohos_hiSysEvent' import { mockHiTraceChain } from './ohos_hiTraceChain' diff --git a/runtime/main/extend/systemplugin/napi/ohos_hichecker.js b/runtime/main/extend/systemplugin/napi/ohos_hichecker.js new file mode 100644 index 00000000..b414bab7 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_hichecker.js @@ -0,0 +1,50 @@ +/* + * 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" + +function buildMockInfo(interfaceName) { + return interfaceName + " interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device." +} + + +export function mockHiChecker() { + const RULE_CAUTION_PRINT_LOG = paramMock.paramNumberMock; + const RULE_CAUTION_TRIGGER_CRASH = paramMock.paramNumberMock; + const RULE_THREAD_CHECK_SLOW_PROCESS = paramMock.paramNumberMock; + const RULE_CHECK_ABILITY_CONNECTION_LEAK = paramMock.paramNumberMock; + const hichecker = { + RULE_CAUTION_PRINT_LOG, + RULE_CAUTION_TRIGGER_CRASH, + RULE_THREAD_CHECK_SLOW_PROCESS, + RULE_CHECK_ABILITY_CONNECTION_LEAK, + addRule: function(...args) { + console.warn(buildMockInfo("hichecker.addRule")) + }, + removeRule: function(...args) { + console.warn(buildMockInfo("hichecker.removeRule")) + }, + getRule: function(...args) { + console.warn(buildMockInfo("hichecker.getRule")) + return paramMock.paramNumberMock; + }, + contains: function(...args) { + console.warn(buildMockInfo("hichecker.contains")) + return paramMock.paramBooleanMock; + }, + } + return hichecker +} From 2489dcb55f8a04e932444f163c41899420f672c0 Mon Sep 17 00:00:00 2001 From: lutao Date: Tue, 26 Jul 2022 19:18:09 +0800 Subject: [PATCH 2/3] fix Signed-off-by: lutao --- .../main/extend/systemplugin/napi/index.js | 2 ++ .../systemplugin/napi/ohos_hichecker.js | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 5c1ee0a3..d99a70d4 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -346,6 +346,8 @@ export function mockRequireNapiFun() { return mockProcess(); case "url": return mockUrl(); + case "hichecker": + return mockHiChecker(); case "hiAppEvent": return mockHiAppEvent(); case "hilog": diff --git a/runtime/main/extend/systemplugin/napi/ohos_hichecker.js b/runtime/main/extend/systemplugin/napi/ohos_hichecker.js index b414bab7..2683fd64 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_hichecker.js +++ b/runtime/main/extend/systemplugin/napi/ohos_hichecker.js @@ -15,34 +15,32 @@ import { paramMock } from "../utils" -function buildMockInfo(interfaceName) { - return interfaceName + " interface mocked in the Previewer. How this interface works on the Previewer" + - " may be different from that on a real device." -} - - export function mockHiChecker() { - const RULE_CAUTION_PRINT_LOG = paramMock.paramNumberMock; - const RULE_CAUTION_TRIGGER_CRASH = paramMock.paramNumberMock; - const RULE_THREAD_CHECK_SLOW_PROCESS = paramMock.paramNumberMock; - const RULE_CHECK_ABILITY_CONNECTION_LEAK = paramMock.paramNumberMock; + const RULE_CAUTION_PRINT_LOG = 9223372036854775808n; + const RULE_CAUTION_TRIGGER_CRASH = 4611686018427387904n; + const RULE_THREAD_CHECK_SLOW_PROCESS = 1n; + const RULE_CHECK_ABILITY_CONNECTION_LEAK = 8589934592n; const hichecker = { RULE_CAUTION_PRINT_LOG, RULE_CAUTION_TRIGGER_CRASH, RULE_THREAD_CHECK_SLOW_PROCESS, RULE_CHECK_ABILITY_CONNECTION_LEAK, addRule: function(...args) { - console.warn(buildMockInfo("hichecker.addRule")) + console.warn("hichecker.addRule interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") }, removeRule: function(...args) { - console.warn(buildMockInfo("hichecker.removeRule")) + console.warn("hichecker.removeRule interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") }, getRule: function(...args) { - console.warn(buildMockInfo("hichecker.getRule")) + console.warn("hichecker.getRule interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") return paramMock.paramNumberMock; }, contains: function(...args) { - console.warn(buildMockInfo("hichecker.contains")) + console.warn("hichecker.contains interface mocked in the Previewer. How this interface works on the Previewer" + + " may be different from that on a real device.") return paramMock.paramBooleanMock; }, } From c5ae2a6e15a9d32257a6c5bfdd3f5445b2ce3744 Mon Sep 17 00:00:00 2001 From: lutao Date: Wed, 27 Jul 2022 15:57:26 +0800 Subject: [PATCH 3/3] fix compail fail Signed-off-by: lutao --- runtime/main/extend/systemplugin/napi/ohos_hichecker.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/main/extend/systemplugin/napi/ohos_hichecker.js b/runtime/main/extend/systemplugin/napi/ohos_hichecker.js index 2683fd64..6d0af8e9 100644 --- a/runtime/main/extend/systemplugin/napi/ohos_hichecker.js +++ b/runtime/main/extend/systemplugin/napi/ohos_hichecker.js @@ -16,10 +16,10 @@ import { paramMock } from "../utils" export function mockHiChecker() { - const RULE_CAUTION_PRINT_LOG = 9223372036854775808n; - const RULE_CAUTION_TRIGGER_CRASH = 4611686018427387904n; - const RULE_THREAD_CHECK_SLOW_PROCESS = 1n; - const RULE_CHECK_ABILITY_CONNECTION_LEAK = 8589934592n; + const RULE_CAUTION_PRINT_LOG = paramMock.paramNumberMock; + const RULE_CAUTION_TRIGGER_CRASH = paramMock.paramNumberMock; + const RULE_THREAD_CHECK_SLOW_PROCESS = paramMock.paramNumberMock; + const RULE_CHECK_ABILITY_CONNECTION_LEAK = paramMock.paramNumberMock; const hichecker = { RULE_CAUTION_PRINT_LOG, RULE_CAUTION_TRIGGER_CRASH,