From 9e9aa976bffc7d82dcd2d30d4f70aa46f510b98c Mon Sep 17 00:00:00 2001 From: Anduin1109 Date: Mon, 4 Aug 2025 11:37:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B3=E9=97=ADusb?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=80=89=E6=8B=A9=E5=90=8EremoteObject=5F?= =?UTF-8?q?=E6=A6=82=E7=8E=87=E6=80=A7UAF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anduin1109 --- .../include/usb_function_switch_window.h | 1 + .../native/src/usb_function_switch_window.cpp | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/services/native/include/usb_function_switch_window.h b/services/native/include/usb_function_switch_window.h index 35be4834..18025a8a 100644 --- a/services/native/include/usb_function_switch_window.h +++ b/services/native/include/usb_function_switch_window.h @@ -84,6 +84,7 @@ private: const std::string functionSwitchBundleName_ = "com.usb.right"; const std::string functionSwitchExtAbility_ = "UsbFunctionSwitchExtAbility"; bool isDialogInstalled_ = false; + bool isDialogClosed_ = true; Utils::Timer checkDialogTimer_ {"checkDialogTimer"}; uint32_t checkDialogTimerId_ {UINT32_MAX}; }; diff --git a/services/native/src/usb_function_switch_window.cpp b/services/native/src/usb_function_switch_window.cpp index fe0a700a..e8ce3a08 100644 --- a/services/native/src/usb_function_switch_window.cpp +++ b/services/native/src/usb_function_switch_window.cpp @@ -246,6 +246,7 @@ void UsbFunctionSwitchWindow::UsbFuncAbilityConn::OnAbilityConnectDone(const App USB_HILOGE(MODULE_USB_SERVICE, "show dialog failed: %{public}d", ret); return; } + isDialogClosed_ = false; remoteObject_ = remoteObject; return; } @@ -276,6 +277,7 @@ void UsbFunctionSwitchWindow::UsbFuncAbilityConn::CloseDialog() success = reply.ReadInt32(replyCode); } USB_HILOGI(MODULE_USB_SERVICE, "CloseDialog: ret=%{public}d, %{public}d, %{public}d", ret, success, replyCode); + isDialogClosed_ = true; } bool UsbFunctionSwitchWindow::ShowFunctionSwitchWindow() @@ -317,6 +319,7 @@ bool UsbFunctionSwitchWindow::UnShowFunctionSwitchWindow() return true; } + int32_t retryTimes = 0; auto abmc = AAFwk::AbilityManagerClient::GetInstance(); if (abmc == nullptr) { USB_HILOGE(MODULE_USB_SERVICE, "GetInstance failed"); @@ -324,14 +327,20 @@ bool UsbFunctionSwitchWindow::UnShowFunctionSwitchWindow() } USB_HILOGI(MODULE_USB_SERVICE, "unshow function switch window"); usbFuncAbilityConn->CloseDialog(); - - auto ret = abmc->DisconnectAbility(usbFuncAbilityConn); - if (ret != UEC_OK) { - USB_HILOGE(MODULE_SERVICE, "DisconnectAbility failed %{public}d", ret); - return false; + while (retryTimes < MAX_RETRY_TIMES) { + if (isDialogClosed_) { + auto ret = abmc->DisconnectAbility(usbFuncAbilityConn); + if (ret != UEC_OK) { + USB_HILOGE(MODULE_SERVICE, "DisconnectAbility failed %{public}d", ret); + return false; + } + USB_HILOGD(MODULE_USB_SERVICE, "unshow function switch window success"); + return true; + } + sleep(RETRY_INTERVAL_SECONDS); } - USB_HILOGD(MODULE_USB_SERVICE, "unshow function switch window success"); - return true; + USB_HILOGE(MODULE_SERVICE, "CloseDialog time out"); + return false; } bool UsbFunctionSwitchWindow::CheckDialogInstallStatus() -- Gitee From a877ce753e844e8c19b9586c9f44359fc1c0bf59 Mon Sep 17 00:00:00 2001 From: Anduin1109 Date: Mon, 4 Aug 2025 14:16:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B3=E9=97=ADusb?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=80=89=E6=8B=A9=E5=90=8EremoteObject=5F?= =?UTF-8?q?=E6=A6=82=E7=8E=87=E6=80=A7UAF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anduin1109 --- services/native/include/usb_function_switch_window.h | 2 +- services/native/src/usb_function_switch_window.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/native/include/usb_function_switch_window.h b/services/native/include/usb_function_switch_window.h index 18025a8a..7c34144d 100644 --- a/services/native/include/usb_function_switch_window.h +++ b/services/native/include/usb_function_switch_window.h @@ -68,6 +68,7 @@ private: public: void CloseDialog(); private: + bool isDialogClosed_ = true; sptr remoteObject_ = nullptr; }; bool ShowFunctionSwitchWindow(); @@ -84,7 +85,6 @@ private: const std::string functionSwitchBundleName_ = "com.usb.right"; const std::string functionSwitchExtAbility_ = "UsbFunctionSwitchExtAbility"; bool isDialogInstalled_ = false; - bool isDialogClosed_ = true; Utils::Timer checkDialogTimer_ {"checkDialogTimer"}; uint32_t checkDialogTimerId_ {UINT32_MAX}; }; diff --git a/services/native/src/usb_function_switch_window.cpp b/services/native/src/usb_function_switch_window.cpp index e8ce3a08..c9b654fd 100644 --- a/services/native/src/usb_function_switch_window.cpp +++ b/services/native/src/usb_function_switch_window.cpp @@ -328,7 +328,7 @@ bool UsbFunctionSwitchWindow::UnShowFunctionSwitchWindow() USB_HILOGI(MODULE_USB_SERVICE, "unshow function switch window"); usbFuncAbilityConn->CloseDialog(); while (retryTimes < MAX_RETRY_TIMES) { - if (isDialogClosed_) { + if (usbFuncAbilityConn->isDialogClosed_) { auto ret = abmc->DisconnectAbility(usbFuncAbilityConn); if (ret != UEC_OK) { USB_HILOGE(MODULE_SERVICE, "DisconnectAbility failed %{public}d", ret); -- Gitee From 7cc1b17b27e47d013eacc0620b3cf68c34355b7b Mon Sep 17 00:00:00 2001 From: Anduin1109 Date: Mon, 4 Aug 2025 15:51:58 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B3=E9=97=ADusb?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=80=89=E6=8B=A9=E5=90=8EremoteObject=5F?= =?UTF-8?q?=E6=A6=82=E7=8E=87=E6=80=A7UAF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anduin1109 --- services/native/include/usb_function_switch_window.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/include/usb_function_switch_window.h b/services/native/include/usb_function_switch_window.h index 7c34144d..bdcee953 100644 --- a/services/native/include/usb_function_switch_window.h +++ b/services/native/include/usb_function_switch_window.h @@ -67,8 +67,8 @@ private: void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; public: void CloseDialog(); - private: bool isDialogClosed_ = true; + private: sptr remoteObject_ = nullptr; }; bool ShowFunctionSwitchWindow(); -- Gitee