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 UPDATE_SERVICE_ONDEMAND_H 17 #define UPDATE_SERVICE_ONDEMAND_H 18 19 #include "update_helper.h" 20 21 #include <mutex> 22 #include <unistd.h> 23 24 #include "iservice_registry.h" 25 #include "system_ability_definition.h" 26 #include "system_ability_load_callback_stub.h" 27 28 namespace OHOS { 29 namespace UpdateEngine { 30 static constexpr int64_t UPDATER_SA_INIT_TIME = 1000 * 1000; 31 static constexpr int64_t SLEEP_TIME = 500 * 1000; 32 static constexpr int32_t RETRY_TIMES = 10; 33 34 enum class LoadUpdaterSaStatus { 35 WAIT_RESULT = 0, 36 SUCCESS, 37 FAIL, 38 }; 39 40 class UpdateServiceOnDemand : public SystemAbilityLoadCallbackStub { 41 public: 42 static sptr<UpdateServiceOnDemand> GetInstance(); 43 bool TryLoadUpdaterSa(); 44 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject>& remoteObject) override; 45 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 46 47 private: 48 void InitStatus(); 49 void WaitUpdaterSaInit(); 50 bool CheckUpdaterSaLoaded(); 51 bool LoadUpdaterSa(); 52 53 LoadUpdaterSaStatus loadUpdaterSaStatus_ = LoadUpdaterSaStatus::WAIT_RESULT; 54 static sptr<UpdateServiceOnDemand> instance_; 55 static std::mutex instanceLock_; 56 }; 57 } // namespace UpdateEngine 58 } // namespace OHOS 59 #endif // UPDATE_SERVICE_ONDEMAND_H 60