Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrProxyActivity.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrProxyActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrProxyActivity.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..644c14d3ae5959952b406f41a2be4426c709cd07 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrProxyActivity.java |
| @@ -0,0 +1,60 @@ |
| +// 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.app.Activity; |
| +import android.app.ActivityManager; |
| +import android.os.Bundle; |
| +import android.os.StrictMode; |
| + |
| +import org.chromium.base.Log; |
| + |
| +import java.io.BufferedReader; |
| +import java.io.File; |
| +import java.io.FileInputStream; |
| +import java.io.IOException; |
| +import java.io.InputStreamReader; |
| + |
| +/** |
| + * Dispatches incoming intents to the appropriate VR activity based on the VR intent extras. |
| + */ |
| +public class VrProxyActivity extends Activity { |
| + private static final String TAG = "VrProxyActivity"; |
| + |
| + @Override |
| + public void onCreate(Bundle savedInstanceState) { |
| + super.onCreate(savedInstanceState); |
| + Log.v(TAG, "VR DON flow success, resuming Chrome in VR."); |
| + |
| + ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
| + |
| + // TODO(mthiesse): See VrShellDelegate#launchInVR |
| + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| + StrictMode.allowThreadDiskWrites(); |
| + File dir = VrShellDelegate.getOrCreateVRDirectory(); |
| + File tidFile = new File(dir, VrShellDelegate.TID_FILE); |
|
Ted C
2017/03/31 18:17:18
Are we worried about Chrome dying while this is ha
mthiesse
2017/03/31 20:06:14
Wouldn't we have to somehow start the VrProxyActiv
|
| + File resultFile = new File(dir, VrShellDelegate.RESULT_SUCCESS_FILE); |
|
Ted C
2017/03/31 18:17:18
same thing, are we not calling directly into our o
|
| + try { |
|
Ted C
2017/03/31 18:17:18
you don't need nested try catches.
this can be:
|
| + try { |
| + BufferedReader stream = |
| + new BufferedReader(new InputStreamReader(new FileInputStream(tidFile))); |
| + String line = stream.readLine(); |
| + stream.close(); |
| + if (line == null) throw new IOException(); |
| + int tid = Integer.parseInt(line); |
| + resultFile.createNewFile(); |
| + finish(); |
| + activityManager.moveTaskToFront(tid, 0); |
|
Ted C
2017/03/31 18:17:18
does this need to happen after finish? I'm wonder
|
| + } catch (IOException | NumberFormatException e) { |
| + Log.e(TAG, "Failed to read file: " + tidFile.getAbsolutePath()); |
| + finish(); |
| + return; |
| + } |
| + } finally { |
| + tidFile.delete(); |
| + StrictMode.setThreadPolicy(oldPolicy); |
| + } |
| + } |
| +} |