| Index: chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java
|
| diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java
|
| index 375b77b55635f06f7bcff8507ce08de5a8481cbb..7b021ebe565c5843801473072f1c60b80309ed8c 100644
|
| --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java
|
| +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/ChromeInstrumentationTestRunner.java
|
| @@ -11,18 +11,25 @@ import android.text.TextUtils;
|
| import com.google.android.gms.common.ConnectionResult;
|
| import com.google.android.gms.common.GoogleApiAvailability;
|
|
|
| +import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.BaseChromiumInstrumentationTestRunner;
|
| import org.chromium.base.test.BaseTestResult;
|
| import org.chromium.base.test.util.DisableIfSkipCheck;
|
| import org.chromium.base.test.util.RestrictionSkipCheck;
|
| import org.chromium.chrome.browser.ChromeVersionInfo;
|
| +import org.chromium.chrome.browser.vr_shell.VrClassesWrapper;
|
| +import org.chromium.chrome.browser.vr_shell.VrDaydreamApi;
|
| import org.chromium.chrome.test.util.ChromeDisableIf;
|
| import org.chromium.chrome.test.util.ChromeRestriction;
|
| import org.chromium.policy.test.annotations.Policies;
|
| import org.chromium.ui.base.DeviceFormFactor;
|
|
|
| +import java.lang.reflect.Constructor;
|
| import java.lang.reflect.InvocationTargetException;
|
| -import java.lang.reflect.Method;
|
| +import java.util.concurrent.Callable;
|
| +import java.util.concurrent.CancellationException;
|
| +import java.util.concurrent.ExecutionException;
|
| +import java.util.concurrent.FutureTask;
|
|
|
| /**
|
| * An Instrumentation test runner that optionally spawns a test HTTP server.
|
| @@ -50,30 +57,58 @@ public class ChromeInstrumentationTestRunner extends BaseChromiumInstrumentation
|
| }
|
|
|
| private class ChromeRestrictionSkipCheck extends RestrictionSkipCheck {
|
| + private VrDaydreamApi mDaydreamApi;
|
| + private boolean mAttemptedToGetApi;
|
|
|
| public ChromeRestrictionSkipCheck(Context targetContext) {
|
| super(targetContext);
|
| }
|
|
|
| + @SuppressWarnings("unchecked")
|
| + private VrDaydreamApi getDaydreamApi() {
|
| + if (!mAttemptedToGetApi) {
|
| + mAttemptedToGetApi = true;
|
| + try {
|
| + Class<? extends VrClassesWrapper> vrClassesBuilderClass =
|
| + (Class<? extends VrClassesWrapper>) Class.forName(
|
| + "org.chromium.chrome.browser.vr_shell.VrClassesWrapperImpl");
|
| + Constructor<?> vrClassesBuilderConstructor =
|
| + vrClassesBuilderClass.getConstructor(Context.class);
|
| + VrClassesWrapper vrClassesBuilder =
|
| + (VrClassesWrapper) vrClassesBuilderConstructor.newInstance(
|
| + getTargetContext());
|
| + mDaydreamApi = vrClassesBuilder.createVrDaydreamApi();
|
| + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
|
| + | IllegalArgumentException | InvocationTargetException
|
| + | NoSuchMethodException e) {
|
| + return null;
|
| + }
|
| + }
|
| + return mDaydreamApi;
|
| + }
|
| +
|
| private boolean isDaydreamReady() {
|
| - // Might be compiled without the GVR SDK, and thus the NDK, so
|
| - // use reflection to try to get the class and call its static
|
| - // method.
|
| - Class<?> daydreamApi;
|
| - try {
|
| - daydreamApi = Class.forName("com.google.vr.ndk.base.DaydreamApi");
|
| - } catch (ClassNotFoundException e) {
|
| + return getDaydreamApi() == null ? false :
|
| + getDaydreamApi().isDaydreamReadyDevice();
|
| + }
|
| +
|
| + private boolean isDaydreamViewPaired() {
|
| + if (getDaydreamApi() == null) {
|
| return false;
|
| }
|
| -
|
| + // isDaydreamCurrentViewer() creates a concrete instance of DaydreamApi,
|
| + // which can only be done on the main thread
|
| + FutureTask<Boolean> checker = new FutureTask<Boolean>(new Callable<Boolean>() {
|
| + @Override
|
| + public Boolean call() {
|
| + return getDaydreamApi().isDaydreamCurrentViewer();
|
| + }
|
| + });
|
| + ThreadUtils.runOnUiThreadBlocking(checker);
|
| try {
|
| - Method platformCheck = daydreamApi.getMethod(
|
| - "isDaydreamReadyPlatform", Context.class);
|
| - Boolean isDaydream = (Boolean) platformCheck.invoke(
|
| - daydreamApi, getTargetContext());
|
| - return isDaydream.booleanValue();
|
| - } catch (NoSuchMethodException | SecurityException | IllegalAccessException
|
| - | IllegalArgumentException | InvocationTargetException e) {
|
| + return checker.get().booleanValue();
|
| + } catch (CancellationException | InterruptedException | ExecutionException
|
| + | IllegalArgumentException e) {
|
| return false;
|
| }
|
| }
|
| @@ -114,6 +149,11 @@ public class ChromeInstrumentationTestRunner extends BaseChromiumInstrumentation
|
| return true;
|
| }
|
| }
|
| + if (TextUtils.equals(restriction,
|
| + ChromeRestriction.RESTRICTION_TYPE_DAYDREAM_VIEW)
|
| + && !isDaydreamViewPaired()) {
|
| + return true;
|
| + }
|
| return false;
|
| }
|
| }
|
|
|