diff --git a/services/BUILD.gn b/services/BUILD.gn index aa10b3988a8237194a79b72ab2e69da92052e3f5..2fefab42bc3e02ef66da2e8dd798ebb3c226c498 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -19,6 +19,7 @@ group("fms") { deps = [ ":fms_server", ":fms_service.cfg", + ":external_file_manager_hap", ] } @@ -91,3 +92,39 @@ ohos_shared_library("fms_server") { "samgr_standard:samgr_proxy", ] } + +### external file manager hap +ohos_hap("external_file_manager_hap") { + hap_profile = "file_extension_hap/entry/src/main/module.json" + deps = [ + ":external_file_manager_js_assets", + ":external_file_manager_resources", + ] + certificate_profile = "signature/fileextension.p7b" + hap_name = "external_file_manager" + subsystem_name = "filemanagement" + part_name = "user_file_service" + module_install_dir = "app/com.ohos.UserFile.ExternalFileManager" +} + +ohos_js_assets("external_file_manager_js_assets") { + hap_profile = "file_extension_hap/entry/src/main/module.json" + ets2abc = true + source_dir = "file_extension_hap/entry/src/main/ets" +} + +ohos_app_scope("external_file_manager_app_profile") { + app_profile = "file_extension_hap/AppScope/app.json" + sources = [ "file_extension_hap/AppScope/resources" ] +} + +ohos_resources("external_file_manager_resources") { + sources = [ + "file_extension_hap/entry/src/main/resources", + ] + deps = [ + ":external_file_manager_app_profile", + ] + hap_profile = "file_extension_hap/entry/src/main/module.json" +} +### external file manager hap \ No newline at end of file diff --git a/services/file_extension_hap/AppScope/app.json b/services/file_extension_hap/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..9ed7e1acf9559e97986f90dcbbec33f3cfc6bd63 --- /dev/null +++ b/services/file_extension_hap/AppScope/app.json @@ -0,0 +1,11 @@ +{ + "app": { + "bundleName": "com.ohos.UserFile.ExternalFileManager", + "versionCode": 100, + "versionName": "1.0.0", + "minAPIVersion": 9, + "targetAPIVersion": 9, + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/services/file_extension_hap/AppScope/resources/base/element/string.json b/services/file_extension_hap/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..bdb9ac3627d877c9908763446d259fc514e50c41 --- /dev/null +++ b/services/file_extension_hap/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ExternalFileManager" + } + ] +} diff --git a/services/file_extension_hap/AppScope/resources/base/media/app_icon.png b/services/file_extension_hap/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/services/file_extension_hap/AppScope/resources/base/media/app_icon.png differ diff --git a/services/file_extension_hap/build-profile.json5 b/services/file_extension_hap/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8fac20813cb081694e75ab50d19a5faac524c66c --- /dev/null +++ b/services/file_extension_hap/build-profile.json5 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 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": { + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/services/file_extension_hap/entry/build-profile.json5 b/services/file_extension_hap/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3089f7ba484c6385983234a1f147c161a5d9cdd --- /dev/null +++ b/services/file_extension_hap/entry/build-profile.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 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": { + }, + "targets": [ + { + "name": "default", + } + ] +} \ No newline at end of file diff --git a/services/file_extension_hap/entry/hvigorfile.js b/services/file_extension_hap/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..d7720ee6a7aad5c617d1fd2f6fc8c87067bfa32c --- /dev/null +++ b/services/file_extension_hap/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/services/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts b/services/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..18d98c8eff2695a4f4ff6fa1d03e9da70b763a96 --- /dev/null +++ b/services/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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 AbilityStage from "@ohos.application.AbilityStage" +import hilog from '@ohos.hilog' + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + hilog.info(0x0001, 'js server tag dsa', "MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..32c6778f69c2fcbb935be204eb84fe7c6b001107 --- /dev/null +++ b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2022 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 Extension from '@ohos.application.FileExtensionAbility' +import uriClass from '@ohos.uri' +import fileio from '@ohos.fileio' +import hilog from '@ohos.hilog' +import fileExtensionInfo from "@ohos.fileExtensionInfo" + +const FLAG = fileExtensionInfo.FLAG; + +export default class FileExtAbility extends Extension { + onCreate(want) { + hilog.info(0x0001, 'js server tag dsa', 'FileExtAbility onCreate, want:' + want.abilityName); + } + + getPath(uri) { + let uriObj = new uriClass.URI(uri); + let path = uriObj.path; + hilog.info(0x0001, 'js server tag dsa', 'getPath is ' + path); + return path; + } + + genNewFileUri(uri, displayName) { + let arr = uri.split('/'); + let newFileUri = uri; + if (arr.pop() == '') { + newFileUri += displayName; + } else { + newFileUri += '/' + displayName; + } + hilog.info(0x0001, 'js server tag dsa', 'genNewFileUri is ' + newFileUri); + return newFileUri; + } + + getFileName(uri) { + let arr = uri.split('/'); + let name = arr.pop(); + if (name == '') { + name = arr.pop(); + } + return name; + } + + renameUri(uri, displayName) { + let arr = uri.split('/'); + let newFileUri = ''; + if (arr.pop() == '') { + arr.pop(); + arr.push(displayName) + arr.push(''); + } else { + arr.push(displayName) + } + for (var index = 0; index < arr.length; index++) { + if (arr[index] == '') { + newFileUri += '/'; + } else if (index == arr.length - 1) { + newFileUri += arr[index]; + } else { + newFileUri += arr[index] + '/'; + } + } + hilog.info(0x0001, 'js server tag dsa', 'renameUri is ' + newFileUri); + return newFileUri; + } + + listDir(path, cb) { + hilog.info(0x0001, 'js server tag dsa', 'listDir: ' + path); + try { + let stat = fileio.statSync(path); + if (stat.isDirectory()) { + let dir = fileio.opendirSync(path); + let hasNextFile = true; + while (hasNextFile) { + try { + let dirent = dir.readSync(); + this.listDir(path + '/' + dirent.name, cb); + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'listDir dir.readSync catch' + e); + hasNextFile = false; + cb(path); + } + } + } else { + cb(path); + } + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'listDir catch ' + e + ' ' + path); + cb(path); + } + } + + openFile(sourceFileUri, flags) { + hilog.info(0x0001, 'js server tag dsa', 'openFile, uri:' + sourceFileUri + ',flags:' + flags); + let fd = 0; + try { + let path = this.getPath(sourceFileUri); + fd = fileio.openSync(path, flags, 0o666); + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'openFile catch' + e); + fd = -1; + } + + return fd; + } + + closeFile(fd, uri) { + try { + fileio.closeSync(fd); + return true; + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'closeFile catch' + e); + return false; + } + } + + createFile(parentUri, displayName) { + hilog.info(0x0001, 'js server tag dsa', 'createFile, uri:' + parentUri + ', displayName:' + displayName); + try { + let newFileUri = this.genNewFileUri(parentUri, displayName); + let path = this.getPath(newFileUri); + fileio.openSync(path, 0o100, 0o666); + return newFileUri; + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'createFile catch' + e); + return ''; + } + } + + mkdir(parentUri, displayName) { + hilog.info(0x0001, 'js server tag dsa', 'mkdir, uri:' + parentUri + ', displayName:' + displayName); + try { + let newFileUri = this.genNewFileUri(parentUri, displayName); + let path = this.getPath(newFileUri); + fileio.mkdirSync(path); + return newFileUri; + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'mkdir catch' + e); + return ''; + } + } + + delete(selectFileUri) { + hilog.info(0x0001, 'js server tag dsa', 'delete, uri:' + selectFileUri); + let path = this.getPath(selectFileUri); + let code = 0; + this.listDir(path, function (filePath) { + try { + fileio.unlinkSync(filePath); + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'delete catch' + e); + code = -1; + } + }); + + return code; + } + + move(sourceFileUri, targetParentUri) { + hilog.info(0x0001, 'js server tag dsa', 'move, sourceFileUri:' + sourceFileUri + ', targetParentUri:' + targetParentUri); + try { + let displayName = this.getFileName(sourceFileUri); + let newFileUri = this.genNewFileUri(targetParentUri, displayName); + let oldPath = this.getPath(sourceFileUri); + let newPath = this.getPath(newFileUri); + fileio.renameSync(oldPath, newPath); + return newFileUri; + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'rename catch' + e); + return ''; + } + } + + rename(sourceFileUri, displayName) { + hilog.info(0x0001, 'js server tag dsa', 'rename, sourceFileUri:' + sourceFileUri + ', displayName:' + displayName); + try { + let newFileUri = this.renameUri(sourceFileUri, displayName); + let oldPath = this.getPath(sourceFileUri); + let newPath = this.getPath(newFileUri); + fileio.renameSync(oldPath, newPath); + return newFileUri; + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'rename catch' + e); + return ''; + } + } + + query(sourceFileUri) { + hilog.info(0x0001, 'js server tag dsa', 'query, sourceFileUri:' + sourceFileUri); + try { + let path = this.getPath(sourceFileUri); + let stat = fileio.statSync(path); + return { + uri: sourceFileUri, + fileName: this.getFileName(sourceFileUri), + mode: stat.mode, + size: stat.size, + mtime: stat.mtime, + mimiType: '', + }; + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'query catch' + e); + return null; + } + } + + listFile(sourceFileUri) { + hilog.info(0x0001, 'js server tag dsa', 'listFile, sourceFileUri: ' + sourceFileUri); + + let infos = []; + try { + let path = this.getPath(sourceFileUri); + let dir = fileio.opendirSync(path); + let hasNextFile = true; + while (hasNextFile) { + try { + let dirent = dir.readSync(); + let stat = fileio.statSync(path + '/' + dirent.name); + infos.push({ + uri: this.genNewFileUri(sourceFileUri, dirent.name), + fileName: dirent.name, + mode: stat.mode, + size: stat.size, + mtime: stat.mtime, + mimiType: '', + }); + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'dir.readSync catch' + e); + hasNextFile = false; + } + } + } catch (e) { + hilog.info(0x0001, 'js server tag dsa', 'listFile catch' + e); + } + + hilog.info(0x0001, 'js server tag dsa', 'listFile return: ' + JSON.stringify(infos)); + return infos; + } + + getRoots() { + hilog.info(0x0001, 'js server tag dsa', 'getRoots'); + let roots = [{ + uri: 'fileAccess:///data/storage/el1/bundle/storage_daemon', + displayName: 'storage_daemon', + deviceId: '', + flags: FLAG.SUPPORTS_WRITE | FLAG.SUPPORTS_DELETE | FLAG.SUPPORTS_RENAME | FLAG.SUPPORTS_COPY + | FLAG.SUPPORTS_MOVE | FLAG.SUPPORTS_REMOVE | FLAG.DIR_SUPPORTS_CREATE | FLAG.DIR_PREFERS_LAST_MODIFIED, + }]; + return roots; + } +}; \ No newline at end of file diff --git a/services/file_extension_hap/entry/src/main/module.json b/services/file_extension_hap/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..20916b6afa6dc19b9080114a6bceaf8c1be1d94e --- /dev/null +++ b/services/file_extension_hap/entry/src/main/module.json @@ -0,0 +1,25 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "mainElement": "FileExtensionAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [], + "extensionAbilities": [ + { + "srcEntrance": "./ets/FileExtensionAbility/FileExtensionAbility.ts", + "name": "FileExtensionAbility", + "type": "fileAccess", + "visible": true + } + ] + } +} \ No newline at end of file diff --git a/services/file_extension_hap/entry/src/main/resources/base/element/string.json b/services/file_extension_hap/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c4e8611bfbd8bb3177924f05e7e22a7ca3dcf5dd --- /dev/null +++ b/services/file_extension_hap/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "description_serviceability", + "value": "description_serviceability" + } + ] +} \ No newline at end of file diff --git a/services/file_extension_hap/entry/src/main/resources/base/media/icon.png b/services/file_extension_hap/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/services/file_extension_hap/entry/src/main/resources/base/media/icon.png differ diff --git a/services/file_extension_hap/entry/src/main/resources/base/profile/main_pages.json b/services/file_extension_hap/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b12d9e9faa33835d362c73333632d70b7c61328a --- /dev/null +++ b/services/file_extension_hap/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,3 @@ +{ + "src": [] +} \ No newline at end of file diff --git a/services/file_extension_hap/hvigorfile.js b/services/file_extension_hap/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..5f2735e3deeaf655828407544bbed9365c258278 --- /dev/null +++ b/services/file_extension_hap/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/services/signature/fileextension.p7b b/services/signature/fileextension.p7b new file mode 100644 index 0000000000000000000000000000000000000000..ddb74239918c96a341ee6dc7d118aba46355e5d0 Binary files /dev/null and b/services/signature/fileextension.p7b differ