1 /* 2 * Copyright (c) 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 UPDATE_SERVICE_KITS_IMPL_H 17 #define UPDATE_SERVICE_KITS_IMPL_H 18 19 #include "singleton.h" 20 21 #include "base_service_kits_impl.h" 22 #include "iupdate_callback.h" 23 #include "update_define.h" 24 #include "update_service_kits.h" 25 #include "update_callback.h" 26 #include "update_service_proxy.h" 27 28 namespace OHOS::UpdateService { 29 class UpdateServiceKitsImpl final : public UpdateServiceKits, 30 public DelayedRefSingleton<UpdateServiceKitsImpl>, 31 public BaseServiceKitsImpl<IUpdateService> { 32 DECLARE_DELAYED_REF_SINGLETON(UpdateServiceKitsImpl); 33 34 public: 35 DISALLOW_COPY_AND_MOVE(UpdateServiceKitsImpl); 36 37 int32_t RegisterUpdateCallback(const UpgradeInfo &info, const UpdateCallbackInfo &cb, int32_t &funcResult) final; 38 39 int32_t UnregisterUpdateCallback(const UpgradeInfo &info, int32_t &funcResult) final; 40 41 int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult, 42 int32_t &funcResult) final; 43 44 int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, 45 const DownloadOptions &downloadOptions, BusinessError &businessError, int32_t &funcResult) final; 46 47 int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, 48 const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError, int32_t &funcResult) final; 49 50 int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, 51 const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError, int32_t &funcResult) final; 52 53 int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, 54 const UpgradeOptions &upgradeOptions, BusinessError &businessError, int32_t &funcResult) final; 55 56 int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, 57 const ClearOptions &clearOptions, BusinessError &businessError, int32_t &funcResult) final; 58 59 int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError, int32_t &funcResult) final; 60 61 int32_t GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo, 62 BusinessError &businessError, int32_t &funcResult) final; 63 64 int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, 65 const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo, 66 BusinessError &businessError, int32_t &funcResult) final; 67 68 int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, 69 BusinessError &businessError, int32_t &funcResult) final; 70 71 int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions, 72 VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError, int32_t &funcResult) final; 73 74 int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError, 75 int32_t &funcResult) final; 76 77 int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, BusinessError &businessError, 78 int32_t &funcResult) final; 79 80 int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError, 81 int32_t &funcResult) final; 82 83 int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError, int32_t &funcResult) final; 84 85 int32_t FactoryReset(BusinessError &businessError) final; 86 87 int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, 88 const std::vector<std::string> &packageNames, BusinessError &businessError, int32_t &funcResult) final; 89 90 int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, 91 BusinessError &businessError, int32_t &funcResult) final; 92 93 protected: 94 void RegisterCallback() override; 95 void ResetService(const wptr<IRemoteObject> &remote) override; 96 97 #ifndef UPDATER_UT 98 private: 99 #endif 100 std::map<UpgradeInfo, sptr<IUpdateCallback>> remoteUpdateCallbackMap_; 101 UpgradeInfo upgradeInfo_{}; 102 int32_t retryTimes_ = 0; 103 }; 104 } // namespace OHOS::UpdateService 105 #endif // UPDATE_SERVICE_KITS_IMPL_H 106