From 342f1cc6354e21be244325e7e63f5b5fa3f48ddb Mon Sep 17 00:00:00 2001 From: sfchu Date: Fri, 26 Sep 2025 15:05:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A4=9A=E8=AE=BE=E5=A4=87=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=80=E5=8F=91=E5=90=8C=E6=BA=90=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=B7=A5=E7=A8=8B=20=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 32 ++++++++++++++++--- .../entrybackupability/EntryBackupAbility.ets | 17 +++++++++- .../entry/src/main/ets/pages/Index.ets | 22 +++++++++++++ .../entry/src/main/module.json5 | 12 +++++++ .../main/resources/base/element/string.json | 4 +++ 5 files changed, 82 insertions(+), 5 deletions(-) diff --git a/ArkUI/orientationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUI/orientationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets index e8c03cc6..a9c87930 100644 --- a/ArkUI/orientationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ArkUI/orientationDevelopment/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,12 +1,33 @@ -import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +/* + * Copyright (c) 2024 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 { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + onCreate(): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + hilog.error(DOMAIN, 'testTag', '%{public}s', + `Failed to setColorMode. Cause code: ${error.code}, message: ${error.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } @@ -17,7 +38,10 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - AppStorage.setOrCreate('mainWindow', windowStage.getMainWindow()); + AppStorage.setOrCreate('mainWindow', windowStage.getMainWindow().catch((error: BusinessError) => { + hilog.error(DOMAIN, 'testTag', '%{public}s', + `Failed to getMainWindow. Cause code: ${error.code}, message: ${error.message}`); + })); windowStage.loadContent('pages/Index', (err) => { if (err.code) { hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); diff --git a/ArkUI/orientationDevelopment/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUI/orientationDevelopment/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index 8e4de992..293e76ae 100644 --- a/ArkUI/orientationDevelopment/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/ArkUI/orientationDevelopment/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,5 +1,20 @@ -import { hilog } from '@kit.PerformanceAnalysisKit'; +/* + * Copyright (c) 2024 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 { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; const DOMAIN = 0x0000; diff --git a/ArkUI/orientationDevelopment/entry/src/main/ets/pages/Index.ets b/ArkUI/orientationDevelopment/entry/src/main/ets/pages/Index.ets index 5c9b16d9..148c0a8e 100644 --- a/ArkUI/orientationDevelopment/entry/src/main/ets/pages/Index.ets +++ b/ArkUI/orientationDevelopment/entry/src/main/ets/pages/Index.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + // [Start enable_nfc] import { nfcController } from '@kit.ConnectivityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -7,6 +22,10 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; struct Index { // [StartExclude enable_nfc] @State message: string = 'Hello World'; + + aboutToAppear(): void { + this.canIUseNfc(); + } // [EndExclude enable_nfc] canIUseNfc(): void { @@ -18,11 +37,14 @@ struct Index { } // [End caniuse_nfc_core] // [EndExclude enable_nfc] + if (canIUse('SystemCapability.Communication.NFC.Core')){ try { nfcController.enableNfc(); hilog.info(0x0000, 'Index', `nfcController enableNfc success`); } catch (businessError) { hilog.error(0x0000, 'Index', `nfcController enableNfc businessError: ${businessError}`); + }}else { + hilog.info(0x0000, 'Index', 'NFC not by this device.'); } // [StartExclude enable_nfc] } diff --git a/ArkUI/orientationDevelopment/entry/src/main/module.json5 b/ArkUI/orientationDevelopment/entry/src/main/module.json5 index f3a040d0..1b7aac5b 100644 --- a/ArkUI/orientationDevelopment/entry/src/main/module.json5 +++ b/ArkUI/orientationDevelopment/entry/src/main/module.json5 @@ -60,6 +60,18 @@ } ] } + ], + "requestPermissions": [ + { + "name": "ohos.permission.MANAGE_SECURE_SETTINGS", + "reason": "$string:manage_secure_settings_reason", + "usedScene": { + "abilities": [ + "FormAbility" + ], + "when": "inuse" + } + } ] // [EndExclude module] } diff --git a/ArkUI/orientationDevelopment/entry/src/main/resources/base/element/string.json b/ArkUI/orientationDevelopment/entry/src/main/resources/base/element/string.json index f9459551..9075650e 100644 --- a/ArkUI/orientationDevelopment/entry/src/main/resources/base/element/string.json +++ b/ArkUI/orientationDevelopment/entry/src/main/resources/base/element/string.json @@ -11,6 +11,10 @@ { "name": "EntryAbility_label", "value": "label" + }, + { + "name": "manage_secure_settings_reason", + "value": "To enable NFC, you need to apply for this permission." } ] } \ No newline at end of file -- Gitee From 37187c4887f7b846516e28691848c4954c1d4bff Mon Sep 17 00:00:00 2001 From: sfchu Date: Fri, 26 Sep 2025 15:18:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=B8=8D=E7=94=A8=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArkUI/orientationDevelopment/.gitignore | 12 ------- .../orientationDevelopment/code-linter.json5 | 32 ----------------- ArkUI/orientationDevelopment/entry/.gitignore | 6 ---- .../entry/build-profile.json5 | 3 -- .../src/ohosTest/ets/test/Ability.test.ets | 35 ------------------- .../entry/src/ohosTest/ets/test/List.test.ets | 5 --- .../entry/src/ohosTest/module.json5 | 14 -------- .../oh-package-lock.json5 | 28 --------------- 8 files changed, 135 deletions(-) delete mode 100644 ArkUI/orientationDevelopment/.gitignore delete mode 100644 ArkUI/orientationDevelopment/code-linter.json5 delete mode 100644 ArkUI/orientationDevelopment/entry/.gitignore delete mode 100644 ArkUI/orientationDevelopment/entry/src/ohosTest/ets/test/Ability.test.ets delete mode 100644 ArkUI/orientationDevelopment/entry/src/ohosTest/ets/test/List.test.ets delete mode 100644 ArkUI/orientationDevelopment/entry/src/ohosTest/module.json5 delete mode 100644 ArkUI/orientationDevelopment/oh-package-lock.json5 diff --git a/ArkUI/orientationDevelopment/.gitignore b/ArkUI/orientationDevelopment/.gitignore deleted file mode 100644 index d2ff2014..00000000 --- a/ArkUI/orientationDevelopment/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/node_modules -/oh_modules -/local.properties -/.idea -**/build -/.hvigor -.cxx -/.clangd -/.clang-format -/.clang-tidy -**/.test -/.appanalyzer \ No newline at end of file diff --git a/ArkUI/orientationDevelopment/code-linter.json5 b/ArkUI/orientationDevelopment/code-linter.json5 deleted file mode 100644 index 073990fa..00000000 --- a/ArkUI/orientationDevelopment/code-linter.json5 +++ /dev/null @@ -1,32 +0,0 @@ -{ - "files": [ - "**/*.ets" - ], - "ignore": [ - "**/src/ohosTest/**/*", - "**/src/test/**/*", - "**/src/mock/**/*", - "**/node_modules/**/*", - "**/oh_modules/**/*", - "**/build/**/*", - "**/.preview/**/*" - ], - "ruleSet": [ - "plugin:@performance/recommended", - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "@security/no-unsafe-aes": "error", - "@security/no-unsafe-hash": "error", - "@security/no-unsafe-mac": "warn", - "@security/no-unsafe-dh": "error", - "@security/no-unsafe-dsa": "error", - "@security/no-unsafe-ecdsa": "error", - "@security/no-unsafe-rsa-encrypt": "error", - "@security/no-unsafe-rsa-sign": "error", - "@security/no-unsafe-rsa-key": "error", - "@security/no-unsafe-dsa-key": "error", - "@security/no-unsafe-dh-key": "error", - "@security/no-unsafe-3des": "error" - } -} \ No newline at end of file diff --git a/ArkUI/orientationDevelopment/entry/.gitignore b/ArkUI/orientationDevelopment/entry/.gitignore deleted file mode 100644 index e2713a27..00000000 --- a/ArkUI/orientationDevelopment/entry/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/ArkUI/orientationDevelopment/entry/build-profile.json5 b/ArkUI/orientationDevelopment/entry/build-profile.json5 index 4d611879..0311b505 100644 --- a/ArkUI/orientationDevelopment/entry/build-profile.json5 +++ b/ArkUI/orientationDevelopment/entry/build-profile.json5 @@ -20,9 +20,6 @@ "targets": [ { "name": "default" - }, - { - "name": "ohosTest", } ] } \ No newline at end of file diff --git a/ArkUI/orientationDevelopment/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUI/orientationDevelopment/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 85c78f67..00000000 --- a/ArkUI/orientationDevelopment/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,35 +0,0 @@ -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }) - }) -} \ No newline at end of file diff --git a/ArkUI/orientationDevelopment/entry/src/ohosTest/ets/test/List.test.ets b/ArkUI/orientationDevelopment/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 794c7dc4..00000000 --- a/ArkUI/orientationDevelopment/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import abilityTest from './Ability.test'; - -export default function testsuite() { - abilityTest(); -} \ No newline at end of file diff --git a/ArkUI/orientationDevelopment/entry/src/ohosTest/module.json5 b/ArkUI/orientationDevelopment/entry/src/ohosTest/module.json5 deleted file mode 100644 index cae0a4a0..00000000 --- a/ArkUI/orientationDevelopment/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,14 +0,0 @@ -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1", - "wearable" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/ArkUI/orientationDevelopment/oh-package-lock.json5 b/ArkUI/orientationDevelopment/oh-package-lock.json5 deleted file mode 100644 index a3925056..00000000 --- a/ArkUI/orientationDevelopment/oh-package-lock.json5 +++ /dev/null @@ -1,28 +0,0 @@ -{ - "meta": { - "stableOrder": true, - "enableUnifiedLockfile": false - }, - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", - "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21" - }, - "packages": { - "@ohos/hamock@1.0.0": { - "name": "@ohos/hamock", - "version": "1.0.0", - "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", - "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har", - "registryType": "ohpm" - }, - "@ohos/hypium@1.0.21": { - "name": "@ohos/hypium", - "version": "1.0.21", - "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==", - "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.21.har", - "registryType": "ohpm" - } - } -} \ No newline at end of file -- Gitee