From e42bf68b52e91b89b45558e8ae2258ecb9a49a4b Mon Sep 17 00:00:00 2001 From: hechaofan Date: Mon, 19 Aug 2024 10:35:38 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=8A=B6=E6=80=81=E4=B8=BAclose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index faff38fc..97dda5a0 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1538,6 +1538,11 @@ bool UsbService::AddDevice(uint8_t busNum, uint8_t devAddr) usbHostManager_->AddDevice(devInfo); ExecuteStrategy(devInfo); + const UsbDev dev = {busNum, devAddr}; + ret = usbd_->CloseDevice(dev); + if (ret != UEC_OK) { + USB_HILOGI(MODULE_USB_SERVICE, "CloseDevice failed ret=%{public}d", ret); + } return true; } // LCOV_EXCL_STOP @@ -2157,7 +2162,7 @@ int32_t UsbService::ManageInterfaceTypeImpl(InterfaceType interfaceType, bool di iterInterface->second[PROTOCAL_INDEX] == RANDOM_VALUE_INDICATE)) { ManageInterface(dev, interfaces[i].GetId(), disable); USB_HILOGI(MODULE_USB_SERVICE, "size %{public}zu, interfaceType: %{public}d, disable: %{public}d", - devices.size(), (int32_t)interfaceType, disable); + devices.size(), static_cast(interfaceType), disable); std::this_thread::sleep_for(std::chrono::milliseconds(MANAGE_INTERFACE_INTERVAL)); } } @@ -2177,14 +2182,14 @@ int32_t UsbService::ManageDeviceTypeImpl(InterfaceType interfaceType, bool disab std::map devices; usbHostManager_->GetDevices(devices); - USB_HILOGI(MODULE_USB_SERVICE, "list size %{public}zu, interfaceType: %{public}d, disable: %{public}d", - devices.size(), (int32_t)interfaceType, disable); for (auto it = devices.begin(); it != devices.end(); ++it) { if ((it->second->GetClass() == iterInterface->second[BASECLASS_INDEX]) && (it->second->GetSubclass() == iterInterface->second[SUBCLASS_INDEX] || iterInterface->second[SUBCLASS_INDEX] == RANDOM_VALUE_INDICATE) && (it->second->GetProtocol() == iterInterface->second[PROTOCAL_INDEX] || iterInterface->second[PROTOCAL_INDEX] == RANDOM_VALUE_INDICATE)) { ManageDeviceImpl(it->second->GetVendorId(), it->second->GetProductId(), disable); + USB_HILOGI(MODULE_USB_SERVICE, "list size %{public}zu, interfaceType: %{public}d, disable: %{public}d", + devices.size(), static_cast(interfaceType), disable); std::this_thread::sleep_for(std::chrono::milliseconds(MANAGE_INTERFACE_INTERVAL)); } } -- Gitee From 6f9c19625a1bb714a2e622c3d4a8e3491cfff0a8 Mon Sep 17 00:00:00 2001 From: hechaofan Date: Mon, 26 Aug 2024 15:35:16 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E6=9C=AA=E6=89=A7=E8=A1=8Cconnect?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5claim=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 40 ++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index 97dda5a0..5ae929a6 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1008,7 +1008,13 @@ int32_t UsbService::Close(uint8_t busNum, uint8_t devAddr) USB_HILOGE(MODULE_USB_SERVICE, "UsbService::usbd_ is nullptr"); return UEC_SERVICE_INVALID_VALUE; } - return usbd_->CloseDevice(dev); + + int32_t ret = usbd_->CloseDevice(dev); + if (ret != UEC_OK) { + USB_HILOGE(MODULE_USBD, "Close device failed width ret = %{public}d", ret); + return ret; + } + return UEC_OK; } // LCOV_EXCL_STOP @@ -1171,7 +1177,7 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de } int32_t ret = usbd_->OpenDevice(uDev); if (ret != UEC_OK) { - USB_HILOGE(MODULE_USB_SERVICE, "OpenDevice failed ret=%{public}d", ret); + USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfo OpenDevice failed ret=%{public}d", ret); return ret; } @@ -1182,10 +1188,12 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de ret = GetConfigDescriptor(dev, descriptor); if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetConfigDescriptor ret=%{public}d", ret); - return ret; } - - return UEC_OK; + int32_t ret = usbd_->CloseDevice(uDev); + if (ret != UEC_OK) { + USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfo CloseDevice failed ret=%{public}d", ret); + } + return ret; } // LCOV_EXCL_STOP @@ -1538,12 +1546,7 @@ bool UsbService::AddDevice(uint8_t busNum, uint8_t devAddr) usbHostManager_->AddDevice(devInfo); ExecuteStrategy(devInfo); - const UsbDev dev = {busNum, devAddr}; - ret = usbd_->CloseDevice(dev); - if (ret != UEC_OK) { - USB_HILOGI(MODULE_USB_SERVICE, "CloseDevice failed ret=%{public}d", ret); - } - return true; + return ret; } // LCOV_EXCL_STOP @@ -2204,7 +2207,20 @@ int32_t UsbService::ManageInterface(const HDI::Usb::V1_0::UsbDev &dev, uint8_t i USB_HILOGE(MODULE_USB_SERVICE, "usbd_ is nullptr"); return UEC_SERVICE_INVALID_VALUE; } - return usbd_->ManageInterface(dev, interfaceId, disable); + int32_t ret = usbd_->OpenDevice(dev); + if (ret != UEC_OK) { + USB_HILOGE(MODULE_USB_SERVICE, "ManageInterface OpenDevice failed ret=%{public}d", ret); + return ret; + } + ret = usbd_->ManageInterface(dev, interfaceId, disable); + if (ret != 0) { + USB_HILOGE(MODULE_USB_SERVICE, "ManageInterface failed ret=%{public}d", ret); + } + ret = usbd_->CloseDevice(dev); + if (ret != UEC_OK) { + USB_HILOGE(MODULE_USBD, "ManageInterface Close device failed ret = %{public}d", ret); + } + return ret; } // LCOV_EXCL_STOP -- Gitee From 483285d4d6eaf62f308c89dc794dd743784aed08 Mon Sep 17 00:00:00 2001 From: hechaofan Date: Tue, 27 Aug 2024 01:50:14 +0000 Subject: [PATCH 03/10] update services/native/src/usb_service.cpp. Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index 5ae929a6..9d0a64aa 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1546,7 +1546,7 @@ bool UsbService::AddDevice(uint8_t busNum, uint8_t devAddr) usbHostManager_->AddDevice(devInfo); ExecuteStrategy(devInfo); - return ret; + return true; } // LCOV_EXCL_STOP -- Gitee From c8e080b40411636ccd5ab05d44a2b56d8cb3e750 Mon Sep 17 00:00:00 2001 From: hechaofan Date: Tue, 27 Aug 2024 01:51:29 +0000 Subject: [PATCH 04/10] update services/native/src/usb_service.cpp. Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index 9d0a64aa..c70f9bec 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1009,12 +1009,7 @@ int32_t UsbService::Close(uint8_t busNum, uint8_t devAddr) return UEC_SERVICE_INVALID_VALUE; } - int32_t ret = usbd_->CloseDevice(dev); - if (ret != UEC_OK) { - USB_HILOGE(MODULE_USBD, "Close device failed width ret = %{public}d", ret); - return ret; - } - return UEC_OK; + return usbd_->CloseDevice(dev); } // LCOV_EXCL_STOP -- Gitee From dd1216497c298e65d0f0d9826495a55edf1fec1f Mon Sep 17 00:00:00 2001 From: hechaofan Date: Tue, 27 Aug 2024 01:52:06 +0000 Subject: [PATCH 05/10] update services/native/src/usb_service.cpp. Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index c70f9bec..35379906 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1008,7 +1008,6 @@ int32_t UsbService::Close(uint8_t busNum, uint8_t devAddr) USB_HILOGE(MODULE_USB_SERVICE, "UsbService::usbd_ is nullptr"); return UEC_SERVICE_INVALID_VALUE; } - return usbd_->CloseDevice(dev); } // LCOV_EXCL_STOP -- Gitee From 4154020644b095aae5c0df5006cb7740033b8f9a Mon Sep 17 00:00:00 2001 From: hechaofan Date: Tue, 27 Aug 2024 02:23:56 +0000 Subject: [PATCH 06/10] update services/native/src/usb_service.cpp. Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index 35379906..3e526842 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1183,7 +1183,7 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetConfigDescriptor ret=%{public}d", ret); } - int32_t ret = usbd_->CloseDevice(uDev); + ret = usbd_->CloseDevice(uDev); if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfo CloseDevice failed ret=%{public}d", ret); } -- Gitee From 81bf006ec9831949eebdbb7eaafca42184e3802b Mon Sep 17 00:00:00 2001 From: hechaofan Date: Tue, 27 Aug 2024 03:49:51 +0000 Subject: [PATCH 07/10] update services/native/src/usb_service.cpp. Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index 3e526842..0a2bbc4e 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1182,6 +1182,7 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de ret = GetConfigDescriptor(dev, descriptor); if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetConfigDescriptor ret=%{public}d", ret); + return ret; } ret = usbd_->CloseDevice(uDev); if (ret != UEC_OK) { @@ -2209,6 +2210,7 @@ int32_t UsbService::ManageInterface(const HDI::Usb::V1_0::UsbDev &dev, uint8_t i ret = usbd_->ManageInterface(dev, interfaceId, disable); if (ret != 0) { USB_HILOGE(MODULE_USB_SERVICE, "ManageInterface failed ret=%{public}d", ret); + return ret; } ret = usbd_->CloseDevice(dev); if (ret != UEC_OK) { -- Gitee From 74c2ab5d65dfa5f697d2dd9f32da7639baf69f84 Mon Sep 17 00:00:00 2001 From: hechaofan Date: Tue, 27 Aug 2024 04:00:14 +0000 Subject: [PATCH 08/10] update services/native/src/usb_service.cpp. Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index 0a2bbc4e..ffcf268b 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1179,16 +1179,16 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfoDescriptor ret=%{public}d", ret); } - ret = GetConfigDescriptor(dev, descriptor); - if (ret != UEC_OK) { + int32_t res = GetConfigDescriptor(dev, descriptor); + if (res != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetConfigDescriptor ret=%{public}d", ret); - return ret; } ret = usbd_->CloseDevice(uDev); if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfo CloseDevice failed ret=%{public}d", ret); + return ret; } - return ret; + return res; } // LCOV_EXCL_STOP @@ -2207,16 +2207,16 @@ int32_t UsbService::ManageInterface(const HDI::Usb::V1_0::UsbDev &dev, uint8_t i USB_HILOGE(MODULE_USB_SERVICE, "ManageInterface OpenDevice failed ret=%{public}d", ret); return ret; } - ret = usbd_->ManageInterface(dev, interfaceId, disable); - if (ret != 0) { + int32_t res = usbd_->ManageInterface(dev, interfaceId, disable); + if (res != 0) { USB_HILOGE(MODULE_USB_SERVICE, "ManageInterface failed ret=%{public}d", ret); - return ret; } ret = usbd_->CloseDevice(dev); if (ret != UEC_OK) { USB_HILOGE(MODULE_USBD, "ManageInterface Close device failed ret = %{public}d", ret); + return ret; } - return ret; + return res; } // LCOV_EXCL_STOP -- Gitee From c466aa6bb8fdd95402fd6ca9a1771a2940b18738 Mon Sep 17 00:00:00 2001 From: hechaofan Date: Tue, 27 Aug 2024 06:26:28 +0000 Subject: [PATCH 09/10] update services/native/src/usb_service.cpp. Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index ffcf268b..5d5aa1ce 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1169,6 +1169,7 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de USB_HILOGE(MODULE_USB_SERVICE, "UsbService::usbd_ is nullptr"); return UEC_SERVICE_INVALID_VALUE; } + int32_t res = false; int32_t ret = usbd_->OpenDevice(uDev); if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfo OpenDevice failed ret=%{public}d", ret); @@ -1178,8 +1179,14 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de ret = GetDeviceInfoDescriptor(uDev, descriptor, dev); if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfoDescriptor ret=%{public}d", ret); + res = usbd_->CloseDevice(uDev); + if (res != UEC_OK) { + USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfo CloseDevice failed res=%{public}d", res); + return res; + } + return ret; } - int32_t res = GetConfigDescriptor(dev, descriptor); + res = GetConfigDescriptor(dev, descriptor); if (res != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetConfigDescriptor ret=%{public}d", ret); } -- Gitee From 420a7e3103250ad2513607f9ec3693d002897203 Mon Sep 17 00:00:00 2001 From: hechaofan Date: Tue, 27 Aug 2024 07:28:49 +0000 Subject: [PATCH 10/10] update services/native/src/usb_service.cpp. Signed-off-by: hechaofan --- services/native/src/usb_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/usb_service.cpp b/services/native/src/usb_service.cpp index 5d5aa1ce..6ecb10f4 100644 --- a/services/native/src/usb_service.cpp +++ b/services/native/src/usb_service.cpp @@ -1169,7 +1169,7 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de USB_HILOGE(MODULE_USB_SERVICE, "UsbService::usbd_ is nullptr"); return UEC_SERVICE_INVALID_VALUE; } - int32_t res = false; + int32_t res = UEC_OK; int32_t ret = usbd_->OpenDevice(uDev); if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInfo OpenDevice failed ret=%{public}d", ret); -- Gitee