From 08280849dc0039dd1646e12b34ef0933cb9418da Mon Sep 17 00:00:00 2001 From: Jintao Zhu Date: Tue, 29 Jun 2021 21:39:10 +0800 Subject: [PATCH] Fix "already registered" error Root cause: Upon running into the method "UiAutomationManager.registerUiTestAutomationServiceLocked", after assigning "mUiAutomationService" with newly created object, the calling of "mUiAutomationService.onAdded()" may throw an exception which simply skipping the next code line "mUiAutomationService.mServiceInterface.asBinder().linkToDeath", which preventing it from getting notification when the "mServiceInterface" process dies, then, the "mUiAutomationService" will never have a chance to be clean-up-ed. And, next time, upon running into registerUiTestAutomationServiceLocked again, it has to complain "already registered". Solution: Move the line "mUiAutomationService.onAdded()" to after the line "linkToDeath", so that, the possible exception will not prohibit the linkToDeath operation. Bug: 192317057 Test: monkey test for one day and one night Co-authored-by: Zheng Xiaoying Signed-off-by: Jintao Zhu Change-Id: Ife4584804910290fac70dbe6d6934333f9a7486a --- .../com/android/server/accessibility/UiAutomationManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java b/services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java index d1c3a02c6761a..1c614a02757e8 100644 --- a/services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java +++ b/services/accessibility/java/com/android/server/accessibility/UiAutomationManager.java @@ -114,7 +114,6 @@ class UiAutomationManager { mUiAutomationFlags = flags; mUiAutomationServiceInfo = accessibilityServiceInfo; mUiAutomationService.mServiceInterface = serviceClient; - mUiAutomationService.onAdded(); try { mUiAutomationService.mServiceInterface.asBinder().linkToDeath(mUiAutomationService, 0); @@ -124,6 +123,8 @@ class UiAutomationManager { return; } + mUiAutomationService.onAdded(); + mUiAutomationService.connectServiceUnknownThread(); } }