/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "boot_animation_controller.h" #include "boot_animation_factory.h" #include "config_policy_utils.h" #include #include #include #include #include #include #include "util.h" namespace OHOS { namespace { const std::string BOOT_CUSTOM_CONFIG_PATH_SUFFIX = "etc/bootanimation/bootanimation_custom_config.json"; const std::string BOOT_CUSTOM_CONFIG_PATH_ENTERPRISE_DEVICE = "/data/service/el1/public/edm/config/system/all/graphic/bootanimation/bootanimation_custom_config.json"; const std::string SYS_PARAM_IS_ENTERPRISE_DEVICE = "const.edm.is_enterprise_device"; } void BootAnimationController::Start() { LOGI("BootAnimationController START"); WaitRenderServiceInit(); std::string path = GetConfigFilePath(); if (!ParseBootConfig(path, duration_, isCompatible_, isMultiDisplay_, animationConfigs_)) { LOGI("parse config json error, create default config"); isCompatible_ = true; CreateDefaultBootConfig(); } BootStrategyType bootType = GetBootType(); strategy_ = BootAnimationFactory::GetBootStrategy(bootType); if (strategy_) { strategy_->configPath_ = path; strategy_->Display(duration_, animationConfigs_); } } void BootAnimationController::WaitRenderServiceInit() const { bool isRsInited = false; while (!isRsInited) { sptr saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (saMgr == nullptr) { LOGI("saMgr is null, please wait..."); usleep(SLEEP_TIME_US); continue; } sptr renderObj = saMgr->CheckSystemAbility(RENDER_SERVICE); if (renderObj == nullptr || !system::GetBoolParameter("bootevent.renderservice.ready", false)) { usleep(SLEEP_TIME_US); } else { LOGI("renderService is initialized"); isRsInited = true; } } } std::string BootAnimationController::GetConfigFilePath() { std::string isEnterpriseDevice = system::GetParameter(SYS_PARAM_IS_ENTERPRISE_DEVICE, ""); LOGI("isEnterpriseDevice: %{public}s", isEnterpriseDevice.c_str()); if (isEnterpriseDevice == "true" && IsFileExisted(BOOT_CUSTOM_CONFIG_PATH_ENTERPRISE_DEVICE)) { LOGI("is enterprise device"); return BOOT_CUSTOM_CONFIG_PATH_ENTERPRISE_DEVICE; } char buf[MAX_PATH_LEN] = {0}; char *path = GetOneCfgFile(BOOT_CUSTOM_CONFIG_PATH_SUFFIX.c_str(), buf, MAX_PATH_LEN); if (path != nullptr) { return path; } LOGW("path not find %{public}s", BOOT_CUSTOM_CONFIG_PATH_SUFFIX.c_str()); return ""; } void BootAnimationController::CreateDefaultBootConfig() { BootAnimationConfig config; config.screenId = 0; animationConfigs_.emplace_back(config); } BootStrategyType BootAnimationController::GetBootType() const { if (isCompatible_) { return BootStrategyType::COMPATIBLE; } if (isMultiDisplay_ || animationConfigs_.size() == 1) { return BootStrategyType::INDEPENDENT; } return BootStrategyType::ASSOCIATIVE; } } // namespace OHOS