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 #endif
31 };
32 } // namespace
33
Instance()34 PowerExtIntfWrapper& PowerExtIntfWrapper::Instance()
35 {
36 static PowerExtIntfWrapper instance(POWER_MANAGER_EXT_PATH, ALL_POWER_EXT_INTF_SYMBOL);
37 return instance;
38 }
39
GetRebootCommand(const std::string & rebootReason,std::string & rebootCmd) const40 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::GetRebootCommand(
41 const std::string& rebootReason, std::string& rebootCmd) const
42 {
43 POWER_HILOGI(COMP_SVC, "Enter GetRebootCommand wrapper");
44 void* funcPtr = intfLoader_.QueryInterface("GetRebootCommand");
45 if (funcPtr == nullptr) {
46 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
47 }
48 auto getRebootCommandFunc = reinterpret_cast<const char* (*)(const std::string&)>(funcPtr);
49 rebootCmd = getRebootCommandFunc(rebootReason);
50 return PowerExtIntfWrapper::ErrCode::ERR_OK;
51 }
52
SubscribeScreenLockCommonEvent() const53 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::SubscribeScreenLockCommonEvent() const
54 {
55 void* funcPtr = intfLoader_.QueryInterface("SubscribeScreenLockCommonEvent");
56 if (funcPtr == nullptr) {
57 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
58 }
59 auto subscribeScrLockEventFunc = reinterpret_cast<void (*)(void)>(funcPtr);
60 subscribeScrLockEventFunc();
61 return PowerExtIntfWrapper::ErrCode::ERR_OK;
62 }
63
UnSubscribeScreenLockCommonEvent() const64 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::UnSubscribeScreenLockCommonEvent() const
65 {
66 void* funcPtr = intfLoader_.QueryInterface("UnSubscribeScreenLockCommonEvent");
67 if (funcPtr == nullptr) {
68 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
69 }
70 auto unSubscribeScrLockEventFunc = reinterpret_cast<void (*)(void)>(funcPtr);
71 unSubscribeScrLockEventFunc();
72 return PowerExtIntfWrapper::ErrCode::ERR_OK;
73 }
74
BlockHibernateUntilScrLckReady() const75 PowerExtIntfWrapper::ErrCode PowerExtIntfWrapper::BlockHibernateUntilScrLckReady() const
76 {
77 void* funcPtr = intfLoader_.QueryInterface("BlockHibernateUntilScrLckReady");
78 if (funcPtr == nullptr) {
79 return PowerExtIntfWrapper::ErrCode::ERR_NOT_FOUND;
80 }
81 auto blockHibernateFunc = reinterpret_cast<void (*)(void)>(funcPtr);
82 blockHibernateFunc();
83 return PowerExtIntfWrapper::ErrCode::ERR_OK;
84 }
85
86 } // namespace PowerMgr
87 } // namespace OHOS