diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/entryability/EntryAbility.ets b/ArkTS_high_performance_segment/entry/src/main/ets/entryability/EntryAbility.ets index 508880af8c33aa838016d1cd4b2c68be2f447540..27b1c69664a8f0f9eac6044587d378f7510e3018 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,12 +1,33 @@ +/* + * 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; 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); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x000, 'testTag', `setColorMode failed. code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkTS_high_performance_segment/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index 786789953f923e62a8fa2a82f18fc70255316335..0a97e21bd7a15599af76a806695860ff1eb0ebfe 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,15 +1,30 @@ +/* + * 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 { hilog } from '@kit.PerformanceAnalysisKit'; import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; const DOMAIN = 0x0000; export default class EntryBackupAbility extends BackupExtensionAbility { - async onBackup () { + async onBackup() { hilog.info(DOMAIN, 'testTag', 'onBackup ok'); await Promise.resolve(); } - async onRestore (bundleVersion : BundleVersion) { + async onRestore(bundleVersion: BundleVersion) { hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); await Promise.resolve(); } diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/pages/Index.ets b/ArkTS_high_performance_segment/entry/src/main/ets/pages/Index.ets index 8e2d24ad42693fc877d51bb7820f0a9da68fa135..0f481f696485b8c840d49ad9e7d7dff7f6b71241 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/pages/Index.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/pages/Index.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + @Entry @Component struct Index { diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment.ets index 1f745f666a5690fb1ab650409ba2f9226656208b..abef65684ce2dd1bbf50d3134c8766ce56d4d674 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + // [Start Counter_example1] // The variable does not change in the subsequent process. It is recommended to declare it as a constant let PRICE = 10000; diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment2.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment2.ets index cd096f2dd8c83bb6adfc27315aa5ce57114795c0..5991dc97b7257c833b8aef20306ab2b1600d55b8 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment2.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment2.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + // [Start Case4] // app.ets import { getObject, TestA } from './segment'; diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment3.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment3.ets index f5d371a8d16ce19091997e3338245d269c04a198..612126065a5173cbfd17ab62fd6188eacd0ea712 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment3.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment3.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + // [Start Case8] import HashMap from '@ohos.util.HashMap'; diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment4.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment4.ets index f9dc50322a29a0e69e095917dbb257413bc83623..0dd33c4213f234a254e5a1b3220388443800f1f7 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment4.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment4.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + // [Start Case10] // A is any ets file that can be imported import { A } from "./A" diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment5.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment5.ets index 30828c874a1128fcf4a6d2045494a859b1c384f5..8b7b70a567cd6bf522f339838b418c33967738d9 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment5.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment5.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + // [Start Case11] import lazy { A } from "./A" diff --git a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment6.ets b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment6.ets index a04b9687cc09be36c347177fccbcd1bb1bfbf253..a7bd08f80dbd075951281051f38ea9664bba567c 100644 --- a/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment6.ets +++ b/ArkTS_high_performance_segment/entry/src/main/ets/segment/segment6.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + // Attention: This is the counterexample file // [Start export_multi_levels] diff --git a/OptimizationOfLoadingNonPreloadedImageResources/.gitignore b/OptimizationOfLoadingNonPreloadedImageResources/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/.gitignore @@ -0,0 +1,12 @@ +/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/OptimizationOfLoadingNonPreloadedImageResources/AppScope/app.json5 b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8346beef092fd44beeac140331021eb2b230e3a3 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.OptimizationOfLoadingNonPreloadedImageResources", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/element/string.json b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cd43db6ec5cdf93c9616caabe848ae54a906894d --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "OptimizationOfLoadingNonPreloadedImageResources" + } + ] +} diff --git a/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/background.png b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/background.png differ diff --git a/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/foreground.png b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/foreground.png differ diff --git a/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/layered_image.json b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/build-profile.json5 b/OptimizationOfLoadingNonPreloadedImageResources/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..618a66a565f6665c26b655e2d56e9fd9dbc180fd --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/build-profile.json5 @@ -0,0 +1,56 @@ +{ + "app": { + "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\Administrator\\.ohos\\config\\default_OptimizationOfLoadingNonPreloadedImageResources_hD1sesx_57rfTiQ279NzHRFJHKcCMbqHHcTYG0DaXjg=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001A59ED096588E0C342C8D9ABE2D6D30188F693DFE1CDE2DC8577CEBB52199A55AF88594F5F9068", + "profile": "C:\\Users\\Administrator\\.ohos\\config\\default_OptimizationOfLoadingNonPreloadedImageResources_hD1sesx_57rfTiQ279NzHRFJHKcCMbqHHcTYG0DaXjg=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\default_OptimizationOfLoadingNonPreloadedImageResources_hD1sesx_57rfTiQ279NzHRFJHKcCMbqHHcTYG0DaXjg=.p12", + "storePassword": "0000001A8803F5FD6010D8E670A1FE2C962BC1A566D5C0629D0C8EC17C3CCDD2FDA8650886B90315D1B0" + } + } + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.1.1(19)", + "compatibleSdkVersion": "5.1.1(19)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/code-linter.json5 b/OptimizationOfLoadingNonPreloadedImageResources/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "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/OptimizationOfLoadingNonPreloadedImageResources/entry/.gitignore b/OptimizationOfLoadingNonPreloadedImageResources/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/build-profile.json5 b/OptimizationOfLoadingNonPreloadedImageResources/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d611879c7913fb0610c686e2399258ab3a6dad1 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/hvigorfile.ts b/OptimizationOfLoadingNonPreloadedImageResources/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0e3a1ab98a91bc918d6404b2413111a5011f14a --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/obfuscation-rules.txt b/OptimizationOfLoadingNonPreloadedImageResources/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/entryability/EntryAbility.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..508880af8c33aa838016d1cd4b2c68be2f447540 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,44 @@ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +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); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e4de99282050bad799ac892eb85ac5449364a51 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,16 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/DownsampleThePixelmapUsingDesiredSize.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/DownsampleThePixelmapUsingDesiredSize.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad140454aa6849b30bc632dcd8c5f3c28dc6a7e4 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/DownsampleThePixelmapUsingDesiredSize.ets @@ -0,0 +1,76 @@ +/* + * 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 { BusinessError } from "@kit.BasicServicesKit"; +import { image } from "@kit.ImageKit"; +import { fileIo } from "@kit.CoreFileKit"; +import { photoAccessHelper } from "@kit.MediaLibraryKit"; + +@Component +export struct DownsampleThePixelmapUsingDesiredSize { + // [Start DownsampleThePixelmapUsingDesiredSize] + @State pixel: image.PixelMap | undefined = undefined; + + build() { + NavDestination() { + Column() { + Image(this.pixel) + .objectFit(ImageFit.None) + .width(300) + .height('30%') + + Button('Select image').onClick(() => { + try { + // Select album images. + let uris: Array = []; + let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; + PhotoSelectOptions.maxSelectNumber = 1; + let photoPicker = new photoAccessHelper.PhotoViewPicker(); + photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { + uris = PhotoSelectResult.photoUris; + let file = fileIo.openSync(uris[0], fileIo.OpenMode.READ_ONLY); + console.info('file fd: ' + file.fd); + let buffer = new ArrayBuffer(4096); + let readLen = fileIo.readSync(file.fd, buffer); + console.info('readSync data to file succeed and buffer size is:' + readLen); + const imageSource: image.ImageSource = image.createImageSource(file.fd); + let decodingOptions: image.DecodingOptions = { + editable: true, + desiredPixelFormat: 3, + desiredSize: { width: 400, height: 300 } + } + imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => { + console.info('Succeeded in creating pixelMap object through image decoding parameters.'); + this.pixel = pixelMap; + }).catch((error: BusinessError) => { + console.error(`Failed to create pixelMap object through image decoding parameters, error.code ${error.code}, error.message ${error.message}`); + }) + }).catch((err: BusinessError) => { + console.error(`Invoke photoPicker.select failed, code is ${err.code}, message is ${err.message}`); + }) + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('photoPicker failed with err: ' + JSON.stringify(err)); + } + }) + } + .width('100%') + .height('100%') + } + .backgroundColor('#F1F3F5') + } + + // [End DownsampleThePixelmapUsingDesiredSize] +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/Index.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4671234847a23d6517fb9221fa1d5396c6ec60ca --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,82 @@ +/* + * 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 { OptimizeWebImagesUsingCDN } from './OptimizeWebImagesUsingCDN'; +import { DownsampleThePixelmapUsingDesiredSize } from './DownsampleThePixelmapUsingDesiredSize'; +import { UseAutoResizeToDownsampleTheImageComponent } from './UseAutoResizeToDownsampleTheImageComponent'; + +@Entry +@Component +struct Index { + @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack(); + + @Builder + PageMap(name: string, param: string) { + if (name === 'OptimizeWebImagesUsingCDN') { + OptimizeWebImagesUsingCDN() + } else if (name === 'DownsampleThePixelmapUsingDesiredSize') { + DownsampleThePixelmapUsingDesiredSize() + } else if (name === 'UseAutoResizeToDownsampleTheImageComponent') { + UseAutoResizeToDownsampleTheImageComponent() + } + } + + build() { + Navigation(this.pageInfos) { + Column() { + Column({ space: 12 }) { + Button('使用CDN优化网络图片资源') + .width('100%') + .borderRadius(20) + .backgroundColor('#0A59F7') + .onClick(() => { + this.pageInfos.pushPathByName('OptimizeWebImagesUsingCDN', ''); + }) + + Button('使用desiredSize对pixelmap进行降采样') + .width('100%') + .borderRadius(20) + .backgroundColor('#0A59F7') + .onClick(() => { + this.pageInfos.pushPathByName('DownsampleThePixelmapUsingDesiredSize', ''); + }) + + Button('使用autoResize对Image组件进行降采样') + .width('100%') + .borderRadius(20) + .backgroundColor('#0A59F7') + .margin({ bottom: 16 }) + .onClick(() => { + this.pageInfos.pushPathByName('UseAutoResizeToDownsampleTheImageComponent', ''); + }) + } + .width('100%') + .justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + .padding({ + left: 16, + right: 16 + }) + .justifyContent(FlexAlign.End) + } + .title('非预置图片资源加载优化') + .height('100%') + .width('100%') + .backgroundColor('#F1F3F5') + .navDestination(this.PageMap) + } +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/OptimizeWebImagesUsingCDN.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/OptimizeWebImagesUsingCDN.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c15c533db3ba5b06145029238dc27d58b502dc1 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/OptimizeWebImagesUsingCDN.ets @@ -0,0 +1,36 @@ +/* + * 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. + */ + +@Component +export struct OptimizeWebImagesUsingCDN { + // [Start OptimizeWebImagesUsingCDN] + // It needs to be replaced with the image resource address required by the developer. + private imgUrl = 'https://******.com/path/to/image.jpg?w=200&h=150&fit=cover&q=85&format=webp'; + + build() { + NavDestination() { + Column() { + Image(this.imgUrl) + .width(200) + .height(150) + .objectFit(ImageFit.Cover) + } + .width('100%') + .height('100%') + } + .backgroundColor('#F1F3F5') + } + // [End OptimizeWebImagesUsingCDN] +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/UseAutoResizeToDownsampleTheImageComponent.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/UseAutoResizeToDownsampleTheImageComponent.ets new file mode 100644 index 0000000000000000000000000000000000000000..1668f30d4c3008c031368212a62e820d82623678 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/ets/pages/UseAutoResizeToDownsampleTheImageComponent.ets @@ -0,0 +1,78 @@ +/* + * 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 { BusinessError } from "@kit.BasicServicesKit"; +import { image } from "@kit.ImageKit"; +import { fileIo } from "@kit.CoreFileKit"; +import { photoAccessHelper } from "@kit.MediaLibraryKit"; + +@Component +export struct UseAutoResizeToDownsampleTheImageComponent { + // [Start UseAutoResizeToDownsampleTheImageComponent] + @State imageUrl: image.PixelMap | undefined = undefined; + + build() { + NavDestination() { + Column() { + // [Start UseAutoResizeToDownsampleTheImageComponent] + Image(this.imageUrl) + .width(300) + .height(200) + .autoResize(true) + // [End UseAutoResizeToDownsampleTheImageComponent] + + Button('Select image').onClick(() => { + try { + // Select album images. + let uris: Array = []; + let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; + PhotoSelectOptions.maxSelectNumber = 1; + let photoPicker = new photoAccessHelper.PhotoViewPicker(); + photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { + uris = PhotoSelectResult.photoUris; + let file = fileIo.openSync(uris[0], fileIo.OpenMode.READ_ONLY); + console.info('file fd: ' + file.fd); + let buffer = new ArrayBuffer(4096); + let readLen = fileIo.readSync(file.fd, buffer); + console.info('readSync data to file succeed and buffer size is:' + readLen); + const imageSource: image.ImageSource = image.createImageSource(file.fd); + let decodingOptions: image.DecodingOptions = { + editable: true, + desiredPixelFormat: 3 + } + imageSource.createPixelMap().then((pixelMap: image.PixelMap) => { + console.info('Succeeded in creating pixelMap object through image decoding parameters.'); + this.imageUrl = pixelMap; + }).catch((error: BusinessError) => { + console.error(`Failed to create pixelMap object through image decoding parameters, error.code ${error.code}, error.message ${error.message}`); + }) + }).catch((err: BusinessError) => { + console.error(`Invoke photoPicker.select failed, code is ${err.code}, message is ${err.message}`); + }) + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('photoPicker failed with err: ' + JSON.stringify(err)); + } + }) + } + .width('100%') + .height('100%') + } + .backgroundColor('#F1F3F5') + } + + // [End UseAutoResizeToDownsampleTheImageComponent] +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/module.json5 b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..53024e8f020cc0824592631ba6924108c8028f0f --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/module.json5 @@ -0,0 +1,50 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/color.json b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/float.json b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/string.json b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/background.png b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/background.png differ diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/foreground.png b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/foreground.png differ diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/layered_image.json b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/startIcon.png b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/media/startIcon.png differ diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/profile/backup_config.json b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/profile/main_pages.json b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/dark/element/color.json b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/mock/mock-config.json5 b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/ets/test/Ability.test.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +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/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/ets/test/List.test.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/module.json5 b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..509a3a28a3e6be8d7f98cc563fa8195657d77d1d --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/ohosTest/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/test/List.test.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/test/List.test.ets @@ -0,0 +1,5 @@ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/entry/src/test/LocalUnit.test.ets b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,33 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // 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. + 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/OptimizationOfLoadingNonPreloadedImageResources/hvigorfile.ts b/OptimizationOfLoadingNonPreloadedImageResources/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..47113e2e36ecefde41c136272a0bd6ff745cffe4 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/OptimizationOfLoadingNonPreloadedImageResources/oh-package-lock.json5 b/OptimizationOfLoadingNonPreloadedImageResources/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c2f6d1bc9cb330eeb990573aa7e74cbccfb64b61 --- /dev/null +++ b/OptimizationOfLoadingNonPreloadedImageResources/oh-package-lock.json5 @@ -0,0 +1,28 @@ +{ + "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://ohpm.openharmony.cn/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://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.21.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/SimpleChatList/entry/src/main/ets/entryability/EntryAbility.ets b/SimpleChatList/entry/src/main/ets/entryability/EntryAbility.ets index 972943b3fc48126078bf16c84c88a15ab87c5b8f..baaf775149e789d6b52b3fa4c5e2f50824e184e8 100644 --- a/SimpleChatList/entry/src/main/ets/entryability/EntryAbility.ets +++ b/SimpleChatList/entry/src/main/ets/entryability/EntryAbility.ets @@ -22,7 +22,12 @@ 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); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x000, 'testTag', `setColorMode failed. code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); }