diff --git a/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp b/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp index f701609be01d88ff071c0c29d7bcc6188c2223c6..b57b0b02d6f7160eaeba7c1b9b930910d61bc7a3 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp @@ -40,8 +40,7 @@ int FileAccessExtProxy::OpenFile(const Uri &uri, const int flags, int &fd) return E_IPCS; } - std::string insideInputUri = uri.ToString(); - if (!data.WriteString(insideInputUri)) { + if (!data.WriteParcelable(&uri)) { HILOG_ERROR("fail to WriteParcelable uri"); return E_IPCS; } @@ -89,8 +88,7 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display return E_IPCS; } - std::string insideInputUri = parent.ToString(); - if (!data.WriteString(insideInputUri)) { + if (!data.WriteParcelable(&parent)) { HILOG_ERROR("fail to WriteParcelable parent"); return E_IPCS; } @@ -119,17 +117,17 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display return ret; } - std::string tempUri; - if (!reply.ReadString(tempUri)) { + std::unique_ptr tempUri(reply.ReadParcelable()); + if (tempUri == nullptr) { HILOG_ERROR("ReadParcelable value is nullptr."); return E_IPCS; } - if (tempUri.empty()) { + newFile = Uri(*tempUri); + if (newFile.ToString().empty()) { HILOG_ERROR("get uri is empty."); return E_GETRESULT; } - newFile = Uri(tempUri); return ERR_OK; } @@ -144,8 +142,7 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, return E_IPCS; } - std::string insideInputUri = parent.ToString(); - if (!data.WriteString(insideInputUri)) { + if (!data.WriteParcelable(&parent)) { HILOG_ERROR("fail to WriteParcelable parent"); return E_IPCS; } @@ -174,17 +171,17 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName, return ret; } - std::string tempUri; - if (!reply.ReadString(tempUri)) { + std::unique_ptr tempUri(reply.ReadParcelable()); + if (tempUri == nullptr) { HILOG_ERROR("ReadParcelable value is nullptr."); return E_IPCS; } - if (tempUri.empty()) { + newFile = Uri(*tempUri); + if (newFile.ToString().empty()) { HILOG_ERROR("get uri is empty."); return E_GETRESULT; } - newFile = Uri(tempUri); return ERR_OK; } @@ -199,8 +196,7 @@ int FileAccessExtProxy::Delete(const Uri &sourceFile) return E_IPCS; } - std::string insideInputUri = sourceFile.ToString(); - if (!data.WriteString(insideInputUri)) { + if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR("fail to WriteParcelable sourceFile"); return E_IPCS; } @@ -237,14 +233,12 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri return E_IPCS; } - std::string insideInputSourceUri = sourceFile.ToString(); - if (!data.WriteString(insideInputSourceUri)) { + if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR("fail to WriteParcelable sourceFile"); return E_IPCS; } - std::string insideInputTargetUri = targetParent.ToString(); - if (!data.WriteString(insideInputTargetUri)) { + if (!data.WriteParcelable(&targetParent)) { HILOG_ERROR("fail to WriteParcelable targetParent"); return E_IPCS; } @@ -268,17 +262,17 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri return ret; } - std::string tempUri; - if (!reply.ReadString(tempUri)) { + std::unique_ptr tempUri(reply.ReadParcelable()); + if (tempUri == nullptr) { HILOG_ERROR("ReadParcelable value is nullptr."); return E_IPCS; }; - if (tempUri.empty()) { + newFile = Uri(*tempUri); + if (newFile.ToString().empty()) { HILOG_ERROR("get uri is empty."); return E_GETRESULT; } - newFile = Uri(tempUri); return ERR_OK; } @@ -287,15 +281,13 @@ static int WriteCopyFuncArguments(OHOS::MessageParcel &data, const Uri &sourceUr { UserAccessTracer trace; trace.Start("WriteCopyFuncArguments"); - std::string insideInputSourceUri = sourceUri.ToString(); - if (!data.WriteString(insideInputSourceUri)) { - HILOG_ERROR("fail to WriteParcelable insideInputSourceUri"); + if (!data.WriteParcelable(&sourceUri)) { + HILOG_ERROR("fail to WriteParcelable uri"); return E_IPCS; } - std::string insideInputTargetUri = destUri.ToString(); - if (!data.WriteString(insideInputTargetUri)) { - HILOG_ERROR("fail to WriteParcelable insideInputTargetUri"); + if (!data.WriteParcelable(&destUri)) { + HILOG_ERROR("fail to WriteParcelable targetParent"); return E_IPCS; } @@ -387,8 +379,7 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display return E_IPCS; } - std::string insideInputSourceUri = sourceFile.ToString(); - if (!data.WriteString(insideInputSourceUri)) { + if (!data.WriteParcelable(&sourceFile)) { HILOG_ERROR("fail to WriteParcelable sourceFile"); return E_IPCS; } @@ -417,17 +408,17 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display return ret; } - std::string tempUri; - if (!reply.ReadString(tempUri)) { + std::unique_ptr tempUri(reply.ReadParcelable()); + if (tempUri == nullptr) { HILOG_ERROR("ReadParcelable value is nullptr."); return E_IPCS; } - if (tempUri.empty()) { + newFile = Uri(*tempUri); + if (newFile.ToString().empty()) { HILOG_ERROR("get uri is empty."); return E_GETRESULT; } - newFile = Uri(tempUri); return ERR_OK; } @@ -593,8 +584,7 @@ int FileAccessExtProxy::Query(const Uri &uri, std::vector &columns, return E_IPCS; } - std::string insideInputUri = uri.ToString(); - if (!data.WriteString(insideInputUri)) { + if (!data.WriteParcelable(&uri)) { HILOG_ERROR("fail to WriteParcelable sourceFile"); return E_IPCS; } @@ -683,8 +673,7 @@ static int WriteThumbnailArgs(MessageParcel &data, const Uri &uri, const Thumbna HILOG_ERROR("WriteInterfaceToken failed"); return E_IPCS; } - std::string insideInputUri = uri.ToString(); - if (!data.WriteString(insideInputUri)) { + if (!data.WriteParcelable(&uri)) { HILOG_ERROR("fail to WriteParcelable selectfile"); return E_IPCS; } @@ -747,8 +736,7 @@ int FileAccessExtProxy::GetFileInfoFromUri(const Uri &selectFile, FileInfo &file return E_IPCS; } - std::string insideInputUri = selectFile.ToString(); - if (!data.WriteString(insideInputUri)) { + if (!data.WriteParcelable(&selectFile)) { HILOG_ERROR("fail to WriteParcelable selectFile"); return E_IPCS; } @@ -836,8 +824,7 @@ int FileAccessExtProxy::Access(const Uri &uri, bool &isExist) return E_IPCS; } - std::string insideInputUri = uri.ToString(); - if (!data.WriteString(insideInputUri)) { + if (!data.WriteParcelable(&uri)) { HILOG_ERROR("fail to WriteParcelable uri"); return E_IPCS; } diff --git a/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp b/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp index 18a286639a099a96dc7a07f163aed1e04576815e..854bff8694f751379443254c689062fc796fd2e1 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp @@ -94,17 +94,12 @@ ErrCode FileAccessExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply { UserAccessTracer trace; trace.Start("CmdOpenFile"); - std::string insideInputUri; - if (!data.ReadString(insideInputUri)) { + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { HILOG_ERROR("Parameter OpenFile fail to ReadParcelable uri"); return E_IPCS; } - if (insideInputUri.empty()) { - HILOG_ERROR("Parameter OpenFile insideInputUri is empty"); - return EINVAL; - } - int flags = E_IPCS; if (!data.ReadInt32(flags)) { HILOG_ERROR("Parameter OpenFile fail to ReadInt32 flags"); @@ -117,8 +112,7 @@ ErrCode FileAccessExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply } int fd = -1; - Uri uri(insideInputUri); - int ret = OpenFile(uri, flags, fd); + int ret = OpenFile(*uri, flags, fd); UniqueFd uniqueFd(fd); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter OpenFile fail to WriteInt32 ret"); @@ -137,17 +131,12 @@ ErrCode FileAccessExtStub::CmdCreateFile(MessageParcel &data, MessageParcel &rep { UserAccessTracer trace; trace.Start("CmdCreateFile"); - std::string insideInputUri; - if (!data.ReadString(insideInputUri)) { - HILOG_ERROR("Parameter OpenFile fail to ReadParcelable uri"); + std::shared_ptr parent(data.ReadParcelable()); + if (parent == nullptr) { + HILOG_ERROR("Parameter CreateFile fail to ReadParcelable parent"); return E_IPCS; } - if (insideInputUri.empty()) { - HILOG_ERROR("Parameter CreateFile insideInputUri is empty"); - return EINVAL; - } - std::string displayName = ""; if (!data.ReadString(displayName)) { HILOG_ERROR("Parameter CreateFile fail to ReadString displayName"); @@ -161,15 +150,13 @@ ErrCode FileAccessExtStub::CmdCreateFile(MessageParcel &data, MessageParcel &rep std::string newFile = ""; OHOS::Uri newFileUri(newFile); - Uri uri(insideInputUri); - int ret = CreateFile(uri, displayName, newFileUri); + int ret = CreateFile(*parent, displayName, newFileUri); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter CreateFile fail to WriteInt32 ret"); return E_IPCS; } - std::string insideOutputUri = newFileUri.ToString(); - if (!reply.WriteString(insideOutputUri)) { + if (!reply.WriteParcelable(&newFileUri)) { HILOG_ERROR("Parameter CreateFile fail to WriteParcelable newFileUri"); return E_IPCS; } @@ -181,17 +168,12 @@ ErrCode FileAccessExtStub::CmdMkdir(MessageParcel &data, MessageParcel &reply) { UserAccessTracer trace; trace.Start("CmdMkdir"); - std::string insideInputUri; - if (!data.ReadString(insideInputUri)) { - HILOG_ERROR("Parameter Mkdir fail to ReadParcelable uri"); + std::shared_ptr parent(data.ReadParcelable()); + if (parent == nullptr) { + HILOG_ERROR("Parameter Mkdir fail to ReadParcelable parent"); return E_IPCS; } - if (insideInputUri.empty()) { - HILOG_ERROR("Parameter Mkdir insideInputUri is empty"); - return EINVAL; - } - std::string displayName = ""; if (!data.ReadString(displayName)) { HILOG_ERROR("Parameter Mkdir fail to ReadString displayName"); @@ -205,15 +187,13 @@ ErrCode FileAccessExtStub::CmdMkdir(MessageParcel &data, MessageParcel &reply) std::string newFile = ""; OHOS::Uri newFileUri(newFile); - Uri uri(insideInputUri); - int ret = Mkdir(uri, displayName, newFileUri); + int ret = Mkdir(*parent, displayName, newFileUri); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter Mkdir fail to WriteInt32 ret"); return E_IPCS; } - std::string insideOutputUri = newFileUri.ToString(); - if (!reply.WriteString(insideOutputUri)) { + if (!reply.WriteParcelable(&newFileUri)) { HILOG_ERROR("Parameter Mkdir fail to WriteParcelable newFileUri"); return E_IPCS; } @@ -225,19 +205,13 @@ ErrCode FileAccessExtStub::CmdDelete(MessageParcel &data, MessageParcel &reply) { UserAccessTracer trace; trace.Start("CmdDelete"); - std::string insideInputUri; - if (!data.ReadString(insideInputUri)) { + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { HILOG_ERROR("Parameter Delete fail to ReadParcelable uri"); return E_IPCS; } - if (insideInputUri.empty()) { - HILOG_ERROR("Parameter Delete insideInputUri is empty"); - return EINVAL; - } - - Uri uri(insideInputUri); - int ret = Delete(uri); + int ret = Delete(*uri); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter Delete fail to WriteInt32 ret"); return E_IPCS; @@ -250,30 +224,27 @@ ErrCode FileAccessExtStub::CmdMove(MessageParcel &data, MessageParcel &reply) { UserAccessTracer trace; trace.Start("CmdMove"); - std::string sourceFile; - if (!data.ReadString(sourceFile)) { - HILOG_ERROR("Parameter Move fail to ReadParcelable uri"); + std::shared_ptr sourceFile(data.ReadParcelable()); + if (sourceFile == nullptr) { + HILOG_ERROR("Parameter Move fail to ReadParcelable sourceFile"); return E_IPCS; } - std::string targetParent; - if (!data.ReadString(targetParent)) { - HILOG_ERROR("Parameter Move fail to ReadParcelable uri"); + std::shared_ptr targetParent(data.ReadParcelable()); + if (targetParent == nullptr) { + HILOG_ERROR("Parameter Move fail to ReadParcelable targetParent"); return E_IPCS; } std::string newFile = ""; OHOS::Uri newFileUri(newFile); - Uri source(sourceFile); - Uri target(targetParent); - int ret = Move(source, target, newFileUri); + int ret = Move(*sourceFile, *targetParent, newFileUri); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter Move fail to WriteInt32 ret"); return E_IPCS; } - std::string insideOutputUri = newFileUri.ToString(); - if (!reply.WriteString(insideOutputUri)) { + if (!reply.WriteParcelable(&newFileUri)) { HILOG_ERROR("Parameter Move fail to WriteParcelable newFileUri"); return E_IPCS; } @@ -285,15 +256,15 @@ ErrCode FileAccessExtStub::CmdCopy(MessageParcel &data, MessageParcel &reply) { UserAccessTracer trace; trace.Start("CmdCopy"); - std::string sourceUri; - if (!data.ReadString(sourceUri)) { - HILOG_ERROR("Parameter Copy fail to ReadParcelable uri"); + std::shared_ptr sourceUri(data.ReadParcelable()); + if (sourceUri == nullptr) { + HILOG_ERROR("Parameter Copy fail to ReadParcelable sourceUri"); return E_IPCS; } - std::string destUri; - if (!data.ReadString(destUri)) { - HILOG_ERROR("Parameter Copy fail to ReadParcelable uri"); + std::shared_ptr destUri(data.ReadParcelable()); + if (destUri == nullptr) { + HILOG_ERROR("Parameter Copy fail to ReadParcelable destUri"); return E_IPCS; } @@ -304,9 +275,7 @@ ErrCode FileAccessExtStub::CmdCopy(MessageParcel &data, MessageParcel &reply) } std::vector copyResult; - Uri source(sourceUri); - Uri dest(destUri); - int ret = Copy(source, dest, copyResult, force); + int ret = Copy(*sourceUri, *destUri, copyResult, force); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter Copy fail to WriteInt32 ret"); return E_IPCS; @@ -331,9 +300,9 @@ ErrCode FileAccessExtStub::CmdRename(MessageParcel &data, MessageParcel &reply) { UserAccessTracer trace; trace.Start("CmdRename"); - std::string sourceFile; - if (!data.ReadString(sourceFile)) { - HILOG_ERROR("Parameter Rename fail to ReadParcelable uri"); + std::shared_ptr sourceFile(data.ReadParcelable()); + if (sourceFile == nullptr) { + HILOG_ERROR("Parameter Rename fail to ReadParcelable sourceFile"); return E_IPCS; } @@ -350,15 +319,13 @@ ErrCode FileAccessExtStub::CmdRename(MessageParcel &data, MessageParcel &reply) std::string newFile = ""; OHOS::Uri newFileUri(newFile); - Uri source(sourceFile); - int ret = Rename(source, displayName, newFileUri); + int ret = Rename(*sourceFile, displayName, newFileUri); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter Rename fail to WriteInt32 ret"); return E_IPCS; } - std::string insideOutputUri = newFileUri.ToString(); - if (!reply.WriteString(insideOutputUri)) { + if (!reply.WriteParcelable(&newFileUri)) { HILOG_ERROR("Parameter Rename fail to WriteParcelable newFileUri"); return E_IPCS; } @@ -500,8 +467,8 @@ ErrCode FileAccessExtStub::CmdQuery(MessageParcel &data, MessageParcel &reply) { UserAccessTracer trace; trace.Start("CmdQuery"); - std::string uri; - if (!data.ReadString(uri)) { + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { HILOG_ERROR("Parameter Query fail to ReadParcelable uri"); return E_IPCS; } @@ -520,8 +487,7 @@ ErrCode FileAccessExtStub::CmdQuery(MessageParcel &data, MessageParcel &reply) columns.push_back(data.ReadString()); } std::vector results; - Uri sourceUri(uri); - int ret = Query(sourceUri, columns, results); + int ret = Query(*uri, columns, results); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter Query fail to WriteInt32 ret"); return E_IPCS; @@ -547,8 +513,8 @@ ErrCode FileAccessExtStub::CmdGetThumbnail(MessageParcel &data, MessageParcel &r { UserAccessTracer trace; trace.Start("CmdGetThumbnail"); - std::string uri; - if (!data.ReadString(uri)) { + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { HILOG_ERROR("Parameter GetThumbnail fail to ReadParcelable uri"); return E_IPCS; } @@ -560,8 +526,7 @@ ErrCode FileAccessExtStub::CmdGetThumbnail(MessageParcel &data, MessageParcel &r } std::shared_ptr pixelMap; - Uri sourceUri(uri); - int ret = GetThumbnail(sourceUri, *thumbnailSize, pixelMap); + int ret = GetThumbnail(*uri, *thumbnailSize, pixelMap); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter CmdGetThumbnail fail to WriteInt32 ret"); return E_IPCS; @@ -579,15 +544,14 @@ ErrCode FileAccessExtStub::CmdGetFileInfoFromUri(MessageParcel &data, MessagePar { UserAccessTracer trace; trace.Start("CmdGetFileInfoFromUri"); - std::string uri; - if (!data.ReadString(uri)) { - HILOG_ERROR("Parameter GetFileInfoFromUri fail to ReadParcelable uri"); - return E_IPCS; + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { + HILOG_ERROR("SelectFile uri is nullptr"); + return E_URIS; } FileInfo fileInfoTemp; - Uri sourceUri(uri); - int ret = GetFileInfoFromUri(sourceUri, fileInfoTemp); + int ret = GetFileInfoFromUri(*uri, fileInfoTemp); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter GetFileInfoFromUri fail to WriteInt32 ret"); return E_IPCS; @@ -626,15 +590,14 @@ ErrCode FileAccessExtStub::CmdAccess(MessageParcel &data, MessageParcel &reply) { UserAccessTracer trace; trace.Start("CmdAccess"); - std::string uri; - if (!data.ReadString(uri)) { - HILOG_ERROR("Parameter Query fail to ReadParcelable uri"); - return E_IPCS; + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { + HILOG_ERROR("Access uri is nullptr"); + return E_URIS; } bool isExist = false; - Uri sourceUri(uri); - int ret = Access(sourceUri, isExist); + int ret = Access(*uri, isExist); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter Access fail to WriteInt32 ret"); return E_IPCS;