/* * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "quick_fixer.h" #include #include "app_log_wrapper.h" #include "quick_fix_deleter.h" #include "quick_fix_deployer.h" #include "quick_fix_switcher.h" namespace OHOS { namespace AppExecFwk { QuickFixer::QuickFixer(const sptr &statusCallback) : statusCallback_(statusCallback) { APP_LOGI("enter QuickFixer"); } void QuickFixer::DeployQuickFix(const std::vector &bundleFilePaths, bool isDebug) { APP_LOGI("DeployQuickFix start"); if (statusCallback_ == nullptr) { APP_LOGE("DeployQuickFix failed due to nullptr statusCallback"); } std::unique_ptr deployer = std::make_unique(bundleFilePaths, isDebug); auto ret = deployer->Execute(); // callback operation DeployQuickFixResult result = deployer->GetDeployQuickFixResult(); result.resultCode = ret; std::shared_ptr deployRes = std::make_shared(result); if (statusCallback_ != nullptr) { statusCallback_->OnPatchDeployed(deployRes); } } void QuickFixer::SwitchQuickFix(const std::string &bundleName, bool enable) { APP_LOGI("SwitchQuickFix start"); if (statusCallback_ == nullptr) { APP_LOGE("SwitchQuickFix failed due to nullptr statusCallback"); } std::unique_ptr switcher = std::make_unique(bundleName, enable); auto ret = switcher->Execute(); // callback operation SwitchQuickFixResult result; result.resultCode = ret; result.bundleName = bundleName; std::shared_ptr switchRes = std::make_shared(result); if (statusCallback_ != nullptr) { statusCallback_->OnPatchSwitched(switchRes); } } void QuickFixer::DeleteQuickFix(const std::string &bundleName) { APP_LOGI("DeleteQuickFix start"); if (statusCallback_ == nullptr) { APP_LOGE("DeleteQuickFix failed due to nullptr statusCallback"); } std::unique_ptr deleter = std::make_unique(bundleName); auto ret = deleter->Execute(); // callback operation DeleteQuickFixResult result; result.resultCode = ret; result.bundleName = bundleName; std::shared_ptr deleteRes = std::make_shared(result); if (statusCallback_ != nullptr) { statusCallback_->OnPatchDeleted(deleteRes); } } } // AppExecFwk } // OHOS