Merge "Fix bad tests exposed by parallel reduction support." into nyc-dev
diff --git a/common/device-side/preconditions/src/com/android/compatibility/common/preconditions/ScreenLockHelper.java b/common/device-side/preconditions/src/com/android/compatibility/common/preconditions/ScreenLockHelper.java
index d2380af..385f22f 100644
--- a/common/device-side/preconditions/src/com/android/compatibility/common/preconditions/ScreenLockHelper.java
+++ b/common/device-side/preconditions/src/com/android/compatibility/common/preconditions/ScreenLockHelper.java
@@ -18,6 +18,7 @@
 
 import android.app.KeyguardManager;
 import android.content.Context;
+import android.os.Build;
 
 /**
  * ScreenLockHelper is used to check whether the device is protected by a locked screen.
@@ -29,6 +30,9 @@
      * is no way to programmatically distinguish between the two.
      */
     public static boolean isDeviceSecure(Context context) {
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
+            return true; // KeyguardManager.isDeviceSecure() added in M, skip this check
+        }
         KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
         return km.isDeviceSecure();
     }
diff --git a/common/device-side/preconditions/src/com/android/compatibility/common/preconditions/WifiHelper.java b/common/device-side/preconditions/src/com/android/compatibility/common/preconditions/WifiHelper.java
index 70a4b03..ef63544 100644
--- a/common/device-side/preconditions/src/com/android/compatibility/common/preconditions/WifiHelper.java
+++ b/common/device-side/preconditions/src/com/android/compatibility/common/preconditions/WifiHelper.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
+import android.os.Build;
 
 /**
  * WifiHelper is used to check whether the device is connected to WiFi.
@@ -27,6 +28,9 @@
 public class WifiHelper {
 
     public static boolean isWifiConnected(Context context) {
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+            return true; // ConnectivityManager.getNetworkInfo() added in LOLLIPOP, skip this check
+        }
         ConnectivityManager cm = (ConnectivityManager)
                 context.getSystemService(Context.CONNECTIVITY_SERVICE);
         NetworkInfo wifiNetworkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
diff --git a/tests/expectations/knownfailures.txt b/tests/expectations/knownfailures.txt
index 56475fd..9b3a09d 100644
--- a/tests/expectations/knownfailures.txt
+++ b/tests/expectations/knownfailures.txt
@@ -158,6 +158,14 @@
   bug: 17508787
 },
 {
+  description: "This test is not working on Android Player",
+  names: [
+    "com.android.cts.devicepolicy.MixedDeviceOwnerTest#testPackageInstallUserRestrictions",
+    "com.android.cts.devicepolicy.MixedProfileOwnerTest#testPackageInstallUserRestrictions"
+  ],
+  bug: 27949133
+},
+{
   description: "Test is not yet properly implemented",
   names: [
     "android.voicesettings.cts.ZenModeTest#testAll"
diff --git a/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java b/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
index c991b6f..8bbf448 100644
--- a/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
+++ b/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
@@ -135,6 +135,54 @@
                 mActivity.getAepEs31Support());
     }
 
+    public void testOpenGlEsVersionForVrHighPerformance() throws InterruptedException {
+        if (!supportsVrHighPerformance())
+            return;
+        restartActivityWithClientVersion(3);
+
+        int reportedVersion = getVersionFromActivityManager(mActivity);
+        int major = getMajorVersion(reportedVersion);
+        int minor = getMinorVersion(reportedVersion);
+
+        assertTrue("OpenGL ES version 3.2 or higher is required for VR high-performance devices " +
+            " but this device supports only version " + major + "." + minor,
+            (major == 3 && minor >= 2) || major > 3);
+    }
+
+    public void testRequiredExtensionsForVrHighPerformance() throws InterruptedException {
+        if (!supportsVrHighPerformance())
+            return;
+        restartActivityWithClientVersion(3);
+
+        String extensions = mActivity.getExtensionsString();
+        final String requiredList[] = {
+            "EXT_protected_textures",
+            "EXT_multisampled_render_to_texture",
+            "OVR_multiview",
+            "OVR_multiview_multisampled_render_to_texture",
+            "OVR_multiview2",
+        };
+
+        for (int i = 0; i < requiredList.length; ++i) {
+            assertTrue("Required extension for VR high-performance is missing: " + requiredList[i],
+                    hasExtension(extensions, requiredList[i]));
+        }
+
+        EGL10 egl = (EGL10) EGLContext.getEGL();
+        EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+        extensions = egl.eglQueryString(display, EGL10.EGL_EXTENSIONS);
+        final String requiredEglList[] = {
+            "EGL_ANDROID_front_buffer_auto_refresh",
+            "EGL_EXT_protected_content",
+            "EGL_KHR_mutable_render_buffer",
+        };
+
+        for (int i = 0; i < requiredList.length; ++i) {
+            assertTrue("Required EGL extension for VR high-performance is missing: " +
+                requiredEglList[i], hasExtension(extensions, requiredEglList[i]));
+        }
+    }
+
     private static boolean hasExtension(String extensions, String name) {
         return OpenGlEsVersionCtsActivity.hasExtension(extensions, name);
     }
@@ -264,4 +312,13 @@
             setActivityIntent(null);
         }
     }
+
+    /**
+     * Return whether the system supports FEATURE_VR_MODE and
+     * FEATURE_VR_MODE_HIGH_PERFORMANCE. This is used to skip some tests.
+     */
+    private boolean supportsVrHighPerformance() {
+        PackageManager pm = mActivity.getPackageManager();
+        return pm.hasSystemFeature(PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE);
+    }
 }
