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