use of android.support.annotation.UiThread in project AndroidChromium by JackyAndroid.
the class ChromeStrictMode method configureStrictMode.
/**
* Turn on StrictMode detection based on build and command-line switches.
*/
@UiThread
// FindBugs doesn't like conditionals with compile time results
@SuppressFBWarnings("UCF_USELESS_CONTROL_FLOW")
public static void configureStrictMode() {
assert ThreadUtils.runningOnUiThread();
if (sIsStrictModeAlreadyConfigured) {
return;
}
sIsStrictModeAlreadyConfigured = true;
StrictMode.ThreadPolicy.Builder threadPolicy = new StrictMode.ThreadPolicy.Builder(StrictMode.getThreadPolicy());
StrictMode.VmPolicy.Builder vmPolicy = new StrictMode.VmPolicy.Builder(StrictMode.getVmPolicy());
CommandLine commandLine = CommandLine.getInstance();
if ("eng".equals(Build.TYPE) || BuildConfig.DCHECK_IS_ON || ChromeVersionInfo.isLocalBuild() || commandLine.hasSwitch(ChromeSwitches.STRICT_MODE)) {
turnOnDetection(threadPolicy, vmPolicy);
addDefaultPenalties(threadPolicy, vmPolicy);
if ("death".equals(commandLine.getSwitchValue(ChromeSwitches.STRICT_MODE))) {
addThreadDeathPenalty(threadPolicy);
addVmDeathPenalty(vmPolicy);
} else if ("testing".equals(commandLine.getSwitchValue(ChromeSwitches.STRICT_MODE))) {
addThreadDeathPenalty(threadPolicy);
// Currently VmDeathPolicy kills the process, and is not visible on bot test output.
}
}
// Enroll 1% of dev sessions into StrictMode watch. This is done client-side rather than
// through finch because this decision is as early as possible in the browser initialization
// process. We need to detect early start-up StrictMode violations before loading native and
// before warming the SharedPreferences (that is a violation in an of itself). We will
// closely monitor this on dev channel.
boolean enableStrictModeWatch = (ChromeVersionInfo.isDevBuild() && Math.random() < UPLOAD_PROBABILITY);
if ((ChromeVersionInfo.isLocalBuild() && !BuildConfig.DCHECK_IS_ON) || enableStrictModeWatch) {
turnOnDetection(threadPolicy, vmPolicy);
initializeStrictModeWatch();
}
StrictMode.setThreadPolicy(threadPolicy.build());
StrictMode.setVmPolicy(vmPolicy.build());
}
Aggregations