diff --git a/CoreFile/AppFileBackup/.gitignore b/CoreFile/AppFileBackup/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CoreFile/AppFileBackup/.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/CoreFile/AppFileBackup/AppScope/app.json5 b/CoreFile/AppFileBackup/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..37bccd13dd46c0e720b87432b8556da28a2aa11a --- /dev/null +++ b/CoreFile/AppFileBackup/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.appfilebackup", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CoreFile/AppFileBackup/AppScope/resources/base/element/string.json b/CoreFile/AppFileBackup/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3332f8b420e0d7d92da4d019d7138e851d40a518 --- /dev/null +++ b/CoreFile/AppFileBackup/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AppFileBackup" + } + ] +} diff --git a/CoreFile/AppFileBackup/AppScope/resources/base/media/app_icon.png b/CoreFile/AppFileBackup/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CoreFile/AppFileBackup/AppScope/resources/base/media/app_icon.png differ diff --git a/CoreFile/AppFileBackup/README_zh.md b/CoreFile/AppFileBackup/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..0729879a03f30e8198b976db01ce4c8596e714d4 --- /dev/null +++ b/CoreFile/AppFileBackup/README_zh.md @@ -0,0 +1,73 @@ +# 应用触发数据备份恢复(仅对系统应用开放) + +## 介绍 + +仅系统应用可以触发数据备份恢复,触发后备份恢复框架会确认各个应用是否接入了数据备份恢复。如果应用已接入,备份恢复框架将会根据应用的配置文件备份、恢复数据。本实例实现了获取能力文件、应用备份数据和应用恢复数据三大功能,应用还涉及到权限申请方式和系统应用签名,该工程中展示的代码详细描述可查如下链接。 + +- [获取能力文件](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/file-management/app-file-backup.md#获取能力文件) +- [应用备份数据](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/file-management/app-file-backup.md#应用备份数据) +- [应用恢复数据](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/file-management/app-file-backup.md#应用恢复数据) + +## 效果预览 + +| | +| :------------------------------------------------: | +| | + +使用说明: + +1. 本应用主要用于拉起应用数据备份,依赖于FileBackuoExtension应用,在使用前确保安装FileBackuoExtension应用。 +2. 启动该应用后,通过点击相关的按钮可以拉起FileBackuoExtensiony应用的数据备份和恢复,备份和恢复将会按照FileBackuoExtensiony应用中配置的数据 备份和恢复框架进行。 + +## 工程目录 + +``` +├──entry/src/main +| ├──ets +| | ├──backuprestore +| | | └──BackupRestore.ets // 备份恢复函数封装 +| | ├──commom +| | | ├──Logger.ts // 日志工具 +| | ├──entryability +| | | └──EntryAbility.ets // 程序入口类 +| | ├──entrybackupability +| | | └──EntryBackupAbility.ets +| | └──pages // 页面文件 +| | └──Index.ets // 主界面 +| ├──resources // 资源文件目录 +``` + +## 具体实现 + +1. 导入依赖模块@ohos.file.backup,申请系统权限ohos.permission.BACKUP,详情请参考:[权限申请的方式](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/determine-application-mode.md) +2. 获取能力文件需要调用backup.getLocalCapabilities,函数封装在BackupRestore.ets。 +3. 启动应用备份过程中,备份恢复服务会将应用的数据打包成文件,通过创建实例时所注册的回调onFileReady接口返回文件句柄。 +4. 备份恢复服务会根据开发者调用getFileHandle的请求内容,将应用待恢复数据的文件句柄,通过创建实例时注册的回调onFileReady]接口返回。 + +## 相关权限 + +| 权限名 | 权限说明 | 级别 | +| ---------------------- | -------------------------- | ------------ | +| ohos.permission.BACKUP | 允许应用拥有备份恢复能力。 | system_basic | + +## 依赖 + +该应用作为系统级应用程序,为了实现备份和恢复功能,必须预先安装文件备份扩展应用。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568。 +2. 本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.58,镜像版本号:OpenHarmony 5.1.0.51。 +3. 本示例需要使用DevEco Studio 5. 1Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 +4. 本示例涉及部分接口需要配置系统应用签名,可以参考[特殊权限配置方法](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/hapsigntool-overview.md) ,把配置文件中的“apl”字段信息改为“system_basic”。 + +## 下载 + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/CoreFile/AppFileBackup > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` + diff --git a/CoreFile/AppFileBackup/build-profile.json5 b/CoreFile/AppFileBackup/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed6ac10fe418243a87b782e58e43e83578977471 --- /dev/null +++ b/CoreFile/AppFileBackup/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * 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": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "compatibleSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "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/CoreFile/AppFileBackup/code-linter.json5 b/CoreFile/AppFileBackup/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/CoreFile/AppFileBackup/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/.gitignore b/CoreFile/AppFileBackup/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/build-profile.json5 b/CoreFile/AppFileBackup/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * 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": { + }, + "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/CoreFile/AppFileBackup/entry/hvigorfile.ts b/CoreFile/AppFileBackup/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/entry/obfuscation-rules.txt b/CoreFile/AppFileBackup/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/entry/oh-package.json5 b/CoreFile/AppFileBackup/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/CoreFile/AppFileBackup/entry/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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/CoreFile/AppFileBackup/entry/src/main/ets/backuprestore/BackupRestore.ets b/CoreFile/AppFileBackup/entry/src/main/ets/backuprestore/BackupRestore.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f6562491465b9965297877775dcf86dadab5aa5 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/ets/backuprestore/BackupRestore.ets @@ -0,0 +1,251 @@ +/* + * 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 get_local_cap_ability] +// [Start session_backup] +// [Start session_restore] +import { fileIo as fs } from '@kit.CoreFileKit'; +import { backup } from '@kit.CoreFileKit'; +import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@ohos.base'; +// [StartExclude session_restore] +// [StartExclude session_backup] +// [StartExclude get_local_cap_ability] +import { ReadOptions } from '@kit.CoreFileKit'; +import buffer from '@ohos.buffer'; +import Logger from '../common/Logger'; + +const BUFFER: number = 1024; // 读写文件的缓冲区 +// [EndExclude get_local_cap_ability] +// [EndExclude session_backup] +// [EndExclude session_restore] + +// 请在组件内获取context,确保this.getUIContext().getHostContext()返回结果为UIAbilityContext +let context = this.getUIContext().getHostContext() as common.UIAbilityContext; +let filesDir = context.filesDir; + +// [StartExclude session_backup] +// [StartExclude session_restore] +// 获取能力文件 +export async function getLocalCapabilities(): Promise { + try { + let fileData = await backup.getLocalCapabilities(); + console.info('getLocalCapabilities success'); + let fpath = filesDir + '/localCapabilities.json'; + fs.copyFileSync(fileData.fd, fpath); + // [StartExclude get_local_cap_ability] + let file = fs.openSync(fpath, fs.OpenMode.READ_WRITE); + // 从文件中读取一段内容 + let arrayBuffer = new ArrayBuffer(BUFFER); + let readOptions: ReadOptions = { + offset: 0, // 从文件的开头开始读取 + length: arrayBuffer.byteLength + }; + let readLen = fs.readSync(file.fd, arrayBuffer, readOptions); + // 这个 buf 对象是 arrayBuffer 中从位置 0 开始的前 readLen 字节 + let buf = buffer.from(arrayBuffer, 0, readLen); + console.info('the content of file: ' + buf.toString()); + // [EndExclude get_local_cap_ability] + fs.closeSync(fileData.fd); + } catch (error) { + console.error(`getLocalCapabilities failed with err, code is ${err.code}, message is ${err.message}`); + } +} +// [End get_local_cap_ability] +// [EndExclude session_backup] + +// 应用备份数据 +// 创建SessionBackup类的实例用于备份数据 +let gSession: backup.SessionBackup; + +function createSessionBackup(): backup.SessionBackup { + let generalCallbacks: backup.GeneralCallbacks = { + // onFileReady为服务回调给应用侧数据完成的通知,建议开发者在该接口内不要进行过多的耗时实现,可以通过异步线程实现file.fd数据的处理 + onFileReady: (err: BusinessError, file: backup.File) => { + if (err) { + console.error(`onFileReady err, code is ${err.code}, message is ${err.message}`); + } + try { + let bundlePath = filesDir + '/' + file.bundleName; + if (!fs.accessSync(bundlePath)) { + fs.mkdirSync(bundlePath); + } + // 此处执行copyFileSync会多一次内存拷贝,开发者可以直接使用onFileReady的file.fd来进行数据处理,处理完成后close即可,这样会减少内存消耗 + fs.copyFileSync(file.fd, bundlePath + `/${file.uri}`); + fs.closeSync(file.fd); + console.info('onFileReady success'); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`onFileReady failed. Code: ${err.code}, message: ${err.message}`); + } + }, + onBundleBegin: (err: BusinessError, bundleName: string) => { + if (err) { + console.error(`onBundleBegin err, code is ${err.code}, message is ${err.message}`); + } else { + console.info('onBundleBegin bundleName: ' + bundleName); + } + }, + onBundleEnd: (err: BusinessError, bundleName: string) => { + if (err) { + console.error(`onBundleEnd err, code is ${err.code}, message is ${err.message}`); + } else { + console.info('onBundleEnd bundleName: ' + bundleName); + } + }, + onAllBundlesEnd: (err: BusinessError) => { + if (err) { + console.error(`onAllBundlesEnd err, code is ${err.code}, message is ${err.message}`); + } else { + console.info('onAllBundlesEnd'); + } + }, + onBackupServiceDied: () => { + console.info('onBackupServiceDied'); + }, + onResultReport: (bundleName: string, result: string) => { + console.info('onResultReport bundleName: ' + bundleName); + console.info('onResultReport result: ' + result); + }, + onProcess: (bundleName: string, process: string) => { + console.info('onProcess bundleName: ' + bundleName); + console.info('onProcess result: ' + process); + } + } + let sessionBackup = new backup.SessionBackup(generalCallbacks); + return sessionBackup; +} + +// [StartExclude session_backup] +export async function release() { + try { + await gSession.release(); + console.info('release success'); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`release err, code is ${err.code}, message is ${err.message}`); + } +} +// [EndExclude session_backup] +export async function sessionBackup(): Promise { + gSession = createSessionBackup(); + // 此处可根据backup.getLocalCapabilities()提供的能力文件,选择需要备份的应用 + // 也可直接根据应用包名称进行备份 + const backupApps: string[] = [ + 'com.samples.filebackupextension', + ] + await gSession.appendBundles(backupApps); + console.info('appendBundles success'); +} +// [End session_backup] +// [EndExclude session_restore] +// 应用数据恢复 +// 创建SessionRestore类的实例用于恢复数据 +let gSessionRestore: backup.SessionRestore; +let initMap = new Map(); +let testFileNum = 2; // 初始化文件个数 +let testBundleName = 'com.samples.filebackupextension'; // 测试包名 +initMap.set(testBundleName, testFileNum); +let countMap = new Map(); +countMap.set(testBundleName, 0); // 初始化计数 + +async function publishFile(file: backup.File): Promise { + console.info('start publishFile'); + let fileMeta: backup.FileMeta = { + bundleName: file.bundleName, + uri: '' + } + await gSessionRestore.publishFile(fileMeta); +} + +function createSessionRestore(): backup.SessionRestore { + let generalCallbacks: backup.GeneralCallbacks = { + onFileReady: (err: BusinessError, file: backup.File) => { + if (err) { + console.error(`onFileReady err, code is ${err.code}, message is ${err.message}`); + } + // 此处开发者请根据实际场景待恢复文件存放位置进行调整 bundlePath + let bundlePath: string = `${filesDir}/${file.bundleName}/`; + if (!fs.accessSync(bundlePath)) { + console.error('onFileReady bundlePath err : ' + bundlePath); + } + console.info('fd : ' + file.fd); + let targetPath = `${bundlePath}${file.uri}`; + fs.copyFileSync(targetPath, file.fd); + fs.closeSync(file.fd); + let currentCount = countMap.get(file.bundleName) || 0; // 如果没有找到对应的计数,则默认返回 0 + countMap.set(file.bundleName, ++currentCount); + // 恢复数据传输完成后,会通知服务端文件准备就绪 + if (countMap.get(file.bundleName) == initMap.get(file.bundleName)) { // 每个包的所有文件收到后触发publishFile + publishFile(file); + } + console.info('onFileReady success'); + }, + onBundleBegin: (err: BusinessError, bundleName: string) => { + if (err) { + console.error(`onBundleBegin failed with err, code is ${err.code}, message is ${err.message}`); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err: BusinessError, bundleName: string) => { + if (err) { + console.error(`onBundleEnd failed with err, code is ${err.code}, message is ${err.message}`); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err: BusinessError) => { + if (err) { + console.error(`onAllBundlesEnd failed with err, code is ${err.code}, message is ${err.message}`); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + }, + onResultReport: (bundleName: string, result: string) => { + console.info('onResultReport bundleName: ' + bundleName); + console.info('onResultReport result: ' + result); + }, + onProcess: (bundleName: string, process: string) => { + console.info('onProcess bundleName: ' + bundleName); + console.info('onProcess result: ' + process); + } + } + let sessionRestore = new backup.SessionRestore(generalCallbacks); + return sessionRestore; +} + +export async function sessionRestore(): Promise { + gSessionRestore = createSessionRestore(); + const restoreApps: string[] = [ + 'com.samples.filebackupextension' + ]; + // 能力文件的获取方式可以根据开发者实际场景进行调整。此处仅为请求示例 + // 开发者也可以根据能力文件内容的结构示例,自行构造能力文件内容 + let fileDat = await backup.getLocalCapabilities(); + await gSessionRestore.appendBundles(fileDat.fd, restoreApps); + console.info('appendBundles success'); + // 添加需要恢复的应用成功后,请根据需要恢复的应用名称,调用getFileHandle接口获取待恢复应用数文件的文件句柄 + // 应用待恢复数据文件数请依据实际备份文件个数为准,此处仅为请求示例 + let handle: backup.FileMeta = { + bundleName: restoreApps[0], + uri: 'manage.json' + }; + await gSessionRestore.getFileHandle(handle); + handle.uri = 'part.0.tar'; + await gSessionRestore.getFileHandle(handle); + console.info('getFileHandle success'); +} +// [End session_restore] diff --git a/CoreFile/AppFileBackup/entry/src/main/ets/common/Logger.ts b/CoreFile/AppFileBackup/entry/src/main/ets/common/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..8c439f8a1ece09db4277ec28b978ab4499dd3a59 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/ets/common/Logger.ts @@ -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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +export class Logger { + private domain: number; + private prefix: string = '[Sample_AppFileBackup]'; + private format: string = '%{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0x0000; // 应用的编码 + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]): void { + hilog.fatal(this.domain, this.prefix, this.format, args); + } + + isLoggable(level: number): void { + hilog.isLoggable(this.domain, this.prefix, level); + } +} + +export default new Logger('[Sample_AppFileBackup]'); + diff --git a/CoreFile/AppFileBackup/entry/src/main/ets/entryability/EntryAbility.ets b/CoreFile/AppFileBackup/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CoreFile/AppFileBackup/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/entry/src/main/ets/pages/Index.ets b/CoreFile/AppFileBackup/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8eab2c1f8cca90c55b294573539079a9f0e6740e --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,73 @@ +/* + * 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 { getLocalCapabilities, sessionBackup, sessionRestore, release } from '../backuprestore/BackupRestore'; + +let MARGIN = 12; // 组件间的间隔 + +@Entry +@Component +struct FileBackup { + @State message: string = ''; + + build() { + Column() { + TextArea({ + text: this.message, + placeholder: '', + }) + .width('100%') + .height('45%') + Row() { + Button($r('app.string.applicationTriggersDataBackup')) + .width('40%') + .height('100%') + .margin(MARGIN) + .onClick(() => { + sessionBackup(); + }) + Button($r('app.string.applicationTriggersDataReStore')) + .width('40%') + .height('100%') + .margin(MARGIN) + .onClick(() => { + sessionRestore(); + }) + } + .width('80%') + .height('10%') + .margin(MARGIN) + + Row() { + Button($r('app.string.releaseBackup')) + .width('40%') + .height('100%') + .margin(MARGIN) + .onClick(() => { + release(); + }) + Button($r('app.string.capabilityDocumentation')) + .width('40%') + .height('100%') + .margin(MARGIN) + .onClick(() => { + getLocalCapabilities(); + }) + } + .width('80%') + .height('10%') + } + } +} diff --git a/CoreFile/AppFileBackup/entry/src/main/module.json5 b/CoreFile/AppFileBackup/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3e0bb8ef38bda50eda925b3f44eae8fffe3fcc34 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/module.json5 @@ -0,0 +1,79 @@ +/* + * 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" + } + ] + } + ], + // [Start request_permission_backup] + "requestPermissions": [ + { + "name": "ohos.permission.BACKUP", + "usedScene": { + "abilities": [ + "FormAbility" + ], + "when": "always" + } + } + ] + // [End request_permission_backup] + } +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/main/resources/base/element/color.json b/CoreFile/AppFileBackup/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/entry/src/main/resources/base/element/string.json b/CoreFile/AppFileBackup/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7328a720bf822e672bdd7ee48d904a39ce3fc02b --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AppBackup" + }, + { + "name": "capabilityDocumentation", + "value": "获取能力文件" + }, + { + "name": "applicationTriggersDataBackup", + "value": "应用触发数据备份" + }, + { + "name": "applicationTriggersDataReStore", + "value": "应用触发数据恢复" + }, + { + "name": "releaseBackup", + "value": "结束备份服务" + }, + { + "name": "deleteFile", + "value": "文件删除" + } + ] +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/main/resources/base/media/background.png b/CoreFile/AppFileBackup/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CoreFile/AppFileBackup/entry/src/main/resources/base/media/background.png differ diff --git a/CoreFile/AppFileBackup/entry/src/main/resources/base/media/foreground.png b/CoreFile/AppFileBackup/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CoreFile/AppFileBackup/entry/src/main/resources/base/media/foreground.png differ diff --git a/CoreFile/AppFileBackup/entry/src/main/resources/base/media/layered_image.json b/CoreFile/AppFileBackup/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/entry/src/main/resources/base/media/startIcon.png b/CoreFile/AppFileBackup/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CoreFile/AppFileBackup/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CoreFile/AppFileBackup/entry/src/main/resources/base/profile/backup_config.json b/CoreFile/AppFileBackup/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/main/resources/base/profile/main_pages.json b/CoreFile/AppFileBackup/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CoreFile/AppFileBackup/entry/src/main/resources/en_US/element/string.json b/CoreFile/AppFileBackup/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a4bcd322afa4f5d03fcde26d7c195f5560bf49c3 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AppBackup" + }, + { + "name": "capabilityDocumentation", + "value": "capabilityDocumentation" + }, + { + "name": "applicationTriggersDataBackup", + "value": "applicationTriggersDataBackup" + }, + { + "name": "applicationTriggersDataReStore", + "value": "applicationTriggersDataRestore" + }, + { + "name": "releaseBackup", + "value": "releaseBackup" + }, + { + "name": "deleteFile", + "value": "deleteFile" + } + ] +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/main/resources/zh_CN/element/string.json b/CoreFile/AppFileBackup/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c6351376efc3cbb20ca61adfcef84ccee0d39594 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AppBackup" + }, + { + "name": "capabilityDocumentation", + "value": "获取能力文件" + }, + { + "name": "applicationTriggersDataBackup", + "value": "应用触发数据备份" + }, + { + "name": "applicationTriggersDataReStore", + "value": "应用触发数据恢复" + }, + { + "name": "releaseBackup", + "value": "结束备份服务" + }, + { + "name": "deleteFile", + "value": "文件删除" + } + ] +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/mock/mock-config.json5 b/CoreFile/AppFileBackup/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/ohosTest/ets/test/FileBackup.test.ets b/CoreFile/AppFileBackup/entry/src/ohosTest/ets/test/FileBackup.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..65ef84741d8882eb307f61d0f37067365c4d2992 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/ohosTest/ets/test/FileBackup.test.ets @@ -0,0 +1,183 @@ +/* + * 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 { describe, it, expect } from '@ohos/hypium'; +import { Driver, ON, Component, abilityDelegatorRegistry } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DELAY_TIME = 1500; // 延时1.5秒 +const TAG = '[Sample_AppFileBackup]'; +const DOMAIN = 0xF811; +const BUNDLE = 'AppFileBackup_'; + +const DELEGATOR = abilityDelegatorRegistry.getAbilityDelegator(); +const BUNDLENAME = abilityDelegatorRegistry.getArguments().bundleName; +const ABILITYDELEGATOR = abilityDelegatorRegistry.getAbilityDelegator(); + +async function getResourceString(resource: Resource): Promise { + let manage = ABILITYDELEGATOR.getAppContext().resourceManager; + let text = await manage.getStringValue(resource); + return text; +} + +export default function FileBackupRestoreTest() { + describe('FileBackupTest', () => { + /** + * @tc.number StartAbility_001 + * @tc.name StartAbility_001 + * @tc.desc 启动Ability + */ + it(BUNDLE + 'StartAbility_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin'); + // start tested ability + const want: Want = { + bundleName: BUNDLENAME, + abilityName: 'EntryAbility' + }; + await DELEGATOR.startAbility(want); + // check top display ability + let driver: Driver = Driver.create(); + await driver.delayMs(DELAY_TIME); + const ability: UIAbility = await DELEGATOR.getCurrentTopAbility(); + hilog.info(DOMAIN, TAG, BUNDLE + 'get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + done(); + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end'); + }) + /** + * @tc.number FileBackup_001 + * @tc.name FileBackup_001 + * @tc.desc 文件的备份 + */ + it(BUNDLE + 'FileBackup_001', 0, async () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'FileBackup_001 begin'); + let str = await getResourceString($r('app.string.applicationTriggersDataBackup')); + let driver: Driver = Driver.create(); + await driver.assertComponentExist(ON.text(str)); + hilog.info(DOMAIN, TAG, BUNDLE + 'Apply to trigger file data backup'); + let button: Component = await driver.findComponent(ON.text(str)); + await button.click(); + await driver.delayMs(DELAY_TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'FileBackup_001 end'); + }) + /** + * @tc.number FileBackup_002 + * @tc.name FileBackup_002 + * @tc.desc 结束备份服务 + */ + it(BUNDLE + 'FileBackup_002', 0, async () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'FileBackup_002 begin'); + let str = await getResourceString($r('app.string.releaseBackup')); + let driver: Driver = Driver.create(); + await driver.assertComponentExist(ON.text(str)); + hilog.info(DOMAIN, TAG, BUNDLE + 'End backup service'); + let button: Component = await driver.findComponent(ON.text(str)); + await button.click(); + await driver.delayMs(DELAY_TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'FileBackup_002 end'); + }) + /** + * @tc.number FileRestore_001 + * @tc.name FileRestore_001 + * @tc.desc 启动备份应用 + */ + it(BUNDLE + 'FileRestore_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'FileRestore_001 begin'); + // start Restore ability + const want: Want = { + bundleName: 'com.samples.filebackupextension', + abilityName: 'EntryAbility' + }; + await DELEGATOR.startAbility(want); + let driver: Driver = Driver.create(); + await driver.delayMs(DELAY_TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'Start fileBackupExtension ability'); + done(); + hilog.info(DOMAIN, TAG, BUNDLE + 'FileRestore_001 end'); + }) + /** + * @tc.number FileRestore_002 + * @tc.name FileRestore_002 + * @tc.desc 删除数据文件 + */ + it(BUNDLE + 'FileRestore_002', 0, async () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'FileRestore_002 begin'); + let str = await getResourceString($r('app.string.deleteFile')); + let driver: Driver = Driver.create(); + await driver.assertComponentExist(ON.text(str)); + hilog.info(DOMAIN, TAG, BUNDLE + 'Apply to trigger file data backup'); + let button: Component = await driver.findComponent(ON.text(str)); + await button.click(); + await driver.delayMs(DELAY_TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'FileRestore_002 end'); + }) + /** + * @tc.number StartAbility_002 + * @tc.name StartAbility_002 + * @tc.desc 启动自身应用以触发数据恢复 + */ + it(BUNDLE + 'StartAbility_002', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_002 begin'); + const want: Want = { + bundleName: BUNDLENAME, + abilityName: 'EntryAbility' + }; + await DELEGATOR.startAbility(want); + let driver: Driver = Driver.create(); + await driver.delayMs(DELAY_TIME); + const ability: UIAbility = await DELEGATOR.getCurrentTopAbility(); + hilog.info(DOMAIN, TAG, BUNDLE + 'get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + done(); + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_002 end'); + }) + /** + * @tc.number FileRestore_003 + * @tc.name FileRestore_003 + * @tc.desc 恢复数据文件 + */ + it(BUNDLE + 'FileRestore_003', 0, async () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'FileRestore_003 begin'); + let str = await getResourceString($r('app.string.applicationTriggersDataReStore')); + let driver: Driver = Driver.create(); + await driver.assertComponentExist(ON.text(str)); + hilog.info(DOMAIN, TAG, BUNDLE + 'Apply to trigger file data backup'); + let button: Component = await driver.findComponent(ON.text(str)); + await button.click(); + await driver.delayMs(DELAY_TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'FileRestore_003 end'); + }) + /** + * @tc.number StartAbility_003 + * @tc.name StartAbility_003 + * @tc.desc + */ + it(BUNDLE + 'StartAbility_003', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_003 begin'); + // start Restore ability + const want: Want = { + bundleName: 'com.samples.filebackupextension', + abilityName: 'EntryAbility' + }; + let driver: Driver = Driver.create(); + await driver.delayMs(DELAY_TIME); + await DELEGATOR.startAbility(want); + hilog.info(DOMAIN, TAG, BUNDLE + 'get top ability'); + done(); + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_003 end'); + }) + }) +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/ohosTest/ets/test/List.test.ets b/CoreFile/AppFileBackup/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f94d95c7b5275a340f55ed79a37148f3fff9ab13 --- /dev/null +++ b/CoreFile/AppFileBackup/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 FileBackupTest from './FileBackup.test'; + +export default function testsuite() { + FileBackupTest(); +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/ohosTest/module.json5 b/CoreFile/AppFileBackup/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/entry/src/test/List.test.ets b/CoreFile/AppFileBackup/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/entry/src/test/LocalUnit.test.ets b/CoreFile/AppFileBackup/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CoreFile/AppFileBackup/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/CoreFile/AppFileBackup/hvigor/hvigor-config.json5 b/CoreFile/AppFileBackup/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/hvigorfile.ts b/CoreFile/AppFileBackup/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/CoreFile/AppFileBackup/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/CoreFile/AppFileBackup/oh-package.json5 b/CoreFile/AppFileBackup/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/CoreFile/AppFileBackup/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.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/CoreFile/AppFileBackup/ohosTest.md b/CoreFile/AppFileBackup/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..84cbbc452fa8ad54bf9b7f567469c0fae44dd0c3 --- /dev/null +++ b/CoreFile/AppFileBackup/ohosTest.md @@ -0,0 +1,15 @@ +# 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------- | ------------------------------------------- | ---- | ---------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | \ | 应用被拉起 | 是 | pass | +| 应用触发数据备份 | FileBackupExtension应用的文件成功创建 | \ | 日志输出备份流程 | 是 | pass | +| 退出备份恢复服务 | 备份会话已经注册 | \ | 退出备份恢复服务 | 是 | pass | +| 拉起FileBackupExtension应用 | 应用已安装 | \ | 成功拉起应用 | 是 | pass | +| 删除数据文件 | FileBackupExtension应用的文件已经创建且备份 | \ | 文件被删除 | 是 | pass | +| 拉起本应用 | 应用已安装 | \ | 应用被拉起 | 是 | pass | +| 应用触发数据恢复 | 数据文件完成备份 | \ | 日志输出恢复流程 | 是 | pass | +| 查看文件是否恢复成功 | FileBackupExtension应用已安装 | \ | 文件恢复并显示 | 是 | pass | + diff --git a/CoreFile/AppFileBackup/screenshots/start.jpg b/CoreFile/AppFileBackup/screenshots/start.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2312975def33f372b507f273b18a61a86b975993 Binary files /dev/null and b/CoreFile/AppFileBackup/screenshots/start.jpg differ diff --git a/CoreFile/FileBackupExtension/.gitignore b/CoreFile/FileBackupExtension/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CoreFile/FileBackupExtension/.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/CoreFile/FileBackupExtension/AppScope/app.json5 b/CoreFile/FileBackupExtension/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..08891bc0f14caa41b0f16ec8621248b1d8942036 --- /dev/null +++ b/CoreFile/FileBackupExtension/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.filebackupextension", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CoreFile/FileBackupExtension/AppScope/resources/base/element/string.json b/CoreFile/FileBackupExtension/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..57edf168387dd07561e5d29380f455d62df5a64b --- /dev/null +++ b/CoreFile/FileBackupExtension/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "FileBackupExtension" + } + ] +} diff --git a/CoreFile/FileBackupExtension/AppScope/resources/base/media/app_icon.png b/CoreFile/FileBackupExtension/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CoreFile/FileBackupExtension/AppScope/resources/base/media/app_icon.png differ diff --git a/CoreFile/FileBackupExtension/README_zh.md b/CoreFile/FileBackupExtension/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..95be0da42250df1b758d8c67db502fbbfc5a2184 --- /dev/null +++ b/CoreFile/FileBackupExtension/README_zh.md @@ -0,0 +1,72 @@ +# 应用接入数据备份恢复 + +## 介绍 + +应用接入数据备份恢复需要通过配置BackupExtensionAbility实现。 + +BackupExtensionAbility,是[Stage模型](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/application-models/stage-model-development-overview.md)模型中扩展组件[ ExtensionAbility](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/application-models/extensionability-overview.md)的派生类。开发者可以通过修改配置文件定制备份恢复框架的行为,包括是否允许备份恢复,备份哪些文件等。 + +本sample主要给备份恢复服务提供应用,用于生成数据、删除数据和备份恢复后显示数据。该工程中展示的代码详细描述可查如下链接。 + +- [应用接入数据备份恢复](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/file-management/app-file-backup-extension.md) + +## 效果预览 + +| 初始界面 | 文件创建 | 文件删除 | 文件恢复后显示 | +| -------------------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------ | ------------------------------------------------------- | +| | | | | + +使用说明: + +1. 点击按钮“文件创建”,应用会生成5个txt文件,大小在1Byte到1024Byte之间,用于校验备份和恢复的数据为同一数据。 +2. 本应用仅适用于生成和显示数据,具体的备份和恢复的操作需要另外的应用AppFileBackup来执行。 +3. 按钮“文件删除”操作用户在备份恢复的测试验证过程中删除文件。 + +## 工程目录 +``` +entry/src/main/ets/ +|---Application +|---Common +| |---Logger.ts // 日志工具 +| |---BackupExtension.ets // 备份恢复类 +|---entruability +| |---EntryAbility.ts // Ability类 +|---entrybackability +| |---EntryBackupAbility.ts +|---fileFs +| |---CreateFile.ts // 文件的创建和删除封装 +|---pages +| |---Index.ets // 首页 +``` +## 具体实现 + +1. 备份恢复框架的开发步骤,请参考介绍中应用接入数据备份恢复链接。 +1. 应用封装CreateFile类,其中包含个函数,用于文件的创建和删除,具体代码实现请参考:CreateFile.ets。 + +## 相关权限 + +无 + +## 依赖 + +该应用为备份恢复服务的框架实现,仅进行文件的创建和删除,不涉及备份和恢复的具体流程,数据文件的备份和恢复依赖于AppFileBackup应用。 + +## 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.58,镜像版本号:OpenHarmony 5.0.2.58。 + +3.本示例需要使用DevEco Studio 5. 1Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +## 下载 + +如需单独下载本工程,执行如下命令: +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/CoreFile/FileBackupExtension > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master + +``` diff --git a/CoreFile/FileBackupExtension/build-profile.json5 b/CoreFile/FileBackupExtension/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed6ac10fe418243a87b782e58e43e83578977471 --- /dev/null +++ b/CoreFile/FileBackupExtension/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * 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": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "compatibleSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "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/CoreFile/FileBackupExtension/code-linter.json5 b/CoreFile/FileBackupExtension/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/CoreFile/FileBackupExtension/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/.gitignore b/CoreFile/FileBackupExtension/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/build-profile.json5 b/CoreFile/FileBackupExtension/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * 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": { + }, + "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/CoreFile/FileBackupExtension/entry/hvigorfile.ts b/CoreFile/FileBackupExtension/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3d28cb60475cede46d0aa36973096d5544dbcd1 --- /dev/null +++ b/CoreFile/FileBackupExtension/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/CoreFile/FileBackupExtension/entry/obfuscation-rules.txt b/CoreFile/FileBackupExtension/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/CoreFile/FileBackupExtension/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/CoreFile/FileBackupExtension/entry/oh-package.json5 b/CoreFile/FileBackupExtension/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/CoreFile/FileBackupExtension/entry/src/main/ets/common/BackupExtension.ets b/CoreFile/FileBackupExtension/entry/src/main/ets/common/BackupExtension.ets new file mode 100644 index 0000000000000000000000000000000000000000..ea45e99c5bf37c2b2a2e967c95fc6839a00fbd8c --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/ets/common/BackupExtension.ets @@ -0,0 +1,88 @@ +/* + * 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 on_backup_restore] +// [Start on_release] +import { BackupExtensionAbility } from '@kit.CoreFileKit'; +// [StartExclude on_release] +import { BundleVersion } from '@kit.CoreFileKit'; +// [EndExclude on_release] +// [StartExclude on_backup_restore] +import { fileIo } from '@kit.CoreFileKit'; +// [EndExclude on_backup_restore] + +// [StartExclude on_release] +interface ErrorInfo { + type: string, + errorCode: number, + errorInfo: string +} +// [EndExclude on_release] + +// [StartExclude on_backup_restore] +const SCENARIO_BACKUP: number = 1; +const SCENARIO_RESTORE: number = 2; +// 需要清理的临时目录 +let filePath: string = '/data/storage/el2/base/.temp/'; +// [EndExclude on_backup_restore] + +class BackupExt extends BackupExtensionAbility { + // [StartExclude on_release] + //onBackupEx + async onBackupEx(backupInfo: string): Promise { + console.info('onBackupEx ok'); + let errorInfo: ErrorInfo = { + type: 'ErrorInfo', + errorCode: 0, + errorInfo: 'app diy error info' + } + return JSON.stringify(errorInfo); + } + + // onRestoreEx + async onRestoreEx(bundleVersion : BundleVersion, restoreInfo: string): Promise { + console.info(`onRestoreEx begin`); + let errorInfo: ErrorInfo = { + type: 'ErrorInfo', + errorCode: 0, + errorInfo: 'app diy error info' + } + return JSON.stringify(errorInfo); + } + // [EndExclude on_release] + // [StartExclude on_backup_restore] + // onRelease + async onRelease(scenario: number): Promise { + try { + if (scenario == SCENARIO_BACKUP) { + // 备份场景,应用自行实现处理,以清理备份产生的临时文件为例 + console.info(`onRelease begin`); + await fileIo.rmdir(filePath); + console.info(`onRelease end, rmdir succeed`); + } + if (scenario == SCENARIO_RESTORE) { + // 恢复场景,应用自行实现处理,以清理恢复产生的临时文件为例 + console.info(`onRelease begin`); + await fileIo.rmdir(filePath); + console.info(`onRelease end, rmdir succeed`); + } + } catch (error) { + console.error(`onRelease failed with error. Code: ${error.code}, message: ${error.message}`); + } + } + // [EndExclude on_backup_restore] +} +// [End on_backup_restore] +// [End on_release] diff --git a/CoreFile/FileBackupExtension/entry/src/main/ets/common/Logger.ts b/CoreFile/FileBackupExtension/entry/src/main/ets/common/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..fbf4ecb0c07cea0cdd0a221849791c22de1a4976 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/ets/common/Logger.ts @@ -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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +export class Logger { + private domain: number; + private prefix: string = '[Sample_FileBackupExtension]'; + private format: string = '%{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0x0000; // 应用的编码 + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]): void { + hilog.fatal(this.domain, this.prefix, this.format, args); + } + + isLoggable(level: number): void { + hilog.isLoggable(this.domain, this.prefix, level); + } +} + +export default new Logger('[Sample_FileBackupExtension]'); + diff --git a/CoreFile/FileBackupExtension/entry/src/main/ets/entryability/EntryAbility.ets b/CoreFile/FileBackupExtension/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(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'); + } +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CoreFile/FileBackupExtension/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d95efb9994d951c12095d77bdf91811e77a6adc --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,29 @@ +/* + * 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 backup_sample] +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)); + } +} +// [End backup_sample] \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/main/ets/fileFs/CreateFile.ts b/CoreFile/FileBackupExtension/entry/src/main/ets/fileFs/CreateFile.ts new file mode 100644 index 0000000000000000000000000000000000000000..fc6aafa4649a292243bab89797f00e78a2a8017c --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/ets/fileFs/CreateFile.ts @@ -0,0 +1,75 @@ +/* + * 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 Logger from '../common/Logger'; +import { fileIo as fs } from '@kit.CoreFileKit'; +import { BusinessError } from '@ohos.base'; + +const ONE_KILOBYTE: number = 1024; // 1k = 1024B +const FILE_NUM: number = 5; // 创建文件的数量 + +export default class CreatFile { + baseDir: string = AppStorage.get('sanBoxFileDir') + '/TextDir'; + + constructor() { + } + + async createTestFiles(filePath: string): Promise { + try { + let num = FILE_NUM; + if (!fs.accessSync(filePath)) { + fs.mkdirSync(filePath); + } + let dpath = filePath; + Logger.info('sanBoxFileDir = ' + dpath); + Logger.info('num is = ' + num); + for (let i = 0; i < num; i++) { + let myFile = dpath + `/TestFile_${i}.txt`; + Logger.info('readyFile myFile = ' + myFile); + let file = fs.openSync(myFile, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); + fs.writeSync(file.fd, new ArrayBuffer(ONE_KILOBYTE * Math.random())); + fs.closeSync(file); + } + } catch (err) { + let error: BusinessError = err as BusinessError; + Logger.error('Failed to prepare media files, error:' + error.message + error.code); + } + } + + async deleteTestFiles(filePath: string): Promise { + try { + let num = FILE_NUM; + if (!fs.accessSync(filePath)) { + fs.mkdirSync(filePath); + } + let dpath = filePath; + Logger.info('sanBoxFileDir = ' + dpath); + Logger.info('num is = ' + num); + for (let i = 0; i < num; i++) { + let myFile = dpath + `/TestFile_${i}.txt`; + fs.unlink(myFile).then(() => { + Logger.info('remove file succeed'); + }).catch((err: BusinessError) => { + Logger.error('remove file failed with error message: ' + err.message + err.code); + }); + } + } catch (err) { + let error: BusinessError = err as BusinessError; + Logger.error('Failed to prepare media files, error:' + error.message + error.code); + } + } +} + + diff --git a/CoreFile/FileBackupExtension/entry/src/main/ets/pages/Index.ets b/CoreFile/FileBackupExtension/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c828e1b00a90a2608643f6dcb507ad46ae378091 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,144 @@ +/* + * 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 CreateFile from '../fileFs/CreateFile'; +import Logger from '../common/Logger'; +import fs from '@ohos.file.fs'; +import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let context = getContext(this) as common.UIAbilityContext; +let filesDir = context.filesDir; +let countFile = 0; // 文件数量计数初始化 + +@Entry +@Component +struct BackupExample { + createFile = new CreateFile(); + baseDir: string = filesDir; + @State filePathSize: Array = []; + @State showFilePath: Array = []; + + onPageShow() { + try { + if (!fs.accessSync(this.baseDir)) { + fs.mkdirSync(this.baseDir); + // 数组初始化 + this.showFilePath[0] = ''; + this.filePathSize[0] = ''; + return; + } + Logger.info(`readyFileToFileFs successful`); + } catch (e) { + let error: BusinessError = e as BusinessError; + Logger.error(`readyFileToFileFs has failed for: {message: ${error.message}, code: ${error.code}}`); + } + let filenames = fs.listFileSync(this.baseDir); + countFile = filenames.length; + for (let i = 0; i < filenames.length; i++) { + Logger.info('filename:' + filenames[i]); + this.showFilePath[i] = filenames[i]; + let filePath = this.baseDir + '/' + filenames[i]; + this.filePathSize[i] = fs.statSync(filePath).size.toString() + 'Byte'; + Logger.info('arrayFilename: ' + i + this.showFilePath[i].toString()); + } + } + + build() { + Column() { + Text($r('app.string.FileData')) + .fontSize(14) + .fontColor($r('sys.color.font_primary')) + .margin({ top: 8, left: 48, bottom: 8 }) + .id('fileData') + .opacity(0.6) + .align(Alignment.TopStart) + .width('93%') + List({ space: 10, initialIndex: 0 }) { + ForEach(this.showFilePath, (item: string, index?: number) => { + ListItem() { + Column() { + Row() { + Text(' ' + item) + .fontSize(16) + .fontColor($r('sys.color.black')) + .width('70%') + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ left: 20 }) + .id('file' + index) + if (index !== undefined) { + Text(this.filePathSize[index]) + .fontSize(14) + .width('20%') + .textAlign(TextAlign.End) + .fontColor($r('sys.color.black')) + .fontWeight(400) + .margin({ right: 16 }) + .opacity(0.6) + .id('size' + index) + } + } + .width('100%') + .height(56) + + if (this.showFilePath[0] !== '') { + Divider() + .strokeWidth('1vp') + .color($r('sys.color.black')) + .opacity(0.05) + .margin({ left: 24, right: 24 }) + .width('90%') + } + } + .width('100%') + } + }, (item: string) => item) + } + .height('80%') + .width('93%') + .borderRadius(24) + .backgroundColor(0xFFFFFF) + .align(Alignment.Center) + + Row() { + Button($r('app.string.CreateFiles')) + .id('createFiles') + .backgroundColor($r('sys.color.brand')) + .margin(15) + .width('35%') + .borderRadius(20) + .onClick(async () => { + await this.createFile.createTestFiles(this.baseDir); + this.onPageShow(); + }) + Button($r('app.string.FileDelete')) + .backgroundColor($r('sys.color.brand')) + .margin(15) + .width('35%') + .borderRadius(20) + .onClick(async () => { + await this.createFile.deleteTestFiles(this.baseDir); + for (let i = 0; i < countFile; i++) { + this.showFilePath[i] = ''; + } + }) + } + } + .width('100%') + .height('100%') + .backgroundColor('#F1F3F5') + } +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/main/module.json5 b/CoreFile/FileBackupExtension/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f683de16b7ab74290fce217fea27538e3170447b --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/module.json5 @@ -0,0 +1,70 @@ +/* + * 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" + ] + } + ], + "permissions": [ + ] + } + ], + // [Start extension_abilities] + "extensionAbilities": [ + { + "name": "BackupExtension", + "srcEntry": "./ets/common/BackupExtension.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + // [End extension_abilities] + } +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/main/resources/base/element/color.json b/CoreFile/FileBackupExtension/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CoreFile/FileBackupExtension/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/CoreFile/FileBackupExtension/entry/src/main/resources/base/element/string.json b/CoreFile/FileBackupExtension/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c3f27a70fcfacd862b66e5f8712545f3275ae0ec --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "FileBackup" + }, + { + "name": "CreateFiles", + "value": "文件创建" + }, + { + "name": "FileData", + "value": "文件数据" + }, + { + "name": "FilelistWaitingToBeGenerated", + "value": "文件列表正在生成" + }, + { + "name": "FileDelete", + "value": "文件删除" + } + ] +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/background.png b/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/background.png differ diff --git a/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/foreground.png b/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/foreground.png differ diff --git a/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/layered_image.json b/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CoreFile/FileBackupExtension/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/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/startIcon.png b/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CoreFile/FileBackupExtension/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CoreFile/FileBackupExtension/entry/src/main/resources/base/profile/backup_config.json b/CoreFile/FileBackupExtension/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..8c0d561a7345eca6f6c09a118983d0d9e67becf5 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,11 @@ +{ + "allowToBackupRestore": true, + "includes": [ + "data/storage/el2/base/haps/*/files/" + ], + "excludes": [ + "" + ], + "fullBackupOnly": false, + "restoreDeps": "" +} diff --git a/CoreFile/FileBackupExtension/entry/src/main/resources/base/profile/main_pages.json b/CoreFile/FileBackupExtension/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CoreFile/FileBackupExtension/entry/src/main/resources/dark/element/color.json b/CoreFile/FileBackupExtension/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CoreFile/FileBackupExtension/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/CoreFile/FileBackupExtension/entry/src/mock/mock-config.json5 b/CoreFile/FileBackupExtension/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/ohosTest/ets/test/Index.test.ets b/CoreFile/FileBackupExtension/entry/src/ohosTest/ets/test/Index.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..08c87e09a68dffe7f2027022f38f19e6c5f2ec2c --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/ohosTest/ets/test/Index.test.ets @@ -0,0 +1,91 @@ +/* + * 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 { describe, it, expect } from '@ohos/hypium'; +import { Driver, ON, Component, abilityDelegatorRegistry } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DELAY_TIME = 1200; // 延时1.2秒 +const TAG = '[Sample_FileBackupExtension]'; +const DOMAIN = 0xF811; +const BUNDLE = 'FileBackupExtension_'; + +const DELEGATOR = abilityDelegatorRegistry.getAbilityDelegator(); +const BUNDLENAME = abilityDelegatorRegistry.getArguments().bundleName; +const ABILITYDELEGATOR = abilityDelegatorRegistry.getAbilityDelegator(); + +async function getResourceString(resource: Resource): Promise { + let manage = ABILITYDELEGATOR.getAppContext().resourceManager; + let text = await manage.getStringValue(resource); + return text; +} + +export default function IndexTest() { + describe('IndexTest', () => { + /** + * @tc.number StartAbility_001 + * @tc.name StartAbility_001 + * @tc.desc 启动Ability + */ + it(BUNDLE + 'StartAbility_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin'); + // start tested ability + const want: Want = { + bundleName: BUNDLENAME, + abilityName: 'EntryAbility' + }; + await DELEGATOR.startAbility(want); + // check top display ability + const ability: UIAbility = await DELEGATOR.getCurrentTopAbility(); + hilog.info(DOMAIN, TAG, BUNDLE + 'get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('TestAbility'); + done(); + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end'); + }) + /** + * @tc.number FileBackupExtension_001 + * @tc.name FileBackupExtension_001 + * @tc.desc 文件的创建 + */ + it(BUNDLE + 'FileBackupExtension_001', 0, async () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'FileBackupExtension_001 begin'); + let str = await getResourceString($r('app.string.CreateFiles')); + let driver: Driver = Driver.create(); + await driver.assertComponentExist(ON.text(str)); + let button: Component = await driver.findComponent(ON.text(str)); + hilog.info(DOMAIN, TAG, BUNDLE + 'Create the file'); + await button.click(); + await driver.delayMs(DELAY_TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'FileBackupExtension_001 end'); + }) + /** + * @tc.number FileBackupExtension_002 + * @tc.name FileBackupExtension_002 + * @tc.desc 文件删除 + */ + it(BUNDLE + 'FileBackupExtension_002', 0, async () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'FileBackupExtension_002 begin'); + let str = await getResourceString($r('app.string.FileDelete')); + let driver: Driver = Driver.create(); + await driver.assertComponentExist(ON.text(str)); + let button: Component = await driver.findComponent(ON.text(str)); + hilog.info(DOMAIN, TAG, BUNDLE + 'Delete the file'); + await button.click(); + await driver.delayMs(DELAY_TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'FileBackupExtension_002 end'); + }) + }) +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/ohosTest/ets/test/List.test.ets b/CoreFile/FileBackupExtension/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..00cfe9627bd61a31322328fd121fab7f4d2f6d64 --- /dev/null +++ b/CoreFile/FileBackupExtension/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 IndexTest from './Index.test'; + +export default function testsuite() { + IndexTest(); +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/ohosTest/module.json5 b/CoreFile/FileBackupExtension/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CoreFile/FileBackupExtension/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/CoreFile/FileBackupExtension/entry/src/test/List.test.ets b/CoreFile/FileBackupExtension/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/entry/src/test/LocalUnit.test.ets b/CoreFile/FileBackupExtension/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CoreFile/FileBackupExtension/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/CoreFile/FileBackupExtension/hvigor/hvigor-config.json5 b/CoreFile/FileBackupExtension/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/CoreFile/FileBackupExtension/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.1", + "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/CoreFile/FileBackupExtension/hvigorfile.ts b/CoreFile/FileBackupExtension/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..4beb74fe5b573059b972acf9312d33ea1703c016 --- /dev/null +++ b/CoreFile/FileBackupExtension/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/CoreFile/FileBackupExtension/oh-package.json5 b/CoreFile/FileBackupExtension/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9b142d655b140175b33fe2a0c804ca498119f87f --- /dev/null +++ b/CoreFile/FileBackupExtension/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * 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.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/CoreFile/FileBackupExtension/ohosTest.md b/CoreFile/FileBackupExtension/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..5bfa93327d5ba626833fd473c94994ca758745a6 --- /dev/null +++ b/CoreFile/FileBackupExtension/ohosTest.md @@ -0,0 +1,10 @@ +# 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ---------------- | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | \ | 应用被拉起 | 是 | pass | +| 文件创建 | 应用被拉起 | \ | 输出创建的文件 | 是 | pass | +| 文件删除 | 文件已经成功创建 | \ | 文件被删除 | 是 | pass | + diff --git a/CoreFile/FileBackupExtension/screenshots/fileCreate.jpg b/CoreFile/FileBackupExtension/screenshots/fileCreate.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3cf78db1bf3eedf3d0a5abc40e8a94346d5bbc55 Binary files /dev/null and b/CoreFile/FileBackupExtension/screenshots/fileCreate.jpg differ diff --git a/CoreFile/FileBackupExtension/screenshots/fileDelete.jpg b/CoreFile/FileBackupExtension/screenshots/fileDelete.jpg new file mode 100644 index 0000000000000000000000000000000000000000..69661629a3143f1ece356f07943eaa7e528f1260 Binary files /dev/null and b/CoreFile/FileBackupExtension/screenshots/fileDelete.jpg differ diff --git a/CoreFile/FileBackupExtension/screenshots/fileRestore.jpg b/CoreFile/FileBackupExtension/screenshots/fileRestore.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3cf78db1bf3eedf3d0a5abc40e8a94346d5bbc55 Binary files /dev/null and b/CoreFile/FileBackupExtension/screenshots/fileRestore.jpg differ diff --git a/CoreFile/FileBackupExtension/screenshots/start.jpg b/CoreFile/FileBackupExtension/screenshots/start.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c754711035cdae672df8e5951ffe2569aceb9577 Binary files /dev/null and b/CoreFile/FileBackupExtension/screenshots/start.jpg differ diff --git a/CoreFile/PersistPermission/.gitignore b/CoreFile/PersistPermission/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CoreFile/PersistPermission/.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/CoreFile/PersistPermission/AppScope/app.json5 b/CoreFile/PersistPermission/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2637525d9cd4b50b0aeccae3cc443f9d6beda4bf --- /dev/null +++ b/CoreFile/PersistPermission/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.example.persistpermission", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/CoreFile/PersistPermission/AppScope/resources/base/element/string.json b/CoreFile/PersistPermission/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6e88e367c05e70b45cbdca48a5383546aab18458 --- /dev/null +++ b/CoreFile/PersistPermission/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "PersistPermission" + } + ] +} diff --git a/CoreFile/PersistPermission/AppScope/resources/base/media/background.png b/CoreFile/PersistPermission/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/CoreFile/PersistPermission/AppScope/resources/base/media/background.png differ diff --git a/CoreFile/PersistPermission/AppScope/resources/base/media/foreground.png b/CoreFile/PersistPermission/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/CoreFile/PersistPermission/AppScope/resources/base/media/foreground.png differ diff --git a/CoreFile/PersistPermission/AppScope/resources/base/media/layered_image.json b/CoreFile/PersistPermission/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CoreFile/PersistPermission/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/build-profile.json5 b/CoreFile/PersistPermission/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8492b3d734d39bea26372c31042126cc81435f6d --- /dev/null +++ b/CoreFile/PersistPermission/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * 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", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/code-linter.json5 b/CoreFile/PersistPermission/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed05653cca31b61d64cf6471529eaf50d4f70709 --- /dev/null +++ b/CoreFile/PersistPermission/code-linter.json5 @@ -0,0 +1,47 @@ +/* + * 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. + */ + +{ + "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/CoreFile/PersistPermission/entry/.gitignore b/CoreFile/PersistPermission/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CoreFile/PersistPermission/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/build-profile.json5 b/CoreFile/PersistPermission/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6bf0d132e6f78049e712446c63f2633b2d1613d3 --- /dev/null +++ b/CoreFile/PersistPermission/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * 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": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "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/CoreFile/PersistPermission/entry/hvigorfile.ts b/CoreFile/PersistPermission/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/CoreFile/PersistPermission/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. */ +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/obfuscation-rules.txt b/CoreFile/PersistPermission/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/CoreFile/PersistPermission/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/CoreFile/PersistPermission/entry/oh-package.json5 b/CoreFile/PersistPermission/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/CoreFile/PersistPermission/entry/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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/CoreFile/PersistPermission/entry/src/main/ets/entryability/EntryAbility.ets b/CoreFile/PersistPermission/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..62f53acbc95e5be7985f8fb1fe2db591cea260bd --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CoreFile/PersistPermission/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a97e21bd7a15599af76a806695860ff1eb0ebfe --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/main/ets/pages/Index.ets b/CoreFile/PersistPermission/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9be9ebd9f5f66c9328974b2e9d948443aec60ed9 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,57 @@ +/* + * 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 { persistPermissionExample } from '../persistpermission/PersistPermission'; +import { revokePermissionExample } from '../persistpermission/PersistPermission'; +import { activatePermissionExample } from '../persistpermission/PersistPermission'; + +@Entry +@Component +struct Index { + @State message: string = ''; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize($r('app.float.size_15')) + .fontWeight(FontWeight.Bold) + Button($r('app.string.invokeInterfaceButton1')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + persistPermissionExample(); + }) + Button($r('app.string.invokeInterfaceButton2')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + revokePermissionExample(); + }) + Button($r('app.string.invokeInterfaceButton3')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + activatePermissionExample(); + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/main/ets/persistpermission/PersistPermission.ets b/CoreFile/PersistPermission/entry/src/main/ets/persistpermission/PersistPermission.ets new file mode 100644 index 0000000000000000000000000000000000000000..a8fcb13989caf847d31edde99e309cf1140fe309 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/ets/persistpermission/PersistPermission.ets @@ -0,0 +1,116 @@ +/* + * 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 activate_permission_example] +// [Start revoke_permission_example] +// [Start persist_permission_example] +import { BusinessError } from '@kit.BasicServicesKit'; +import { picker } from '@kit.CoreFileKit'; +import { fileShare } from '@kit.CoreFileKit'; + +// [StartExclude activate_permission_example] +// [StartExclude revoke_permission_example] +export async function persistPermissionExample() { + try { + // [StartExclude persist_permission_example] + // [Start can_use_example] + if (!canIUse('SystemCapability.FileManagement.AppFileService.FolderAuthorization')) { + console.error('this api is not supported on this device'); + return; + } + // [End can_use_example] + // [EndExclude persist_permission_example] + let documentSelectOptions = new picker.DocumentSelectOptions(); + let documentPicker = new picker.DocumentViewPicker(); + let uris = await documentPicker.select(documentSelectOptions); + let policyInfo: fileShare.PolicyInfo = { + uri: uris[0], + operationMode: fileShare.OperationMode.READ_MODE, + }; + let policies: fileShare.PolicyInfo[] = [policyInfo]; + fileShare.persistPermission(policies).then(() => { + console.info('persistPermission successfully'); + }).catch((err: BusinessError>) => { + console.error('persistPermission failed with error message: ' + err.message + ', error code: ' + err.code); + if (err.code == 13900001 && err.data) { + for (let i = 0; i < err.data.length; i++) { + console.error('error code : ' + JSON.stringify(err.data[i].code)); + console.error('error uri : ' + JSON.stringify(err.data[i].uri)); + console.error('error reason : ' + JSON.stringify(err.data[i].message)); + } + } + }); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`persistPermission failed with err, Error code: ${err.code}, message: ${err.message}`); + } +} +// [End persist_permission_example] +// [EndExclude revoke_permission_example] +export async function revokePermissionExample() { + try { + let uri = 'file://docs/storage/Users/username/tmp.txt'; + let policyInfo: fileShare.PolicyInfo = { + uri: uri, + operationMode: fileShare.OperationMode.READ_MODE, + }; + let policies: fileShare.PolicyInfo[] = [policyInfo]; + fileShare.revokePermission(policies).then(() => { + console.info('revokePermission successfully'); + }).catch((err: BusinessError>) => { + console.error('revokePermission failed with error message: ' + err.message + ', error code: ' + err.code); + if (err.code == 13900001 && err.data) { + for (let i = 0; i < err.data.length; i++) { + console.error('error code : ' + JSON.stringify(err.data[i].code)); + console.error('error uri : ' + JSON.stringify(err.data[i].uri)); + console.error('error reason : ' + JSON.stringify(err.data[i].message)); + } + } + }); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`revokePermission failed with err, Error code: ${err.code}, message: ${err.message}`); + } +} +// [End revoke_permission_example] +// [EndExclude activate_permission_example] +export async function activatePermissionExample() { + try { + let uri = 'file://docs/storage/Users/username/tmp.txt'; + let policyInfo: fileShare.PolicyInfo = { + uri: uri, + operationMode: fileShare.OperationMode.READ_MODE, + }; + let policies: fileShare.PolicyInfo[] = [policyInfo]; + fileShare.activatePermission(policies).then(() => { + console.info('activatePermission successfully'); + }).catch((err: BusinessError>) => { + console.error('activatePermission failed with error message: ' + err.message + ', error code: ' + err.code); + if (err.code == 13900001 && err.data) { + for (let i = 0; i < err.data.length; i++) { + console.error('error code : ' + JSON.stringify(err.data[i].code)); + console.error('error uri : ' + JSON.stringify(err.data[i].uri)); + console.error('error reason : ' + JSON.stringify(err.data[i].message)); + if (err.data[i].code == fileShare.PolicyErrorCode.PERMISSION_NOT_PERSISTED) { + //可以选择进行持久化后再激活。 + } + } + } + }); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`activatePermission failed with err, Error code: ${err.code}, message: ${err.message}`); + } +} +// [End activate_permission_example] \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/main/module.json5 b/CoreFile/PersistPermission/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..25148c9e0e582c3ed037ae97ca8fad095ec7adb8 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * 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": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/main/resources/base/element/color.json b/CoreFile/PersistPermission/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CoreFile/PersistPermission/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/CoreFile/PersistPermission/entry/src/main/resources/base/element/float.json b/CoreFile/PersistPermission/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..3d7a861509938ed4854066b6aeeedd22770786c2 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/resources/base/element/float.json @@ -0,0 +1,12 @@ +{ + "float": [ + { + "name": "size_15", + "value": "15" + }, + { + "name": "size_20", + "value": "20" + } + ] +} diff --git a/CoreFile/PersistPermission/entry/src/main/resources/base/element/string.json b/CoreFile/PersistPermission/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fbfc735a552639eb417d022113eb988868862076 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "PersistPermission" + }, + { + "name": "invokeInterfaceButton1", + "value": "persistPermission" + }, + { + "name": "invokeInterfaceButton2", + "value": "revokePermission" + }, + { + "name": "invokeInterfaceButton3", + "value": "activatePermission" + } + ] +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/main/resources/base/media/background.png b/CoreFile/PersistPermission/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/CoreFile/PersistPermission/entry/src/main/resources/base/media/background.png differ diff --git a/CoreFile/PersistPermission/entry/src/main/resources/base/media/foreground.png b/CoreFile/PersistPermission/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/CoreFile/PersistPermission/entry/src/main/resources/base/media/foreground.png differ diff --git a/CoreFile/PersistPermission/entry/src/main/resources/base/media/layered_image.json b/CoreFile/PersistPermission/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CoreFile/PersistPermission/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/CoreFile/PersistPermission/entry/src/main/resources/base/media/startIcon.png b/CoreFile/PersistPermission/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CoreFile/PersistPermission/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CoreFile/PersistPermission/entry/src/main/resources/base/profile/backup_config.json b/CoreFile/PersistPermission/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/main/resources/base/profile/main_pages.json b/CoreFile/PersistPermission/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CoreFile/PersistPermission/entry/src/main/resources/dark/element/color.json b/CoreFile/PersistPermission/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CoreFile/PersistPermission/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/CoreFile/PersistPermission/entry/src/mock/mock-config.json5 b/CoreFile/PersistPermission/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/ohosTest/ets/test/Ability.test.ets b/CoreFile/PersistPermission/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * 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, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/ohosTest/ets/test/List.test.ets b/CoreFile/PersistPermission/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/CoreFile/PersistPermission/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/CoreFile/PersistPermission/entry/src/ohosTest/module.json5 b/CoreFile/PersistPermission/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a43680ca704ea9bf17ba9b9f88086a2735012c37 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/ohosTest/module.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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/CoreFile/PersistPermission/entry/src/test/List.test.ets b/CoreFile/PersistPermission/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/entry/src/test/LocalUnit.test.ets b/CoreFile/PersistPermission/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CoreFile/PersistPermission/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/hvigor/hvigor-config.json5 b/CoreFile/PersistPermission/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b8fea3f097bd68b0bc4d87de986d2cb7732c1d9b --- /dev/null +++ b/CoreFile/PersistPermission/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * 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": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | 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 */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "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/CoreFile/PersistPermission/hvigorfile.ts b/CoreFile/PersistPermission/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/CoreFile/PersistPermission/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. */ +} \ No newline at end of file diff --git a/CoreFile/PersistPermission/oh-package.json5 b/CoreFile/PersistPermission/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..69cb43cba3addcee1840403c67405134a2a9102c --- /dev/null +++ b/CoreFile/PersistPermission/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": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/CoreFile/PersistPermission/ohosTest.md b/CoreFile/PersistPermission/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..5659e5d6839ce3c3d55186cf020e168c745aca42 --- /dev/null +++ b/CoreFile/PersistPermission/ohosTest.md @@ -0,0 +1,10 @@ +# 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|---------------------------|--------------------------------------------| ---- | -------------------------- |------| -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | +| 测试persistPermission接口 | 安装应用,进入首页 | | 成功运行 | 否 | Pass | +| 测试revokePermission接口 | 安装应用,进入首页 | | 成功运行 | 否 | pass | +| 测试activatePermission接口 | 安装应用,进入首页 | | 成功运行 | 否 | pass | \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/.gitignore b/CoreFile/UserFile/FileShareDevelopment_C/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/.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/CoreFile/UserFile/FileShareDevelopment_C/AppScope/app.json5 b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b4c2f451bcd9d09fd4a31e44418e01cebae0e2e2 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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.example.filesharedevelopment_c", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/element/string.json b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a2fbd05b2af882f42e60d6e1776e60f680392ee4 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "FileShareDevelopment_C" + } + ] +} diff --git a/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/background.png b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/background.png differ diff --git a/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/foreground.png b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/foreground.png differ diff --git a/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/layered_image.json b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/build-profile.json5 b/CoreFile/UserFile/FileShareDevelopment_C/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9ec668d0151c34f1df85976365151af79338510 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * 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", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "nativeCompiler": "BiSheng", + "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/CoreFile/UserFile/FileShareDevelopment_C/code-linter.json5 b/CoreFile/UserFile/FileShareDevelopment_C/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed05653cca31b61d64cf6471529eaf50d4f70709 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/code-linter.json5 @@ -0,0 +1,47 @@ +/* + * 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. + */ + +{ + "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/CoreFile/UserFile/FileShareDevelopment_C/entry/.gitignore b/CoreFile/UserFile/FileShareDevelopment_C/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/build-profile.json5 b/CoreFile/UserFile/FileShareDevelopment_C/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3974c0bbe91b785fb2f765d1e8ba3cb31e2ae74c --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + }, + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/hvigorfile.ts b/CoreFile/UserFile/FileShareDevelopment_C/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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. */ +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/obfuscation-rules.txt b/CoreFile/UserFile/FileShareDevelopment_C/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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/CoreFile/UserFile/FileShareDevelopment_C/entry/oh-package.json5 b/CoreFile/UserFile/FileShareDevelopment_C/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/CMakeLists.txt b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d518f5c17358b093987b8103d928a18681c8e34a --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(FileShareDevelopment_C) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libohfileshare.so) \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/napi_init.cpp b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5246c30a0f4943a6a30629055c92d42c7d168428 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,266 @@ +/* + * 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. + */ + +#include "napi/native_api.h" +#include +#include +#include + +static napi_value NAPI_OH_FileShare_PersistPermission(napi_env env, napi_callback_info info) +{ + // [Start persist_permission_example] + static const uint32_t policyNum = 2; + char strTestPath1[] = "file://com.example.fileshare/data/storage/el2/base/files/test1.txt"; + char strTestPath2[] = "file://com.example.fileshare/data/storage/el2/base/files/test2.txt"; + FileShare_PolicyInfo policy[policyNum] = { + {strTestPath1, static_cast(strlen(strTestPath1)), FileShare_OperationMode::READ_MODE}, + {strTestPath2, static_cast(strlen(strTestPath2)), FileShare_OperationMode::WRITE_MODE}}; + FileShare_PolicyErrorResult* result = nullptr; + uint32_t resultNum = 0; + napi_value napiResult; + std::string resultStr; + auto ret = OH_FileShare_PersistPermission(policy, policyNum, &result, &resultNum); + if (ret != ERR_OK) { + if (ret == ERR_EPERM && result != nullptr) { + for (uint32_t i = 0; i < resultNum; i++) { + std::cout << "error uri: " << result[i].uri << std::endl; + std::cout << "error code: " << result[i].code << std::endl; + std::cout << "error message: " << result[i].message << std::endl; + // [StartExclude persist_permission_example] + resultStr += "error uri: "; + resultStr += result[i].uri; + resultStr += "\n"; + resultStr += "error code: "; + resultStr += result[i].code; + resultStr += "\n"; + resultStr += "error message: "; + resultStr += result[i].message; + resultStr += "\n"; + // [EndExclude persist_permission_example] + } + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + // [End persist_permission_example] + napi_status status = napi_create_string_utf8(env, resultStr.c_str(), NAPI_AUTO_LENGTH, &napiResult); + if (status != napi_ok) { + return nullptr; + } + return napiResult; +} + +static napi_value NAPI_OH_FileShare_ActivatePermission(napi_env env, napi_callback_info info) +{ + static const uint32_t policyNum = 2; + char strTestPath1[] = "file://com.example.fileshare/data/storage/el2/base/files/test1.txt"; + char strTestPath2[] = "file://com.example.fileshare/data/storage/el2/base/files/test2.txt"; + FileShare_PolicyInfo policy[policyNum] = { + {strTestPath1, static_cast(strlen(strTestPath1)), FileShare_OperationMode::READ_MODE}, + {strTestPath2, static_cast(strlen(strTestPath2)), FileShare_OperationMode::WRITE_MODE}}; + FileShare_PolicyErrorResult* result = nullptr; + uint32_t resultNum = 0; + napi_value napiResult; + std::string resultStr; + // [Start activate_permission_example] + auto ret = OH_FileShare_ActivatePermission(policy, policyNum, &result, &resultNum); + if (ret != ERR_OK) { + if (ret == ERR_EPERM && result != nullptr) { + for (uint32_t i = 0; i < resultNum; i++) { + std::cout << "error uri: " << result[i].uri << std::endl; + std::cout << "error code: " << result[i].code << std::endl; + std::cout << "error message: " << result[i].message << std::endl; + // [StartExclude activate_permission_example] + resultStr += "error uri: "; + resultStr += result[i].uri; + resultStr += "\n"; + resultStr += "error code: "; + resultStr += result[i].code; + resultStr += "\n"; + resultStr += "error message: "; + resultStr += result[i].message; + resultStr += "\n"; + // [EndExclude activate_permission_example] + } + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + // [End activate_permission_example] + napi_status status = napi_create_string_utf8(env, resultStr.c_str(), NAPI_AUTO_LENGTH, &napiResult); + if (status != napi_ok) { + return nullptr; + } + return napiResult; +} + +static napi_value NAPI_OH_FileShare_DeactivatePermission(napi_env env, napi_callback_info info) +{ + static const uint32_t policyNum = 2; + char strTestPath1[] = "file://com.example.fileshare/data/storage/el2/base/files/test1.txt"; + char strTestPath2[] = "file://com.example.fileshare/data/storage/el2/base/files/test2.txt"; + FileShare_PolicyInfo policy[policyNum] = { + {strTestPath1, static_cast(strlen(strTestPath1)), FileShare_OperationMode::READ_MODE}, + {strTestPath2, static_cast(strlen(strTestPath2)), FileShare_OperationMode::WRITE_MODE}}; + FileShare_PolicyErrorResult* result = nullptr; + uint32_t resultNum = 0; + napi_value napiResult; + std::string resultStr; + // [Start deactivate_permission_example] + auto ret = OH_FileShare_DeactivatePermission(policy, policyNum, &result, &resultNum); + if (ret != ERR_OK) { + if (ret == ERR_EPERM && result != nullptr) { + for (uint32_t i = 0; i < resultNum; i++) { + std::cout << "error uri: " << result[i].uri << std::endl; + std::cout << "error code: " << result[i].code << std::endl; + std::cout << "error message: " << result[i].message << std::endl; + // [StartExclude deactivate_permission_example] + resultStr += "error uri: "; + resultStr += result[i].uri; + resultStr += "\n"; + resultStr += "error code: "; + resultStr += result[i].code; + resultStr += "\n"; + resultStr += "error message: "; + resultStr += result[i].message; + resultStr += "\n"; + // [EndExclude deactivate_permission_example] + } + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + // [End deactivate_permission_example] + napi_status status = napi_create_string_utf8(env, resultStr.c_str(), NAPI_AUTO_LENGTH, &napiResult); + if (status != napi_ok) { + return nullptr; + } + return napiResult; +} + +static napi_value NAPI_OH_FileShare_RevokePermission(napi_env env, napi_callback_info info) +{ + static const uint32_t policyNum = 2; + char strTestPath1[] = "file://com.example.fileshare/data/storage/el2/base/files/test1.txt"; + char strTestPath2[] = "file://com.example.fileshare/data/storage/el2/base/files/test2.txt"; + FileShare_PolicyInfo policy[policyNum] = { + {strTestPath1, static_cast(strlen(strTestPath1)), FileShare_OperationMode::READ_MODE}, + {strTestPath2, static_cast(strlen(strTestPath2)), FileShare_OperationMode::WRITE_MODE}}; + FileShare_PolicyErrorResult* result = nullptr; + uint32_t resultNum = 0; + napi_value napiResult; + std::string resultStr; + // [Start revoke_permission_example] + auto ret = OH_FileShare_RevokePermission(policy, policyNum, &result, &resultNum); + if (ret != ERR_OK) { + if (ret == ERR_EPERM && result != nullptr) { + for (uint32_t i = 0; i < resultNum; i++) { + std::cout << "error uri: " << result[i].uri << std::endl; + std::cout << "error code: " << result[i].code << std::endl; + std::cout << "error message: " << result[i].message << std::endl; + // [StartExclude revoke_permission_example] + resultStr += "error uri: "; + resultStr += result[i].uri; + resultStr += "\n"; + resultStr += "error code: "; + resultStr += result[i].code; + resultStr += "\n"; + resultStr += "error message: "; + resultStr += result[i].message; + resultStr += "\n"; + // [EndExclude revoke_permission_example] + } + } + } + OH_FileShare_ReleasePolicyErrorResult(result, resultNum); + // [End revoke_permission_example] + napi_status status = napi_create_string_utf8(env, resultStr.c_str(), NAPI_AUTO_LENGTH, &napiResult); + if (status != napi_ok) { + return nullptr; + } + return napiResult; +} + +static napi_value NAPI_OH_FileShare_CheckPersistentPermission(napi_env env, napi_callback_info info) +{ + static const uint32_t policyNum = 2; + char strTestPath1[] = "file://com.example.fileshare/data/storage/el2/base/files/test1.txt"; + char strTestPath2[] = "file://com.example.fileshare/data/storage/el2/base/files/test2.txt"; + FileShare_PolicyInfo policy[policyNum] = { + {strTestPath1, static_cast(strlen(strTestPath1)), FileShare_OperationMode::READ_MODE}, + {strTestPath2, static_cast(strlen(strTestPath2)), FileShare_OperationMode::WRITE_MODE}}; + uint32_t resultNum = 0; + napi_value napiResult; + std::string resultStr; + // [Start check_persistent_permission_example] + bool *result = nullptr; + auto ret = OH_FileShare_CheckPersistentPermission(policy, policyNum, &result, &resultNum); + if (ret != ERR_OK) { + if (ret == ERR_EPERM && result != nullptr) { + for (uint32_t i = 0; i < resultNum && resultNum <= policyNum; i++) { + std::cout << "uri: " << policy[i].uri << std::endl; + std::cout << "result: " << result[i] << std::endl; + // [StartExclude check_persistent_permission_example] + resultStr += "uri: "; + resultStr += policy[i].uri; + resultStr += "\n"; + resultStr += "result: "; + resultStr += result[i]; + resultStr += "\n"; + // [EndExclude check_persistent_permission_example] + } + } + } + std::cout << "retCode: " << ret << std::endl; + free(result); + // [End check_persistent_permission_example] + napi_status status = napi_create_string_utf8(env, resultStr.c_str(), NAPI_AUTO_LENGTH, &napiResult); + if (status != napi_ok) { + return nullptr; + } + return napiResult; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "OH_FileShare_PersistPermission", nullptr, NAPI_OH_FileShare_PersistPermission, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "OH_FileShare_ActivatePermission", nullptr, NAPI_OH_FileShare_ActivatePermission, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "OH_FileShare_DeactivatePermission", nullptr, NAPI_OH_FileShare_DeactivatePermission, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "OH_FileShare_RevokePermission", nullptr, NAPI_OH_FileShare_RevokePermission, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "OH_FileShare_CheckPersistentPermission", nullptr, NAPI_OH_FileShare_CheckPersistentPermission, nullptr, + nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/types/libentry/Index.d.ts b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..55c491c6e10cf6cf237a6c3a351c69f216bac7a3 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +export const OH_FileShare_PersistPermission: () => string; + +export const OH_FileShare_ActivatePermission: () => string; + +export const OH_FileShare_DeactivatePermission: () => string; + +export const OH_FileShare_RevokePermission: () => string; + +export const OH_FileShare_CheckPersistentPermission: () => string; \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/types/libentry/oh-package.json5 b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/entryability/EntryAbility.ets b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..62f53acbc95e5be7985f8fb1fe2db591cea260bd --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a97e21bd7a15599af76a806695860ff1eb0ebfe --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/pages/Index.ets b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..197ac7b6f943be8d872e331f4ae8fcc58d362d06 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,69 @@ +/* + * 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 testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State message: string = ''; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize($r('app.float.size_15')) + .fontWeight(FontWeight.Bold) + Button($r('app.string.invokeInterfaceButton1')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + this.message = testNapi.OH_FileShare_PersistPermission(); + }) + Button($r('app.string.invokeInterfaceButton2')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + this.message = testNapi.OH_FileShare_ActivatePermission(); + }) + Button($r('app.string.invokeInterfaceButton3')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + this.message = testNapi.OH_FileShare_DeactivatePermission(); + }) + Button($r('app.string.invokeInterfaceButton4')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + this.message = testNapi.OH_FileShare_RevokePermission(); + }) + Button($r('app.string.invokeInterfaceButton5')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + this.message = testNapi.OH_FileShare_CheckPersistentPermission(); + }) + } + .width('100%') + } + .height('100%') + } +} diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/module.json5 b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..25148c9e0e582c3ed037ae97ca8fad095ec7adb8 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * 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": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/element/color.json b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/element/float.json b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..b8724de0724df917bb9d708b7422428398a86490 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/element/float.json @@ -0,0 +1,20 @@ +{ + "float": [ + { + "name": "size_5", + "value": "5" + }, + { + "name": "size_10", + "value": "10" + }, + { + "name": "size_15", + "value": "15" + }, + { + "name": "size_20", + "value": "20" + } + ] +} diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/element/string.json b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..622a2e862e2c547f24b39aaa5a9c3060a17fad7c --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "FileShareDevelopment_C" + }, + { + "name": "invokeInterfaceButton1", + "value": "PersistPermission" + }, + { + "name": "invokeInterfaceButton2", + "value": "ActivatePermission" + }, + { + "name": "invokeInterfaceButton3", + "value": "DeactivatePermission" + }, + { + "name": "invokeInterfaceButton4", + "value": "RevokePermission" + }, + { + "name": "invokeInterfaceButton5", + "value": "CheckPersistentPermission" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/background.png b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/background.png differ diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/foreground.png b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/foreground.png differ diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/layered_image.json b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/startIcon.png b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/profile/backup_config.json b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/profile/main_pages.json b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/dark/element/color.json b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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/CoreFile/UserFile/FileShareDevelopment_C/entry/src/mock/Libentry.mock.ets b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/mock/Libentry.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..eebf1ed910f6a8f2a9e7e565aa71b179b7b8b537 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + +const NativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default NativeMock; \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/mock/mock-config.json5 b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2c7d2ba82b796a2850ced0a277d261d7d7355416 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/mock/mock-config.json5 @@ -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. + */ + +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/ohosTest/ets/test/Ability.test.ets b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * 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, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/ohosTest/ets/test/List.test.ets b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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/CoreFile/UserFile/FileShareDevelopment_C/entry/src/ohosTest/module.json5 b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a43680ca704ea9bf17ba9b9f88086a2735012c37 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/ohosTest/module.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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/test/List.test.ets b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/entry/src/test/LocalUnit.test.ets b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/hvigor/hvigor-config.json5 b/CoreFile/UserFile/FileShareDevelopment_C/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b8fea3f097bd68b0bc4d87de986d2cb7732c1d9b --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * 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": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | 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 */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "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/CoreFile/UserFile/FileShareDevelopment_C/hvigorfile.ts b/CoreFile/UserFile/FileShareDevelopment_C/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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. */ +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileShareDevelopment_C/oh-package.json5 b/CoreFile/UserFile/FileShareDevelopment_C/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..69cb43cba3addcee1840403c67405134a2a9102c --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/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": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/CoreFile/UserFile/FileShareDevelopment_C/ohosTest.md b/CoreFile/UserFile/FileShareDevelopment_C/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..2f2529b2ef5f0a31f02bb9da7ce9a989fa42e632 --- /dev/null +++ b/CoreFile/UserFile/FileShareDevelopment_C/ohosTest.md @@ -0,0 +1,12 @@ +# 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|---------------------------|--------------------------------------------| ---- | -------------------------- |------| -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | +| 测试OH_FileShare_PersistPermission接口 | 安装应用,进入首页 | | 成功运行 | 否 | Pass | +| 测试OH_FileShare_ActivatePermission接口 | 安装应用,进入首页 | | 成功运行 | 否 | pass | +| 测试OH_FileShare_DeactivatePermission接口 | 安装应用,进入首页 | | 成功运行 | 否 | pass | +| 测试OH_FileShare_RevokePermission接口 | 安装应用,进入首页 | | 成功运行 | 否 | pass | +| 测试OH_FileShare_CheckPersistentPermission接口 | 安装应用,进入首页 | | 成功运行 | 否 | pass | \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/.gitignore b/CoreFile/UserFile/FileUriDevelopment_C/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/.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/CoreFile/UserFile/FileUriDevelopment_C/AppScope/app.json5 b/CoreFile/UserFile/FileUriDevelopment_C/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..faa606f8a1db76b33e2b33740c17295753b56941 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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.fileuridevelopment_c", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CoreFile/UserFile/FileUriDevelopment_C/AppScope/resources/base/element/string.json b/CoreFile/UserFile/FileUriDevelopment_C/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f1da2e079ed5b583dc877fbeb3909bb94e8fa4b4 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "FileUriDevelopment_C" + } + ] +} diff --git a/CoreFile/UserFile/FileUriDevelopment_C/AppScope/resources/base/media/app_icon.png b/CoreFile/UserFile/FileUriDevelopment_C/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CoreFile/UserFile/FileUriDevelopment_C/AppScope/resources/base/media/app_icon.png differ diff --git a/CoreFile/UserFile/FileUriDevelopment_C/PageImg/FileUriDevelopment_c.jpeg b/CoreFile/UserFile/FileUriDevelopment_C/PageImg/FileUriDevelopment_c.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..e7a5dfae8c5213963db7ba118185abcfbf4ef0dd Binary files /dev/null and b/CoreFile/UserFile/FileUriDevelopment_C/PageImg/FileUriDevelopment_c.jpeg differ diff --git a/CoreFile/UserFile/FileUriDevelopment_C/README_zh.md b/CoreFile/UserFile/FileUriDevelopment_C/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..36f1a9fcb15ca19d47fcbf8584b77a29a0f3d3e5 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/README_zh.md @@ -0,0 +1,96 @@ +# FileUri开发指导(C/C++) + +### 介绍 + +该工程提供了关于文件URI的基本操作,对外提供了URI与沙箱路径之间互相转换、远端URI判定、获取URI所在目录路径的URI等接口,方便用户将文件URI与沙箱路径相互转换。该工程中展示的代码详细描述可查如下链接。 + +- [FileUri开发指导(C/C++)](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/file-management/native-fileuri-guidelines.md) + +### 效果预览 + +|主页| +|--------------------------------| +|| + +使用说明: + +1. 在主界面,点击GetUriFromPath接口按钮获取代码里指定文件路径对应的uri,并输出到文本框里。 +2. 在主界面,点击GetPathFromUri接口按钮获取代码里指定uri对应的文件路径,并输出到文本框里。 +3. 在主界面,点击GetFullDirectoryUri接口按钮获取代码里指定文件uri所在路径的uri,并输出到文本框里。 +4. 在主界面,点击IsValidUri接口按钮判断代码里指定文件uri是否正确,并判断结果输出到文本框里。 +5. 在主界面,点击GetFileName接口按钮获取uri中的文件名称,并输出到文本框里。 +6. 切换到Deveco日志页面,搜索”HiAppEvent eventInfo“,出现以下日志。 + +``` +HiAppEvent eventInfo.WatcherType=OnTrigger: /data/storage/el2/base/haps/entry/files/test.txt +HiAppEvent eventInfo.WatcherType=OnTrigger: file://com.samples.fileuridevelopment_c/data/storage/el2/base/haps/entry/files/test.txt +HiAppEvent eventInfo.WatcherType=OnTrigger: file://com.samples.fileuridevelopment_c/data/storage/el2/base/haps/entry/files/test.txt +HiAppEvent eventInfo.WatcherType=OnTrigger: /data/storage/el2/base/haps/entry/files/test.txt +HiAppEvent eventInfo.WatcherType=OnTrigger: file://com.samples.fileuridevelopment_c/data/storage/el2/base/haps/entry/files/test.txt +HiAppEvent eventInfo.WatcherType=OnTrigger: file://com.samples.fileuridevelopment_c/data/storage/el2/base/haps/entry/files +HiAppEvent eventInfo.WatcherType=OnTrigger: file://com.samples.fileuridevelopment_c/data/storage/el2/base/haps/entry/files/test.txt +HiAppEvent eventInfo.WatcherType=OnTrigger: file://com.samples.fileuridevelopment_c/data/storage/el2/base/haps/entry/files/test.txt +HiAppEvent eventInfo.WatcherType=OnTrigger: test.txt +``` + + + +### 工程目录 + +``` +├──entry/src/main +| ├──cpp +| | └──CMakeLists.txt // 动态库链接 +| | └──napi_init.cpp // c++函数实现文件 +| | ├──types // c++函数配置目录 +| ├──ets +| | ├──entryability +| | | └──EntryAbility.ets // 程序入口类 +| | ├──entrybackupability +| | | └──EntryBackupAbility.ets +| | └──pages // 页面文件 +| | └──Index.ets // 主界面 +| ├──resources // 资源文件目录 +``` + +### 具体实现 + +* 在CMake脚本中链接动态库,添加头文件。 + +* 调用OH_FileUri_GetUriFromPath接口,在接口中malloc的内存需要在使用完后释放,因此需要free对应的内存。 +* 调用OH_FileUri_GetPathFromUri通过URi转成对应的PATH,在接口中malloc的内存需要在使用完后释放,因此需要free对应的内存。 +* 调用OH_FileUri_GetFullDirectoryUri获取URI所在路径的URI,在接口中malloc的内存需要在使用完后释放,因此需要free对应的内存。 +* 调用OH_FileUri_IsValidUri接口进行URI格式验证。 +* 调用OH_FileUri_GetFileName获取URI中的文件名称,在接口中malloc的内存需要在使用完后释放,因此需要free对应的内存。 + +### 相关权限 + +不涉及 + +### 依赖 + +不涉及 + +### 约束与限制 + +1.转换或者判断URI类型之前必须保证传入的参数正确有效。 + +2.为保证数据的准确性,在转换或者判断过程中只允许处理一个对象。 + +3.本示例仅支持标准系统上运行,支持设备:RK3568。 + +4.本示例已适配API16版本SDK,版本号:5.1.0.47,镜像版本号:OpenHarmony5.1.0.47。 + +5.本示例需要使用DevEco Studio (5.0.3.910)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/CoreFile/UserFile/FileUriDevelopment_C > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/build-profile.json5 b/CoreFile/UserFile/FileUriDevelopment_C/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..099dfbac6e061178a54c806957d245f748ddec9d --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/build-profile.json5 @@ -0,0 +1,63 @@ +/* + * 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": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 16, + "compatibleSdkVersion": 16, + "runtimeOS": "OpenHarmony", + "buildOption": { + "externalNativeOptions": { + "abiFilters": [ + "arm64-v8a", + "x86_64" + ], + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ], + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/.gitignore b/CoreFile/UserFile/FileUriDevelopment_C/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/build-profile.json5 b/CoreFile/UserFile/FileUriDevelopment_C/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/hvigorfile.ts b/CoreFile/UserFile/FileUriDevelopment_C/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/entry/obfuscation-rules.txt b/CoreFile/UserFile/FileUriDevelopment_C/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/entry/oh-package.json5 b/CoreFile/UserFile/FileUriDevelopment_C/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/CMakeLists.txt b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0492dce8c055fce65a30e726a96fe5723b4fe846 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(FileUriDevelopment_C) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libohfileuri.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/napi_init.cpp b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d386293db255ec7ee94f20e280ff65678b93d265 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,278 @@ +/* + * 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. + */ + +#include "napi/native_api.h" +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "Sample_fileUri" + +// [Start get_uri_from_path_example] +static napi_value NAPI_Global_OH_FileUri_GetUriFromPathExample(napi_env env, napi_callback_info info) +{ + // [StartExclude get_uri_from_path_example] + // 参数个数为1 + size_t argc = 1; + napi_value args[1] = { nullptr }; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取字符串的长度,初始化字符串长度为0 + size_t strLength = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &strLength); + // [EndExclude get_uri_from_path_example] + // 为 char* uri 分配内存 + char *path = new char[strLength + 1]; // +1 for null terminator + // 将 JavaScript 字符串复制到 uri + // [StartExclude get_uri_from_path_example] + napi_get_value_string_utf8(env, args[0], path, strLength + 1, &strLength); + // [EndExclude get_uri_from_path_example] + unsigned int length = strlen(path); + // 输出传入路径字符串 + // [StartExclude get_uri_from_path_example] + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", path); + // [EndExclude get_uri_from_path_example] + char *uriResult = nullptr; + FileManagement_ErrCode ret = OH_FileUri_GetUriFromPath(path, length, &uriResult); + // 输出结果uri字符串 + // [StartExclude get_uri_from_path_example] + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", uriResult); + napi_value result; + // [EndExclude get_uri_from_path_example] + if (ret == 0 && uriResult != nullptr) { + // 将C字符串转换为napi_value + napi_status status = napi_create_string_utf8(env, uriResult, NAPI_AUTO_LENGTH, &result); + if (status != napi_ok) { + free(uriResult); + return nullptr; + } + free(uriResult); // 释放临时字符串 + } else { + // 将C字符串转换为napi_value + napi_status status = napi_create_string_utf8(env, "Hello World", NAPI_AUTO_LENGTH, &result); + if (status != napi_ok) { + return nullptr; + } + } + return result; +} +// [End get_uri_from_path_example] + +// [Start get_path_from_uri_example] +static napi_value NAPI_Global_OH_FileUri_GetPathFromUriExample(napi_env env, napi_callback_info info) +{ + // [StartExclude get_path_from_uri_example] + // 参数个数为1 + size_t argc = 1; + napi_value args[1] = { nullptr }; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取字符串的长度,初始化字符串长度为0 + size_t strLength = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &strLength); + // 为 char* uri 分配内存 + // [EndExclude get_path_from_uri_example] + char *uri = new char[strLength + 1]; // +1 for null terminator + // 将 JavaScript 字符串复制到 uri + napi_get_value_string_utf8(env, args[0], uri, strLength + 1, &strLength); + + unsigned int length = strlen(uri); + // 输出传入uri符串 + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", uri); + char *pathResult = nullptr; + FileManagement_ErrCode ret = OH_FileUri_GetPathFromUri(uri, length, &pathResult); + // 输出获取路径结果符串 + // [StartExclude get_path_from_uri_example] + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", pathResult); + napi_value result; + // [EndExclude get_path_from_uri_example] + if (ret == 0 && pathResult != nullptr) { + // 将C字符串转换为napi_value + napi_status status = napi_create_string_utf8(env, pathResult, NAPI_AUTO_LENGTH, &result); + if (status != napi_ok) { + free(pathResult); + return nullptr; + } + free(pathResult); // 释放临时字符串 + } else { + // 将空字符串转换为napi_value + napi_status status = napi_create_string_utf8(env, "", NAPI_AUTO_LENGTH, &result); + if (status != napi_ok) { + return nullptr; + } + } + return result; +} +// [End get_path_from_uri_example] + +// [Start get_full_directory_uri] +static napi_value NAPI_Global_OH_FileUri_GetFullDirectoryUriExample(napi_env env, napi_callback_info info) +{ + // [StartExclude get_full_directory_uri] + // 参数个数为1 + size_t argc = 1; + napi_value args[1] = { nullptr }; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取字符串的长度,初始化字符串长度为0 + size_t strLength = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &strLength); + // 为 char* uri 分配内存 + // [EndExclude get_full_directory_uri] + char *uri = new char[strLength + 1]; // +1 for null terminator + // 将 JavaScript 字符串复制到 uri + napi_get_value_string_utf8(env, args[0], uri, strLength + 1, &strLength); + + unsigned int length = strlen(uri); + // 输出传入uri字符串 + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", uri); + char *uriResult = nullptr; + FileManagement_ErrCode ret = OH_FileUri_GetFullDirectoryUri(uri, length, &uriResult); + // 输出所在路径uri字符串 + // [StartExclude get_full_directory_uri] + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", uriResult); + napi_value result = nullptr; + // [EndExclude get_full_directory_uri] + if (ret == 0 && uriResult != nullptr) { + // 使用napi接口创建一个字符串类型的napi_value来返回正确结果 + napi_create_string_utf8(env, uriResult, NAPI_AUTO_LENGTH, &result); + } else { + // 使用napi接口创建一个表示null值的napi_value来返回错误或空值情况 + napi_get_null(env, &result); + } + if (uriResult != nullptr) { + free(uriResult); + } + return result; +} +// [End get_full_directory_uri] + +// [Start is_valid_uri_example] +static napi_value NAPI_Global_OH_FileUri_IsValidUriExample(napi_env env, napi_callback_info info) +{ + // [StartExclude is_valid_uri_example] + // 参数个数为1 + size_t argc = 1; + napi_value args[1] = { nullptr }; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取字符串的长度,初始化字符串长度为0 + size_t strLength = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &strLength); + // 为 char* uri 分配内存 + // [EndExclude is_valid_uri_example] + char *uri = new char[strLength + 1]; // +1 for null terminator + // 将 JavaScript 字符串复制到 uri + napi_get_value_string_utf8(env, args[0], uri, strLength + 1, &strLength); + unsigned int length = strlen(uri); + // 输出传入uri字符串 + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", uri); + bool flags = OH_FileUri_IsValidUri(uri, length); + // [StartExclude is_valid_uri_example] + napi_value result; + // 将bool值转换为napi_value + napi_status status = napi_get_boolean(env, flags, &result); + if (status != napi_ok) { + // 处理错误 + napi_throw_error(env, nullptr, "Failed to convert boolean to napi_value"); + return nullptr; + } + return result; + // [EndExclude is_valid_uri_example] +} +// [End is_valid_uri_example] + +// [Start get_file_name_example] +static napi_value NAPI_Global_OH_FileUri_GetFileNameExample(napi_env env, napi_callback_info info) +{ + // [StartExclude get_file_name_example] + // 参数个数为1 + size_t argc = 1; + napi_value args[1] = { nullptr }; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取字符串的长度,初始化字符串长度为0 + size_t strLength = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &strLength); + // 为 char* uri 分配内存 + // [EndExclude get_file_name_example] + char *uri = new char[strLength + 1]; // +1 for null terminator + // 将 JavaScript 字符串复制到 uri + napi_get_value_string_utf8(env, args[0], uri, strLength + 1, &strLength); + + unsigned int length = strlen(uri); + // 输出传入uri字符串 + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", uri); + char *uriResult = nullptr; + FileManagement_ErrCode ret = OH_FileUri_GetFileName(uri, length, &uriResult); + // 输出获取到的文件名称 + // [StartExclude get_file_name_example] + OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.WatcherType=OnTrigger: %{public}s", uriResult); + napi_value result; + // [EndExclude get_file_name_example] + if (ret == 0 && uriResult != nullptr) { + // 将C字符串转换为napi_value + napi_status status = napi_create_string_utf8(env, uriResult, NAPI_AUTO_LENGTH, &result); + if (status != napi_ok) { + free(uriResult); + return NULL; + } + free(uriResult); // 释放临时字符串 + } else { + // 将空字符串转换为napi_value + napi_status status = napi_create_string_utf8(env, "", NAPI_AUTO_LENGTH, &result); + if (status != napi_ok) { + return nullptr; + } + } + return result; +} +// [End get_file_name_example] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"OH_FileUri_GetUriFromPathExample", nullptr, NAPI_Global_OH_FileUri_GetUriFromPathExample, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"OH_FileUri_GetPathFromUriExample", nullptr, NAPI_Global_OH_FileUri_GetPathFromUriExample, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"OH_FileUri_GetFullDirectoryUriExample", nullptr, NAPI_Global_OH_FileUri_GetFullDirectoryUriExample, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"OH_FileUri_IsValidUriExample", nullptr, NAPI_Global_OH_FileUri_IsValidUriExample, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"OH_FileUri_GetFileNameExample", nullptr, NAPI_Global_OH_FileUri_GetFileNameExample, nullptr, nullptr, nullptr, + napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, // 模块版本号,设置为1遵循当前的 N-API 版本规范 + .nm_flags = 0, // 模块标志,设置为0,表示没有特殊标志 + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, // 保留字段,通常初始化为0 +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/types/libentry/Index.d.ts b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..2385e74adf0d95611ec79daf797336daeeaa25a0 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +export const OH_FileUri_GetUriFromPathExample: (path: string) => string; + +export const OH_FileUri_GetPathFromUriExample: (uri: string) => string; + +export const OH_FileUri_GetFullDirectoryUriExample: (uri: string) => string; + +export const OH_FileUri_IsValidUriExample: (uri: string) => boolean; + +export const OH_FileUri_GetFileNameExample: (uri: string) => string; \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/types/libentry/oh-package.json5 b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/common/Logger.ts b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/common/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..148b9e9cacba97fab13dcc6526e2f0ed4143ff0f --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/common/Logger.ts @@ -0,0 +1,68 @@ +/* + * 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'; + +const DOMAIN: number = 0x0000; // 此处使用自行申请的应用代码号 +const PREFIX: string = '[Sample_FileUriDevelopment_C]'; // 应用log标签 + +export class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = DOMAIN; + } + + getDomain() { + return this.domain; + } + + getPrefix() { + return this.prefix; + } + + getFormat() { + return this.format; + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]) { + hilog.fatal(this.domain, this.prefix, this.format, args); + } + + isLoggable(level: number) { + hilog.isLoggable(this.domain, this.prefix, level); + } +} + +export default new Logger(PREFIX); diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/entryability/EntryAbility.ets b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5539bddd7a772710f55da0ddd7b5676305469de --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b74fe507979e31c9d239b7f29ea9102f6144b7cf --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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 { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +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/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/pages/Index.ets b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..529cb201a958a3f55b0c1aff286349382b67cbe2 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,108 @@ +/* + * 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 { buffer } from '@kit.ArkTS'; +import { fileUri, fileIo as fs, ReadOptions } from '@kit.CoreFileKit'; +import common from '@ohos.app.ability.common'; +import Logger from '../common/Logger'; +import testNapi from 'libentry.so'; + +// 获取应用文件沙箱路径 +let context = getContext(this) as common.UIAbilityContext; +let filesDir = context.filesDir; +let filePath = filesDir + '/test.txt'; // 文件路径 +let uri = fileUri.getUriFromPath(filePath); // 从文件路径获取 URI + +export function createFile(): string { + // 新建并打开文件 + let file = fs.openSync(filesDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + // 写入一段内容至文件 + let writeLen = fs.writeSync(file.fd, 'Try to write str : hello world'); + Logger.info('The length of str is: ' + writeLen); // 写入内容的长度 + // 从文件读取一段内容 + let arrayBuffer = new ArrayBuffer(1024); // 分配一个 1024 字节的缓冲区 + let readOptions: ReadOptions = { + offset: 0, // 从文件的开头开始读取 + length: arrayBuffer.byteLength // 读取的长度为缓冲区的大小 + }; + let readLen = fs.readSync(file.fd, arrayBuffer, readOptions); // 实际读取的字节数 + // 这个 buf 对象是 arrayBuffer 中从位置 0 开始的前 readLen 字节 + let buf = buffer.from(arrayBuffer, 0, readLen); + Logger.info('the content of file: ' + buf.toString()); // 打印文件内容 + let str = 'the content of file: ' + buf.toString(); + // 关闭文件 + fs.closeSync(file); + return str; +} + +@Entry +@Component +struct Index { + @State message: string = ''; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize($r('app.float.size_50')) // 设置字体大小为 50 + .fontWeight(FontWeight.Bold) + Button($r('app.string.invokeInterfaceButton1')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + createFile(); + this.message = testNapi.OH_FileUri_GetUriFromPathExample(filePath); + }) + + Button($r('app.string.invokeInterfaceButton2')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + this.message = testNapi.OH_FileUri_GetPathFromUriExample(uri); + }) + + Button($r('app.string.invokeInterfaceButton3')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + this.message = testNapi.OH_FileUri_GetFullDirectoryUriExample(uri); + }) + + Button($r('app.string.invokeInterfaceButton4')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + if (testNapi.OH_FileUri_IsValidUriExample(uri)) { + this.message = 'UriIsTrue'; + } + }) + + Button($r('app.string.invokeInterfaceButton5')) + .width('80%') // 设置按钮宽度为 80% + .height('10%') // 设置按钮高度为 10% + .margin({ top: $r('app.float.size_20') }) // 设置按钮上边距为 20 + .onClick(() => { + this.message = testNapi.OH_FileUri_GetFileNameExample(uri); + }) + } + .width('100%') // 设置列的宽度为 100% + } + .height('100%') // 设置行的高度为 100% + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/module.json5 b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/color.json b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..b99ebd2b9c4b3a455465e850b4eeee9548ba886a --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/color.json @@ -0,0 +1,24 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "whiteColor", + "value": "#FFFFFF" + }, + { + "name": "lightGrayColor", + "value": "#F0F0F0" + }, + { + "name": "grayColor", + "value": "#808080" + }, + { + "name": "blackColor", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/float.json b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..30e6a4c0edf724b1459705043d7488912328bd16 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/float.json @@ -0,0 +1,36 @@ +{ + "float": [ + { + "name": "size_5", + "value": "10" + }, + { + "name": "size_10", + "value": "10" + }, + { + "name": "size_13", + "value": "13" + }, + { + "name": "size_15", + "value": "15" + }, + { + "name": "size_20", + "value": "20" + }, + { + "name": "size_25", + "value": "25" + }, + { + "name": "size_40", + "value": "40" + }, + { + "name": "size_50", + "value": "50" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/string.json b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c1fa7ac34d315f0057cd5a2f0d33f890a3d768dd --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "FileUriDevelopment_C" + }, + { + "name": "invokeInterfaceButton1", + "value": "GetUriFromPath" + }, + { + "name": "invokeInterfaceButton2", + "value": "GetPathFromUri" + }, + { + "name": "invokeInterfaceButton3", + "value": "GetFullDirectoryUri" + }, + { + "name": "invokeInterfaceButton4", + "value": "IsValidUri" + }, + { + "name": "invokeInterfaceButton5", + "value": "GetFileName" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/background.png b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/background.png differ diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/foreground.png b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/foreground.png differ diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/layered_image.json b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/startIcon.png b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/profile/backup_config.json b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/profile/main_pages.json b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/en_US/element/string.json b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..db4dedd6b71384eef6ce60ec319fedbaf5b5f99f --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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": "FileUriDevelopment_C" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/zh_CN/element/string.json b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5cb723ed88048c84158b1ac0b1d423cdfc5567f6 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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": "FileUriDevelopment_C" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/ohosTest/ets/test/Ability.test.ets b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d1adb0ac477672784a3591e55bcd03a7b9ade3f3 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,182 @@ +/* + * 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. + */ + +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { describe, it, expect } from '@ohos/hypium'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const TAG = '[Sample_FileUriDevelopment_c]'; +const DOMAIN = 0xF811; +const BUNDLE = 'FileUriDevelopment_c_'; +const DELAY_TIME_1S = 1000; + +const DELEGATOR: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const BUNDLENAME = abilityDelegatorRegistry.getArguments().bundleName; + +export default function abilityTest() { + describe('FileUriDevelopment_cTest', () => { + /** + * @tc.number CoreFileKit_StartAbility_001 + * @tc.name CoreFileKit_StartAbility_001 + * @tc.desc 启动Ability + */ + it(BUNDLE + 'StartAbility_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,begin'); + // start tested ability + const want: Want = { + bundleName: BUNDLENAME, + abilityName: 'EntryAbility' + }; + await DELEGATOR.startAbility(want); + let driver: Driver = Driver.create(); + await driver.delayMs(DELAY_TIME_1S); + // check top display ability + const ability: UIAbility = await DELEGATOR.getCurrentTopAbility(); + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + done(); + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,end'); + }) + /** + * @tc.number CoreFileKit_InterfaceTest_001 + * @tc.name CoreFileKit_InterfaceTest_001 + * @tc.desc 测试接口OH_FileUri_GetUriFromPath + */ + it(BUNDLE + 'InterfaceTest_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_001, begin'); + // 初始化 Driver,用于 UI 操作 + const driver = Driver.create(); + // 等待 1000 毫秒,确保 UI 渲染完成 + await driver.delayMs(DELAY_TIME_1S); + + // 查找按钮组件 + const getUriFromPathButton = await driver.findComponent(ON.text('GetUriFromPath')); + // 点击按钮 + await getUriFromPathButton.click(); + // 等待 1000 毫秒,确保点击后的操作完成 + await driver.delayMs(DELAY_TIME_1S); + // 检查文本组件是否改变 + await driver.assertComponentExist( + ON.text('file://' + BUNDLENAME + '/data/storage/el2/base/haps/entry/files/test.txt') + ); + + // 标记测试用例完成 + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_001, end'); + done(); + }) + /** + * @tc.number CoreFileKit_InterfaceTest_002 + * @tc.name CoreFileKit_InterfaceTest_002 + * @tc.desc 测试接口OH_FileUri_GetPathFromUri + */ + it(BUNDLE + 'InterfaceTest_002', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_002, begin'); + // 初始化 Driver,用于 UI 操作 + const driver = Driver.create(); + // 等待 1000 毫秒,确保 UI 渲染完成 + await driver.delayMs(DELAY_TIME_1S); + + // 查找按钮组件 + const getPathFromUriButton = await driver.findComponent(ON.text('GetPathFromUri')); + // 点击按钮 + await getPathFromUriButton.click(); + // 等待 1000 毫秒,确保点击后的操作完成 + await driver.delayMs(DELAY_TIME_1S); + // 检查文本组件是否改变 + await driver.assertComponentExist(ON.text('/data/storage/el2/base/haps/entry/files/test.txt')); + + // 标记测试用例完成 + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_002, end'); + done(); + }) + /** + * @tc.number CoreFileKit_InterfaceTest_003 + * @tc.name CoreFileKit_InterfaceTest_003 + * @tc.desc 测试接口OH_FileUri_GetFullDirectoryUri + */ + it(BUNDLE + 'InterfaceTest_003', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_003, begin'); + // 初始化 Driver,用于 UI 操作 + const driver = Driver.create(); + // 等待 1000 毫秒,确保 UI 渲染完成 + await driver.delayMs(DELAY_TIME_1S); + + // 查找按钮组件 + const getFullDirectoryUriButton = await driver.findComponent(ON.text('GetFullDirectoryUri')); + // 点击按钮 + await getFullDirectoryUriButton.click(); + // 等待 1000 毫秒,确保点击后的操作完成 + await driver.delayMs(DELAY_TIME_1S); + // 检查文本组件是否改变 + await driver.assertComponentExist(ON.text('file://' + BUNDLENAME + '/data/storage/el2/base/haps/entry/files')); + + // 标记测试用例完成 + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_003, end'); + done(); + }) + /** + * @tc.number CoreFileKit_InterfaceTest_004 + * @tc.name CoreFileKit_InterfaceTest_004 + * @tc.desc 测试接口OH_FileUri_IsValidUri + */ + it(BUNDLE + 'InterfaceTest_004', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_004, begin'); + // 初始化 Driver,用于 UI 操作 + const driver = Driver.create(); + // 等待 1000 毫秒,确保 UI 渲染完成 + await driver.delayMs(DELAY_TIME_1S); + + // 查找按钮组件 + const isValidUriButton = await driver.findComponent(ON.text('IsValidUri')); + // 点击按钮 + await isValidUriButton.click(); + // 等待 1000 毫秒,确保点击后的操作完成 + await driver.delayMs(DELAY_TIME_1S); + // 检查文本组件是否改变 + await driver.assertComponentExist(ON.text('UriIsTrue')); + + // 标记测试用例完成 + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_004, end'); + done(); + }) + /** + * @tc.number CoreFileKit_InterfaceTest_005 + * @tc.name CoreFileKit_InterfaceTest_005 + * @tc.desc 测试接口OH_FileUri_GetFileName + */ + it(BUNDLE + 'InterfaceTest_005', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_005, begin'); + // 初始化 Driver,用于 UI 操作 + const driver = Driver.create(); + // 等待 1000 毫秒,确保 UI 渲染完成 + await driver.delayMs(DELAY_TIME_1S); + + // 查找按钮组件 + const getFileNameButton = await driver.findComponent(ON.text('GetFileName')); + // 点击按钮 + await getFileNameButton.click(); + // 等待 1000 毫秒,确保点击后的操作完成 + await driver.delayMs(DELAY_TIME_1S); + // 检查文本组件是否改变 + await driver.assertComponentExist(ON.text('test.txt')); + + // 标记测试用例完成 + hilog.info(DOMAIN, TAG, BUNDLE + 'InterfaceTest_005, end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/CoreFile/UserFile/FileUriDevelopment_C/entry/src/ohosTest/ets/test/List.test.ets b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/entry/src/ohosTest/module.json5 b/CoreFile/UserFile/FileUriDevelopment_C/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/hvigor/hvigor-config.json5 b/CoreFile/UserFile/FileUriDevelopment_C/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/hvigorfile.ts b/CoreFile/UserFile/FileUriDevelopment_C/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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/CoreFile/UserFile/FileUriDevelopment_C/oh-package.json5 b/CoreFile/UserFile/FileUriDevelopment_C/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/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.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/CoreFile/UserFile/FileUriDevelopment_C/ohosTest.md b/CoreFile/UserFile/FileUriDevelopment_C/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..7e0bd48c959710787f1d4a3416f8489c873cbf2d --- /dev/null +++ b/CoreFile/UserFile/FileUriDevelopment_C/ohosTest.md @@ -0,0 +1,13 @@ +# FileUriDevelopment_C 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------- | ------------------ | ---- | ---------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 调用OH_FileUri_GetUriFromPath | 安装应用,进入首页 | | 获取到的URI输出到应用页面文本框内 | 是 | Pass | +| 调用OH_FileUri_GetPathFromUri | 安装应用,进入首页 | | 获取到的PATH输出到应用页面文本框内 | 是 | Pass | +| 调用OH_FileUri_GetFullDirectoryUri | 安装应用,进入首页 | | 获取URI所在路径的URI输出到应用页面文本框 | 是 | Pass | +| 调用OH_FileUri_IsValidUri | 安装应用,进入首页 | | 将URI判断结果输出到应用页面文本框 | 是 | Pass | +| 调用OH_FileUri_GetFileName | 安装应用,进入首页 | | 获取URI中的文件名称输出到应用页面文本框 | 是 | Pass | + diff --git a/CoreFile/UserFile/UserFileURI/.gitignore b/CoreFile/UserFile/UserFileURI/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/.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/CoreFile/UserFile/UserFileURI/AppScope/app.json5 b/CoreFile/UserFile/UserFileURI/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bc4886d3c65225acf71576662e5d0fd2a42c99b7 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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.userfileuri", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CoreFile/UserFile/UserFileURI/AppScope/resources/base/element/string.json b/CoreFile/UserFile/UserFileURI/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ebc4295724049456ed63672eab496169b7ad9846 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UserFileURI" + } + ] +} diff --git a/CoreFile/UserFile/UserFileURI/AppScope/resources/base/media/app_icon.png b/CoreFile/UserFile/UserFileURI/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CoreFile/UserFile/UserFileURI/AppScope/resources/base/media/app_icon.png differ diff --git a/CoreFile/UserFile/UserFileURI/PageImg/UserFileURI.jpeg b/CoreFile/UserFile/UserFileURI/PageImg/UserFileURI.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..a7eee99df45f3a211e49784bd2949d7af511ba4e Binary files /dev/null and b/CoreFile/UserFile/UserFileURI/PageImg/UserFileURI.jpeg differ diff --git a/CoreFile/UserFile/UserFileURI/README_zh.md b/CoreFile/UserFile/UserFileURI/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..877f698ed8f1f438b249346fd5c0a81cda7fa412 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/README_zh.md @@ -0,0 +1,101 @@ +# 用户文件uri介绍 + +### 介绍 + +本示例主要展示了有关用户文件uri的功能,使用DocumentViewPicker接口 、AudioViewPicker接口、fileAccess模块、fs模块、photoAccessHelper模块、userFileManager模块、createFileAccessHelper等,实现了获取文档类uri、获取媒体文件uri、通过uri复制文件的功能。该工程中展示的代码与权限等详细描述可查如下链接。 + +- [用户文件uri介绍](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/file-management/user-file-uri-intro.md) + +### 效果预览 + +|主页| +|:------------------------------:| +|主页| + +使用说明: + +1. 在主界面,可以选择点击ReadDocumentUri、ReadMediaUri、CopyAFile按钮使用对应的功能。 +2. 点击ReadDocumentUri按钮,将在指定目录创建一个文件,在日志中打印文件的uri,重命名该文件,再次打印该文件的uri,成功后将输出“ReadDocumentUriSuccess”到主页文本框,在Deveco日志中搜索“rename success, renameUri”,有对应的日志。 +3. 点击ReadMediaUri按钮,拉起PhotoAccessHelper的PhotoViewPicker选择已有媒体文件或拍摄一个媒体文件,读取该媒体文件的uri已经基本信息,并输出“ReadMediaUriSuccess”到主页文本框,在Deveco日志中搜索“PhotoViewPicker.select successfully”,有对应的日志。 +4. 点击CopyAFile按钮,复制指定文件到指定目录,并输出”CopyAFileSuccess“到主页文本框,在Deveco日志中搜索“copyFile success, fileUr“,有对应的日志。 +5. 点击SelectDocumentFile按钮,可以调用Picker选择查看创建的文档类文件与复制的文档类文件,直观查看创建和复制结果。 + +### 工程目录 + +``` +├──entry/src/main +| ├──ets +| | ├──common +| | | └──Logger.ts // 日志打印封装类 +| | | └──PermissionUtils.ets // 权限申请封装类 +| | ├──entryability +| | | └──EntryAbility.ets // 程序入口类 +| | ├──entrybackupability +| | | └──EntryBackupAbility.ets +| | └──pages // 页面文件 +| | └──Index.ets // 主界面 +| ├──resources // 资源文件目录 +``` + +### 具体实现 + +* 文档类uri获取方式: + * 通过[文件选择器(FilePicker)](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md#ohosfilepicker-选择器)的DocumentViewPicker接口选择或保存文件,返回选择或保存的文件uri。 + * 通过[文件选择器(FilePicker)](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md#ohosfilepicker-选择器)的AudioViewPicker接口选择或保存文件,返回选择或保存的文件uri。 + * 通过[fileAccess模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileAccess-sys.md)获取文件uri,使用获取到的文件uri进行重命名操作。 + * 通过[fileAccess模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileAccess-sys.md)获取文档类目录下的文件得到对应文件的FileInfo对象,此对象中就包含对应文件或者目录的uri属性,此模块中的接口为系统接口,使用此模块需要注意应用是否为系统应用。支持获取文件uri的目录有: + - 外部存储目录 + - Docs目录 + - Download目录 + - Desktop目录 + - Documents目录 + - Share共享盘目录 + +* 媒体文件uri使用方式: + * 通过[photoAccessHelper模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-media-library-kit/js-apis-photoAccessHelper.md)的PhotoViewPicker选择媒体文件,返回选择的媒体文件文件的uri。 + * 通过[photoAccessHelper模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-media-library-kit/js-apis-photoAccessHelper.md)模块中的getAssets或createAsset接口获取媒体文件对应文件的uri。 + * 通过[userFileManager模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-userFileManager-sys.md)中的getPhotoAssets、getAudioAssets、createAudioAsset或createPhotoAsset接口获取媒体文件对应文件的uri。 + * normal等级的应用使用此类uri可以通过[photoAccessHelper模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-media-library-kit/js-apis-photoAccessHelper.md)模块进行进一步处理。 + * system_basic等级及以上的应用使用此类uri的方式除了上述通过[photoAccessHelper模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-media-library-kit/js-apis-photoAccessHelper.md)外还可以通过[userFileManager模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-userFileManager-sys.md)进行进一步处理。 + * 若normal等级的应用也可以通过临时授权的方式使用[photoAccessHelper模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-media-library-kit/js-apis-photoAccessHelper.md)的PhotoViewPicker得到的uri使用photoAccessHelper.getAssets接口获取对应uri的PhotoAsset对象。这种方式获取的对象可以调用getThumbnail获取缩略图和使用get接口读取PhotoKeys中的部分信息。 +* 用户复制文件到指定目录: + * 通过[fileAccess模块](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileAccess-sys.md)的createFileAccessHelper接口创建fileAccessHelper helper。 + * 获取源文件的srcUri。 + * 获取目的路径的destUri。 + * 获取备用名 fileName。 + * 使用helper.copyFile(srcUri, destUri, fileName) 进行文件操作。 + +### 相关权限 + +[ohos.permission.FILE_ACCESS_MANAGER](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionfile_access_manager) + +[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_bundle_info_privileged) + +[ohos.permission.READ_IMAGEVIDEO](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionread_imagevideo) + +### 依赖 + +不涉及 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例已适配API16版本SDK,版本号:5.1.0.47,镜像版本号:OpenHarmony5.1.0.47。 + +3.本示例需要使用DevEco Studio (5.0.3.910)及以上版本才可编译运行。 + +4.本示例相关权限为system_basic级别,需要配置高权限签名,可参考[申请使用受控权限](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/declare-permissions-in-acl.md)。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/CoreFile/UserFile/UserFileURI > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` + diff --git a/CoreFile/UserFile/UserFileURI/build-profile.json5 b/CoreFile/UserFile/UserFileURI/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0fa83c0da167624d6eb4c0711ecf82425895ac47 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/build-profile.json5 @@ -0,0 +1,64 @@ +/* + * 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": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 16, + "targetSdkVersion": 16, + "compatibleSdkVersion": 16, + "runtimeOS": "OpenHarmony", + "buildOption": { + "externalNativeOptions": { + "abiFilters": [ + "arm64-v8a", + "x86_64" + ], + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ], + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/.gitignore b/CoreFile/UserFile/UserFileURI/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/build-profile.json5 b/CoreFile/UserFile/UserFileURI/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * 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": { + }, + "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/CoreFile/UserFile/UserFileURI/entry/hvigorfile.ts b/CoreFile/UserFile/UserFileURI/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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/CoreFile/UserFile/UserFileURI/entry/obfuscation-rules.txt b/CoreFile/UserFile/UserFileURI/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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/CoreFile/UserFile/UserFileURI/entry/oh-package.json5 b/CoreFile/UserFile/UserFileURI/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/ets/common/Logger.ts b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/common/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..58add1cbec1f88ce259811fda78d912977b7917d --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/common/Logger.ts @@ -0,0 +1,68 @@ +/* + * 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'; + +const DOMAIN: number = 0x0000; // 此处使用自行申请的应用代码号 +const PREFIX: string = '[Sample_UserFileURI]'; // 应用log标签 + +export class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = DOMAIN; + } + + getDomain() { + return this.domain; + } + + getPrefix() { + return this.prefix; + } + + getFormat() { + return this.format; + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]) { + hilog.fatal(this.domain, this.prefix, this.format, args); + } + + isLoggable(level: number) { + hilog.isLoggable(this.domain, this.prefix, level); + } +} + +export default new Logger(PREFIX); diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/ets/common/PermissionUtils.ets b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/common/PermissionUtils.ets new file mode 100644 index 0000000000000000000000000000000000000000..2dcfc7442e0b5f01cb7d41113846b85f17951421 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/common/PermissionUtils.ets @@ -0,0 +1,95 @@ +/* + * 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 { abilityAccessCtrl, bundleManager, common, Permissions } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { promptAction } from '@kit.ArkUI'; + +export const permissions: Permissions[] = ['ohos.permission.READ_IMAGEVIDEO']; + +async function checkPermissionGrant(permission: Permissions): Promise { + // 1. 创建应用权限管理器 + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + let grantStatus: abilityAccessCtrl.GrantStatus = abilityAccessCtrl.GrantStatus.PERMISSION_DENIED; + + // 2. 获取应用程序的accessTokenID + let tokenId: number = 0; + try { + let bundleInfo: bundleManager.BundleInfo = await bundleManager.getBundleInfoForSelf( + bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION); + let appInfo: bundleManager.ApplicationInfo = bundleInfo.appInfo; + tokenId = appInfo.accessTokenId; + } catch (error) { + const err: BusinessError = error as BusinessError; + console.error(`Failed to get bundle info for self. Code is ${err.code}, message is ${err.message}`); + } + + // 3. 校验应用是否被授予权限 + try { + grantStatus = await atManager.checkAccessToken(tokenId, permission); + } catch (error) { + const err: BusinessError = error as BusinessError; + console.error(`Failed to check access token. Code is ${err.code}, message is ${err.message}`); + } + + return grantStatus; +} + + +export async function checkAndRequestPermissions(permissions: Permissions[], context: common.UIAbilityContext): + Promise { + let grantStatus: abilityAccessCtrl.GrantStatus = await checkPermissionGrant(permissions[0]); + + if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { + // 已经授权,可以继续访问目标操作 + promptAction.showToast({ + message: 'permission succeed!', // 显示文本 + }) + } else { + // 申请权限 + reqPermissionsFromUser(permissions, context); + } +} + +// 使用UIExtensionAbility:将common.UIAbilityContext 替换为common.UIExtensionContext +export function reqPermissionsFromUser(permissions: Permissions[], context: common.UIAbilityContext): void { + // 1. 创建应用权限管理器 + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + // 2. 拉起弹框请求用户授权 requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗 + atManager.requestPermissionsFromUser(context, permissions).then((data) => { + let grantStatus: number[] = data.authResults; + let length: number = grantStatus.length; + for (let i = 0; i < length; i++) { + if (grantStatus[i] === 0) { + // 用户授权,可以继续访问目标操作 + promptAction.showToast({ + message: 'permission succeed!', // 显示文本 + }) + } else { + // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限 + promptAction.showToast({ + message: 'user refused authorization!', // 显示文本 + }) + return; + } + } + // 授权成功 + }).catch((err: BusinessError) => { + console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`); + }) +} + + + diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/ets/entryability/EntryAbility.ets b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..e985a322b65aad6515c26543aea3e9342471de92 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/entryability/EntryAbility.ets @@ -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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { checkAndRequestPermissions,permissions } from '../common/PermissionUtils' +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(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) => { + checkAndRequestPermissions(permissions, this.context); + 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'); + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b74fe507979e31c9d239b7f29ea9102f6144b7cf --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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 { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +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/CoreFile/UserFile/UserFileURI/entry/src/main/ets/pages/Index.ets b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d69240ac4fb672d001611ad75a1de687fc96918 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,339 @@ +/* + * 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 copy_file_uri_example ] +// [Start function_example] +// [Start import_user_fileAccess] +// [Start import_get_uri_assets] +import { BusinessError } from '@kit.BasicServicesKit'; +// [StartExclude import_get_uri_assets] +import { Want } from '@kit.AbilityKit'; +// [EndExclude import_get_uri_assets] +import { common } from '@kit.AbilityKit'; +// [StartExclude import_get_uri_assets] +import { fileAccess} from '@kit.CoreFileKit'; +// [EndExclude import_get_uri_assets] +// [StartExclude copy_file_uri_example] +// [StartExclude function_example] +import { dataSharePredicates } from '@kit.ArkData'; +// [StartExclude import_get_uri_assets] +import { fileIo as fs} from '@kit.CoreFileKit'; +import { picker } from '@kit.CoreFileKit'; +// [EndExclude import_get_uri_assets] +import { photoAccessHelper } from '@kit.MediaLibraryKit'; + +// 定义一个uri数组,用于接收PhotoViewPicker选择图片返回的uri +let uris: string[] = []; +// [EndExclude function_example] +// [EndExclude copy_file_uri_example] + +// context 是EntryAbility 传过来的context +let context = this.getUIContext().getHostContext() as common.UIAbilityContext; +// [End import_user_fileAccess] + +// [StartExclude copy_file_uri_example] +// [StartExclude function_example] +// [StartExclude import_get_uri_assets] +async function getFileAccessAbilityInfo() { + let wantInfos: Want[] = []; + try { + wantInfos = await fileAccess.getFileAccessAbilityInfo(); + console.info('getFileAccessAbilityInfo data ' + JSON.stringify(wantInfos)); + } catch (err) { + let error: BusinessError = err as BusinessError; + console.error('getFileAccessAbilityInfo failed, errCode:' + error.code + ', errMessage:' + error.message); + } +} +// [EndExclude import_get_uri_assets] + +// 调用PhotoViewPicker.select选择图片 +async function photoPickerGetUri() { + try { + let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; + // 设置最多可以选择的图片数量为1 + photoSelectOptions.maxSelectNumber = 1; + let photoPicker = new photoAccessHelper.PhotoViewPicker(); + // 等待用户选择图片 + let photoSelectResult: photoAccessHelper.PhotoSelectResult = await photoPicker.select(photoSelectOptions); + console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(photoSelectResult)); + uris = photoSelectResult.photoUris; + } catch (err) { + let err: BusinessError = error as BusinessError; + console.error(`PhotoViewPicker failed with err, code is ${err.code}, message is ${err.message}`); + } +} + +async function uriGetAssets(): Promise { + // 检查uris数组是否为空 + if (uris.length === 0) { + throw new Error('No URIs available'); + } + try { + let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); + let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); + // 配置查询条件,使用PhotoViewPicker选择图片返回的uri进行查询 + predicates.equalTo('uri', uris[0]); + let fetchOption: photoAccessHelper.FetchOptions = { + fetchColumns: [photoAccessHelper.PhotoKeys.WIDTH, photoAccessHelper.PhotoKeys.HEIGHT, + photoAccessHelper.PhotoKeys.TITLE, photoAccessHelper.PhotoKeys.DURATION], + predicates: predicates + }; + let fetchResult: photoAccessHelper.FetchResult = + await phAccessHelper.getAssets(fetchOption); + // 得到uri对应的PhotoAsset对象,读取文件的部分信息 + const asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); + console.info('asset displayName: ', asset.displayName); + console.info('asset uri: ', asset.uri); + console.info('asset photoType: ', asset.photoType); + console.info('asset width: ', asset.get(photoAccessHelper.PhotoKeys.WIDTH)); + console.info('asset height: ', asset.get(photoAccessHelper.PhotoKeys.HEIGHT)); + console.info('asset title: ' + asset.get(photoAccessHelper.PhotoKeys.TITLE)); + // 获取缩略图 + asset.getThumbnail((err, pixelMap) => { + if (err == undefined) { + console.info('getThumbnail successful ' + JSON.stringify(pixelMap)); + } else { + console.error('getThumbnail fail', err); + } + }); + // [StartExclude import_get_uri_assets] + if (uris.length !== 0 && asset !== null) { + return 'ReadMediaUriSuccess'; + } + // [EndExclude import_get_uri_assets] + } catch (error) { + console.error(`uriGetAssets failed with err, code is ${error.code}, message is ${error.message}`); + return 'ReadMediaUriFail'; + } + return 'ReadMediaUriFail'; +} +// [End import_get_uri_assets] +// [EndExclude function_example] +async function documentURIExample() { + let fileAccessHelper: fileAccess.FileAccessHelper; + // wantInfos 从getFileAccessAbilityInfo()获取 + let wantInfos: Want[] = [ + { + bundleName: 'com.ohos.UserFile.ExternalFileManager', + abilityName: 'FileExtensionAbility', + }, + ]; + try { + fileAccessHelper = fileAccess.createFileAccessHelper(context, wantInfos); + if (!fileAccessHelper) { + console.error('createFileAccessHelper interface returns an undefined object'); + } + // 以内置存储目录为例 + // 示例代码sourceUri表示Download目录,该uri是对应的fileInfo中uri + // 开发者应根据自己实际获取的uri进行开发 + let sourceUri: string = 'file://docs/storage/Users/currentUser/Download'; + let displayName: string = 'test1.txt'; + let fileUri: string; + try { + // 创建文件返回该文件的uri + fileUri = await fileAccessHelper.createFile(sourceUri, displayName); + if (!fileUri) { + console.error('createFile return undefined object'); + } + console.info('createFile success, fileUri: ' + JSON.stringify(fileUri)); + // 将刚创建的文件进行重命名,返回新文件的uri + let renameUri = await fileAccessHelper.rename(fileUri, 'renameFile.txt'); + console.info('rename success, renameUri: ' + JSON.stringify(renameUri)); + } catch (err) { + let error: BusinessError = err as BusinessError; + console.error('createFile failed, errCode:' + error.code + ', errMessage:' + error.message); + } + } catch (err) { + let error: BusinessError = err as BusinessError; + console.error('createFileAccessHelper failed, errCode:' + error.code + ', errMessage:' + error.message); + } +} +// [End function_example] +// [EndExclude copy_file_uri_example] +async function copyingFileByUriExample() { + let fileAccessHelper: fileAccess.FileAccessHelper; + // wantInfos 从getFileAccessAbilityInfo()获取 + let wantInfos: Want[] = [ + { + bundleName: 'com.ohos.UserFile.ExternalFileManager', + abilityName: 'FileExtensionAbility', + }, + ]; + try { + fileAccessHelper = fileAccess.createFileAccessHelper(context, wantInfos); + if (!fileAccessHelper) { + console.error('createFileAccessHelper interface returns an undefined object'); + } + // 以内置存储目录为例 + // 示例代码sourceUri表示Download目录,该uri是对应的fileInfo中uri + // 开发者应根据自己实际获取的uri进行开发 + let sourceUri: string = 'file://docs/storage/Users/currentUser/Download/renameFile.txt'; + // 将文件复制到的位置uri + let destUri: string = 'file://docs/storage/Users/currentUser/Documents'; + // 如果文件名冲突,要使用的文件名 + let displayName: string = 'file.txt'; + // 存放返回的uri + let fileUri: string; + try { + // 复制文件返回该文件的uri + fileUri = await fileAccessHelper.copyFile(sourceUri, destUri, displayName); + if (!fileUri) { + console.error('copyFile return undefined object'); + } + console.info('copyFile success, fileUri: ' + JSON.stringify(fileUri)); + } catch (err) { + let error: BusinessError = err as BusinessError; + console.error('copyFile failed, errCode:' + error.code + ', errMessage:' + error.message); + } + } catch (err) { + let error: BusinessError = err as BusinessError; + console.error('createFileAccessHelper failed, errCode:' + error.code + ', errMessage:' + error.message); + } +} +// [End copy_file_uri_example] + +@Entry +@Component +struct Index { + @State uriMessage: string = ''; // 初始化状态变量,用于显示消息 + @State result: string = ''; + @State documentUris: string[] = []; + + build() { + Column({ space: $r('app.float.size_10') }) { // 外层列布局,子元素间距为10 + Column({ space: $r('app.float.size_10') }) { // 内层列布局,子元素间距为10 + // 读取文件uri按钮 + Button($r('app.string.readDocumentUriButton')) + .width('80%') // 按钮宽度占屏幕宽度80% + .height('10%') // 按钮高度占屏幕高度10% + .fontSize($r('app.float.size_25')) // 按钮字体大小为25 + .borderRadius($r('app.float.size_25')) // 按钮圆角半径为25 + .backgroundColor($r('app.color.whiteColor')) // 按钮背景颜色为白色 + .shadow({ + radius: $r('app.float.size_10'), // 阴影半径为10 + color: $r('app.color.grayColor'), // 阴影颜色为灰色 + offsetX: $r('app.float.size_15'), // 阴影水平偏移量为15 + offsetY: $r('app.float.size_15') // 阴影垂直偏移量为15 + }) + .fontColor($r('app.color.blackColor')) // 按钮字体颜色为黑色 + .onClick(() => { + this.uriMessage = ''; // 重置消息为默认值 + documentURIExample(); // 调用方法处理文档URI + }) + // 读取图片uri按钮 + Button($r('app.string.readMediaUriButton')) + .width('80%') // 按钮宽度占屏幕宽度80% + .height('10%') // 按钮高度占屏幕高度10% + .fontSize($r('app.float.size_25')) // 按钮字体大小为25 + .borderRadius($r('app.float.size_25')) // 按钮圆角半径为25 + .backgroundColor($r('app.color.whiteColor')) // 按钮背景颜色为白色 + .shadow({ + radius: $r('app.float.size_10'), // 阴影半径为10 + color: $r('app.color.grayColor'), // 阴影颜色为灰色 + offsetX: $r('app.float.size_15'), // 阴影水平偏移量为15 + offsetY: $r('app.float.size_15') // 阴影垂直偏移量为15 + }) + .fontColor($r('app.color.blackColor')) // 按钮字体颜色为黑色 + .onClick(async () => { + try { + this.uriMessage = ''; // 重置消息为默认值 + // 首先获取图片URI + await photoPickerGetUri(); + // 然后获取图片资源信息 + this.uriMessage = await uriGetAssets(); + } catch (error) { + console.error('Error:', error); // 日志记录错误信息 + this.uriMessage = 'Error: ' + error.message; // 显示错误信息 + } + }) + // 通过uri复制文件按钮 + Button($r('app.string.copyAFileButton')) + .width('80%') // 按钮宽度占屏幕宽度80% + .height('10%') // 按钮高度占屏幕高度10% + .fontSize($r('app.float.size_25')) // 按钮字体大小为25 + .borderRadius($r('app.float.size_25')) // 按钮圆角半径为25 + .backgroundColor($r('app.color.whiteColor')) // 按钮背景颜色为白色 + .shadow({ + radius: $r('app.float.size_10'), // 阴影半径为10 + color: $r('app.color.grayColor'), // 阴影颜色为灰色 + offsetX: $r('app.float.size_15'), // 阴影水平偏移量为15 + offsetY: $r('app.float.size_15') // 阴影垂直偏移量为15 + }) + .fontColor($r('app.color.blackColor')) // 按钮字体颜色为黑色 + .onClick(() => { + this.uriMessage = ''; // 重置消息为默认值 + copyingFileByUriExample(); // 调用方法处理文件复制 + }) + Text(this.uriMessage) + .fontSize($r('app.float.size_50')) // 文本字体大小为50 + .fontWeight(FontWeight.Bold) // 文本字体加粗 + .margin({ top: $r('app.float.size_20') }) // 文本上边距为20 + // 读取文件按钮 + Button($r('app.string.selectDocumentFileButton')) + .width('80%') // 按钮宽度占屏幕宽度80% + .height('10%') // 按钮高度占屏幕高度10% + .fontSize($r('app.float.size_25')) // 按钮字体大小为25 + .borderRadius($r('app.float.size_25')) // 按钮圆角半径为25 + .backgroundColor($r('app.color.whiteColor')) // 按钮背景颜色为白色 + .shadow({ + radius: $r('app.float.size_10'), // 阴影半径为10 + color: $r('app.color.grayColor'), // 阴影颜色为灰色 + offsetX: $r('app.float.size_15'), // 阴影水平偏移量为15 + offsetY: $r('app.float.size_15') // 阴影垂直偏移量为15 + }) + .fontColor($r('app.color.blackColor')) // 按钮字体颜色为黑色 + .onClick(() => { + documentURIExample(); + this.selectDocumentFiles(); + }) + Text(this.result) + .fontSize($r('app.float.size_50')) // 文本字体大小为50 + .fontWeight(FontWeight.Bold) // 文本字体加粗 + .margin({ top: $r('app.float.size_20') }) // 文本上边距为20 + } + } + .width('100%') // 外层列布局宽度占满屏幕 + .height('100%') // 外层列布局高度占满屏幕 + .alignItems(HorizontalAlign.Center) // 水平居中对齐 + .justifyContent(FlexAlign.Center) // 垂直居中对齐 + .backgroundColor($r('app.color.lightGrayColor')) // 背景颜色为浅灰色 + } + + selectDocumentFiles() { + const documentSelectOptions = new picker.DocumentSelectOptions(); + const context = getContext(this) as common.Context; + const documentViewPicker = new picker.DocumentViewPicker(context); + documentViewPicker.select(documentSelectOptions).then((documentSelectResult: string[]) => { + this.documentUris = documentSelectResult; + console.info('documentViewPicker.select to file succeed and uris are:' + this.documentUris); + if (this.documentUris.length > 0) { + this.readDocumentFile(this.documentUris[0]); + } + }).catch((err: BusinessError) => { + console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`); + }); + } + + readDocumentFile(uri: string) { + let file = fs.openSync(uri, fs.OpenMode.READ_ONLY); + console.info('file fd: ' + file.fd); + let buffer = new ArrayBuffer(4096); // 分配一个大小为4096字节的缓冲区 + let readLen = fs.readSync(file.fd, buffer); // 读取文件内容 + console.info('readSync data to file succeed and buffer size is:' + readLen); + this.result = 'readSync data to file succeed and buffer size is:' + readLen; + fs.closeSync(file); + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/module.json5 b/CoreFile/UserFile/UserFileURI/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..53bb015f4665af68fb160db8015fb64c2779893e --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/module.json5 @@ -0,0 +1,98 @@ +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.FILE_ACCESS_MANAGER", // 声明要申请的权限 + "reason": "$string:reason_MICROPHONE", // 申请该权限的原因 + "usedScene": { + "abilities": [ + "FormAbility" // 使用权限的UIAbility或者ExtensionAbility组件的名称。 + ], + "when":"always" // 调用时机 always:始终 inuse:使用时(在前台) + } + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", // 声明要申请的权限 + "reason": "$string:reason_MICROPHONE", // 申请该权限的原因 + "usedScene": { + "abilities": [ + "FormAbility" // 使用权限的UIAbility或者ExtensionAbility组件的名称。 + ], + "when":"always" // 调用时机 always:始终 inuse:使用时(在前台) + } + }, + { + "name": "ohos.permission.READ_IMAGEVIDEO", // 声明要申请的权限 + "reason": "$string:reason_MICROPHONE", // 申请该权限的原因 + "usedScene": { + "abilities": [ + "FormAbility" // 使用权限的UIAbility或者ExtensionAbility组件的名称。 + ], + "when":"always" // 调用时机 always:始终 inuse:使用时(在前台) + } + } + ] + } +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/color.json b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..b99ebd2b9c4b3a455465e850b4eeee9548ba886a --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/color.json @@ -0,0 +1,24 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "whiteColor", + "value": "#FFFFFF" + }, + { + "name": "lightGrayColor", + "value": "#F0F0F0" + }, + { + "name": "grayColor", + "value": "#808080" + }, + { + "name": "blackColor", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/float.json b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..30e6a4c0edf724b1459705043d7488912328bd16 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/float.json @@ -0,0 +1,36 @@ +{ + "float": [ + { + "name": "size_5", + "value": "10" + }, + { + "name": "size_10", + "value": "10" + }, + { + "name": "size_13", + "value": "13" + }, + { + "name": "size_15", + "value": "15" + }, + { + "name": "size_20", + "value": "20" + }, + { + "name": "size_25", + "value": "25" + }, + { + "name": "size_40", + "value": "40" + }, + { + "name": "size_50", + "value": "50" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/string.json b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..14d5b9d74694e1dfae09c106a92739ad567c577c --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "UserFileURI" + }, + { + "name": "reason_MICROPHONE", + "value": "reason_MICROPHONE" + }, + { + "name": "readDocumentUriButton", + "value": "ReadDocumentUri" + }, + { + "name": "readMediaUriButton", + "value": "ReadMediaUri" + }, + { + "name": "copyAFileButton", + "value": "CopyAFile" + }, + { + "name": "selectDocumentFileButton", + "value": "selectDocumentFile" + } + ] +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/background.png b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/background.png differ diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/foreground.png b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/foreground.png differ diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/layered_image.json b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/startIcon.png b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/profile/backup_config.json b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/profile/main_pages.json b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CoreFile/UserFile/UserFileURI/entry/src/main/resources/dark/element/color.json b/CoreFile/UserFile/UserFileURI/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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/CoreFile/UserFile/UserFileURI/entry/src/ohosTest/ets/test/Ability.test.ets b/CoreFile/UserFile/UserFileURI/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb990456658dfc7bbac0cf9fe622246cc88c1250 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,136 @@ +/* + * 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 { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { describe, expect, it } from '@ohos/hypium'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG = '[Sample_UserFileUri]'; +const DOMAIN = 0xF811; +const BUNDLE = 'UserFileUri_'; +const DELAY_TIME_1S = 1000; +const DELAY_TIME_2S = 2000; + +const DELEGATOR = abilityDelegatorRegistry.getAbilityDelegator(); +const BUNDLENAME = abilityDelegatorRegistry.getArguments().bundleName; + + +export default function abilityTest() { + describe('UserFileUriTest', () => { + /** + * @tc.number CoreFileKit_StartAbility_001 + * @tc.name CoreFileKit_StartAbility_001 + * @tc.desc 启动Ability + */ + it(BUNDLE + 'StartAbility_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,begin'); + // start tested ability + const want: Want = { + bundleName: BUNDLENAME, + abilityName: 'EntryAbility' + }; + await DELEGATOR.startAbility(want); + let driver: Driver = Driver.create(); + await driver.delayMs(DELAY_TIME_1S); + // check top display ability + const ability: UIAbility = await DELEGATOR.getCurrentTopAbility(); + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + done(); + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,end'); + }) + /** + * @tc.number CoreFileKit_UserDocumentFileURI_001 + * @tc.name CoreFileKit_UserDocumentFileURI_001 + * @tc.desc 测试在设备生成文件并读取uri功能 + */ + it(BUNDLE + 'UserDocumentFileURI_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'UserDocumentFileURI_001, begin'); + + const driver = Driver.create(); + // 等待 1000 毫秒,确保 UI 渲染完成 + await driver.delayMs(DELAY_TIME_1S); + + let applyPermission: Driver = Driver.create(); + await applyPermission.click(500, 700); // 点击屏幕坐标 (500, 700) 处 + await driver.delayMs(DELAY_TIME_2S); // 延迟2秒,等待操作完成 + + // 查找按钮组件 + const readButton = await driver.findComponent(ON.text('ReadDocumentUri')); + await readButton.click(); + await driver.delayMs(DELAY_TIME_2S); // 延迟2秒,等待操作完成 + + // 检查文本组件是否改变 + await driver.assertComponentExist(ON.text('ReadDocumentUriSuccess')); + + // 标记测试用例完成 + hilog.info(DOMAIN, TAG, BUNDLE + 'UserDocumentFileURI_001, end') + done(); + }) + /** + * @tc.number CoreFileKit_UserMediaFileURI_002 + * @tc.name CoreFileKit_UserMediaFileURI_002 + * @tc.desc 测试在设备选择图片并读取图片uri功能 + */ + it(BUNDLE + 'UserMediaFileURI_002', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'UserMediaFileURI_002, begin'); + + const driver = Driver.create(); + // 查找按钮组件 + const button = await driver.findComponent(ON.text('ReadMediaUri')); + await button.click(); + await driver.delayMs(DELAY_TIME_2S); // 延迟2秒,等待操作完成 + + let selectMedia: Driver = Driver.create(); + await selectMedia.click(200, 300); // 点击屏幕坐标 (200, 300) 处 + await driver.delayMs(DELAY_TIME_2S); // 延迟2秒,等待操作完成 + + await selectMedia.click(360, 1100); // 点击屏幕坐标 (360, 1100) 处 + await driver.delayMs(DELAY_TIME_2S); // 延迟2秒,等待操作完成 + + await selectMedia.click(680, 80); // 点击屏幕坐标 (680, 80) 处 + await driver.delayMs(DELAY_TIME_2S); // 延迟2秒,等待操作完成 + + // 检查文本组件是否改变 + await driver.assertComponentExist(ON.text('ReadMediaUriSuccess')); + + // 标记测试用例完成 + hilog.info(DOMAIN, TAG, BUNDLE + 'UserMediaFileURI_002, end') + done(); + }) + /** + * @tc.number CoreFileKit_CopyingFileByURI_003 + * @tc.name CoreFileKit_CopyingFileByURI_003 + * @tc.desc 测试通过uri复制文件功能 + */ + it(BUNDLE + 'CopyingFileByURI_003', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'CopyingFileByURI_003, begin'); + + const driver = Driver.create(); + // 查找按钮组件 + const copyButton = await driver.findComponent(ON.text('CopyAFile')); + await copyButton.click(); + await driver.delayMs(DELAY_TIME_2S); // 延迟2秒,等待操作完成 + + // 检查文本组件是否改变 + await driver.assertComponentExist(ON.text('CopyAFileSuccess')); + + // 标记测试用例完成 + hilog.info(DOMAIN, TAG, BUNDLE + 'CopyingFileByURI_003, end') + done(); + }) + }) +} \ No newline at end of file diff --git a/CoreFile/UserFile/UserFileURI/entry/src/ohosTest/ets/test/List.test.ets b/CoreFile/UserFile/UserFileURI/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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/CoreFile/UserFile/UserFileURI/entry/src/ohosTest/module.json5 b/CoreFile/UserFile/UserFileURI/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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/CoreFile/UserFile/UserFileURI/hvigor/hvigor-config.json5 b/CoreFile/UserFile/UserFileURI/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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.1", + "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/CoreFile/UserFile/UserFileURI/hvigorfile.ts b/CoreFile/UserFile/UserFileURI/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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/CoreFile/UserFile/UserFileURI/oh-package.json5 b/CoreFile/UserFile/UserFileURI/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/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.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/CoreFile/UserFile/UserFileURI/ohosTest.md b/CoreFile/UserFile/UserFileURI/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..33c63ca8447fd712ad30265c222cf868cd05e232 --- /dev/null +++ b/CoreFile/UserFile/UserFileURI/ohosTest.md @@ -0,0 +1,11 @@ +# UserFileURI 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------------ | ---- | --------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 申请权限 | 成功拉起应用 | | 成功申请权限 | 是 | Pass | +| 读取文档类文件uri | 安装应用,进入首页 | | 将读取文件uri成功结果输出到指定文本框内 | 是 | Pass | +| 读取媒体文件uri | 安装应用,进入首页 | | 将读取图片的uri成功结果输出到指定文本框 | 是 | Pass | +| 通过uri复制文件 | 安装应用,进入首页 | | 将读取复制文件成功结果输出到指定文本框 | 是 | Pass |