From ea1f041e1167de9add5346a7d4fe6afec095d910 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Fri, 29 Nov 2013 15:54:07 -0800 Subject: [PATCH] CB-5487: Remote Debugging is on when your Android app is debuggable. --- .../org/apache/cordova/CordovaWebView.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 9e94722d..97804934 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -37,6 +37,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -281,6 +284,28 @@ public class CordovaWebView extends WebView { settings.setDatabaseEnabled(true); settings.setDatabasePath(databasePath); + + //Determine whether we're in debug or release mode, and turn on Debugging! + try { + final String packageName = this.cordova.getActivity().getPackageName(); + final PackageManager pm = this.cordova.getActivity().getPackageManager(); + ApplicationInfo appInfo; + + appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); + + if((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 && + android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) + { + setWebContentsDebuggingEnabled(true); + } + } catch (IllegalArgumentException e) { + Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); + e.printStackTrace(); + } catch (NameNotFoundException e) { + Log.d(TAG, "This should never happen: Your application's package can't be found."); + e.printStackTrace(); + } + settings.setGeolocationDatabasePath(databasePath); // Enable DOM storage