1 /* 2 * Copyright (c) 2021 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 "update_define.h" 22 #include "update_helper.h" 23 #include "update_service_kits.h" 24 #include "iupdate_callback.h" 25 #include "update_callback.h" 26 #include "update_service_proxy.h" 27 28 namespace OHOS { 29 namespace UpdateEngine { 30 class UpdateServiceKitsImpl final : public UpdateServiceKits, 31 public DelayedRefSingleton<UpdateServiceKitsImpl> { 32 DECLARE_DELAYED_REF_SINGLETON(UpdateServiceKitsImpl); 33 public: 34 DISALLOW_COPY_AND_MOVE(UpdateServiceKitsImpl); 35 36 int32_t RegisterUpdateCallback(const UpgradeInfo &info, const UpdateCallbackInfo &cb) final; 37 38 int32_t UnregisterUpdateCallback(const UpgradeInfo &info) final; 39 40 int32_t CheckNewVersion(const UpgradeInfo &info) final; 41 42 int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, 43 const DownloadOptions &downloadOptions, BusinessError &businessError) final; 44 45 int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, 46 const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) final; 47 48 int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, 49 const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) final; 50 51 int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, 52 const UpgradeOptions &upgradeOptions, BusinessError &businessError) final; 53 54 int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, 55 const ClearOptions &clearOptions, BusinessError &businessError) final; 56 57 int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) final; 58 59 int32_t GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo, 60 BusinessError &businessError) final; 61 62 int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, 63 const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo, 64 BusinessError &businessError) final; 65 66 int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, 67 BusinessError &businessError) final; 68 69 int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions, 70 VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError) final; 71 72 int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) final; 73 74 int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, BusinessError &businessError) final; 75 76 int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) final; 77 78 int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) final; 79 80 int32_t FactoryReset(BusinessError &businessError) final; 81 82 int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, const std::string &packageName, 83 BusinessError &businessError) final; 84 85 int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, 86 BusinessError &businessError) final; 87 88 #ifndef UPDATER_UT 89 private: 90 #endif 91 // For call event procession 92 class RemoteUpdateCallback final : public UpdateCallback { 93 public: 94 RemoteUpdateCallback(const UpdateCallbackInfo &cb); 95 ~RemoteUpdateCallback(); 96 97 DISALLOW_COPY_AND_MOVE(RemoteUpdateCallback); 98 99 void OnCheckVersionDone(const BusinessError &businessError, const CheckResult &checkResult) final; 100 101 void OnEvent(const EventInfo &eventInfo) final; 102 private: 103 UpdateCallbackInfo updateCallback_ {}; 104 }; 105 106 // For death event procession 107 class DeathRecipient final : public IRemoteObject::DeathRecipient { 108 public: 109 DeathRecipient() = default; 110 ~DeathRecipient() final = default; 111 DISALLOW_COPY_AND_MOVE(DeathRecipient); 112 void OnRemoteDied(const wptr<IRemoteObject>& remote) final; 113 }; 114 115 void ResetService(const wptr<IRemoteObject>& remote); 116 sptr<IUpdateService> GetService(); 117 118 std::mutex updateServiceLock_; 119 sptr<IUpdateService> updateService_ {}; 120 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {}; 121 std::map<UpgradeInfo, sptr<IUpdateCallback>> remoteUpdateCallbackMap_; 122 UpgradeInfo upgradeInfo_ {}; 123 }; 124 } // namespace UpdateEngine 125 } // namespace OHOS 126 #endif // UPDATE_SERVICE_KITS_IMPL_H 127