1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_MEDIA_CLOUD_SYNC_CLOUD_MEDIA_DOWNLOAD_CONTROLLER_SERVICE_H 17 #define OHOS_MEDIA_CLOUD_SYNC_CLOUD_MEDIA_DOWNLOAD_CONTROLLER_SERVICE_H 18 19 #include <string> 20 #include <vector> 21 #include <map> 22 23 #include "message_parcel.h" 24 #include "datashare_stub.h" 25 #include "rdb_store.h" 26 #include "sys_utils.h" 27 #include "user_define_ipc.h" 28 #include "i_media_controller_service.h" 29 #include "cloud_media_operation_code.h" 30 #include "medialibrary_errno.h" 31 #include "cloud_media_download_controller_processor.h" 32 #include "cloud_media_download_service.h" 33 #include "cloud_media_define.h" 34 35 namespace OHOS::Media::CloudSync { 36 class EXPORT CloudMediaDownloadControllerService : public IPC::IMediaControllerService { 37 private: 38 int32_t GetDownloadThms(MessageParcel &data, MessageParcel &reply); 39 int32_t GetDownloadThmNum(MessageParcel &data, MessageParcel &reply); 40 int32_t GetDownloadThmsByUri(MessageParcel &data, MessageParcel &reply); 41 int32_t OnDownloadThms(MessageParcel &data, MessageParcel &reply); 42 int32_t GetDownloadAsset(MessageParcel &data, MessageParcel &reply); 43 int32_t OnDownloadAsset(MessageParcel &data, MessageParcel &reply); 44 45 private: 46 using RequestHandle = int32_t (CloudMediaDownloadControllerService::*)(MessageParcel &, MessageParcel &); 47 const std::map<uint32_t, RequestHandle> HANDLERS = { 48 {static_cast<uint32_t>(CloudMediaOperationCode::CMD_GET_DOWNLOAD_THM), 49 &CloudMediaDownloadControllerService::GetDownloadThms}, 50 {static_cast<uint32_t>(CloudMediaOperationCode::CMD_GET_DOWNLOAD_THM_NUM), 51 &CloudMediaDownloadControllerService::GetDownloadThmNum}, 52 {static_cast<uint32_t>(CloudMediaOperationCode::CMD_GET_DOWNLOAD_THM_BY_URI), 53 &CloudMediaDownloadControllerService::GetDownloadThmsByUri}, 54 {static_cast<uint32_t>(CloudMediaOperationCode::CMD_ON_DOWNLOAD_THMS), 55 &CloudMediaDownloadControllerService::OnDownloadThms}, 56 {static_cast<uint32_t>(CloudMediaOperationCode::CMD_GET_DOWNLOAD_ASSET), 57 &CloudMediaDownloadControllerService::GetDownloadAsset}, 58 {static_cast<uint32_t>(CloudMediaOperationCode::CMD_ON_DOWNLOAD_ASSET), 59 &CloudMediaDownloadControllerService::OnDownloadAsset}, 60 }; 61 62 public: 63 virtual ~CloudMediaDownloadControllerService() = default; Accept(uint32_t code)64 bool Accept(uint32_t code) override 65 { 66 return this->HANDLERS.find(code) != this->HANDLERS.end(); 67 } OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,OHOS::Media::IPC::IPCContext & context)68 int32_t OnRemoteRequest( 69 uint32_t code, MessageParcel &data, MessageParcel &reply, OHOS::Media::IPC::IPCContext &context) override 70 { 71 auto it = this->HANDLERS.find(code); 72 if (!this->Accept(code) || it == this->HANDLERS.end()) { 73 return IPC::UserDefineIPC().WriteResponseBody(reply, E_IPC_SEVICE_NOT_FOUND); 74 } 75 SysUtils::SlowDown(); 76 return (this->*(it->second))(data, reply); 77 } GetPermissionPolicy(uint32_t code,std::vector<std::vector<PermissionType>> & permissionPolicy,bool & isBypass)78 int32_t GetPermissionPolicy( 79 uint32_t code, std::vector<std::vector<PermissionType>> &permissionPolicy, bool &isBypass) override 80 { 81 permissionPolicy = {{CLOUD_READ, CLOUD_WRITE}}; 82 return E_SUCCESS; 83 } 84 85 private: 86 CloudMediaDownloadControllerProcessor processor_; 87 CloudMediaDownloadService service_; 88 }; 89 } // namespace OHOS::Media::CloudSync 90 #endif // OHOS_MEDIA_CLOUD_SYNC_CLOUD_MEDIA_DOWNLOAD_CONTROLLER_SERVICE_H