/* * Copyright (c) 2021-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. */ #ifndef USB_FUNCTION_MANAGER_H #define USB_FUNCTION_MANAGER_H #include #include #include #include "timer.h" #include "usb_common.h" #include "usb_function_switch_window.h" #include "usb_srv_support.h" #include "v1_0/iusb_interface.h" #include "v1_0/iusbd_subscriber.h" #define USB_FUNCTION_MTP (1 << 3) #define USB_FUNCTION_PTP (1 << 4) #define USB_FUNCTION_STORAGE (1 << 9) namespace OHOS { namespace USB { class UsbDeviceManager { public: UsbDeviceManager(); ~UsbDeviceManager(); int32_t Init(); static bool AreSettableFunctions(int32_t funcs); int32_t SetUsbd(const sptr &usbd); static uint32_t ConvertFromString(std::string_view funcs); static std::string ConvertToString(uint32_t func); void UpdateFunctions(int32_t func); int32_t GetCurrentFunctions(); void HandleEvent(int32_t status); void GetDumpHelp(int32_t fd); void Dump(int32_t fd, const std::vector &args); bool IsGadgetConnected(void); int32_t UserChangeProcess(); private: void ProcessFunctionSwitchWindow(bool connected); void DumpGetSupportFunc(int32_t fd); void DumpSetFunc(int32_t fd, const std::string &args); void ReportFuncChangeSysEvent(int32_t currentFunctions, int32_t updateFunctions); void ReportDevicePlugSysEvent(int32_t currentFunctions, bool connected); void ProcessFuncChange(bool connected, int32_t currentFunc); void BroadcastFuncChange(bool connected, int32_t currentFunc); static constexpr uint32_t functionSettable_ = UsbSrvSupport::FUNCTION_HDC | UsbSrvSupport::FUNCTION_ACM | UsbSrvSupport::FUNCTION_ECM | UsbSrvSupport::FUNCTION_MTP | UsbSrvSupport::FUNCTION_PTP | UsbSrvSupport::FUNCTION_RNDIS | UsbSrvSupport::FUNCTION_STORAGE; static const std::map FUNCTION_MAPPING_N2C; int32_t currentFunctions_ {UsbSrvSupport::FUNCTION_HDC}; bool connected_ {false}; bool gadgetConnected_ {false}; sptr usbd_ = nullptr; Utils::Timer delayDisconn_ {"delayDisconnTimer"}; uint32_t delayDisconnTimerId_ {UINT32_MAX}; }; } // namespace USB } // namespace OHOS #endif // USB_FUNCTION_MANAGER_H