From f1659bda260ec4865c790178c50e7a74685ad610 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Wed, 13 Jul 2022 11:36:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- .../file_access/include/ifile_access_ext_base.h | 14 +++++++------- .../file_access/src/file_access_helper.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) 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 5c79a87b..fdc837b8 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_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 39dd4886..97545ce0 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -114,6 +114,10 @@ std::shared_ptr FileAccessHelper::Creator( bool FileAccessHelper::Release() { + if (fileAccessExtConnection_ == nullptr) { + return false; + } + if (fileAccessExtConnection_->IsExtAbilityConnected()) { fileAccessExtConnection_->DisconnectFileExtAbility(); } @@ -123,6 +127,10 @@ bool FileAccessHelper::Release() bool FileAccessHelper::GetProxy() { + if (fileAccessExtConnection_ == nullptr) { + return false; + } + if (!fileAccessExtConnection_->IsExtAbilityConnected()) { fileAccessExtConnection_->ConnectFileExtAbility(want_, token_); } -- Gitee From a64ec2c135935877ddaeb0e746f2cf36f4d3f64f Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Wed, 13 Jul 2022 15:07:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- .../file_access/src/file_access_helper.cpp | 7 ++++++- .../file_access/src/napi_common_fileaccess.cpp | 16 ---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 97545ce0..f29a7696 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("failed, token == nullptr"); + return nullptr; + } + sptr fileAccessExtProxy = nullptr; sptr fileAccessExtConnection = FileAccessExtConnection::GetInstance(); @@ -130,7 +135,7 @@ 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 b8a02f7b..7f0075c3 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; } -- Gitee From 3c6bdb5b230bd997261b14bc3adb74a98a825425 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Wed, 13 Jul 2022 15:34:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- frameworks/innerkits/file_access/src/file_access_helper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index f29a7696..9a3a497a 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -64,7 +64,7 @@ FileAccessHelper::FileAccessHelper(const sptr &token, std::shared_ptr FileAccessHelper::Creator(const sptr &token, const AAFwk::Want &want) { if (token == nullptr) { - HILOG_ERROR("failed, token == nullptr"); + HILOG_ERROR("FileAccessHelper::Creator failed, token is nullptr"); return nullptr; } @@ -93,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; } -- Gitee