Skip to content

Commit

Permalink
add checkbox to Setting: 'Enable Remote Debugger'
Browse files Browse the repository at this point in the history
when:
  * app setting is enabled
  * phone is connected to a remote computer by `adb`
    - either:
      * physically with a USB cable
      * wirelessly over a LAN
user can:
  * inspect contents of WebView in DevTools with Chrome desktop at:
      chrome://inspect/#devices

quick refresher:
  * # enable USB debugging
  * # connect by USB
    adb devices
    adb tcpip 5555
    # disconnect USB
  * # connect by WiFi from any computer:
    adb connect 192.168.1.x:5555
    adb devices
  • Loading branch information
warren-bank committed Sep 1, 2020
1 parent 6050576 commit fd9b8f8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public static boolean contains(ArrayList<DrawerListItem> items, String uri) {

private String current_page_url;
private WebView webView;
private boolean shouldUpdateWebViewDebugConfigs;
private boolean shouldClearWebView;
private BrowserWebViewClient webViewClient;
private BrowserDownloadListener downloadListener;
Expand Down Expand Up @@ -239,6 +240,11 @@ public void onResume() {
super.onResume();
WebCastApplication.activityResumed();

if (shouldUpdateWebViewDebugConfigs) {
shouldUpdateWebViewDebugConfigs = false;
BrowserDebugUtils.configWebView(BrowserActivity.this);
}

webView.loadUrl(current_page_url);
shouldClearWebView = true;
}
Expand Down Expand Up @@ -799,6 +805,7 @@ public void onClick_action_watch_all_videos(View view) {

private void initWebView() {
BrowserDebugUtils.configWebView(BrowserActivity.this);
shouldUpdateWebViewDebugConfigs = false;

webViewClient = new BrowserWebViewClient(BrowserActivity.this) {
@Override
Expand Down Expand Up @@ -1022,6 +1029,7 @@ public boolean onOptionsItemSelected(MenuItem menuItem) {
case R.id.action_settings: {
Intent in = new Intent(BrowserActivity.this, SettingsActivity.class);
startActivity(in);
shouldUpdateWebViewDebugConfigs = true;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,37 @@

public class BrowserDebugUtils {

public static void configWebView(Context context) {
private static boolean isWebContentsDebuggingEnabled = false;

public static boolean configWebView(Context context) {
boolean didChange = false;

if (Build.VERSION.SDK_INT >= 19) { // Build.VERSION_CODES.KITKAT
if (
(BuildConfig.DEBUG)
|| (0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE))
|| (BrowserUtils.getEnableRemoteDebuggerPreference(context))
) {
WebView.setWebContentsDebuggingEnabled(true);
if (!isWebContentsDebuggingEnabled) {
isWebContentsDebuggingEnabled = true;
WebView.setWebContentsDebuggingEnabled(true);

Toast.makeText(context, "WebView remote debugging enabled", Toast.LENGTH_SHORT).show();
Toast.makeText(context, "WebView remote debugging enabled", Toast.LENGTH_SHORT).show();
didChange = true;
}
}
else {
if (isWebContentsDebuggingEnabled) {
isWebContentsDebuggingEnabled = false;
WebView.setWebContentsDebuggingEnabled(false);

Toast.makeText(context, "WebView remote debugging disabled", Toast.LENGTH_SHORT).show();
didChange = true;
}
}
}

return didChange;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public static String getVideoPlayerPreference(Context context) {
return prefs.getString(pref_key, pref_default);
}

public static boolean getEnableRemoteDebuggerPreference(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String pref_key = context.getString(R.string.pref_enableremotedebugger_key);
String pref_default = context.getString(R.string.pref_enableremotedebugger_default);
boolean val_default = "true".equals(pref_default);

return prefs.getBoolean(pref_key, val_default);
}

public static int getIndexOfArray(Object needle, Object[] haystack) {
for (int i=0; i < haystack.length; i++) {
if (
Expand Down
12 changes: 10 additions & 2 deletions android-studio-project/WebCast/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string translatable="false" name="pref_settings_key">settings_key</string>
<string name="pref_settings_title">WebCast Settings</string>

<!-- SettingsActivity: Video Player -->
<string name="pref_videoplayer_array_names_1">internal w/ Chromecast sender</string>
<string name="pref_videoplayer_array_names_2">external</string>
<string name="pref_videoplayer_array_names_3">@string/activity_name_exoairplayersender</string>
Expand All @@ -42,9 +43,16 @@
</string-array>

<string translatable="false" name="pref_videoplayer_key">pref_videoplayer</string>
<string translatable="false" name="pref_videoplayer_title">Video Player</string>
<string translatable="false" name="pref_videoplayer_summary">watch videos using..</string>
<string translatable="false" name="pref_videoplayer_default">@string/pref_videoplayer_array_values_1</string>
<string name="pref_videoplayer_title">Video Player</string>
<string name="pref_videoplayer_summary">watch videos using..</string>

<!-- SettingsActivity: Enable Remote Debugger -->
<string translatable="false" name="pref_enableremotedebugger_key">pref_enableremotedebugger</string>
<string translatable="false" name="pref_enableremotedebugger_default">false</string>
<string name="pref_enableremotedebugger_title">Enable Remote Debugger</string>
<string name="pref_enableremotedebugger_summary_on" >WebView can be inspected on LAN</string>
<string name="pref_enableremotedebugger_summary_off">WebView cannot be inspected on LAN</string>

<!-- ExoAirPlayerSenderActivity -->
<string translatable="false" name="pref_persistentcookies_key">pref_persistentcookies</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
android:entryValues="@array/pref_videoplayer_array_values"
android:defaultValue="@string/pref_videoplayer_default" />

<CheckBoxPreference
android:key="@string/pref_enableremotedebugger_key"
android:title="@string/pref_enableremotedebugger_title"
android:summaryOn="@string/pref_enableremotedebugger_summary_on"
android:summaryOff="@string/pref_enableremotedebugger_summary_off"
android:defaultValue="@string/pref_enableremotedebugger_default" />

</PreferenceCategory>
</PreferenceScreen>
4 changes: 2 additions & 2 deletions android-studio-project/constants.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project.ext {
releaseVersionCode = Integer.parseInt("004090516", 10)
releaseVersion = '004.09.05-16API'
releaseVersionCode = Integer.parseInt("004090616", 10)
releaseVersion = '004.09.06-16API'
minSdkVersion = 16
targetSdkVersion = 28
compileSdkVersion = 28
Expand Down

0 comments on commit fd9b8f8

Please sign in to comment.