Skip to content

Commit

Permalink
Add debug logging switch to release build developer options (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemarvin committed Aug 16, 2019
1 parent 0881c56 commit 76affca
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
Expand Up @@ -72,6 +72,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static int FOVEATED_WEBVR_DEFAULT_LEVEL = 0;
private final static long CRASH_RESTART_DELTA = 2000;
public final static boolean AUTOPLAY_ENABLED = false;
public final static boolean DEBUG_LOGGING_DEFAULT = false;

// Enable telemetry by default (opt-out).
public final static boolean CRASH_REPORTING_DEFAULT = false;
Expand Down Expand Up @@ -554,5 +555,15 @@ public void setSpeechDataCollectionReviewed(boolean isEnabled) {
editor.putBoolean(mContext.getString(R.string.settings_key_speech_data_collection_reviewed), isEnabled);
editor.commit();
}

public boolean isDebugLogginEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_debug_logging), DEBUG_LOGGING_DEFAULT);
}

public void setDebugLoggingEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_debug_logging), isEnabled);
editor.commit();
}
}

Expand Up @@ -79,6 +79,9 @@ public void setContext(Context context, Bundle aExtras) {

if (BuildConfig.DEBUG) {
runtimeSettingsBuilder.arguments(new String[] { "-purgecaches" });
runtimeSettingsBuilder.debugLogging(true);
} else {
runtimeSettingsBuilder.debugLogging(SettingsStore.getInstance(context).isDebugLogginEnabled());
}

mRuntime = GeckoRuntime.create(context, runtimeSettingsBuilder.build());
Expand Down
Expand Up @@ -40,8 +40,6 @@ public static void vrPrefsWorkAround(Context aContext, Bundle aExtras) {
out.write("pref(\"media.webspeech.synth.enabled\", false);\n".getBytes());
// Prevent autozoom when giving a form field focus.
out.write("pref(\"formhelper.autozoom\", false);\n".getBytes());
String geckoLogLevel = BuildConfig.DEBUG ? "Debug" : "Warn";
out.write(("pref(\"geckoview.logging\", \"" + geckoLogLevel + "\");\n").getBytes());
// Uncomment this to enable WebRender. WARNING NOT READY FOR USAGE.
// out.write("pref(\"gfx.webrender.all\", true);\n".getBytes());
int msaa = SettingsStore.getInstance(aContext).getMSAALevel();
Expand Down
Expand Up @@ -11,6 +11,7 @@

import androidx.databinding.DataBindingUtil;

import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
Expand Down Expand Up @@ -56,6 +57,12 @@ private void initialize(Context aContext) {
mBinding.performanceMonitorSwitch.setOnCheckedChangeListener(mPerformanceListener);
setPerformance(SettingsStore.getInstance(getContext()).isPerformanceMonitorEnabled(), false);

if (BuildConfig.DEBUG) {
mBinding.debugLoggingSwitch.setVisibility(View.GONE);
} else {
setDebugLogging(SettingsStore.getInstance(getContext()).isDebugLogginEnabled(), false);
}

if (!isServoAvailable()) {
mBinding.servoSwitch.setVisibility(View.GONE);

Expand All @@ -81,6 +88,10 @@ private void initialize(Context aContext) {
setPerformance(value, doApply);
};

private SwitchSetting.OnCheckedChangeListener mDebugLogginListener = (compoundButton, value, doApply) -> {
setDebugLogging(value, doApply);
};

private SwitchSetting.OnCheckedChangeListener mServoListener = (compoundButton, b, doApply) -> {
setServo(b, true);
};
Expand All @@ -89,7 +100,6 @@ private void initialize(Context aContext) {
boolean restart = false;
if (mBinding.remoteDebuggingSwitch.isChecked() != SettingsStore.REMOTE_DEBUGGING_DEFAULT) {
setRemoteDebugging(SettingsStore.REMOTE_DEBUGGING_DEFAULT, true);
restart = true;
}

if (mBinding.showConsoleSwitch.isChecked() != SettingsStore.CONSOLE_LOGS_DEFAULT) {
Expand All @@ -106,7 +116,12 @@ private void initialize(Context aContext) {
setPerformance(SettingsStore.PERFORMANCE_MONITOR_DEFAULT, true);
}

if (restart && mDelegate != null) {
if (mBinding.debugLoggingSwitch.isChecked() != SettingsStore.DEBUG_LOGGING_DEFAULT) {
setDebugLogging(SettingsStore.DEBUG_LOGGING_DEFAULT, true);
restart = true;
}

if (restart) {
showRestartDialog();
}
};
Expand Down Expand Up @@ -157,6 +172,17 @@ private void setPerformance(boolean value, boolean doApply) {
}
}

private void setDebugLogging(boolean value, boolean doApply) {
mBinding.debugLoggingSwitch.setOnCheckedChangeListener(null);
mBinding.debugLoggingSwitch.setValue(value, false);
mBinding.debugLoggingSwitch.setOnCheckedChangeListener(mDebugLogginListener);

if (doApply) {
SettingsStore.getInstance(getContext()).setDebugLoggingEnabled(value);
showRestartDialog();
}
}

private void setServo(boolean value, boolean doApply) {
mBinding.servoSwitch.setOnCheckedChangeListener(null);
mBinding.servoSwitch.setValue(value, false);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/options_developer.xml
Expand Up @@ -60,6 +60,12 @@
android:layout_height="wrap_content"
app:description="@string/developer_options_performance_monitor" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/debug_logging_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/developer_options_debug_logging" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/servo_switch"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Expand Up @@ -44,6 +44,7 @@
<string name="settings_key_browser_world_width" translatable="false">settings_browser_world_width</string>
<string name="settings_key_browser_world_height" translatable="false">settings_browser_world_height</string>
<string name="settings_key_notifications" translatable="false">settings_key_notifications</string>
<string name="settings_key_debug_logging" translatable="false">settings_key_debug_logging</string>
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
<string name="private_report_url" translatable="false">https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&amp;label=browser-firefox-reality&amp;url=%1$s</string>
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/values/strings.xml
Expand Up @@ -275,12 +275,18 @@
A dialog should appear with a field labeled with the text, 'Enable Multiprocess'. -->
<string name="developer_options_multiprocess">Enable Multiprocess</string>

<!-- This string labels and On/Off switch in the developer options dialog and is used to toggle
<!-- This string labels an On/Off switch in the developer options dialog and is used to toggle
the performance monitor. The Performance monitor is used to detect pages that cause the
browser to run below a target framerate and pauses the page to restore performance.
-->
<string name="developer_options_performance_monitor">Enable Performance Monitor</string>

<!-- This string labels an On/Off switch in the developer options dialog and is used to toggle
debug logging. Debug logging provides runtime diagnostic information that may be collected
to help diagnose and fix problems with the application.
-->
<string name="developer_options_debug_logging">Enable Debug Logging</string>

<!-- The string labels an On/Off switch in the developer options dialog and is used to toggle enabling Servo. -->
<string name="developer_options_servo">Enable Servo</string>

Expand Down

0 comments on commit 76affca

Please sign in to comment.