1 /*
2  * Copyright (c) 2024 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 "bms_key_event_mgr.h"
17 
18 #include "app_log_tag_wrapper.h"
19 #include "inner_bundle_info.h"
20 #include "parameters.h"
21 
22 #include <set>
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 const std::string BOOTEVENT_BMS_MAIN_BUNDLES_READY = "bootevent.bms.main.bundles.ready";
28 const std::string MAIN_BUNDLE_NAME_SCENE_BOARD = "com.ohos.sceneboard";
29 const std::string MAIN_BUNDLE_NAME_SCENE_BOARD_PATH = "/system/app/SceneBoard";
30 const std::set<std::string> MAIN_BUNDLES_SET = {
31     MAIN_BUNDLE_NAME_SCENE_BOARD,
32     MAIN_BUNDLE_NAME_SCENE_BOARD_PATH
33 };
34 constexpr const char *BMS_PARAM_TRUE = "true";
35 constexpr const char *BMS_PARAM_FALSE = "false";
36 }
37 
38 std::atomic_uint BmsKeyEventMgr::isMainBundleReady_ = true;
39 
ProcessMainBundleStatusFinally()40 void BmsKeyEventMgr::ProcessMainBundleStatusFinally()
41 {
42     LOG_I(BMS_TAG_DEFAULT, "ProcessMainBundleStatus start");
43     if (isMainBundleReady_) {
44         if (!system::SetParameter(BOOTEVENT_BMS_MAIN_BUNDLES_READY, BMS_PARAM_TRUE)) {
45             LOG_E(BMS_TAG_DEFAULT, "bms set parameter failed");
46         }
47     } else {
48         LOG_E(BMS_TAG_DEFAULT, "ProcessMainBundleStatus main bundle not ready");
49     }
50     LOG_I(BMS_TAG_DEFAULT, "ProcessMainBundleStatus end");
51 }
52 
ProcessMainBundleInstallFailed(const std::string & bundleName,int32_t errCode)53 void BmsKeyEventMgr::ProcessMainBundleInstallFailed(const std::string &bundleName, int32_t errCode)
54 {
55     if (MAIN_BUNDLES_SET.find(bundleName) == MAIN_BUNDLES_SET.end()) {
56         return;
57     }
58     LOG_I(BMS_TAG_DEFAULT, "bundleName:%{public}s install failed, errCode:%{public}d", bundleName.c_str(), errCode);
59     isMainBundleReady_ = false;
60     if (!system::SetParameter(BOOTEVENT_BMS_MAIN_BUNDLES_READY, BMS_PARAM_FALSE)) {
61         LOG_E(BMS_TAG_DEFAULT, "bms set parameter failed");
62     }
63 }
64 } // namespace AppExecFwk
65 } // namespace OHOS
66