From bcfcffb16aad34f4a78f8d56c9bb1ea328866f49 Mon Sep 17 00:00:00 2001 From: joseph_ju Date: Tue, 24 Oct 2023 02:34:51 +0000 Subject: [PATCH 1/5] =?UTF-8?q?nap=E4=BA=8B=E4=BB=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: joseph_ju --- .../sched_controller/app_state_observer.cpp | 30 +- .../sched_controller/cgroup_event_handler.cpp | 18 +- .../include/app_state_observer.h | 3 +- .../include/cgroup_event_handler.h | 3 +- .../sched_controller/include/supervisor.h | 1 + .../ressched_client/include/res_type.h | 30 +- ...amera_observer.h => hisysevent_observer.h} | 59 +++- .../observer/include/observer_manager.h | 8 +- .../observer/src/camera_observer.cpp | 35 -- .../observer/src/hisysevent_observer.cpp | 298 ++++++++++++++++++ .../observer/src/observer_manager.cpp | 42 ++- ressched/services/BUILD.gn | 6 +- 12 files changed, 456 insertions(+), 77 deletions(-) rename ressched/sched_controller/observer/include/{camera_observer.h => hisysevent_observer.h} (33%) mode change 100644 => 100755 delete mode 100644 ressched/sched_controller/observer/src/camera_observer.cpp create mode 100755 ressched/sched_controller/observer/src/hisysevent_observer.cpp diff --git a/cgroup_sched/framework/sched_controller/app_state_observer.cpp b/cgroup_sched/framework/sched_controller/app_state_observer.cpp index a01c3a70..f1db4cac 100644 --- a/cgroup_sched/framework/sched_controller/app_state_observer.cpp +++ b/cgroup_sched/framework/sched_controller/app_state_observer.cpp @@ -166,7 +166,7 @@ void RmsApplicationStateObserver::OnProcessDied(const ProcessData &processData) ResType::RES_TYPE_PROCESS_STATE_CHANGE, ResType::ProcessStatus::PROCESS_DIED, payload); } -void RmsApplicationStateObserver::OnApplicationStateChanged(const AppStateData &appStateData) +void RmsApplicationStateObserver::OnAppStateChanged(const AppStateData &appStateData) { if (!ValidateAppStateData(appStateData)) { CGS_LOGE("%{public}s : validate app state data failed!", __func__); @@ -181,7 +181,7 @@ void RmsApplicationStateObserver::OnApplicationStateChanged(const AppStateData & auto state = appStateData.state; cgHandler->PostTask([cgHandler, uid, pid, bundleName, state] { - cgHandler->HandleApplicationStateChanged(uid, pid, bundleName, state); + cgHandler->HandleAppStateChanged(uid, pid, bundleName, state); }); } @@ -191,5 +191,31 @@ void RmsApplicationStateObserver::OnApplicationStateChanged(const AppStateData & payload["bundleName"] = appStateData.bundleName; ResSchedUtils::GetInstance().ReportDataInProcess(ResType::RES_TYPE_APP_STATE_CHANGE, appStateData.state, payload); } + +void RmsApplicationStateObserver::OnProcessStateChanged(const ProcessData &processData) +{ + if (!ValidateProcessData(processData)) { + CGS_LOGE("%{public}s : validate process data failed!", __func__); + return; + } + auto cgHandler = SchedController::GetInstance().GetCgroupEventHandler(); + if (cgHandler) { + auto uid = processData.uid; + auto pid = processData.pid; + auto bundleName = processData.bundleName; + auto state = static_cast(processData.state); + + cgHandler->PostTask([cgHandler, uid, pid, bundleName, state] { + cgHandler->HandleProcessStateChanged(uid, pid, bundleName, state); + }); + } + + nlohmann::json payload; + payload["pid"] = std::to_string(processData.pid); + payload["uid"] = std::to_string(processData.uid); + payload["bundleName"] = processData.bundleName; + ResSchedUtils::GetInstance().ReportDataInProcess( + ResType::RES_TYPE_PROCESS_STATE_CHANGE, static_cast(processData.state), payload); +} } // namespace ResourceSchedule } // namespace OHOS diff --git a/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp b/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp index 8647331c..3c11057c 100644 --- a/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp +++ b/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp @@ -158,7 +158,7 @@ void CgroupEventHandler::HandleForegroundApplicationChanged(uid_t uid, pid_t pid CgroupAdjuster::GetInstance().AdjustAllProcessGroup(*(app.get()), AdjustSource::ADJS_FG_APP_CHANGE); } -void CgroupEventHandler::HandleApplicationStateChanged(uid_t uid, pid_t pid, +void CgroupEventHandler::HandleAppStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state) { if (!supervisor_) { @@ -166,7 +166,7 @@ void CgroupEventHandler::HandleApplicationStateChanged(uid_t uid, pid_t pid, return; } CGS_LOGD("%{public}s : %{public}d, %{public}s, %{public}d", __func__, uid, bundleName.c_str(), state); - ChronoScope cs("HandleApplicationStateChanged"); + ChronoScope cs("HandleAppStateChanged"); // remove terminated application if (state == (int32_t)(ApplicationState::APP_STATE_TERMINATED)) { supervisor_->RemoveApplication(uid); @@ -179,6 +179,20 @@ void CgroupEventHandler::HandleApplicationStateChanged(uid_t uid, pid_t pid, app->SetMainProcess(procRecord); } +void CgroupEventHandler::HandleProcessStateChanged(uid_t uid, pid_t pid, + const std::string& bundleName, int32_t state) +{ + if (!supervisor_) { + CGS_LOGE("%{public}s : supervisor nullptr!", __func__); + return; + } + CGS_LOGD("%{public}s : %{public}d, %{public}s, %{public}d", __func__, uid, bundleName.c_str(), state); + ChronoScope cs("HandleProcessStateChanged"); + std::shared_ptr app = supervisor_->GetAppRecordNonNull(uid); + std::shared_ptr procRecord = app->GetProcessRecordNonNull(pid); + procRecord->processState_ = state; +} + void CgroupEventHandler::HandleAbilityStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, const std::string& abilityName, uintptr_t token, int32_t abilityState, int32_t abilityType) { diff --git a/cgroup_sched/framework/sched_controller/include/app_state_observer.h b/cgroup_sched/framework/sched_controller/include/app_state_observer.h index 7ded9a58..2b9c2bec 100644 --- a/cgroup_sched/framework/sched_controller/include/app_state_observer.h +++ b/cgroup_sched/framework/sched_controller/include/app_state_observer.h @@ -32,7 +32,8 @@ public: void OnExtensionStateChanged(const AbilityStateData &abilityStateData) override; void OnProcessCreated(const ProcessData &processData) override; void OnProcessDied(const ProcessData &processData) override; - void OnApplicationStateChanged(const AppStateData &appStateData) override; + void OnAppStateChanged(const AppStateData &appStateData) override; + void OnProcessStateChanged(const ProcessData &processData) override; private: inline bool ValidateAppStateData(const AppStateData &appStateData) const diff --git a/cgroup_sched/framework/sched_controller/include/cgroup_event_handler.h b/cgroup_sched/framework/sched_controller/include/cgroup_event_handler.h index 4e9f8435..241e9773 100644 --- a/cgroup_sched/framework/sched_controller/include/cgroup_event_handler.h +++ b/cgroup_sched/framework/sched_controller/include/cgroup_event_handler.h @@ -37,7 +37,8 @@ public: void HandleAbilityAdded(int32_t saId, const std::string& deviceId); void HandleAbilityRemoved(int32_t saId, const std::string& deviceId); void HandleForegroundApplicationChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); - void HandleApplicationStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); + void HandleAppStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); + void HandleProcessStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); void HandleAbilityStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, const std::string& abilityName, uintptr_t token, int32_t abilityState, int32_t abilityType); void HandleExtensionStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, diff --git a/cgroup_sched/framework/sched_controller/include/supervisor.h b/cgroup_sched/framework/sched_controller/include/supervisor.h index 3cdf20f4..b5e08dce 100644 --- a/cgroup_sched/framework/sched_controller/include/supervisor.h +++ b/cgroup_sched/framework/sched_controller/include/supervisor.h @@ -98,6 +98,7 @@ public: uint32_t continuousTaskFlag_ = 0; int32_t renderTid_ = 0; int32_t maliTid_ = 0; + int32_t processState_ = 0; std::vector> abilities_; std::vector> windows_; diff --git a/ressched/interfaces/innerkits/ressched_client/include/res_type.h b/ressched/interfaces/innerkits/ressched_client/include/res_type.h index ac9873f1..af68c064 100644 --- a/ressched/interfaces/innerkits/ressched_client/include/res_type.h +++ b/ressched/interfaces/innerkits/ressched_client/include/res_type.h @@ -125,6 +125,11 @@ enum : uint32_t { RES_TYPE_LOAD_URL = 44, // mousewheel event; value means nothing. RES_TYPE_MOUSEWHEEL = 45, + // report camera state, value 0: camera connect; value 1: camera disconnect + RES_TYPE_REPORT_CAMERA_STATE = 46, + // report runningLock state, value 0: runningLock disable; value 1: runningLock enable; + // value 2: runningLock is proxied; value 3: runningLock is not proxied + RES_TYPE_RUNNINGLOCK_STATE = 47, }; inline const std::map resTypeToStr = { @@ -171,7 +176,9 @@ inline const std::map resTypeToStr = { { RES_TYPE_WEB_GESTURE_MOVE, "RES_TYPE_WEB_GESTURE_MOVE" }, { RES_TYPE_WEB_SLIDE_NORMAL, "RES_TYPE_WEB_SLIDE_NORMAL" }, { RES_TYPE_LOAD_URL, "RES_TYPE_LOAD_URL" }, - { RES_TYPE_MOUSEWHEEL, "RES_TYPE_MOUSEWHEEL" } + { RES_TYPE_MOUSEWHEEL, "RES_TYPE_MOUSEWHEEL" }, + { RES_TYPE_REPORT_CAMERA_STATE, "RES_TYPE_REPORT_CAMERA_STATE" }, + { RES_TYPE_RUNNINGLOCK_STATE, "RES_TYPE_RUNNINGLOCK_STATE" } }; /** @@ -206,6 +213,9 @@ enum ScreenLockStatus : int64_t { enum ProcessStatus : int64_t { PROCESS_CREATED = 0, PROCESS_DIED = 1, + PROCESS_READY = 2, + PROCESS_FOREGROUND = 3, + PROCESS_BACKGROUND = 4, }; /** @@ -384,6 +394,24 @@ enum WebSlideNormal : int64_t { WEB_SLIDE_NORMAL_START = 0, WEB_SLIDE_NORMAL_END = 1, }; + +/** + * @brief camera state + */ +enum CameraState : int64_t { + CAMERA_CONNECT = 0, + CAMERA_DISCONNECT = 1, +}; + +/** + * @brief Runninglock State + */ +enum RunninglockState : int64_t { + RUNNINGLOCK_STATE_DISABLE = 0, + RUNNINGLOCK_STATE_ENABLE = 1, + RUNNINGLOCK_STATE_PROXIED = 2, + RUNNINGLOCK_STATE_UNPROXIED_RESTORE = 3, +}; } // namespace ResType } // namespace ResourceSchedule } // namespace OHOS diff --git a/ressched/sched_controller/observer/include/camera_observer.h b/ressched/sched_controller/observer/include/hisysevent_observer.h old mode 100644 new mode 100755 similarity index 33% rename from ressched/sched_controller/observer/include/camera_observer.h rename to ressched/sched_controller/observer/include/hisysevent_observer.h index 5b55a02f..ce2a9344 --- a/ressched/sched_controller/observer/include/camera_observer.h +++ b/ressched/sched_controller/observer/include/hisysevent_observer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,23 +13,68 @@ * limitations under the License. */ -#ifndef RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_CAMERA_OBSERVER_H -#define RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_CAMERA_OBSERVER_H +#ifndef RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_HISYSEVENT_OBSERVER_H +#define RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_HISYSEVENT_OBSERVER_H #include #include #include "hisysevent_listener.h" +#include "nlohmann/json.hpp" namespace OHOS { namespace ResourceSchedule { -class CameraObserver : public HiviewDFX::HiSysEventListener { +class HiSysEventObserver : public HiviewDFX::HiSysEventListener { public: - CameraObserver() : HiviewDFX::HiSysEventListener() {} - virtual ~CameraObserver() {} void OnEvent(std::shared_ptr sysEvent) override; void OnServiceDied() override; + void ProcessHiSysEvent(const std::string& eventName, const nlohmann::json& root); + + HiSysEventObserver(); + ~HiSysEventObserver(); + +private: + void ProcessRunningLockEvent(const nlohmann::json& root, const std::string& eventName); + void ProcessAudioEvent(const nlohmann::json& root, const std::string& eventName); + void ProcessCameraEvent(const nlohmann::json& root, const std::string& eventName); + void ProcessBluetoothEvent(const nlohmann::json& root, const std::string& eventName); + void ProcessWifiEvent(const nlohmann::json& root, const std::string& eventName); + bool CheckJsonValue(const nlohmann::json& value, std::initializer_list params); + + std::map> handleObserverMap_; +}; + +/** +* Audio State +*/ +enum class AudioState : int32_t { + AUDIO_STATE_INVALID = -1, + AUDIO_STATE_NEW, + AUDIO_STATE_PREPARED, + AUDIO_STATE_RUNNING, + AUDIO_STATE_STOPPED, + AUDIO_STATE_RELEASED, + AUDIO_STATE_PAUSED +}; + +/** +* Runninglock State +*/ +enum class RunningLockState : int32_t { + RUNNINGLOCK_STATE_DISABLE = 0, + RUNNINGLOCK_STATE_ENABLE, + RUNNINGLOCK_STATE_PROXIED, + RUNNINGLOCK_STATE_UNPROXIED_RESTORE, +}; + +/** +* Wifi State +*/ +enum class WifiState : int32_t { + CONNECTED = 0, + DISCONNECTED }; } // namespace ResourceSchedule } // namespace OHOS -#endif // RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_CAMERA_OBSERVER_H +#endif // RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_HISYSEVENT_OBSERVER_H diff --git a/ressched/sched_controller/observer/include/observer_manager.h b/ressched/sched_controller/observer/include/observer_manager.h index d60f2051..a5cc7f58 100644 --- a/ressched/sched_controller/observer/include/observer_manager.h +++ b/ressched/sched_controller/observer/include/observer_manager.h @@ -21,7 +21,7 @@ #include "single_instance.h" #include "audio_observer.h" -#include "camera_observer.h" +#include "hisysevent_observer.h" #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE #include "device_movement_observer.h" #endif @@ -48,8 +48,8 @@ public: virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; }; - void InitCameraObserver(); - void DisableCameraObserver(); + void InitHiSysEventObserver(); + void DisableHiSysEventObserver(); void InitTelephonyObserver(); void DisableTelephonyObserver(); void InitAudioObserver(); @@ -62,7 +62,7 @@ public: pid_t pid_ = -1; std::map> handleObserverMap_; std::map> removeObserverMap_; - std::shared_ptr cameraObserver_ = nullptr; + std::shared_ptr hiSysEventObserver_ = nullptr; #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE int32_t slotId_ = 0; sptr telephonyObserver_ = nullptr; diff --git a/ressched/sched_controller/observer/src/camera_observer.cpp b/ressched/sched_controller/observer/src/camera_observer.cpp deleted file mode 100644 index e400b8b0..00000000 --- a/ressched/sched_controller/observer/src/camera_observer.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "camera_observer.h" - -#include "res_sched_log.h" - -namespace OHOS { -namespace ResourceSchedule { -void CameraObserver::OnEvent(std::shared_ptr sysEvent) -{ - if (sysEvent == nullptr) { - return; - } - RESSCHED_LOGD("EventDetail: %{public}s", sysEvent->AsJson().c_str()); -} - -void CameraObserver::OnServiceDied() -{ - RESSCHED_LOGE("CameraObserver service disconnected"); -} -} // namespace ResourceSchedule -} // namespace OHOS diff --git a/ressched/sched_controller/observer/src/hisysevent_observer.cpp b/ressched/sched_controller/observer/src/hisysevent_observer.cpp new file mode 100755 index 00000000..5117293c --- /dev/null +++ b/ressched/sched_controller/observer/src/hisysevent_observer.cpp @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hisysevent_observer.h" + +#include "bluetooth_def.h" +#include "res_sched_log.h" +#include "res_sched_mgr.h" +#include "res_type.h" + +namespace OHOS { +namespace ResourceSchedule { +namespace { + static const std::string WIFI_CONNECTION = "WIFI_CONNECTION"; + static const std::string WIFI_SCAN = "WIFI_SCAN"; + static const std::string CAMERA_CONNECT = "CAMERA_CONNECT"; + constexpr int32_t WIFISCAN = 2; + constexpr int32_t WIFICONNECTED = 3; + constexpr int32_t WIFIDISCONNECTED = 5; + constexpr int32_t CAMERACONNECT = 0; + constexpr int32_t CAMERADISCONNECT = 1; + constexpr int32_t RENDERERRUNNING = 2; + constexpr int32_t RENDERERSTOPPED = 3; + constexpr int32_t RUNNINGLOCK_DISABLE = 0; + constexpr int32_t RUNNINGLOCK_ENABLE = 1; + constexpr int32_t RUNNINGLOCK_PROXIED = 2; +} + +HiSysEventObserver::HiSysEventObserver() : HiviewDFX::HiSysEventListener() +{ + handleObserverMap_ = { + {"RUNNINGLOCK", std::bind(&HiSysEventObserver::ProcessRunningLockEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"STREAM_CHANGE", std::bind(&HiSysEventObserver::ProcessAudioEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"CAMERA_CONNECT", std::bind(&HiSysEventObserver::ProcessCameraEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"CAMERA_DISCONNECT", std::bind(&HiSysEventObserver::ProcessCameraEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"BR_SWITCH_STATE", std::bind(&HiSysEventObserver::ProcessBluetoothEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"SPP_CONNECT_STATE", std::bind(&HiSysEventObserver::ProcessBluetoothEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"BLE_SWITCH_STATE", std::bind(&HiSysEventObserver::ProcessBluetoothEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"BLE_SCAN_START", std::bind(&HiSysEventObserver::ProcessBluetoothEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"BLE_SCAN_STOP", std::bind(&HiSysEventObserver::ProcessBluetoothEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"WIFI_CONNECTION", std::bind(&HiSysEventObserver::ProcessWifiEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}, + {"WIFI_SCAN", std::bind(&HiSysEventObserver::ProcessWifiEvent, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)} + }; +} + +HiSysEventObserver::~HiSysEventObserver() +{ + handleObserverMap_.clear(); +} + +bool HiSysEventObserver::CheckJsonValue(const nlohmann::json& value, std::initializer_list params) +{ + for (auto param : params) { + if (value.find(param) == value.end()) { + return false; + } + } + return true; +} + +void HiSysEventObserver::OnEvent(std::shared_ptr sysEvent) +{ + if (sysEvent == nullptr) { + RESSCHED_LOGE("OnEvent hisysevent info is null"); + return; + } + std::string eventDetail = sysEvent->AsJson(); + RESSCHED_LOGD("Process hisysevent event, detail:%{public}s", eventDetail.c_str()); + nlohmann::json root = nlohmann::json::parse(eventDetail, nullptr, false); + if (root.is_discarded()) { + RESSCHED_LOGE("Parse hisysevent data failed"); + return; + } + if (!CheckJsonValue(root, { "domain_", "name_" }) + || !root.at("domain_").is_string() || !root.at("name_").is_string()) { + RESSCHED_LOGE("hisysevent data domain info lost"); + return; + } + std::string domainName = root.at("domain_").get(); + std::string eventName = root.at("name_").get(); + RESSCHED_LOGI("hisysevent info, domain: %{public}s, name:%{public}s", domainName.c_str(), eventName.c_str()); + ProcessHiSysEvent(eventName, root); +} + +void HiSysEventObserver::ProcessHiSysEvent(const std::string& eventName, const nlohmann::json& root) +{ + auto funcIter = handleObserverMap_.find(eventName.c_str()); + if (funcIter != handleObserverMap_.end()) { + auto function = funcIter->second; + if (function) { + function(this, root, eventName); + } + } +} + +void HiSysEventObserver::ProcessRunningLockEvent(const nlohmann::json& root, const std::string& eventName) +{ + std::string str = root.dump(); + nlohmann::json payload; + if (root.contains("UID") && root.at("UID").is_number_integer()) { + payload["uid"] = root.at("UID").get(); + } else { + RESSCHED_LOGE("running lock event uid format error!"); + return; + } + if (root.contains("PID") && root.at("PID").is_number_integer()) { + payload["pid"] = root.at("PID").get(); + } else { + RESSCHED_LOGE("running lock event pid format error!"); + return; + } + + if (root.contains("STATE") && root.at("STATE").is_number_integer()) { + RunningLockState lockState = RunningLockState(root.at("STATE").get()); + RESSCHED_LOGD("Process runninglock event, event type is:%{public}d", lockState); + switch (lockState) { + case RunningLockState::RUNNINGLOCK_STATE_DISABLE: { + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_RUNNINGLOCK_STATE, + RUNNINGLOCK_DISABLE, payload); + break; + } + case RunningLockState::RUNNINGLOCK_STATE_ENABLE: { + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_RUNNINGLOCK_STATE, + RUNNINGLOCK_ENABLE, payload); + break; + } + case RunningLockState::RUNNINGLOCK_STATE_PROXIED: + case RunningLockState::RUNNINGLOCK_STATE_UNPROXIED_RESTORE: { + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_RUNNINGLOCK_STATE, + RUNNINGLOCK_PROXIED, payload); + break; + } + default: + break; + } + } else { + RESSCHED_LOGE("running lock event state format error!"); + return; + } +} + +void HiSysEventObserver::ProcessAudioEvent(const nlohmann::json& root, const std::string& eventName) +{ + std::string str = root.dump(); + RESSCHED_LOGD("Process audio event, event root :%{public}s", str.c_str()); + nlohmann::json payload; + if (root.contains("UID") && root.at("UID").is_number_integer()) { + payload["uid"] = root.at("UID").get(); + } else { + RESSCHED_LOGE("audio event uid format error!"); + return; + } + if (root.contains("PID") && root.at("PID").is_number_integer()) { + payload["pid"] = root.at("PID").get(); + } else { + RESSCHED_LOGE("audio event pid format error!"); + return; + } + + if (root.contains("STATE") && root.at("STATE").is_number_integer()) { + AudioState audioState = AudioState(root.at("STATE").get()); + RESSCHED_LOGD("Process audio event, event type is:%{public}d", audioState); + switch (audioState) { + case AudioState::AUDIO_STATE_RUNNING: + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_AUDIO_RENDER_STATE_CHANGE, + RENDERERRUNNING, payload); + break; + case AudioState::AUDIO_STATE_STOPPED: + case AudioState::AUDIO_STATE_RELEASED: + case AudioState::AUDIO_STATE_PAUSED: + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_AUDIO_RENDER_STATE_CHANGE, + RENDERERSTOPPED, payload); + break; + default: + break; + } + } else { + RESSCHED_LOGE("audio event state format error!"); + return; + } +} + +void HiSysEventObserver::ProcessCameraEvent(const nlohmann::json& root, const std::string& eventName) +{ + std::string str = root.dump(); + RESSCHED_LOGD("Process camera event, event root:%{public}s, eventName:%{public}s", str.c_str(), eventName.c_str()); + nlohmann::json payload; + if (root.contains("UID") && root.at("UID").is_number_integer()) { + payload["uid"] = root.at("UID").get(); + } else { + RESSCHED_LOGE("camera event uid format error!"); + return; + } + if (root.contains("PID") && root.at("PID").is_number_integer()) { + payload["pid"] = root.at("PID").get(); + } else { + RESSCHED_LOGE("camera event pid format error!"); + return; + } + + if (eventName == CAMERA_CONNECT) { + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_REPORT_CAMERA_STATE, CAMERACONNECT, payload); + } else { + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_REPORT_CAMERA_STATE, CAMERADISCONNECT, payload); + } +} + +void HiSysEventObserver::ProcessBluetoothEvent(const nlohmann::json& root, const std::string& eventName) +{ + std::string str = root.dump(); + RESSCHED_LOGD("Process bluetooth event, event root :%{public}s", str.c_str()); + if (root.contains("STATE") && root.at("STATE").is_number_integer()) { + const nlohmann::json payload = nlohmann::json::object(); + RESSCHED_LOGD("Process bluetooth event, event type is:%{public}d", root.at("STATE").get()); + if (root.at("STATE").get() == Bluetooth::BTStateID::STATE_TURN_ON) { + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_BLUETOOTH_A2DP_CONNECT_STATE_CHANGE, + Bluetooth::BTStateID::STATE_TURN_ON, payload); + } else if (root.at("STATE").get() == Bluetooth::BTStateID::STATE_TURN_OFF) { + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_BLUETOOTH_A2DP_CONNECT_STATE_CHANGE, + Bluetooth::BTStateID::STATE_TURN_OFF, payload); + } + } else { + RESSCHED_LOGE("Bluetooth event type not support!"); + return; + } +} + +void HiSysEventObserver::ProcessWifiEvent(const nlohmann::json& root, const std::string& eventName) +{ + std::string str = root.dump(); + RESSCHED_LOGD("Process wifi event, event root :%{public}s, eventName:%{public}s", str.c_str(), eventName.c_str()); + nlohmann::json payload; + if (root.contains("uid_") && root.at("uid_").is_number_integer()) { + payload["uid"] = root.at("uid_").get(); + } else { + RESSCHED_LOGE("Wifi event uid format error!"); + return; + } + if (root.contains("pid_") && root.at("pid_").is_number_integer()) { + payload["pid"] = root.at("pid_").get(); + } else { + RESSCHED_LOGE("Wifi event pid format error!"); + return; + } + + if (eventName == WIFI_CONNECTION) { + if (root.contains("TYPE") && root.at("TYPE").is_number_integer()) { + WifiState connectionType = WifiState(root.at("TYPE").get()); + switch (connectionType) { + case WifiState::CONNECTED: + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WIFI_CONNECT_STATE_CHANGE, + WIFICONNECTED, payload); + break; + case WifiState::DISCONNECTED: + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WIFI_CONNECT_STATE_CHANGE, + WIFIDISCONNECTED, payload); + break; + default: + break; + } + } + } else if (eventName == WIFI_SCAN) { + ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WIFI_CONNECT_STATE_CHANGE, WIFISCAN, payload); + } else { + RESSCHED_LOGE("Wifi event name not support!"); + return; + } +} + +void HiSysEventObserver::OnServiceDied() +{ + RESSCHED_LOGE("HiSysEventObserver service disconnected"); +} +} // namespace ResourceSchedule +} // namespace OHOS diff --git a/ressched/sched_controller/observer/src/observer_manager.cpp b/ressched/sched_controller/observer/src/observer_manager.cpp index 61c5f1e5..9a59ddc5 100644 --- a/ressched/sched_controller/observer/src/observer_manager.cpp +++ b/ressched/sched_controller/observer/src/observer_manager.cpp @@ -48,7 +48,7 @@ void ObserverManager::Disable() { handleObserverMap_.clear(); removeObserverMap_.clear(); - DisableCameraObserver(); + DisableHiSysEventObserver(); DisableTelephonyObserver(); sysAbilityListener_ = nullptr; } @@ -74,14 +74,14 @@ void ObserverManager::InitSysAbilityListener() } handleObserverMap_ = { - { DFX_SYS_EVENT_SERVICE_ABILITY_ID, std::bind(&ObserverManager::InitCameraObserver, std::placeholders::_1) }, + { DFX_SYS_EVENT_SERVICE_ABILITY_ID, std::bind(&ObserverManager::InitHiSysEventObserver, std::placeholders::_1) }, { TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID, std::bind(&ObserverManager::InitTelephonyObserver, std::placeholders::_1) }, { AUDIO_POLICY_SERVICE_ID, std::bind(&ObserverManager::InitAudioObserver, std::placeholders::_1) }, { MSDP_MOVEMENT_SERVICE_ID, std::bind(&ObserverManager::InitDeviceMovementObserver, std::placeholders::_1) } }; removeObserverMap_ = { - { DFX_SYS_EVENT_SERVICE_ABILITY_ID, std::bind(&ObserverManager::DisableCameraObserver, std::placeholders::_1) }, + { DFX_SYS_EVENT_SERVICE_ABILITY_ID, std::bind(&ObserverManager::DisableHiSysEventObserver, std::placeholders::_1) }, { TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID, std::bind(&ObserverManager::DisableTelephonyObserver, std::placeholders::_1) }, { AUDIO_POLICY_SERVICE_ID, std::bind(&ObserverManager::DisableAudioObserver, std::placeholders::_1) }, @@ -132,44 +132,42 @@ void ObserverManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbility( } } -void ObserverManager::InitCameraObserver() +void ObserverManager::InitHiSysEventObserver() { - RESSCHED_LOGI("Init camera observer"); - if (!cameraObserver_) { - cameraObserver_ = std::make_shared(); + RESSCHED_LOGI("Init hisysevent observer"); + if (!hiSysEventObserver_) { + hiSysEventObserver_ = std::make_shared(); } - HiviewDFX::ListenerRule cameraStateRule("CAMERA", "CAMERA_STATE"); - HiviewDFX::ListenerRule cameraStatisticRule("CAMERA", "CAMERA_STATISTIC"); + HiviewDFX::ListenerRule statsRule("PowerStats"); std::vector sysRules; - sysRules.push_back(cameraStateRule); - sysRules.push_back(cameraStatisticRule); - auto res = HiviewDFX::HiSysEventManager::AddListener(cameraObserver_, sysRules); + sysRules.push_back(statsRule); + auto res = HiviewDFX::HiSysEventManager::AddListener(hiSysEventObserver_, sysRules); if (res == 0) { - RESSCHED_LOGD("ObserverManager init camera observer successfully"); + RESSCHED_LOGD("ObserverManager init hisysevent observer successfully"); } else { - RESSCHED_LOGW("ObserverManager init camera observer failed"); + RESSCHED_LOGW("ObserverManager init hisysevent observer failed"); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::RSS, "INIT_FAULT", HiviewDFX::HiSysEvent::EventType::FAULT, "COMPONENT_NAME", "MAIN", "ERR_TYPE", "register failure", - "ERR_MSG", "Register a camera observer failed!"); + "ERR_MSG", "Register a hisysevent observer failed!"); } } -void ObserverManager::DisableCameraObserver() +void ObserverManager::DisableHiSysEventObserver() { - RESSCHED_LOGI("Disable camera observer"); - if (cameraObserver_ == nullptr) { + RESSCHED_LOGI("Disable hisysevent observer"); + if (hiSysEventObserver_ == nullptr) { return; } - auto res = HiviewDFX::HiSysEventManager::RemoveListener(cameraObserver_); + auto res = HiviewDFX::HiSysEventManager::RemoveListener(hiSysEventObserver_); if (res == 0) { - RESSCHED_LOGD("ObserverManager disable camera observer successfully"); + RESSCHED_LOGD("ObserverManager disable hisysevent observer successfully"); } else { - RESSCHED_LOGW("ObserverManager disable camera observer failed"); + RESSCHED_LOGW("ObserverManager disable hisysevent observer failed"); } - cameraObserver_ = nullptr; + hiSysEventObserver_ = nullptr; } void ObserverManager::InitTelephonyObserver() diff --git a/ressched/services/BUILD.gn b/ressched/services/BUILD.gn index e21f31d8..3c27f97a 100644 --- a/ressched/services/BUILD.gn +++ b/ressched/services/BUILD.gn @@ -51,7 +51,7 @@ ohos_shared_library("resschedsvc") { sources = [ "../sched_controller/common_event/src/event_controller.cpp", "../sched_controller/observer/src/audio_observer.cpp", - "../sched_controller/observer/src/camera_observer.cpp", + "../sched_controller/observer/src/hisysevent_observer.cpp", "../sched_controller/observer/src/observer_manager.cpp", "resschedmgr/resschedfwk/src/config_reader.cpp", "resschedmgr/resschedfwk/src/kill_process.cpp", @@ -76,6 +76,7 @@ ohos_shared_library("resschedsvc") { "audio_framework:audio_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "bluetooth:btframework", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -130,7 +131,7 @@ ohos_static_library("resschedsvc_static") { sources = [ "../sched_controller/common_event/src/event_controller.cpp", "../sched_controller/observer/src/audio_observer.cpp", - "../sched_controller/observer/src/camera_observer.cpp", + "../sched_controller/observer/src/hisysevent_observer.cpp", "../sched_controller/observer/src/observer_manager.cpp", "resschedmgr/resschedfwk/src/config_reader.cpp", "resschedmgr/resschedfwk/src/kill_process.cpp", @@ -155,6 +156,7 @@ ohos_static_library("resschedsvc_static") { "audio_framework:audio_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "bluetooth:btframework", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", -- Gitee From d031f60a776a7a058641fa9b202213e7b29e16a2 Mon Sep 17 00:00:00 2001 From: joseph Date: Tue, 24 Oct 2023 04:04:53 +0000 Subject: [PATCH 2/5] =?UTF-8?q?update=20ressched/sched=5Fcontroller/observ?= =?UTF-8?q?er/src/observer=5Fmanager.cpp.=20=E4=BF=AE=E6=94=B9codecheck?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: joseph --- ressched/sched_controller/observer/src/observer_manager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ressched/sched_controller/observer/src/observer_manager.cpp b/ressched/sched_controller/observer/src/observer_manager.cpp index 9a59ddc5..bc4877be 100644 --- a/ressched/sched_controller/observer/src/observer_manager.cpp +++ b/ressched/sched_controller/observer/src/observer_manager.cpp @@ -74,14 +74,16 @@ void ObserverManager::InitSysAbilityListener() } handleObserverMap_ = { - { DFX_SYS_EVENT_SERVICE_ABILITY_ID, std::bind(&ObserverManager::InitHiSysEventObserver, std::placeholders::_1) }, + { DFX_SYS_EVENT_SERVICE_ABILITY_ID, std::bind(&ObserverManager::InitHiSysEventObserver, + std::placeholders::_1) }, { TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID, std::bind(&ObserverManager::InitTelephonyObserver, std::placeholders::_1) }, { AUDIO_POLICY_SERVICE_ID, std::bind(&ObserverManager::InitAudioObserver, std::placeholders::_1) }, { MSDP_MOVEMENT_SERVICE_ID, std::bind(&ObserverManager::InitDeviceMovementObserver, std::placeholders::_1) } }; removeObserverMap_ = { - { DFX_SYS_EVENT_SERVICE_ABILITY_ID, std::bind(&ObserverManager::DisableHiSysEventObserver, std::placeholders::_1) }, + { DFX_SYS_EVENT_SERVICE_ABILITY_ID, std::bind(&ObserverManager::DisableHiSysEventObserver, + std::placeholders::_1) }, { TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID, std::bind(&ObserverManager::DisableTelephonyObserver, std::placeholders::_1) }, { AUDIO_POLICY_SERVICE_ID, std::bind(&ObserverManager::DisableAudioObserver, std::placeholders::_1) }, -- Gitee From f368acb487fe9a9a9bb81e95f220f5fa3f22bf65 Mon Sep 17 00:00:00 2001 From: joseph Date: Tue, 24 Oct 2023 04:07:43 +0000 Subject: [PATCH 3/5] =?UTF-8?q?update=20ressched/interfaces/innerkits/ress?= =?UTF-8?q?ched=5Fclient/include/res=5Ftype.h.=20=E4=BF=AE=E6=94=B9restype?= =?UTF-8?q?=E7=9A=84id=E6=8E=92=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: joseph --- .../innerkits/ressched_client/include/res_type.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ressched/interfaces/innerkits/ressched_client/include/res_type.h b/ressched/interfaces/innerkits/ressched_client/include/res_type.h index af68c064..091080e5 100644 --- a/ressched/interfaces/innerkits/ressched_client/include/res_type.h +++ b/ressched/interfaces/innerkits/ressched_client/include/res_type.h @@ -107,6 +107,11 @@ enum : uint32_t { RES_TYPE_SHOW_REMOTE_ANIMATION = 33, // load page; value 0: load page begin, value 1: load page end. RES_TYPE_LOAD_PAGE = 34, + // report camera state, value 0: camera connect; value 1: camera disconnect + RES_TYPE_REPORT_CAMERA_STATE = 35, + // report runningLock state, value 0: runningLock disable; value 1: runningLock enable; + // value 2: runningLock is proxied; value 3: runningLock is not proxied + RES_TYPE_RUNNINGLOCK_STATE = 36, // drag status bar event; value 0: start drag, value 1: stop drag. RES_TYPE_DRAG_STATUS_BAR = 37, // report SceneBoard service, value pid; payload:uid, main_tid, bundleName @@ -125,11 +130,6 @@ enum : uint32_t { RES_TYPE_LOAD_URL = 44, // mousewheel event; value means nothing. RES_TYPE_MOUSEWHEEL = 45, - // report camera state, value 0: camera connect; value 1: camera disconnect - RES_TYPE_REPORT_CAMERA_STATE = 46, - // report runningLock state, value 0: runningLock disable; value 1: runningLock enable; - // value 2: runningLock is proxied; value 3: runningLock is not proxied - RES_TYPE_RUNNINGLOCK_STATE = 47, }; inline const std::map resTypeToStr = { @@ -168,6 +168,8 @@ inline const std::map resTypeToStr = { { RES_TYPE_MOVE_WINDOW, "RES_TYPE_MOVE_WINDOW" }, { RES_TYPE_SHOW_REMOTE_ANIMATION, "RES_TYPE_SHOW_REMOTE_ANIMATION" }, { RES_TYPE_LOAD_PAGE, "RES_TYPE_LOAD_PAGE" }, + { RES_TYPE_REPORT_CAMERA_STATE, "RES_TYPE_REPORT_CAMERA_STATE" }, + { RES_TYPE_RUNNINGLOCK_STATE, "RES_TYPE_RUNNINGLOCK_STATE" }, { RES_TYPE_DRAG_STATUS_BAR, "RES_TYPE_DRAG_STATUS_BAR" }, { RES_TYPE_REPORT_SCENE_BOARD, "RES_TYPE_REPORT_SCENE_BOARD" }, { RES_TYPE_REPORT_KEY_THREAD, "RES_TYPE_REPORT_KEY_THREAD" }, @@ -176,9 +178,7 @@ inline const std::map resTypeToStr = { { RES_TYPE_WEB_GESTURE_MOVE, "RES_TYPE_WEB_GESTURE_MOVE" }, { RES_TYPE_WEB_SLIDE_NORMAL, "RES_TYPE_WEB_SLIDE_NORMAL" }, { RES_TYPE_LOAD_URL, "RES_TYPE_LOAD_URL" }, - { RES_TYPE_MOUSEWHEEL, "RES_TYPE_MOUSEWHEEL" }, - { RES_TYPE_REPORT_CAMERA_STATE, "RES_TYPE_REPORT_CAMERA_STATE" }, - { RES_TYPE_RUNNINGLOCK_STATE, "RES_TYPE_RUNNINGLOCK_STATE" } + { RES_TYPE_MOUSEWHEEL, "RES_TYPE_MOUSEWHEEL" } }; /** -- Gitee From 4afc0de8a7197507d8cc3a99edefbfa39e8ab3ac Mon Sep 17 00:00:00 2001 From: joseph Date: Tue, 24 Oct 2023 04:09:22 +0000 Subject: [PATCH 4/5] =?UTF-8?q?update=20ressched/services/BUILD.gn.=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9gn=E6=96=87=E4=BB=B6=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: joseph --- ressched/services/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ressched/services/BUILD.gn b/ressched/services/BUILD.gn index 3c27f97a..5bfe1e41 100644 --- a/ressched/services/BUILD.gn +++ b/ressched/services/BUILD.gn @@ -74,9 +74,9 @@ ohos_shared_library("resschedsvc") { "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "audio_framework:audio_client", + "bluetooth:btframework", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "bluetooth:btframework", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -154,9 +154,9 @@ ohos_static_library("resschedsvc_static") { "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "audio_framework:audio_client", + "bluetooth:btframework", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "bluetooth:btframework", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", -- Gitee From d25ea53b4ac48dcd8affad179be691677e91ba29 Mon Sep 17 00:00:00 2001 From: joseph Date: Wed, 25 Oct 2023 08:25:55 +0000 Subject: [PATCH 5/5] =?UTF-8?q?update=20ressched/sched=5Fcontroller/observ?= =?UTF-8?q?er/src/hisysevent=5Fobserver.cpp.=20=E4=BF=AE=E6=94=B9=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E8=A7=84=E8=8C=83=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: joseph --- ressched/sched_controller/observer/src/hisysevent_observer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ressched/sched_controller/observer/src/hisysevent_observer.cpp b/ressched/sched_controller/observer/src/hisysevent_observer.cpp index 5117293c..45a86d07 100755 --- a/ressched/sched_controller/observer/src/hisysevent_observer.cpp +++ b/ressched/sched_controller/observer/src/hisysevent_observer.cpp @@ -73,7 +73,7 @@ HiSysEventObserver::~HiSysEventObserver() bool HiSysEventObserver::CheckJsonValue(const nlohmann::json& value, std::initializer_list params) { - for (auto param : params) { + for (const auto& param : params) { if (value.find(param) == value.end()) { return false; } -- Gitee