Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrDaydreamApiImpl.java

Issue 2668003006: Add restriction for running tests only with Daydream View headset (Closed)
Patch Set: Address tedchoc@ comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrDaydreamApiImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrDaydreamApiImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrDaydreamApiImpl.java
index 74fa03eb73051b8cb89e1492f592b5437e249e69..20f8aec7038ddeb6a32dec1ef096aee497e56199 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrDaydreamApiImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrDaydreamApiImpl.java
@@ -7,32 +7,38 @@ package org.chromium.chrome.browser.vr_shell;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
import android.os.StrictMode;
import com.google.vr.ndk.base.DaydreamApi;
import com.google.vr.ndk.base.GvrApi;
+import junit.framework.Assert;
+
+import org.chromium.ui.base.WindowAndroid;
+
+
/**
* A wrapper for DaydreamApi. Note that we have to recreate the DaydreamApi instance each time we
* use it, or API calls begin to silently fail.
*/
public class VrDaydreamApiImpl implements VrDaydreamApi {
private static final String TAG = "VrDaydreamApiImpl";
- private final Activity mActivity;
+ private final Context mContext;
- public VrDaydreamApiImpl(Activity activity) {
- mActivity = activity;
+ public VrDaydreamApiImpl(Context context) {
+ mContext = context;
}
@Override
public boolean isDaydreamReadyDevice() {
- return DaydreamApi.isDaydreamReadyPlatform(mActivity);
+ return DaydreamApi.isDaydreamReadyPlatform(mContext);
}
@Override
public boolean registerDaydreamIntent(final PendingIntent pendingIntent) {
- DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
+ DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return false;
daydreamApi.registerDaydreamIntent(pendingIntent);
daydreamApi.close();
@@ -41,7 +47,7 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
@Override
public boolean unregisterDaydreamIntent() {
- DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
+ DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return false;
daydreamApi.unregisterDaydreamIntent();
daydreamApi.close();
@@ -55,7 +61,7 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
@Override
public boolean launchInVr(final PendingIntent pendingIntent) {
- DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
+ DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return false;
daydreamApi.launchInVr(pendingIntent);
daydreamApi.close();
@@ -64,16 +70,18 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
@Override
public boolean exitFromVr(int requestCode, final Intent intent) {
- DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
+ DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return false;
- daydreamApi.exitFromVr(mActivity, requestCode, intent);
+ Activity activity = WindowAndroid.activityFromContext(mContext);
+ Assert.assertNotNull(activity);
+ daydreamApi.exitFromVr(activity, requestCode, intent);
daydreamApi.close();
return true;
}
@Override
public Boolean isDaydreamCurrentViewer() {
- DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
+ DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return false;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
// If this is the first time any app reads the daydream config file, daydream may create its
@@ -91,7 +99,7 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
@Override
public void launchVrHomescreen() {
- DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
+ DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return;
daydreamApi.launchVrHomescreen();
daydreamApi.close();

Powered by Google App Engine
This is Rietveld 408576698