1 /* 2 * Copyright (c) 2022-2023 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_BACKUP_SERVICE_PROXY_H 17 #define OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H 18 19 #include <condition_variable> 20 #include <cstddef> 21 #include <cstdint> 22 #include <mutex> 23 24 #include "i_service.h" 25 #include "iremote_proxy.h" 26 #include "system_ability_load_callback_stub.h" 27 28 namespace OHOS::FileManagement::Backup { 29 class ServiceProxy : public IRemoteProxy<IService> { 30 public: 31 ErrCode InitRestoreSession(sptr<IServiceReverse> remote) override; 32 ErrCode InitBackupSession(sptr<IServiceReverse> remote) override; 33 ErrCode Start() override; 34 UniqueFd GetLocalCapabilities() override; 35 ErrCode PublishFile(const BFileInfo &fileInfo) override; 36 ErrCode AppFileReady(const std::string &fileName, UniqueFd fd) override; 37 ErrCode AppDone(ErrCode errCode) override; 38 ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; 39 ErrCode AppendBundlesRestoreSession(UniqueFd fd, 40 const std::vector<BundleName> &bundleNames, 41 RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, 42 int32_t userId = DEFAULT_INVAL_VALUE) override; 43 ErrCode AppendBundlesBackupSession(const std::vector<BundleName> &bundleNames) override; 44 ErrCode Finish() override; 45 46 public: ServiceProxy(const sptr<IRemoteObject> & impl)47 explicit ServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IService>(impl) {} ~ServiceProxy()48 ~ServiceProxy() override {} 49 50 public: 51 static sptr<IService> GetInstance(); 52 static void InvaildInstance(); 53 54 public: 55 class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { 56 public: 57 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override; 58 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 59 60 public: 61 std::condition_variable proxyConVar_; 62 std::atomic<bool> isLoadSuccess_ = {false}; 63 }; 64 65 private: 66 static inline std::mutex proxyMutex_; 67 static inline sptr<IService> serviceProxy_ = nullptr; 68 static inline BrokerDelegator<ServiceProxy> delegator_; 69 }; 70 } // namespace OHOS::FileManagement::Backup 71 72 #endif // OHOS_FILEMGMT_BACKUP_SERVICE_PROXY_H