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 #include "quick_fixer.h"
17
18 #include "app_log_tag_wrapper.h"
19 #include "quick_fix_deleter.h"
20 #include "quick_fix_deployer.h"
21 #include "quick_fix_switcher.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
QuickFixer(const sptr<IQuickFixStatusCallback> & statusCallback)25 QuickFixer::QuickFixer(const sptr<IQuickFixStatusCallback> &statusCallback) : statusCallback_(statusCallback)
26 {
27 LOG_I(BMS_TAG_DEFAULT, "enter QuickFixer");
28 }
29
DeployQuickFix(const std::vector<std::string> & bundleFilePaths,bool isDebug,const std::string & targetPath)30 void QuickFixer::DeployQuickFix(const std::vector<std::string> &bundleFilePaths, bool isDebug,
31 const std::string &targetPath)
32 {
33 LOG_I(BMS_TAG_DEFAULT, "DeployQuickFix start");
34
35 std::unique_ptr<QuickFixDeployer> deployer = std::make_unique<QuickFixDeployer>(
36 bundleFilePaths, isDebug, targetPath);
37 auto ret = deployer->Execute();
38
39 // callback operation
40 DeployQuickFixResult result = deployer->GetDeployQuickFixResult();
41 result.resultCode = ret;
42 std::shared_ptr<QuickFixResult> deployRes = std::make_shared<DeployQuickFixResult>(result);
43 if (statusCallback_ != nullptr) {
44 statusCallback_->OnPatchDeployed(deployRes);
45 } else {
46 LOG_E(BMS_TAG_DEFAULT, "DeployQuickFix failed due to nullptr statusCallback");
47 }
48 }
49
SwitchQuickFix(const std::string & bundleName,bool enable)50 void QuickFixer::SwitchQuickFix(const std::string &bundleName, bool enable)
51 {
52 LOG_I(BMS_TAG_DEFAULT, "SwitchQuickFix start");
53 if (statusCallback_ == nullptr) {
54 LOG_E(BMS_TAG_DEFAULT, "SwitchQuickFix failed due to nullptr statusCallback");
55 }
56
57 std::unique_ptr<IQuickFix> switcher = std::make_unique<QuickFixSwitcher>(bundleName, enable);
58 auto ret = switcher->Execute();
59
60 // callback operation
61 SwitchQuickFixResult result;
62 result.resultCode = ret;
63 result.bundleName = bundleName;
64 std::shared_ptr<QuickFixResult> switchRes = std::make_shared<SwitchQuickFixResult>(result);
65 if (statusCallback_ != nullptr) {
66 statusCallback_->OnPatchSwitched(switchRes);
67 }
68 }
69
DeleteQuickFix(const std::string & bundleName)70 void QuickFixer::DeleteQuickFix(const std::string &bundleName)
71 {
72 LOG_I(BMS_TAG_DEFAULT, "DeleteQuickFix start");
73 if (statusCallback_ == nullptr) {
74 LOG_E(BMS_TAG_DEFAULT, "DeleteQuickFix failed due to nullptr statusCallback");
75 }
76
77 std::unique_ptr<IQuickFix> deleter = std::make_unique<QuickFixDeleter>(bundleName);
78 auto ret = deleter->Execute();
79
80 // callback operation
81 DeleteQuickFixResult result;
82 result.resultCode = ret;
83 result.bundleName = bundleName;
84 std::shared_ptr<QuickFixResult> deleteRes = std::make_shared<DeleteQuickFixResult>(result);
85 if (statusCallback_ != nullptr) {
86 statusCallback_->OnPatchDeleted(deleteRes);
87 }
88 }
89 } // AppExecFwk
90 } // OHOS