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 
16 #include "boot_animation_strategy.h"
17 
18 #include "log.h"
19 #include <parameters.h>
20 #include "util.h"
21 
22 namespace OHOS {
23 namespace {
24     constexpr const char* DUE_UPDATE_TYPE_PARAM = "persist.dupdate_engine.update_type";
25     const std::string DUE_UPDATE_TYPE_MANUAL = "manual";
26     const std::string DUE_UPDATE_TYPE_NIGHT = "night";
27     constexpr const char* OTA_BMS_COMPILE_SWITCH = "const.bms.optimizing_apps.switch";
28     const std::string OTA_BMS_COMPILE_SWITCH_OFF = "off";
29     const std::string OTA_BMS_COMPILE_SWITCH_ON = "on";
30 }
31 
CheckExitAnimation()32 bool BootAnimationStrategy::CheckExitAnimation()
33 {
34     if (!isAnimationEnd_) {
35         LOGI("boot animation is end");
36         system::SetParameter(BOOT_ANIMATION_FINISHED, "true");
37         isAnimationEnd_ = true;
38     }
39     bool bootEventCompleted = system::GetBoolParameter(BOOT_COMPLETED, false);
40     if (bootEventCompleted) {
41         LOGI("read boot completed is true");
42         return true;
43     }
44     return false;
45 }
46 
CheckNeedOtaCompile() const47 bool BootAnimationStrategy::CheckNeedOtaCompile() const
48 {
49     LOGI("CheckNeedOtaCompile");
50     std::string otaCompileSwitch = system::GetParameter(OTA_BMS_COMPILE_SWITCH, OTA_BMS_COMPILE_SWITCH_OFF);
51     if (otaCompileSwitch != OTA_BMS_COMPILE_SWITCH_ON) {
52         LOGI("ota compile switch is: %{public}s", otaCompileSwitch.c_str());
53         return false;
54     }
55 
56     std::string dueUpdateType = system::GetParameter(DUE_UPDATE_TYPE_PARAM, "");
57     LOGI("dueUpdateType is: %{public}s", dueUpdateType.c_str());
58     bool isOtaUpdate = dueUpdateType == DUE_UPDATE_TYPE_MANUAL || dueUpdateType == DUE_UPDATE_TYPE_NIGHT;
59 
60     std::string bmsCompileStatus  = system::GetParameter(BMS_COMPILE_STATUS, "-1");
61     LOGI("bmsCompileStatus is: %{public}s", bmsCompileStatus.c_str());
62     bool isCompileDone = bmsCompileStatus == BMS_COMPILE_STATUS_END;
63 
64     if (isOtaUpdate && !isCompileDone) {
65         return true;
66     }
67     return false;
68 }
69 } // namespace OHOS
70