1 /* 2 * Copyright (c) 2022 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_FILEMGMT_CLOUD_SYNC_SERVICE_PROXY_H 17 #define OHOS_FILEMGMT_CLOUD_SYNC_SERVICE_PROXY_H 18 19 #include "iremote_proxy.h" 20 #include "system_ability_load_callback_stub.h" 21 22 #include "i_cloud_sync_service.h" 23 24 namespace OHOS::FileManagement::CloudSync { 25 class CloudSyncServiceProxy : public IRemoteProxy<ICloudSyncService> { 26 public: CloudSyncServiceProxy(const sptr<IRemoteObject> & impl)27 explicit CloudSyncServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<ICloudSyncService>(impl) {} ~CloudSyncServiceProxy()28 ~CloudSyncServiceProxy() override {} 29 30 static sptr<ICloudSyncService> GetInstance(); 31 static void InvaildInstance(); 32 int32_t UnRegisterCallbackInner(const std::string &bundleName = "") override; 33 int32_t RegisterCallbackInner(const sptr<IRemoteObject> &remoteObject, const std::string &bundleName = "") override; 34 int32_t StartSyncInner(bool forceFlag, const std::string &bundleName = "") override; 35 int32_t TriggerSyncInner(const std::string &bundleName, const int32_t &userId) override; 36 int32_t StopSyncInner(const std::string &bundleName = "", bool forceFlag = false) override; 37 int32_t ResetCursor(const std::string &bundleName = "") override; 38 int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) override; 39 int32_t OptimizeStorage(const int32_t agingDays) override; 40 int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) override; 41 int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) override; 42 int32_t NotifyEventChange(int32_t userId, const std::string &eventId, const std::string &extraData) override; 43 int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) override; 44 int32_t DisableCloud(const std::string &accoutId) override; 45 int32_t StartDownloadFile(const std::string &uri) override; 46 int32_t StartFileCacheWriteParcel(MessageParcel &data, 47 const std::vector<std::string> &pathVec, 48 bool &isCallbackValid, 49 const sptr<IRemoteObject> &downloadCallback); 50 int32_t StartFileCache(const std::vector<std::string> &uriVec, 51 int64_t &downloadId, 52 bool isCallbackValid = false, 53 const sptr<IRemoteObject> &downloadCallback = nullptr) override; 54 int32_t StopDownloadFile(const std::string &uri, bool needClean = false) override; 55 int32_t StopFileCache(const int64_t &downloadId, bool needClean = false) override; 56 int32_t RegisterDownloadFileCallback(const sptr<IRemoteObject> &downloadCallback) override; 57 int32_t UnregisterDownloadFileCallback() override; 58 int32_t UploadAsset(const int32_t userId, const std::string &request, std::string &result) override; 59 int32_t DownloadFile(const int32_t userId, const std::string &bundleName, AssetInfoObj &assetInfoObj) override; 60 int32_t DownloadFiles(const int32_t userId, 61 const std::string &bundleName, 62 const std::vector<AssetInfoObj> &assetInfoObj, 63 std::vector<bool> &assetResultMap) override; 64 int32_t DownloadAsset(const uint64_t taskId, const int32_t userId, 65 const std::string &bundleName, 66 const std::string &networkId, 67 AssetInfoObj &assetInfoObj) override; 68 int32_t DownloadThumb() override; 69 int32_t RegisterDownloadAssetCallback(const sptr<IRemoteObject> &remoteObject) override; 70 int32_t DeleteAsset(const int32_t userId, const std::string &uri) override; 71 int32_t GetSyncTimeInner(int64_t &syncTime, const std::string &bundleName = "") override; 72 int32_t CleanCacheInner(const std::string &uri) override; 73 int32_t BatchDentryFileInsert(const std::vector<DentryFileInfoObj> &fileInfo, 74 std::vector<std::string> &failCloudId) override; 75 76 class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { 77 public: 78 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override; 79 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 80 81 std::condition_variable proxyConVar_; 82 std::atomic<bool> isLoadSuccess_{false}; 83 }; 84 85 private: 86 static inline std::mutex proxyMutex_; 87 static inline std::mutex instanceMutex_; 88 static inline std::mutex downloadMutex_; 89 static inline sptr<ICloudSyncService> serviceProxy_; 90 static inline BrokerDelegator<CloudSyncServiceProxy> delegator_; 91 }; 92 } // namespace OHOS::FileManagement::CloudSync 93 94 #endif // OHOS_FILEMGMT_CLOUD_SYNC_SERVICE_PROXY_H 95