diff --git a/CppCrash/.gitignore b/CppCrash/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CppCrash/.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/CppCrash/AppScope/app.json5 b/CppCrash/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aefb31371deaa2d1239968aac1442f11e32a1361 --- /dev/null +++ b/CppCrash/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.cppcrash", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/CppCrash/AppScope/resources/base/element/string.json b/CppCrash/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5ebe019e7aa5389e7446d86a1a5195889cffb1e7 --- /dev/null +++ b/CppCrash/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CppCrash" + } + ] +} diff --git a/CppCrash/AppScope/resources/base/media/background.png b/CppCrash/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/CppCrash/AppScope/resources/base/media/background.png differ diff --git a/CppCrash/AppScope/resources/base/media/foreground.png b/CppCrash/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/CppCrash/AppScope/resources/base/media/foreground.png differ diff --git a/CppCrash/AppScope/resources/base/media/layered_image.json b/CppCrash/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CppCrash/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/CppCrash/build-profile.json5 b/CppCrash/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..adff6a0e3095f2c79f2fede08f299e7658c3dbca --- /dev/null +++ b/CppCrash/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.0.5(17)", + "compatibleSdkVersion": "5.0.0(12)", + "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/CppCrash/code-linter.json5 b/CppCrash/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/.gitignore b/CppCrash/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CppCrash/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CppCrash/entry/build-profile.json5 b/CppCrash/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..38bdcc9929e2c5bd7f51c4fc96a398ccebd0d6ce --- /dev/null +++ b/CppCrash/entry/build-profile.json5 @@ -0,0 +1,39 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/CppCrash/entry/hvigorfile.ts b/CppCrash/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/CppCrash/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. */ +} diff --git a/CppCrash/entry/obfuscation-rules.txt b/CppCrash/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/CppCrash/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/CppCrash/entry/oh-package-lock.json5 b/CppCrash/entry/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c8c8d64769f4712bca04df64e51eb46442cbc59 --- /dev/null +++ b/CppCrash/entry/oh-package-lock.json5 @@ -0,0 +1,18 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "libentry.so@src/main/cpp/types/libentry": "libentry.so@src/main/cpp/types/libentry" + }, + "packages": { + "libentry.so@src/main/cpp/types/libentry": { + "name": "libentry.so", + "version": "1.0.0", + "resolved": "src/main/cpp/types/libentry", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/CppCrash/entry/oh-package.json5 b/CppCrash/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..54cb066266f9993f5a023f2ac5a8dfc5d2574643 --- /dev/null +++ b/CppCrash/entry/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/CppCrash/entry/src/main/cpp/CMakeLists.txt b/CppCrash/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1acd3ec1c568e86cb70911ecc57edfbb21bcd1ea --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(CppCrash) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse1.cpp b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1f95605b420cb22e313bc257263f1f952b3484c --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse1.cpp @@ -0,0 +1,20 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +/** + * 最佳实践:CppCrash问题案例分析 + */ + +#include + +// [Start TriggerCrash1] +static napi_value TriggerCrash(napi_env env, napi_callback_info info) +{ + char *s = "hello world"; + s[1] = 'H'; + return 0; +} +// [End TriggerCrash1] diff --git a/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse2.cpp b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5bd9cd2fcbdfb35fc1e78aa26ff6fa517c4e393a --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse2.cpp @@ -0,0 +1,20 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +/** + * 最佳实践:CppCrash问题案例分析 + */ + +#include + +// [Start TriggerCrash2] +static napi_value TriggerCrash(napi_env env, napi_callback_info info) +{ + uint64_t* p = (uint64_t*)0xffffffcfc42ae6f4; + *p = 10; + return 0; +} +// [End TriggerCrash2] diff --git a/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse3.cpp b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef27751c70c71c84e953426a2970f0a607e0cd58 --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse3.cpp @@ -0,0 +1,20 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +/** + * 最佳实践:CppCrash问题案例分析 + */ + +#include + +// [Start TriggerCrash3] +static napi_value TriggerCrash(napi_env env, napi_callback_info info) +{ + int *a = NULL; + *a = 1; + return 0; +} +// [End TriggerCrash3] diff --git a/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse4.cpp b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse4.cpp new file mode 100644 index 0000000000000000000000000000000000000000..35efe1ea512d5b3d48c71f3a425d88dc8f14509d --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse4.cpp @@ -0,0 +1,24 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +/** + * 最佳实践:CppCrash问题案例分析 + */ + +#include +#include +#include + +// [Start TriggerCrash4] +static napi_value TriggerCrash(napi_env env, napi_callback_info info) +{ + void *pc = malloc(1024); + free(pc); + free(pc); // repetitive free + printf("free ok!\n"); + return 0; +} +// [End TriggerCrash4] diff --git a/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse5.cpp b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse5.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b98e3e434f21736d8f820423bb220737d023c15 --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse5.cpp @@ -0,0 +1,24 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +/** + * 最佳实践:CppCrash问题案例分析 + */ + +#include +#include +void OH_LOG_FATAL(const char *c, const char *cc) { + +} + +// [Start TriggerCrash5] +static napi_value TriggerCrash(napi_env env, napi_callback_info info) +{ + OH_LOG_FATAL("LOG_APP", "test fatal log."); + abort(); + return 0; +} +// [End TriggerCrash5] \ No newline at end of file diff --git a/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse6.cpp b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse6.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f39dbcaf377d439134a13978e5576dd0c36313f2 --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CppCrashCaseAnalyse6.cpp @@ -0,0 +1,25 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +/** + * 最佳实践:CppCrash问题案例分析 + */ + +#include +#include + +// [Start TriggerCrash6] +static napi_value TriggerCrash(napi_env env, napi_callback_info info) +{ +# if 0 //If the value is 0, an error will be reported. If it is 1, it is normal + void *pc = malloc(1024); +# else + void *pc = nullptr; +# endif + assert(pc != nullptr); + return 0; +} +// [End TriggerCrash6] \ No newline at end of file diff --git a/CppCrash/entry/src/main/cpp/CppCrashQuestionCheck1.cpp b/CppCrash/entry/src/main/cpp/CppCrashQuestionCheck1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d47d9003ed9803a43507a0ad09b5ce84b2c43a8 --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CppCrashQuestionCheck1.cpp @@ -0,0 +1,27 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +/** + * 最佳实践:CppCrash问题排查方法 + */ + +// [Start getStackReference] +# include + +int& getStackReference() { + int x = 5; + return x; // Return the reference of x +} + + +int main() { + int& ref = getStackReference(); // Obtain the reference of x + // x is released after the getStackReference function returns + // ref is now a dangling reference. Continuing to access it will result in undefined behavior + std::cout << ref << std::endl; // Attempting to output the value of x is an undefined behavior + return 0; +} +// [End getStackReference] \ No newline at end of file diff --git a/CppCrash/entry/src/main/cpp/CppCrashQuestionCheck2.cpp b/CppCrash/entry/src/main/cpp/CppCrashQuestionCheck2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..10e720cba954f8171610330f27301b5ed870a534 --- /dev/null +++ b/CppCrash/entry/src/main/cpp/CppCrashQuestionCheck2.cpp @@ -0,0 +1,33 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +/** + * 最佳实践:CppCrash问题排查方法 + */ + +// [Start RecursiveClass] +# include + +class RecursiveClass { +public: + RecursiveClass() { + std::cout << "Constructing RecursiveClass" << std::endl; + } + + + ~RecursiveClass() { + std::cout << "Destructing RecursiveClass" << std::endl; + // Make recursive calls in the destructor + RecursiveClass obj; + } +}; + + +int main() { + RecursiveClass obj; + return 0; +} +// [End RecursiveClass] diff --git a/CppCrash/entry/src/main/cpp/napi_init.cpp b/CppCrash/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85330e3e84d1f6c8a82e544fb315483ca597d23d --- /dev/null +++ b/CppCrash/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,53 @@ +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args , nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; + +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/CppCrash/entry/src/main/cpp/types/libentry/index.d.ts b/CppCrash/entry/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e44f3615a4767c36b4fdc841b781af96bf1971a8 --- /dev/null +++ b/CppCrash/entry/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1 @@ +export const add: (a: number, b: number) => number; \ No newline at end of file diff --git a/CppCrash/entry/src/main/cpp/types/libentry/oh-package.json5 b/CppCrash/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17f2fec28b34ad5d42507c4fa15c7e4d0d16eb70 --- /dev/null +++ b/CppCrash/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/CppCrash/entry/src/main/ets/entryability/EntryAbility.ets b/CppCrash/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..508880af8c33aa838016d1cd4b2c68be2f447540 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CppCrash/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e4de99282050bad799ac892eb85ac5449364a51 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/main/ets/pages/Index.ets b/CppCrash/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e2d24ad42693fc877d51bb7820f0a9da68fa135 --- /dev/null +++ b/CppCrash/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,23 @@ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CppCrash/entry/src/main/module.json5 b/CppCrash/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a1cea8b6a4560cee7bda7a2db52f310c035ab6c8 --- /dev/null +++ b/CppCrash/entry/src/main/module.json5 @@ -0,0 +1,52 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "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": [ + "action.system.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/CppCrash/entry/src/main/resources/base/element/color.json b/CppCrash/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/main/resources/base/element/float.json b/CppCrash/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/CppCrash/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/CppCrash/entry/src/main/resources/base/element/string.json b/CppCrash/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/main/resources/base/media/background.png b/CppCrash/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/CppCrash/entry/src/main/resources/base/media/background.png differ diff --git a/CppCrash/entry/src/main/resources/base/media/foreground.png b/CppCrash/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/CppCrash/entry/src/main/resources/base/media/foreground.png differ diff --git a/CppCrash/entry/src/main/resources/base/media/layered_image.json b/CppCrash/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/main/resources/base/media/startIcon.png b/CppCrash/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CppCrash/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CppCrash/entry/src/main/resources/base/profile/backup_config.json b/CppCrash/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CppCrash/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/CppCrash/entry/src/main/resources/base/profile/main_pages.json b/CppCrash/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CppCrash/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CppCrash/entry/src/main/resources/dark/element/color.json b/CppCrash/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/mock/mock-config.json5 b/CppCrash/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/CppCrash/entry/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/CppCrash/entry/src/ohosTest/ets/test/Ability.test.ets b/CppCrash/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/ohosTest/ets/test/List.test.ets b/CppCrash/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/ohosTest/module.json5 b/CppCrash/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..55725a929993a8a18b3808d41ef037759440488b --- /dev/null +++ b/CppCrash/entry/src/ohosTest/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/CppCrash/entry/src/test/List.test.ets b/CppCrash/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/CppCrash/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/CppCrash/entry/src/test/LocalUnit.test.ets b/CppCrash/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/CppCrash/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/CppCrash/hvigor/hvigor-config.json5 b/CppCrash/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5bebc9755447385d82ce4138f54d991b1f85f348 --- /dev/null +++ b/CppCrash/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.5", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/CppCrash/hvigorfile.ts b/CppCrash/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/CppCrash/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. */ +} diff --git a/CppCrash/oh-package-lock.json5 b/CppCrash/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c6f99f5c73b06c5fdef7ec6f491b74b7befebe2e --- /dev/null +++ b/CppCrash/oh-package-lock.json5 @@ -0,0 +1,27 @@ +{ + "meta": { + "stableOrder": true + }, + "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 diff --git a/CppCrash/oh-package.json5 b/CppCrash/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a8aff0c5aff22d78aa26fd19c3861f4320e951ff --- /dev/null +++ b/CppCrash/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.0.5", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/JSCrash/.gitignore b/JSCrash/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/JSCrash/.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/JSCrash/AppScope/app.json5 b/JSCrash/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b59947ef22af5c9556772a5ddf60e0d1dc736f4d --- /dev/null +++ b/JSCrash/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.jscrash", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/JSCrash/AppScope/resources/base/element/string.json b/JSCrash/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7472d31d167e43bdff48f28aa38eaba344004de6 --- /dev/null +++ b/JSCrash/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JSCrash" + } + ] +} diff --git a/JSCrash/AppScope/resources/base/media/background.png b/JSCrash/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/JSCrash/AppScope/resources/base/media/background.png differ diff --git a/JSCrash/AppScope/resources/base/media/foreground.png b/JSCrash/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/JSCrash/AppScope/resources/base/media/foreground.png differ diff --git a/JSCrash/AppScope/resources/base/media/layered_image.json b/JSCrash/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/JSCrash/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/JSCrash/build-profile.json5 b/JSCrash/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..adff6a0e3095f2c79f2fede08f299e7658c3dbca --- /dev/null +++ b/JSCrash/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.0.5(17)", + "compatibleSdkVersion": "5.0.0(12)", + "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/JSCrash/code-linter.json5 b/JSCrash/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/.gitignore b/JSCrash/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/JSCrash/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/JSCrash/entry/build-profile.json5 b/JSCrash/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d611879c7913fb0610c686e2399258ab3a6dad1 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/hvigorfile.ts b/JSCrash/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/JSCrash/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. */ +} diff --git a/JSCrash/entry/obfuscation-rules.txt b/JSCrash/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/JSCrash/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/JSCrash/entry/oh-package.json5 b/JSCrash/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..248c3b7541a589682a250f86a6d3ecf7414d2d6a --- /dev/null +++ b/JSCrash/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/JSCrash/entry/src/main/ets/entryability/EntryAbility.ets b/JSCrash/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..508880af8c33aa838016d1cd4b2c68be2f447540 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/JSCrash/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e4de99282050bad799ac892eb85ac5449364a51 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/main/ets/pages/Index.ets b/JSCrash/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e2d24ad42693fc877d51bb7820f0a9da68fa135 --- /dev/null +++ b/JSCrash/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,23 @@ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse1.ets b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse1.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4d0f2fa6114226aa4d27767902ea1ba748517df --- /dev/null +++ b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse1.ets @@ -0,0 +1,54 @@ +/** + * 最佳实践:JSCrash问题案例分析 + */ + +import { hidebug } from '@kit.PerformanceAnalysisKit'; + +// 添加SCBSceneContainerSession类型定义 +interface NeedRenderTranslate { + translateY: number; +} + +interface SCBSceneContainerSession { + needRenderTranslate: NeedRenderTranslate; +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + @State translationUpY: number = 0; + @State translationDownY: number = 0; + @State screenWidth: number = 0; + @State recentScale: number = 0; + @State multiCardsNum: number = 0; + + // [Start updateGestureValue1] + // Update the attributes related to manual effects + public updateGestureValue(screenWidth: number, recentScale: number, sceneContainerSessionList: SCBSceneContainerSession[]) { + // Calculation of the distance moved by the hand + this.translationUpY = (this.multiCardsNum >= 1) ? sceneContainerSessionList[this.multiCardsNum - 1].needRenderTranslate.translateY : 0; // Report an incorrect line number + this.translationDownY = (this.multiCardsNum >= 2) ? sceneContainerSessionList[this.multiCardsNum - 2].needRenderTranslate.translateY : 0; + this.screenWidth = px2vp(screenWidth); + this.recentScale = recentScale; + } + // [End updateGestureValue1] + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(()=>{ + hidebug.getPss(); + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse2.ets b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse2.ets new file mode 100644 index 0000000000000000000000000000000000000000..b9bd73bf6f348c26f02a8c161dfa3dde358482cb --- /dev/null +++ b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse2.ets @@ -0,0 +1,58 @@ +/** + * 最佳实践:JSCrash问题案例分析 + */ + +import { hidebug } from '@kit.PerformanceAnalysisKit'; + +// 添加SCBSceneContainerSession类型定义 +interface NeedRenderTranslate { + translateY: number; +} + +interface SCBSceneContainerSession { + needRenderTranslate: NeedRenderTranslate; +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + @State translationUpY: number = 0; + @State translationDownY: number = 0; + @State screenWidth: number = 0; + @State recentScale: number = 0; + @State multiCardsNum: number = 0; + + // [Start updateGestureValue2] + // Update the attributes related to manual effects + public updateGestureValue(screenWidth: number, recentScale: number, sceneContainerSessionList: SCBSceneContainerSession[]) { + // Calculation of the distance moved by the hand + this.translationUpY = (this.multiCardsNum >= 1) ? + sceneContainerSessionList[this.multiCardsNum - 1]?.needRenderTranslate.translateY : 0; + this.translationDownY = (this.multiCardsNum >= 2) ? + sceneContainerSessionList[this.multiCardsNum - 2]?.needRenderTranslate.translateY : 0; + this.screenWidth = px2vp(screenWidth); + this.recentScale = recentScale; + } + // [End updateGestureValue2] + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(()=>{ + hidebug.getPss(); + throw new Error("TEST JS ERROR") + }) + + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse3.ets b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse3.ets new file mode 100644 index 0000000000000000000000000000000000000000..85f9599278cd07c8444e3e3a4169b7752f3ee9a1 --- /dev/null +++ b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse3.ets @@ -0,0 +1,33 @@ +/** + * 最佳实践:JSCrash问题案例分析 + */ + +import { hidebug } from '@kit.PerformanceAnalysisKit'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(()=>{ + hidebug.getPss(); + // [Start TestJSError] + throw new Error("TEST JS ERROR") + // [End TestJSError] + }) + + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse4.ets b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse4.ets new file mode 100644 index 0000000000000000000000000000000000000000..b070d5bf57be72153b2203653276f3c11ead8ace --- /dev/null +++ b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse4.ets @@ -0,0 +1,34 @@ +/** + * 最佳实践:JSCrash问题案例分析 + */ + +import wifiManager from '@ohos.wifiManager'; +import { Log as log } from './utils' +class BaseComponent { + onStart(): void { + + } +} + +class Index extends BaseComponent{ + isConnected: boolean = false; + handleUpdateState() {} + isWifiActive: boolean = false; + + // [Start JSCrashCaseAnalyse4] + onStart(): void { + super.onStart(); + log.showInfo('onStart'); + // [StartExclude JSCrashCaseAnalyse4] + wifiManager.on('wifiConnectionChange', (data) => { + this.isConnected = data === 1 ? true : false; + this.handleUpdateState(); + }); + wifiManager.on('wifiStateChange', (data) => { + this.isWifiActive = data === 1 ? true : false; + this.handleUpdateState(); + }); + // [EndExclude JSCrashCaseAnalyse4] + } + // [End JSCrashCaseAnalyse4] +} diff --git a/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse5.ets b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse5.ets new file mode 100644 index 0000000000000000000000000000000000000000..3be65c7b28a2d2026ddfe121c8790aa8e78e0a0c --- /dev/null +++ b/JSCrash/entry/src/main/ets/pages/JSCrashCaseAnalyse5.ets @@ -0,0 +1,42 @@ +/** + * 最佳实践:JSCrash问题案例分析 + */ + +import wifiManager from '@ohos.wifiManager'; +import { Log as log } from './utils' +class BaseComponent { + onStart(): void { + + } +} + +class Index extends BaseComponent{ + isConnected: boolean = false; + handleUpdateState() {} + isWifiActive: boolean = false; + + // [Start JSCrashCaseAnalyse5] + onStart(): void { + super.onStart(); + log.showInfo('onStart'); + // [StartExclude JSCrashCaseAnalyse5] + try { + wifiManager.on('wifiConnectionChange', (data) => { + this.isConnected = data === 1 ? true : false; + this.handleUpdateState(); + }); + } catch (error) { + log.showError('wifiConnectionChange error'); + } + try { + wifiManager.on('wifiStateChange', (data) => { + this.isWifiActive = data === 1 ? true : false; + this.handleUpdateState(); + }); + } catch (error) { + log.showError('wifiStateChange error'); + } + // [EndExclude JSCrashCaseAnalyse5] + } + // [End JSCrashCaseAnalyse5] +} diff --git a/JSCrash/entry/src/main/ets/pages/JSCrashQuestionCheck.ets b/JSCrash/entry/src/main/ets/pages/JSCrashQuestionCheck.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf1bfbe15c479408ddd3b0c1792ad12cc5fe20e9 --- /dev/null +++ b/JSCrash/entry/src/main/ets/pages/JSCrashQuestionCheck.ets @@ -0,0 +1,30 @@ +/** + * 最佳实践:JSCrash问题排查方法 + */ + +// [Start JSCrashQuestionCheck] +import { hidebug } from '@kit.PerformanceAnalysisKit'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(()=>{ + hidebug.getPss(); + }) + } + .height('100%') + .width('100%') + } +} +// [End JSCrashQuestionCheck] \ No newline at end of file diff --git a/JSCrash/entry/src/main/ets/pages/utils.ets b/JSCrash/entry/src/main/ets/pages/utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..624c38b007bf4a3b92688590bb1195e592430e13 --- /dev/null +++ b/JSCrash/entry/src/main/ets/pages/utils.ets @@ -0,0 +1,89 @@ +import hilog from '@ohos.hilog'; + +const TAG = 'ZCM_Default'; + +const DOMAIN = 0x0011; +const SYMBOL = " --> "; + +export class Log { + /** + * Outputs info-level logs. + * + * @param tag Identifies the log tag. + * @param format Indicates the log format string. + * @param args Indicates the log parameters. + * @since 7 + */ + static showInfo(tag: string) { + if (Log.isLoggable(tag, hilog.LogLevel.INFO)) { + hilog.info(DOMAIN, TAG, tag + SYMBOL); + } + } + + /** + * Outputs debug-level logs. + * + * @param tag Identifies the log tag. + * @param format Indicates the log format string. + * @param args Indicates the log parameters. + * @since 7 + */ + static showDebug(tag: string, format: string, ...args: string[]) { + if (Log.isLoggable(tag, hilog.LogLevel.DEBUG)) { + hilog.debug(DOMAIN, TAG, tag + SYMBOL + format, args); + } + } + + /** + * Outputs warning-level logs. + * + * @param tag Identifies the log tag. + * @param format Indicates the log format string. + * @param args Indicates the log parameters. + * @since 7 + */ + static showWarn(tag: string, format: string, ...args: string[]) { + if (Log.isLoggable(tag, hilog.LogLevel.WARN)) { + hilog.warn(DOMAIN, TAG, tag + SYMBOL + format, args); + } + } + + /** + * Outputs error-level logs. + * + * @param tag Identifies the log tag. + * @param format Indicates the log format string. + * @param args Indicates the log parameters. + * @since 7 + */ + static showError(tag: string) { + if (Log.isLoggable(tag, hilog.LogLevel.ERROR)) { + hilog.error(DOMAIN, TAG, tag + SYMBOL); + } + } + + /** + * Outputs fatal-level logs. + * + * @param tag Identifies the log tag. + * @param format Indicates the log format string. + * @param args Indicates the log parameters. + * @since 7 + */ + static showFatal(tag: string, format: string, ...args: string[]) { + if (Log.isLoggable(tag, hilog.LogLevel.FATAL)) { + hilog.fatal(DOMAIN, TAG, tag + SYMBOL + format, args); + } + } + + /** + * Checks whether logs of the specified tag, and level can be printed. + * + * @param tag Identifies the log tag. + * @param level log level + * @since 7 + */ + private static isLoggable(tag:string, level: hilog.LogLevel): boolean { + return hilog.isLoggable(DOMAIN, tag, level); + } +} \ No newline at end of file diff --git a/JSCrash/entry/src/main/module.json5 b/JSCrash/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a1cea8b6a4560cee7bda7a2db52f310c035ab6c8 --- /dev/null +++ b/JSCrash/entry/src/main/module.json5 @@ -0,0 +1,52 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "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": [ + "action.system.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/JSCrash/entry/src/main/resources/base/element/color.json b/JSCrash/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/main/resources/base/element/float.json b/JSCrash/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/JSCrash/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/JSCrash/entry/src/main/resources/base/element/string.json b/JSCrash/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/main/resources/base/media/background.png b/JSCrash/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/JSCrash/entry/src/main/resources/base/media/background.png differ diff --git a/JSCrash/entry/src/main/resources/base/media/foreground.png b/JSCrash/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/JSCrash/entry/src/main/resources/base/media/foreground.png differ diff --git a/JSCrash/entry/src/main/resources/base/media/layered_image.json b/JSCrash/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/main/resources/base/media/startIcon.png b/JSCrash/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/JSCrash/entry/src/main/resources/base/media/startIcon.png differ diff --git a/JSCrash/entry/src/main/resources/base/profile/backup_config.json b/JSCrash/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/JSCrash/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/JSCrash/entry/src/main/resources/base/profile/main_pages.json b/JSCrash/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/JSCrash/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/JSCrash/entry/src/main/resources/dark/element/color.json b/JSCrash/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/mock/mock-config.json5 b/JSCrash/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/JSCrash/entry/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/JSCrash/entry/src/ohosTest/ets/test/Ability.test.ets b/JSCrash/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/ohosTest/ets/test/List.test.ets b/JSCrash/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/ohosTest/module.json5 b/JSCrash/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..55725a929993a8a18b3808d41ef037759440488b --- /dev/null +++ b/JSCrash/entry/src/ohosTest/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/JSCrash/entry/src/test/List.test.ets b/JSCrash/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/JSCrash/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/JSCrash/entry/src/test/LocalUnit.test.ets b/JSCrash/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/JSCrash/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/JSCrash/hvigor/hvigor-config.json5 b/JSCrash/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5bebc9755447385d82ce4138f54d991b1f85f348 --- /dev/null +++ b/JSCrash/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.5", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/JSCrash/hvigorfile.ts b/JSCrash/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/JSCrash/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. */ +} diff --git a/JSCrash/oh-package-lock.json5 b/JSCrash/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c6f99f5c73b06c5fdef7ec6f491b74b7befebe2e --- /dev/null +++ b/JSCrash/oh-package-lock.json5 @@ -0,0 +1,27 @@ +{ + "meta": { + "stableOrder": true + }, + "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 diff --git a/JSCrash/oh-package.json5 b/JSCrash/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a8aff0c5aff22d78aa26fd19c3861f4320e951ff --- /dev/null +++ b/JSCrash/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.0.5", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/StabilityCodingSpecification/.gitignore b/StabilityCodingSpecification/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/StabilityCodingSpecification/.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/StabilityCodingSpecification/AppScope/app.json5 b/StabilityCodingSpecification/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..340094e36ca0dd6384336aea5a509b2147bb4a83 --- /dev/null +++ b/StabilityCodingSpecification/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.stabilitycodingspecification", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/StabilityCodingSpecification/AppScope/resources/base/element/string.json b/StabilityCodingSpecification/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c826aaf4d90d8eec9dcdf2b7d26c7a44374e116b --- /dev/null +++ b/StabilityCodingSpecification/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "StabilityCodingSpecification" + } + ] +} diff --git a/StabilityCodingSpecification/AppScope/resources/base/media/background.png b/StabilityCodingSpecification/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/StabilityCodingSpecification/AppScope/resources/base/media/background.png differ diff --git a/StabilityCodingSpecification/AppScope/resources/base/media/foreground.png b/StabilityCodingSpecification/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/StabilityCodingSpecification/AppScope/resources/base/media/foreground.png differ diff --git a/StabilityCodingSpecification/AppScope/resources/base/media/layered_image.json b/StabilityCodingSpecification/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/StabilityCodingSpecification/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/StabilityCodingSpecification/DevEcoStaticCheck/.gitignore b/StabilityCodingSpecification/DevEcoStaticCheck/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/build-profile.json5 b/StabilityCodingSpecification/DevEcoStaticCheck/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d611879c7913fb0610c686e2399258ab3a6dad1 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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/StabilityCodingSpecification/DevEcoStaticCheck/hvigorfile.ts b/StabilityCodingSpecification/DevEcoStaticCheck/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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. */ +} diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/obfuscation-rules.txt b/StabilityCodingSpecification/DevEcoStaticCheck/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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/StabilityCodingSpecification/DevEcoStaticCheck/oh-package.json5 b/StabilityCodingSpecification/DevEcoStaticCheck/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aa8c54df55e44d3d11da6e1ed22003ac08cdc662 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "devecostaticcheck", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/devecostaticcheckability/DevEcoStaticCheckAbility.ets b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/devecostaticcheckability/DevEcoStaticCheckAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c1058ffe6ba4a27843b5d84e9443026b0f55a8b --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/devecostaticcheckability/DevEcoStaticCheckAbility.ets @@ -0,0 +1,43 @@ +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class DevEcoStaticCheckAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + 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'); + } +} diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/pages/Index.ets b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..612dc7131e9b55504a2f2ac9bd178f6b03ac8b35 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/pages/Index.ets @@ -0,0 +1,35 @@ +/** + * 最佳实践:使用DevEco Studio静态检测编码规范 + */ + +// [Start Foo1] +class Foo { + static bar() {} +} + +Foo.bar(); +// [End Foo1] + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/pages/Index2.ets b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/pages/Index2.ets new file mode 100644 index 0000000000000000000000000000000000000000..1975992afa1e8929e7bd477148468f9cdaed4725 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/ets/pages/Index2.ets @@ -0,0 +1,33 @@ +/** + * 最佳实践:使用DevEco Studio静态检测编码规范 + */ + +// [Start Foo2] +class foo { //Here is an example of a naming style error, where foo is the incorrect class name used, and the correct class name should be Foo + bar() {} +} +// [End Foo2] + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/module.json5 b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5d96966c895dab6d7573ca5a9dc256cf65ac3176 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/module.json5 @@ -0,0 +1,28 @@ +{ + "module": { + "name": "DevEcoStaticCheck", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "DevEcoStaticCheckAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "DevEcoStaticCheckAbility", + "srcEntry": "./ets/devecostaticcheckability/DevEcoStaticCheckAbility.ets", + "description": "$string:DevEcoStaticCheckAbility_desc", + "icon": "$media:layered_image", + "label": "$string:DevEcoStaticCheckAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/element/color.json b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/element/float.json b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/element/string.json b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..18f3a211cf341fd7db82ddf7c6e8fab573c4d729 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "DevEcoStaticCheckAbility_desc", + "value": "description" + }, + { + "name": "DevEcoStaticCheckAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/background.png b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/background.png differ diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/foreground.png b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/foreground.png differ diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/layered_image.json b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/startIcon.png b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/media/startIcon.png differ diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/profile/main_pages.json b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/mock/mock-config.json5 b/StabilityCodingSpecification/DevEcoStaticCheck/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/ohosTest/ets/test/Ability.test.ets b/StabilityCodingSpecification/DevEcoStaticCheck/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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/StabilityCodingSpecification/DevEcoStaticCheck/src/ohosTest/ets/test/List.test.ets b/StabilityCodingSpecification/DevEcoStaticCheck/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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/StabilityCodingSpecification/DevEcoStaticCheck/src/ohosTest/module.json5 b/StabilityCodingSpecification/DevEcoStaticCheck/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f428861897c749812d57202bac37b2fd861cc340 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/src/ohosTest/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "DevEcoStaticCheck_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/StabilityCodingSpecification/DevEcoStaticCheck/src/test/List.test.ets b/StabilityCodingSpecification/DevEcoStaticCheck/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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/StabilityCodingSpecification/DevEcoStaticCheck/src/test/LocalUnit.test.ets b/StabilityCodingSpecification/DevEcoStaticCheck/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/StabilityCodingSpecification/DevEcoStaticCheck/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/StabilityCodingSpecification/NDKDevelopArkTS1/.gitignore b/StabilityCodingSpecification/NDKDevelopArkTS1/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/build-profile.json5 b/StabilityCodingSpecification/NDKDevelopArkTS1/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..38bdcc9929e2c5bd7f51c4fc96a398ccebd0d6ce --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/build-profile.json5 @@ -0,0 +1,39 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/hvigorfile.ts b/StabilityCodingSpecification/NDKDevelopArkTS1/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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. */ +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/obfuscation-rules.txt b/StabilityCodingSpecification/NDKDevelopArkTS1/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/oh-package-lock.json5 b/StabilityCodingSpecification/NDKDevelopArkTS1/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c8c8d64769f4712bca04df64e51eb46442cbc59 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/oh-package-lock.json5 @@ -0,0 +1,18 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "libentry.so@src/main/cpp/types/libentry": "libentry.so@src/main/cpp/types/libentry" + }, + "packages": { + "libentry.so@src/main/cpp/types/libentry": { + "name": "libentry.so", + "version": "1.0.0", + "resolved": "src/main/cpp/types/libentry", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/oh-package.json5 b/StabilityCodingSpecification/NDKDevelopArkTS1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..68c1f331660ac39b2df183576c149a3ed0348b94 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/oh-package.json5 @@ -0,0 +1,18 @@ +/** + * 最佳实践:NDK开发ArkTS侧编码规范 + */ + +// [Start NDKDevelopArkTSohPackage1] +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + // Dependent so + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} +// [End NDKDevelopArkTSohPackage1] \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CMakeLists.txt b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..612752ef9a98083662d873167ab0cb6181e1cc67 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(MyApplication14) +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + + +# 声明一个产物libentry.so,SHARED表示产物为动态库,hello.cpp为产物的源代码 +add_library(entry SHARED napi_init.cpp) + + +# 声明产物entry链接时需要的三方库libace_napi.z.so +target_link_libraries(entry PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CallbackContext.cpp b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CallbackContext.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d787ee821b405d2884787a4fc3575f9b24b9938e --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CallbackContext.cpp @@ -0,0 +1,7 @@ +// +// Created on 2025/5/21. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +#include "CallbackContext.h" diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CallbackContext.h b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CallbackContext.h new file mode 100644 index 0000000000000000000000000000000000000000..780b0e1ed370c561d675b15483e16f3ddf287441 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/CallbackContext.h @@ -0,0 +1,14 @@ +// +// Created on 2025/5/21. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +#ifndef STABILITYCODINGSPECIFICATION_CALLBACKCONTEXT_H +#define STABILITYCODINGSPECIFICATION_CALLBACKCONTEXT_H + +class CallbackContext { + +}; + +#endif //STABILITYCODINGSPECIFICATION_CALLBACKCONTEXT_H diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/Context.cpp b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/Context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b0ea3f4fa5f16ad7cadc1b43cb555c044cf5932 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/Context.cpp @@ -0,0 +1,7 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +#include "Context.h" diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/Context.h b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/Context.h new file mode 100644 index 0000000000000000000000000000000000000000..97e329aa1e14b635446667b55cf07ecff6b07ddd --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/Context.h @@ -0,0 +1,14 @@ +// +// Created on 2025/5/20. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +#ifndef STABILITYCODINGSPECIFICATION_CONTEXT_H +#define STABILITYCODINGSPECIFICATION_CONTEXT_H + +class Context { + +}; + +#endif //STABILITYCODINGSPECIFICATION_CONTEXT_H diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/napi_init.cpp b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85330e3e84d1f6c8a82e544fb315483ca597d23d --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/napi_init.cpp @@ -0,0 +1,53 @@ +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args , nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; + +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/types/libentry/index.d.ts b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..66193624c2b11942a83dfd86e7ebd433150a2900 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1,7 @@ +/** + * 最佳实践:NDK开发ArkTS侧编码规范 + */ + +// [Start NDKDevelopArkTSohPackage3] +export const add: (a: number, b: number) => number; +// [End NDKDevelopArkTSohPackage3] diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/types/libentry/oh-package.json5 b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17f2fec28b34ad5d42507c4fa15c7e4d0d16eb70 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/uv_work_t.cpp b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/uv_work_t.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae2c40268b79575c63d97b2f6c39c5f97e61428f --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/uv_work_t.cpp @@ -0,0 +1,7 @@ +// +// Created on 2025/5/21. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +#include "uv_work_t.h" diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/uv_work_t.h b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/uv_work_t.h new file mode 100644 index 0000000000000000000000000000000000000000..c2151da0d68b1fe7d6ab2752ac2387951e57f701 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/cpp/uv_work_t.h @@ -0,0 +1,14 @@ +// +// Created on 2025/5/21. +// +// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found, +// please include "napi/native_api.h". + +#ifndef STABILITYCODINGSPECIFICATION_UV_WORK_T_H +#define STABILITYCODINGSPECIFICATION_UV_WORK_T_H + +class uv_work_t { + +}; + +#endif //STABILITYCODINGSPECIFICATION_UV_WORK_T_H diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/declarations/libentry.d.ts b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/declarations/libentry.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d22270d93b88ff8bcb988cc62bc4ee6307f10988 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/declarations/libentry.d.ts @@ -0,0 +1,3 @@ +declare module 'libentry.so' { + export function add(a: number, b: number): number; +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/entryability/EntryAbility.ets b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..508880af8c33aa838016d1cd4b2c68be2f447540 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/entrybackupability/EntryBackupAbility.ets b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e4de99282050bad799ac892eb85ac5449364a51 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/pages/Index.ets b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..93bc6676e75610d105d477caa9398fb5247f741f --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/ets/pages/Index.ets @@ -0,0 +1,30 @@ +/** + * 最佳实践:NDK开发ArkTS侧编码规范 + */ + +// [Start NDKDevelopArkTSohPackage2] +import { hilog } from '@kit.PerformanceAnalysisKit'; +// import rely on so +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + // call native + hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3)); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End NDKDevelopArkTSohPackage2] \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/module.json5 b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3d0544ec34a55bcb270afacc8b4c0b06a825303a --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/module.json5 @@ -0,0 +1,52 @@ +{ + "module": { + "name": "NDKDevelopArkTS1", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "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": [ + "action.system.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/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/element/color.json b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/element/float.json b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/element/string.json b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/background.png b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/background.png differ diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/foreground.png b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/foreground.png differ diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/layered_image.json b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/startIcon.png b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/media/startIcon.png differ diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/profile/backup_config.json b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/profile/main_pages.json b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/dark/element/color.json b/StabilityCodingSpecification/NDKDevelopArkTS1/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/mock/mock-config.json5 b/StabilityCodingSpecification/NDKDevelopArkTS1/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/ohosTest/ets/test/Ability.test.ets b/StabilityCodingSpecification/NDKDevelopArkTS1/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/ohosTest/ets/test/List.test.ets b/StabilityCodingSpecification/NDKDevelopArkTS1/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/ohosTest/module.json5 b/StabilityCodingSpecification/NDKDevelopArkTS1/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b8006be8338bf519190cfc373e80924d298c5dc3 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/src/ohosTest/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "NDKDevelopArkTS1_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS1/src/test/List.test.ets b/StabilityCodingSpecification/NDKDevelopArkTS1/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS1/src/test/LocalUnit.test.ets b/StabilityCodingSpecification/NDKDevelopArkTS1/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS1/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/StabilityCodingSpecification/NDKDevelopArkTS2/.gitignore b/StabilityCodingSpecification/NDKDevelopArkTS2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/build-profile.json5 b/StabilityCodingSpecification/NDKDevelopArkTS2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..38bdcc9929e2c5bd7f51c4fc96a398ccebd0d6ce --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/build-profile.json5 @@ -0,0 +1,39 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/hvigorfile.ts b/StabilityCodingSpecification/NDKDevelopArkTS2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/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. */ +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/obfuscation-rules.txt b/StabilityCodingSpecification/NDKDevelopArkTS2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/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/StabilityCodingSpecification/NDKDevelopArkTS2/oh-package-lock.json5 b/StabilityCodingSpecification/NDKDevelopArkTS2/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..df46c01501a4a9db286f4847c96203dd1418883c --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/oh-package-lock.json5 @@ -0,0 +1,28 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "liblibrary.so@../library/src/main/cpp/types/liblibrary": "liblibrary.so@../library/src/main/cpp/types/liblibrary", + "library@../library": "library@../library" + }, + "packages": { + "liblibrary.so@../library/src/main/cpp/types/liblibrary": { + "name": "liblibrary.so", + "version": "1.0.0", + "resolved": "../library/src/main/cpp/types/liblibrary", + "registryType": "local" + }, + "library@../library": { + "name": "library", + "version": "1.0.0", + "resolved": "../library", + "registryType": "local", + "dependencies": { + "liblibrary.so": "file:./src/main/cpp/types/liblibrary" + } + } + } +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/oh-package.json5 b/StabilityCodingSpecification/NDKDevelopArkTS2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f5748ea18844624f143868cebdabb32c9ced83a2 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/oh-package.json5 @@ -0,0 +1,18 @@ +/** + * 最佳实践:NDK开发ArkTS侧编码规范 + */ + +// [Start NDKDevelopArkTSohPackage4] +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + // Dependent on other modules under the current project + "library": "file:../library" + } +} +// [End NDKDevelopArkTSohPackage4] \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/CMakeLists.txt b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..612752ef9a98083662d873167ab0cb6181e1cc67 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(MyApplication14) +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + + +# 声明一个产物libentry.so,SHARED表示产物为动态库,hello.cpp为产物的源代码 +add_library(entry SHARED napi_init.cpp) + + +# 声明产物entry链接时需要的三方库libace_napi.z.so +target_link_libraries(entry PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/napi_init.cpp b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c8d6f32f7c16a449b16d3e323181217b5a59072b --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/napi_init.cpp @@ -0,0 +1,53 @@ +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args , nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; + +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry2", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntry2Module(void) +{ + napi_module_register(&demoModule); +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/types/libentry/index.d.ts b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e44f3615a4767c36b4fdc841b781af96bf1971a8 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1 @@ +export const add: (a: number, b: number) => number; \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/types/libentry/oh-package.json5 b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17f2fec28b34ad5d42507c4fa15c7e4d0d16eb70 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/declarations/liblibrary.d.ts b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/declarations/liblibrary.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e0e0705504da075a2912ece9c5d04efdc7d864d9 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/declarations/liblibrary.d.ts @@ -0,0 +1,7 @@ +// src/main/ets/declarations/liblibrary.d.ts +declare module 'liblibrary.so' { + const testNapi: { + add(a: number, b: number): number; + }; + export default testNapi; +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/declarations/library.d.ts b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/declarations/library.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..41656d5b24b2e46fddf423d8b69b21364ae4179a --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/declarations/library.d.ts @@ -0,0 +1,5 @@ +declare module 'library' { + export const testNapi: { + add(a: number, b: number): number; + }; +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/entry2ability/Entry2Ability.ets b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..de312bfa6b61bf04aaa0c4f697932e1032ae6ec2 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/entry2ability/Entry2Ability.ets @@ -0,0 +1,43 @@ +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class Entry2Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + 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'); + } +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/pages/Index.ets b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1c44d6fa7aaec1d40900ef7a6da0178555675595 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/** + * 最佳实践:NDK开发ArkTS侧编码规范 + */ + +// [Start NDKDevelopArkTSohPackage5] +import { hilog } from '@kit.PerformanceAnalysisKit'; +// import rely on so +import { testNapi } from 'library'; + + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + // call native + hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(1, 2)); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End NDKDevelopArkTSohPackage5] + diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/pages/Index2.ets b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/pages/Index2.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a9c615d8ad36a6a9f8df3d871b4e8c8c1f94ec1 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/ets/pages/Index2.ets @@ -0,0 +1,8 @@ +/** + * 最佳实践:NDK开发ArkTS侧编码规范 + */ + +// [Start NDKDevelopArkTSohPackage6] +import testNapi from 'liblibrary.so'; +export {testNapi} +// [End NDKDevelopArkTSohPackage6] \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/module.json5 b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1ecc8be4c8d4a30d56ba080f61a097901c33dad5 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/module.json5 @@ -0,0 +1,28 @@ +{ + "module": { + "name": "NDKDevelopArkTS2", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/element/color.json b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/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/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/element/float.json b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/element/string.json b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b5d6bb35a6a060543c4f14bd39037a5a5041599e --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry2Ability_desc", + "value": "description" + }, + { + "name": "Entry2Ability_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/background.png b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/background.png differ diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/foreground.png b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/foreground.png differ diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/layered_image.json b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/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/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/startIcon.png b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/media/startIcon.png differ diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/profile/main_pages.json b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/mock/mock-config.json5 b/StabilityCodingSpecification/NDKDevelopArkTS2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/ohosTest/ets/test/Ability.test.ets b/StabilityCodingSpecification/NDKDevelopArkTS2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/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/StabilityCodingSpecification/NDKDevelopArkTS2/src/ohosTest/ets/test/List.test.ets b/StabilityCodingSpecification/NDKDevelopArkTS2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/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/StabilityCodingSpecification/NDKDevelopArkTS2/src/ohosTest/module.json5 b/StabilityCodingSpecification/NDKDevelopArkTS2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2968fd2b7d0246cef7321dae2d4947da69bcd713 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/src/ohosTest/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "NDKDevelopArkTS2_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/StabilityCodingSpecification/NDKDevelopArkTS2/src/test/List.test.ets b/StabilityCodingSpecification/NDKDevelopArkTS2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/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/StabilityCodingSpecification/NDKDevelopArkTS2/src/test/LocalUnit.test.ets b/StabilityCodingSpecification/NDKDevelopArkTS2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/StabilityCodingSpecification/NDKDevelopArkTS2/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/StabilityCodingSpecification/build-profile.json5 b/StabilityCodingSpecification/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3c415c405388eece3421d52f05121e458b6b1385 --- /dev/null +++ b/StabilityCodingSpecification/build-profile.json5 @@ -0,0 +1,66 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.0.5(17)", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "NDKDevelopArkTS1", + "srcPath": "./NDKDevelopArkTS1", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "NDKDevelopArkTS2", + "srcPath": "./NDKDevelopArkTS2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "DevEcoStaticCheck", + "srcPath": "./DevEcoStaticCheck", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/StabilityCodingSpecification/code-linter.json5 b/StabilityCodingSpecification/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/StabilityCodingSpecification/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/StabilityCodingSpecification/code-linter1.json5 b/StabilityCodingSpecification/code-linter1.json5 new file mode 100644 index 0000000000000000000000000000000000000000..49b14df202ffc5bf8a6976fd65b7c894e087fefc --- /dev/null +++ b/StabilityCodingSpecification/code-linter1.json5 @@ -0,0 +1,58 @@ +/** + * 最佳实践:使用DevEco Studio静态检测编码规范 + */ + +// [Start codeLinterJson1] +{ + "files": //A glob pattern array used to represent the file range applicable to the configuration. Apply default configuration without specification + [ + "**/*.js", //STRING + "**/*.ts" + ], + "ignore": //A glob pattern array representing files that the configuration object should not be applicable to. If not specified, the configuration object will apply to all files matched by files + [ + "build/**/*", //STRING + "node_modules/**/*" + ], + "ruleSet": //Set the rule set for checking to be applied + [ + "plugin:@typescript-eslint/recommended" //Quick batch import rule set, enumeration type:plugin:@typescript-eslint/all, plugin:@typescript-eslint/recommended, plugin:@cross-device-app-dev/all, plugin:@cross-device-app-dev/recommended等 + ], + "rules": //Specific rules in the rule set configured by ruleSet can be modified, disabled, or added outside of the rule set; RuleSet and rules jointly determine the rules applied for code checking + { + "@typescript-eslint/no-explicit-any": // When ruleId is followed by an array, the first element is the alarm level, and the following object elements are rule specific switch configurations + [ + "error", //Alarm level: enumeration type, supports configuration as suggestion, error, warn, off + { + "ignoreRestArgs": true //Specific switch configurations for rules are optional, and different rules have different configuration items at the lower level + } + ], + "@typescript-eslint/explicit-function-return-type": 2, // When ruleId is followed by a single number, it indicates that only the alarm level is set. The enumeration values are: 3 (suggestion), 2 (error), 1 (warn), 0 (off) + "@typescript-eslint/no-unsafe-return": "warn" // When ruleId is followed by a separate string, it indicates that only the alarm level is set, and the enumeration values are: suggestion, error, warn, off + }, + "overrides": //Customize rule configuration for specific directories or files + [ + { + "files": //Specify the files or directories that require customized configuration rules + [ + "entry/**/*.ts" //STRING + ], + "excluded": + [ + "entry/**/*.test.js" //Specify the directories or files that need to be excluded, and the excluded directories or files will not be checked according to customized rule configurations; STRING + ], + "rules": //Support modifying, disabling, or adding rules for public configurations outside of overlaps; This configuration will override the public configuration + { + "@typescript-eslint/explicit-function-return-type": // ruleId: Enumeration type + [ + "warn", //Alarm level: enumeration type, supports configuration as error, warn, off; Covering public configuration, explicit function return type alarm level is warm + { + allowExpressions: true //Specific switch configurations for rules are optional, and different rules have different configuration items at the lower level + } + ], + "@typescript-eslint/no-unsafe-return": "off" // Covering public configurations without checking the no unsafe return rule + } + } + ] +} +// [End codeLinterJson1] \ No newline at end of file diff --git a/StabilityCodingSpecification/code-linter2.json5 b/StabilityCodingSpecification/code-linter2.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7e8bf05ebeebdec43ef6bc433679c727e75d2187 --- /dev/null +++ b/StabilityCodingSpecification/code-linter2.json5 @@ -0,0 +1,23 @@ +/** + * 最佳实践:使用DevEco Studio静态检测编码规范 + */ + +// [Start codeLinterJson2] +{ + "rules": { + "@typescript-eslint/no-restricted-syntax": [ + // Alarm level: Enumeration type, supports configuration as error, warn, off + "error", + { + // The selector attribute is mandatory. Configure the syntax to be disabled + // The statements to be restricted can be filtered through a specific DSL. The CallExpression represents the method call expression, and the square brackets behind it are the filtering conditions (determined according to the Node of the syntax tree). + // Among them, callee.oobject.name filters the objects (class, namespace, or module) that call the method based on the specified name, which is "Foo" in the above example + // Callee-propey.name filters the called methods based on the specified name, which is "bar" in the above example + "selector": "CallExpression[callee.object.name='Foo'][callee.property.name='bar']", + // The message attribute is optional, configure the error message to be displayed + "message": "Foo.bar() is not allowed" + } + ] + }, +} +// [End codeLinterJson2] \ No newline at end of file diff --git a/StabilityCodingSpecification/code-linter3.json5 b/StabilityCodingSpecification/code-linter3.json5 new file mode 100644 index 0000000000000000000000000000000000000000..230a7d7a0839ba42345456e36b32fb7af22e2b4d --- /dev/null +++ b/StabilityCodingSpecification/code-linter3.json5 @@ -0,0 +1,26 @@ +/** + * 最佳实践:使用DevEco Studio静态检测编码规范 + */ + +// [Start codeLinterJson3] +{ + "rules": { + "@typescript-eslint/naming-convention": [ + "error", + { + // The selector attribute is required, configure the syntax to be checked, and the class configured here represents checking custom component names + "selector": "class", + // The format attribute is required, configure the expected naming style, support enumeration values, and the PascalCase configured here represents the camel hump style + "format": ["PascalCase"], + // Optional custom attribute, configure user-defined naming style + "custom": { + // Regux attribute is required, configure specific regularization + "regex": "^[a-zA-Z]+$", + // The match attribute is mandatory, configured as true to indicate an error when a regular miss occurs; Set to false to indicate a regular hit report error + "match": true + } + } + ] + }, +} +// [End codeLinterJson3] \ No newline at end of file diff --git a/StabilityCodingSpecification/code-linter4.json5 b/StabilityCodingSpecification/code-linter4.json5 new file mode 100644 index 0000000000000000000000000000000000000000..37e1f210a6ade83d1052214321f02f8d4ec984b2 --- /dev/null +++ b/StabilityCodingSpecification/code-linter4.json5 @@ -0,0 +1,20 @@ +/** + * 最佳实践:使用DevEco Studio静态检测编码规范 + */ + +// [Start codeLinterJson4] +{ + "rules": { + "@hw-stylistic/file-naming-convention": [ + // Alarm level: enumeration type, supports configuration as error, warn, off + "error", + { + // The selector property is optional and can be configured as code or resources + // code表示检查代码文件的命名风格 + // Code represents checking the naming style of code files + "selector": "code" + } + ] + }, +} +// [End codeLinterJson4] \ No newline at end of file diff --git a/StabilityCodingSpecification/hvigor/hvigor-config.json5 b/StabilityCodingSpecification/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5bebc9755447385d82ce4138f54d991b1f85f348 --- /dev/null +++ b/StabilityCodingSpecification/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.5", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/StabilityCodingSpecification/hvigorfile.ts b/StabilityCodingSpecification/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/StabilityCodingSpecification/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. */ +} diff --git a/StabilityCodingSpecification/log.txt b/StabilityCodingSpecification/log.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec9ca34963a9a03736b66baa6c4f1dabb47cf5f2 --- /dev/null +++ b/StabilityCodingSpecification/log.txt @@ -0,0 +1,31 @@ +18:34:34:924 log timer task size: 1 +18:43:49:590 log task queue not empty +18:43:49:591 log task size: 1 +18:43:49:591 log before pop task size: 1 +18:43:49:592 log after task size: 0 +18:43:50:104 log timer task size: 1 +18:43:52:020 log task queue not empty +18:43:52:021 log task size: 1 +18:43:52:021 log before pop task size: 1 +18:43:52:021 log after task size: 0 +18:43:52:524 log timer task size: 1 +18:43:52:695 log task queue not empty +18:43:52:696 log task size: 1 +18:43:52:697 log before pop task size: 1 +18:43:52:698 log after task size: 0 +18:43:53:205 log timer task size: 1 +18:43:55:738 log task queue not empty +18:43:55:739 log task size: 1 +18:43:55:739 log before pop task size: 1 +18:43:55:739 log after task size: 0 +18:43:56:252 log timer task size: 1 +18:43:56:869 log task queue not empty +18:43:56:870 log task size: 1 +18:43:56:871 log before pop task size: 1 +18:43:56:871 log after task size: 0 +18:43:57:383 log timer task size: 1 +18:43:58:151 log task queue not empty +18:43:58:152 log task size: 1 +18:43:58:152 log before pop task size: 1 +18:43:58:153 log after task size: 0 +18:43:58:662 log timer task size: 1 diff --git a/StabilityCodingSpecification/oh-package-lock.json5 b/StabilityCodingSpecification/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c6f99f5c73b06c5fdef7ec6f491b74b7befebe2e --- /dev/null +++ b/StabilityCodingSpecification/oh-package-lock.json5 @@ -0,0 +1,27 @@ +{ + "meta": { + "stableOrder": true + }, + "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 diff --git a/StabilityCodingSpecification/oh-package.json5 b/StabilityCodingSpecification/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a8aff0c5aff22d78aa26fd19c3861f4320e951ff --- /dev/null +++ b/StabilityCodingSpecification/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.0.5", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +}