IssueNo:#IA8XSF

Description:add system event
Sig:SIG_ApplicaitonFramework
Feature or Bugfix:Bugfix
Binary Source:No
Signed-off-by: wangtiantian <wangtiantian19@huawei.com>
This commit is contained in:
wangtiantian 2024-07-15 20:52:01 +08:00
parent 190662742f
commit dc44b3c30c
10 changed files with 146 additions and 1 deletions

View File

@ -93,7 +93,7 @@
"build": {
"sub_component": [
"//foundation/bundlemanager/bundle_framework:bms_target",
"//foundation/bundlemanager/bundle_framework/etc:bms.para.dac"
"//foundation/bundlemanager/bundle_framework/etc:bms_para"
],
"inner_kits": [
{

View File

@ -13,6 +13,20 @@
import("//build/ohos.gni")
group("bms_para") {
deps = [
":bms.para",
":bms.para.dac",
]
}
ohos_prebuilt_etc("bms.para") {
source = "bms.para"
part_name = "bundle_framework"
subsystem_name = "bundlemanager"
module_install_dir = "etc/param"
}
ohos_prebuilt_etc("bms.para.dac") {
source = "bms.para.dac"
part_name = "bundle_framework"

14
etc/bms.para Normal file
View File

@ -0,0 +1,14 @@
# Copyright (c) 2024 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.
bootevent.bms.main.bundles.ready = false

View File

@ -13,4 +13,5 @@
const.bms.optimizing_apps.switch = foundation:foundation:0755
bms.optimizing_apps.status = foundation:foundation:0755
bootevent.bms.main.bundles.ready = foundation:foundation:0755

View File

@ -173,6 +173,7 @@ bundle_mgr_source = [
"${services_path}/bundlemgr/src/app_provision_info/app_provision_info_manager.cpp",
"${services_path}/bundlemgr/src/app_provision_info/app_provision_info_rdb.cpp",
"${services_path}/bundlemgr/src/bms_extension/bms_extension_client.cpp",
"${services_path}/bundlemgr/src/bms_key_event_mgr.cpp",
"${services_path}/bundlemgr/src/bms_param.cpp",
"${services_path}/bundlemgr/src/bundle_common_event_mgr.cpp",
"${services_path}/bundlemgr/src/bundle_data_mgr.cpp",

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 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.
*/
#ifndef FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BMS_KEY_EVENT_MGR_H
#define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BMS_KEY_EVENT_MGR_H
#include <string>
namespace OHOS {
namespace AppExecFwk {
class BmsKeyEventMgr {
public:
static void ProcessMainBundleStatusFinally();
static void ProcessMainBundleInstallFailed(const std::string &bundleName, int32_t errCode);
private:
static std::atomic_uint isMainBundleReady_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BMS_KEY_EVENT_MGR_H

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2024 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 "bms_key_event_mgr.h"
#include "app_log_tag_wrapper.h"
#include "inner_bundle_info.h"
#include "parameters.h"
#include <set>
namespace OHOS {
namespace AppExecFwk {
namespace {
const std::string BOOTEVENT_BMS_MAIN_BUNDLES_READY = "bootevent.bms.main.bundles.ready";
const std::string MAIN_BUNDLE_NAME_SCENE_BOARD = "com.ohos.sceneboard";
const std::string MAIN_BUNDLE_NAME_SCENE_BOARD_PATH = "/system/app/SceneBoard";
const std::set<std::string> MAIN_BUNDLES_SET = {
MAIN_BUNDLE_NAME_SCENE_BOARD,
MAIN_BUNDLE_NAME_SCENE_BOARD_PATH
};
constexpr const char *BMS_PARAM_TRUE = "true";
constexpr const char *BMS_PARAM_FALSE = "false";
}
std::atomic_uint BmsKeyEventMgr::isMainBundleReady_ = true;
void BmsKeyEventMgr::ProcessMainBundleStatusFinally()
{
LOG_I(BMS_TAG_DEFAULT, "ProcessMainBundleStatus start");
if (isMainBundleReady_) {
if (!system::SetParameter(BOOTEVENT_BMS_MAIN_BUNDLES_READY, BMS_PARAM_TRUE)) {
LOG_E(BMS_TAG_DEFAULT, "bms set parameter failed");
}
} else {
LOG_E(BMS_TAG_DEFAULT, "ProcessMainBundleStatus main bundle not ready");
}
LOG_I(BMS_TAG_DEFAULT, "ProcessMainBundleStatus end");
}
void BmsKeyEventMgr::ProcessMainBundleInstallFailed(const std::string &bundleName, int32_t errCode)
{
if (MAIN_BUNDLES_SET.find(bundleName) == MAIN_BUNDLES_SET.end()) {
return;
}
LOG_I(BMS_TAG_DEFAULT, "bundleName:%{public}s install failed, errCode:%{public}d", bundleName.c_str(), errCode);
isMainBundleReady_ = false;
if (!system::SetParameter(BOOTEVENT_BMS_MAIN_BUNDLES_READY, BMS_PARAM_FALSE)) {
LOG_E(BMS_TAG_DEFAULT, "bms set parameter failed");
}
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -29,6 +29,7 @@
#include "app_provision_info_manager.h"
#include "app_privilege_capability.h"
#include "app_service_fwk_installer.h"
#include "bms_key_event_mgr.h"
#include "bundle_install_checker.h"
#include "bundle_mgr_host_impl.h"
#include "bundle_mgr_service.h"
@ -357,6 +358,8 @@ void BMSEventHandler::BundleRebootStartEvent()
ProcessRebootQuickFixUnInstallAndRecover(QUICK_FIX_APP_RECOVER_FILE);
CheckALLResourceInfo();
}
// need process main bundle status
BmsKeyEventMgr::ProcessMainBundleStatusFinally();
if (IsModuleUpdate()) {
HandleModuleUpdate();
@ -1674,6 +1677,7 @@ void BMSEventHandler::InnerProcessRebootBundleInstall(
std::unordered_map<std::string, InnerBundleInfo> infos;
if (!ParseHapFiles(scanPathIter, infos) || infos.empty()) {
LOG_E(BMS_TAG_DEFAULT, "obtain bundleinfo failed : %{public}s ", scanPathIter.c_str());
BmsKeyEventMgr::ProcessMainBundleInstallFailed(scanPathIter, ERR_APPEXECFWK_PARSE_UNEXPECTED);
SavePreInstallException(scanPathIter);
continue;
}

View File

@ -17,6 +17,7 @@
#include "app_log_wrapper.h"
#include "bms_extension_data_mgr.h"
#include "bms_key_event_mgr.h"
#include "bundle_mgr_service.h"
#include "bundle_mgr_service_event_handler.h"
#include "bundle_permission_mgr.h"
@ -85,6 +86,7 @@ public:
if (resultCode != ERR_OK && resultCode !=
ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON && needReInstall_) {
APP_LOGI("needReInstall bundleName: %{public}s", bundleName_.c_str());
BmsKeyEventMgr::ProcessMainBundleInstallFailed(bundleName_, resultCode);
SavePreInstallException(bundleName_);
}
}
@ -213,6 +215,8 @@ void BundleUserMgrHostImpl::AfterCreateNewUser(int32_t userId)
{
if (userId == Constants::START_USERID) {
DelayedSingleton<BundleMgrService>::GetInstance()->NotifyBundleScanStatus();
// need process main bundle status
BmsKeyEventMgr::ProcessMainBundleStatusFinally();
}
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP

View File

@ -16,6 +16,7 @@
#include "system_bundle_installer.h"
#include "app_log_wrapper.h"
#include "bms_key_event_mgr.h"
#include "bundle_mgr_service.h"
namespace OHOS {
@ -39,6 +40,9 @@ ErrCode SystemBundleInstaller::InstallSystemBundle(
ErrCode result = InstallBundle(filePath, installParam, appType);
if (result != ERR_OK) {
APP_LOGE("install system bundle fail, error: %{public}d", result);
if (result != ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON) {
BmsKeyEventMgr::ProcessMainBundleInstallFailed(filePath, result);
}
}
return result;
}
@ -78,6 +82,9 @@ ErrCode SystemBundleInstaller::OTAInstallSystemBundle(
if ((errCode != ERR_OK) && (errCode != ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON)) {
APP_LOGE("install system bundle fail, error: %{public}d", errCode);
result = errCode;
if (!filePaths.empty()) {
BmsKeyEventMgr::ProcessMainBundleInstallFailed(filePaths[0], result);
}
}
ResetInstallProperties();
}
@ -119,6 +126,7 @@ ErrCode SystemBundleInstaller::OTAInstallSystemBundleNeedCheckUser(
if ((errCode != ERR_OK) && (errCode != ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON)) {
APP_LOGE("install system bundle %{public}s fail err %{public}d", bundleName.c_str(), errCode);
result = errCode;
BmsKeyEventMgr::ProcessMainBundleInstallFailed(bundleName, result);
}
ResetInstallProperties();
}