• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "component_sched_plugin.h"
17 
18 #ifdef COMPONENT_SCHED_ENABLE
19 #include "component_sched_client.h"
20 #endif
21 
22 #include "config_info.h"
23 #include "plugin_mgr.h"
24 #include "res_sched_log.h"
25 #include "res_type.h"
26 
27 namespace OHOS {
28 namespace ResourceSchedule {
29 using namespace ResType;
30 namespace {
31     const std::string LIB_NAME = "libcomponent_sched_plugin.z.so";
32 }
IMPLEMENT_SINGLE_INSTANCE(ComponentSchedPlugin)33 IMPLEMENT_SINGLE_INSTANCE(ComponentSchedPlugin)
34 
35 void ComponentSchedPlugin::Init()
36 {
37     resTypes_.insert(RES_TYPE_SCREEN_STATUS);
38     resTypes_.insert(RES_TYPE_WINDOW_FOCUS);
39     resTypes_.insert(RES_TYPE_CALL_STATE_UPDATE);
40     resTypes_.insert(RES_TYPE_AUDIO_RENDER_STATE_CHANGE);
41     resTypes_.insert(RES_TYPE_AUDIO_RING_MODE_CHANGE);
42     resTypes_.insert(RES_TYPE_AUDIO_VOLUME_KEY_CHANGE);
43     resTypes_.insert(RES_TYPE_CONTINUOUS_TASK);
44     resTypes_.insert(RES_TYPE_DEVICE_STILL_STATE_CHANGE);
45     resTypes_.insert(RES_TYPE_APP_INSTALL_UNINSTALL);
46     resTypes_.insert(RES_TYPE_USER_SWITCH);
47 
48     for (auto resType : resTypes_) {
49         PluginMgr::GetInstance().SubscribeResource(LIB_NAME, resType);
50     }
51     RESSCHED_LOGI("ComponentSchedPlugin::Init success");
52 }
53 
Disable()54 void ComponentSchedPlugin::Disable()
55 {
56     for (auto resType : resTypes_) {
57         PluginMgr::GetInstance().UnSubscribeResource(LIB_NAME, resType);
58     }
59     resTypes_.clear();
60     RESSCHED_LOGI("ComponentSchedPlugin::Disable success");
61 }
62 
DispatchResource(const std::shared_ptr<ResData> & data)63 void ComponentSchedPlugin::DispatchResource(const std::shared_ptr<ResData>& data)
64 {
65     if (!data) {
66         RESSCHED_LOGW("ComponentSchedPlugin::DispatchResource data is null");
67         return;
68     }
69 
70     RESSCHED_LOGD(
71         "ComponentSchedPlugin::DispatchResource type=%{public}u value=%{public}lld",
72         data->resType, (long long)(data->value));
73 
74 #ifdef COMPONENT_SCHED_ENABLE
75     ComponentScheduler::ComponentSchedClient::GetInstance().ReportSceneInfo(data);
76 #endif
77 }
78 
OnPluginInit(std::string & libName)79 extern "C" bool OnPluginInit(std::string& libName)
80 {
81     if (libName != LIB_NAME) {
82         RESSCHED_LOGE("ComponentSchedPlugin::OnPluginInit lib name is not match");
83         return false;
84     }
85     ComponentSchedPlugin::GetInstance().Init();
86     RESSCHED_LOGI("ComponentSchedPlugin::OnPluginInit success.");
87     return true;
88 }
89 
OnPluginDisable()90 extern "C" void OnPluginDisable()
91 {
92     ComponentSchedPlugin::GetInstance().Disable();
93     RESSCHED_LOGI("ComponentSchedPlugin::OnPluginDisable success.");
94 }
95 
OnDispatchResource(const std::shared_ptr<ResData> & data)96 extern "C" void OnDispatchResource(const std::shared_ptr<ResData>& data)
97 {
98     ComponentSchedPlugin::GetInstance().DispatchResource(data);
99     RESSCHED_LOGD("ComponentSchedPlugin::OnDispatchResource success.");
100 }
101 } // namespace ResourceSchedule
102 } // namespace OHOS
103