diff --git a/OAT.xml b/OAT.xml index 1a67ebc2da5f0708956df8d1dd45227f848fd947..8326276bf82952c31f6e6e807136ee4664a0a026 100644 --- a/OAT.xml +++ b/OAT.xml @@ -57,6 +57,37 @@ Note:If the text contains special characters, please escape them according to th + + + + + + + + @@ -119,6 +153,10 @@ Note:If the text contains special characters, please escape them according to th + + + + @@ -2083,6 +2121,11 @@ Note:If the text contains special characters, please escape them according to th + + + + + @@ -2180,6 +2223,11 @@ Note:If the text contains special characters, please escape them according to th + + + + + diff --git a/code/ArkTS1.2/ANISample/.gitignore b/code/ArkTS1.2/ANISample/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/ArkTS1.2/ANISample/.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/code/ArkTS1.2/ANISample/AppScope/app.json5 b/code/ArkTS1.2/ANISample/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bb88803bcb9f23bfdcd6c122a26ebe1206723306 --- /dev/null +++ b/code/ArkTS1.2/ANISample/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.aniTest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/ArkTS1.2/ANISample/AppScope/resources/base/element/string.json b/code/ArkTS1.2/ANISample/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..37c0a94520cf0ccf7baddb6e00b1c38d3c4e95c7 --- /dev/null +++ b/code/ArkTS1.2/ANISample/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ANITest" + } + ] +} diff --git a/code/ArkTS1.2/ANISample/AppScope/resources/base/media/app_icon.png b/code/ArkTS1.2/ANISample/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/ArkTS1.2/ANISample/AppScope/resources/base/media/app_icon.png differ diff --git a/code/ArkTS1.2/ANISample/build-profile.json5 b/code/ArkTS1.2/ANISample/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6a325164e4f9f873bcb884a635ef0e36a15a06cc --- /dev/null +++ b/code/ArkTS1.2/ANISample/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + "arkTSVersion": "1.2", + "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/code/ArkTS1.2/ANISample/code-linter.json5 b/code/ArkTS1.2/ANISample/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/entry/.gitignore b/code/ArkTS1.2/ANISample/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/build-profile.json5 b/code/ArkTS1.2/ANISample/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8ac81840b69fd7c78c2024c6570ed01e4292cf6d --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/build-profile.json5 @@ -0,0 +1,29 @@ +{ + "apiType": "stageMode", + "arkTSVersion": "1.2", + "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/code/ArkTS1.2/ANISample/entry/hvigorfile.ts b/code/ArkTS1.2/ANISample/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/entry/obfuscation-rules.txt b/code/ArkTS1.2/ANISample/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/entry/oh-package.json5 b/code/ArkTS1.2/ANISample/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..248c3b7541a589682a250f86a6d3ecf7414d2d6a --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/entry/src/main/cpp/CMakeLists.txt b/code/ArkTS1.2/ANISample/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..15486e20fdbd53bc8238e9932234409392fac3b4 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(MyApplication) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +set(CMAKE_CXX_STANDARD 17) +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) +add_library(entry SHARED ani_init.cpp) +target_link_libraries(entry PUBLIC libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_accessing_fields.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_accessing_fields.cpp new file mode 100644 index 0000000000000000000000000000000000000000..794f49807d56eadb622e0d812d2d767d18b37aee --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_accessing_fields.cpp @@ -0,0 +1,485 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ani/ani.h" +#include "hilog/log.h" +#include + +#define CHAR_A 'A' +#define CHAR_B 'B' +#define CHAR_G 'G' +#define CHAR_U 'U' +#define CHAR_Z 'Z' +#define NUM15 15 +#define NUM2 2 +#define NUM120 120 +#define NUM255 255 +#define NUM65538 65538 +#define NUM12345678910 12345678910 +#define NUM3_12 3.12 +#define NUM3_14 3.14 +#define NUM4_56 4.56 +#define NUM15_23 15.23 +#define NUM15_2365941 15.2365941 +#define NUM12365478941 12365478941 + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域 +#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag + +// Accessing Fields of Objects Class Operations +static void UpdateFields(ani_env *env, ani_object obj) +{ + std::cout << "Update Field in native" << std::endl; + const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_field boolField; + if (ANI_OK != env->Class_FindField(cls, "boolField", &boolField)) { + std::cerr << "Get Field Fail" << className << "'" << std::endl; + return; + } + ani_field doubleField; + if (ANI_OK != env->Class_FindField(cls, "doubleField", &doubleField)) { + std::cerr << "Get Field Fail" << className << "'" << std::endl; + return; + } + ani_field floatField; + if (ANI_OK != env->Class_FindField(cls, "floatField", &floatField)) { + std::cerr << "Get Field Fail" << className << "'" << std::endl; + return; + } + ani_field charField; + if (ANI_OK != env->Class_FindField(cls, "charField", &charField)) { + std::cerr << "Get Field Fail" << className << "'" << std::endl; + return; + } + ani_boolean boolValue = ANI_TRUE; + if (ANI_OK != env->Object_SetField_Boolean(obj, boolField, boolValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_double doubleValue = NUM3_14; + if (ANI_OK != env->Object_SetField_Double(obj, doubleField, doubleValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_float floatValue = NUM4_56; + if (ANI_OK != env->Object_SetField_Float(obj, floatField, floatValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_char charValue = CHAR_Z; + if (ANI_OK != env->Object_SetField_Char(obj, charField, charValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + return; +} + +static void UpdateFields2(ani_env *env, ani_object obj) +{ + std::cout << "Update Field in native" << std::endl; + const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_field intField; + if (ANI_OK != env->Class_FindField(cls, "intField", &intField)) { + std::cerr << "Get Field Fail" << className << "'" << std::endl; + return; + } + ani_field shortField; + if (ANI_OK != env->Class_FindField(cls, "shortField", &shortField)) { + std::cerr << "Get Field Fail" << className << "'" << std::endl; + return; + } + ani_field longField; + if (ANI_OK != env->Class_FindField(cls, "longField", &longField)) { + std::cerr << "Get Field Fail" << className << "'" << std::endl; + return; + } + ani_field byteField; + if (ANI_OK != env->Class_FindField(cls, "byteField", &byteField)) { + std::cerr << "Get Field Fail" << className << "'" << std::endl; + return; + } + ani_int intValue = NUM15; + if (ANI_OK != env->Object_SetField_Int(obj, intField, intValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_short shortValue = NUM255; + if (ANI_OK != env->Object_SetField_Short(obj, shortField, shortValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_long longValue = NUM12345678910; + if (ANI_OK != env->Object_SetField_Long(obj, longField, longValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_byte byteValue = CHAR_A; + if (ANI_OK != env->Object_SetField_Byte(obj, byteField, byteValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } +} + +static ani_int UpdateIntFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_int intField; + if (ANI_OK != env->Object_GetFieldByName_Int(obj, "getIntField", &intField)) { + std::cerr << "Get Field Fail" << std::endl; + return 0; + } + return intField; +} + +static ani_double UpdateDoubleFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_double doubleField; + if (ANI_OK != env->Object_GetFieldByName_Double(obj, "getDoubleField", &doubleField)) { + std::cerr << "Get Field Fail" << std::endl; + return 0.0; + } + return doubleField; +} + +static ani_boolean UpdateBoolFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_boolean boolField; + if (ANI_OK != env->Object_GetFieldByName_Boolean(obj, "getBoolField", &boolField)) { + std::cerr << "Get Field Fail" << std::endl; + return false; + } + return boolField; +} + +static ani_short UpdateShortFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_short shortField; + if (ANI_OK != env->Object_GetFieldByName_Short(obj, "getShortField", &shortField)) { + std::cerr << "Get Field Fail" << std::endl; + return 0; + } + return shortField; +} + +static ani_long UpdateLongFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_long longField; + if (ANI_OK != env->Object_GetFieldByName_Long(obj, "getLongField", &longField)) { + std::cerr << "Get Field Fail" << std::endl; + return 0; + } + return longField; +} + +static ani_char UpdateCharFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_char charField; + if (ANI_OK != env->Object_GetFieldByName_Char(obj, "getCharField", &charField)) { + std::cerr << "Get Field Fail" << std::endl; + return 0; + } + return charField; +} + +static ani_float UpdateFloatFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_float floatField; + if (ANI_OK != env->Object_GetFieldByName_Float(obj, "getFloatField", &floatField)) { + std::cerr << "Get Field Fail" << std::endl; + return 0.0; + } + return floatField; +} + +static ani_byte UpdateByteFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_byte byteField; + if (ANI_OK != env->Object_GetFieldByName_Byte(obj, "getByteField", &byteField)) { + std::cerr << "Get Field Fail" << std::endl; + return 0x0; + } + return byteField; +} + +static void UpdateByNameFields(ani_env *env, ani_object obj) +{ + std::cout << "Update Field in native" << std::endl; + const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_byte byteValue = CHAR_B; + if (ANI_OK != env->Object_SetFieldByName_Byte(obj, "fieldByName_Byte", byteValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_double doubleValue = NUM4_56; + if (ANI_OK != env->Object_SetFieldByName_Double(obj, "fieldByName_Double", doubleValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_short shortValue = NUM255; + if (ANI_OK != env->Object_SetFieldByName_Short(obj, "fieldByName_Short", shortValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_boolean boolValue = true; + if (ANI_OK != env->Object_SetFieldByName_Boolean(obj, "fieldByName_Bool", boolValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + return; +} + +static void UpdateByNameFields2(ani_env *env, ani_object obj) +{ + std::cout << "Update Field in native" << std::endl; + const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_float floatValue = NUM15_23; + if (ANI_OK != env->Object_SetFieldByName_Float(obj, "fieldByName_Float", floatValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_long longValue = NUM12365478941; + if (ANI_OK != env->Object_SetFieldByName_Long(obj, "fieldByName_Long", longValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_char charValue = CHAR_G; + if (ANI_OK != env->Object_SetFieldByName_Char(obj, "fieldByName_Char", charValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + ani_int intValue = NUM120; + if (ANI_OK != env->Object_SetFieldByName_Int(obj, "fieldByName_Int", intValue)) { + std::cerr << "Set Field Fail" << className << "'" << std::endl; + } + return; +} + +// Accessing Static Fields Class Operations +static void UpdateStaticFields(ani_env *env, ani_object obj) +{ + std::cout << "Update Field in native" << std::endl; + const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_static_field intField; + if (ANI_OK != env->Class_FindStaticField(cls, "intStaticField", &intField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field shortField; + if (ANI_OK != env->Class_FindStaticField(cls, "shortStaticField", &shortField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field longField; + if (ANI_OK != env->Class_FindStaticField(cls, "longStaticField", &longField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field charField; + if (ANI_OK != env->Class_FindStaticField(cls, "charStaticField", &charField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_int intValue = NUM65538; + if (ANI_OK != env->Class_SetStaticField_Int(cls, intField, intValue)) { + std::cerr << "Set StaticField Fail" << className << "'" << std::endl; + } + ani_short shortValue = NUM2; + if (ANI_OK != env->Class_SetStaticField_Short(cls, shortField, shortValue)) { + std::cerr << "Set StaticField Fail" << className << "'" << std::endl; + } + ani_long longValue = NUM12345678910; + if (ANI_OK != env->Class_SetStaticField_Long(cls, longField, longValue)) { + std::cerr << "Set StaticField Fail" << className << "'" << std::endl; + } + ani_char charValue = CHAR_U; + if (ANI_OK != env->Class_SetStaticField_Char(cls, charField, charValue)) { + std::cerr << "Set StaticField Fail" << className << "'" << std::endl; + } + return; +} + +static void UpdateStaticFields2(ani_env *env, ani_object obj) +{ + std::cout << "Update Field in native" << std::endl; + const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_static_field doubleField; + if (ANI_OK != env->Class_FindStaticField(cls, "doubleStaticField", &doubleField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field floatField; + if (ANI_OK != env->Class_FindStaticField(cls, "floatStaticField", &floatField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field boolField; + if (ANI_OK != env->Class_FindStaticField(cls, "boolStaticField", &boolField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field byteField; + if (ANI_OK != env->Class_FindStaticField(cls, "byteStaticField", &byteField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_double doubleValue = NUM15_2365941; + if (ANI_OK != env->Class_SetStaticField_Double(cls, doubleField, doubleValue)) { + std::cerr << "Set StaticField Fail" << className << "'" << std::endl; + } + ani_float floatValue = NUM3_12; + if (ANI_OK != env->Class_SetStaticField_Float(cls, floatField, floatValue)) { + std::cerr << "Set StaticField Fail" << className << "'" << std::endl; + } + ani_boolean boolValue = true; + if (ANI_OK != env->Class_SetStaticField_Boolean(cls, boolField, boolValue)) { + std::cerr << "Set StaticField Fail" << className << "'" << std::endl; + } + ani_byte byteValue = CHAR_U; + if (ANI_OK != env->Class_SetStaticField_Byte(cls, byteField, byteValue)) { + std::cerr << "Set StaticField Fail" << className << "'" << std::endl; + } + return; +} + +static void GetStaticFields(ani_env *env, ani_object obj) +{ + std::cout << "Get Field in native" << std::endl; + const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_static_field intField; + if (ANI_OK != env->Class_FindStaticField(cls, "intStaticField", &intField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field shortField; + if (ANI_OK != env->Class_FindStaticField(cls, "shortStaticField", &shortField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field longField; + if (ANI_OK != env->Class_FindStaticField(cls, "longStaticField", &longField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field charField; + if (ANI_OK != env->Class_FindStaticField(cls, "charStaticField", &charField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_int intValue; + if (ANI_OK != env->Class_GetStaticField_Int(cls, intField, &intValue)) { + std::cerr << "Set StaticField Fail " << className << "'" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Int result: %{public}d", intValue); + ani_short shortValue; + if (ANI_OK != env->Class_GetStaticField_Short(cls, shortField, &shortValue)) { + std::cerr << "Set StaticField Fail " << className << "'" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Short result: %{public}h", shortValue); + ani_long longValue; + if (ANI_OK != env->Class_GetStaticField_Long(cls, longField, &longValue)) { + std::cerr << "Set StaticField Fail " << className << "'" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Long result: %{public}l", longValue); + ani_char charValue; + if (ANI_OK != env->Class_GetStaticField_Char(cls, charField, &charValue)) { + std::cerr << "Set StaticField Fail " << className << "'" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Char result: %{public}c", charValue); + return; +} + +static void GetStaticFields2(ani_env *env, ani_object obj) +{ + std::cout << "Get Field in native" << std::endl; + const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_static_field byteField; + if (ANI_OK != env->Class_FindStaticField(cls, "byteStaticField", &byteField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field doubleField; + if (ANI_OK != env->Class_FindStaticField(cls, "doubleStaticField", &doubleField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field floatField; + if (ANI_OK != env->Class_FindStaticField(cls, "floatStaticField", &floatField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_static_field boolField; + if (ANI_OK != env->Class_FindStaticField(cls, "boolStaticField", &boolField)) { + std::cerr << "Get StaticField Fail" << className << "'" << std::endl; + return; + } + ani_byte byteValue; + if (ANI_OK != env->Class_GetStaticField_Byte(cls, byteField, &byteValue)) { + std::cerr << "Set StaticField Fail " << className << "'" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Byte result: %{public}c", byteValue); + ani_double doubleValue; + if (ANI_OK != env->Class_GetStaticField_Double(cls, doubleField, &doubleValue)) { + std::cerr << "Set StaticField Fail " << className << "'" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Double result: %{public}lf", doubleValue); + ani_boolean boolValue; + if (ANI_OK != env->Class_GetStaticField_Boolean(cls, boolField, &boolValue)) { + std::cerr << "Set StaticField Fail " << className << "'" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Boolean result: %{public}d", static_cast(boolValue)); + ani_float floatValue; + if (ANI_OK != env->Class_GetStaticField_Float(cls, floatField, &floatValue)) { + std::cerr << "Set StaticField Fail " << className << "'" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Boolean result: %{public}f", floatValue); + return; +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_array.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_array.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ebd2e63d52917a91170d97630db2d721b359a68b --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_array.cpp @@ -0,0 +1,121 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ani/ani.h" +#include "hilog/log.h" +#include + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域 +#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag +// Array Operations +static void ProcessArray(ani_env *env, ani_object object, ani_array_double doubleArray) +{ + ani_size length; + if (ANI_OK != env->Array_GetLength(doubleArray, &length)) { + std::cerr << "Array_GetLength FAILED" << std::endl; + return; + } + OH_LOG_ERROR(LOG_APP, "testTag Array_GetLength result: %{public}d", length); + ani_array_double doubleValue; + if (ANI_OK != env->Array_New_Double(length, &doubleValue)) { + std::cerr << "Array_New_Double FAILED" << std::endl; + return; + } + for (ani_int i = 0; i < length; ++i) { + OH_LOG_ERROR(LOG_APP, "testTag Array_New_Double result: %{public}f", doubleValue[i]); + } + + ani_array_int intValue; + if (ANI_OK != env->Array_New_Int(length, &intValue)) { + std::cerr << "Array_New_Int FAILED" << std::endl; + return; + } + for (ani_int i = 0; i < length; ++i) { + OH_LOG_ERROR(LOG_APP, "testTag Array_New_Int result: %{public}d", intValue[i]); + } + + ani_array_short shortValue; + if (ANI_OK != env->Array_New_Short(length, &shortValue)) { + std::cerr << "Array_New_Short FAILED" << std::endl; + return; + } + for (ani_int i = 0; i < length; ++i) { + OH_LOG_ERROR(LOG_APP, "testTag Array_New_Short result: %{public}d", shortValue[i]); + } + + ani_array_char charValue; + if (ANI_OK != env->Array_New_Char(length, &charValue)) { + std::cerr << "Array_New_Char FAILED" << std::endl; + return; + } + std::cout << "Array int Content:" << doubleArray << std::endl; +} + +static void ProcessArray2(ani_env *env, ani_object object, ani_array_double doubleArray) +{ + ani_size length; + if (ANI_OK != env->Array_GetLength(doubleArray, &length)) { + std::cerr << "Array_GetLength FAILED" << std::endl; + return; + } + ani_array_char charValue; + if (ANI_OK != env->Array_New_Char(length, &charValue)) { + std::cerr << "Array_New_Char FAILED" << std::endl; + return; + } + for (ani_int i = 0; i < length; ++i) { + OH_LOG_ERROR(LOG_APP, "testTag Array_New_Char result: %{public}c", charValue[i]); + } + + ani_array_boolean boolValue; + if (ANI_OK != env->Array_New_Boolean(length, &boolValue)) { + std::cerr << "Array_New_Boolean FAILED" << std::endl; + return; + } + for (ani_int i = 0; i < length; ++i) { + OH_LOG_ERROR(LOG_APP, "testTag Array_New_Boolean result: %{public}d", boolValue[i]); + } + + ani_array_long longValue; + if (ANI_OK != env->Array_New_Long(length, &longValue)) { + std::cerr << "Array_New_Long FAILED" << std::endl; + return; + } + for (ani_int i = 0; i < length; ++i) { + OH_LOG_ERROR(LOG_APP, "testTag Array_New_Long result: %{public}ld", longValue[i]); + } + + ani_array_float floatValue; + if (ANI_OK != env->Array_New_Float(length, &floatValue)) { + std::cerr << "Array_New_Float FAILED" << std::endl; + return; + } + for (ani_int i = 0; i < length; ++i) { + OH_LOG_ERROR(LOG_APP, "testTag Array_New_Float result: %{public}f", floatValue[i]); + } + std::cout << "Array int Content:" << doubleArray << std::endl; +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_calling_methods.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_calling_methods.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bdbff7eec3a405acfd3fd7890f53891e5dc27733 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_calling_methods.cpp @@ -0,0 +1,335 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ani/ani.h" +#include + +// Calling Instance Methods +static void NativeVoidFunc(ani_env *env, ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedVoidFunc", ":V", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return; + } + std::cout << "Print in Native Func" << std::endl; + if (ANI_OK != env->Object_CallMethod_Void(obj, managedMethod)) { + std::cerr << "Object_CallMethod_Void Fail" << std::endl; + return; + } +} + +static ani_boolean NativeBoolFunc(ani_env *env, ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return false; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedBoolFunc", ":Z", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return false; + } + std::cout << "Print in Native Func" << std::endl; + ani_boolean boolValue; + if (ANI_OK != env->Object_CallMethod_Boolean(obj, managedMethod, &boolValue)) { + std::cerr << "Object_CallMethod_Boolean Fail" << std::endl; + return false; + } + return boolValue; +} + +static ani_int NativeIntFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return 0; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedIntFunc", ":I", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return 0; + } + std::cout << "Print in Native Func" << std::endl; + ani_int intValue; + if (ANI_OK != env->Object_CallMethod_Int(obj, managedMethod, &intValue)) { + std::cerr << "Object_CallMethod_Int Fail" << std::endl; + return 0; + } + return intValue; +} + + +static ani_short NativeShortFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return 0; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedShortFunc", ":S", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return 0; + } + std::cout << "Print in Native Func" << std::endl; + ani_short shortValue; + if (ANI_OK != env->Object_CallMethod_Short(obj, managedMethod, &shortValue)) { + std::cerr << "Object_CallMethod_Short Fail" << std::endl; + return 0; + } + return shortValue; +} + +static ani_long NativeLongFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return 0; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedLongFunc", ":J", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return 0; + } + std::cout << "Print in Native Func" << std::endl; + ani_long longValue; + if (ANI_OK != env->Object_CallMethod_Long(obj, managedMethod, &longValue)) { + std::cerr << "Object_CallMethod_Long Fail" << std::endl; + return 0; + } + return longValue; +} + +static ani_double NativeDoubleFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return 0; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedDoubleFunc", ":D", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return 0; + } + std::cout << "Print in Native Func" << std::endl; + ani_double doubleValue; + if (ANI_OK != env->Object_CallMethod_Double(obj, managedMethod, &doubleValue)) { + std::cerr << "Object_CallMethod_Double Fail" << std::endl; + return 0; + } + return doubleValue; +} + +static ani_float NativeFloatFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return 0.0; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedFloatFunc", ":F", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return 0.0; + } + std::cout << "Print in Native Func" << std::endl; + ani_float floatValue; + if (ANI_OK != env->Object_CallMethod_Float(obj, managedMethod, &floatValue)) { + std::cerr << "Object_CallMethod_Float Fail" << std::endl; + return 0.0; + } + return floatValue; +} + +static ani_char NativeCharFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return 0; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedCharFunc", ":C", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return 0; + } + std::cout << "Print in Native Func" << std::endl; + ani_char charValue; + if (ANI_OK != env->Object_CallMethod_Char(obj, managedMethod, &charValue)) { + std::cerr << "Object_CallMethod_Char Fail" << std::endl; + return 0; + } + return charValue; +} + +static ani_byte NativeByteFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return 0; + } + ani_method managedMethod; + if (ANI_OK != env->Class_FindMethod(cls, "ManagedByteFunc", ":B", &managedMethod)) { + std::cerr << "Class_FindMethod Fail" << std::endl; + return 0; + } + std::cout << "Print in Native Func" << std::endl; + ani_byte byteValue; + if (ANI_OK != env->Object_CallMethod_Byte(obj, managedMethod, &byteValue)) { + std::cerr << "Object_CallMethod_Byte Fail" << std::endl; + return 0; + } + return byteValue; +} + +static void NativeByNameFunc(ani_env *env, ani_object obj) +{ + std::cout << "Print in Native Func" << std::endl; + if (ANI_OK != env->Object_CallMethodByName_Void(obj, "ManagedByNameVoidFunc", ":V")) { + std::cerr << "Object_CallMethodByName_Void Fail" << std::endl; + return; + } +} + +static ani_double NativeByNameDoubleFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_double doubleValue; + if (ANI_OK != env->Object_CallMethodByName_Double(obj, "ManagedByNameDoubleFunc", ":D", &doubleValue)) { + std::cerr << "Object_CallMethodByName_Double Fail" << std::endl; + return 0.0; + } + return doubleValue; +} + +static ani_boolean NativeByNameBoolFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_boolean boolValue; + if (ANI_OK != env->Object_CallMethodByName_Boolean(obj, "ManagedByNameBoolFunc", ":Z", &boolValue)) { + std::cerr << "Object_CallMethodByName_Double Fail" << std::endl; + return false; + } + return boolValue; +} + +static ani_int NativeByNameIntFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_int intValue; + if (ANI_OK != env->Object_CallMethodByName_Int(obj, "ManagedByNameIntFunc", ":I", &intValue)) { + std::cerr << "Object_CallMethodByName_Int Fail" << std::endl; + return false; + } + return intValue; +} + +static ani_short NativeByNameShortFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_short shortValue; + if (ANI_OK != env->Object_CallMethodByName_Short(obj, "ManagedByNameShortFunc", ":S", &shortValue)) { + std::cerr << "Object_CallMethodByName_Short Fail" << std::endl; + return 0; + } + return shortValue; +} + +static ani_long NativeByNameLongFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_long longValue; + if (ANI_OK != env->Object_CallMethodByName_Long(obj, "ManagedByNameLongFunc", ":J", &longValue)) { + std::cerr << "Object_CallMethodByName_Long Fail" << std::endl; + return 0; + } + return longValue; +} + +static ani_char NativeByNameCharFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_char charValue; + if (ANI_OK != env->Object_CallMethodByName_Char(obj, "ManagedByNameCharFunc", ":C", &charValue)) { + std::cerr << "Object_CallMethodByName_Char Fail" << std::endl; + return '0'; + } + return charValue; +} + +static ani_float NativeByNameFloatFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_float floatValue; + if (ANI_OK != env->Object_CallMethodByName_Float(obj, "ManagedByNameFloatFunc", ":F", &floatValue)) { + std::cerr << "Object_CallMethodByName_Float Fail" << std::endl; + return 0.0; + } + return floatValue; +} + +static ani_byte NativeByNameByteFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + ani_byte byteValue; + if (ANI_OK != env->Object_CallMethodByName_Byte(obj, "ManagedByNameByteFunc", ":B", &byteValue)) { + std::cerr << "Object_CallMethodByName_Byte Fail" << std::endl; + return 0x0; + } + return byteValue; +} + +// todo Calling Static Methods +static void NativeStaticFunc(ani_env *env, ani_object obj) +{ + static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls; + if (ANI_OK != env->FindClass(className, &cls)) { + std::cerr << "Not found '" << className << "'" << std::endl; + return; + } + ani_static_method managedMethod; + if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFunc", ":V", &managedMethod)) { + std::cerr << "Class_FindStaticMethod Fail" << std::endl; + return; + } + std::cout << "Print in ManagedStaticFunc " << std::endl; + if (ANI_OK != env->Class_CallStaticMethod_Void(cls, managedMethod, ":V")) { + std::cerr << "Class_CallStaticMethod_Void Fail" << std::endl; + return; + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_init.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a6b57ebed6d03831b6d8098c215bfa719bd93fd7 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_init.cpp @@ -0,0 +1,116 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ani/ani.h" +#include "ani_accessing_fields.cpp" +#include "ani_array.cpp" +#include "ani_calling_methods.cpp" +#include "ani_exceptions.cpp" +#include "ani_object.cpp" +#include "ani_promise.cpp" +#include "ani_references.cpp" +#include "ani_string.cpp" +#include "ani_versionInfo.cpp" +#include +#include +#include +#include "hilog/log.h" + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域 +#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag + +auto Methods() +{ + std::array method = { + ani_native_function{"UpdateFields", ":V", reinterpret_cast(UpdateFields)}, + ani_native_function{"UpdateFields2", ":V", reinterpret_cast(UpdateFields2)}, + ani_native_function{"UpdateIntFields", ":I", reinterpret_cast(UpdateIntFields)}, + ani_native_function{"UpdateDoubleFields", ":D", reinterpret_cast(UpdateDoubleFields)}, + ani_native_function{"UpdateBoolFields", ":Z", reinterpret_cast(UpdateBoolFields)}, + ani_native_function{"UpdateShortFields", ":S", reinterpret_cast(UpdateShortFields)}, + ani_native_function{"UpdateLongFields", ":J", reinterpret_cast(UpdateLongFields)}, + ani_native_function{"UpdateCharFields", ":C", reinterpret_cast(UpdateCharFields)}, + ani_native_function{"UpdateFloatFields", ":F", reinterpret_cast(UpdateFloatFields)}, + ani_native_function{"UpdateByteFields", ":B", reinterpret_cast(UpdateByteFields)}, + ani_native_function{"UpdateByNameFields", ":V", reinterpret_cast(UpdateByNameFields)}, + ani_native_function{"UpdateByNameFields2", ":V", reinterpret_cast(UpdateByNameFields2)}, + ani_native_function{"UpdateStaticFields", ":V", reinterpret_cast(UpdateStaticFields)}, + ani_native_function{"UpdateStaticFields2", ":V", reinterpret_cast(UpdateStaticFields2)}, + ani_native_function{"ProcessArray", "[D:V", reinterpret_cast(ProcessArray)}, + ani_native_function{"ProcessArray2", "[D:V", reinterpret_cast(ProcessArray2)}, + ani_native_function{"NativeVoidFunc", ":V", reinterpret_cast(NativeVoidFunc)}, + ani_native_function{"NativeBoolFunc", ":Z", reinterpret_cast(NativeBoolFunc)}, + ani_native_function{"NativeIntFunc", ":I", reinterpret_cast(NativeIntFunc)}, + ani_native_function{"NativeLongFunc", ":J", reinterpret_cast(NativeLongFunc)}, + ani_native_function{"NativeDoubleFunc", ":D", reinterpret_cast(NativeDoubleFunc)}, + ani_native_function{"NativeFloatFunc", ":F", reinterpret_cast(NativeFloatFunc)}, + ani_native_function{"NativeCharFunc", ":C", reinterpret_cast(NativeCharFunc)}, + ani_native_function{"NativeByteFunc", ":B", reinterpret_cast(NativeByteFunc)}, + ani_native_function{"NativeStaticFunc", ":V", reinterpret_cast(NativeStaticFunc)}, + ani_native_function{"GetVersionInfo", ":I", reinterpret_cast(GetVersionInfo)}, + ani_native_function{"Global_Local_References", ":V", reinterpret_cast(Global_Local_References)}, + ani_native_function{"Weak_Global_References", ":V", reinterpret_cast(Weak_Global_References)}, + ani_native_function{"String_Operations", ":Lstd/core/String;", reinterpret_cast(String_Operations)}, + ani_native_function{"NativeByNameFunc", ":V", reinterpret_cast(NativeByNameFunc)}, + ani_native_function{"NativeByNameDoubleFunc", ":D", reinterpret_cast(NativeByNameDoubleFunc)}, + ani_native_function{"NativeByNameBoolFunc", ":Z", reinterpret_cast(NativeByNameBoolFunc)}, + ani_native_function{"NativeByNameIntFunc", ":I", reinterpret_cast(NativeByNameIntFunc)}, + ani_native_function{"NativeByNameShortFunc", ":S", reinterpret_cast(NativeByNameShortFunc)}, + ani_native_function{"NativeByNameLongFunc", ":J", reinterpret_cast(NativeByNameLongFunc)}, + ani_native_function{"NativeByNameCharFunc", ":C", reinterpret_cast(NativeByNameCharFunc)}, + ani_native_function{"NativeByNameFloatFunc", ":F", reinterpret_cast(NativeByNameFloatFunc)}, + ani_native_function{"NativeByNameByteFunc", ":B", reinterpret_cast(NativeByNameByteFunc)}, + ani_native_function{"HandleDoubleData", "D:D", reinterpret_cast(HandleDoubleData)}, + }; + return method; +} + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + std::cerr << "Unsupported ANI_VERSION_1" << std::endl; + return ANI_OUT_OF_REF; + } + OH_LOG_ERROR(LOG_APP, "testTag get vm success start"); + if (ANI_OK != env->GetVM(&vm)) { + std::cerr << "GetVM Fail" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag get vm success end"); + static const char *clsName = "Lentry/src/main/ets/entryability/EntryAbility/Calc;"; + ani_class cls{}; + if (ANI_OK != env->FindClass(clsName, &cls)) { + std::cerr << "Not found '" << clsName << "'" << std::endl; + return ANI_INVALID_ARGS; + } + std::array method = Methods(); + if (ANI_OK != env->Class_BindNativeMethods(cls, method.data(), method.size())) { + return ANI_INVALID_TYPE; + }; + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_object.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14624ffa900c231e887e29f6c8bf7e3ac8633d6d --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_object.cpp @@ -0,0 +1,63 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ani/ani.h" +#include "hilog/log.h" +#include + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域 +#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag + +static ani_double HandleDoubleData([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_fn_object fnObj, + ani_double val_double1) +{ + ani_class cls; + if (ANI_OK != env->FindClass("Lstd/core/Double;", &cls)) { + std::cerr << "Not found " << std::endl; + return 0.0; + } + ani_method ctor; + if (ANI_OK != env->Class_FindMethod(cls, "", "D:V", &ctor)) { + std::cerr << "Not found " << std::endl; + } + ani_object rs; + if (ANI_OK != env->Object_New(cls, ctor, &rs, val_double1)) { + std::cerr << "Object_New fail " << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Object_New success"); + ani_type result; + if (ANI_OK != env->Object_GetType(rs, &result)) { + std::cerr << "Object_GetType fail " << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Object_GetType success"); + ani_boolean boolresult; + if (ANI_OK != env->Object_InstanceOf(fnObj, cls, &boolresult)) { + std::cerr << "Object_InstanceOf fail " << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag Object_InstanceOf result: %{public}d", boolresult); + return val_double1; +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_references.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_references.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6807640b0f32f5f6cd74eab4dd2fc3b78b89a891 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_references.cpp @@ -0,0 +1,79 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ani/ani.h" +#include "hilog/log.h" +#include +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域 +#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag + +//// Global and Local References +static void Global_Local_References([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ani_ref ref; + ani_ref result; + if (ANI_OK != env->GlobalReference_Create(ref, &result)) { + std::cerr << "GlobalReference_Create FAILED" << std::endl; + return; + } + OH_LOG_ERROR(LOG_APP, "testTag GlobalReference_Create success"); + ani_boolean isNull; + if (ANI_OK != env->Reference_IsNull(result, &isNull)) { + std::cerr << "Reference_IsNull" << std::endl; + return; + } + ani_ref ref0 = nullptr; + ani_ref ref1 = nullptr; + ani_boolean boolresult; + if (ANI_OK != env->Reference_StrictEquals(ref0, ref1, &boolresult)) { + std::cerr << "Reference_StrictEquals" << std::endl; + return; + } + + if (ANI_OK != env->GlobalReference_Delete(result)) { + std::cerr << "Reference_IsNull" << std::endl; + return; + } + OH_LOG_ERROR(LOG_APP, "testTag GlobalReference_Delete success"); +} + +// Weak Global References; +static void Weak_Global_References([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ani_ref ref; + ani_wref result; + if (ANI_OK != env->WeakReference_Create(ref, &result)) { + std::cerr << "WeakReference_Create FAILED" << std::endl; + return; + } + OH_LOG_ERROR(LOG_APP, "testTag WeakReference_Create success"); + if (ANI_OK != env->WeakReference_Delete(result)) { + std::cerr << "WeakReference_Delete FAILED" << std::endl; + return; + } + OH_LOG_ERROR(LOG_APP, "testTag WeakReference_Delete success"); +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_string.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_string.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a97a096a35628a7bf44ea1e5dca6902a150b085 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_string.cpp @@ -0,0 +1,49 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ani/ani.h" +#include "hilog/log.h" +#include + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域 +#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag +// String Operations + +static ani_string String_Operations(ani_env *env, [[maybe_unused]] ani_object obj) +{ + std::string msg = "testTag this message in cpp"; + ani_string ani_str; + if (ANI_OK != env->String_NewUTF8(msg.c_str(), msg.size(), &ani_str)) { + std::cerr << "String_NewUTF8 fail" << std::endl; + } + ani_size strSize; + if (ANI_OK != env->String_GetUTF8Size(ani_str, &strSize)) { + std::cerr << "String_NewUTF8 fail" << std::endl; + } + OH_LOG_ERROR(LOG_APP, "testTag String_GetUTF8Size result: %{public}ld", strSize); + return ani_str; +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_versionInfo.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_versionInfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e2fdf19277d48ac223d3f9ce8d8b4d35bf75e9dd --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_versionInfo.cpp @@ -0,0 +1,39 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ani/ani.h" +#include +#include + +// Version Information +static uint32_t GetVersionInfo([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj) +{ + uint32_t version; + if (ANI_OK != env->GetVersion(&version)) { + std::cerr << "GetVersion Fail" << std::endl; + return 0; + } + return version; +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/ets/entryability/EntryAbility.ets b/code/ArkTS1.2/ANISample/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..39de01a5fc79d55135f7e3aa1b411baf425ac409 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,343 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import { BusinessError } from '@ohos.base'; +import hilog from '@ohos.hilog'; +import { MyCallback } from '../models/MyCallback'; +import hilog from '@ohos.hilog' + +class Calc { + native UpdateFields(): void; + + native UpdateFields2(): void; + + byteField: byte; + charField: char; + boolField: boolean; + floatField: float; + doubleField: double; + shortField: short; + intField: int; + longField: long; + + native UpdateStaticFields(): void; + + native UpdateStaticFields2(): void; + + static intStaticField: int; + static shortStaticField: short; + static longStaticField: long; + static charStaticField: char; + static doubleStaticField: double; + static floatStaticField: float; + static boolStaticField: boolean; + static byteStaticField: byte; + + constructor(a: int, b: double, c: boolean, f: long) { + this.getIntField = a; + this.getDoubleField = b; + this.getBoolField = c; + this.getLongField = f; + } + + getDoubleField: double; + getIntField: int; + getBoolField: boolean; + getShortField: short = 15; + getLongField: long; + getCharField: char = 'D'; + getFloatField: float = 10.23; + getByteField: byte = 0x1; + + native UpdateIntFields(): int; + + native UpdateDoubleFields(): double; + + native UpdateBoolFields(): boolean; + + native UpdateShortFields(): short; + + native UpdateLongFields(): long; + + native UpdateCharFields(): char; + + native UpdateFloatFields(): float; + + native UpdateByteFields(): byte; + + fieldByName_Byte: byte; + fieldByName_Double: double; + fieldByName_Short: short; + fieldByName_Float: float; + fieldByName_Int: int; + fieldByName_Long: long; + fieldByName_Char: char; + fieldByName_Bool: boolean; + + native UpdateByNameFields(): void; + + native UpdateByNameFields2(): void; + + native GetVersionInfo(): int; + + native NativeVoidFunc(): void; + + ManagedVoidFunc(): void { + hilog.error(0x0000, 'testTag', "Print in ManagedVoidFunc"); + } + + native NativeIntFunc(): int; + + ManagedIntFunc(): int { + hilog.error(0x0000, 'testTag', "Print in ManagedIntFunc"); + return 10; + } + + native NativeBoolFunc(): boolean; + + ManagedBoolFunc(): boolean { + hilog.error(0x0000, 'testTag', "Print in ManagedBoolFunc"); + return true; + } + + native NativeShortFunc(): short; + + ManagedShortFunc(): short { + hilog.error(0x0000, 'testTag', "Print in ManagedShortFunc"); + return 22; + } + + native NativeLongFunc(): long; + + ManagedLongFunc(): long { + hilog.error(0x0000, 'testTag', "Print in ManagedLongFunc"); + return 12365478965; + } + + native NativeDoubleFunc(): double; + + ManagedDoubleFunc(): double { + hilog.error(0x0000, 'testTag', "Print in ManagedDoubleFunc"); + return 12.35; + } + + native NativeCharFunc(): char; + + ManagedCharFunc(): char { + hilog.error(0x0000, 'testTag', "Print in ManagedCharFunc"); + return 'I'; + } + + native NativeFloatFunc(): float; + + ManagedFloatFunc(): float { + hilog.error(0x0000, 'testTag', "Print in ManagedFloatFunc"); + return 45.32; + } + + native NativeByteFunc(): byte; + + ManagedByteFunc(): byte { + hilog.error(0x0000, 'testTag', "Print in ManagedByteFunc"); + return 0x1; + } + + native NativeStaticFunc(): void; + + static ManagedStaticFunc(): void { + hilog.error(0x0000, 'testTag', "Print in ManagedStaticFunc"); + } + + native NativeByNameFunc(): void; + + ManagedByNameVoidFunc(): void { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameVoidFunc"); + } + + native NativeByNameDoubleFunc(): double; + + ManagedByNameDoubleFunc(): double { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameDoubleFunc"); + return 3.33; + } + + native NativeByNameBoolFunc(): boolean; + + ManagedByNameBoolFunc(): boolean { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameBoolFunc"); + return true; + } + + native NativeByNameIntFunc(): int; + + ManagedByNameIntFunc(): int { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameIntFunc"); + return 10; + } + + native NativeByNameShortFunc(): short; + + ManagedByNameShortFunc(): short { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameShortFunc"); + return 1456; + } + + native NativeByNameLongFunc(): long; + + ManagedByNameLongFunc(): long { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameLongFunc"); + return 12345679852; + } + + native NativeByNameCharFunc(): char; + + ManagedByNameCharFunc(): char { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameCharFunc"); + return 'K'; + } + + native NativeByNameFloatFunc(): float; + + ManagedByNameFloatFunc(): float { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameFloatFunc"); + return 15.655; + } + + native NativeByNameByteFunc(): byte; + + ManagedByNameByteFunc(): byte { + hilog.error(0x0000, 'testTag', "Print in ManagedByNameByteFunc"); + return 0x3; + } + + native Global_Local_References(): void; + + native Weak_Global_References(): void; + + native VMInterface(): void; + + native String_Operations(s: string): void; + + native String_Operations2(): string; + + native HandleDoubleData(val1: double): double + + native ProcessArray(a: double[]): void; + + native ProcessArray2(a: double[]): void; +} + +class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', 'EntryAbility onCreate'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + hilog.info(0x0000, 'testTag', 'EntryAbility onWindowStageCreate'); + try { + loadLibrary("entry") + } catch (e: Error) { + hilog.error(0x0000, 'testTag', 'loadFailed', e.message); + } + hilog.error(0x0000, 'testTag', 'AfterLoading the library'); + let cls = new Calc(20, 1.23, true, 14785236951); + cls.UpdateFields(); + cls.UpdateFields2(); + hilog.error(0x0000, 'testTag', 'UpdateField result byteField ' + cls.byteField); + hilog.error(0x0000, 'testTag', 'UpdateField result charField ' + cls.charField); + hilog.error(0x0000, 'testTag', 'UpdateField result doubleField ' + cls.doubleField); + hilog.error(0x0000, 'testTag', 'UpdateField result boolField ' + cls.boolField); + hilog.error(0x0000, 'testTag', 'UpdateField result floatField ' + cls.floatField); + hilog.error(0x0000, 'testTag', 'UpdateField result shortField ' + cls.shortField); + hilog.error(0x0000, 'testTag', 'UpdateField result intField : ' + cls.intField); + hilog.error(0x0000, 'testTag', 'UpdateField result longField ' + cls.longField); + cls.UpdateStaticFields(); + cls.UpdateStaticFields2(); + hilog.error(0x0000, 'testTag', 'UpdateStaticFields intStaticField : ' + Calc.intStaticField); + hilog.error(0x0000, 'testTag', 'UpdateStaticFields shortStaticField : ' + Calc.shortStaticField); + hilog.error(0x0000, 'testTag', 'UpdateStaticFields longStaticField : ' + Calc.longStaticField); + hilog.error(0x0000, 'testTag', 'UpdateStaticFields charStaticField : ' + Calc.charStaticField); + hilog.error(0x0000, 'testTag', 'UpdateStaticFields intStaticField : ' + Calc.doubleStaticField); + hilog.error(0x0000, 'testTag', 'UpdateStaticFields shortStaticField : ' + Calc.floatStaticField); + hilog.error(0x0000, 'testTag', 'UpdateStaticFields longStaticField : ' + Calc.boolStaticField); + hilog.error(0x0000, 'testTag', 'UpdateStaticFields charStaticField : ' + Calc.byteStaticField); + hilog.error(0x0000, 'testTag', 'Get Ets UpdateIntFields result : ' + cls.UpdateIntFields()); + hilog.error(0x0000, 'testTag', 'Get Ets UpdateDoubleFields result : ' + cls.UpdateDoubleFields()); + hilog.error(0x0000, 'testTag', 'Get Ets UpdateBoolFields result : ' + cls.UpdateBoolFields()); + hilog.error(0x0000, 'testTag', 'Get Ets UpdateShortFields result : ' + cls.UpdateShortFields()); + hilog.error(0x0000, 'testTag', 'Get Ets UpdateLongFields result : ' + cls.UpdateLongFields()); + hilog.error(0x0000, 'testTag', 'Get Ets UpdateCharFields result : ' + cls.UpdateCharFields()); + hilog.error(0x0000, 'testTag', 'Get Ets UpdateFloatFields result : ' + cls.UpdateFloatFields()); + hilog.error(0x0000, 'testTag', 'Get Ets UpdateByteFields result : ' + cls.UpdateByteFields()); + cls.NativeVoidFunc(); + cls.NativeBoolFunc(); + cls.NativeIntFunc(); + cls.NativeLongFunc(); + cls.NativeDoubleFunc(); + cls.NativeFloatFunc(); + cls.NativeCharFunc(); + cls.NativeByteFunc(); + cls.NativeStaticFunc(); + cls.UpdateByNameFields(); + cls.UpdateByNameFields2(); + hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Bytes ' + cls.fieldByName_Byte); + hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Double ' + cls.fieldByName_Double); + hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Short ' + cls.fieldByName_Short); + hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Bool ' + cls.fieldByName_Bool); + hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Float ' + cls.fieldByName_Float); + hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Int ' + cls.fieldByName_Int); + hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Long ' + cls.fieldByName_Long); + hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Char ' + cls.fieldByName_Char); + hilog.error(0x0000, 'testTag', 'GetVersionInfo result : ' + cls.GetVersionInfo()); + cls.Global_Local_References(); + cls.Weak_Global_References(); + cls.NativeByNameFunc(); + hilog.error(0x0000, 'testTag', 'NativeByNameDoubleFunc() result ' + cls.NativeByNameDoubleFunc()); + hilog.error(0x0000, 'testTag', 'NativeByNameBoolFunc() result ' + cls.NativeByNameBoolFunc()); + hilog.error(0x0000, 'testTag', 'NativeByNameIntFunc() result ' + cls.NativeByNameIntFunc()); + hilog.error(0x0000, 'testTag', 'NativeByNameShortFunc() result ' + cls.NativeByNameShortFunc()); + hilog.error(0x0000, 'testTag', 'NativeByNameLongFunc() result ' + cls.NativeByNameLongFunc()); + hilog.error(0x0000, 'testTag', 'NativeByNameCharFunc() result ' + cls.NativeByNameCharFunc()); + hilog.error(0x0000, 'testTag', 'NativeByNameFloatFunc() result ' + cls.NativeByNameFloatFunc()); + hilog.error(0x0000, 'testTag', 'NativeByNameByteFunc() result ' + cls.NativeByNameByteFunc()); + hilog.error(0x0000, 'testTag', 'HandleDoubleData() result ' + cls.HandleDoubleData(30.3)); + hilog.error(0x0000, 'testTag', 'String_Operations result : ' + cls.String_Operations()) + let s: double[] = [5, 15, 20]; + cls.ProcessArray(s); + cls.ProcessArray2(s); + + try { + windowStage.loadContent('pages/Index', (err: Error): void => { + hilog.info(0x0000, 'testTag', 'loadContent entering'); + }); + } catch (e: Error) { + hilog.info(0x0000, 'testTag', 'loadContent catch error:-----------' + e.message); + } + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/ets/models/MyCallback.ets b/code/ArkTS1.2/ANISample/entry/src/main/ets/models/MyCallback.ets new file mode 100644 index 0000000000000000000000000000000000000000..a646f66bba874f18f9edfa9816df4e2312111f36 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/ets/models/MyCallback.ets @@ -0,0 +1,60 @@ +/** + * MIT License + * Copyright (c) 2025 indiespirit + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. +*/ +import { AsyncCallback, BusinessError, Callback, ErrorCallback } from '@ohos.base'; +import hilog from '@ohos.hilog'; + +const SYNTAX_ERROR_CODE: double = 1002; + +export class MyCallback { + static myCallback(callback: Callback): void { + hilog.info(0x0000, 'testTag', 'myCallback'); + callback('myCallback'); + } + + static myAsyncCallback(callback: AsyncCallback): void { + hilog.info(0x0000, 'testTag', 'myAsyncCallback'); + let error = new Error('Business Error', 'basicError2 message', undefined); + let be2: BusinessError = new BusinessError(SYNTAX_ERROR_CODE, error); + callback(be2, 'yAsyncCallback'); + } + + static myErrorCallback(callback: ErrorCallback>): void { + hilog.info(0x0000, 'testTag', 'myErrorCallback'); + let error = new Error('Business Error', 'myErrorCallback message', undefined); + let result: string = 'test'; + let be: BusinessError = new BusinessError(SYNTAX_ERROR_CODE, result, error); + callback(be); + } + + static runCasesOfCallback() { + MyCallback.myCallback((data: string) => { + hilog.info(0x0000, 'testTag', 'MyCallback' + data); + }) + MyCallback.myAsyncCallback((error: BusinessError, result: string) => { + hilog.info(0x0000, 'testTag', `myAsyncCallback, error: ${error.message}, result:${result}`); + }) + MyCallback.myErrorCallback((error: BusinessError) => { + hilog.info(0x0000, 'testTag', `myAsyncCallback, error: ${error.message}`); + }) + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/ets/pages/Index.ets b/code/ArkTS1.2/ANISample/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf99afe69e00a42fdda7fec35f38ecde6bab308b --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,55 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +import { memo, __memo_context_type, __memo_id_type } from '@ohos.arkui.stateManagement' // should be insert by ui-plugins +import { Text, TextAttribute, Column, Component, Button, ButtonAttribute, ClickEvent, UserView } from '@ohos.arkui.component' // TextAttribute should be insert by ui-plugins +import { State, StateDecoratedVariable, MutableState, stateOf, observableProxy } from '@ohos.arkui.stateManagement' // should be insert by ui-plugins +import hilog from '@ohos.hilog' + +@Component +struct MyStateSample { + @State stateVar: string = 'state var'; + message: string = 'var'; + build() { + Column(undefined) { + Button(this.message).backgroundColor('#FFFF00FF') + .onClick((e: ClickEvent) => { + hilog.info(0x0000, 'testTag', 'On Click'); + }) + Text(this.stateVar).fontSize(20) + } + } +} + +export class ComExampleTrivialApplication extends UserView { + getBuilder() { + hilog.info(0x0000, 'testTag', 'getBuilder'); + let wrapper = @memo () => { + hilog.info(0x0000, 'testTag', 'MyStateSample'); + MyStateSample(undefined) + } + return wrapper + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/module.json5 b/code/ArkTS1.2/ANISample/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..de78b5cae3b2ba99788048311e5d0cd34d075039 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/module.json5 @@ -0,0 +1,38 @@ +{ + "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" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/element/color.json b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/entry/src/main/resources/base/element/float.json b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/element/string.json b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/background.png b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/background.png differ diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/foreground.png b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/layered_image.json b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/startIcon.png b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/profile/backup_config.json b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/profile/main_pages.json b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/dark/element/color.json b/code/ArkTS1.2/ANISample/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/hvigor/hvigor-config.json5 b/code/ArkTS1.2/ANISample/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..85e8d4b2175fc4747650344f025e7d145bc3d361 --- /dev/null +++ b/code/ArkTS1.2/ANISample/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.1.0", + "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/code/ArkTS1.2/ANISample/hvigorfile.ts b/code/ArkTS1.2/ANISample/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/code/ArkTS1.2/ANISample/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/code/ArkTS1.2/ANISample/oh-package.json5 b/code/ArkTS1.2/ANISample/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7f512c9632708e85a7ea34e739c01b0b8f1ad92e --- /dev/null +++ b/code/ArkTS1.2/ANISample/oh-package.json5 @@ -0,0 +1,8 @@ +{ + "modelVersion": "5.1.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + } +}