1 /*
2 * Copyright (c) 2024-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 "power_ext_intf_wrapper.h"
17 #include "power_log.h"
18
19 namespace OHOS {
20 namespace PowerMgr {
21 namespace {
22 const char* POWER_MANAGER_EXT_PATH = "libpower_manager_ext.z.so";
23
24 const std::vector<std::string> ALL_POWER_EXT_INTF_SYMBOL = {
25 #ifdef POWER_MANAGER_POWER_ENABLE_S4
26 "OnHibernateEnd",
27 #endif
28 #ifdef POWER_MANAGER_ENABLE_WATCH_CUSTOMIZED_SCREEN_COMMON_EVENT_RULES
29 "SetScreenOnEventRules",
30 "PublishCustomizedScreenEvent",
31 "NotifyScreenOnEventAgain",
32 "NotifyOperateEventAfterScreenOn",
33 #endif
34 };
35 } // namespace
36
Instance()37 PowerExtIntfWrapper& PowerExtIntfWrapper::Instance()
38 {
39 static PowerExtIntfWrapper instance(POWER_MANAGER_EXT_PATH, ALL_POWER_EXT_INTF_SYMBOL);
40 return instance;
41 }
42
GetRebootCommand(const std::string & rebootReason,std::string & rebootCmd) const43 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::GetRebootCommand(
44 const std::string& rebootReason, std::string& rebootCmd) const
45 {
46 POWER_HILOGI(COMP_SVC, "Enter GetRebootCommand wrapper");
47 void* funcPtr = intfLoader_.QueryInterface("GetRebootCommand");
48 if (funcPtr == nullptr) {
49 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
50 }
51 auto getRebootCommandFunc = reinterpret_cast<const char* (*)(const std::string&)>(funcPtr);
52 rebootCmd = getRebootCommandFunc(rebootReason);
53 return PowerExtIntfWrapper::ErrCode::ERR_OK;
54 }
55
SubscribeScreenLockCommonEvent() const56 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::SubscribeScreenLockCommonEvent() const
57 {
58 void* funcPtr = intfLoader_.QueryInterface("SubscribeScreenLockCommonEvent");
59 if (funcPtr == nullptr) {
60 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
61 }
62 auto subscribeScrLockEventFunc = reinterpret_cast<void (*)(void)>(funcPtr);
63 subscribeScrLockEventFunc();
64 return PowerExtIntfWrapper::ErrCode::ERR_OK;
65 }
66
UnSubscribeScreenLockCommonEvent() const67 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::UnSubscribeScreenLockCommonEvent() const
68 {
69 void* funcPtr = intfLoader_.QueryInterface("UnSubscribeScreenLockCommonEvent");
70 if (funcPtr == nullptr) {
71 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
72 }
73 auto unSubscribeScrLockEventFunc = reinterpret_cast<void (*)(void)>(funcPtr);
74 unSubscribeScrLockEventFunc();
75 return PowerExtIntfWrapper::ErrCode::ERR_OK;
76 }
77
BlockHibernateUntilScrLckReady() const78 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::BlockHibernateUntilScrLckReady() const
79 {
80 void* funcPtr = intfLoader_.QueryInterface("BlockHibernateUntilScrLckReady");
81 if (funcPtr == nullptr) {
82 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
83 }
84 auto blockHibernateFunc = reinterpret_cast<void (*)(void)>(funcPtr);
85 blockHibernateFunc();
86 return PowerExtIntfWrapper::ErrCode::ERR_OK;
87 }
88
OnHibernateEnd(bool hibernateResult)89 void PowerExtIntfWrapper::OnHibernateEnd(bool hibernateResult)
90 {
91 POWER_HILOGI(COMP_SVC, "Enter OnHibernateEnd wrapper");
92 void *funcPtr = intfLoader_.QueryInterface("OnHibernateEnd");
93 if (funcPtr == nullptr) {
94 return;
95 }
96 auto OnHibernateEndFunc = reinterpret_cast<void (*)(bool)>(funcPtr);
97 OnHibernateEndFunc(hibernateResult);
98 }
99
100 #ifdef POWER_MANAGER_ENABLE_WATCH_CUSTOMIZED_SCREEN_COMMON_EVENT_RULES
SetScreenOnEventRules(StateChangeReason reason,const std::vector<StateChangeReason> & stateChangeReason,const std::vector<WakeupDeviceType> & wakeupDeviceTypes)101 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::SetScreenOnEventRules(StateChangeReason reason,
102 const std::vector<StateChangeReason>& stateChangeReason, const std::vector<WakeupDeviceType>& wakeupDeviceTypes)
103 {
104 void *funcPtr = intfLoader_.QueryInterface("SetScreenOnEventRules");
105 if (funcPtr == nullptr) {
106 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
107 }
108 auto setScreenOnEventRulesFunc = reinterpret_cast<void (*)(
109 StateChangeReason, const std::vector<StateChangeReason>&, const std::vector<WakeupDeviceType>&)>(funcPtr);
110 setScreenOnEventRulesFunc(reason, stateChangeReason, wakeupDeviceTypes);
111 return PowerExtIntfWrapper::ErrCode::ERR_OK;
112 }
113
PublishCustomizedScreenEvent(PowerState state,std::vector<std::string> bundleNames)114 void PowerExtIntfWrapper::PublishCustomizedScreenEvent(PowerState state, std::vector<std::string> bundleNames)
115 {
116 void *funcPtr = intfLoader_.QueryInterface("PublishCustomizedScreenEvent");
117 if (funcPtr == nullptr) {
118 return;
119 }
120 auto publishCustomizedScreenEventFunc =
121 reinterpret_cast<void (*)(PowerState, std::vector<std::string>)>(funcPtr);
122 publishCustomizedScreenEventFunc(state, bundleNames);
123 }
124
NotifyScreenOnEventAgain(WakeupDeviceType reason,std::vector<std::string> bundleNames)125 bool PowerExtIntfWrapper::NotifyScreenOnEventAgain(WakeupDeviceType reason, std::vector<std::string> bundleNames)
126 {
127 void *funcPtr = intfLoader_.QueryInterface("NotifyScreenOnEventAgain");
128 if (funcPtr == nullptr) {
129 return false;
130 }
131 auto notifyScreenOnEventAgain =
132 reinterpret_cast<bool (*)(WakeupDeviceType, std::vector<std::string>)>(funcPtr);
133 return notifyScreenOnEventAgain(reason, bundleNames);
134 }
135
NotifyOperateEventAfterScreenOn(std::vector<std::string> bundleNames)136 void PowerExtIntfWrapper::NotifyOperateEventAfterScreenOn(std::vector<std::string> bundleNames)
137 {
138 void *funcPtr = intfLoader_.QueryInterface("NotifyOperateEventAfterScreenOn");
139 if (funcPtr == nullptr) {
140 return;
141 }
142 auto notifyOperateEventAfterScreenOnFunc = reinterpret_cast<void (*)(std::vector<std::string>)>(funcPtr);
143 notifyOperateEventAfterScreenOnFunc(bundleNames);
144 }
145 #endif
146
147 } // namespace PowerMgr
148 } // namespace OHOS