Commit 353eaeaa authored by bsheedy's avatar bsheedy Committed by Commit Bot

Add APK to simulate VR NFC scan

Adds a standalone APK that, when run, simulates a Daydream View NFC tag
scan. This is so that Telemetry can enter the VR browser without making
any modifications to Chrome, e.g. a flag.

Bug: 726906
Change-Id: I37a430c98b08dc41363fdc02b3486193b9e26fa6
Reviewed-on: https://chromium-review.googlesource.com/517682Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#476348}
parent 9aa1d083
......@@ -545,6 +545,7 @@ if (enable_vr) {
"javatests/src/org/chromium/chrome/browser/vr_shell/EmulatedVrController.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/MockVrCoreVersionCheckerImpl.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/MockVrDaydreamApi.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/NfcSimUtils.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/VrFeedbackInfoBarTest.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/VrShellTest.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java",
......@@ -579,6 +580,17 @@ if (enable_vr) {
"//third_party/WebKit/LayoutTests/resources/testharness.js",
]
}
android_library("vr_nfc_simulator_java") {
testonly = true
java_files = [
"javatests/src/org/chromium/chrome/browser/vr_shell/nfc_apk/SimNfcActivity.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/NfcSimUtils.java",
]
deps = []
}
}
# Overrides icon / name defined in chrome_java_resources.
......@@ -876,6 +888,8 @@ chrome_public_test_vr_apk_manifest =
"$root_gen_dir/chrome_public_test_vr_apk_manifest/AndroidManifest.xml"
chrome_sync_shell_test_apk_manifest =
"$root_gen_dir/chrome_sync_shell_test_apk_manifest/AndroidManifest.xml"
vr_nfc_simulator_apk_manifest =
"$root_gen_dir/vr_nfc_simulator_apk_manifest/AndroidManifest.xml"
jinja_template("chrome_public_test_apk_manifest") {
input = "javatests/AndroidManifest.xml"
......@@ -889,6 +903,12 @@ jinja_template("chrome_public_test_vr_apk_manifest") {
variables = chrome_public_jinja_variables
}
jinja_template("vr_nfc_simulator_apk_manifest") {
input = "javatests/src/org/chromium/chrome/browser/vr_shell/nfc_apk/AndroidManifest.xml"
output = vr_nfc_simulator_apk_manifest
variables = chrome_public_jinja_variables
}
jinja_template("chrome_sync_shell_test_apk_manifest") {
input = "sync_shell/javatests/AndroidManifest.xml"
output = chrome_sync_shell_test_apk_manifest
......@@ -935,6 +955,18 @@ if (enable_vr) {
]
proguard_enabled = !is_java_debug
}
android_apk("vr_nfc_simulator_apk") {
testonly = true
apk_name = "VrNfcSimulator"
android_manifest = vr_nfc_simulator_apk_manifest
android_manifest_dep = ":vr_nfc_simulator_apk_manifest"
deps = [
":vr_nfc_simulator_java",
]
proguard_enabled = false
}
}
android_library("chrome_sync_shell_test_apk_java") {
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.vr_shell;
import android.content.ComponentName;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* Utility class to simulate a Daydream View NFC tag being scanned. In its own
* class so that both instrumentation tests and the standalone APK for use with
* Telemetry can share code without the APK including instrumentation-test-only
* code.
*/
public class NfcSimUtils {
private static final String DETECTION_ACTIVITY = ".nfc.ViewerDetectionActivity";
// TODO(bsheedy): Use constants from VrCore if ever exposed
private static final String APPLICATION_RECORD_STRING = "com.google.vr.vrcore";
private static final String RESERVED_KEY = "google.vr/rsvd";
private static final String VERSION_KEY = "google.vr/ver";
private static final String DATA_KEY = "google.vr/data";
private static final ByteOrder BYTE_ORDER = ByteOrder.BIG_ENDIAN;
// Hard coded viewer ID (0x03) instead of using NfcParams and converting
// to a byte array because NfcParams were removed from the GVR SDK
private static final byte[] PROTO_BYTES = new byte[] {(byte) 0x08, (byte) 0x03};
private static final int VERSION = 123;
private static final int RESERVED = 456;
/**
* Makes an Intent that triggers VrCore as if the Daydream headset's NFC
* tag was scanned.
* @return The intent to send to VrCore to simulate an NFC scan.
*/
public static Intent makeNfcIntent() {
Intent nfcIntent = new Intent(NfcAdapter.ACTION_NDEF_DISCOVERED);
NdefMessage[] messages = new NdefMessage[] {new NdefMessage(
new NdefRecord[] {NdefRecord.createMime(RESERVED_KEY, intToByteArray(RESERVED)),
NdefRecord.createMime(VERSION_KEY, intToByteArray(VERSION)),
NdefRecord.createMime(DATA_KEY, PROTO_BYTES),
NdefRecord.createApplicationRecord(APPLICATION_RECORD_STRING)})};
nfcIntent.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, messages);
nfcIntent.setComponent(new ComponentName(
APPLICATION_RECORD_STRING, APPLICATION_RECORD_STRING + DETECTION_ACTIVITY));
return nfcIntent;
}
private static byte[] intToByteArray(int i) {
final ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
bb.order(BYTE_ORDER);
bb.putInt(i);
return bb.array();
}
}
......@@ -5,12 +5,8 @@
package org.chromium.chrome.browser.vr_shell;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.view.View;
import android.view.ViewGroup;
......@@ -19,8 +15,6 @@ import org.chromium.chrome.browser.infobar.InfoBarLayout;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;
......@@ -34,20 +28,6 @@ public class VrUtils {
public static final int POLL_TIMEOUT_SHORT_MS = 1000;
public static final int POLL_TIMEOUT_LONG_MS = 10000;
private static final String DETECTION_ACTIVITY =
".nfc.ViewerDetectionActivity";
// TODO(bsheedy): Use constants from VrCore if ever exposed
private static final String APPLICATION_RECORD_STRING = "com.google.vr.vrcore";
private static final String RESERVED_KEY = "google.vr/rsvd";
private static final String VERSION_KEY = "google.vr/ver";
private static final String DATA_KEY = "google.vr/data";
private static final ByteOrder BYTE_ORDER = ByteOrder.BIG_ENDIAN;
// Hard coded viewer ID (0x03) instead of using NfcParams and converting
// to a byte array because NfcParams were removed from the GVR SDK
private static final byte[] PROTO_BYTES = new byte[] {(byte) 0x08, (byte) 0x03};
private static final int VERSION = 123;
private static final int RESERVED = 456;
/**
* Gets the VrShellDelegate instance on the UI thread, as otherwise the
* Choreographer obtained in VrShellDelegate's constructor is for the instrumentation
......@@ -91,37 +71,12 @@ public class VrUtils {
});
}
private static byte[] intToByteArray(int i) {
final ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
bb.order(BYTE_ORDER);
bb.putInt(i);
return bb.array();
}
/**
* Makes an Intent that triggers VrCore as if the Daydream headset's NFC
* tag was scanned.
* @return The intent to send to VrCore to simulate an NFC scan.
*/
public static Intent makeNfcIntent() {
Intent nfcIntent = new Intent(NfcAdapter.ACTION_NDEF_DISCOVERED);
NdefMessage[] messages = new NdefMessage[] {new NdefMessage(
new NdefRecord[] {NdefRecord.createMime(RESERVED_KEY, intToByteArray(RESERVED)),
NdefRecord.createMime(VERSION_KEY, intToByteArray(VERSION)),
NdefRecord.createMime(DATA_KEY, PROTO_BYTES),
NdefRecord.createApplicationRecord(APPLICATION_RECORD_STRING)})};
nfcIntent.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, messages);
nfcIntent.setComponent(new ComponentName(APPLICATION_RECORD_STRING,
APPLICATION_RECORD_STRING + ".nfc.ViewerDetectionActivity"));
return nfcIntent;
}
/**
* Simulates the NFC tag of the Daydream headset being scanned.
* @param context The Context that the activity will be started from.
*/
public static void simNfcScan(Context context) {
Intent nfcIntent = makeNfcIntent();
Intent nfcIntent = NfcSimUtils.makeNfcIntent();
try {
context.startActivity(nfcIntent);
} catch (ActivityNotFoundException e) {
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2017 The Chromium Authors. All rights reserved. Use of
this source code is governed by a BSD-style license that can be found
in the LICENSE file. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.chromium.chrome.browser.vr_shell.nfc_apk">
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="24" />
<application>
<activity android:name="org.chromium.chrome.browser.vr_shell.nfc_apk.SimNfcActivity"
android:exported="true"
android:theme="@android:style/Theme.NoDisplay"
android:excludeFromRecents="true"/>
</application>
</manifest>
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.vr_shell.nfc_apk;
import android.app.Activity;
import android.os.Bundle;
import org.chromium.chrome.browser.vr_shell.NfcSimUtils;
/**
* Activity to simulate an NFC scan of a Daydream View VR headset. This is so
* tests that cannot interact directly with Java, e.g. Telemetry tests, can
* still force Chrome to enter VR.
*/
public class SimNfcActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Send off intent and close this application
startActivity(NfcSimUtils.makeNfcIntent());
finish();
}
}
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