diff --git a/services/BUILD.gn b/services/BUILD.gn index 78366209e0d768b06d58cd2cead640a6aff7df52..1a330bfb83122f4fba7b48b735a9f389a43f92f5 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -62,7 +62,6 @@ ohos_shared_library("fms_server") { "//base/notification/ans_standard/frameworks/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager:dataobs_manager", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native:storage_manager_sa_proxy", "//foundation/filemanagement/storage_service/services/storage_manager:storage_manager", diff --git a/services/include/file_manager_service_def.h b/services/include/file_manager_service_def.h index 7fb87a7fda3df6fae7d349d422d22a445bd1cc8b..e8ffae9fb6790787c4e20e2513e8a134e335eba7 100644 --- a/services/include/file_manager_service_def.h +++ b/services/include/file_manager_service_def.h @@ -46,7 +46,7 @@ constexpr int32_t CODE_MASK = 0xff; constexpr int32_t EQUIPMENT_SHIFT = 16; const std::string FISRT_LEVEL_ALBUM = "dataability:///album"; -const std::string ROOT_PATH = "/data/media"; +const std::string ROOT_PATH = "/storage/media"; const std::string IMAGE_ROOT_NAME = "image_album"; const std::string VIDEO_ROOT_NAME = "video_album"; const std::string AUDIO_ROOT_NAME = "audio_album"; diff --git a/services/sa_profile/5010.xml b/services/sa_profile/5010.xml index 96b4b077a81c497777fd43b45b984474d5598b0b..4a49745e4f073177bc43ef6b8df733b3cb2432bf 100644 --- a/services/sa_profile/5010.xml +++ b/services/sa_profile/5010.xml @@ -25,4 +25,4 @@ false 1 - + \ No newline at end of file diff --git a/services/src/fileoper/media_file_utils.cpp b/services/src/fileoper/media_file_utils.cpp index bf30808a928c336652603c5941b22db7b037aba7..34d8ccfd7b300d5cc9b84727408b79258b105905 100644 --- a/services/src/fileoper/media_file_utils.cpp +++ b/services/src/fileoper/media_file_utils.cpp @@ -17,13 +17,14 @@ #include +#include "data_ability_predicates.h" #include "file_manager_service_def.h" #include "file_manager_service_errno.h" - +#include "log.h" #include "media_asset.h" #include "media_data_ability_const.h" -#include "medialibrary_data_ability.h" -#include "log.h" +#include "rdb_errno.h" +#include "values_bucket.h" using namespace std; namespace OHOS { @@ -287,17 +288,14 @@ shared_ptr MediaFileUtils::DoQuery(string selecti NativeRdb::DataAbilityPredicates predicates; predicates.SetWhereClause(selection); predicates.SetWhereArgs(selectionArgs); - Media::MediaLibraryDataAbility mediaLibDb; - mediaLibDb.InitMediaLibraryRdbStore(); Uri uri = Uri(Media::MEDIALIBRARY_DATA_URI); vector columns; - return mediaLibDb.Query(uri, columns, predicates); + return abilityHelper->Query(uri, columns, predicates); } int MediaFileUtils::DoInsert(const string &name, const string &path, const string &type, string &uri) { - Media::ValuesBucket values; - + NativeRdb::ValuesBucket values; string albumPath; if (!GetAlbumPath(name, path, albumPath)) { ERR_LOG("path not exsit"); @@ -310,9 +308,7 @@ int MediaFileUtils::DoInsert(const string &name, const string &path, const strin Uri createAsset(Media::MEDIALIBRARY_DATA_URI + "/" + Media::MEDIA_FILEOPRN + "/" + Media::MEDIA_FILEOPRN_CREATEASSET); - Media::MediaLibraryDataAbility mediaLibDb; - mediaLibDb.InitMediaLibraryRdbStore(); - int index = mediaLibDb.Insert(createAsset, values); + int index = abilityHelper->Insert(createAsset, values); if (index < 0) { ERR_LOG("Fail to create fail %{public}s %{public}s", name.c_str(), path.c_str()); return E_CREATE_FAIL; @@ -328,7 +324,6 @@ bool MediaFileUtils::InitMediaTableColIndexMap(shared_ptr> mediaData = { - {Media::MEDIA_DATA_DB_ID, "string"}, {Media::MEDIA_DATA_DB_URI, "string"}, {Media::MEDIA_DATA_DB_MEDIA_TYPE, "string"}, {Media::MEDIA_DATA_DB_NAME, "string"}, @@ -356,13 +351,10 @@ bool MediaFileUtils::PushFileInfo(shared_ptr resu return false; } int index = 0; - string id; - result->GetString(mediaTableMap[index++].first, id); string uri; result->GetString(mediaTableMap[index++].first, uri); unique_ptr file = make_unique(); - string path = uri + "/" + id; - file->SetPath(path); + file->SetPath(uri); string type; result->GetString(mediaTableMap[index++].first, type); file->SetType(type); @@ -380,28 +372,6 @@ bool MediaFileUtils::PushFileInfo(shared_ptr resu return true; } -bool MediaFileUtils::PopFileInfo(FileInfo &file, MessageParcel &reply) -{ - string path; - string name; - string type; - int64_t size = 0; - int64_t at = 0; - int64_t mt = 0; - - reply.ReadString(path); - reply.ReadString(type); - reply.ReadString(name); - reply.ReadInt64(size); - reply.ReadInt64(at); - reply.ReadInt64(mt); - file = FileInfo(name, path, type); - file.SetSize(size); - file.SetAddedTime(at); - file.SetModifiedTime(mt); - return true; -} - int MediaFileUtils::GetFileInfoFromResult(shared_ptr result, MessageParcel &reply, int res) { @@ -425,5 +395,17 @@ int MediaFileUtils::GetFileInfoFromResult(shared_ptr obj) +{ + if (abilityHelper == nullptr) { + abilityHelper = AppExecFwk::DataAbilityHelper::Creator(obj, make_shared(Media::MEDIALIBRARY_DATA_URI)); + if (abilityHelper == nullptr) { + DEBUG_LOG("get %{public}s helper fail", Media::MEDIALIBRARY_DATA_URI.c_str()); + return false; + } + } + return true; +} } // namespace FileManagerService } // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/media_file_utils.h b/services/src/fileoper/media_file_utils.h index 371eb5356c69e5efcf8ec4d5113307367bc19cbb..b0649026a7a39a04c92a15726352c2f1d675de14 100644 --- a/services/src/fileoper/media_file_utils.h +++ b/services/src/fileoper/media_file_utils.h @@ -22,6 +22,13 @@ #include "file_info.h" #include "file_oper.h" +#include "ipc_types.h" +#include "iremote_broker.h" +#include "iremote_proxy.h" +#include "iremote_stub.h" + +#include "data_ability_helper.h" + namespace OHOS { namespace FileManagerService { class MediaFileUtils { @@ -38,8 +45,10 @@ public: static int GetFileInfoFromResult(std::shared_ptr result, MessageParcel &reply, int res); static bool InitMediaTableColIndexMap(std::shared_ptr result); + static bool InitHelper(sptr obj); private: inline static std::vector> mediaTableMap = {}; + inline static std::shared_ptr abilityHelper = nullptr; }; } // namespace FileManagerService } // namespace OHOS diff --git a/services/src/server/file_manager_service_stub.cpp b/services/src/server/file_manager_service_stub.cpp index a11c8371d9f01e1a2abe9e7874258777bb61a4a8..f3c5d21e4b99295d5a1dedeb86e740e60259cb1b 100644 --- a/services/src/server/file_manager_service_stub.cpp +++ b/services/src/server/file_manager_service_stub.cpp @@ -15,22 +15,23 @@ #include "file_manager_service_stub.h" -#include "file_manager_service.h" #include "file_manager_service_def.h" #include "file_manager_service_errno.h" +#include "file_manager_service.h" #include "log.h" +#include "media_file_utils.h" #include "oper_factory.h" using namespace std; namespace OHOS { namespace FileManagerService { -int GetEquipmentCode(uint32_t code) +static int GetEquipmentCode(uint32_t code) { return (code >> EQUIPMENT_SHIFT) & CODE_MASK; } -int GetOperCode(uint32_t code) +static int GetOperCode(uint32_t code) { return code & CODE_MASK; } @@ -54,6 +55,11 @@ int FileManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { // to do checkpermission() + if (!MediaFileUtils::InitHelper(AsObject())) { + ERR_LOG("InitHelper error %{public}d", FAIL); + reply.WriteInt32(FAIL); + return FAIL; + } // do file process int32_t errCode = OperProcess(code, data, reply); reply.WriteInt32(errCode);