OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.vr_shell; | 5 package org.chromium.chrome.browser.vr_shell; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
9 import android.content.ComponentName; | 9 import android.content.ComponentName; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.content.pm.ActivityInfo; | 12 import android.content.pm.ActivityInfo; |
13 import android.content.res.Configuration; | 13 import android.content.res.Configuration; |
14 import android.net.Uri; | |
14 import android.os.Build; | 15 import android.os.Build; |
15 import android.os.Handler; | 16 import android.os.Handler; |
16 import android.os.StrictMode; | 17 import android.os.StrictMode; |
17 import android.os.SystemClock; | 18 import android.os.SystemClock; |
18 import android.support.annotation.IntDef; | 19 import android.support.annotation.IntDef; |
19 import android.view.Choreographer; | 20 import android.view.Choreographer; |
20 import android.view.Choreographer.FrameCallback; | 21 import android.view.Choreographer.FrameCallback; |
21 import android.view.Display; | 22 import android.view.Display; |
22 import android.view.View; | 23 import android.view.View; |
23 import android.view.ViewGroup; | 24 import android.view.ViewGroup; |
24 import android.view.ViewGroup.LayoutParams; | 25 import android.view.ViewGroup.LayoutParams; |
25 import android.view.WindowManager; | 26 import android.view.WindowManager; |
26 import android.widget.FrameLayout; | 27 import android.widget.FrameLayout; |
27 | 28 |
28 import org.chromium.base.Log; | 29 import org.chromium.base.Log; |
30 import org.chromium.base.PackageUtils; | |
29 import org.chromium.base.VisibleForTesting; | 31 import org.chromium.base.VisibleForTesting; |
30 import org.chromium.base.annotations.CalledByNative; | 32 import org.chromium.base.annotations.CalledByNative; |
31 import org.chromium.base.annotations.JNINamespace; | 33 import org.chromium.base.annotations.JNINamespace; |
32 import org.chromium.base.library_loader.LibraryLoader; | 34 import org.chromium.base.library_loader.LibraryLoader; |
35 | |
36 import org.chromium.chrome.R; | |
33 import org.chromium.chrome.browser.ChromeActivity; | 37 import org.chromium.chrome.browser.ChromeActivity; |
34 import org.chromium.chrome.browser.ChromeFeatureList; | 38 import org.chromium.chrome.browser.ChromeFeatureList; |
35 import org.chromium.chrome.browser.ChromeTabbedActivity; | 39 import org.chromium.chrome.browser.ChromeTabbedActivity; |
40 import org.chromium.chrome.browser.infobar.InfoBarIdentifier; | |
41 import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder; | |
36 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; | 42 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
37 import org.chromium.chrome.browser.tab.Tab; | 43 import org.chromium.chrome.browser.tab.Tab; |
38 | 44 |
39 import java.lang.annotation.Retention; | 45 import java.lang.annotation.Retention; |
40 import java.lang.annotation.RetentionPolicy; | 46 import java.lang.annotation.RetentionPolicy; |
41 import java.lang.reflect.Constructor; | 47 import java.lang.reflect.Constructor; |
42 import java.lang.reflect.InvocationTargetException; | 48 import java.lang.reflect.InvocationTargetException; |
43 | 49 |
44 /** | 50 /** |
45 * Manages interactions with the VR Shell. | 51 * Manages interactions with the VR Shell. |
(...skipping 24 matching lines...) Expand all Loading... | |
70 // TODO(bshe): These should be replaced by string provided by NDK. Currently , it only available | 76 // TODO(bshe): These should be replaced by string provided by NDK. Currently , it only available |
71 // in SDK and we don't want add dependency to SDK just to get these strings. | 77 // in SDK and we don't want add dependency to SDK just to get these strings. |
72 private static final String DAYDREAM_CATEGORY = "com.google.intent.category. DAYDREAM"; | 78 private static final String DAYDREAM_CATEGORY = "com.google.intent.category. DAYDREAM"; |
73 private static final String CARDBOARD_CATEGORY = "com.google.intent.category .CARDBOARD"; | 79 private static final String CARDBOARD_CATEGORY = "com.google.intent.category .CARDBOARD"; |
74 | 80 |
75 private static final String MIN_SDK_VERSION_PARAM_NAME = "min_sdk_version"; | 81 private static final String MIN_SDK_VERSION_PARAM_NAME = "min_sdk_version"; |
76 | 82 |
77 private static final String VR_ACTIVITY_ALIAS = | 83 private static final String VR_ACTIVITY_ALIAS = |
78 "org.chromium.chrome.browser.VRChromeTabbedActivity"; | 84 "org.chromium.chrome.browser.VRChromeTabbedActivity"; |
79 | 85 |
86 private static final String VR_CORE_PACKAGE_ID = "com.google.vr.vrcore"; | |
87 private static final int VR_CORE_MIN_VERSION = 160723800; // recent: 1607228 70,160723800 | |
Bernhard Bauer
2017/02/16 12:12:51
What does that comment mean?
amp
2017/02/16 18:41:35
These were recent versions of the package. I stil
amp
2017/02/17 01:50:38
Done.
| |
88 | |
80 private static final long REENTER_VR_TIMEOUT_MS = 1000; | 89 private static final long REENTER_VR_TIMEOUT_MS = 1000; |
81 | 90 |
82 private final ChromeTabbedActivity mActivity; | 91 private final ChromeTabbedActivity mActivity; |
83 private Intent mEnterVRIntent; | 92 private Intent mEnterVRIntent; |
84 | 93 |
85 @VrSupportLevel | 94 @VrSupportLevel |
86 private int mVrSupportLevel; | 95 private int mVrSupportLevel; |
87 | 96 |
88 private final VrClassesWrapper mVrClassesWrapper; | 97 private final VrClassesWrapper mVrClassesWrapper; |
89 private VrShell mVrShell; | 98 private VrShell mVrShell; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 if (!success && !mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent()) ) { | 281 if (!success && !mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent()) ) { |
273 mVrClassesWrapper.setVrModeEnabled(false); | 282 mVrClassesWrapper.setVrModeEnabled(false); |
274 } | 283 } |
275 mRequestedWebVR = false; | 284 mRequestedWebVR = false; |
276 } | 285 } |
277 | 286 |
278 /* package */ boolean canEnterVR(Tab tab) { | 287 /* package */ boolean canEnterVR(Tab tab) { |
279 if (!LibraryLoader.isInitialized()) { | 288 if (!LibraryLoader.isInitialized()) { |
280 return false; | 289 return false; |
281 } | 290 } |
291 // TODO(amp): Figure out how this works with isVrCoreCompatible check. | |
292 int vrCoreVersion = PackageUtils.getPackageVersion(mActivity, VR_CORE_PA CKAGE_ID); | |
293 if (vrCoreVersion < VR_CORE_MIN_VERSION) { | |
294 // Assume upgrade as most comment case. | |
295 String actionText = | |
296 mActivity.getString(R.string.vr_services_check_infobar_updat e_action); | |
297 if (vrCoreVersion == -1) { | |
298 // VrCore not installed, make sure it's supported first | |
299 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | |
300 // Not supported | |
301 return false; | |
302 } | |
303 // Supported, but not installed. Ask user to install instead of upgrade. | |
304 actionText = mActivity.getString(R.string.vr_services_check_info bar_install_action); | |
305 } | |
306 SimpleConfirmInfoBarBuilder.create(tab, | |
307 new SimpleConfirmInfoBarBuilder.Listener() { | |
308 @Override | |
309 public void onInfoBarDismissed() {} | |
310 | |
311 @Override | |
312 public boolean onInfoBarButtonClicked(boolean isPrimary) { | |
313 mActivity.startActivity(new Intent(Intent.ACTION_VIE W, | |
314 Uri.parse("market://details?id=" + VR_CORE_P ACKAGE_ID))); | |
315 return false; | |
316 } | |
317 }, | |
318 InfoBarIdentifier.VR_SERVICES_UPGRADE, R.drawable.vr_service s, | |
319 mActivity.getString(R.string.vr_services_check_infobar_text, actionText), | |
320 actionText, null, true); | |
321 return false; | |
322 } | |
282 // If vr isn't in the build, or we haven't initialized yet, or vr shell is not enabled and | 323 // If vr isn't in the build, or we haven't initialized yet, or vr shell is not enabled and |
283 // this is not a web vr request, then return immediately. | 324 // this is not a web vr request, then return immediately. |
284 if (mVrSupportLevel == VR_NOT_AVAILABLE || mNativeVrShellDelegate == 0 | 325 if (mVrSupportLevel == VR_NOT_AVAILABLE || mNativeVrShellDelegate == 0 |
285 || (!isVrShellEnabled() && !(mRequestedWebVR || mListeningForWeb VrActivate))) { | 326 || (!isVrShellEnabled() && !(mRequestedWebVR || mListeningForWeb VrActivate))) { |
286 return false; | 327 return false; |
287 } | 328 } |
288 // TODO(mthiesse): When we have VR UI for opening new tabs, etc., allow VR Shell to be | 329 // TODO(mthiesse): When we have VR UI for opening new tabs, etc., allow VR Shell to be |
289 // entered without any current tabs. | 330 // entered without any current tabs. |
290 if (tab == null) { | 331 if (tab == null) { |
291 return false; | 332 return false; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 } | 669 } |
629 | 670 |
630 private native long nativeInit(); | 671 private native long nativeInit(); |
631 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result); | 672 private native void nativeSetPresentResult(long nativeVrShellDelegate, boole an result); |
632 private native void nativeDisplayActivate(long nativeVrShellDelegate); | 673 private native void nativeDisplayActivate(long nativeVrShellDelegate); |
633 private native void nativeUpdateVSyncInterval(long nativeVrShellDelegate, lo ng timebaseNanos, | 674 private native void nativeUpdateVSyncInterval(long nativeVrShellDelegate, lo ng timebaseNanos, |
634 double intervalSeconds); | 675 double intervalSeconds); |
635 private native void nativeOnPause(long nativeVrShellDelegate); | 676 private native void nativeOnPause(long nativeVrShellDelegate); |
636 private native void nativeOnResume(long nativeVrShellDelegate); | 677 private native void nativeOnResume(long nativeVrShellDelegate); |
637 } | 678 } |
OLD | NEW |