RESTRICT AUTOMERGE : Skip test case "testRotation" on TV device as it only support Landscape.

On TV, you cannot physically rotate the screen, so it doesn't make sense
to allow anything but the default orientation. Skip test case "testRotation"
on TV device as it only support Landscape.
Bug: 135752912
Test: run cts -m CtsAppTestCases -t android.app.cts.DisplayTest#testRotation
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/PackageUtil.java b/common/device-side/util/src/com/android/compatibility/common/util/PackageUtil.java
new file mode 100644
index 0000000..674fc31
--- /dev/null
+++ b/common/device-side/util/src/com/android/compatibility/common/util/PackageUtil.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.compatibility.common.util;
+
+import android.content.pm.PackageManager;
+import android.support.test.InstrumentationRegistry;
+import android.util.Log;
+
+/**
+ * Device-side utility class for PackageManager-related operations
+ */
+public class PackageUtil {
+    private static final String TAG = PackageUtil.class.getSimpleName();
+
+    private static boolean hasDeviceFeature(final String requiredFeature) {
+        return InstrumentationRegistry.getContext()
+                .getPackageManager()
+                .hasSystemFeature(requiredFeature);
+    }
+
+    /**
+     * Rotation support is indicated by explicitly having both landscape and portrait
+     * features or not listing either at all.
+     */
+    public static boolean supportsRotation() {
+        final boolean supportsLandscape = hasDeviceFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE);
+        final boolean supportsPortrait = hasDeviceFeature(PackageManager.FEATURE_SCREEN_PORTRAIT);
+        return (supportsLandscape && supportsPortrait)
+                || (!supportsLandscape && !supportsPortrait);
+    }
+}
diff --git a/tests/app/src/android/app/cts/DisplayTest.java b/tests/app/src/android/app/cts/DisplayTest.java
index e3ce544..fc6a6f3 100644
--- a/tests/app/src/android/app/cts/DisplayTest.java
+++ b/tests/app/src/android/app/cts/DisplayTest.java
@@ -21,6 +21,7 @@
 import android.app.stubs.OrientationTestUtils;
 import android.test.ActivityInstrumentationTestCase2;
 import android.view.Display;
+import static com.android.compatibility.common.util.PackageUtil.supportsRotation;
 
 /**
  * Tests to verify functionality of {@link Display}.
@@ -47,6 +48,10 @@
      * updated adjustments after a rotation.
      */
     public void testRotation() throws Throwable {
+        if (!supportsRotation()) {
+          // Skip rotation test if device doesn't support it.
+          return;
+        }
         // Get a {@link Display} instance before rotation.
         final Display origDisplay = mActivity.getDisplay();