• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     constexpr const char* HMOS_UPDATE_PARAM = "persist.update.hmos_to_next_flag";
27     const std::string DUE_UPDATE_TYPE_MANUAL = "manual";
28     const std::string DUE_UPDATE_TYPE_NIGHT = "night";
29 }
30 
CheckExitAnimation()31 bool BootAnimationStrategy::CheckExitAnimation()
32 {
33     if (!isAnimationEnd_) {
34         LOGI("boot animation is end");
35         if (!system::GetBoolParameter(BOOT_ANIMATION_STARTED, false)) {
36             system::SetParameter(BOOT_ANIMATION_STARTED, "true");
37         }
38         system::SetParameter(BOOT_ANIMATION_FINISHED, "true");
39         isAnimationEnd_ = true;
40     }
41     bool bootEventCompleted = system::GetBoolParameter(BOOT_COMPLETED, false);
42     if (bootEventCompleted) {
43         LOGI("read boot completed is true");
44 #ifdef FEATURE_CHECK_EXIT_ANIMATION_EXT
45         return CheckExitAnimationExt();
46 #else
47         return true;
48 #endif
49     }
50     return false;
51 }
52 
53 #ifdef FEATURE_CHECK_EXIT_ANIMATION_EXT
54 #define CHECK_EXIT_ANIMATION_EXT_PATH "libwatch_bootanimation_ext.z.so"
55 #define CHECK_EXIT_ANIMATION_EXT_FUNC_NAME "CheckExitAnimationExt"
56 typedef bool(*Func)();
CheckExitAnimationExt()57 bool BootAnimationStrategy::CheckExitAnimationExt()
58 {
59     LOGI("CheckExitAnimationExt");
60     void *handler = dlopen(CHECK_EXIT_ANIMATION_EXT_PATH, RTLD_LAZY | RTLD_NODELETE);
61     if (handler == nullptr) {
62         LOGI("CheckExitAnimationExt Dlopen failed, reason: %{public}s", dlerror());
63         dlclose(handler);
64         return true;
65     }
66 
67     Func CheckExitAnimationExtFunc = (Func)dlsym(handler, CHECK_EXIT_ANIMATION_EXT_FUNC_NAME);
68     if (CheckExitAnimationExtFunc == nullptr) {
69         LOGI("CheckExitAnimationExt find function failed, reason: %{public}s", dlerror());
70         dlclose(handler);
71         return true;
72     }
73 
74     bool resCode = CheckExitAnimationExtFunc();
75     dlclose(handler);
76     return resCode;
77 }
78 #endif
79 
IsOtaUpdate() const80 bool BootAnimationStrategy::IsOtaUpdate() const
81 {
82     std::string dueUpdateType = system::GetParameter(DUE_UPDATE_TYPE_PARAM, "");
83     LOGI("dueUpdateType is: %{public}s", dueUpdateType.c_str());
84     bool isSingleUpdate = dueUpdateType == DUE_UPDATE_TYPE_MANUAL || dueUpdateType == DUE_UPDATE_TYPE_NIGHT;
85     bool isHmosUpdate = system::GetIntParameter(HMOS_UPDATE_PARAM, -1) == 1;
86     LOGI("isSingleUpdate: %{public}d, isHmosUpdate: %{public}d", isSingleUpdate, isHmosUpdate);
87     return isSingleUpdate || isHmosUpdate;
88 }
89 } // namespace OHOS
90