1 /*
2 * Copyright (c) 2022 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 #ifdef RSS_DEVICE_STANDBY_ENABLE
17 #include "device_standby_plugin.h"
18 #include "standby_service_client.h"
19 #include "standby_service_log.h"
20 #include "config_info.h"
21 #include "plugin_mgr.h"
22 #include "res_type.h"
23 #include "nlohmann/json.hpp"
24
25 namespace OHOS {
26 namespace ResourceSchedule {
27 using namespace ResType;
28 namespace {
29 const std::string LIB_NAME = "libdevice_standby_plugin.z.so";
30 }
IMPLEMENT_SINGLE_INSTANCE(DeviceStandbyPlugin)31 IMPLEMENT_SINGLE_INSTANCE(DeviceStandbyPlugin)
32
33 void DeviceStandbyPlugin::Init()
34 {
35 resTypes_.insert(RES_TYPE_APP_INSTALL_UNINSTALL);
36 resTypes_.insert(RES_TYPE_SCREEN_STATUS);
37 resTypes_.insert(RES_TYPE_TIME_CHANGED);
38 resTypes_.insert(RES_TYPE_NITZ_TIME_CHANGED);
39 resTypes_.insert(RES_TYPE_TIMEZONE_CHANGED);
40 resTypes_.insert(RES_TYPE_NITZ_TIMEZONE_CHANGED);
41 resTypes_.insert(RES_TYPE_CHARGING_DISCHARGING);
42 resTypes_.insert(RES_TYPE_USB_DEVICE);
43 resTypes_.insert(RES_TYPE_CALL_STATE_CHANGED);
44 resTypes_.insert(RES_TYPE_WIFI_P2P_STATE_CHANGED);
45 resTypes_.insert(RES_TYPE_EFFICIENCY_RESOURCES_STATE_CHANGED);
46 resTypes_.insert(RES_TYPE_POWER_MODE_CHANGED);
47 #ifdef FEATURE_PRODUCT_WATCH
48 resTypes_.insert(RES_TYPE_CLICK_RECOGNIZE);
49 #endif
50 resTypes_.insert(RES_TYPE_MMI_INPUT_POWER_KEY);
51
52 for (auto resType : resTypes_) {
53 PluginMgr::GetInstance().SubscribeResource(LIB_NAME, resType);
54 }
55 STANDBYSERVICE_LOGI("DevicesStandbyPlugin::Init success");
56 }
57
Disable()58 void DeviceStandbyPlugin::Disable()
59 {
60 for (auto resType : resTypes_) {
61 PluginMgr::GetInstance().UnSubscribeResource(LIB_NAME, resType);
62 }
63 resTypes_.clear();
64 STANDBYSERVICE_LOGI("DevicesStandbyPlugin::Disable success");
65 }
66
DispatchResource(const std::shared_ptr<ResData> & data)67 void DeviceStandbyPlugin::DispatchResource(const std::shared_ptr<ResData>& data)
68 {
69 if (!data) {
70 STANDBYSERVICE_LOGW("DeviceStandbyPlugin::DispatchResource data is null");
71 return;
72 }
73
74 STANDBYSERVICE_LOGI(
75 "DeviceStandbyPlugin::DispatchResource type=%{public}u value=%{public}lld",
76 data->resType, (long long)(data->value));
77
78 DevStandbyMgr::StandbyServiceClient::GetInstance().HandleEvent(
79 std::make_shared<ResData>(data->resType, data->value, data->payload));
80 }
81
OnPluginInit(std::string & libName)82 extern "C" bool OnPluginInit(std::string& libName)
83 {
84 if (libName != LIB_NAME) {
85 STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginInit lib name is not match");
86 return false;
87 }
88 DeviceStandbyPlugin::GetInstance().Init();
89 STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginInit success.");
90 return true;
91 }
92
OnPluginDisable()93 extern "C" void OnPluginDisable()
94 {
95 DeviceStandbyPlugin::GetInstance().Disable();
96 STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginDisable success.");
97 }
98
OnDispatchResource(const std::shared_ptr<ResData> & data)99 extern "C" void OnDispatchResource(const std::shared_ptr<ResData>& data)
100 {
101 DeviceStandbyPlugin::GetInstance().DispatchResource(data);
102 STANDBYSERVICE_LOGD("DeviceStandbyPlugin::OnDispatchResource success.");
103 }
104 } // namespace ResourceSchedule
105 } // namespace OHOS
106 #endif