From 5ae62f983e307fa3d99103c63d315ea2e9abbb2a Mon Sep 17 00:00:00 2001 From: Isaac Murchie Date: Wed, 14 May 2014 13:13:31 -0700 Subject: [PATCH] Fix touch actions below API 18 --- .../bootstrap/handler/MultiPointerGesture.java | 18 +++++++++++++----- .../bootstrap/handler/TouchableEvent.java | 12 ++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/MultiPointerGesture.java b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/MultiPointerGesture.java index 4af429029..d1402a2a3 100644 --- a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/MultiPointerGesture.java +++ b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/MultiPointerGesture.java @@ -1,5 +1,7 @@ package io.appium.android.bootstrap.handler; +import android.os.Build; + import android.view.MotionEvent.PointerCoords; import com.android.uiautomator.core.UiObject; @@ -39,12 +41,18 @@ public class MultiPointerGesture extends TouchableEvent { } } else { Object controller = getController(); - final Method pmpg = getMethod("performMultiPointerGesture", controller); - Boolean rt = (Boolean)pmpg.invoke(controller, (Object)pcs); - if (rt.booleanValue()) { - return getSuccessResult("OK"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + final Method pmpg = getMethod("performMultiPointerGesture", controller); + Boolean rt = (Boolean)pmpg.invoke(controller, (Object)pcs); + if (rt.booleanValue()) { + return getSuccessResult("OK"); + } else { + return getErrorResult("Unable to perform multi pointer gesture"); + } } else { - return getErrorResult("Unable to perform multi pointer gesture"); + Logger.error("Device does not support API < 18!"); + return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, + "Cannot perform multi pointer gesture on device below API level 18"); } } } catch (final ElementNotInHashException e) { diff --git a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/TouchableEvent.java b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/TouchableEvent.java index 804c06010..8f6306296 100644 --- a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/TouchableEvent.java +++ b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/TouchableEvent.java @@ -3,6 +3,8 @@ package io.appium.android.bootstrap.handler; import io.appium.android.bootstrap.CommandHandler; import io.appium.android.bootstrap.Logger; +import android.os.Build; + import android.view.MotionEvent.PointerCoords; import com.android.uiautomator.core.UiDevice; @@ -34,8 +36,14 @@ public abstract class TouchableEvent extends CommandHandler { final UiDevice device = UiDevice.getInstance(); final Object bridge = enableField(device.getClass(), "mUiAutomationBridge") .get(device); - final Object controller = enableField(bridge.getClass().getSuperclass(), - "mInteractionController").get(bridge); + Object controller = null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + controller = enableField(bridge.getClass().getSuperclass(), + "mInteractionController").get(bridge); + } else { + controller = enableField(bridge.getClass(), + "mInteractionController").get(bridge); + } return controller; }