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 const std::string BOOT_CUSTOM_CONFIG_PATH_ENTERPRISE_DEVICE
31 = "/data/service/el1/public/edm/config/system/all/graphic/bootanimation/bootanimation_custom_config.json";
32 const std::string SYS_PARAM_IS_ENTERPRISE_DEVICE = "const.edm.is_enterprise_device";
33 }
34
Start()35 void BootAnimationController::Start()
36 {
37 LOGI("BootAnimationController START");
38 WaitRenderServiceInit();
39 std::string path = GetConfigFilePath();
40 if (!ParseBootConfig(path, duration_, isCompatible_, isMultiDisplay_, animationConfigs_)) {
41 LOGI("parse config json error, create default config");
42 isCompatible_ = true;
43 CreateDefaultBootConfig();
44 }
45
46 BootStrategyType bootType = GetBootType();
47 strategy_ = BootAnimationFactory::GetBootStrategy(bootType);
48 if (strategy_) {
49 strategy_->Display(duration_, animationConfigs_);
50 }
51 }
52
WaitRenderServiceInit() const53 void BootAnimationController::WaitRenderServiceInit() const
54 {
55 bool isRsInited = false;
56 while (!isRsInited) {
57 sptr<ISystemAbilityManager> saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
58 if (saMgr == nullptr) {
59 LOGI("saMgr is null, please wait...");
60 usleep(SLEEP_TIME_US);
61 continue;
62 }
63 sptr<IRemoteObject> renderObj = saMgr->GetSystemAbility(RENDER_SERVICE);
64 if (renderObj == nullptr || !system::GetBoolParameter("bootevent.renderservice.ready", false)) {
65 LOGI("renderService is not initialized, please wait...");
66 usleep(SLEEP_TIME_US);
67 } else {
68 LOGI("renderService is initialized");
69 isRsInited = true;
70 }
71 }
72 }
73
GetConfigFilePath()74 std::string BootAnimationController::GetConfigFilePath()
75 {
76 std::string isEnterpriseDevice = system::GetParameter(SYS_PARAM_IS_ENTERPRISE_DEVICE, "");
77 LOGI("isEnterpriseDevice: %{public}s", isEnterpriseDevice.c_str());
78 if (isEnterpriseDevice == "true" && IsFileExisted(BOOT_CUSTOM_CONFIG_PATH_ENTERPRISE_DEVICE)) {
79 LOGI("is enterprise device");
80 return BOOT_CUSTOM_CONFIG_PATH_ENTERPRISE_DEVICE;
81 }
82 char buf[MAX_PATH_LEN] = {0};
83 char *path = GetOneCfgFile(BOOT_CUSTOM_CONFIG_PATH_SUFFIX.c_str(), buf, MAX_PATH_LEN);
84 if (path != nullptr) {
85 LOGI("boot config path: %{public}s", path);
86 return path;
87 }
88 LOGW("path not find %{public}s", BOOT_CUSTOM_CONFIG_PATH_SUFFIX.c_str());
89 return "";
90 }
91
CreateDefaultBootConfig()92 void BootAnimationController::CreateDefaultBootConfig()
93 {
94 BootAnimationConfig config;
95 config.screenId = 0;
96 animationConfigs_.emplace_back(config);
97 }
98
GetBootType() const99 BootStrategyType BootAnimationController::GetBootType() const
100 {
101 if (isCompatible_) {
102 return BootStrategyType::COMPATIBLE;
103 }
104
105 if (isMultiDisplay_ || animationConfigs_.size() == 1) {
106 return BootStrategyType::INDEPENDENT;
107 }
108
109 return BootStrategyType::ASSOCIATIVE;
110 }
111 } // namespace OHOS
112