Commit d2245163 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: disable some strictmode checks for some OEMs

No change to production logic, this only impacts the WebView shell test
app. This disables StrictMode for some manufacturers, as our test team
has been blocked from using the WebView shell on those devices.

This links to bug comments with stack traces pointing to the relevant
vendor code.

This also changes existing code to re-assign to the Builder variable,
since CTS and docs don't actually guarantee Builder methods mutate and
return the same instance.

Bug: 1090841
Test: I verified the drag and drop crash is gone
Change-Id: I6dfd4c417563706b25187e1de21918f27553598d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2378725Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarShimi Zhang <ctzsm@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802798}
parent 02022e7f
...@@ -238,49 +238,79 @@ public class WebViewBrowserActivity extends AppCompatActivity { ...@@ -238,49 +238,79 @@ public class WebViewBrowserActivity extends AppCompatActivity {
} }
} }
@Override /**
public void onCreate(Bundle savedInstanceState) { * Enables StrictMode to catch as much as reasonable. This selectively disables some StrictMode
super.onCreate(savedInstanceState); * policies for some devices, as some manufacturers modify the Android framework in such a
ContextUtils.initApplicationContext(getApplicationContext()); * way as to unavoidably violate StrictMode (ex. the platform code which opens the 3-dots menu
WebView.setWebContentsDebuggingEnabled(true); * is not controlled by WebView or by WebView shell browser).
setContentView(R.layout.activity_webview_browser); */
setSupportActionBar((Toolbar) findViewById(R.id.browser_toolbar)); private void enableStrictMode() {
mUrlBar = (EditText) findViewById(R.id.url_field); String manufacturer = Build.MANUFACTURER.toLowerCase(Locale.US);
mUrlBar.setOnKeyListener((View view, int keyCode, KeyEvent event) -> {
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
loadUrlFromUrlBar(view);
return true;
}
return false;
});
findViewById(R.id.btn_load_url).setOnClickListener((view) -> loadUrlFromUrlBar(view));
StrictMode.ThreadPolicy.Builder threadPolicyBuilder = StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().penaltyDeath(); new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().penaltyDeath();
if (Build.MANUFACTURER.toLowerCase(Locale.US).equals("samsung")) {
if (manufacturer.equals("samsung")) {
// See crbug.com/1056368, Samsung device has an internal method // See crbug.com/1056368, Samsung device has an internal method
// "android.util.GeneralUtil#isSupportedGloveModeInternal", which reads file and // "android.util.GeneralUtil#isSupportedGloveModeInternal", which reads file and
// violates strict mode policy. This method is called when showing the dropdown menu // violates strict mode policy. This method is called when showing the dropdown menu
// after user clicks the 3-dots menu. However this showing code is part of Android // after user clicks the 3-dots menu. However this showing code is part of Android
// framework and not controlled by this app, so we need to permit disk read for the UI // framework and not controlled by this app, so we need to permit disk read for the UI
// thread. // thread.
threadPolicyBuilder.permitDiskReads(); threadPolicyBuilder = threadPolicyBuilder.permitDiskReads();
// See crbug.com/1082701, Samsung device uses OEM specific clipboard API, which will // See crbug.com/1082701 and https://crbug.com/1090841#c38, Samsung device uses OEM
// need to read the disk on UI thread. This app can't control it because it is in the // specific clipboard API, which will need to read the disk on UI thread. This app can't
// framework. We need to permit disk write for the UI thread. // control it because it is in the framework. We need to permit disk write for the UI
threadPolicyBuilder.permitDiskWrites(); // thread.
//
// Also: https://crbug.com/1090841#c31
threadPolicyBuilder = threadPolicyBuilder.permitDiskWrites();
} else if (manufacturer.equals("htc")) {
// https://crbug.com/1090841#c30
threadPolicyBuilder = threadPolicyBuilder.permitDiskReads();
} else if (manufacturer.equals("huawei")) {
// https://crbug.com/1090841#c32
threadPolicyBuilder = threadPolicyBuilder.permitDiskReads();
} else if (manufacturer.equals("lge")) {
// https://crbug.com/1090841#c33
threadPolicyBuilder = threadPolicyBuilder.permitDiskReads();
} else if (manufacturer.equals("oneplus")) {
// https://crbug.com/1090841#c37
threadPolicyBuilder = threadPolicyBuilder.permitDiskReads();
} }
StrictMode.setThreadPolicy(threadPolicyBuilder.build()); StrictMode.setThreadPolicy(threadPolicyBuilder.build());
// Conspicuously omitted: detectCleartextNetwork() and detectFileUriExposure() to permit
// http:// and file:// origins. // Omissions:
// * detectCleartextNetwork() to permit testing http:// URLs
// * detectFileUriExposure() to permit testing file:// URLs
// * detectLeakedClosableObjects() because of drag and drop (https://crbug.com/1090841#c40)
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectActivityLeaks() .detectActivityLeaks()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects() .detectLeakedRegistrationObjects()
.detectLeakedSqlLiteObjects() .detectLeakedSqlLiteObjects()
.penaltyLog() .penaltyLog()
.penaltyDeath() .penaltyDeath()
.build()); .build());
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContextUtils.initApplicationContext(getApplicationContext());
WebView.setWebContentsDebuggingEnabled(true);
setContentView(R.layout.activity_webview_browser);
setSupportActionBar((Toolbar) findViewById(R.id.browser_toolbar));
mUrlBar = (EditText) findViewById(R.id.url_field);
mUrlBar.setOnKeyListener((View view, int keyCode, KeyEvent event) -> {
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
loadUrlFromUrlBar(view);
return true;
}
return false;
});
findViewById(R.id.btn_load_url).setOnClickListener((view) -> loadUrlFromUrlBar(view));
enableStrictMode();
createAndInitializeWebView(); createAndInitializeWebView();
......
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