Adding changes in UiBenchJankTestHelper to fix test cases in UiBenchJankTests.

Because of swipe right does not work for all devices it is added clicking image button to open nav drawer.
Adding gesture margin to existing swipe to avoid flakiness.

https://android-build.googleplex.com/builds/forrest/run/L57700000404943792


Bug: 145545440
Test: uibenchhelper

Change-Id: Iafb45e3dcc12d79e6a6a6054520f5f2592699e5d
diff --git a/tests/jank/uibench/src/com/android/uibench/janktests/UiBenchJankTestsHelper.java b/tests/jank/uibench/src/com/android/uibench/janktests/UiBenchJankTestsHelper.java
index f6f0076..0dcb4f3 100644
--- a/tests/jank/uibench/src/com/android/uibench/janktests/UiBenchJankTestsHelper.java
+++ b/tests/jank/uibench/src/com/android/uibench/janktests/UiBenchJankTestsHelper.java
@@ -55,7 +55,7 @@
     private UiDevice mDevice;
     private Context mContext;
     private DisplayMetrics mDisplayMetrics;
-    protected UiObject2 mContents;
+    protected UiObject2 mContents, mNavigation;
 
     private UiBenchJankTestsHelper(Context context, UiDevice device) {
         mContext = context;
@@ -101,6 +101,13 @@
         Assert.assertNotNull(activityName + " isn't found", mContents);
     }
 
+    private int getEdgeSensitivity() {
+        int resId =
+                mContext.getResources()
+                        .getIdentifier("config_backGestureInset", "dimen", "android");
+        return mContext.getResources().getDimensionPixelSize(resId) + 1;
+    }
+
     /**
      * To perform the fling down and up on given content for flingCount number
      * of times
@@ -111,6 +118,7 @@
 
     public void flingUpDown(UiObject2 content, int flingCount, boolean reverse) {
         for (int count = 0; count < flingCount; count++) {
+            content.setGestureMargin(getEdgeSensitivity());
             SystemClock.sleep(SHORT_TIMEOUT);
             content.fling(reverse ? Direction.UP : Direction.DOWN);
             SystemClock.sleep(SHORT_TIMEOUT);
@@ -123,15 +131,18 @@
      * of times
      */
     public void swipeRightLeft(UiObject2 content, int swipeCount) {
+        mNavigation = mDevice.wait(Until.findObject(By.desc("Open navigation drawer")), TIMEOUT);
+        content.setGestureMargin(getEdgeSensitivity());
         for (int count = 0; count < swipeCount; count++) {
             SystemClock.sleep(SHORT_TIMEOUT);
-            content.swipe(Direction.RIGHT, 1);
+            mNavigation.click();
             SystemClock.sleep(SHORT_TIMEOUT);
             content.swipe(Direction.LEFT, 1);
         }
     }
 
     public void slowSingleFlingDown(UiObject2 content) {
+        content.setGestureMargin(getEdgeSensitivity());
         SystemClock.sleep(SHORT_TIMEOUT);
         content.fling(Direction.DOWN, (int)(SLOW_FLING_SPEED * mDisplayMetrics.density));
         mDevice.waitForIdle();