Commit b52864d5 authored by Paul Miller's avatar Paul Miller Committed by Commit Bot

Fix StrictMode violation

Work around bug b/120099466 in Android < Q in which faild reflection
causes disk reads.

BUG=948308

Change-Id: I38ab4c55a9e11f2bb2a5153740894f9f4f6c88d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574940Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Paul Miller <paulmiller@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652627}
parent 60a7838b
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
package org.chromium.ui.touchless; package org.chromium.ui.touchless;
import android.os.StrictMode;
import org.chromium.base.BuildInfo;
/** /**
* org.chromium.ui.touchless.TouchlessEventHandler * org.chromium.ui.touchless.TouchlessEventHandler
*/ */
...@@ -21,11 +25,16 @@ public class TouchlessEventHandler { ...@@ -21,11 +25,16 @@ public class TouchlessEventHandler {
private static TouchlessEventHandler sInstance; private static TouchlessEventHandler sInstance;
static { static {
// Work around Android bug b/120099466 in which failed reflection causes disk reads.
StrictMode.ThreadPolicy oldPolicy = null;
if (!BuildInfo.isAtLeastQ()) oldPolicy = StrictMode.allowThreadDiskReads();
try { try {
sInstance = (TouchlessEventHandler) Class.forName(EVENT_HANDLER_INTERNAL).newInstance(); sInstance = (TouchlessEventHandler) Class.forName(EVENT_HANDLER_INTERNAL).newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| IllegalArgumentException e) { | IllegalArgumentException e) {
sInstance = null; sInstance = null;
} finally {
if (oldPolicy != null) StrictMode.setThreadPolicy(oldPolicy);
} }
} }
......
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