• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_animationconfig.h"
16 #include "log.h"
17 #include "config_policy_utils.h"
18 
19 using namespace OHOS;
20 static const std::string BOOT_CUSTOM_PATHSUFFIX = "etc/bootanimation/bootanimation_custom_config.json";
21 static const std::string BOOT_PIC_ZIP = "/system/etc/graphic/bootpic.zip";
22 static const std::string BOOT_VIDEO_PATH = "/system/etc/graphic/bootvideo.mp4";
23 static const std::string BOOT_SOUND_URI = "file://system/etc/graphic/bootsound.wav";
24 
ReadPicZipFile(ImageStructVec & vec,int32_t & freq)25 bool BootAnimationConfig::ReadPicZipFile(ImageStructVec& vec, int32_t& freq)
26 {
27     BootAniConfig jsonConfig;
28     std::string picZipPath = GetPicZipPath();
29     ReadZipFile(picZipPath, vec, jsonConfig);
30     int32_t imageNum = static_cast<int32_t>(vec.size());
31     if (imageNum <= 0) {
32         LOGE("zip pic num is 0.");
33         return false;
34     }
35     SortZipFile(vec);
36     if (CheckFrameRateValid(jsonConfig.frameRate)) {
37         freq = jsonConfig.frameRate;
38     } else {
39         LOGI("Only Support 30, 60 frame rate: %{public}d", jsonConfig.frameRate);
40     }
41     LOGI("end to Readzip pics freq: %{public}d totalPicNum: %{public}d", freq, imageNum);
42     return true;
43 }
44 
CheckFrameRateValid(int32_t ratevalue)45 bool BootAnimationConfig::CheckFrameRateValid(int32_t ratevalue)
46 {
47     std::vector<int> freqs = {60, 30};
48     int nCount = std::count(freqs.begin(), freqs.end(), ratevalue);
49     if (nCount <= 0) {
50         return false;
51     }
52     return true;
53 }
54 
CheckBootVideoEnabled()55 void BootAnimationConfig::CheckBootVideoEnabled()
56 {
57     if (custConfig_.custVideoPath.empty() && !custConfig_.custPicZipPath.empty()) {
58         LOGI("Custom picture path is config and custom video path is not config");
59         bootVideoEnabled_ = false;
60         return;
61     }
62 
63     if (!custConfig_.custVideoPath.empty() && !IsFileExisted(custConfig_.custVideoPath)) {
64         LOGE("Custom video file is not found");
65     }
66 }
67 
GetPicZipPath()68 std::string BootAnimationConfig::GetPicZipPath()
69 {
70     std::string retstr = BOOT_PIC_ZIP;
71     if (custConfig_.custPicZipPath.empty()) {
72         LOGI("custpic path not config");
73         return retstr;
74     }
75 
76     if (IsFileExisted(custConfig_.custPicZipPath)) {
77         LOGI("custpic path %{public}s", custConfig_.custPicZipPath.c_str());
78         retstr = custConfig_.custPicZipPath;
79     }
80     return retstr;
81 }
82 
GetSoundUrl()83 std::string BootAnimationConfig::GetSoundUrl()
84 {
85     std::string retstr = BOOT_SOUND_URI;
86     if (custConfig_.custSoundsPath.empty()) {
87         LOGI("custsound path not config");
88         return retstr;
89     }
90 
91     if (IsFileExisted(custConfig_.custSoundsPath)) {
92         LOGI("custsound path %{public}s", custConfig_.custSoundsPath.c_str());
93         retstr = "file:/" + custConfig_.custSoundsPath;
94     }
95     return retstr;
96 }
97 
GetCustomCfgFile()98 std::string BootAnimationConfig::GetCustomCfgFile()
99 {
100     std::string ret = "";
101     char buf[MAX_PATH_LEN] = {0};
102     char *pfile = GetOneCfgFile(BOOT_CUSTOM_PATHSUFFIX.c_str(), buf, MAX_PATH_LEN);
103     if (pfile != nullptr) {
104         LOGI("get one filePath:%{public}s", pfile);
105         return pfile;
106     } else {
107         LOGI("not find %{public}s", BOOT_CUSTOM_PATHSUFFIX.c_str());
108     }
109     return ret;
110 }
111 
GetBootVideoPath()112 std::string BootAnimationConfig::GetBootVideoPath()
113 {
114     if (custConfig_.custVideoPath.empty()) {
115         return BOOT_VIDEO_PATH;
116     }
117     return custConfig_.custVideoPath;
118 }
119 
GetBootExtraVideoPath()120 std::string BootAnimationConfig::GetBootExtraVideoPath()
121 {
122     if (custConfig_.custExtraVideoPath.empty()) {
123         return GetBootVideoPath();
124     }
125     return custConfig_.custExtraVideoPath;
126 }
127 
GetRotateScreenId()128 int32_t BootAnimationConfig::GetRotateScreenId()
129 {
130     return custConfig_.rotateScreenId;
131 }
132 
GetRotateDegree()133 int32_t BootAnimationConfig::GetRotateDegree()
134 {
135     return custConfig_.rotateDegree;
136 }
137 
ParserCustomCfgFile()138 void BootAnimationConfig::ParserCustomCfgFile()
139 {
140     std::string file = GetCustomCfgFile();
141     if (!file.empty()) {
142         ReadCustomBootConfig(file, custConfig_);
143         CheckBootVideoEnabled();
144     }
145 }
146 
IsBootVideoEnabled()147 bool BootAnimationConfig::IsBootVideoEnabled()
148 {
149     return bootVideoEnabled_;
150 }
151