diff --git a/frameworks/innerkits/file_access/include/file_access_ext_ability_module_loader.h b/frameworks/innerkits/file_access/include/file_access_ext_ability_module_loader.h index fad8b9cf8c79e7cc960da40b00910b87a2c5660a..174bad17572ecdcaaf2c92f5fe28018430263d60 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_ability_module_loader.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_ability_module_loader.h @@ -16,7 +16,14 @@ #ifndef FILE_EXT_ABILITY_MODULE_LOADER_H #define FILE_EXT_ABILITY_MODULE_LOADER_H +#include +#include + +#include "extension.h" #include "extension_module_loader.h" +#include "runtime.h" +#include "singleton.h" + namespace OHOS { namespace FileAccessFwk { using namespace AbilityRuntime; diff --git a/frameworks/innerkits/file_access/include/file_access_ext_connection.h b/frameworks/innerkits/file_access/include/file_access_ext_connection.h index e47b0cffd9a9cd1cb0abdcc1414f3caf827135d0..4d51afb8b4782c7103721f959a6456789f69c09a 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_connection.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_connection.h @@ -16,11 +16,14 @@ #ifndef FILE_EXT_CONNECTION_H #define FILE_EXT_CONNECTION_H -#include +#include +#include #include "ability_connect_callback_stub.h" -#include "event_handler.h" +#include "element_name.h" #include "ifile_access_ext_base.h" +#include "iremote_object.h" +#include "refbase.h" #include "want.h" namespace OHOS { @@ -31,21 +34,22 @@ public: virtual ~FileAccessExtConnection() = default; static sptr GetInstance(); - void OnAbilityConnectDone( const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; - void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; - void ConnectFileExtAbility(const AAFwk::Want &want, const sptr &token); - void DisconnectFileExtAbility(); - bool IsExtAbilityConnected(); - sptr GetFileExtProxy(); private: + struct ThreadLockInfo { + std::condition_variable condition; + std::mutex mutex; + bool isReady = false; + }; + ThreadLockInfo connectLockInfo_; + static sptr instance_; static std::mutex mutex_; std::atomic isConnected_ = {false}; diff --git a/frameworks/innerkits/file_access/include/file_access_ext_proxy.h b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h index d4918e22c9c5107d9f5e83953be78387cad94773..f450951cd99889b5d71553a9738698950d599ad0 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_proxy.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_proxy.h @@ -16,10 +16,17 @@ #ifndef FILE_EXT_PROXY_H #define FILE_EXT_PROXY_H -#include +#include +#include +#include #include "file_access_extension_info.h" #include "ifile_access_ext_base.h" +#include "iremote_broker.h" +#include "iremote_object.h" +#include "iremote_proxy.h" +#include "refbase.h" +#include "uri.h" namespace OHOS { namespace FileAccessFwk { diff --git a/frameworks/innerkits/file_access/include/file_access_ext_stub.h b/frameworks/innerkits/file_access/include/file_access_ext_stub.h index 73c1552a19cc3d038137adf15fd9db787d7a3ca2..8c23289297e9d90f9cb76e57dbe13236e3037398 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_stub.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_stub.h @@ -16,11 +16,16 @@ #ifndef FILE_EXT_STUB_H #define FILE_EXT_STUB_H -#include +#include + +#include #include -#include "file_access_extension_info.h" #include "ifile_access_ext_base.h" +#include "iremote_stub.h" +#include "message_option.h" +#include "message_parcel.h" +#include "refbase.h" namespace OHOS { namespace FileAccessFwk { diff --git a/frameworks/innerkits/file_access/include/file_access_ext_stub_impl.h b/frameworks/innerkits/file_access/include/file_access_ext_stub_impl.h index 1cd130ba5c0ec93b4b4003c6dbf30038c3060341..4ee634a0ca0c7b8f4b57d8d615d6a6fbd062379c 100644 --- a/frameworks/innerkits/file_access/include/file_access_ext_stub_impl.h +++ b/frameworks/innerkits/file_access/include/file_access_ext_stub_impl.h @@ -17,11 +17,13 @@ #define FILE_EXT_STUB_IMPL_H #include +#include #include "file_access_ext_ability.h" #include "file_access_ext_stub.h" #include "file_access_extension_info.h" -#include "native_engine/native_value.h" +#include "js_native_api_types.h" +#include "uri.h" namespace OHOS { namespace FileAccessFwk { diff --git a/frameworks/innerkits/file_access/include/file_access_helper.h b/frameworks/innerkits/file_access/include/file_access_helper.h index be151480047119289242ca56f6042df89e7c62ab..df3899d0145fa94b4282fb63b1b7b1e42fd94675 100644 --- a/frameworks/innerkits/file_access/include/file_access_helper.h +++ b/frameworks/innerkits/file_access/include/file_access_helper.h @@ -16,14 +16,17 @@ #ifndef FILE_ACCESS_HELPER_H #define FILE_ACCESS_HELPER_H -#include +#include +#include #include +#include #include "context.h" #include "file_access_ext_connection.h" #include "file_access_extension_info.h" -#include "hilog_wrapper.h" #include "ifile_access_ext_base.h" +#include "iremote_object.h" +#include "refbase.h" #include "uri.h" #include "want.h" diff --git a/frameworks/innerkits/file_access/include/ifile_access_ext_base.h b/frameworks/innerkits/file_access/include/ifile_access_ext_base.h index 5c79a87b62b8fea0fa0cdb801b4171aeacd876d4..fdc837b8ce8d9612634cd5570e0555cb1e7845a8 100644 --- a/frameworks/innerkits/file_access/include/ifile_access_ext_base.h +++ b/frameworks/innerkits/file_access/include/ifile_access_ext_base.h @@ -32,13 +32,13 @@ public: enum { CMD_OPEN_FILE = 1, - CMD_CREATE_FILE = 2, - CMD_MKDIR = 3, - CMD_DELETE = 4, - CMD_MOVE = 5, - CMD_RENAME = 6, - CMD_LIST_FILE = 7, - CMD_GET_ROOTS = 8 + CMD_CREATE_FILE, + CMD_MKDIR, + CMD_DELETE, + CMD_MOVE, + CMD_RENAME, + CMD_LIST_FILE, + CMD_GET_ROOTS }; virtual int OpenFile(const Uri &uri, int flags) = 0; diff --git a/frameworks/innerkits/file_access/src/file_access_ext_ability_module_loader.cpp b/frameworks/innerkits/file_access/src/file_access_ext_ability_module_loader.cpp index 221ccfad1cb53ac66935de81f32e276280dae321..9e79c4de608e00d6a07e5441f8d0bed28d811190 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_ability_module_loader.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_ability_module_loader.cpp @@ -14,6 +14,10 @@ */ #include "file_access_ext_ability_module_loader.h" + +#include +#include + #include "file_access_ext_ability.h" namespace OHOS { diff --git a/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp b/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp index e7e9604213e8ac10430d82dd8cc09d3760a57b9b..5d5da63ca2198d516c3816e273839cc49ecf562b 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_connection.cpp @@ -15,12 +15,19 @@ #include "file_access_ext_connection.h" +#include + +#include "ability_connect_callback_interface.h" #include "ability_manager_client.h" #include "file_access_ext_proxy.h" #include "hilog_wrapper.h" +#include "iremote_broker.h" namespace OHOS { namespace FileAccessFwk { +namespace { + constexpr int WAIT_TIME = 1; // second +} sptr FileAccessExtConnection::instance_ = nullptr; std::mutex FileAccessExtConnection::mutex_; @@ -39,15 +46,18 @@ void FileAccessExtConnection::OnAbilityConnectDone( const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) { if (remoteObject == nullptr) { - HILOG_ERROR("%{public}s failed, remote is nullptr", __func__); + HILOG_ERROR("remote is nullptr"); return; } fileExtProxy_ = iface_cast(remoteObject); if (fileExtProxy_ == nullptr) { - HILOG_ERROR("%{public}s failed, fileExtProxy_ is nullptr", __func__); + HILOG_ERROR("fileExtProxy_ is nullptr"); return; } isConnected_.store(true); + std::lock_guard lock(connectLockInfo_.mutex); + connectLockInfo_.isReady = true; + connectLockInfo_.condition.notify_all(); } void FileAccessExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) @@ -59,7 +69,15 @@ void FileAccessExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementN void FileAccessExtConnection::ConnectFileExtAbility(const AAFwk::Want &want, const sptr &token) { ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, token); - HILOG_INFO("%{public}s called end, ret=%{public}d", __func__, ret); + if (ret != ERR_OK) { + HILOG_INFO("ConnectAbility ret=%{public}d", ret); + return; + } + std::unique_lock lock(connectLockInfo_.mutex); + if (!connectLockInfo_.condition.wait_for(lock, std::chrono::seconds(WAIT_TIME), + [this] { return fileExtProxy_ != nullptr && connectLockInfo_.isReady; })) { + HILOG_INFO("Wait connect timeout."); + } } void FileAccessExtConnection::DisconnectFileExtAbility() diff --git a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp index 46a754421ce84381009fb7e909aa78647715ecc2..059331c8f738c43bfa6d841554d596ac6ceb9aa9 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_proxy.cpp @@ -18,6 +18,9 @@ #include "file_access_framework_errno.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" +#include "ipc_types.h" +#include "message_option.h" +#include "message_parcel.h" namespace OHOS { namespace FileAccessFwk { diff --git a/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp b/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp index ddc2ee80dbd9a4f2cda1fe3aacc2db89dac76b80..b08878572ab402e1c714e6a14ea676d40d6a526e 100644 --- a/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp +++ b/frameworks/innerkits/file_access/src/file_access_ext_stub.cpp @@ -15,11 +15,23 @@ #include "file_access_ext_stub.h" +#include +#include +#include +#include +#include +#include + +#include "access_token.h" #include "accesstoken_kit.h" +#include "file_access_extension_info.h" #include "file_access_framework_errno.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" +#include "ipc_object_stub.h" #include "ipc_skeleton.h" +#include "ipc_types.h" +#include "uri.h" namespace OHOS { namespace FileAccessFwk { diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 39dd4886d3e169e81db4e2939bdfe224255cb2bc..9a3a497a74c6272f60f5fba99355966be7e97a64 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -63,6 +63,11 @@ FileAccessHelper::FileAccessHelper(const sptr &token, std::shared_ptr FileAccessHelper::Creator(const sptr &token, const AAFwk::Want &want) { + if (token == nullptr) { + HILOG_ERROR("FileAccessHelper::Creator failed, token is nullptr"); + return nullptr; + } + sptr fileAccessExtProxy = nullptr; sptr fileAccessExtConnection = FileAccessExtConnection::GetInstance(); @@ -88,7 +93,7 @@ std::shared_ptr FileAccessHelper::Creator( const std::shared_ptr &context, const AAFwk::Want &want) { if (context == nullptr) { - HILOG_ERROR("failed, context == nullptr"); + HILOG_ERROR("FileAccessHelper::Creator failed, context is nullptr"); return nullptr; } @@ -114,6 +119,10 @@ std::shared_ptr FileAccessHelper::Creator( bool FileAccessHelper::Release() { + if (fileAccessExtConnection_ == nullptr) { + return false; + } + if (fileAccessExtConnection_->IsExtAbilityConnected()) { fileAccessExtConnection_->DisconnectFileExtAbility(); } @@ -123,6 +132,10 @@ bool FileAccessHelper::Release() bool FileAccessHelper::GetProxy() { + if (fileAccessExtConnection_ == nullptr) { + return false; + } + if (!fileAccessExtConnection_->IsExtAbilityConnected()) { fileAccessExtConnection_->ConnectFileExtAbility(want_, token_); } diff --git a/frameworks/innerkits/file_access/src/napi_common_fileaccess.cpp b/frameworks/innerkits/file_access/src/napi_common_fileaccess.cpp index b8a02f7b60e53a1d3b7c3b7a1f612b26bc68ac7b..7f0075c38ebe18554355c3d9f90d00a95242b2ad 100644 --- a/frameworks/innerkits/file_access/src/napi_common_fileaccess.cpp +++ b/frameworks/innerkits/file_access/src/napi_common_fileaccess.cpp @@ -112,27 +112,21 @@ napi_value WrapFileInfo(napi_env env, const FileInfo &fileInfo) NAPI_CALL(env, napi_create_object(env, &jsObject)); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapStringToJS(env, fileInfo.uri.ToString()); SetPropertyValueByPropertyName(env, jsObject, "uri", jsValue); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapStringToJS(env, fileInfo.fileName); SetPropertyValueByPropertyName(env, jsObject, "fileName", jsValue); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapStringToJS(env, fileInfo.mode); SetPropertyValueByPropertyName(env, jsObject, "mode", jsValue); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapInt64ToJS(env, fileInfo.size); SetPropertyValueByPropertyName(env, jsObject, "size", jsValue); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapInt64ToJS(env, fileInfo.mtime); SetPropertyValueByPropertyName(env, jsObject, "mtime", jsValue); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapStringToJS(env, fileInfo.mimeType); SetPropertyValueByPropertyName(env, jsObject, "mimeType", jsValue); @@ -150,12 +144,10 @@ bool UnwrapFileInfo(napi_env env, napi_value param, FileInfo &fileInfo) fileInfo.uri = Uri(natValueString); } - natValueString = ""; if (OHOS::AppExecFwk::UnwrapStringByPropertyName(env, param, "fileName", natValueString)) { fileInfo.fileName = natValueString; } - natValueString = ""; if (OHOS::AppExecFwk::UnwrapStringByPropertyName(env, param, "mode", natValueString)) { fileInfo.mode = natValueString; } @@ -165,12 +157,10 @@ bool UnwrapFileInfo(napi_env env, napi_value param, FileInfo &fileInfo) fileInfo.size = natValueInt64; } - natValueInt64 = ERR_OK; if (UnwrapInt64ByPropertyName(env, param, "mtime", natValueInt64)) { fileInfo.mtime = natValueInt64; } - natValueString = ""; if (OHOS::AppExecFwk::UnwrapStringByPropertyName(env, param, "mimeType", natValueString)) { fileInfo.mimeType = natValueString; } @@ -226,19 +216,15 @@ napi_value WrapDeviceInfo(napi_env env, const DeviceInfo &deviceInfo) NAPI_CALL(env, napi_create_object(env, &jsObject)); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapStringToJS(env, deviceInfo.uri.ToString()); SetPropertyValueByPropertyName(env, jsObject, "uri", jsValue); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapStringToJS(env, deviceInfo.displayName); SetPropertyValueByPropertyName(env, jsObject, "displayName", jsValue); - jsValue = nullptr; jsValue = OHOS::AppExecFwk::WrapStringToJS(env, deviceInfo.deviceId); SetPropertyValueByPropertyName(env, jsObject, "deviceId", jsValue); - jsValue = nullptr; jsValue = WrapUint32ToJS(env, deviceInfo.flags); SetPropertyValueByPropertyName(env, jsObject, "flags", jsValue); @@ -256,12 +242,10 @@ bool UnwrapDeviceInfo(napi_env env, napi_value param, DeviceInfo &deviceInfo) deviceInfo.uri = Uri(natValueString); } - natValueString = ""; if (OHOS::AppExecFwk::UnwrapStringByPropertyName(env, param, "displayName", natValueString)) { deviceInfo.displayName = natValueString; } - natValueString = ""; if (OHOS::AppExecFwk::UnwrapStringByPropertyName(env, param, "deviceId", natValueString)) { deviceInfo.deviceId = natValueString; } diff --git a/interfaces/kits/napi/common/file_extension_info_napi.cpp b/interfaces/kits/napi/common/file_extension_info_napi.cpp index 800b6e0cc8f253347f3a570bdc047799d579740a..5673104c1c0ff9c3d9c3fd722d6a1299ea2d0463 100644 --- a/interfaces/kits/napi/common/file_extension_info_napi.cpp +++ b/interfaces/kits/napi/common/file_extension_info_napi.cpp @@ -12,11 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "file_extension_info_napi.h" +#include +#include #include + #include "file_access_extension_info.h" #include "hilog_wrapper.h" +#include "js_native_api.h" +#include "napi/native_common.h" namespace OHOS { namespace FileAccessFwk { diff --git a/interfaces/kits/napi/common/file_extension_info_napi.h b/interfaces/kits/napi/common/file_extension_info_napi.h index dab3c05960f8e5563dae6088f8d3fb1dc9b067e0..e66a8b02adb58a3fa8a10abd9dcfe0469e1f0680 100644 --- a/interfaces/kits/napi/common/file_extension_info_napi.h +++ b/interfaces/kits/napi/common/file_extension_info_napi.h @@ -16,8 +16,8 @@ #ifndef FILE_EXTENSION_INFO_NAPI_H #define FILE_EXTENSION_INFO_NAPI_H -#include "napi/native_api.h" #include "napi/native_node_api.h" + namespace OHOS { namespace FileAccessFwk { void InitFlag(napi_env env, napi_value exports); diff --git a/interfaces/kits/napi/file_access_ext_ability/file_access_ext_ability_module.cpp b/interfaces/kits/napi/file_access_ext_ability/file_access_ext_ability_module.cpp index 539d60ddf6b3092a0463c45971e153ac7d3225a0..4d4891b3756fb86a07e8228886a106224252bd83 100644 --- a/interfaces/kits/napi/file_access_ext_ability/file_access_ext_ability_module.cpp +++ b/interfaces/kits/napi/file_access_ext_ability/file_access_ext_ability_module.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "module_manager/native_module_manager.h" #include "native_engine/native_engine.h" extern const char _binary_file_access_ext_ability_js_start[]; diff --git a/interfaces/kits/napi/file_extension_info_module/module_export_napi.cpp b/interfaces/kits/napi/file_extension_info_module/module_export_napi.cpp index 950e3900333eb9fd4b50863fc3dec1da73b6314e..b74e8166e5d6a0d55dc06a38d04d63c97e1de50b 100644 --- a/interfaces/kits/napi/file_extension_info_module/module_export_napi.cpp +++ b/interfaces/kits/napi/file_extension_info_module/module_export_napi.cpp @@ -15,10 +15,9 @@ #include "module_export_napi.h" -#include #include "file_extension_info_napi.h" +#include "js_native_api_types.h" #include "napi/native_api.h" -#include "napi/native_node_api.h" namespace OHOS { namespace FileAccessFwk { 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 index 756e587c2cfbcd0b401a49c4f51f8136dafad683..cc1f349791acd8307f165d801b9d2de1616ca6e7 100644 --- a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts +++ b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -17,8 +17,8 @@ import fileio from '@ohos.fileio' import { init, delVolumeInfo, getVolumeInfoList } from './VolumeManager' import { onReceiveEvent } from './Subcriber' import fileExtensionInfo from "@ohos.fileExtensionInfo" -import appManager from '@ohos.application.appManager'; import hilog from '@ohos.hilog' +import process from '@ohos.process'; const FLAG = fileExtensionInfo.FLAG; const BUNDLE_NAME = 'com.ohos.UserFile.ExternalFileManager'; @@ -33,7 +33,7 @@ export default class FileExtAbility extends Extension { init(); onReceiveEvent(function (data) { if (data.event == 'usual.event.data.VOLUME_MOUNTED') { - appManager.killProcessesByBundleName(BUNDLE_NAME); + process.exit(0); } else { delVolumeInfo(data.parameters.id); } diff --git a/services/file_extension_hap/entry/src/main/module.json b/services/file_extension_hap/entry/src/main/module.json index 3908c63b3421cbcc5c56f8a048201758823e3c5b..2be4db66968c7bb106b3ce08f9c183455f07135d 100644 --- a/services/file_extension_hap/entry/src/main/module.json +++ b/services/file_extension_hap/entry/src/main/module.json @@ -22,9 +22,6 @@ } ], "requestPermissions": [ - { - "name": "ohos.permission.CLEAN_BACKGROUND_PROCESSES" - }, { "name": "ohos.permission.STORAGE_MANAGER" } diff --git a/services/signature/fileextension.p7b b/services/signature/fileextension.p7b index 66b4457a8a81fb8d3356cf46d67226c850944858..ae89c44a5f8ded8ce4723cbd922a2dd5f9897727 100644 Binary files a/services/signature/fileextension.p7b and b/services/signature/fileextension.p7b differ diff --git a/services/src/fileoper/file_info.cpp b/services/src/fileoper/file_info.cpp index 3eaf90067c1e03dc9f90954ed76c30fed9b15017..d08871a0fb5ff26d48bc0fcc18b86cc2e403ac65 100644 --- a/services/src/fileoper/file_info.cpp +++ b/services/src/fileoper/file_info.cpp @@ -12,8 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "file_info.h" + +#include +#include + #include "log.h" + using namespace std; namespace OHOS { diff --git a/services/src/fileoper/file_info.h b/services/src/fileoper/file_info.h index 8a8742b69811f060918fbf61092aa89ea283bc9e..b46e662c9153e5d99bcdafc3dcc420cd77a9b784 100644 --- a/services/src/fileoper/file_info.h +++ b/services/src/fileoper/file_info.h @@ -16,7 +16,9 @@ #define STORAGE_SERVICES_FILE_INFO_H #include +#include #include + #include "parcel.h" namespace OHOS {