Stop android.print tests from executing if the device does not support print.

Bug: 24856532
Change-Id: Ia3a01043782f81a6605a79a68f0f943d4d051f6a
diff --git a/tests/tests/print/src/android/print/cts/BasePrintTest.java b/tests/tests/print/src/android/print/cts/BasePrintTest.java
index 1378bdb..321ae39 100644
--- a/tests/tests/print/src/android/print/cts/BasePrintTest.java
+++ b/tests/tests/print/src/android/print/cts/BasePrintTest.java
@@ -139,6 +139,14 @@
     }
 
     @Override
+    protected void runTest() throws Throwable {
+        // Do nothing if the device does not support printing.
+        if (supportsPrinting()) {
+            super.runTest();
+        }
+    }
+
+    @Override
     public void setUp() throws Exception {
         super.setUp();
         if (!supportsPrinting()) {
@@ -181,25 +189,28 @@
 
     @Override
     public void tearDown() throws Exception {
-        if (supportsPrinting()) {
-            // Done with the activity.
-            getActivity().finish();
-            enableImes();
-
-            // Restore the locale if needed.
-            if (mOldLocale != null) {
-                Resources resources = getInstrumentation().getTargetContext().getResources();
-                DisplayMetrics displayMetrics = resources.getDisplayMetrics();
-                Configuration newConfiguration = new Configuration(resources.getConfiguration());
-                newConfiguration.locale = mOldLocale;
-                mOldLocale = null;
-                resources.updateConfiguration(newConfiguration, displayMetrics);
-            }
-
-            disablePrintServices();
-            // Make sure the spooler is cleaned.
-            clearPrintSpoolerData();
+        if (!supportsPrinting()) {
+            return;
         }
+
+        // Done with the activity.
+        getActivity().finish();
+        enableImes();
+
+        // Restore the locale if needed.
+        if (mOldLocale != null) {
+            Resources resources = getInstrumentation().getTargetContext().getResources();
+            DisplayMetrics displayMetrics = resources.getDisplayMetrics();
+            Configuration newConfiguration = new Configuration(resources.getConfiguration());
+            newConfiguration.locale = mOldLocale;
+            mOldLocale = null;
+            resources.updateConfiguration(newConfiguration, displayMetrics);
+        }
+
+        disablePrintServices();
+        // Make sure the spooler is cleaned.
+        clearPrintSpoolerData();
+
         super.tearDown();
     }
 
@@ -549,6 +560,7 @@
     }
 
     protected boolean supportsPrinting() {
-        return getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING);
+        return getInstrumentation().getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_PRINTING);
     }
 }