• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_->configPath_ = path;
50         strategy_->Display(duration_, animationConfigs_);
51     }
52 }
53 
WaitRenderServiceInit() const54 void BootAnimationController::WaitRenderServiceInit() const
55 {
56     bool isRsInited = false;
57     while (!isRsInited) {
58         sptr<ISystemAbilityManager> saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
59         if (saMgr == nullptr) {
60             LOGI("saMgr is null, please wait...");
61             usleep(SLEEP_TIME_US);
62             continue;
63         }
64         sptr<IRemoteObject> renderObj = saMgr->CheckSystemAbility(RENDER_SERVICE);
65         if (renderObj == nullptr || !system::GetBoolParameter("bootevent.renderservice.ready", false)) {
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         return path;
86     }
87     LOGW("path not find %{public}s", BOOT_CUSTOM_CONFIG_PATH_SUFFIX.c_str());
88     return "";
89 }
90 
CreateDefaultBootConfig()91 void BootAnimationController::CreateDefaultBootConfig()
92 {
93     BootAnimationConfig config;
94     config.screenId = 0;
95     animationConfigs_.emplace_back(config);
96 }
97 
GetBootType() const98 BootStrategyType BootAnimationController::GetBootType() const
99 {
100     if (isCompatible_) {
101         return BootStrategyType::COMPATIBLE;
102     }
103 
104     if (isMultiDisplay_ || animationConfigs_.size() == 1) {
105         return BootStrategyType::INDEPENDENT;
106     }
107 
108     return BootStrategyType::ASSOCIATIVE;
109 }
110 } // namespace OHOS
111