diff --git a/tests/tests/os/jni/Android.mk b/tests/tests/os/jni/Android.mk
index 6d2f1dd..3305fc9 100644
--- a/tests/tests/os/jni/Android.mk
+++ b/tests/tests/os/jni/Android.mk
@@ -28,37 +28,9 @@
 		android_os_cts_HardwareName.cpp \
 		android_os_cts_OSFeatures.cpp \
 		android_os_cts_NoExecutePermissionTest.cpp \
-		android_os_cts_SeccompTest.cpp
-
-# Select the architectures on which seccomp-bpf are supported. This is used to
-# include extra test files that will not compile on architectures where it is
-# not supported.
-ARCH_SUPPORTS_SECCOMP := 0
-ifeq ($(strip $(TARGET_ARCH)),arm)
-	ARCH_SUPPORTS_SECCOMP = 1
-endif
-
-ifeq ($(strip $(TARGET_ARCH)),arm64)
-	ARCH_SUPPORTS_SECCOMP = 1
-	# Required for __NR_poll definition.
-	LOCAL_CFLAGS += -D__ARCH_WANT_SYSCALL_DEPRECATED
-endif
-
-ifeq ($(strip $(TARGET_ARCH)),x86)
-	ARCH_SUPPORTS_SECCOMP = 1
-endif
-
-ifeq ($(strip $(TARGET_ARCH)),x86_64)
-	ARCH_SUPPORTS_SECCOMP = 1
-endif
-
-ifeq ($(ARCH_SUPPORTS_SECCOMP),1)
-	LOCAL_SRC_FILES += seccomp-tests/tests/seccomp_bpf_tests.c \
-			seccomp_sample_program.cpp
-
-	# This define controls the behavior of OSFeatures.needsSeccompSupport().
-	LOCAL_CFLAGS += -DARCH_SUPPORTS_SECCOMP
-endif
+		android_os_cts_SeccompTest.cpp \
+		seccomp-tests/tests/seccomp_bpf_tests.c \
+		seccomp_sample_program.cpp
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
diff --git a/tests/tests/os/jni/android_os_cts_OSFeatures.cpp b/tests/tests/os/jni/android_os_cts_OSFeatures.cpp
index 153fb27..f734bab 100644
--- a/tests/tests/os/jni/android_os_cts_OSFeatures.cpp
+++ b/tests/tests/os/jni/android_os_cts_OSFeatures.cpp
@@ -82,42 +82,13 @@
     return WIFSIGNALED(status) && (WTERMSIG(status) == SIGSYS);
 }
 
