• 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_fix_mgr.h"
17 
18 #include "app_log_tag_wrapper.h"
19 #include "bundle_memory_guard.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
QuickFixMgr()23 QuickFixMgr::QuickFixMgr()
24 {
25     LOG_I(BMS_TAG_DEFAULT, "create quick fixer async manager instance");
26 }
27 
~QuickFixMgr()28 QuickFixMgr::~QuickFixMgr()
29 {
30     LOG_I(BMS_TAG_DEFAULT, "destory quick fixer async manager instance");
31 }
32 
DeployQuickFix(const std::vector<std::string> & bundleFilePaths,const sptr<IQuickFixStatusCallback> & statusCallback,bool isDebug,const std::string & targetPath,bool isReplace)33 ErrCode QuickFixMgr::DeployQuickFix(const std::vector<std::string> &bundleFilePaths,
34     const sptr<IQuickFixStatusCallback> &statusCallback, bool isDebug, const std::string &targetPath,
35     bool isReplace)
36 {
37     LOG_I(BMS_TAG_DEFAULT, "DeployQuickFix begin");
38     auto quickFixer = CreateQuickFixer(statusCallback);
39     if (quickFixer == nullptr) {
40         LOG_E(BMS_TAG_DEFAULT, "DeployQuickFix failed due to nullptr quick fixer");
41         return ERR_BUNDLEMANAGER_QUICK_FIX_INTERNAL_ERROR;
42     }
43 
44     auto task = [quickFixer, bundleFilePaths, isDebug, targetPath, isReplace] {
45         BundleMemoryGuard memoryGuard;
46         quickFixer->DeployQuickFix(bundleFilePaths, isDebug, targetPath, isReplace);
47     };
48 
49     ffrt::submit(task);
50     return ERR_OK;
51 }
52 
SwitchQuickFix(const std::string & bundleName,bool enable,const sptr<IQuickFixStatusCallback> & statusCallback)53 ErrCode QuickFixMgr::SwitchQuickFix(const std::string &bundleName, bool enable,
54     const sptr<IQuickFixStatusCallback> &statusCallback)
55 {
56     LOG_I(BMS_TAG_DEFAULT, "SwitchQuickFix begin");
57     auto quickFixer = CreateQuickFixer(statusCallback);
58     if (quickFixer == nullptr) {
59         LOG_E(BMS_TAG_DEFAULT, "SwitchQuickFix failed due to nullptr quick fixer");
60         return ERR_BUNDLEMANAGER_QUICK_FIX_INTERNAL_ERROR;
61     }
62 
63     auto task = [quickFixer, bundleName, enable] {
64         BundleMemoryGuard memoryGuard;
65         quickFixer->SwitchQuickFix(bundleName, enable);
66     };
67 
68     ffrt::submit(task);
69     return ERR_OK;
70 }
71 
DeleteQuickFix(const std::string & bundleName,const sptr<IQuickFixStatusCallback> & statusCallback)72 ErrCode QuickFixMgr::DeleteQuickFix(const std::string &bundleName,
73     const sptr<IQuickFixStatusCallback> &statusCallback)
74 {
75     LOG_I(BMS_TAG_DEFAULT, "DeleteQuickFix begin");
76     auto quickFixer = CreateQuickFixer(statusCallback);
77     if (quickFixer == nullptr) {
78         LOG_E(BMS_TAG_DEFAULT, "DeleteQuickFix failed due to nullptr quick fixer");
79         return ERR_BUNDLEMANAGER_QUICK_FIX_INTERNAL_ERROR;
80     }
81 
82     auto task = [quickFixer, bundleName] {
83         BundleMemoryGuard memoryGuard;
84         quickFixer->DeleteQuickFix(bundleName);
85     };
86 
87     ffrt::submit(task);
88     return ERR_OK;
89 }
90 
CreateQuickFixer(const sptr<IQuickFixStatusCallback> & statusCallback)91 std::shared_ptr<QuickFixer> QuickFixMgr::CreateQuickFixer(const sptr<IQuickFixStatusCallback> &statusCallback)
92 {
93     return std::make_shared<QuickFixer>(statusCallback);
94 }
95 } // AppExecFwk
96 } // OHOS