Commit 82b55ac6 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Fix MediaViewerUtils StrictMode violation

Fixes a StrictMode violation caused by a setComponentEnabledSetting in
MediaViewerUtils by wrapping the offending call in a context that
allows disk reads and writes.

Bug: 869217
Change-Id: Ide971ab817cc149df3c828b23a9b4bf4015ff711
Reviewed-on: https://chromium-review.googlesource.com/1155974Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579283}
parent 03aebcbf
......@@ -20,6 +20,7 @@ import android.text.TextUtils;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.IntentHandler;
......@@ -183,9 +184,14 @@ public class MediaViewerUtils {
// This indicates that we don't want to kill Chrome when changing component enabled state.
int flags = PackageManager.DONT_KILL_APP;
if (packageManager.getComponentEnabledSetting(componentName) != newState)
if (packageManager.getComponentEnabledSetting(componentName) != newState) {
// setComponentEnabledSetting ends up both reading and writing to disk, which ends up
// causing StrictMode violations. So, explicitly allow them briefly.
try (StrictModeContext unused = StrictModeContext.allowDiskReads().allowDiskWrites()) {
packageManager.setComponentEnabledSetting(componentName, newState, flags);
}
}
}
/**
* Force MediaLauncherActivity to be enabled for testing.
......
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