| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.app.ApplicationErrorReport; | 7 import android.app.ApplicationErrorReport; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 import android.os.MessageQueue; | 10 import android.os.MessageQueue; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 private static void addVmDeathPenalty(StrictMode.VmPolicy.Builder vmPolicy)
{ | 154 private static void addVmDeathPenalty(StrictMode.VmPolicy.Builder vmPolicy)
{ |
| 155 vmPolicy.penaltyDeath(); | 155 vmPolicy.penaltyDeath(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * Turn on StrictMode detection based on build and command-line switches. | 159 * Turn on StrictMode detection based on build and command-line switches. |
| 160 */ | 160 */ |
| 161 @UiThread | 161 @UiThread |
| 162 // FindBugs doesn't like conditionals with compile time results | 162 // FindBugs doesn't like conditionals with compile time results |
| 163 @SuppressFBWarnings("UCF_USELESS_CONTROL_FLOW_NEXT_LINE") | 163 @SuppressFBWarnings("UCF_USELESS_CONTROL_FLOW") |
| 164 public static void configureStrictMode() { | 164 public static void configureStrictMode() { |
| 165 assert ThreadUtils.runningOnUiThread(); | 165 assert ThreadUtils.runningOnUiThread(); |
| 166 if (sIsStrictModeAlreadyConfigured) { | 166 if (sIsStrictModeAlreadyConfigured) { |
| 167 return; | 167 return; |
| 168 } | 168 } |
| 169 sIsStrictModeAlreadyConfigured = true; | 169 sIsStrictModeAlreadyConfigured = true; |
| 170 | 170 |
| 171 StrictMode.ThreadPolicy.Builder threadPolicy = | 171 StrictMode.ThreadPolicy.Builder threadPolicy = |
| 172 new StrictMode.ThreadPolicy.Builder(StrictMode.getThreadPolicy()
); | 172 new StrictMode.ThreadPolicy.Builder(StrictMode.getThreadPolicy()
); |
| 173 StrictMode.VmPolicy.Builder vmPolicy = | 173 StrictMode.VmPolicy.Builder vmPolicy = |
| 174 new StrictMode.VmPolicy.Builder(StrictMode.getVmPolicy()); | 174 new StrictMode.VmPolicy.Builder(StrictMode.getVmPolicy()); |
| 175 | 175 |
| 176 CommandLine commandLine = CommandLine.getInstance(); | 176 CommandLine commandLine = CommandLine.getInstance(); |
| 177 if ("eng".equals(Build.TYPE) | 177 if ("eng".equals(Build.TYPE) |
| 178 || BuildConfig.IS_DEBUG | 178 || BuildConfig.DCHECK_IS_ON |
| 179 || ChromeVersionInfo.isLocalBuild() | 179 || ChromeVersionInfo.isLocalBuild() |
| 180 || commandLine.hasSwitch(ChromeSwitches.STRICT_MODE)) { | 180 || commandLine.hasSwitch(ChromeSwitches.STRICT_MODE)) { |
| 181 turnOnDetection(threadPolicy, vmPolicy); | 181 turnOnDetection(threadPolicy, vmPolicy); |
| 182 addDefaultPenalties(threadPolicy, vmPolicy); | 182 addDefaultPenalties(threadPolicy, vmPolicy); |
| 183 if ("death".equals(commandLine.getSwitchValue(ChromeSwitches.STRICT_
MODE))) { | 183 if ("death".equals(commandLine.getSwitchValue(ChromeSwitches.STRICT_
MODE))) { |
| 184 addThreadDeathPenalty(threadPolicy); | 184 addThreadDeathPenalty(threadPolicy); |
| 185 addVmDeathPenalty(vmPolicy); | 185 addVmDeathPenalty(vmPolicy); |
| 186 } else if ("testing".equals(commandLine.getSwitchValue(ChromeSwitche
s.STRICT_MODE))) { | 186 } else if ("testing".equals(commandLine.getSwitchValue(ChromeSwitche
s.STRICT_MODE))) { |
| 187 addThreadDeathPenalty(threadPolicy); | 187 addThreadDeathPenalty(threadPolicy); |
| 188 // Currently VmDeathPolicy kills the process, and is not visible
on bot test output. | 188 // Currently VmDeathPolicy kills the process, and is not visible
on bot test output. |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 // Enroll 1% of dev sessions into StrictMode watch. This is done client-
side rather than | 191 // Enroll 1% of dev sessions into StrictMode watch. This is done client-
side rather than |
| 192 // through finch because this decision is as early as possible in the br
owser initialization | 192 // through finch because this decision is as early as possible in the br
owser initialization |
| 193 // process. We need to detect early start-up StrictMode violations befor
e loading native and | 193 // process. We need to detect early start-up StrictMode violations befor
e loading native and |
| 194 // before warming the SharedPreferences (that is a violation in an of it
self). We will | 194 // before warming the SharedPreferences (that is a violation in an of it
self). We will |
| 195 // closely monitor this on dev channel. | 195 // closely monitor this on dev channel. |
| 196 boolean enableStrictModeWatch = | 196 boolean enableStrictModeWatch = |
| 197 (ChromeVersionInfo.isDevBuild() && Math.random() < UPLOAD_PROBAB
ILITY); | 197 (ChromeVersionInfo.isDevBuild() && Math.random() < UPLOAD_PROBAB
ILITY); |
| 198 if ((ChromeVersionInfo.isLocalBuild() && !BuildConfig.IS_DEBUG) || enabl
eStrictModeWatch) { | 198 if ((ChromeVersionInfo.isLocalBuild() && !BuildConfig.DCHECK_IS_ON) |
| 199 || enableStrictModeWatch) { |
| 199 turnOnDetection(threadPolicy, vmPolicy); | 200 turnOnDetection(threadPolicy, vmPolicy); |
| 200 initializeStrictModeWatch(); | 201 initializeStrictModeWatch(); |
| 201 } | 202 } |
| 202 | 203 |
| 203 StrictMode.setThreadPolicy(threadPolicy.build()); | 204 StrictMode.setThreadPolicy(threadPolicy.build()); |
| 204 StrictMode.setVmPolicy(vmPolicy.build()); | 205 StrictMode.setVmPolicy(vmPolicy.build()); |
| 205 } | 206 } |
| 206 } | 207 } |
| OLD | NEW |