-jboolean android_os_cts_OSFeatures_needsSeccompSupport(JNIEnv*, jobject)
-{
-#if !defined(ARCH_SUPPORTS_SECCOMP)
-    // Seccomp support is only available for ARM, x86, x86_64.
-    // This define is controlled by the Android.mk.
-    return false;
-#endif
-
-    int major;
-    int minor;
-    struct utsname uts;
-    if (uname(&uts) == -1) {
-        return false;
-    }
-
-    if (sscanf(uts.release, "%d.%d", &major, &minor) != 2) {
-        return false;
-    }
-
-    // Kernels before 3.8 don't have seccomp
-    if ((major < 3) || ((major == 3) && (minor < 8))) {
-        return false;
-    }
-
-    return true;
-}
-
 static JNINativeMethod gMethods[] = {
     {  "getNoNewPrivs", "()I",
             (void *) android_os_cts_OSFeatures_getNoNewPrivs  },
     {  "prctlCapBsetRead", "(I)I",
             (void *) android_os_cts_OSFeatures_prctlCapBsetRead },
     {  "hasSeccompSupport", "()Z",
-            (void *) android_os_cts_OSFeatures_hasSeccompSupport  },
-    {  "needsSeccompSupport", "()Z",
-            (void *) android_os_cts_OSFeatures_needsSeccompSupport  }
+            (void *) android_os_cts_OSFeatures_hasSeccompSupport  }
 };
 
 int register_android_os_cts_OSFeatures(JNIEnv* env)
diff --git a/tests/tests/os/src/android/os/cts/OSFeatures.java b/tests/tests/os/src/android/os/cts/OSFeatures.java
index 9c4660c..7c1eb82 100644
--- a/tests/tests/os/src/android/os/cts/OSFeatures.java
+++ b/tests/tests/os/src/android/os/cts/OSFeatures.java
@@ -24,5 +24,4 @@
     public static native int getNoNewPrivs();
     public static native int prctlCapBsetRead(int i);
     public static native boolean hasSeccompSupport();
-    public static native boolean needsSeccompSupport();
 }
