| 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 69755f3f2c2b25e6743066c92383a1a4ccccc4d8..943b61e5fd46553ba2e1ef2a6b7cc6dc13e42c48 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
|
| @@ -4,43 +4,64 @@
|
|
|
| package org.chromium.chrome.browser.vr_shell;
|
|
|
| +import android.app.Activity;
|
| import android.app.PendingIntent;
|
| -import android.content.Context;
|
| +import android.content.ComponentName;
|
| +import android.content.Intent;
|
|
|
| +import com.google.vr.ndk.base.AndroidCompat;
|
| import com.google.vr.ndk.base.DaydreamApi;
|
|
|
| import org.chromium.base.annotations.UsedByReflection;
|
|
|
| /**
|
| - * A wrapper for DaydreamApi.
|
| + * 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.
|
| */
|
| @UsedByReflection("VrShellDelegate.java")
|
| public class VrDaydreamApiImpl implements VrDaydreamApi {
|
| - private DaydreamApi mDaydreamApi;
|
| + private final Activity mActivity;
|
|
|
| @UsedByReflection("VrShellDelegate.java")
|
| - public VrDaydreamApiImpl(Context context) {
|
| - mDaydreamApi = DaydreamApi.create(context);
|
| + public VrDaydreamApiImpl(Activity activity) {
|
| + mActivity = activity;
|
| }
|
|
|
| @Override
|
| - public void registerDaydreamIntent(PendingIntent pendingIntent) {
|
| - if (mDaydreamApi != null) {
|
| - mDaydreamApi.registerDaydreamIntent(pendingIntent);
|
| - }
|
| + public void registerDaydreamIntent(final PendingIntent pendingIntent) {
|
| + DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
|
| + daydreamApi.registerDaydreamIntent(pendingIntent);
|
| + daydreamApi.close();
|
| }
|
| +
|
| @Override
|
| public void unregisterDaydreamIntent() {
|
| - if (mDaydreamApi != null) {
|
| - mDaydreamApi.unregisterDaydreamIntent();
|
| - }
|
| + DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
|
| + daydreamApi.unregisterDaydreamIntent();
|
| + daydreamApi.close();
|
| + }
|
| +
|
| + @Override
|
| + public Intent createVrIntent(final ComponentName componentName) {
|
| + return DaydreamApi.createVrIntent(componentName);
|
| + }
|
| +
|
| + @Override
|
| + public void launchInVr(final PendingIntent pendingIntent) {
|
| + DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
|
| + daydreamApi.launchInVr(pendingIntent);
|
| + daydreamApi.close();
|
| + }
|
| +
|
| + @Override
|
| + public void exitFromVr(int requestCode, final Intent intent) {
|
| + DaydreamApi daydreamApi = DaydreamApi.create(mActivity);
|
| + daydreamApi.exitFromVr(mActivity, requestCode, intent);
|
| + daydreamApi.close();
|
| }
|
|
|
| @Override
|
| - public void close() {
|
| - if (mDaydreamApi != null) {
|
| - mDaydreamApi.close();
|
| - }
|
| - mDaydreamApi = null;
|
| + public void setVrModeEnabled(boolean enabled) {
|
| + AndroidCompat.setVrModeEnabled(mActivity, enabled);
|
| }
|
| }
|
|
|