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 d55372a3323eeab2a9a5510cbb58ff8005844583..cb4a140a5f48ccbfee213ef10c5bbfd681403caa 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; } @@ -451,8 +443,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; } @@ -481,17 +472,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; } @@ -705,8 +696,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; } @@ -795,8 +785,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; } @@ -859,8 +848,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; } @@ -948,8 +936,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 9c5aa5551b7110c2167dd4881a1401592ad8a156..0a5a78939265aa27466a7d65baafec74ca942502 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 @@ -97,17 +97,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"); @@ -120,8 +115,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"); @@ -140,17 +134,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"); @@ -164,15 +153,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; } @@ -184,17 +171,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"); @@ -208,15 +190,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; } @@ -228,19 +208,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; @@ -253,30 +227,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; } @@ -288,15 +259,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; } @@ -306,10 +277,8 @@ ErrCode FileAccessExtStub::CmdCopy(MessageParcel &data, MessageParcel &reply) return E_IPCS; } - std::vector copyResult; - Uri source(sourceUri); - Uri dest(destUri); - int ret = Copy(source, dest, copyResult, force); + std::vector copyResult; + int ret = Copy(*sourceUri, *destUri, copyResult, force); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter Copy fail to WriteInt32 ret"); return E_IPCS; @@ -372,9 +341,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; } @@ -391,15 +360,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; } @@ -576,8 +543,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; } @@ -596,8 +563,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; @@ -623,10 +589,10 @@ 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; + return E_URIS; } std::shared_ptr thumbnailSize(data.ReadParcelable()); @@ -636,8 +602,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; @@ -655,15 +620,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; @@ -702,15 +666,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;