From b23be23f1417c12779ee27d51a2330ae21387b1e Mon Sep 17 00:00:00 2001 From: yanxuejun Date: Fri, 9 May 2025 16:18:17 +0800 Subject: [PATCH] fix: improve power arkts1.2 Signed-off-by: yanxuejun --- frameworks/ets/taihe/runninglock/BUILD.gn | 7 ++ .../runninglock/idl/ohos.runningLock.taihe | 2 +- .../ets/taihe/runninglock/test/test_main.ets | 48 ++++++++++ .../taihe/runninglock/test/xts/List.test.ets | 19 ++++ .../runninglock/test/xts/RunningLock.test.ets | 95 +++++++++++++++++++ .../taihe/runninglock/test/xts/Util.test.ets | 24 +++++ 6 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 frameworks/ets/taihe/runninglock/test/test_main.ets create mode 100644 frameworks/ets/taihe/runninglock/test/xts/List.test.ets create mode 100644 frameworks/ets/taihe/runninglock/test/xts/RunningLock.test.ets create mode 100644 frameworks/ets/taihe/runninglock/test/xts/Util.test.ets diff --git a/frameworks/ets/taihe/runninglock/BUILD.gn b/frameworks/ets/taihe/runninglock/BUILD.gn index 0469df43..32dc23ab 100644 --- a/frameworks/ets/taihe/runninglock/BUILD.gn +++ b/frameworks/ets/taihe/runninglock/BUILD.gn @@ -68,6 +68,13 @@ generate_static_abc("runningLock_abc") { dependencies = [ ":run_taihe" ] } +generate_static_abc("runningLock_test_abc") { + base_url = "$powermgr_framework/ets/taihe/runninglock/test" + files = [ "$powermgr_framework/ets/taihe/runninglock/test/test_main.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/runningLock_test_abc.abc" +} + ohos_prebuilt_etc("runningLock_etc") { source = "$target_out_dir/runningLock_abc.abc" module_install_dir = "framework" diff --git a/frameworks/ets/taihe/runninglock/idl/ohos.runningLock.taihe b/frameworks/ets/taihe/runninglock/idl/ohos.runningLock.taihe index f867d5ad..4b8c2609 100644 --- a/frameworks/ets/taihe/runninglock/idl/ohos.runningLock.taihe +++ b/frameworks/ets/taihe/runninglock/idl/ohos.runningLock.taihe @@ -18,7 +18,7 @@ @!sts_inject(""" static { loadLibrary("power_manager_runninglock_taihe_native.z") }""") -enum RunningLockType: i32 { BACKGROUND = 1, PROXIMITY_SCREEN_CONTROL } +enum RunningLockType: i32 { PROXIMITY_SCREEN_CONTROL = 2 } @class interface RunningLock { diff --git a/frameworks/ets/taihe/runninglock/test/test_main.ets b/frameworks/ets/taihe/runninglock/test/test_main.ets new file mode 100644 index 00000000..c77e2428 --- /dev/null +++ b/frameworks/ets/taihe/runninglock/test/test_main.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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 runningLock from "@ohos.runningLock"; + +function main() { + try { + console.info('create async RunningLock start'); + runningLock.create("RunningLockTest", runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL, (error: Error, lock_?: runningLock.RunningLock) => { + if (!error.message) { + console.info('create async RunningLock success'); + lock_?.hold(30000); + let isHold = lock_?.isHolding(); + console.info('isHold RunningLock after hold ${isHold}'); + lock_?.unhold(); + isHold = lock_?.isHolding(); + console.info('isHold RunningLock after unhold ${isHold}'); + console.info('create async RunningLock end'); + } else { + console.error('create async RunningLock ERROR ', error); + } + }) + + console.info('create async promise RunningLock start'); + let lock_ = await runningLock.create("RunningLockTest", runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL); + lock_.hold(30000); + let isHold = lock_.isHolding(); + console.info('isHold RunningLock after hold ${isHold}'); + lock_.unhold(); + isHold = lock_.isHolding(); + console.info('isHold RunningLock after unhold ${isHold}'); + console.info('create async promise RunningLock end'); + } catch (err) { + console.error("test runningLock err: " + err) + } +} \ No newline at end of file diff --git a/frameworks/ets/taihe/runninglock/test/xts/List.test.ets b/frameworks/ets/taihe/runninglock/test/xts/List.test.ets new file mode 100644 index 00000000..d0fa58cb --- /dev/null +++ b/frameworks/ets/taihe/runninglock/test/xts/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 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 RunningLockTest from './RunningLock.test' +export default function testsuite() { + RunningLockTest(); +} diff --git a/frameworks/ets/taihe/runninglock/test/xts/RunningLock.test.ets b/frameworks/ets/taihe/runninglock/test/xts/RunningLock.test.ets new file mode 100644 index 00000000..964f6a8d --- /dev/null +++ b/frameworks/ets/taihe/runninglock/test/xts/RunningLock.test.ets @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2025 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 { describe, it, expect, TestType, Size, Level, beforeAll} from "../../index"; +import { BusinessError } from '@ohos.base' +import hilog from '@ohos.hilog' +import Utils from './Util.test'; +import runningLock from '@ohos.runningLock' + +let domain: number = 0x0000; +let tag: string = 'testTag'; +const ERROR_CODE = 201; + +export default function RunningLockTest() { + + describe("RunningLockTest", (): void => { + hilog.info(domain, tag, '%{public}s', 'describe start'); + it("RunningLockTest0100", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: () => void): Promise => { + hilog.info(domain, tag, '%{public}s', 'RunningLockTest0100 start'); + let TAG = 'RunningLockTest0100'; + try { + runningLock.create("RunningLockTest0100", runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL, (error: Error, lock_?: runningLock.RunningLock) => { + if (!error.message) { + console.info(TAG + 'create async RunningLock success') + lock_?.hold(30000); + let isHold = lock_?.isHolding(); + lock_?.unhold(); + isHold = lock_?.isHolding(); + hilog.info(domain, tag, '%{public}s', JSON.stringify(isHold)); + hilog.info(domain, tag, '%{public}s', typeof isHold); + expect(typeof isHold).assertEqual('boolean'); + } else { + console.info(TAG + 'create async RunningLock ERROR ', error); + } + }) + console.info(TAG + ' end'); + done(); + } catch (e : BusinessError) { + hilog.error(domain, tag, '%{public}s', JSON.stringify(e)); + expect(e.code).assertEqual(ERROR_CODE); + done(); + } + }) + it("RunningLockTest0200", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: () => void): Promise => { + hilog.info(domain, tag, '%{public}s', 'RunningLockTest0200 start'); + let TAG = 'RunningLockTest0200'; + try { + let lock_ = await runningLock.create("RunningLockTest0200", runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL); + console.info(TAG + ' create async promise RunningLock success'); + lock_.hold(30000); + let isHold = lock_.isHolding(); + lock_.unhold(); + isHold = lock_.isHolding(); + hilog.info(domain, tag, '%{public}s', JSON.stringify(isHold)); + hilog.info(domain, tag, '%{public}s', typeof isHold); + expect(typeof isHold).assertEqual('boolean'); + console.info(TAG + ' end'); + done(); + } catch (e : BusinessError) { + hilog.error(domain, tag, '%{public}s', JSON.stringify(e)); + expect(e.code).assertEqual(ERROR_CODE); + done(); + } + }) + it("RunningLockTest0300", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: () => void): Promise => { + hilog.info(domain, tag, '%{public}s', 'RunningLockTest0300 start'); + let TAG = 'RunningLockTest0300'; + try { + let runningLockType = runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL; + expect(runningLockType === 2).assertTrue(); + console.info(TAG + ' end'); + done(); + } catch (e) { + hilog.error(domain, tag, '%{public}s', JSON.stringify(e)); + done(); + } + }) + }) + hilog.info(domain, tag, '%{public}s', 'RunningLockTest end'); +} \ No newline at end of file diff --git a/frameworks/ets/taihe/runninglock/test/xts/Util.test.ets b/frameworks/ets/taihe/runninglock/test/xts/Util.test.ets new file mode 100644 index 00000000..6c29b5d0 --- /dev/null +++ b/frameworks/ets/taihe/runninglock/test/xts/Util.test.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 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. + */ + +export default class Utils{ + static async msSleep(count:int) : Promise { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve(0) + }, count) + }) + } +} \ No newline at end of file -- Gitee