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 #include "update_service_impl_manager.h"
17 
18 #include "update_log.h"
19 #include "update_service_impl_firmware.h"
20 
21 using namespace std;
22 
23 namespace OHOS {
24 namespace UpdateEngine {
UpdateServiceImplManager()25 UpdateServiceImplManager::UpdateServiceImplManager()
26 {
27     ENGINE_LOGI("UpdateServiceImplManager");
28 }
29 
~UpdateServiceImplManager()30 UpdateServiceImplManager::~UpdateServiceImplManager()
31 {
32     ENGINE_LOGI("~UpdateServiceImplManager");
33 }
34 
GetOnlineUpdater(const UpgradeInfo & info)35 sptr<IServiceOnlineUpdater> UpdateServiceImplManager::GetOnlineUpdater(const UpgradeInfo &info)
36 {
37     std::lock_guard<std::mutex> lock(updateImplMapLock_);
38     auto iter = updateImpMap_.find(info);
39     if ((iter != updateImpMap_.end()) && (iter->second != nullptr)) {
40         return iter->second;
41     } else {
42         sptr<IServiceOnlineUpdater> updateServiceImpl = nullptr;
43         if (info.businessType.subType == BusinessSubType::FIRMWARE) {
44             updateServiceImpl = new UpdateServiceImplFirmware();
45         } else {
46             ENGINE_LOGI("GetOnlineUpdater unknow business type");
47         }
48         if (updateServiceImpl != nullptr) {
49             updateImpMap_.insert({info, updateServiceImpl});
50         }
51         return updateServiceImpl;
52     }
53 }
54 } // namespace UpdateEngine
55 } // namespace OHOS