diff --git a/ResourceManagement/RawFile/.gitignore b/ResourceManagement/RawFile/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ResourceManagement/RawFile/.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/ResourceManagement/RawFile/AppScope/app.json5 b/ResourceManagement/RawFile/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..023f4a2472a4bedbd3ad93d408b68c6765d3bc65 --- /dev/null +++ b/ResourceManagement/RawFile/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.samples.rawfile", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ResourceManagement/RawFile/AppScope/resources/base/element/string.json b/ResourceManagement/RawFile/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d1a4889b000a3a7fee7be3c883c04c48a827fb7a --- /dev/null +++ b/ResourceManagement/RawFile/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "RawFile" + } + ] +} diff --git a/ResourceManagement/RawFile/AppScope/resources/base/media/app_icon.png b/ResourceManagement/RawFile/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ResourceManagement/RawFile/AppScope/resources/base/media/app_icon.png differ diff --git a/ResourceManagement/RawFile/README.md b/ResourceManagement/RawFile/README.md new file mode 100644 index 0000000000000000000000000000000000000000..57c38d4cca77e52f635624b0dadd08fba968b836 --- /dev/null +++ b/ResourceManagement/RawFile/README.md @@ -0,0 +1,73 @@ +# RawFile(资源管理) + +### 介绍 + +本工程主要实现了[Rawfile开发指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.1.0-Release/zh-cn/application-dev/napi/rawfile-guidelines.md)中功能,开发者可以通过本项目了解如何使用Native Rawfile接口操作Rawfile目录和文件。功能包括文件列表遍历、文件打开、搜索、读取和关闭Rawfile。 + +### 效果预览 + +| 显示页面 | 点击Hello World后的页面 | 点击后日志打印效果 | +| ------------------------------------------------------------|-------------------------------------| ----------------------------------------------- | +| ![](screenshots/RawFile_Index1.png) | ![](screenshots/RawFile_Index2.png) | ![](screenshots/log.png) | + +### 使用说明 + +1. 启动项目后,会显示带有“Hello World”的文本页面; +2. 点击“Hello World”文本触发点击事件; +3. 关注DevEco中的日志窗口,会打印log显示处理结果,包括文件资源的文件列表、文件、文件描述符; + +### 目录结构 + +``` +RawFile/entry/src/ +|---main +│   |---cpp +│   │   |---CMakeLists.txt(CMake构建配置文件) +│   │   |---hello.cpp(RawFile的主要功能逻辑文件) +│   │   |---types +│   │   |---libentry +│   │   |---Index.d.ts(应用侧函数声明文件) +│   │   |---oh-package.json5 +│   |---ets +│   │   |---pages +│   │   |---Index.ets(构建页面,调用RawFile功能函数输出Log日志) +│   |---resources +│   |---rawfile(RawFile调用的资源文件) +│   │   |---rawfile.txt +│   │   |---rawfile1.txt +│   │   |---subrawfile +│   │   |---rawfile2.txt +``` + +### 具体实现 + +- 想要使用Native Rawfile接口操作Rawfile目录和文件。功能包括文件列表遍历、文件打开、搜索、读取和关闭Rawfile,需要在CPP目录下的index.d.ts文件中声明应用侧函数getFileList()、getRawFileContent()、getRawFileDescriptor()、isRawDir()。 +- 在hello.cpp中实现getFileList()、getRawFileContent()、getRawFileDescriptor()、isRawDir()的具体代码,实际操作逻辑。 +- 在ets目录下的index.ets文件就可以通过import testNapi from "libentry.so";导入相关库,进行对上述函数的调用。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 +2. HarmonyOS系统:HarmonyOS 5.1.1 Release及以上。 +3. DevEco Studio版本:DevEco Studio 5.1.1 Release及以上。 +4. HarmonyOS SDK版本:HarmonyOS 5.1.1 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ResourceManagement/RawFile/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` \ No newline at end of file diff --git a/ResourceManagement/RawFile/build-profile.json5 b/ResourceManagement/RawFile/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cbb8d44aa7e11a49adfb37db0589ac1be3abecbe --- /dev/null +++ b/ResourceManagement/RawFile/build-profile.json5 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.1.1(19)", + "targetSdkVersion": "5.1.1(19)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "externalNativeOptions": { + "abiFilters": [ + "arm64-v8a", + "x86_64", + ], + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/.gitignore b/ResourceManagement/RawFile/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ResourceManagement/RawFile/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/build-profile.json5 b/ResourceManagement/RawFile/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..49175e1cfeb8866c2f49d049eef5c8d2133acbd1 --- /dev/null +++ b/ResourceManagement/RawFile/entry/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/hvigorfile.ts b/ResourceManagement/RawFile/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..d34f0f7bb604374263ca9583a1f246037bf476d7 --- /dev/null +++ b/ResourceManagement/RawFile/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { 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/ResourceManagement/RawFile/entry/obfuscation-rules.txt b/ResourceManagement/RawFile/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..fdbb5b9852d7dd5f39bddaeb21ab5ee1f3346749 --- /dev/null +++ b/ResourceManagement/RawFile/entry/obfuscation-rules.txt @@ -0,0 +1,22 @@ +# 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/ResourceManagement/RawFile/entry/oh-package.json5 b/ResourceManagement/RawFile/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d1ae3a496fa4a2c6450a541e8867c5c0ba49358c --- /dev/null +++ b/ResourceManagement/RawFile/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "example description", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/cpp/CMakeLists.txt b/ResourceManagement/RawFile/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..97ecca4027cf07bc3009108efe08721eafacb61d --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,28 @@ + # Copyright (c) 2025 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + + # the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(RawFile) + +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 hello.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so librawfile.z.so) \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/cpp/hello.cpp b/ResourceManagement/RawFile/entry/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c737f6d815440dfa496aa6f88e1871b7efbc708 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/cpp/hello.cpp @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start includes] +#include +#include +#include +#include +#include +#include "napi/native_api.h" +#include "rawfile/raw_file_manager.h" +#include "rawfile/raw_file.h" +#include "rawfile/raw_dir.h" +#include "hilog/log.h" +// [End includes] + +// [Start constants] +const int GLOBAL_RESMGR = 0xFF00; +const char *TAG = "[Sample_rawfile]"; +// [End constants] + +// [Start example_get_file_list] +// 示例一:获取rawfile文件列表 GetFileList +static napi_value GetFileList(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "NDKTest GetFileList Begin"); + size_t argc = 2; + napi_value argv[2] = { nullptr }; + // 获取参数信息 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + // argv[0]即为函数第一个参数Js资源对象,OH_ResourceManager_InitNativeResourceManager转为Native对象 + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + + // 获取函数argv[1],此为rawfile相对路径 + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string dirName(strBuf, strSize); + + // 获取对应的rawDir指针对象 + RawDir* rawDir = OH_ResourceManager_OpenRawDir(mNativeResMgr, dirName.c_str()); + + // 获取rawDir下文件及文件夹数量 + int count = OH_ResourceManager_GetRawFileCount(rawDir); + + // 遍历获取文件名称,并保存 + std::vector tempArray; + for (int i = 0; i < count; i++) { + std::string filename = OH_ResourceManager_GetRawFileName(rawDir, i); + tempArray.emplace_back(filename); + } + + // 转为js数组 + napi_value fileList; + napi_create_array(env, &fileList); + for (size_t i = 0; i < tempArray.size(); i++) { + napi_value jsString; + napi_create_string_utf8(env, tempArray[i].c_str(), NAPI_AUTO_LENGTH, &jsString); + napi_set_element(env, fileList, i, jsString); + } + + // 关闭打开的指针对象 + OH_ResourceManager_CloseRawDir(rawDir); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + return fileList; +} +// [End example_get_file_list] + +// [Start example_get_rawfile_content] +// 示例二:获取rawfile文件内容 GetRawFileContent +napi_value CreateJsArrayValue(napi_env env, std::unique_ptr &data, long length) +{ + // 创建js外部ArrayBuffer + napi_value buffer; + napi_status status = napi_create_external_arraybuffer(env, data.get(), length, + [](napi_env env, void *data, void *hint) { + delete[] static_cast(data); + }, nullptr, &buffer); + // 检测ArrayBuffer是否创建成功 + if (status != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, GLOBAL_RESMGR, TAG, "Failed to create external array buffer"); + return nullptr; + } + // 创建js TypedArray 将ArrayBuffer绑定到TypedArray + napi_value result = nullptr; + status = napi_create_typedarray(env, napi_uint8_array, length, buffer, 0, &result); + if (status != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, GLOBAL_RESMGR, TAG, "Failed to create media typed array"); + return nullptr; + } + data.release(); + return result; +} + +static napi_value GetRawFileContent(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileContent Begin"); + size_t argc = 2; + napi_value argv[2] = { nullptr }; + // 获取参数信息 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + // argv[0]即为函数第一个参数Js资源对象,OH_ResourceManager_InitNativeResourceManager转为Native对象 + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string filename(strBuf, strSize); + + // 获取rawfile指针对象 + RawFile *rawFile = OH_ResourceManager_OpenRawFile(mNativeResMgr, filename.c_str()); + if (rawFile != nullptr) { + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile success"); + } + // 获取rawfile大小并申请内存 + long len = OH_ResourceManager_GetRawFileSize(rawFile); + std::unique_ptr data = std::make_unique(len); + + // 一次性读取rawfile全部内容 + int res = OH_ResourceManager_ReadRawFile(rawFile, data.get(), len); + + // 关闭打开的指针对象 + OH_ResourceManager_CloseRawFile(rawFile); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + // 转为js对象 + return CreateJsArrayValue(env, data, len); +} +// [End example_get_rawfile_content] + +// [Start example_get_rawfile_descriptor] +// 示例三:获取rawfile文件描述符 GetRawFileDescriptor +// 定义一个函数,将RawFileDescriptor转为js对象 +napi_value createJsFileDescriptor(napi_env env, RawFileDescriptor& descriptor) +{ + // 创建js对象 + napi_value result; + napi_status status = napi_create_object(env, &result); + if (status != napi_ok) { + return result; + } + + // 将文件描述符df存入到result对象中 + napi_value fd; + status = napi_create_int32(env, descriptor.fd, &fd); + if (status != napi_ok) { + return result; + } + status = napi_set_named_property(env, result, "fd", fd); + if (status != napi_ok) { + return result; + } + + // 将文件偏移量offset存入到result对象中 + napi_value offset; + status = napi_create_int64(env, descriptor.start, &offset); + if (status != napi_ok) { + return result; + } + status = napi_set_named_property(env, result, "offset", offset); + if (status != napi_ok) { + return result; + } + + // 将文件长度length存入到result对象中 + napi_value length; + status = napi_create_int64(env, descriptor.length, &length); + if (status != napi_ok) { + return result; + } + status = napi_set_named_property(env, result, "length", length); + if (status != napi_ok) { + return result; + } + return result; +} + +static napi_value GetRawFileDescriptor(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "NDKTest GetRawFileDescriptor Begin"); + size_t argc = 2; + napi_value argv[2] = { nullptr }; + // 获取参数信息 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + // argv[0]即为函数第一个参数Js资源对象,OH_ResourceManager_InitNativeResourceManager转为Native对象 + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string filename(strBuf, strSize); + // 获取rawfile指针对象 + RawFile *rawFile = OH_ResourceManager_OpenRawFile(mNativeResMgr, filename.c_str()); + if (rawFile != nullptr) { + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile success"); + } + // 获取rawfile的描述符RawFileDescriptor {fd, offset, length} + RawFileDescriptor descriptor; + OH_ResourceManager_GetRawFileDescriptor(rawFile, descriptor); + // 关闭打开的指针对象 + OH_ResourceManager_CloseRawFile(rawFile); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + // 转为js对象 + return createJsFileDescriptor(env, descriptor); +} +// [End example_get_rawfile_descriptor] + +// [Start example_is_raw_dir] +// 示例四:判断路径是否是rawfile下的目录 IsRawDir +napi_value CreateJsBool(napi_env env, bool &bValue) +{ + napi_value jsValue = nullptr; + if (napi_get_boolean(env, bValue, &jsValue) != napi_ok) { + return nullptr; + } + return jsValue; +} + +static napi_value IsRawDir(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "NDKTest IsRawDir Begin"); + size_t argc = 2; + napi_value argv[2] = { nullptr }; + // 获取参数信息 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + // argv[0]即为函数第一个参数Js资源对象,OH_ResourceManager_InitNativeResourceManager转为Native对象 + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + + napi_valuetype fileNameType; + napi_typeof(env, argv[1], &fileNameType); + if (fileNameType == napi_undefined || fileNameType == napi_null) { + OH_LOG_Print(LOG_APP, LOG_ERROR, GLOBAL_RESMGR, TAG, "NDKTest file name is null"); + bool temp = false; + return CreateJsBool(env, temp); + } + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string filename(strBuf, strSize); + // 判断是否是rawfile下的目录 + bool result = OH_ResourceManager_IsRawDir(mNativeResMgr, filename.c_str()); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + return CreateJsBool(env, result); +} +// [End example_is_raw_dir] + +// [Start module_registration] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "getFileList", nullptr, GetFileList, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "getRawFileContent", nullptr, GetRawFileContent, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "getRawFileDescriptor", nullptr, GetRawFileDescriptor, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "isRawDir", nullptr, IsRawDir, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END +// [End module_registration] + +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/ResourceManagement/RawFile/entry/src/main/cpp/types/libentry/Index.d.ts b/ResourceManagement/RawFile/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ef75cb6c92bf68900057d76754f4787d25b1d0a7 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import resourceManager from '@ohos.resourceManager'; +export const getFileList: (resmgr: resourceManager.ResourceManager, path: string) => Array; +export const getRawFileContent: (resmgr: resourceManager.ResourceManager, path: string) => Uint8Array; +export const getRawFileDescriptor: (resmgr: resourceManager.ResourceManager, path: string) => resourceManager.RawFileDescriptor; +export const isRawDir: (resmgr: resourceManager.ResourceManager, path: string) => boolean; \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/cpp/types/libentry/oh-package.json5 b/ResourceManagement/RawFile/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "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/ResourceManagement/RawFile/entry/src/main/ets/entryability/EntryAbility.ets b/ResourceManagement/RawFile/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5539bddd7a772710f55da0ddd7b5676305469de --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/ResourceManagement/RawFile/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ResourceManagement/RawFile/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/ets/pages/Index.ets b/ResourceManagement/RawFile/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..58cec65633fb8f0e7c0550c315ba9872e6a2c31b --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start native_rawfile_guide_sample] +import { util } from '@kit.ArkTS'; +import { resourceManager } from '@kit.LocalizationKit'; +import testNapi from 'libentry.so'; // 导入so + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + private resMgr = this.getUIContext().getHostContext()?.resourceManager; // 获取本应用包的资源对象 + @State rawfileListMsg: string = 'FileList = '; + @State retMsg: string = 'isRawDir = '; + @State rawfileContentMsg: string = 'RawFileContent = '; + @State rawfileDescriptorMsg: string = 'RawFileDescriptor.length = '; + + build() { + Row() { + Column() { + Text(this.message) + .id('hello_world') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(async () => { + // 传入资源管理对象,以及访问的rawfile文件夹名称 + let rawFileList: Array = testNapi.getFileList(this.resMgr, ''); + this.rawfileListMsg = 'FileList = ' + rawFileList; + console.log(this.rawfileListMsg); + + let ret: boolean = testNapi.isRawDir(this.resMgr, 'subrawfile'); + this.retMsg = 'isRawDir = ' + ret; + console.log(this.retMsg); + + // 传入资源管理对象,以及访问的rawfile文件夹名称 + let rawfileArray: Uint8Array = testNapi.getRawFileContent(this.resMgr, 'rawfile1.txt'); + // 将Uint8Array转为字符串 + let textDecoder: util.TextDecoder = new util.TextDecoder(); + let rawfileContent: string = textDecoder.decodeToString(rawfileArray); + this.rawfileContentMsg = 'RawFileContent = ' + rawfileContent; + console.log(this.rawfileContentMsg); + + // 传入资源管理对象,以及访问的rawfile文件名称 + let rawfileDescriptor: resourceManager.RawFileDescriptor = + testNapi.getRawFileDescriptor(this.resMgr, 'rawfile1.txt'); + this.rawfileDescriptorMsg = 'RawFileDescriptor.length = ' + rawfileDescriptor.length; + console.log(this.rawfileDescriptorMsg); + }) + Text(this.rawfileListMsg).id('get_file_list').fontSize(30); + Text(this.retMsg).id('is_raw_dir').fontSize(30); + Text(this.rawfileContentMsg).id('get_raw_file_content').fontSize(30); + Text(this.rawfileDescriptorMsg).id('get_raw_file_descriptor').fontSize(30); + } + .width('100%') + } + .height('100%') + } +} + +// [End native_rawfile_guide_sample] \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/module.json5 b/ResourceManagement/RawFile/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "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/ResourceManagement/RawFile/entry/src/main/resources/base/element/color.json b/ResourceManagement/RawFile/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ResourceManagement/RawFile/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/ResourceManagement/RawFile/entry/src/main/resources/base/element/string.json b/ResourceManagement/RawFile/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4f99809f4f4e56c05b81056a841971d1ddf4e02d --- /dev/null +++ b/ResourceManagement/RawFile/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": "RawFile" + } + ] +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/resources/base/media/background.png b/ResourceManagement/RawFile/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ResourceManagement/RawFile/entry/src/main/resources/base/media/background.png differ diff --git a/ResourceManagement/RawFile/entry/src/main/resources/base/media/foreground.png b/ResourceManagement/RawFile/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ResourceManagement/RawFile/entry/src/main/resources/base/media/foreground.png differ diff --git a/ResourceManagement/RawFile/entry/src/main/resources/base/media/layered_image.json b/ResourceManagement/RawFile/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ResourceManagement/RawFile/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/ResourceManagement/RawFile/entry/src/main/resources/base/media/startIcon.png b/ResourceManagement/RawFile/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ResourceManagement/RawFile/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ResourceManagement/RawFile/entry/src/main/resources/base/profile/backup_config.json b/ResourceManagement/RawFile/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/resources/base/profile/main_pages.json b/ResourceManagement/RawFile/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ResourceManagement/RawFile/entry/src/main/resources/en_US/element/string.json b/ResourceManagement/RawFile/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4f99809f4f4e56c05b81056a841971d1ddf4e02d --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "RawFile" + } + ] +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/resources/rawfile/rawfile.txt b/ResourceManagement/RawFile/entry/src/main/resources/rawfile/rawfile.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b25a452b307397a28a2c425fd2dc129e1ae8749 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/resources/rawfile/rawfile.txt @@ -0,0 +1 @@ +rawfile1 content \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/resources/rawfile/rawfile1.txt b/ResourceManagement/RawFile/entry/src/main/resources/rawfile/rawfile1.txt new file mode 100644 index 0000000000000000000000000000000000000000..e975e96a837bf72a98c0b96118c8ab4a290c03b7 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/resources/rawfile/rawfile1.txt @@ -0,0 +1 @@ +sdgdfg \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/resources/rawfile/subrawfile/rawfile2.txt b/ResourceManagement/RawFile/entry/src/main/resources/rawfile/subrawfile/rawfile2.txt new file mode 100644 index 0000000000000000000000000000000000000000..34983e7b18f0ebc8f398f34411be67d9f794b5c4 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/resources/rawfile/subrawfile/rawfile2.txt @@ -0,0 +1 @@ +fdsafsdf \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/main/resources/zh_CN/element/string.json b/ResourceManagement/RawFile/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..30224382c07825206d7f81fcfa08b5188ed5da12 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "RawFile" + } + ] +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/ohosTest/ets/test/Ability.test.ets b/ResourceManagement/RawFile/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b271712f59d7d61fc909ac1eea18ca9a57672bf --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, expect, it } from '@ohos/hypium'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; + +const TAG = '[Sample_rawfile]'; +const DOMAIN = 0xF811; +const BUNDLE = 'com.samples.rawfile'; +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); + +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} + +export default function abilityTest() { + describe('RawFileTest', () => { + it('StartAbility_001', 0, async (done: Function) => { + console.info("uitest: StartAbility_001 begin"); + const want: Want = { + bundleName: BUNDLE, + abilityName: 'EntryAbility', + }; + await delegator.startAbility(want); + await sleep(3000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + done(); + console.info("uitest: StartAbility_001 end"); + }); + + it(BUNDLE + 'clickTest_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'clickTest begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let Textbutton = await driver.findComponent(ON.id('hello_world')); + Textbutton.click(); + await sleep(3000); + hilog.info(DOMAIN, TAG, BUNDLE + 'clickTest end'); + done(); + }) + + it(BUNDLE + 'getRawFileTest_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'GetFileListTest begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let fileListText = await driver.findComponent(ON.id('get_file_list')); + expect(await fileListText.getText() === 'FileList = rawfile.txt,rawfile1.txt,subrawfile').assertTrue(); + hilog.info(DOMAIN, TAG, BUNDLE + 'GetFileListTest end'); + done(); + }) + + it(BUNDLE + 'getRawFileTest_002', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'IsRawDirTest begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let rawDirText = await driver.findComponent(ON.id('is_raw_dir')); + expect(await rawDirText.getText() === 'isRawDir = true').assertTrue(); + hilog.info(DOMAIN, TAG, BUNDLE + 'IsRawDirTest end'); + done(); + }) + + it(BUNDLE + 'getRawFileTest_003', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'GetRawFileContentTest begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let fileContentText = await driver.findComponent(ON.id('get_raw_file_content')); + expect(await fileContentText.getText() === 'RawFileContent = sdgdfg').assertTrue(); + hilog.info(DOMAIN, TAG, BUNDLE + 'GetRawFileContentTest end'); + done(); + }) + + it(BUNDLE + 'getRawFileTest_004', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'GetRawFileDescriptor begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let fileDescriptorText = await driver.findComponent(ON.id('get_raw_file_descriptor')); + expect(await fileDescriptorText.getText() === 'RawFileDescriptor.length = 6').assertTrue(); + hilog.info(DOMAIN, TAG, BUNDLE + 'GetRawFileDescriptor end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/ohosTest/ets/test/List.test.ets b/ResourceManagement/RawFile/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ResourceManagement/RawFile/entry/src/ohosTest/module.json5 b/ResourceManagement/RawFile/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ResourceManagement/RawFile/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ResourceManagement/RawFile/hvigor/hvigor-config.json5 b/ResourceManagement/RawFile/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a2c44fdf8f9ac103168672568ff000ac395a2edc --- /dev/null +++ b/ResourceManagement/RawFile/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.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/ResourceManagement/RawFile/hvigorfile.ts b/ResourceManagement/RawFile/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..bdda2ce8c21a84a324a2897985cdde635f3a9ac5 --- /dev/null +++ b/ResourceManagement/RawFile/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { 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/ResourceManagement/RawFile/oh-package.json5 b/ResourceManagement/RawFile/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b7f346f7ddb2fc98ac428c55207a63ff89ea1c70 --- /dev/null +++ b/ResourceManagement/RawFile/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.18", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ResourceManagement/RawFile/ohosTest.md b/ResourceManagement/RawFile/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..46f28f7b2afc9e42a71eab5cfe6f46b75fff663f --- /dev/null +++ b/ResourceManagement/RawFile/ohosTest.md @@ -0,0 +1,12 @@ +# RM.002 【资源管理】开发指南示例代码源码工程开源Sample仓-设计文档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | -------- | ----------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 主页点击 | 位于主页 | 点击文本 | 打印log日志,改变主页文本显示 | 是 | Pass | +| 资源文件列表显示 | 位于主页 | | 显示资源文件列表 | 是 | Pass | +| 是否位于资源目录显示 | 位于主页 | | 显示资源文件是否位于资源目录 | 是 | Pass | +| 资源文件内容显示 | 位于主页 | | 显示资源文件内容 | 是 | Pass | +| 资源文件描述符显示 | 位于主页 | | 显示资源文件描述符 | 是 | Pass | diff --git a/ResourceManagement/RawFile/screenshots/.gitkeep b/ResourceManagement/RawFile/screenshots/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/ResourceManagement/RawFile/screenshots/RawFile_Index1.png b/ResourceManagement/RawFile/screenshots/RawFile_Index1.png new file mode 100644 index 0000000000000000000000000000000000000000..9aefe5e417ea808a82163e3a20d926a5753a821e Binary files /dev/null and b/ResourceManagement/RawFile/screenshots/RawFile_Index1.png differ diff --git a/ResourceManagement/RawFile/screenshots/RawFile_Index2.png b/ResourceManagement/RawFile/screenshots/RawFile_Index2.png new file mode 100644 index 0000000000000000000000000000000000000000..af4629bdf9a5502f7b65efdfa94b278882bee580 Binary files /dev/null and b/ResourceManagement/RawFile/screenshots/RawFile_Index2.png differ diff --git a/ResourceManagement/RawFile/screenshots/log.png b/ResourceManagement/RawFile/screenshots/log.png new file mode 100644 index 0000000000000000000000000000000000000000..bb6ae558718334d8c2e07c2eab3c41dd770ca6fa Binary files /dev/null and b/ResourceManagement/RawFile/screenshots/log.png differ