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