1 /* 2 * Copyright (c) 2023-2025 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 HANDLEALLOCSOCKETFD_FUZZER_H 17 #define HANDLEALLOCSOCKETFD_FUZZER_H 18 19 #define FUZZ_PROJECT_NAME "handleallocsocketfd_fuzzer" 20 21 #include <memory> 22 #include <string> 23 24 #include <fcntl.h> 25 #include "nocopyable.h" 26 27 #include "cooperate_events.h" 28 #include "delegate_tasks.h" 29 #include "device_manager.h" 30 #include "devicestatus_define.h" 31 #include "devicestatus_delayed_sp_singleton.h" 32 #include "drag_manager.h" 33 #include "i_context.h" 34 #include "timer_manager.h" 35 #define private public 36 #include "devicestatus_service.h" 37 #include "fi_log.h" 38 #include "message_parcel.h" 39 #include "ddm_adapter.h" 40 #include "devicestatus_define.h" 41 42 #include "intention_service.h" 43 #include "socket_session_manager.h" 44 45 namespace OHOS { 46 namespace Msdp { 47 namespace DeviceStatus { 48 49 struct TimerInfo { 50 int32_t times { 0 }; 51 int32_t timerId { 0 }; 52 }; 53 54 class ContextService final : public IContext { 55 ContextService(); 56 ~ContextService(); 57 DISALLOW_COPY_AND_MOVE(ContextService); 58 public: 59 IDelegateTasks& GetDelegateTasks() override; 60 IDeviceManager& GetDeviceManager() override; 61 ITimerManager& GetTimerManager() override; 62 IDragManager& GetDragManager() override; 63 IDDMAdapter& GetDDM() override; 64 IPluginManager& GetPluginManager() override; 65 ISocketSessionManager& GetSocketSessionManager() override; 66 IInputAdapter& GetInput() override; 67 IDSoftbusAdapter& GetDSoftbus() override; 68 private: 69 void OnStart(); 70 void OnStop(); 71 bool Init(); 72 int32_t EpollCreate(); 73 int32_t AddEpoll(EpollEventType type, int32_t fd); 74 int32_t DelEpoll(EpollEventType type, int32_t fd); 75 int32_t EpollCtl(int32_t fd, int32_t op, struct epoll_event &event); 76 int32_t EpollWait(int32_t maxevents, int32_t timeout, struct epoll_event &events); 77 void EpollClose(); 78 int32_t InitTimerMgr(); 79 int32_t InitDevMgr(); 80 void OnThread(); 81 void OnTimeout(const epoll_event &ev); 82 void OnDeviceMgr(const epoll_event &ev); 83 int32_t EnableDevMgr(int32_t nRetries); 84 void DisableDevMgr(); 85 int32_t InitDelegateTasks(); 86 void OnDelegateTask(const struct epoll_event &ev); 87 static ContextService* GetInstance(); 88 private: 89 std::atomic<ServiceRunningState> state_ { ServiceRunningState::STATE_NOT_START }; 90 std::thread worker_; 91 DelegateTasks delegateTasks_; 92 DeviceManager devMgr_; 93 TimerManager timerMgr_; 94 std::atomic<bool> ready_ { false }; 95 DragManager dragMgr_; 96 int32_t epollFd_ { -1 }; 97 SocketSessionManager socketSessionMgr_; 98 std::unique_ptr<IDDMAdapter> ddm_; 99 std::unique_ptr<IInputAdapter> input_; 100 std::unique_ptr<IPluginManager> pluginMgr_; 101 std::unique_ptr<IDSoftbusAdapter> dsoftbusAda_; 102 }; 103 } // namespace DeviceStatus 104 } // namespace Msdp 105 } // namespace OHOS 106 #endif // HANDLEALLOCSOCKETFD_FUZZER_H