Skip screen orientation check for devices that do not support portrait.

TV devices do not support rotation, so it does not make sense to test
screen orientation for portrait and reverse portrait orientations.

Bug: 111938575
Test: cts -m CtsDpiTestCases -t android.dpi.cts.ConfigurationScreenLayoutTest#testScreenLayout
Tested on Pixel too and no behavior changes

Change-Id: I5c4a8197c6c1e2299c3efe1f369d15aa5d0e0136
diff --git a/tests/tests/dpi/src/android/dpi/cts/ConfigurationScreenLayoutTest.java b/tests/tests/dpi/src/android/dpi/cts/ConfigurationScreenLayoutTest.java
index 3015b07..d7c9366 100644
--- a/tests/tests/dpi/src/android/dpi/cts/ConfigurationScreenLayoutTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/ConfigurationScreenLayoutTest.java
@@ -20,7 +20,9 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
 import android.content.res.Configuration;
+import android.support.test.InstrumentationRegistry;
 import android.test.ActivityInstrumentationTestCase2;
 import android.util.DisplayMetrics;
 import android.view.Display;
@@ -42,6 +44,11 @@
     }
 
     public void testScreenLayout() throws Exception {
+        if (!supportsRotation()) {
+            // test has no effect if device does not support rotation
+            tearDown();
+            return;
+        }
         int expectedScreenLayout = computeScreenLayout();
         int expectedSize = expectedScreenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
         int expectedLong = expectedScreenLayout & Configuration.SCREENLAYOUT_LONG_MASK;
@@ -86,6 +93,12 @@
         return screenLayout;
     }
 
+    private boolean hasDeviceFeature(final String requiredFeature) {
+        return InstrumentationRegistry.getContext()
+                .getPackageManager()
+                .hasSystemFeature(requiredFeature);
+    }
+
     private Activity startOrientationActivity(int orientation) {
         Intent intent = new Intent();
         intent.putExtra(OrientationActivity.EXTRA_ORIENTATION, orientation);
@@ -139,4 +152,15 @@
         }
         return screenLayout;
     }
+
+    /**
+     * Rotation support is indicated by explicitly having both landscape and portrait
+     * features or not listing either at all.
+     */
+    private boolean supportsRotation() {
+        final boolean supportsLandscape = hasDeviceFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE);
+        final boolean supportsPortrait = hasDeviceFeature(PackageManager.FEATURE_SCREEN_PORTRAIT);
+        return (supportsLandscape && supportsPortrait)
+                || (!supportsLandscape && !supportsPortrait);
+    }
 }