diff --git a/bundle.json b/bundle.json index 30d7336b2f3adc69229370dcdba3e466ea3d503f..885de4b30e4650fbf80017cb8b9480c56f122107 100644 --- a/bundle.json +++ b/bundle.json @@ -52,7 +52,8 @@ "relational_store", "drivers_interface_input", "cJSON", - "selinux_adapter" + "selinux_adapter", + "hdf_core" ] }, "build": { diff --git a/frameworks/ddk/usb/BUILD.gn b/frameworks/ddk/usb/BUILD.gn index c9c120936c1448fa71d87a4ab882a3f348a633b4..5cb0401583a798237679529388271294c3e25c84 100644 --- a/frameworks/ddk/usb/BUILD.gn +++ b/frameworks/ddk/usb/BUILD.gn @@ -31,7 +31,7 @@ ohos_shared_library("usb_ndk") { external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_ddk_proxy_1.1", + "drivers_interface_usb:libusb_ddk_proxy_1.2", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index c5ed9efc8b9b283305a4eb2fc462cba489b15b08..061a4fde74dd6a00b66bffa7d8d9b10fa3cca6bf 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -57,7 +57,7 @@ ohos_shared_library("driver_ext_mgr_client") { ohos_source_set("external_device_manager_stub") { public_configs = [ ":ext_dvc_mgr_public_config" ] output_values = get_target_outputs(":external_device_manager_interface") - sources = filter_include(output_values, [ "*mgr_stub.cpp" ]) + sources = filter_include(output_values, [ "*mgr_stub.cpp", "*event_listener_stub.cpp" ]) sources += filter_include(output_values, [ "*callback_proxy.cpp" ]) deps = [ ":external_device_manager_interface" ] diff --git a/interfaces/innerkits/IDriverExtMgr.idl b/interfaces/innerkits/IDriverExtMgr.idl index 7633d12863cfa01701ee3fd6a11fb75afe4c464d..334917f901d4780780f8775c9c3549c59d2c6515 100644 --- a/interfaces/innerkits/IDriverExtMgr.idl +++ b/interfaces/innerkits/IDriverExtMgr.idl @@ -27,4 +27,4 @@ interface OHOS.ExternalDeviceManager.IDriverExtMgr { void UnBindDriverWithDeviceId([out] int errorCode, [in] unsigned long deviceId); void QueryDeviceInfo([out] int errorCode, [out] sharedptr[] deviceInfos, [in] boolean isByDeviceId, [in] unsigned long deviceId); void QueryDriverInfo([out] int errorCode, [out] sharedptr[] driverInfos, [in] boolean isByDriverUid, [in] String driverUid); -} \ No newline at end of file +} diff --git a/services/BUILD.gn b/services/BUILD.gn index 3cbf50892043d60b96ec3ce596b10fe53f1290b6..bf3632b3d7ad10437ccbdf88692add9d744343fe 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -18,6 +18,8 @@ ohos_shared_library("driver_extension_manager") { sources = [ "${ext_mgr_path}/services/native/driver_extension_manager/src/driver_ext_mgr_types.cpp", "native/driver_extension_manager/src/driver_ext_mgr.cpp", + "native/driver_extension_manager/src//hisysevent_usb_listener.cpp", + "native/driver_extension_manager/src/event_listener_impl.cpp", "native/driver_extension_manager/src/ext_permission_manager.cpp", ] @@ -53,6 +55,9 @@ ohos_shared_library("driver_extension_manager") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "drivers_interface_usb:libusb_ddk_proxy_1.2", + "hdf_core:libhdi", + "hisysevent:libhisyseventmanager", ] cflags_cc = [ "-fno-asynchronous-unwind-tables", @@ -121,7 +126,9 @@ ohos_static_library("driver_extension_manager_test") { "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "samgr:samgr_proxy", + "samgr:samgr_proxy", + "drivers_interface_usb:libusb_ddk_proxy_1.2", + "hisysevent:libhisyseventmanager", ] subsystem_name = "hdf" diff --git a/services/native/driver_extension_manager/include/driver_ext_mgr.h b/services/native/driver_extension_manager/include/driver_ext_mgr.h index 330029274468382dff20d6913a732ca2621f142a..f9fbd65423bb1bae4f636e7cdf896b6c4b9bd696 100644 --- a/services/native/driver_extension_manager/include/driver_ext_mgr.h +++ b/services/native/driver_extension_manager/include/driver_ext_mgr.h @@ -58,6 +58,7 @@ private: bool accountPromiseUsed_ = false; bool cesPromiseUsed_ = false; std::map>> connectCallbackMap; + int initFault(); }; } // namespace ExternalDeviceManager } // namespace OHOS diff --git a/services/native/driver_extension_manager/include/event_listener_impl.h b/services/native/driver_extension_manager/include/event_listener_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..8949cfc72002771a098381efb1786b8435638861 --- /dev/null +++ b/services/native/driver_extension_manager/include/event_listener_impl.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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 EVENT_LISTENER_IMPL_H +#define EVENT_LISTENER_IMPL_H +#include "refbase.h" +#include "v1_2/ievent_listener.h" + +namespace OHOS { +namespace ExternalDeviceManager { +class EventListenerImpl : public OHOS::HDI::Usb::Ddk::V1_2::IEventListener { +public: + EventListenerImpl() = default; + ~EventListenerImpl() override = default; + int32_t OnEvent(const OHOS::HDI::Usb::Ddk::V1_2::Event& event) override; + +private: + //std::shared_ptr eventI_; +}; +} +} +#endif // SELECTION_LISTENER_IMPL_H \ No newline at end of file diff --git a/services/native/driver_extension_manager/include/hisysevent_usb_listener.h b/services/native/driver_extension_manager/include/hisysevent_usb_listener.h new file mode 100644 index 0000000000000000000000000000000000000000..aa0394cac085efb48b132634a1c8d96ed374964b --- /dev/null +++ b/services/native/driver_extension_manager/include/hisysevent_usb_listener.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021-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. + */ + +#ifndef HISYSEVENT_USB_LISTENER_H +#define HISYSEVENT_USB_LISTENER_H + +#include "hisysevent_listener.h" +#include + +class HiSysEventUsbListener : public OHOS::HiviewDFX::HiSysEventListener { +public: + HiSysEventUsbListener(); + ~HiSysEventUsbListener(); + +public: + virtual void OnEvent(std::shared_ptr sysEvent) override; + virtual void OnServiceDied() override; +}; + +#endif // HISYSEVENT_USB_LISTENER_H diff --git a/services/native/driver_extension_manager/src/bus_extension/core/bus_extension_core.cpp b/services/native/driver_extension_manager/src/bus_extension/core/bus_extension_core.cpp index 2a2affd6f12a3b9ebdd7a2f3f98d0a9095097981..541120643411798ecc76b7600609c0cf18d3cbe8 100644 --- a/services/native/driver_extension_manager/src/bus_extension/core/bus_extension_core.cpp +++ b/services/native/driver_extension_manager/src/bus_extension/core/bus_extension_core.cpp @@ -71,9 +71,9 @@ int32_t BusExtensionCore::Init(std::shared_ptr callback) for (auto &iter : busExtensions_) { if (iter.second->SetDevChangeCallback(callback) != EDM_OK) { ret = EDM_NOK; - EDM_LOGE(MODULE_DEV_MGR, "busExtension init failed, busType is %{public}d", iter.first); + EDM_LOGE(MODULE_DEV_MGR, "[wjg] busExtension init failed, busType is %{public}d", iter.first); } - EDM_LOGD(MODULE_DEV_MGR, "busExtension init successfully, busType is %{public}d", iter.first); + EDM_LOGD(MODULE_DEV_MGR, "[wjg] busExtension init successfully, busType is %{public}d", iter.first); } return ret; } diff --git a/services/native/driver_extension_manager/src/bus_extension/usb/BUILD.gn b/services/native/driver_extension_manager/src/bus_extension/usb/BUILD.gn index 330207f01fcad3b4be547723424302ce8ec0df5b..dda0d3ae359197111e9998885c87c623b158a431 100644 --- a/services/native/driver_extension_manager/src/bus_extension/usb/BUILD.gn +++ b/services/native/driver_extension_manager/src/bus_extension/usb/BUILD.gn @@ -41,7 +41,7 @@ ohos_shared_library("driver_extension_usb_bus") { external_deps = [ "cJSON:cjson", "c_utils:utils", - "drivers_interface_usb:libusb_ddk_proxy_1.1", + "drivers_interface_usb:libusb_ddk_proxy_1.2", "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp b/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp index 0f2f7df6322147d94064e504d05ceb4497715efb..4194af20f23eafe1112b69e3e321729c15da7608 100644 --- a/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp +++ b/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp @@ -64,22 +64,26 @@ void UsbBusExtension::SetUsbInferface(sptr iusb) #else void UsbBusExtension::SetUsbInferface(sptr iusb) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension SetUsbInferface enter"); this->usbInterface_ = iusb; } #endif // EXTDEVMGR_USB_PASS_THROUGH void UsbBusExtension::SetUsbDdk(sptr iUsbDdk) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension SetUsbDdk enter"); this->iUsbDdk_ = iUsbDdk; } BusType UsbBusExtension::GetBusType() { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension GetBusType enter"); return BusType::BUS_TYPE_USB; } shared_ptr UsbBusExtension::AcquireDriverChangeCallback() { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension AcquireDriverChangeCallback enter"); if (this->iUsbDdk_ == nullptr) { this->iUsbDdk_ = V1_1::IUsbDdk::Get(); if (this->iUsbDdk_ == nullptr) { @@ -93,6 +97,7 @@ shared_ptr UsbBusExtension::AcquireDriverChangeCallback() int32_t UsbBusExtension::SetDevChangeCallback(shared_ptr devCallback) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension SetDevChangeCallback enter"); #ifdef EXTDEVMGR_USB_PASS_THROUGH if (this->usbInterface_ == nullptr) { this->usbInterface_ = IUsbHostInterface::Get(SERVICE_NAME, true); @@ -147,6 +152,7 @@ int32_t UsbBusExtension::SetDevChangeCallback(shared_ptr dev bool UsbBusExtension::MatchDriver(const DriverInfo &driver, const DeviceInfo &device, const std::string &type) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension MatchDriver enter"); if (LowerStr(driver.GetBusName()) != "usb") { EDM_LOGW(MODULE_BUS_USB, "driver bus not support by this module [UsbBusExtension]"); return false; @@ -181,6 +187,7 @@ bool UsbBusExtension::MatchDriver(const DriverInfo &driver, const DeviceInfo &de shared_ptr UsbBusExtension::ParseDriverInfo(const map &metadata) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension ParseDriverInfo enter"); shared_ptr usbDriverInfo = make_shared(); if (usbDriverInfo == nullptr) { EDM_LOGE(MODULE_BUS_USB, "creat UsbDriverInfo obj fail\n"); @@ -198,6 +205,7 @@ shared_ptr UsbBusExtension::ParseDriverInfo(const map UsbBusExtension::ParseCommaStrToVectorUint16(const string &str) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension ParseCommaStrToVectorUint16 enter"); vector ret; stringstream ss(str); string s; @@ -219,6 +227,7 @@ vector UsbBusExtension::ParseCommaStrToVectorUint16(const string &str) #ifndef EXTDEVMGR_USB_PASS_THROUGH void UsbBusExtension::UsbdDeathRecipient::OnRemoteDied(const wptr &object) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension OnRemoteDied enter"); auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgrProxy == nullptr) { EDM_LOGE(MODULE_BUS_USB, "get samgr failed"); @@ -234,11 +243,13 @@ void UsbBusExtension::UsbdDeathRecipient::OnRemoteDied(const wptr shared_ptr UsbBusExtension::GetNewDriverInfoExtObject() { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbBusExtension GetNewDriverInfoExtObject enter"); return make_shared(); } __attribute__ ((constructor)) static void RegBusExtension() { + EDM_LOGE(MODULE_COMMON, "[wjg] RegBusExtension enter"); EDM_LOGI(MODULE_COMMON, "installing UsbBusExtension"); RegisterBusExtension(BusType::BUS_TYPE_USB); } diff --git a/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp b/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp index ccc10e6d905fd58247b437cef4416c435ef2759c..4e4acf96b5923f98e907ea12d2935af3bef00634 100644 --- a/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp +++ b/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp @@ -85,6 +85,7 @@ void UsbDevSubscriber::Init(shared_ptr callback, sptr callback, sptr iusb, sptr iUsbDdk) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbDevSubscriber Init enter"); this->iusb_ = iusb; this->callback_ = callback; this->iUsbDdk_ = iUsbDdk; @@ -94,6 +95,7 @@ void UsbDevSubscriber::Init(shared_ptr callback, sptr &interfaceList) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] GetInterfaceDescriptor enter"); int32_t ret = EDM_NOK; if (this->iusb_ == nullptr || this->iUsbDdk_ == nullptr) { return EDM_ERR_INVALID_OBJECT; @@ -139,6 +141,7 @@ int32_t UsbDevSubscriber::GetInterfaceDescriptor(const UsbDev &usbDev, int32_t UsbDevSubscriber::OnDeviceConnect(const UsbDev &usbDev) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] OnDeviceConnect enter"); std::shared_ptr extDevEvent = std::make_shared(__func__, GET_DEVICE_INFO, ToExtDevId(usbDev)); int32_t ret = 0; @@ -190,6 +193,7 @@ int32_t UsbDevSubscriber::OnDeviceConnect(const UsbDev &usbDev) int32_t UsbDevSubscriber::OnDeviceDisconnect(const UsbDev &usbDev) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] OnDeviceDisconnect enter"); EDM_LOGD(MODULE_BUS_USB, "OnDeviceDisconnect enter"); std::string interfaceName = std::string(__func__); if (this->callback_ != nullptr) { @@ -206,6 +210,7 @@ int32_t UsbDevSubscriber::OnDeviceDisconnect(const UsbDev &usbDev) int32_t UsbDevSubscriber::DeviceEvent(const USBDeviceInfo &usbDevInfo) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] DeviceEvent enter"); EDM_LOGD(MODULE_BUS_USB, "DeviceEvent enter"); UsbDev usbDev = {usbDevInfo.busNum, usbDevInfo.devNum}; int32_t ret = 0; @@ -221,11 +226,13 @@ int32_t UsbDevSubscriber::DeviceEvent(const USBDeviceInfo &usbDevInfo) int32_t UsbDevSubscriber::PortChangedEvent(const PortInfo &usbDevInfo) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbDevSubscriber PortChangedEvent enter"); return 0; } std::string UsbDevSubscriber::GetDevStringVal(const UsbDev &usbDev, uint8_t idx) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbDevSubscriber GetDevStringVal enter"); std::string strDesc = " "; std::vector serial; @@ -267,6 +274,7 @@ std::string UsbDevSubscriber::GetDevStringVal(const UsbDev &usbDev, uint8_t idx) void UsbDevSubscriber::SetUsbDevInfoValue(const UsbDevDescLite &deviceDescriptor, shared_ptr &usbDevInfo, std::string snNum) { + EDM_LOGE(MODULE_BUS_USB, "[wjg] UsbDevSubscriber SetUsbDevInfoValue enter"); usbDevInfo->bcdUSB_ = deviceDescriptor.bcdUSB; usbDevInfo->idProduct_ = deviceDescriptor.idProduct; usbDevInfo->idVendor_ = deviceDescriptor.idVendor; diff --git a/services/native/driver_extension_manager/src/driver_ext_mgr.cpp b/services/native/driver_extension_manager/src/driver_ext_mgr.cpp index 334346abec71d8498237bf7bf4af2394881d8965..8dcaa4e057a7d89bb07d13e1383aeb3c2d01a068 100644 --- a/services/native/driver_extension_manager/src/driver_ext_mgr.cpp +++ b/services/native/driver_extension_manager/src/driver_ext_mgr.cpp @@ -28,6 +28,14 @@ #include "system_ability_definition.h" #include "usb_device_info.h" #include "usb_driver_info.h" +#include "v1_2/usb_ddk_service.h" +#include "v1_2/event_listener_stub.h" +#include "event_listener_impl.h" +#include +#include "hisysevent.h" +#include +#include "hisysevent_manager.h" +#include "hisysevent_usb_listener.h" namespace OHOS { namespace ExternalDeviceManager { @@ -41,8 +49,24 @@ DriverExtMgr::~DriverExtMgr() {} void DriverExtMgr::OnStart() { + EDM_LOGI(MODULE_SERVICE, "[wjg] %{public}s enter. test lhb ", __func__); + + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::HDF_USB, "TRANSPORT_FAULT", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, + "ERROR_DESC", "desc", "ERROR_CODE", 0, "OVER_TIME", 1000000000000000); + + auto g_ddk = OHOS::HDI::Usb::Ddk::V1_2::IUsbDdk::Get(); + if (g_ddk == nullptr) { + EDM_LOGI(MODULE_SERVICE, "[wjg] %{public}s g_ddk is null", __func__); + } + auto impl = sptr::MakeSptr(); + int32_t success = g_ddk->RegisterListener(impl); + EDM_LOGI(MODULE_SERVICE, "[wjg] V1_2 %{public}s. register result:%{public}d ", __func__, success); + if (success != USB_DDK_SUCCESS) { + EDM_LOGE(MODULE_USB_DDK, "%{public}s: register listener failed", __func__); + } + int32_t ret; - EDM_LOGI(MODULE_SERVICE, "hdf_ext_devmgr OnStart"); + EDM_LOGI(MODULE_SERVICE, "hdf_ext_devmgr LoadBusExtensionLibs"); BusExtensionCore::GetInstance().LoadBusExtensionLibs(); std::shared_ptr driverChangeCallback = BusExtensionCore::GetInstance().AcquireDriverChangeCallback(BUS_TYPE_USB); @@ -67,10 +91,40 @@ void DriverExtMgr::OnStart() EDM_LOGE(MODULE_DEV_MGR, "OnStart register to system ability manager failed."); return; } + initFault(); + // TODO: 参考: OH_Usb_Init, OH_Usb_GetDevices +} + +int DriverExtMgr::initFault() +{ + EDM_LOGE(MODULE_SERVICE,"[wjg] %{public}s: start1", __func__); + auto manager = std::make_shared(); + if (manager == nullptr) { + EDM_LOGE(MODULE_SERVICE,"[wjg] Failed to create HiSysEventManager"); + return HDF_FAILURE; + } + EDM_LOGE(MODULE_SERVICE,"[wjg] %{public}s: start2", __func__); + OHOS::HiviewDFX::ListenerRule rule(OHOS::HiviewDFX::HiSysEvent::Domain::HDF_USB, "TRANSPORT_FAULT", + "TRANSPORT_FAULT", OHOS::HiviewDFX::RuleType::PREFIX, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); + std::vector rules = {rule}; + EDM_LOGE(MODULE_SERVICE,"[wjg] %{public}s: start3", __func__); + + EDM_LOGE(MODULE_SERVICE,"[wjg] %{public}s: start4", __func__); + auto listener = std::make_shared(); + if (listener == nullptr) { + EDM_LOGE(MODULE_SERVICE,"[wjg] Failed to create listener"); + return HDF_FAILURE; + } + EDM_LOGE(MODULE_SERVICE,"[wjg] %{public}s: start5", __func__); + //auto result = manager->AddListener(listener, rules); + //EDM_LOGE(MODULE_SERVICE,"[wjg] %{public}s result:%{public}d start6", __func__, result); + + return 0; } void DriverExtMgr::OnStop() { + EDM_LOGI(MODULE_SERVICE, "[wjg] %{public}s enter", __func__); EDM_LOGI(MODULE_SERVICE, "hdf_ext_devmgr OnStop"); } @@ -81,6 +135,7 @@ int DriverExtMgr::Dump(int fd, const std::vector &args) void DriverExtMgr::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { + EDM_LOGI(MODULE_SERVICE, "[wjg] %{public}s enter", __func__); EDM_LOGI(MODULE_SERVICE, "OnAddSystemAbility systemAbilityId: %{public}d", systemAbilityId); std::lock_guard lock(promiseMutex_); switch (systemAbilityId) { @@ -118,6 +173,7 @@ void DriverExtMgr::OnAddSystemAbility(int32_t systemAbilityId, const std::string ErrCode DriverExtMgr::QueryDevice(int32_t &errorCode, uint32_t busType, std::vector> &devices) { + EDM_LOGI(MODULE_DEV_MGR, "[wjg] %{public}s enter", __func__); if (!ExtPermissionManager::VerifyPermission(PERMISSION_NAME)) { EDM_LOGE(MODULE_DEV_MGR, "%{public}s no permission", __func__); errorCode = static_cast(UsbErrCode::EDM_ERR_NO_PERM); @@ -157,7 +213,7 @@ ErrCode DriverExtMgr::QueryDevice(int32_t &errorCode, uint32_t busType, ErrCode DriverExtMgr::BindDevice(int32_t &errorCode, uint64_t deviceId, const sptr &connectCallback) { - EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); + EDM_LOGI(MODULE_DEV_MGR, "[wjg] %{public}s enter", __func__); if (!ExtPermissionManager::VerifyPermission(PERMISSION_NAME)) { EDM_LOGE(MODULE_DEV_MGR, "%{public}s no permission", __func__); errorCode = static_cast(UsbErrCode::EDM_ERR_NO_PERM); @@ -177,7 +233,7 @@ ErrCode DriverExtMgr::BindDevice(int32_t &errorCode, uint64_t deviceId, ErrCode DriverExtMgr::UnBindDevice(int32_t &errorCode, uint64_t deviceId) { - EDM_LOGD(MODULE_DEV_MGR, "%{public}s enter", __func__); + EDM_LOGD(MODULE_DEV_MGR, "[wjg] %{public}s enter", __func__); if (!ExtPermissionManager::VerifyPermission(PERMISSION_NAME)) { EDM_LOGE(MODULE_DEV_MGR, "%{public}s no permission", __func__); errorCode = static_cast(UsbErrCode::EDM_ERR_NO_PERM); @@ -193,7 +249,7 @@ ErrCode DriverExtMgr::UnBindDevice(int32_t &errorCode, uint64_t deviceId) ErrCode DriverExtMgr::BindDriverWithDeviceId(int32_t &errorCode, uint64_t deviceId, const sptr &connectCallback) { - EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); + EDM_LOGI(MODULE_DEV_MGR, "[wjg] %{public}s enter", __func__); if (!ExtPermissionManager::VerifyPermission(ACCESS_DDK_DRIVERS_PERMISSION)) { EDM_LOGE(MODULE_DEV_MGR, "%{public}s no permission", __func__); errorCode = static_cast(UsbErrCode::EDM_ERR_NO_PERM); @@ -214,7 +270,7 @@ ErrCode DriverExtMgr::BindDriverWithDeviceId(int32_t &errorCode, uint64_t device ErrCode DriverExtMgr::UnBindDriverWithDeviceId(int32_t &errorCode, uint64_t deviceId) { - EDM_LOGD(MODULE_DEV_MGR, "%{public}s enter", __func__); + EDM_LOGD(MODULE_DEV_MGR, "[wjg] %{public}s enter", __func__); if (!ExtPermissionManager::VerifyPermission(ACCESS_DDK_DRIVERS_PERMISSION)) { EDM_LOGE(MODULE_DEV_MGR, "%{public}s no permission", __func__); errorCode = static_cast(UsbErrCode::EDM_ERR_NO_PERM); @@ -229,7 +285,7 @@ ErrCode DriverExtMgr::UnBindDriverWithDeviceId(int32_t &errorCode, uint64_t devi static std::shared_ptr ParseToDeviceInfoData(const std::shared_ptr &device) { - EDM_LOGD(MODULE_DEV_MGR, "%{public}s enter", __func__); + EDM_LOGD(MODULE_DEV_MGR, "[wjg] %{public}s enter", __func__); if (device == nullptr || device->GetDeviceInfo() == nullptr) { EDM_LOGD(MODULE_DEV_MGR, "device or deviceInfo is null"); return nullptr; @@ -277,7 +333,7 @@ static std::shared_ptr ParseToDeviceInfoData(const std::shared_p static std::shared_ptr ParseToDriverInfoData(const std::shared_ptr &driverInfo) { - EDM_LOGD(MODULE_DEV_MGR, "%{public}s enter", __func__); + EDM_LOGD(MODULE_DEV_MGR, "[wjg] %{public}s enter", __func__); if (driverInfo == nullptr || driverInfo->GetInfoExt() == nullptr) { EDM_LOGD(MODULE_DEV_MGR, "driverInfo or extInfo is null"); return nullptr; @@ -316,7 +372,7 @@ static std::shared_ptr ParseToDriverInfoData(const std::shared_p ErrCode DriverExtMgr::QueryDeviceInfo(int32_t &errorCode, std::vector> &deviceInfos, bool isByDeviceId, const uint64_t deviceId) { - EDM_LOGD(MODULE_DEV_MGR, "%{public}s enter", __func__); + EDM_LOGD(MODULE_DEV_MGR, "[wjg] %{public}s enter", __func__); if (!ExtPermissionManager::IsSystemApp()) { EDM_LOGE(MODULE_DEV_MGR, "%{public}s none system app", __func__); errorCode = static_cast(UsbErrCode::EDM_ERR_NOT_SYSTEM_APP); diff --git a/services/native/driver_extension_manager/src/event_listener_impl.cpp b/services/native/driver_extension_manager/src/event_listener_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bf9b289ecd5dcc523ede5feeecdbd5bacc5cc047 --- /dev/null +++ b/services/native/driver_extension_manager/src/event_listener_impl.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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 "event_listener_impl.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace ExternalDeviceManager { +int32_t EventListenerImpl::OnEvent(const OHOS::HDI::Usb::Ddk::V1_2::Event& event) +{ + EDM_LOGI(MODULE_SERVICE, "[wjg] %{public}s enter.Recveive event name: %{public}s,domain name: %{public}s", __func__, event.name.c_str(), event.domain.c_str()); +// if (event == nullptr) { +// EDM_LOGE(MODULE_SERVICE, "[wjg] device is null"); +// return; +// } + + //eventI_->OnEventChanged(eventInfo); + return 0; +} +} + +} // namespace OHOS \ No newline at end of file diff --git a/services/native/driver_extension_manager/src/hisysevent_usb_listener.cpp b/services/native/driver_extension_manager/src/hisysevent_usb_listener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc986b219b88b20b9d6d26ca107561c359c350d9 --- /dev/null +++ b/services/native/driver_extension_manager/src/hisysevent_usb_listener.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-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 "hisysevent_usb_listener.h" + +#include +#include +#include +#include +#include +#include +#include + +HiSysEventUsbListener::HiSysEventUsbListener() {} + +HiSysEventUsbListener::~HiSysEventUsbListener() {} + +void HiSysEventUsbListener::OnEvent(std::shared_ptr sysEvent) +{ + if (sysEvent == nullptr) { + return; + } + +} + +void HiSysEventUsbListener::OnServiceDied() {} diff --git a/test/moduletest/bus_extension_usb_mt/bus_extension_usb_mt.cpp b/test/moduletest/bus_extension_usb_mt/bus_extension_usb_mt.cpp index f37727f2f5aee909178e264244322cadf8d25e12..fa3d5ba1b268a63a7e156f669b2478037fd0798b 100644 --- a/test/moduletest/bus_extension_usb_mt/bus_extension_usb_mt.cpp +++ b/test/moduletest/bus_extension_usb_mt/bus_extension_usb_mt.cpp @@ -66,6 +66,8 @@ public: TestDevChangeCallback() { }; int32_t OnDeviceAdd(shared_ptr device) override { + EDM_LOGE(MODULE_COMMON, "[wjg] OnDeviceAdd: Id = %{public}016" PRIx64 ", Desc = %{public}s", + device->GetDeviceId(), device->GetDeviceDescription().c_str()); devInfoMap_[device->GetDeviceId()] = device; EDM_LOGI(MODULE_COMMON, "OnDeviceAdd: Id = %{public}016" PRIx64 ", Desc = %{public}s", device->GetDeviceId(), device->GetDeviceDescription().c_str()); @@ -74,6 +76,8 @@ public: }; int32_t OnDeviceRemove(shared_ptr device) override { + EDM_LOGE(MODULE_COMMON, "[wjg] OnDeviceRemove: Id = %{public}016" PRIx64 ", Desc = %{public}s", + device->GetDeviceId(), device->GetDeviceDescription().c_str()); devInfoMap_.erase(device->GetDeviceId()); EDM_LOGI(MODULE_COMMON, "OnDeviceRemove: Id = %{public}016" PRIx64 ", Desc = %{public}s", device->GetDeviceId(), device->GetDeviceDescription().c_str()); @@ -82,6 +86,7 @@ public: }; void PrintAllDevice(void) { + EDM_LOGE(MODULE_COMMON, "[wjg] PrintAllDevice"); cout << "++++++++, all usb device, count = " << devInfoMap_.size() << " detail:" << endl; for (auto &devItem : devInfoMap_) { cout << devItem.second->GetDeviceDescription().c_str() << endl; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9058bad4015c5cdda0f999ab5e51b7ad7d29d5d9..f58b4dec0d791f87730995ea6b05fd7671b3a945 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -46,7 +46,7 @@ ohos_unittest("bus_extension_usb_test") { "bundle_framework:appexecfwk_base", "cJSON:cjson", "c_utils:utils", - "drivers_interface_usb:libusb_ddk_proxy_1.1", + "drivers_interface_usb:libusb_ddk_proxy_1.2", "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", diff --git a/v1_1/IUsbDdk.idl b/v1_1/IUsbDdk.idl new file mode 100644 index 0000000000000000000000000000000000000000..147b04d0e8f27a0d88fd9f0f536dd4a7ff02269b --- /dev/null +++ b/v1_1/IUsbDdk.idl @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * @addtogroup HdiUsbDdk + * @{ + * + * @brief Provides USB DDK APIs to open and close USB interfaces, perform non-isochronous and isochronous\n + * data transfer over USB pipes, and implement control transfer and interrupt transfer, etc. + * @since 5.1 + * @version 1.1 + */ + +/** + * @file IUsbDdk.idl + * + * @brief Declares the USB DDK APIs used by the USB host to access USB devices. + * + * @since 5.1 + * @version 1.1 + */ + +package ohos.hdi.usb.ddk.v1_1; + +import ohos.hdi.usb.ddk.v1_1.UsbDdkTypes; +import ohos.hdi.usb.ddk.v1_0.IUsbDdk; + +/** + * @brief Declares the USB DDK APIs used by the USB host to access USB devices. + * @since 5.1 + * @version 1.1 + */ +interface IUsbDdk extends ohos.hdi.usb.ddk.v1_0.IUsbDdk +{ + /** + * @brief Obtains usb devices. + * + * @param devices USB device array. + * @return 0 if the operation is successful; a negative value otherwise. + * @since 5.1 + * @version 1.0 + */ + GetDevices([out] List deviceIds); + + /** + * @brief Updates peripheral driver information. + * + * @param driverInfo Driver ability information. + * @return 0 if the operation is successful; a negative value otherwise. + * @since 5.1 + * @version 1.0 + */ + UpdateDriverInfo([in] struct DriverAbilityInfo driverInfo); + + /** + * @brief Removes Driver information. + * + * @param driverUid Driver Uid. + * @return 0 if the operation is successful; a negative value otherwise. + * @since 5.1 + * @version 1.0 + */ + RemoveDriverInfo([in] String driverUid); + + /** + * @brief register listener. + * + * @param listener listener. + * @return 0 if the operation is successful; a negative value otherwise. + * @since 5.1 + * @version 1.0 + */ + void RegisterListener([in] IRemoteObject listener); + + /** + * @brief unregister listener. + * + * @param listener listener. + * @return 0 if the operation is successful; a negative value otherwise. + * @since 5.1 + * @version 1.0 + */ + void UnregisterListener([in] IRemoteObject listener); +} diff --git a/v1_1/UsbDdkTypes.idl b/v1_1/UsbDdkTypes.idl new file mode 100644 index 0000000000000000000000000000000000000000..53fecea08d2765be236432bfcbf3983eced58909 --- /dev/null +++ b/v1_1/UsbDdkTypes.idl @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * @addtogroup HdiUsbDdk + * @{ + * + * @brief Provides USB DDK types and declares the macros, enumerated variables, and\n + * data structures required by the USB DDK APIs. + * + * @since 5.1 + * @version 1.1 + */ + +/** + * @file UsbDdkTypes.idl + * + * @brief Provides the enumerated variables, structures, and macros used in USB DDK APIs. + * + * @since 5.1 + * @version 1.1 + */ + +package ohos.hdi.usb.ddk.v1_1; + +import ohos.hdi.usb.ddk.v1_0.UsbDdkTypes; + +/** + * @brief Defines driver info. + * + * @since 5.1 + * @version 1.0 + */ +struct DriverAbilityInfo { + /** Driver uid */ + String driverUid; + /** Vendor id array */ + unsigned short[] vids; +}; \ No newline at end of file