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_STANDBY_CLICK_RECOGNIZE
48 resTypes_.insert(RES_TYPE_CLICK_RECOGNIZE);
49 #endif
50 resTypes_.insert(RES_TYPE_MMI_INPUT_POWER_KEY);
51 resTypes_.insert(RES_TYPE_AUDIO_RENDERER_STANDBY);
52 resTypes_.insert(RES_TYPE_AUDIO_RENDERER_SILENT_PLAYBACK);
53 resTypes_.insert(RES_TYPE_BT_SERVICE_EVENT);
54 resTypes_.insert(RES_TYPE_REPORT_BOKER_GATT_CONNECT);
55 resTypes_.insert(RES_TYPE_BOOT_COMPLETED);
56 resTypes_.insert(RES_TYPE_THERMAL_SCENARIO_REPORT);
57
58 for (auto resType : resTypes_) {
59 PluginMgr::GetInstance().SubscribeResource(LIB_NAME, resType);
60 }
61 STANDBYSERVICE_LOGI("DevicesStandbyPlugin::Init success");
62 }
63
Disable()64 void DeviceStandbyPlugin::Disable()
65 {
66 for (auto resType : resTypes_) {
67 PluginMgr::GetInstance().UnSubscribeResource(LIB_NAME, resType);
68 }
69 resTypes_.clear();
70 STANDBYSERVICE_LOGI("DevicesStandbyPlugin::Disable success");
71 }
72
DispatchResource(const std::shared_ptr<ResData> & data)73 void DeviceStandbyPlugin::DispatchResource(const std::shared_ptr<ResData>& data)
74 {
75 if (!data) {
76 STANDBYSERVICE_LOGW("DeviceStandbyPlugin::DispatchResource data is null");
77 return;
78 }
79
80 STANDBYSERVICE_LOGD(
81 "DeviceStandbyPlugin::DispatchResource type=%{public}u value=%{public}lld",
82 data->resType, (long long)(data->value));
83
84 DevStandbyMgr::StandbyServiceClient::GetInstance().HandleEvent(
85 std::make_shared<ResData>(data->resType, data->value, data->payload));
86 }
87
OnPluginInit(std::string & libName)88 extern "C" bool OnPluginInit(std::string& libName)
89 {
90 if (libName != LIB_NAME) {
91 STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginInit lib name is not match");
92 return false;
93 }
94 DeviceStandbyPlugin::GetInstance().Init();
95 STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginInit success.");
96 return true;
97 }
98
OnPluginDisable()99 extern "C" void OnPluginDisable()
100 {
101 DeviceStandbyPlugin::GetInstance().Disable();
102 STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginDisable success.");
103 }
104
OnDispatchResource(const std::shared_ptr<ResData> & data)105 extern "C" void OnDispatchResource(const std::shared_ptr<ResData>& data)
106 {
107 DeviceStandbyPlugin::GetInstance().DispatchResource(data);
108 STANDBYSERVICE_LOGD("DeviceStandbyPlugin::OnDispatchResource success.");
109 }
110 } // namespace ResourceSchedule
111 } // namespace OHOS
112 #endif