Commit eb9cc7e0 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Add StrictModeContext.allowSlowCalls()

This CL adds StrictModeContext.allowSlowCalls() to avoid crashes when
non-Chrome code calls StrictMode.noteSlowCall(). Use sparingly (e.g.,
to avoid crashes on older versions of the library if a new version
no longer calls noteSlowCall).

Bug: 793841
Change-Id: I24a03b8c241499c00a871a564cff0a5b0b58a87a
Reviewed-on: https://chromium-review.googlesource.com/824273Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523777}
parent 2befc250
...@@ -63,6 +63,16 @@ public final class StrictModeContext implements Closeable { ...@@ -63,6 +63,16 @@ public final class StrictModeContext implements Closeable {
return new StrictModeContext(oldPolicy); return new StrictModeContext(oldPolicy);
} }
/**
* Convenience method for disabling StrictMode for slow calls with try-with-resources.
*/
public static StrictModeContext allowSlowCalls() {
StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder(oldPolicy).permitCustomSlowCalls().build());
return new StrictModeContext(oldPolicy);
}
@Override @Override
public void close() { public void close() {
if (mThreadPolicy != null) { if (mThreadPolicy != null) {
......
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