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