diff --git a/tests/tests/os/src/android/os/cts/SeccompTest.java b/tests/tests/os/src/android/os/cts/SeccompTest.java
index 7376079..410d004 100644
--- a/tests/tests/os/src/android/os/cts/SeccompTest.java
+++ b/tests/tests/os/src/android/os/cts/SeccompTest.java
@@ -60,17 +60,12 @@
     }
 
     public void testSeccomp() {
-        if (OSFeatures.needsSeccompSupport()) {
-            assertTrue("Please enable seccomp support "
-                       + "in your kernel (CONFIG_SECCOMP_FILTER=y)",
-                       OSFeatures.hasSeccompSupport());
-        }
+        assertTrue("Please enable seccomp support "
+                   + "in your kernel (CONFIG_SECCOMP_FILTER=y)",
+                   OSFeatures.hasSeccompSupport());
     }
 
     public void testKernelBasicTests() {
-        if (!OSFeatures.needsSeccompSupport())
-            return;
-
         if (isRunningUnderEmulatedAbi()) {
             Log.d(TAG, "Skipping test running under an emulated ABI");
             return;
@@ -102,9 +97,6 @@
     }
 
     public void testKernelTrapTests() {
-        if (!OSFeatures.needsSeccompSupport())
-            return;
-
         final String[] tests = {
             "TRAP.dfl",
             "TRAP.ign",
@@ -114,9 +106,6 @@
     }
 
     public void testKernelPrecedenceTests() {
-        if (!OSFeatures.needsSeccompSupport())
-            return;
-
         final String[] tests = {
             "precedence.allow_ok",
             "precedence.kill_is_highest",
@@ -133,9 +122,6 @@
 
     /* // The SECCOMP_RET_TRACE does not work under Android Arm32.
     public void testKernelTraceTests() {
-        if (!OSFeatures.needsSeccompSupport())
-            return;
-
         final String[] tests = {
             "TRACE_poke.read_has_side_effects",
             "TRACE_poke.getpid_runs_normally",
@@ -148,9 +134,6 @@
     */
 
     public void testKernelTSYNCTests() {
-        if (!OSFeatures.needsSeccompSupport())
-            return;
-
         if (isRunningUnderEmulatedAbi()) {
             Log.d(TAG, "Skipping test running under an emulated ABI");
             return;
@@ -191,9 +174,6 @@
      */
     public void testIsolatedServicePolicy() throws InterruptedException, ExecutionException,
            RemoteException {
-        if (!OSFeatures.needsSeccompSupport())
-            return;
-
         if (isRunningUnderEmulatedAbi()) {
             Log.d(TAG, "Skipping test running under an emulated ABI");
             return;
@@ -222,9 +202,6 @@
      */
     public void testViolateIsolatedServicePolicy() throws InterruptedException,
            ExecutionException, RemoteException {
-        if (!OSFeatures.needsSeccompSupport())
-            return;
-
         if (isRunningUnderEmulatedAbi()) {
             Log.d(TAG, "Skipping test running under an emulated ABI");
             return;
diff --git a/tests/tests/provider/src/android/provider/cts/BlockedNumberBackupRestoreTest.java b/tests/tests/provider/src/android/provider/cts/BlockedNumberBackupRestoreTest.java
index ed4d5d5..5ea4caf 100644
--- a/tests/tests/provider/src/android/provider/cts/BlockedNumberBackupRestoreTest.java
+++ b/tests/tests/provider/src/android/provider/cts/BlockedNumberBackupRestoreTest.java
@@ -20,13 +20,10 @@
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.provider.BlockedNumberContract;
 import android.telecom.Log;
 
-import java.util.Objects;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 /**
  * CTS tests for backup and restore of blocked numbers using local transport.
  */
@@ -40,13 +37,12 @@
             "android/com.android.internal.backup.LocalTransport";
     private static final String BLOCKED_NUMBERS_PROVIDER_PACKAGE =
             "com.android.providers.blockednumber";
-    private static final Pattern BMGR_ENABLED_PATTERN = Pattern.compile(
-            "^Backup Manager currently (enabled|disabled)$");
 
     private ContentResolver mContentResolver;
     private Context mContext;
     private UiAutomation mUiAutomation;
     private String mOldTransport;
+    private boolean mHasFeature;
 
     @Override
     protected void setUp() throws Exception {
@@ -56,26 +52,34 @@
         mContentResolver = mContext.getContentResolver();
         mUiAutomation = getInstrumentation().getUiAutomation();
 
-        ProviderTestUtils.setDefaultSmsApp(true, mContext.getPackageName(), mUiAutomation);
+        mHasFeature = isFeatureSupported();
 
-        mOldTransport = ProviderTestUtils.setBackupTransport(LOCAL_BACKUP_COMPONENT, mUiAutomation);
-        clearBlockedNumbers();
-        wipeBackup();
+        if (mHasFeature) {
+            ProviderTestUtils.setDefaultSmsApp(true, mContext.getPackageName(), mUiAutomation);
+
+            mOldTransport = ProviderTestUtils.setBackupTransport(
+                    LOCAL_BACKUP_COMPONENT, mUiAutomation);
+            clearBlockedNumbers();
+            wipeBackup();
+        }
     }
 
     @Override
     protected void tearDown() throws Exception {
-        wipeBackup();
-        clearBlockedNumbers();
-        ProviderTestUtils.setBackupTransport(mOldTransport, mUiAutomation);
-        ProviderTestUtils.setDefaultSmsApp(false, mContext.getPackageName(), mUiAutomation);
+        if (mHasFeature) {
+            wipeBackup();
+            clearBlockedNumbers();
+            ProviderTestUtils.setBackupTransport(mOldTransport, mUiAutomation);
+            ProviderTestUtils.setDefaultSmsApp(false, mContext.getPackageName(), mUiAutomation);
+        }
 
         super.tearDown();
     }
 
     public void testBackupAndRestoreForSingleNumber() throws Exception {
-        if (!ProviderTestUtils.hasBackupTransport(LOCAL_BACKUP_COMPONENT, mUiAutomation)) {
+        if (!mHasFeature) {
             Log.i(TAG, "skipping BlockedNumberBackupRestoreTest");
+            return;
         }
 
         Log.i(TAG, "Adding blocked numbers.");
@@ -94,8 +98,9 @@
     }
 
     public void testBackupAndRestoreWithDeletion() throws Exception {
-        if (!ProviderTestUtils.hasBackupTransport(LOCAL_BACKUP_COMPONENT, mUiAutomation)) {
+        if (!mHasFeature) {
             Log.i(TAG, "skipping BlockedNumberBackupRestoreTest");
+            return;
         }
 
         Log.i(TAG, "Adding blocked numbers.");
@@ -122,6 +127,11 @@
         verifyBlockedNumbers("223456789", "323456789");
     }
 
+    private boolean isFeatureSupported() throws Exception {
+        return ProviderTestUtils.hasBackupTransport(LOCAL_BACKUP_COMPONENT, mUiAutomation)
+                && mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
+    }
+
     private void insertBlockedNumber(String number) {
         ContentValues cv = new ContentValues();
         cv.put(BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER, number);