!10726 开机动画增加超时机制

Merge pull request !10726 from ZhuGangQiang/master
This commit is contained in:
openharmony_ci 2024-05-06 08:28:51 +00:00 committed by Gitee
commit 5d4fb7e380
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 44 additions and 29 deletions

View File

@ -31,6 +31,7 @@ private:
void CreateDefaultBootConfig();
BootStrategyType GetBootType() const;
int32_t duration_ = 15;
bool isMultiDisplay_ = false;
bool isCompatible_ = false;
std::vector<BootAnimationConfig> animationConfigs_;

View File

@ -40,7 +40,8 @@ public:
virtual ~BootAnimationOperation();
void Init(const BootAnimationConfig& config, const int32_t width, const int32_t height);
void Init(const BootAnimationConfig& config,
const int32_t width, const int32_t height, const int32_t duration);
void SetSoundEnable(bool isEnabled);
@ -55,12 +56,13 @@ private:
void PlayVideo(const std::string& path);
void PlayPicture(const std::string& path);
void PlaySound(const std::string& path);
void CloseVideoPlayer();
void StopBootAnimation();
private:
bool isSoundEnabled_ = true;
int32_t windowWidth_;
int32_t windowHeight_;
int32_t duration_;
Rosen::ScreenId currentScreenId_;
OHOS::BootAnimationCallback callback_;

View File

@ -26,7 +26,7 @@ public:
virtual ~BootAnimationStrategy() = default;
virtual void Display(std::vector<BootAnimationConfig>& configs) {};
virtual void Display(const int32_t duration, std::vector<BootAnimationConfig>& configs) {};
bool CheckExitAnimation();

View File

@ -26,7 +26,7 @@ public:
virtual ~BootAssociativeDisplayStrategy() = default;
void Display(std::vector<BootAnimationConfig>& configs) override;
void Display(const int32_t duration, std::vector<BootAnimationConfig>& configs) override;
private:
bool IsExtraVideoExist(const std::vector<BootAnimationConfig>& configs);

View File

@ -26,7 +26,7 @@ public:
virtual ~BootCompatibleDisplayStrategy() = default;
void Display(std::vector<BootAnimationConfig>& configs) override;
void Display(const int32_t duration, std::vector<BootAnimationConfig>& configs) override;
private:
std::shared_ptr<BootAnimationOperation> operator_;

View File

@ -27,7 +27,7 @@ public:
virtual ~BootIndependentDisplayStrategy() = default;
void Display(std::vector<BootAnimationConfig>& configs) override;
void Display(const int32_t duration, std::vector<BootAnimationConfig>& configs) override;
private:
std::vector<std::shared_ptr<BootAnimationOperation>> operators_;

View File

