Commit 0bf687f5 authored by bshe's avatar bshe Committed by Commit bot

Fix disk read violation when create GvrLayout

BUG=672477

Review-Url: https://codereview.chromium.org/2556253006
Cr-Commit-Position: refs/heads/master@{#437561}
parent 85a1d404
......@@ -5,17 +5,13 @@
package org.chromium.chrome.browser.vr_shell;
import android.app.Activity;
import android.os.StrictMode;
import com.google.vr.ndk.base.GvrLayout;
import org.chromium.base.Log;
/**
* Creates an active GvrContext from a detached GvrLayout. This is used by magic window mode.
*/
public class NonPresentingGvrContextImpl implements NonPresentingGvrContext {
private static final String TAG = "NPGvrContextImpl";
private GvrLayout mGvrLayout;
public NonPresentingGvrContextImpl(Activity activity) {
......@@ -24,17 +20,7 @@ public class NonPresentingGvrContextImpl implements NonPresentingGvrContext {
@Override
public long getNativeGvrContext() {
long nativeGvrContext = 0;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
nativeGvrContext = mGvrLayout.getGvrApi().getNativeGvrContext();
} catch (Exception ex) {
Log.e(TAG, "Unable to instantiate GvrApi", ex);
return 0;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return nativeGvrContext;
return mGvrLayout.getGvrApi().getNativeGvrContext();
}
@Override
......
......@@ -5,7 +5,9 @@
package org.chromium.chrome.browser.vr_shell;
import android.app.Activity;
import android.os.StrictMode;
import org.chromium.base.Log;
import org.chromium.base.annotations.UsedByReflection;
/**
......@@ -14,6 +16,7 @@ import org.chromium.base.annotations.UsedByReflection;
*/
@UsedByReflection("VrShellDelegate.java")
public class VrClassesBuilderImpl implements VrClassesBuilder {
private static final String TAG = "VrClassesBuilderImpl";
private final Activity mActivity;
@UsedByReflection("VrShellDelegate.java")
......@@ -23,12 +26,28 @@ public class VrClassesBuilderImpl implements VrClassesBuilder {
@Override
public NonPresentingGvrContext createNonPresentingGvrContext() {
return new NonPresentingGvrContextImpl(mActivity);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
return new NonPresentingGvrContextImpl(mActivity);
} catch (Exception ex) {
Log.e(TAG, "Unable to instantiate NonPresentingGvrContextImpl", ex);
return null;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
@Override
public VrShell createVrShell() {
return new VrShellImpl(mActivity);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
return new VrShellImpl(mActivity);
} catch (Exception ex) {
Log.e(TAG, "Unable to instantiate VrShellImpl", ex);
return null;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
@Override
......
......@@ -410,6 +410,7 @@ public class VrShellDelegate {
private long createNonPresentingNativeContext() {
if (mVrClassesBuilder == null) return 0;
mNonPresentingGvrContext = mVrClassesBuilder.createNonPresentingGvrContext();
if (mNonPresentingGvrContext == null) return 0;
return mNonPresentingGvrContext.getNativeGvrContext();
}
......@@ -473,11 +474,8 @@ public class VrShellDelegate {
private boolean createVrShell() {
if (mVrClassesBuilder == null) return false;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
mVrShell = mVrClassesBuilder.createVrShell();
StrictMode.setThreadPolicy(oldPolicy);
return true;
return mVrShell != null;
}
private void addVrViews() {
......
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