From 46e81de3d27c868d08dcb9ebf9698db32ec4e39f Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Thu, 30 Aug 2018 12:07:39 -0700 Subject: [PATCH] Not assuming that all accessibility events contain bundle Bundles come from Launcher being explicitly asked a question. When waiting for ANY event, it may contain any parcelable, so it's incorrect to cast it to Bundle. See this: https://sponge.corp.google.com/target?show=FAILED&sortBy=STATUS&id=9b8d0d26-f81d-427f-8857-b8d71e012504&target=android.test.appsmoke Bug: 110103162 Test: will watch for reducing flakes in platform tests. Change-Id: I989cee018183140d7fd672c0a925f03441ca339c --- .../android/launcher3/tapl/LauncherInstrumentation.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 09bf403aa1..106647607e 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -26,6 +26,7 @@ import android.app.ActivityManager; import android.app.Instrumentation; import android.app.UiAutomation; import android.os.Bundle; +import android.os.Parcelable; import android.provider.Settings; import android.view.accessibility.AccessibilityEvent; @@ -160,14 +161,14 @@ public final class LauncherInstrumentation { } } - private Bundle executeAndWaitForEvent(Runnable command, + private Parcelable executeAndWaitForEvent(Runnable command, UiAutomation.AccessibilityEventFilter eventFilter, String message) { try { final AccessibilityEvent event = mInstrumentation.getUiAutomation().executeAndWaitForEvent( command, eventFilter, WAIT_TIME_MS); assertNotNull("executeAndWaitForEvent returned null (this can't happen)", event); - return (Bundle) event.getParcelableData(); + return event.getParcelableData(); } catch (TimeoutException e) { fail(message); return null; @@ -177,7 +178,7 @@ public final class LauncherInstrumentation { Bundle getAnswerFromLauncher(UiObject2 view, String requestTag) { // Send a fake set-text request to Launcher to initiate a response with requested data. final String responseTag = requestTag + TestProtocol.RESPONSE_MESSAGE_POSTFIX; - return executeAndWaitForEvent( + return (Bundle) executeAndWaitForEvent( () -> view.setText(requestTag), event -> responseTag.equals(event.getClassName()), "Launcher didn't respond to request: " + requestTag);