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

Android: use base layer API to check debuggability

This converts Android WebView code to use the base-layer definition of
whether to enable developer-only features (in this case, the command
line). This also comments the BuildInfo method to mention Android's
definition of debuggability (IS_DEBUGGABLE), which could improve
discoverability.

Although this is a change in logic, this should not impact real
behavior, since "not equal to 'user'" should in practice be the same as
"equal to 'userdebug' or 'eng'," since these are the only three valid
values.

R=agrieve@google.com, tobiasjs@google.com

Bug: 908668
Test: N/A
Change-Id: I6007d564078a899567226a3777c02bfcffc16f75
Reviewed-on: https://chromium-review.googlesource.com/c/1351733
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612785}
parent 7f3ec0c5
......@@ -14,7 +14,7 @@ import org.chromium.android_webview.AwContentsClient;
import org.chromium.android_webview.AwContentsStatics;
import org.chromium.android_webview.AwDevToolsServer;
import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.base.BuildInfo;
import org.chromium.base.Callback;
import org.chromium.base.MemoryPressureLevel;
import org.chromium.base.ThreadUtils;
......@@ -44,10 +44,9 @@ public class SharedStatics {
}
public void setWebContentsDebuggingEnabled(boolean enable) {
// Web Contents debugging is always enabled on debug builds.
if (!CommandLineUtil.isBuildDebuggable()) {
setWebContentsDebuggingEnabledUnconditionally(enable);
}
// On debug builds, Web Contents debugging is enabled elsewhere, and cannot be disabled.
if (BuildInfo.isDebugAndroid()) return;
setWebContentsDebuggingEnabledUnconditionally(enable);
}
public void setWebContentsDebuggingEnabledUnconditionally(boolean enable) {
......
......@@ -35,8 +35,8 @@ import org.chromium.android_webview.HttpAuthDatabase;
import org.chromium.android_webview.ScopedSysTraceEvent;
import org.chromium.android_webview.VariationsSeedLoader;
import org.chromium.android_webview.WebViewChromiumRunQueue;
import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.base.BuildConfig;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.FieldTrialList;
import org.chromium.base.PathService;
......@@ -167,7 +167,7 @@ public class WebViewChromiumAwInit {
AwBrowserProcess.handleMinidumpsAndSetMetricsConsent(true /* updateMetricsConsent */);
mSharedStatics = new SharedStatics();
if (CommandLineUtil.isBuildDebuggable()) {
if (BuildInfo.isDebugAndroid()) {
mSharedStatics.setWebContentsDebuggingEnabledUnconditionally(true);
}
......
......@@ -4,9 +4,9 @@
package org.chromium.android_webview.command_line;
import android.os.Build;
import android.os.StrictMode;
import org.chromium.base.BuildInfo;
import org.chromium.base.CommandLine;
/**
......@@ -22,16 +22,12 @@ public class CommandLineUtil {
public static final String CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH =
"enable-crash-reporter-for-testing";
public static boolean isBuildDebuggable() {
return !Build.TYPE.equals("user");
}
/**
* Initialize the CommandLine for WebView - this should be initialized on the same thread where
* we subsequently access CommandLine.
*/
public static void initCommandLine() {
if (isBuildDebuggable()) {
if (BuildInfo.isDebugAndroid()) {
// Suppress the StrictMode violation as this codepath is only hit on debuggable builds.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
CommandLine.initFromFile(CommandLineUtil.WEBVIEW_COMMAND_LINE_FILE);
......
......@@ -131,8 +131,12 @@ public class BoundaryInterfaceReflectionUtil {
}
}
/**
* Check if this is a debuggable build of Android. Note: we copy BuildInfo's method because we
* cannot depend on the base-layer here (this folder is mirrored into Android).
*/
private static boolean isDebuggable() {
return !Build.TYPE.equals("user");
return "eng".equals(Build.TYPE) || "userdebug".equals(Build.TYPE);
}
/**
......
......@@ -163,6 +163,7 @@ public class BuildInfo {
/**
* Check if this is a debuggable build of Android. Use this to enable developer-only features.
* This is a rough approximation of the hidden API {@code Build.IS_DEBUGGABLE}.
*/
public static boolean isDebugAndroid() {
return "eng".equals(Build.TYPE) || "userdebug".equals(Build.TYPE);
......
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