Commit 91a0deb0 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

Revert "Check if ARCore is installed or needs update."

This reverts commit 703de90c.

Reason for revert: lint errors (http://crbug.com/852189)

Original change's description:
> Check if ARCore is installed or needs update.
> 
> When requesting a session and after the camera permission is confirmed
> to have been granted, check if ARCore is installed and if the version
> used in Chromium is compatible with it. If ARCore is not installed
> or an update is required, a prompt will be shown.
> 
> Bug: 838954
> Change-Id: I35ae39041e7958743bba9cc1c71f5af817bf4240
> Reviewed-on: https://chromium-review.googlesource.com/1074494
> Reviewed-by: Theresa <twellington@chromium.org>
> Reviewed-by: agrieve <agrieve@chromium.org>
> Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
> Reviewed-by: Peter Kasting <pkasting@chromium.org>
> Reviewed-by: Evan Stade <estade@chromium.org>
> Reviewed-by: Klaus Weidner <klausw@chromium.org>
> Commit-Queue: Iker Jamardo <ijamardo@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#566589}

TBR=ddorwin@chromium.org,vollick@chromium.org,pkasting@chromium.org,yfriedman@chromium.org,bshe@chromium.org,mthiesse@chromium.org,estade@chromium.org,twellington@chromium.org,agrieve@chromium.org,klausw@chromium.org,billorr@chromium.org,lincolnfrog@chromium.org,ijamardo@chromium.org

Change-Id: I1f88a1de68d4929a842a4c7bf95aa90a7f48bcba
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 838954
Bug: 852189
Reviewed-on: https://chromium-review.googlesource.com/1098335Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566635}
parent 7006136b
......@@ -4,23 +4,12 @@
package org.chromium.chrome.browser.vr;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder;
import org.chromium.chrome.browser.tab.Tab;
/**
* Provides ARCore classes access to java-related app functionality.
......@@ -28,21 +17,6 @@ import org.chromium.chrome.browser.tab.Tab;
@JNINamespace("vr")
public class ArCoreJavaUtils {
private static final int MIN_SDK_VERSION = Build.VERSION_CODES.N;
private static final String AR_CORE_PACKAGE = "com.google.ar.core";
private static final String METADATA_KEY_APP_TYPE = AR_CORE_PACKAGE;
private static final String METADATA_KEY_MIN_APK_VERSION = "com.google.ar.core.min_apk_version";
private static final int ARCORE_NOT_INSTALLED_VERSION_CODE = -1;
private static final String AR_CORE_MARKET_URI = "market://details?id=" + AR_CORE_PACKAGE;
// TODO(https://crbug.com/850840): Listen to ActivityOnResult to know when
// the intent to install ARCore returns.
private static final int AR_CORE_INSTALL_RESULT = -1;
private enum ArCoreInstallStatus { ARCORE_NEEDS_UPDATE, ARCORE_NOT_INSTALLED, ARCORE_INSTALLED }
private long mNativeArCoreJavaUtils = 0;
private boolean mAppInfoInitialized = false;
private int mAppMinArCoreApkVersionCode = ARCORE_NOT_INSTALLED_VERSION_CODE;
/**
* Gets the current application context.
......@@ -64,117 +38,4 @@ public class ArCoreJavaUtils {
private static boolean shouldLoadArCoreSdk() {
return Build.VERSION.SDK_INT >= MIN_SDK_VERSION;
}
@CalledByNative
private static ArCoreJavaUtils create(long nativeArCoreJavaUtils) {
ThreadUtils.assertOnUiThread();
return new ArCoreJavaUtils(nativeArCoreJavaUtils);
}
private ArCoreJavaUtils(long nativeArCoreJavaUtils) {
mNativeArCoreJavaUtils = nativeArCoreJavaUtils;
initializeAppInfo();
}
@CalledByNative
private void onNativeDestroy() {
mNativeArCoreJavaUtils = 0;
}
private void initializeAppInfo() {
Context context = getApplicationContext();
PackageManager packageManager = context.getPackageManager();
String packageName = context.getPackageName();
Bundle metadata;
try {
metadata = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
.metaData;
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalStateException("Could not load application package metadata", e);
}
if (metadata.containsKey(METADATA_KEY_MIN_APK_VERSION)) {
mAppMinArCoreApkVersionCode = metadata.getInt(METADATA_KEY_MIN_APK_VERSION);
} else {
throw new IllegalStateException(
"Application manifest must contain meta-data " + METADATA_KEY_MIN_APK_VERSION);
}
mAppInfoInitialized = true;
}
private int getArCoreApkVersionNumber() {
try {
PackageInfo info = getApplicationContext().getPackageManager().getPackageInfo(
AR_CORE_PACKAGE, PackageManager.GET_SERVICES);
int version = info.versionCode;
if (version == 0) {
return ARCORE_NOT_INSTALLED_VERSION_CODE;
}
return version;
} catch (PackageManager.NameNotFoundException e) {
return ARCORE_NOT_INSTALLED_VERSION_CODE;
}
}
private ArCoreInstallStatus getArCoreInstallStatus() {
assert mAppInfoInitialized;
int arCoreApkVersionNumber = getArCoreApkVersionNumber();
if (arCoreApkVersionNumber == ARCORE_NOT_INSTALLED_VERSION_CODE) {
return ArCoreInstallStatus.ARCORE_NOT_INSTALLED;
} else if (arCoreApkVersionNumber == 0
|| arCoreApkVersionNumber < mAppMinArCoreApkVersionCode) {
return ArCoreInstallStatus.ARCORE_NEEDS_UPDATE;
}
return ArCoreInstallStatus.ARCORE_INSTALLED;
}
@CalledByNative
private boolean shouldRequestInstallSupportedArCore() {
return getArCoreInstallStatus() != ArCoreInstallStatus.ARCORE_INSTALLED;
}
@CalledByNative
private void requestInstallSupportedArCore(final Tab tab) {
assert shouldRequestInstallSupportedArCore();
ArCoreInstallStatus arcoreInstallStatus = getArCoreInstallStatus();
final Activity activity = tab.getActivity();
String infobarText = null;
String buttonText = null;
switch (arcoreInstallStatus) {
case ARCORE_NOT_INSTALLED:
infobarText = activity.getString(R.string.ar_core_check_infobar_install_text);
buttonText = activity.getString(R.string.app_banner_install);
break;
case ARCORE_NEEDS_UPDATE:
infobarText = activity.getString(R.string.ar_core_check_infobar_update_text);
buttonText = activity.getString(R.string.update_from_market);
break;
case ARCORE_INSTALLED:
assert false;
break;
}
SimpleConfirmInfoBarBuilder.Listener listener = new SimpleConfirmInfoBarBuilder.Listener() {
@Override
public void onInfoBarDismissed() {
if (mNativeArCoreJavaUtils != 0) {
nativeOnRequestInstallSupportedArCoreCanceled(mNativeArCoreJavaUtils);
}
}
@Override
public boolean onInfoBarButtonClicked(boolean isPrimary) {
activity.startActivityForResult(
new Intent(Intent.ACTION_VIEW, Uri.parse(AR_CORE_MARKET_URI)),
AR_CORE_INSTALL_RESULT);
return false;
}
};
// TODO(ijamardo, https://crbug.com/838833): Add icon for AR info bar.
SimpleConfirmInfoBarBuilder.create(tab, listener, InfoBarIdentifier.AR_CORE_UPGRADE_ANDROID,
R.drawable.vr_services, infobarText, buttonText, null, true);
}
private native void nativeOnRequestInstallSupportedArCoreCanceled(long nativeArCoreJavaUtils);
}
......@@ -3317,14 +3317,6 @@ However, you aren’t invisible. Going incognito doesn’t hide your browsing fr
Update
</message>
<!-- ARCore check infobar -->
<message name="IDS_AR_CORE_CHECK_INFOBAR_INSTALL_TEXT" desc="Text to be displayed in the ARCore check infobar. When a WebXR page is loaded, if ARCore is needed to display AR content and it is not installed, an infobar will be shown to the user prompting them to install ARCore.">
To view augmented reality content, install ARCore
</message>
<message name="IDS_AR_CORE_CHECK_INFOBAR_UPDATE_TEXT" desc="Text to be displayed in the ARCore check infobar. When a WebXR page is loaded, if ARCore is needed to display AR content and the installed ARCore is not up to date to the version needed by the implementation, an infobar will be shown to the user prompting them to update ARCore.">
To view augmented reality content, update ARCore
</message>
<!-- Custom Context Menu Informations -->
<message name="IDS_CONTEXTMENU_IMAGE_TITLE" desc="The title of a context menu tab when the item pressed contains more than one type. This indicates that all the actions are related to the image.">
IMAGE
......
......@@ -10,10 +10,8 @@
#include "base/optional.h"
#include "base/task_scheduler/post_task.h"
#include "base/trace_event/trace_event.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/android/vr/arcore_device/arcore_gl.h"
#include "chrome/browser/android/vr/arcore_device/arcore_gl_thread.h"
#include "chrome/browser/android/vr/arcore_device/arcore_java_utils.h"
#include "chrome/browser/android/vr/mailbox_to_surface_bridge.h"
#include "chrome/browser/permissions/permission_manager.h"
#include "chrome/browser/permissions/permission_result.h"
......@@ -87,8 +85,6 @@ ARCoreDevice::ARCoreDevice()
weak_ptr_factory_(this) {
SetVRDisplayInfo(CreateVRDisplayInfo(GetId()));
arcore_java_utils_ = std::make_unique<vr::ArCoreJavaUtils>(this);
// TODO(https://crbug.com/836524) clean up usage of mailbox bridge
// and extract the methods in this class that interact with ARCore API
// into a separate class that implements the ARCore interface.
......@@ -122,9 +118,6 @@ void ARCoreDevice::ResumeTracking() {
is_paused_ = false;
if (!deferred_request_install_supported_arcore_callbacks_.empty())
CallDeferredRequestInstallSupportedARCore();
if (!is_arcore_gl_initialized_)
return;
......@@ -176,97 +169,16 @@ void ARCoreDevice::RequestSession(
base::BindOnce(&ARCoreDevice::OnRequestSessionPreconditionsComplete,
GetWeakPtr(), std::move(callback));
SatisfyRequestSessionPreconditions(
render_process_id, render_frame_id, has_user_activation,
std::move(preconditions_complete_callback));
}
void ARCoreDevice::SatisfyRequestSessionPreconditions(
int render_process_id,
int render_frame_id,
bool has_user_activation,
mojom::VRDisplayHost::RequestSessionCallback callback) {
DCHECK(IsOnMainThread());
DCHECK(is_arcore_gl_thread_initialized_);
if (!arcore_java_utils_->ShouldRequestInstallSupportedArCore()) {
// TODO(https://crbug.com/845792): Consider calling a method to ask for the
// appropriate permissions.
// ARCore sessions require camera permission.
RequestCameraPermission(
render_process_id, render_frame_id, has_user_activation,
base::BindOnce(&ARCoreDevice::OnRequestCameraPermissionComplete,
GetWeakPtr(), std::move(callback)));
return;
}
// ARCore is not installed or requires an update. Store the callback to be
// processed later and only the first request session will trigger the
// request to install or update of the ARCore APK.
auto deferred_callback =
base::BindOnce(&ARCoreDevice::OnRequestARCoreInstallOrUpdateComplete,
GetWeakPtr(), render_process_id, render_frame_id,
has_user_activation, std::move(callback));
deferred_request_install_supported_arcore_callbacks_.push_back(
std::move(deferred_callback));
if (deferred_request_install_supported_arcore_callbacks_.size() > 1)
return;
content::RenderFrameHost* render_frame_host =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
DCHECK(render_frame_host);
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
DCHECK(web_contents);
TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents);
DCHECK(tab_android);
base::android::ScopedJavaLocalRef<jobject> j_tab_android =
tab_android->GetJavaObject();
DCHECK(!j_tab_android.is_null());
arcore_java_utils_->RequestInstallSupportedArCore(j_tab_android);
}
void ARCoreDevice::OnRequestInstallSupportedARCoreCanceled() {
DCHECK(IsOnMainThread());
DCHECK(is_arcore_gl_thread_initialized_);
DCHECK(!deferred_request_install_supported_arcore_callbacks_.empty());
CallDeferredRequestInstallSupportedARCore();
}
void ARCoreDevice::CallDeferredRequestInstallSupportedARCore() {
DCHECK(IsOnMainThread());
DCHECK(is_arcore_gl_thread_initialized_);
DCHECK(!deferred_request_install_supported_arcore_callbacks_.empty());
for (auto& deferred_callback :
deferred_request_install_supported_arcore_callbacks_) {
std::move(deferred_callback).Run();
}
deferred_request_install_supported_arcore_callbacks_.clear();
}
void ARCoreDevice::OnRequestARCoreInstallOrUpdateComplete(
int render_process_id,
int render_frame_id,
bool has_user_activation,
mojom::VRDisplayHost::RequestSessionCallback callback) {
DCHECK(IsOnMainThread());
DCHECK(is_arcore_gl_thread_initialized_);
if (arcore_java_utils_->ShouldRequestInstallSupportedArCore()) {
std::move(callback).Run(false);
return;
}
// TODO(https://crbug.com/838954): Check if ARCore is installed and is the
// correct version. This must happen in the main thread.
// TODO(https://crbug.com/845792): Consider calling a method to ask for the
// appropriate permissions.
// ARCore sessions require camera permission.
RequestCameraPermission(
render_process_id, render_frame_id, has_user_activation,
base::BindOnce(&ARCoreDevice::OnRequestCameraPermissionComplete,
GetWeakPtr(), std::move(callback)));
GetWeakPtr(), std::move(preconditions_complete_callback)));
}
void ARCoreDevice::OnRequestCameraPermissionComplete(
......@@ -334,13 +246,13 @@ void ARCoreDevice::RequestCameraPermission(
content::RenderFrameHost* rfh =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
// The RFH may have been destroyed by the time the request is processed.
DCHECK(rfh);
if (!rfh) {
std::move(callback).Run(false);
return;
}
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(rfh);
DCHECK(web_contents);
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
......
......@@ -15,7 +15,6 @@
namespace vr {
class MailboxToSurfaceBridge;
class ArCoreJavaUtils;
} // namespace vr
namespace content {
......@@ -44,8 +43,6 @@ class ARCoreDevice : public VRDeviceBase {
return weak_ptr_factory_.GetWeakPtr();
}
void OnRequestInstallSupportedARCoreCanceled();
private:
// VRDeviceBase implementation
bool ShouldPauseTrackingWhenFrameDataRestricted() override;
......@@ -82,17 +79,6 @@ class ARCoreDevice : public VRDeviceBase {
bool IsOnMainThread();
void SatisfyRequestSessionPreconditions(
int render_process_id,
int render_frame_id,
bool has_user_activation,
mojom::VRDisplayHost::RequestSessionCallback callback);
void OnRequestARCoreInstallOrUpdateComplete(
int render_process_id,
int render_frame_id,
bool has_user_activation,
mojom::VRDisplayHost::RequestSessionCallback callback);
void CallDeferredRequestInstallSupportedARCore();
void RequestCameraPermission(
int render_process_id,
int render_frame_id,
......@@ -115,7 +101,6 @@ class ARCoreDevice : public VRDeviceBase {
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
std::unique_ptr<vr::MailboxToSurfaceBridge> mailbox_bridge_;
std::unique_ptr<ARCoreGlThread> arcore_gl_thread_;
std::unique_ptr<vr::ArCoreJavaUtils> arcore_java_utils_;
bool is_arcore_gl_thread_initialized_ = false;
bool is_arcore_gl_initialized_ = false;
......@@ -126,10 +111,6 @@ class ARCoreDevice : public VRDeviceBase {
// not be resumed.
bool is_paused_ = false;
// TODO(https://)
std::vector<base::OnceCallback<void()>>
deferred_request_install_supported_arcore_callbacks_;
// Must be last.
base::WeakPtrFactory<ARCoreDevice> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ARCoreDevice);
......
......@@ -4,9 +4,7 @@
#include "chrome/browser/android/vr/arcore_device/arcore_java_utils.h"
#include "chrome/browser/android/vr/arcore_device/arcore_device.h"
#include "chrome/browser/android/vr/arcore_device/arcore_shim.h"
#include "chrome/browser/vr/service/vr_device_manager.h"
#include "jni/ArCoreJavaUtils_jni.h"
using base::android::AttachCurrentThread;
......@@ -27,43 +25,4 @@ bool ArCoreJavaUtils::EnsureLoaded() {
return LoadArCoreSdk();
}
ArCoreJavaUtils::ArCoreJavaUtils(device::ARCoreDevice* arcore_device)
: arcore_device_(arcore_device) {
DCHECK(arcore_device_);
JNIEnv* env = AttachCurrentThread();
if (!env)
return;
ScopedJavaLocalRef<jobject> j_arcore_java_utils =
Java_ArCoreJavaUtils_create(env, (jlong)this);
if (j_arcore_java_utils.is_null())
return;
j_arcore_java_utils_.Reset(j_arcore_java_utils);
}
ArCoreJavaUtils::~ArCoreJavaUtils() {
JNIEnv* env = AttachCurrentThread();
Java_ArCoreJavaUtils_onNativeDestroy(env, j_arcore_java_utils_);
}
void ArCoreJavaUtils::OnRequestInstallSupportedArCoreCanceled(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
arcore_device_->OnRequestInstallSupportedARCoreCanceled();
}
bool ArCoreJavaUtils::ShouldRequestInstallSupportedArCore() {
JNIEnv* env = AttachCurrentThread();
return Java_ArCoreJavaUtils_shouldRequestInstallSupportedArCore(
env, j_arcore_java_utils_);
}
void ArCoreJavaUtils::RequestInstallSupportedArCore(
base::android::ScopedJavaLocalRef<jobject> j_tab_android) {
DCHECK(ShouldRequestInstallSupportedArCore());
JNIEnv* env = AttachCurrentThread();
Java_ArCoreJavaUtils_requestInstallSupportedArCore(env, j_arcore_java_utils_,
j_tab_android);
}
} // namespace vr
......@@ -7,32 +7,14 @@
#include <jni.h>
#include "base/android/scoped_java_ref.h"
#include "base/memory/weak_ptr.h"
namespace device {
class ARCoreDevice;
}
namespace vr {
class ArCoreJavaUtils {
public:
static base::android::ScopedJavaLocalRef<jobject> GetApplicationContext();
static bool EnsureLoaded();
explicit ArCoreJavaUtils(device::ARCoreDevice* arcore_device);
~ArCoreJavaUtils();
bool ShouldRequestInstallSupportedArCore();
void RequestInstallSupportedArCore(
base::android::ScopedJavaLocalRef<jobject> j_tab_android);
// Method called from the Java side
void OnRequestInstallSupportedArCoreCanceled(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
private:
device::ARCoreDevice* arcore_device_;
base::android::ScopedJavaGlobalRef<jobject> j_arcore_java_utils_;
static bool EnsureLoaded();
};
} // namespace vr
......
......@@ -151,7 +151,6 @@ class InfoBarDelegate {
INSTALLABLE_AMBIENT_BADGE_INFOBAR_DELEGATE = 80,
PAGE_LOAD_CAPPING_INFOBAR_DELEGATE = 81,
DOWNLOAD_PROGRESS_INFOBAR_ANDROID = 82,
AR_CORE_UPGRADE_ANDROID = 83,
};
// Describes navigation events, used to decide whether infobars should be
......
......@@ -24013,7 +24013,6 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="79" label="NEAR_OOM_INFOBAR_ANDROID"/>
<int value="80" label="INSTALLABLE_AMBIENT_BADGE_INFOBAR_DELEGATE"/>
<int value="81" label="PAGE_LOAD_CAPPING_INFOBAR_DELEGATE"/>
<int value="83" label="AR_CORE_UPGRADE_ANDROID"/>
</enum>
<enum name="InfoBarResponse">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment