Scroll through the spinner of the printer selection

If the device orientation is landscape, the height of the spinner
 of the printer selection become shorter than the portrait device.
Further, if the status bar height become large, the expected printer
name might not been shown in the spinner of the printer selection.
In that case, UiObjectNotFoundException is thrown and the printer
tests fails.
(e.g. PrintDocumentAdapterContractTest#testNewPrinterSupportsSelectedPrintOptions)
So we think this spinner needs to be scrolled if the expected printer
name is not shown.

Change-Id: I908953d67b2b388011a91e31c38b118aba0e87ca
diff --git a/tests/tests/print/src/android/print/cts/BasePrintTest.java b/tests/tests/print/src/android/print/cts/BasePrintTest.java
old mode 100644
new mode 100755
index c73bb64..9d51e3b
--- a/tests/tests/print/src/android/print/cts/BasePrintTest.java
+++ b/tests/tests/print/src/android/print/cts/BasePrintTest.java
@@ -51,6 +51,7 @@
 import android.support.test.uiautomator.UiAutomatorTestCase;
 import android.support.test.uiautomator.UiObject;
 import android.support.test.uiautomator.UiObjectNotFoundException;
+import android.support.test.uiautomator.UiScrollable;
 import android.support.test.uiautomator.UiSelector;
 import android.util.DisplayMetrics;
 
@@ -226,6 +227,12 @@
                     "com.android.printspooler:id/destination_spinner"));
             destinationSpinner.click();
             UiObject printerOption = new UiObject(new UiSelector().text(printerName));
+            if (!printerOption.exists()) {
+                // Scroll through the spinner
+                UiScrollable printerSpinner = new UiScrollable(new UiSelector().scrollable(true));
+                printerSpinner.setAsVerticalList();
+                printerOption = printerSpinner.getChildByText(new UiSelector().text(printerName), printerName);
+            }
             printerOption.click();
         } catch (UiObjectNotFoundException e) {
             dumpWindowHierarchy();