@ -132,7 +132,7 @@ void PostTask(std::function<void()> func, uint32_t delayTime = 0);
bool IsFileExisted(const std::string& filePath);
bool ParseBootConfig(const std::string& path,
bool ParseBootConfig(const std::string& path, int32_t& duration,
bool& isCompatible, bool& isMultiDisplay, std::vector<BootAnimationConfig>& configs);
void ParseNewConfigFile(cJSON* data, bool& isMultiDisplay, std::vector<BootAnimationConfig>& configs);
@ -141,6 +141,8 @@ void ParseOldConfigFile(cJSON* data, std::vector<BootAnimationConfig>& configs);
void ParseVideoExtraPath(cJSON* data, BootAnimationConfig& config);
void ParseBootDuration(cJSON* data, int32_t& duration);
bool ReadZipFile(const std::string& srcFilePath, ImageStructVec& imgVec, FrameRateConfig& frameConfig);
void SortZipFile(ImageStructVec& imgVec);

View File

@ -31,7 +31,7 @@ void BootAnimationController::Start()
LOGI("BootAnimationController START");
WaitRenderServiceInit();
std::string path = GetConfigFilePath();
if (!ParseBootConfig(path, isCompatible_, isMultiDisplay_, animationConfigs_)) {
if (!ParseBootConfig(path, duration_, isCompatible_, isMultiDisplay_, animationConfigs_)) {
LOGI("parse config json error, create default config");
isCompatible_ = true;
CreateDefaultBootConfig();
@ -40,7 +40,7 @@ void BootAnimationController::Start()
BootStrategyType bootType = GetBootType();
strategy_ = BootAnimationFactory::GetBootStrategy(bootType);
if (strategy_) {
strategy_->Display(animationConfigs_);
strategy_->Display(duration_, animationConfigs_);
}
}

View File

@ -25,6 +25,7 @@
#include "transaction/rs_interfaces.h"
using namespace OHOS;
static const int DELAY_TIME_MS = 1000;
BootAnimationOperation::~BootAnimationOperation()
{
@ -37,12 +38,14 @@ BootAnimationOperation::~BootAnimationOperation()
OHOS::Rosen::RSTransaction::FlushImplicitTransaction();
}
void BootAnimationOperation::Init(const BootAnimationConfig& config, const int32_t width, const int32_t height)
void BootAnimationOperation::Init(const BootAnimationConfig& config, const int32_t width,
const int32_t height, const int32_t duration)
{
LOGI("Init enter, width: %{public}d, height: %{public}d, screenId : " BPUBU64 "", width, height, config.screenId);
currentScreenId_ = config.screenId;
windowWidth_ = width;
windowHeight_ = height;
duration_ = duration * DELAY_TIME_MS;
eventThread_ = std::thread(&BootAnimationOperation::StartEventHandler, this, config);
std::unique_lock<std::mutex> lock(eventMutex_);
@ -58,6 +61,7 @@ void BootAnimationOperation::StartEventHandler(const BootAnimationConfig& config
mainHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner_);
mainHandler_->PostTask(std::bind(&BootAnimationOperation::InitRsDisplayNode, this));
mainHandler_->PostTask(std::bind(&BootAnimationOperation::InitRsSurfaceNode, this, config.rotateDegree));
mainHandler_->PostTask(std::bind(&BootAnimationOperation::StopBootAnimation, this), duration_);
eventCon_.notify_all();
#ifdef PLAYER_FRAMEWORK_ENABLE
if (IsBootVideoEnabled(config)) {
@ -94,7 +98,6 @@ bool BootAnimationOperation::InitRsDisplayNode()
rsDisplayNode_ = OHOS::Rosen::RSDisplayNode::Create(config);
if (rsDisplayNode_ == nullptr) {
LOGE("init display node failed");
mainHandler_->PostTask(std::bind(&AppExecFwk::EventRunner::Stop, runner_));
return false;
}
rsDisplayNode_->SetDisplayOffset(0, 0);
@ -105,7 +108,6 @@ bool BootAnimationOperation::InitRsDisplayNode()
auto transactionProxy = OHOS::Rosen::RSTransactionProxy::GetInstance();
if (transactionProxy == nullptr) {
LOGE("transactionProxy is nullptr");
mainHandler_->PostTask(std::bind(&AppExecFwk::EventRunner::Stop, runner_));
return false;
}
transactionProxy->FlushImplicitTransaction();
@ -123,7 +125,6 @@ bool BootAnimationOperation::InitRsSurfaceNode(const int32_t degree)
rsSurfaceNode_ = Rosen::RSSurfaceNode::Create(rsSurfaceNodeConfig, rsSurfaceNodeType);
if (!rsSurfaceNode_) {
LOGE("create rsSurfaceNode failed");
mainHandler_->PostTask(std::bind(&AppExecFwk::EventRunner::Stop, runner_));
return false;
}
LOGI("rotation degree: %{public}d", degree);
@ -153,7 +154,7 @@ void BootAnimationOperation::PlayVideo(const std::string& path)
params.resPath = path;
callback_ = {
.userData = this,
.callback = std::bind(&BootAnimationOperation::CloseVideoPlayer, this),
.callback = std::bind(&BootAnimationOperation::StopBootAnimation, this),
};
params.callback = &callback_;
params.screenId = currentScreenId_;
@ -198,7 +199,6 @@ bool BootAnimationOperation::InitRsSurface()
Rosen::RenderContextBaseFactory::CreateRenderContext();
if (renderContext == nullptr) {
LOGE("create render context failed");
mainHandler_->PostTask(std::bind(&AppExecFwk::EventRunner::Stop, runner_));
return false;
}
renderContext->Init();
@ -212,7 +212,6 @@ bool BootAnimationOperation::InitRsSurface()
rsSurface_ = OHOS::Rosen::RSSurfaceExtractor::ExtractRSSurface(rsSurfaceNode_);
if (rsSurface_ == nullptr) {
LOGE("rsSurface is nullptr");
mainHandler_->PostTask(std::bind(&AppExecFwk::EventRunner::Stop, runner_));
return false;
}
#ifdef ACE_ENABLE_GL
@ -221,7 +220,6 @@ bool BootAnimationOperation::InitRsSurface()
OHOS::Rosen::RenderContext* rc = OHOS::Rosen::RenderContextFactory::GetInstance().CreateEngine();
if (rc == nullptr) {
LOGE("init egl context failed");
mainHandler_->PostTask(std::bind(&AppExecFwk::EventRunner::Stop, runner_));
return false;
} else {
LOGI("init egl context success");
@ -247,10 +245,12 @@ bool BootAnimationOperation::IsBootVideoEnabled(const BootAnimationConfig& confi
return true;
}
#ifdef PLAYER_FRAMEWORK_ENABLE
void BootAnimationOperation::CloseVideoPlayer()
void BootAnimationOperation::StopBootAnimation()
{
LOGI("close video player");
LOGI("StopBootAnimation");
if (!system::GetBoolParameter(BOOT_ANIMATION_STARTED, false)) {
system::SetParameter(BOOT_ANIMATION_STARTED, "true");
LOGI("set boot animation started true");
}
mainHandler_->PostTask(std::bind(&AppExecFwk::EventRunner::Stop, runner_));
}
#endif

View File

@ -20,7 +20,7 @@
using namespace OHOS;
void BootAssociativeDisplayStrategy::Display(std::vector<BootAnimationConfig>& configs)
void BootAssociativeDisplayStrategy::Display(const int32_t duration, std::vector<BootAnimationConfig>& configs)
{
LOGI("BootAssociativeDisplayStrategy START");
if (configs.size() <= 1) {
@ -53,7 +53,7 @@ void BootAssociativeDisplayStrategy::Display(std::vector<BootAnimationConfig>& c
int screenWidth = modeInfo.GetScreenWidth();
int screenHeight = modeInfo.GetScreenHeight();
operator_ = std::make_shared<BootAnimationOperation>();
operator_->Init(config, screenWidth, screenHeight);
operator_->Init(config, screenWidth, screenHeight, duration);
operator_->GetThread().join();
if (CheckNeedOtaCompile()) {

View File

@ -20,7 +20,7 @@
using namespace OHOS;
void BootCompatibleDisplayStrategy::Display(std::vector<BootAnimationConfig>& configs)
void BootCompatibleDisplayStrategy::Display(const int32_t duration, std::vector<BootAnimationConfig>& configs)
{
LOGI("BootCompatibleDisplayStrategy START");
if (configs.size() != 1) {
@ -47,7 +47,7 @@ void BootCompatibleDisplayStrategy::Display(std::vector<BootAnimationConfig>& co
int32_t screenWidth = modeInfo.GetScreenWidth();
int32_t screenHeight = modeInfo.GetScreenHeight();
operator_ = std::make_shared<BootAnimationOperation>();
operator_->Init(config, screenWidth, screenHeight);
operator_->Init(config, screenWidth, screenHeight, duration);
operator_->GetThread().join();
if (CheckNeedOtaCompile()) {

View File

@ -19,7 +19,7 @@
#include "transaction/rs_interfaces.h"
using namespace OHOS;
void BootIndependentDisplayStrategy::Display(std::vector<BootAnimationConfig>& configs)
void BootIndependentDisplayStrategy::Display(const int32_t duration, std::vector<BootAnimationConfig>& configs)
{
LOGI("BootIndependentDisplayStrategy START");
Rosen::RSInterfaces& interface = Rosen::RSInterfaces::GetInstance();
@ -36,7 +36,7 @@ void BootIndependentDisplayStrategy::Display(std::vector<BootAnimationConfig>& c
} else {
screenConfig = config;
}
op->Init(config, screenWidth, screenHeight);
op->Init(config, screenWidth, screenHeight, duration);
operators_.emplace_back(op);
}

View File

@ -48,8 +48,8 @@ bool IsFileExisted(const std::string& filePath)
return true;
}
bool ParseBootConfig(
const std::string& path, bool& isCompatible, bool& isMultiDisplay, std::vector<BootAnimationConfig>& configs)
bool ParseBootConfig(const std::string& path, int32_t& duration,
bool& isCompatible, bool& isMultiDisplay, std::vector<BootAnimationConfig>& configs)
{
char newpath[PATH_MAX + 1] = { 0x00 };
if (strlen(path.c_str()) > PATH_MAX || realpath(path.c_str(), newpath) == nullptr) {
@ -76,6 +76,7 @@ bool ParseBootConfig(
} else {
ParseNewConfigFile(overallData, isMultiDisplay, configs);
}
ParseBootDuration(overallData, duration);
cJSON_Delete(overallData);
return true;
}
@ -179,6 +180,15 @@ void ParseVideoExtraPath(cJSON* data, BootAnimationConfig& config)
}
}
void ParseBootDuration(cJSON* data, int32_t& duration)
{
cJSON* durationJson = cJSON_GetObjectItem(data, "cust.bootanimation.duration");
if (durationJson != nullptr && cJSON_IsString(durationJson)) {
duration = std::stoi(durationJson->valuestring);
LOGI("cust duration: %{public}d", duration);
}
}
bool ReadZipFile(const std::string& srcFilePath, ImageStructVec& imgVec, FrameRateConfig& frameConfig)
{
unzFile zipFile = unzOpen2(srcFilePath.c_str(), nullptr);