1 /* 2 * Copyright (c) 2023 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 EVENT_HUB_H 17 #define EVENT_HUB_H 18 19 #include <string> 20 #include <vector> 21 22 #include "common_event_manager.h" 23 #include "common_event_support.h" 24 #include "iservice_registry.h" 25 #include "refbase.h" 26 #include "system_ability_definition.h" 27 #include "system_ability_status_change_stub.h" 28 29 #include "i_context.h" 30 31 namespace OHOS { 32 namespace Msdp { 33 namespace DeviceStatus { 34 enum class EventId { 35 EVENT_APP_RUN_FRONT = 1, 36 EVENT_SCREEN_ON, 37 EVENT_SCREEN_OFF, 38 EVENT_SCREEN_LOCK, 39 EVENT_SCREEN_UNLOCK, 40 EVENT_BATTERY_LOW, 41 EVENT_BATTERY_OKAY, 42 EVENT_MAX, 43 }; 44 class EventHub : public OHOS::EventFwk::CommonEventSubscriber { 45 public: EventHub(const OHOS::EventFwk::CommonEventSubscribeInfo & info,IContext * context)46 EventHub(const OHOS::EventFwk::CommonEventSubscribeInfo &info, IContext* context) 47 : CommonEventSubscriber(info), context_(context) {} 48 ~EventHub() override = default; 49 50 static std::shared_ptr<EventHub> GetEventHub(IContext* context); 51 static void RegisterEvent(std::shared_ptr<EventHub> eventHub); 52 static void UnRegisterEvent(std::shared_ptr<EventHub> eventHub); 53 54 void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &event) override; 55 56 private: 57 IContext* context_ { nullptr }; 58 }; 59 class DragAbilityStatusChange : public SystemAbilityStatusChangeStub { 60 public: 61 explicit DragAbilityStatusChange(std::shared_ptr<EventHub> eventHub); 62 ~DragAbilityStatusChange() = default; 63 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 64 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 65 66 private: 67 std::shared_ptr<EventHub> eventHub_ { nullptr }; 68 }; 69 } // namespace DeviceStatus 70 } // namespace Msdp 71 } // namespace OHOS 72 #endif // EVENT_HUB_H