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 #include "boot_animation_controller.h"
16
17 #include "boot_animation_factory.h"
18 #include "config_policy_utils.h"
19 #include <if_system_ability_manager.h>
20 #include <ipc_skeleton.h>
21 #include <iremote_object.h>
22 #include <iservice_registry.h>
23 #include <parameters.h>
24 #include <system_ability_definition.h>
25 #include "util.h"
26
27 namespace OHOS {
28 namespace {
29 const std::string BOOT_CUSTOM_CONFIG_PATH_SUFFIX = "etc/bootanimation/bootanimation_custom_config.json";
30 }
31
Start()32 void BootAnimationController::Start()
33 {
34 LOGI("BootAnimationController START");
35 WaitRenderServiceInit();
36 std::string path = GetConfigFilePath();
37 if (!ParseBootConfig(path, duration_, isCompatible_, isMultiDisplay_, animationConfigs_)) {
38 LOGI("parse config json error, create default config");
39 isCompatible_ = true;
40 CreateDefaultBootConfig();
41 }
42
43 BootStrategyType bootType = GetBootType();
44 strategy_ = BootAnimationFactory::GetBootStrategy(bootType);
45 if (strategy_) {
46 strategy_->Display(duration_, animationConfigs_);
47 }
48 }
49
WaitRenderServiceInit() const50 void BootAnimationController::WaitRenderServiceInit() const
51 {
52 bool isRsInited = false;
53 while (!isRsInited) {
54 sptr<ISystemAbilityManager> saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
55 if (saMgr == nullptr) {
56 LOGI("saMgr is null, please wait...");
57 usleep(SLEEP_TIME_US);
58 continue;
59 }
60 sptr<IRemoteObject> renderObj = saMgr->GetSystemAbility(RENDER_SERVICE);
61 if (renderObj == nullptr || !system::GetBoolParameter("bootevent.renderservice.ready", false)) {
62 LOGI("renderService is not initialized, please wait...");
63 usleep(SLEEP_TIME_US);
64 } else {
65 LOGI("renderService is initialized");
66 isRsInited = true;
67 }
68 }
69 }
70
GetConfigFilePath()71 std::string BootAnimationController::GetConfigFilePath()
72 {
73 char buf[MAX_PATH_LEN] = {0};
74 char *path = GetOneCfgFile(BOOT_CUSTOM_CONFIG_PATH_SUFFIX.c_str(), buf, MAX_PATH_LEN);
75 if (path != nullptr) {
76 LOGI("boot config path: %{public}s", path);
77 return path;
78 }
79 LOGW("path not find %{public}s", BOOT_CUSTOM_CONFIG_PATH_SUFFIX.c_str());
80 return "";
81 }
82
CreateDefaultBootConfig()83 void BootAnimationController::CreateDefaultBootConfig()
84 {
85 BootAnimationConfig config;
86 config.screenId = 0;
87 animationConfigs_.emplace_back(config);
88 }
89
GetBootType() const90 BootStrategyType BootAnimationController::GetBootType() const
91 {
92 if (isCompatible_) {
93 return BootStrategyType::COMPATIBLE;
94 }
95
96 if (isMultiDisplay_ || animationConfigs_.size() == 1) {
97 return BootStrategyType::INDEPENDENT;
98 }
99
100 return BootStrategyType::ASSOCIATIVE;
101 }
102 } // namespace OHOS
103