From 5e92d2e24e4d18c4c82b0c59274618ae02929ed2 Mon Sep 17 00:00:00 2001 From: Daniel Norman Date: Mon, 10 Jul 2023 12:20:09 -0700 Subject: [PATCH] Prepares the main looper for UiAutomator shell command. The underlying UiAutomation object uses classes which expect the main looper to have been prepared. Fix: 289444999 Test: adb shell uiautomator dump Test: Use go/hsv to take a snapshot Change-Id: I43fcc4e9b4c1ab6e09aacd73f638208094641554 --- .../android/uiautomator/core/UiAutomationShellWrapper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java b/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java index 39248730802f5..7489ce3eceeae 100644 --- a/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java +++ b/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java @@ -8,6 +8,7 @@ import android.app.UiAutomation; import android.app.UiAutomationConnection; import android.content.Intent; import android.os.HandlerThread; +import android.os.Looper; import android.os.RemoteException; /** @@ -26,6 +27,10 @@ public class UiAutomationShellWrapper { throw new IllegalStateException("Already connected!"); } mHandlerThread.start(); + // The AccessibilityInteractionClient used by UiAutomation expects the main looper to + // be prepared. In most contexts this is normally done automatically, but must be called + // explicitly here because this is a shell tool. + Looper.prepareMainLooper(); mUiAutomation = new UiAutomation(mHandlerThread.getLooper(), new UiAutomationConnection()); mUiAutomation.connect();