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 #ifndef RESSCHED_SCHED_CONTROLLER_COMMON_EVENT_INCLUDE_EVENT_CONTROLLER_H 17 #define RESSCHED_SCHED_CONTROLLER_COMMON_EVENT_INCLUDE_EVENT_CONTROLLER_H 18 19 #include "common_event_subscriber.h" 20 #include "nlohmann/json.hpp" 21 #include "system_ability_status_change_stub.h" 22 23 #include "single_instance.h" 24 25 namespace OHOS { 26 namespace ResourceSchedule { 27 class EventController : public EventFwk::CommonEventSubscriber { 28 DECLARE_SINGLE_INSTANCE_BASE(EventController); 29 30 public: EventController(const EventFwk::CommonEventSubscribeInfo & subscriberInfo)31 EventController(const EventFwk::CommonEventSubscribeInfo &subscriberInfo) 32 : CommonEventSubscriber(subscriberInfo) {} EventController()33 EventController() {} ~EventController()34 ~ EventController() {} 35 36 virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); 37 void Init(); 38 void Stop(); 39 40 uint32_t resType_ = 0; 41 int64_t value_ = 0; 42 nlohmann::json payload_; 43 44 private: 45 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 46 public: SystemAbilityStatusChangeListener()47 SystemAbilityStatusChangeListener() {}; 48 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 49 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 50 void Stop(); 51 52 private: 53 std::shared_ptr<EventController> subscriber_ = nullptr; 54 }; 55 56 void HandleConnectivityChange(const EventFwk::Want &want, const int32_t &code, nlohmann::json &payload); 57 void HandlePkgAddRemove(const EventFwk::Want &want, nlohmann::json &payload) const; 58 int32_t GetUid(const int32_t &userId, const std::string &bundleName) const; 59 void ReportDataInProcess(const uint32_t &resType, const int64_t &value, const nlohmann::json& payload); 60 61 sptr<SystemAbilityStatusChangeListener> sysAbilityListener_ = nullptr; 62 }; 63 } // namespace ResourceSchedule 64 } // namespace OHOS 65 #endif // RESSCHED_SCHED_CONTROLLER_COMMON_EVENT_INCLUDE_EVENT_CONTROLLER_H