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