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 "quick_fix_switch_state.h"
17
18 #include "quick_fix_boot_scanner.h"
19 #include "quick_fix_delete_state.h"
20 #include "quick_fix_switcher.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
QuickFixSwitchState(const std::string & bundleName,bool enable)24 QuickFixSwitchState::QuickFixSwitchState(const std::string &bundleName, bool enable)
25 : bundleName_(bundleName), enable_(enable)
26 {
27 APP_LOGI("create QuickFixSwitchState");
28 }
29
Process()30 ErrCode QuickFixSwitchState::Process()
31 {
32 APP_LOGD("start to process switch-status bundle %{public}s", bundleName_.c_str());
33 std::unique_ptr<QuickFixSwitcher> switcher = std::make_unique<QuickFixSwitcher>(bundleName_, enable_);
34 auto res = switcher->Execute();
35 if (res != ERR_OK) {
36 APP_LOGE("switch quick fix info failed due to %{public}d", res);
37 return res;
38 }
39
40 std::shared_ptr<QuickFixDeleteState> deleteState = std::make_shared<QuickFixDeleteState>(bundleName_);
41 auto scanner = DelayedSingleton<QuickFixBootScanner>::GetInstance();
42 if (scanner == nullptr) {
43 APP_LOGE("scanner is nullptr");
44 return ERR_BUNDLEMANAGER_QUICK_FIX_INTERNAL_ERROR;
45 }
46 scanner->SetQuickFixState(deleteState);
47 return scanner->ProcessState();
48 }
49 } // AppExecFwk
50 } // OHOS