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