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 <dlfcn.h>
19 #include "log.h"
20 #include <parameters.h>
21 #include "util.h"
22
23 namespace OHOS {
24 namespace {
25 constexpr const char* DUE_UPDATE_TYPE_PARAM = "persist.dupdate_engine.update_type";
26 const std::string DUE_UPDATE_TYPE_MANUAL = "manual";
27 const std::string DUE_UPDATE_TYPE_NIGHT = "night";
28 constexpr const char* OTA_BMS_COMPILE_SWITCH = "const.bms.optimizing_apps.switch";
29 const std::string OTA_BMS_COMPILE_SWITCH_OFF = "off";
30 const std::string OTA_BMS_COMPILE_SWITCH_ON = "on";
31 }
32
CheckExitAnimation()33 bool BootAnimationStrategy::CheckExitAnimation()
34 {
35 if (!isAnimationEnd_) {
36 LOGI("boot animation is end");
37 if (!system::GetBoolParameter(BOOT_ANIMATION_STARTED, false)) {
38 system::SetParameter(BOOT_ANIMATION_STARTED, "true");
39 }
40 system::SetParameter(BOOT_ANIMATION_FINISHED, "true");
41 isAnimationEnd_ = true;
42 }
43 bool bootEventCompleted = system::GetBoolParameter(BOOT_COMPLETED, false);
44 if (bootEventCompleted) {
45 LOGI("read boot completed is true");
46 #ifdef FEATURE_CHECK_EXIT_ANIMATION_EXT
47 return CheckExitAnimationExt();
48 #else
49 return true;
50 #endif
51 }
52 return false;
53 }
54
55 #ifdef FEATURE_CHECK_EXIT_ANIMATION_EXT
56 #define CHECK_EXIT_ANIMATION_EXT_PATH "libwatch_bootanimation_ext.z.so"
57 #define CHECK_EXIT_ANIMATION_EXT_FUNC_NAME "CheckExitAnimationExt"
58 typedef bool(*Func)();
CheckExitAnimationExt()59 bool BootAnimationStrategy::CheckExitAnimationExt()
60 {
61 LOGI("CheckExitAnimationExt");
62 void *handler = dlopen(CHECK_EXIT_ANIMATION_EXT_PATH, RTLD_LAZY | RTLD_NODELETE);
63 if (handler == nullptr) {
64 LOGI("CheckExitAnimationExt Dlopen failed, reason: %{public}s", dlerror());
65 dlclose(handler);
66 return true;
67 }
68
69 Func CheckExitAnimationExtFunc = (Func)dlsym(handler, CHECK_EXIT_ANIMATION_EXT_FUNC_NAME);
70 if (CheckExitAnimationExtFunc == nullptr) {
71 LOGI("CheckExitAnimationExt find function failed, reason: %{public}s", dlerror());
72 dlclose(handler);
73 return true;
74 }
75
76 bool resCode = CheckExitAnimationExtFunc();
77 dlclose(handler);
78 return resCode;
79 }
80 #endif
81
CheckNeedOtaCompile() const82 bool BootAnimationStrategy::CheckNeedOtaCompile() const
83 {
84 LOGI("CheckNeedOtaCompile");
85 std::string otaCompileSwitch = system::GetParameter(OTA_BMS_COMPILE_SWITCH, OTA_BMS_COMPILE_SWITCH_OFF);
86 if (otaCompileSwitch != OTA_BMS_COMPILE_SWITCH_ON) {
87 LOGI("ota compile switch is: %{public}s", otaCompileSwitch.c_str());
88 return false;
89 }
90
91 std::string dueUpdateType = system::GetParameter(DUE_UPDATE_TYPE_PARAM, "");
92 LOGI("dueUpdateType is: %{public}s", dueUpdateType.c_str());
93 bool isOtaUpdate = dueUpdateType == DUE_UPDATE_TYPE_MANUAL || dueUpdateType == DUE_UPDATE_TYPE_NIGHT;
94
95 std::string bmsCompileStatus = system::GetParameter(BMS_COMPILE_STATUS, "-1");
96 LOGI("bmsCompileStatus is: %{public}s", bmsCompileStatus.c_str());
97 bool isCompileDone = bmsCompileStatus == BMS_COMPILE_STATUS_END;
98
99 if (isOtaUpdate && !isCompileDone) {
100 return true;
101 }
102 return false;
103 }
104
CheckNeedBundleScan() const105 bool BootAnimationStrategy::CheckNeedBundleScan() const
106 {
107 LOGI("CheckNeedBundleScan");
108 if (system::GetParameter("bms.scanning_apps.status", "-1") == "1") {
109 LOGI("bundle scan is already done.");
110 return false;
111 }
112 return true;
113 }
114 } // namespace OHOS
115