diff --git a/framework/src/org/apache/cordova/AllowList.java b/framework/src/org/apache/cordova/AllowList.java index 4b4bafcce9..c00b884e39 100644 --- a/framework/src/org/apache/cordova/AllowList.java +++ b/framework/src/org/apache/cordova/AllowList.java @@ -20,12 +20,9 @@ Licensed to the Apache Software Foundation (ASF) under one import java.net.MalformedURLException; import java.util.ArrayList; -import java.util.Iterator; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.cordova.LOG; - import android.net.Uri; public class AllowList { @@ -97,7 +94,7 @@ public boolean matches(Uri uri) { public static final String TAG = "CordovaAllowList"; public AllowList() { - this.allowList = new ArrayList(); + this.allowList = new ArrayList<>(); } /* Match patterns (from http://developer.chrome.com/extensions/match_patterns.html) @@ -157,9 +154,7 @@ public boolean isUrlAllowListed(String uri) { Uri parsedUri = Uri.parse(uri); // Look for match in allow list - Iterator pit = allowList.iterator(); - while (pit.hasNext()) { - URLPattern p = pit.next(); + for (URLPattern p : allowList) { if (p.matches(parsedUri)) { return true; } diff --git a/framework/src/org/apache/cordova/AllowListPlugin.java b/framework/src/org/apache/cordova/AllowListPlugin.java index e85f8ecded..5523f82b5a 100644 --- a/framework/src/org/apache/cordova/AllowListPlugin.java +++ b/framework/src/org/apache/cordova/AllowListPlugin.java @@ -19,11 +19,6 @@ Licensed to the Apache Software Foundation (ASF) under one package org.apache.cordova; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.ConfigXmlParser; -import org.apache.cordova.LOG; -import org.apache.cordova.AllowList; -import org.apache.cordova.CordovaPreferences; import org.xmlpull.v1.XmlPullParser; import android.content.Context; @@ -74,7 +69,7 @@ public void pluginInitialize() { } private class CustomConfigXmlParser extends ConfigXmlParser { - private CordovaPreferences prefs = new CordovaPreferences(); + private final CordovaPreferences prefs = new CordovaPreferences(); @Override public void handleStartTag(XmlPullParser xml) { diff --git a/framework/src/org/apache/cordova/BuildHelper.java b/framework/src/org/apache/cordova/BuildHelper.java index 2899ee2a00..a738af510e 100644 --- a/framework/src/org/apache/cordova/BuildHelper.java +++ b/framework/src/org/apache/cordova/BuildHelper.java @@ -26,16 +26,14 @@ Licensed to the Apache Software Foundation (ASF) under one * */ -import android.app.Activity; import android.content.Context; import java.lang.reflect.Field; - public class BuildHelper { - private static String TAG="BuildHelper"; + private static final String TAG = "BuildHelper"; /* * This needs to be implemented if you wish to use the Camera Plugin or other plugins diff --git a/framework/src/org/apache/cordova/CallbackContext.java b/framework/src/org/apache/cordova/CallbackContext.java index 43363869da..e708957a8c 100644 --- a/framework/src/org/apache/cordova/CallbackContext.java +++ b/framework/src/org/apache/cordova/CallbackContext.java @@ -19,16 +19,13 @@ Licensed to the Apache Software Foundation (ASF) under one package org.apache.cordova; import org.json.JSONArray; - -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.PluginResult; import org.json.JSONObject; public class CallbackContext { private static final String LOG_TAG = "CordovaPlugin"; - private String callbackId; - private CordovaWebView webView; + private final String callbackId; + private final CordovaWebView webView; protected boolean finished; private int changingThreads; diff --git a/framework/src/org/apache/cordova/CallbackMap.java b/framework/src/org/apache/cordova/CallbackMap.java index b825610c5d..5551d13c41 100644 --- a/framework/src/org/apache/cordova/CallbackMap.java +++ b/framework/src/org/apache/cordova/CallbackMap.java @@ -28,10 +28,10 @@ Licensed to the Apache Software Foundation (ASF) under one */ public class CallbackMap { private int currentCallbackId = 0; - private SparseArray> callbacks; + private final SparseArray> callbacks; public CallbackMap() { - this.callbacks = new SparseArray>(); + this.callbacks = new SparseArray<>(); } /** @@ -45,7 +45,7 @@ public CallbackMap() { */ public synchronized int registerCallback(CordovaPlugin receiver, int requestCode) { int mappedId = this.currentCallbackId++; - callbacks.put(mappedId, new Pair(receiver, requestCode)); + callbacks.put(mappedId, new Pair<>(receiver, requestCode)); return mappedId; } diff --git a/framework/src/org/apache/cordova/Config.java b/framework/src/org/apache/cordova/Config.java index 2082f251ab..4fdcc952c4 100644 --- a/framework/src/org/apache/cordova/Config.java +++ b/framework/src/org/apache/cordova/Config.java @@ -54,7 +54,7 @@ public static String getStartUrl() { } public static String getErrorUrl() { - return parser.getPreferences().getString("errorurl", null); + return parser.getPreferences().getString("ErrorUrl", null); } public static List getPluginEntries() { diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java index 0b92e96b63..f216c440d8 100644 --- a/framework/src/org/apache/cordova/ConfigXmlParser.java +++ b/framework/src/org/apache/cordova/ConfigXmlParser.java @@ -29,17 +29,17 @@ Licensed to the Apache Software Foundation (ASF) under one import android.content.Context; public class ConfigXmlParser { - private static String TAG = "ConfigXmlParser"; + private static final String TAG = "ConfigXmlParser"; - private static String SCHEME_HTTP = "http"; - private static String SCHEME_HTTPS = "https"; - private static String DEFAULT_HOSTNAME = "localhost"; + private static final String SCHEME_HTTP = "http"; + private static final String SCHEME_HTTPS = "https"; + private static final String DEFAULT_HOSTNAME = "localhost"; private static final String DEFAULT_CONTENT_SRC = "index.html"; private String launchUrl; private String contentSrc; - private CordovaPreferences prefs = new CordovaPreferences(); - private ArrayList pluginEntries = new ArrayList(20); + private final CordovaPreferences prefs = new CordovaPreferences(); + private final ArrayList pluginEntries = new ArrayList<>(20); public CordovaPreferences getPreferences() { return prefs; @@ -105,9 +105,7 @@ else if (eventType == XmlPullParser.END_TAG) } try { eventType = xml.next(); - } catch (XmlPullParserException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch (XmlPullParserException | IOException e) { e.printStackTrace(); } } diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 50d6b3232c..3f81446e91 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -26,7 +26,6 @@ Licensed to the Apache Software Foundation (ASF) under one import android.app.AlertDialog; import android.annotation.SuppressLint; -import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Color; @@ -41,6 +40,7 @@ Licensed to the Apache Software Foundation (ASF) under one import android.webkit.WebViewClient; import android.widget.FrameLayout; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.splashscreen.SplashScreen; @@ -75,14 +75,14 @@ Licensed to the Apache Software Foundation (ASF) under one *

The use of the set*Property() methods is deprecated in favor of the config.xml file.

*/ public class CordovaActivity extends AppCompatActivity { - public static String TAG = "CordovaActivity"; + public static final String TAG = "CordovaActivity"; // The WebView for our app protected CordovaWebView appView; - private static int ACTIVITY_STARTING = 0; - private static int ACTIVITY_RUNNING = 1; - private static int ACTIVITY_EXITING = 2; + private static final int ACTIVITY_STARTING = 0; + private static final int ACTIVITY_RUNNING = 1; + private static final int ACTIVITY_EXITING = 2; // Keep app running when pause is received. (default = true) // If true, then the JavaScript and native code continue to run in the background @@ -111,7 +111,7 @@ public void onCreate(Bundle savedInstanceState) { // need to activate preferences before super.onCreate to avoid "requestFeature() must be called before adding content" exception loadConfig(); - String logLevel = preferences.getString("loglevel", "ERROR"); + String logLevel = preferences.getString("LogLevel", "ERROR"); LOG.setLogLevel(logLevel); LOG.i(TAG, "Apache Cordova native platform version " + CordovaWebView.CORDOVA_VERSION + " is starting"); @@ -389,23 +389,15 @@ public void onReceivedError(final int errorCode, final String description, final final String errorUrl = preferences.getString("errorUrl", null); if ((errorUrl != null) && (!failingUrl.equals(errorUrl)) && (appView != null)) { // Load URL on UI thread - me.runOnUiThread(new Runnable() { - @Override - public void run() { - me.appView.showWebPage(errorUrl, false, true, null); - } - }); + me.runOnUiThread(() -> me.appView.showWebPage(errorUrl, false, true, null)); } // If not, then display error dialog else { final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP); - me.runOnUiThread(new Runnable() { - @Override - public void run() { - if (exit) { - me.appView.getView().setVisibility(View.GONE); - me.displayError("Application Error", description + " (" + failingUrl + ")", "OK", exit); - } + me.runOnUiThread(() -> { + if (exit) { + me.appView.getView().setVisibility(View.GONE); + me.displayError("Application Error", description + " (" + failingUrl + ")", "OK", exit); } }); } @@ -416,29 +408,23 @@ public void run() { */ public void displayError(final String title, final String message, final String button, final boolean exit) { final CordovaActivity me = this; - me.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - AlertDialog.Builder dlg = new AlertDialog.Builder(me); - dlg.setMessage(message); - dlg.setTitle(title); - dlg.setCancelable(false); - dlg.setPositiveButton(button, - new AlertDialog.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - if (exit) { - finish(); - } - } - }); - dlg.create(); - dlg.show(); - } catch (Exception e) { - finish(); - } + me.runOnUiThread(() -> { + try { + AlertDialog.Builder dlg = new AlertDialog.Builder(me); + dlg.setMessage(message); + dlg.setTitle(title); + dlg.setCancelable(false); + dlg.setPositiveButton(button, + (dialog, which) -> { + dialog.dismiss(); + if (exit) { + finish(); + } + }); + dlg.create(); + dlg.show(); + } catch (Exception e) { + finish(); } }); } @@ -522,8 +508,8 @@ public void onConfigurationChanged(Configuration newConfig) { * @param grantResults */ @Override - public void onRequestPermissionsResult(int requestCode, String permissions[], - int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, + @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); try diff --git a/framework/src/org/apache/cordova/CordovaArgs.java b/framework/src/org/apache/cordova/CordovaArgs.java index d40d26ebbf..452cda300c 100644 --- a/framework/src/org/apache/cordova/CordovaArgs.java +++ b/framework/src/org/apache/cordova/CordovaArgs.java @@ -25,7 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one import android.util.Base64; public class CordovaArgs { - private JSONArray baseArgs; + private final JSONArray baseArgs; public CordovaArgs(JSONArray args) { this.baseArgs = args; diff --git a/framework/src/org/apache/cordova/CordovaBridge.java b/framework/src/org/apache/cordova/CordovaBridge.java index a8e8369232..367e79c73d 100644 --- a/framework/src/org/apache/cordova/CordovaBridge.java +++ b/framework/src/org/apache/cordova/CordovaBridge.java @@ -18,8 +18,6 @@ Licensed to the Apache Software Foundation (ASF) under one */ package org.apache.cordova; -import android.annotation.SuppressLint; - import java.security.SecureRandom; import org.json.JSONArray; @@ -32,8 +30,8 @@ Licensed to the Apache Software Foundation (ASF) under one */ public class CordovaBridge { private static final String LOG_TAG = "CordovaBridge"; - private PluginManager pluginManager; - private NativeToJsMessageQueue jsMessageQueue; + private final PluginManager pluginManager; + private final NativeToJsMessageQueue jsMessageQueue; private volatile int expectedBridgeSecret = -1; // written by UI thread, read by JS thread. public CordovaBridge(PluginManager pluginManager, NativeToJsMessageQueue jsMessageQueue) { @@ -136,9 +134,7 @@ public String promptOnJsPrompt(String origin, String message, String defaultValu String callbackId = array.getString(3); String r = jsExec(bridgeSecret, service, action, callbackId, message); return r == null ? "" : r; - } catch (JSONException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { + } catch (JSONException | IllegalAccessException e) { e.printStackTrace(); } return ""; @@ -148,9 +144,7 @@ else if (defaultValue != null && defaultValue.startsWith("gap_bridge_mode:")) { try { int bridgeSecret = Integer.parseInt(defaultValue.substring(16)); jsSetNativeToJsBridgeMode(bridgeSecret, Integer.parseInt(message)); - } catch (NumberFormatException e){ - e.printStackTrace(); - } catch (IllegalAccessException e) { + } catch (NumberFormatException | IllegalAccessException e){ e.printStackTrace(); } return ""; diff --git a/framework/src/org/apache/cordova/CordovaDialogsHelper.java b/framework/src/org/apache/cordova/CordovaDialogsHelper.java index f74ad8e74e..0b6bed9c40 100644 --- a/framework/src/org/apache/cordova/CordovaDialogsHelper.java +++ b/framework/src/org/apache/cordova/CordovaDialogsHelper.java @@ -20,7 +20,6 @@ Licensed to the Apache Software Foundation (ASF) under one import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.view.KeyEvent; import android.widget.EditText; @@ -42,31 +41,18 @@ public void showAlert(String message, final Result result) { //Don't let alerts break the back button dlg.setCancelable(true); dlg.setPositiveButton(android.R.string.ok, - new AlertDialog.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - result.gotResult(true, null); - } - }); + (dialog, which) -> result.gotResult(true, null)); dlg.setOnCancelListener( - new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - result.gotResult(false, null); - } - }); - dlg.setOnKeyListener(new DialogInterface.OnKeyListener() { - //DO NOTHING - @Override - public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) - { - result.gotResult(true, null); - return false; - } - else - return true; + dialog -> result.gotResult(false, null)); + //DO NOTHING + dlg.setOnKeyListener((dialog, keyCode, event) -> { + if (keyCode == KeyEvent.KEYCODE_BACK) + { + result.gotResult(true, null); + return false; } + else + return true; }); lastHandledDialog = dlg.show(); } @@ -77,38 +63,20 @@ public void showConfirm(String message, final Result result) { dlg.setTitle("Confirm"); dlg.setCancelable(true); dlg.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - result.gotResult(true, null); - } - }); + (dialog, which) -> result.gotResult(true, null)); dlg.setNegativeButton(android.R.string.cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - result.gotResult(false, null); - } - }); + (dialog, which) -> result.gotResult(false, null)); dlg.setOnCancelListener( - new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - result.gotResult(false, null); - } - }); - dlg.setOnKeyListener(new DialogInterface.OnKeyListener() { - //DO NOTHING - @Override - public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) - { - result.gotResult(false, null); - return false; - } - else - return true; + dialog -> result.gotResult(false, null)); + //DO NOTHING + dlg.setOnKeyListener((dialog, keyCode, event) -> { + if (keyCode == KeyEvent.KEYCODE_BACK) + { + result.gotResult(false, null); + return false; } + else + return true; }); lastHandledDialog = dlg.show(); } @@ -132,20 +100,12 @@ public void showPrompt(String message, String defaultValue, final Result result) dlg.setView(input); dlg.setCancelable(false); dlg.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String userText = input.getText().toString(); - result.gotResult(true, userText); - } + (dialog, which) -> { + String userText = input.getText().toString(); + result.gotResult(true, userText); }); dlg.setNegativeButton(android.R.string.cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - result.gotResult(false, null); - } - }); + (dialog, which) -> result.gotResult(false, null)); lastHandledDialog = dlg.show(); } @@ -156,6 +116,6 @@ public void destroyLastDialog(){ } public interface Result { - public void gotResult(boolean success, String value); + void gotResult(boolean success, String value); } } \ No newline at end of file diff --git a/framework/src/org/apache/cordova/CordovaInterface.java b/framework/src/org/apache/cordova/CordovaInterface.java index 867797227b..3a8e87b18f 100755 --- a/framework/src/org/apache/cordova/CordovaInterface.java +++ b/framework/src/org/apache/cordova/CordovaInterface.java @@ -39,14 +39,14 @@ public interface CordovaInterface { * @param intent The intent to start * @param requestCode The request code that is passed to callback to identify the activity */ - abstract public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode); + void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode); /** * Set the plugin to be called when a sub-activity exits. * * @param plugin The plugin on which onActivityResult is to be called */ - abstract public void setActivityResultCallback(CordovaPlugin plugin); + void setActivityResultCallback(CordovaPlugin plugin); /** * Get the Android activity. @@ -56,14 +56,14 @@ public interface CordovaInterface { * * @return the Activity */ - public abstract AppCompatActivity getActivity(); + AppCompatActivity getActivity(); /** * Get the Android context. * * @return the Context */ - public Context getContext(); + Context getContext(); /** * Called when a message is sent to plugin. @@ -72,28 +72,28 @@ public interface CordovaInterface { * @param data The message data * @return Object or null */ - public Object onMessage(String id, Object data); + Object onMessage(String id, Object data); /** * @return a shared thread pool that can be used for background tasks. */ - public ExecutorService getThreadPool(); + ExecutorService getThreadPool(); /** * Sends a permission request to the activity for one permission. */ - public void requestPermission(CordovaPlugin plugin, int requestCode, String permission); + void requestPermission(CordovaPlugin plugin, int requestCode, String permission); /** * Sends a permission request to the activity for a group of permissions */ - public void requestPermissions(CordovaPlugin plugin, int requestCode, String [] permissions); + void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions); /** * Check for a permission. * * @return true if the permission is granted, false otherwise. */ - public boolean hasPermission(String permission); + boolean hasPermission(String permission); } diff --git a/framework/src/org/apache/cordova/CordovaInterfaceImpl.java b/framework/src/org/apache/cordova/CordovaInterfaceImpl.java index 068c43697e..c7b3f2bb4a 100644 --- a/framework/src/org/apache/cordova/CordovaInterfaceImpl.java +++ b/framework/src/org/apache/cordova/CordovaInterfaceImpl.java @@ -23,7 +23,6 @@ Licensed to the Apache Software Foundation (ASF) under one import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.os.Build; import android.os.Bundle; import android.util.Pair; @@ -40,12 +39,12 @@ Licensed to the Apache Software Foundation (ASF) under one */ public class CordovaInterfaceImpl implements CordovaInterface { private static final String TAG = "CordovaInterfaceImpl"; - protected AppCompatActivity activity; - protected ExecutorService threadPool; + protected final AppCompatActivity activity; + protected final ExecutorService threadPool; protected PluginManager pluginManager; protected ActivityResultHolder savedResult; - protected CallbackMap permissionResultCallbacks; + protected final CallbackMap permissionResultCallbacks; protected CordovaPlugin activityResultCallback; protected String initCallbackService; protected int activityResultRequestCode; @@ -199,9 +198,9 @@ public void restoreInstanceState(Bundle savedInstanceState) { } private static class ActivityResultHolder { - private int requestCode; - private int resultCode; - private Intent intent; + private final int requestCode; + private final int resultCode; + private final Intent intent; public ActivityResultHolder(int requestCode, int resultCode, Intent intent) { this.requestCode = requestCode; diff --git a/framework/src/org/apache/cordova/CordovaPlugin.java b/framework/src/org/apache/cordova/CordovaPlugin.java index 90a12c1aac..86dec569dd 100644 --- a/framework/src/org/apache/cordova/CordovaPlugin.java +++ b/framework/src/org/apache/cordova/CordovaPlugin.java @@ -18,18 +18,12 @@ Licensed to the Apache Software Foundation (ASF) under one */ package org.apache.cordova; -import org.apache.cordova.CordovaArgs; -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.CallbackContext; import org.json.JSONArray; import org.json.JSONException; import android.content.Intent; -import android.content.pm.PackageManager; import android.content.res.Configuration; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.webkit.RenderProcessGoneDetail; import android.webkit.WebView; diff --git a/framework/src/org/apache/cordova/CordovaPreferences.java b/framework/src/org/apache/cordova/CordovaPreferences.java index 96c219c9e7..56dd22f141 100644 --- a/framework/src/org/apache/cordova/CordovaPreferences.java +++ b/framework/src/org/apache/cordova/CordovaPreferences.java @@ -23,13 +23,10 @@ Licensed to the Apache Software Foundation (ASF) under one import java.util.Locale; import java.util.Map; -import org.apache.cordova.LOG; - -import android.app.Activity; import android.os.Bundle; public class CordovaPreferences { - private HashMap prefs = new HashMap(20); + private final HashMap prefs = new HashMap<>(20); private Bundle preferencesBundleExtras; public void setPreferencesBundle(Bundle extras) { @@ -84,7 +81,11 @@ public double getDouble(String name, double defaultValue) { name = name.toLowerCase(Locale.ENGLISH); String value = prefs.get(name); if (value != null) { - return Double.valueOf(value); + try { + return Double.parseDouble(value); + } catch (NumberFormatException e) { + // Failed to parse value and will fallback with default value. + } } return defaultValue; } diff --git a/framework/src/org/apache/cordova/CordovaResourceApi.java b/framework/src/org/apache/cordova/CordovaResourceApi.java index 1d6fd6f221..80ac61ee7e 100644 --- a/framework/src/org/apache/cordova/CordovaResourceApi.java +++ b/framework/src/org/apache/cordova/CordovaResourceApi.java @@ -36,10 +36,10 @@ Licensed to the Apache Software Foundation (ASF) under one import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; import java.util.Locale; import java.util.zip.GZIPInputStream; @@ -462,11 +462,7 @@ private OpenForReadResult readDataUri(Uri uri) { if (base64) { data = Base64.decode(dataPartAsString, Base64.DEFAULT); } else { - try { - data = dataPartAsString.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - data = dataPartAsString.getBytes(); - } + data = dataPartAsString.getBytes(StandardCharsets.UTF_8); } InputStream inputStream = new ByteArrayInputStream(data); return new OpenForReadResult(uri, inputStream, contentType, data.length, null); diff --git a/framework/src/org/apache/cordova/CordovaWebViewEngine.java b/framework/src/org/apache/cordova/CordovaWebViewEngine.java index e2a45374cc..3e0d8bf663 100644 --- a/framework/src/org/apache/cordova/CordovaWebViewEngine.java +++ b/framework/src/org/apache/cordova/CordovaWebViewEngine.java @@ -66,7 +66,7 @@ void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client, * Used to retrieve the associated CordovaWebView given a View without knowing the type of Engine. * E.g. ((CordovaWebView.EngineView)activity.findViewById(android.R.id.webView)).getCordovaWebView(); */ - public interface EngineView { + interface EngineView { CordovaWebView getCordovaWebView(); } @@ -74,7 +74,7 @@ public interface EngineView { * Contains methods that an engine uses to communicate with the parent CordovaWebView. * Methods may be added in future cordova versions, but never removed. */ - public interface Client { + interface Client { Boolean onDispatchKeyEvent(KeyEvent event); void clearLoadTimeoutTimer(); void onPageStarted(String newUrl); diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java index 087ed3748b..db4d9531e8 100644 --- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java +++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java @@ -62,7 +62,7 @@ public class CordovaWebViewImpl implements CordovaWebView { private CordovaPreferences preferences; private CoreAndroid appPlugin; private NativeToJsMessageQueue nativeToJsMessageQueue; - private EngineClient engineClient = new EngineClient(); + private final EngineClient engineClient = new EngineClient(); private boolean hasPausedEver; // The URL passed to loadUrl(), not necessarily the URL of the current page. @@ -72,16 +72,16 @@ public class CordovaWebViewImpl implements CordovaWebView { private View mCustomView; private WebChromeClient.CustomViewCallback mCustomViewCallback; - private Set boundKeyCodes = new HashSet(); + private final Set boundKeyCodes = new HashSet<>(); public static CordovaWebViewEngine createEngine(Context context, CordovaPreferences preferences) { - String className = preferences.getString("webview", SystemWebViewEngine.class.getCanonicalName()); + String className = preferences.getString("WebView", SystemWebViewEngine.class.getCanonicalName()); try { Class webViewClass = Class.forName(className); Constructor constructor = webViewClass.getConstructor(Context.class, CordovaPreferences.class); return (CordovaWebViewEngine) constructor.newInstance(context, preferences); } catch (Exception e) { - throw new RuntimeException("Failed to create webview. ", e); + throw new RuntimeException("Failed to create WebView. ", e); } } @@ -91,7 +91,7 @@ public CordovaWebViewImpl(CordovaWebViewEngine cordovaWebViewEngine) { // Convenience method for when creating programmatically (not from Config.xml). public void init(CordovaInterface cordova) { - init(cordova, new ArrayList(), new CordovaPreferences()); + init(cordova, new ArrayList<>(), new CordovaPreferences()); } @SuppressLint("Assert") @@ -148,23 +148,20 @@ public void loadUrlIntoView(final String url, boolean recreatePlugins) { final int loadUrlTimeoutValue = preferences.getInteger("LoadUrlTimeoutValue", 20000); // Timeout error method - final Runnable loadError = new Runnable() { - @Override - public void run() { - stopLoading(); - LOG.e(TAG, "CordovaWebView: TIMEOUT ERROR!"); + final Runnable loadError = () -> { + stopLoading(); + LOG.e(TAG, "CordovaWebView: TIMEOUT ERROR!"); - // Handle other errors by passing them to the WebView in JS - JSONObject data = new JSONObject(); - try { - data.put("errorCode", -6); - data.put("description", "The connection to the server was unsuccessful."); - data.put("url", url); - } catch (JSONException e) { - // Will never happen. - } - pluginManager.postMessage("onReceivedError", data); + // Handle other errors by passing them to the WebView in JS + JSONObject data = new JSONObject(); + try { + data.put("errorCode", -6); + data.put("description", "The connection to the server was unsuccessful."); + data.put("url", url); + } catch (JSONException e) { + // Will never happen. } + pluginManager.postMessage("onReceivedError", data); }; // Timeout timer method @@ -190,14 +187,11 @@ public void run() { if (cordova.getActivity() != null) { final boolean _recreatePlugins = recreatePlugins; - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - if (loadUrlTimeoutValue > 0) { - cordova.getThreadPool().execute(timeoutCheck); - } - engine.loadUrl(url, _recreatePlugins); + cordova.getActivity().runOnUiThread(() -> { + if (loadUrlTimeoutValue > 0) { + cordova.getThreadPool().execute(timeoutCheck); } + engine.loadUrl(url, _recreatePlugins); }); } else { LOG.d(TAG, "Cordova activity does not exist."); @@ -228,7 +222,7 @@ public void showWebPage(String url, boolean openExternal, boolean clearHistory, loadUrlIntoView(url, true); return; } else { - LOG.w(TAG, "showWebPage: Refusing to load URL into webview since it is not in the allow list. URL=" + url); + LOG.w(TAG, "showWebPage: Refusing to load URL into WebView since it is not in the allow list. URL=" + url); return; } } @@ -581,23 +575,15 @@ public void onPageFinishedLoading(String url) { // Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly if (engine.getView().getVisibility() != View.VISIBLE) { - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(2000); - if (cordova.getActivity() != null) { - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - pluginManager.postMessage("spinner", "stop"); - } - }); - } else { - LOG.d(TAG, "Cordova activity does not exist."); - } - } catch (InterruptedException e) { + Thread t = new Thread(() -> { + try { + Thread.sleep(2000); + if (cordova.getActivity() != null) { + cordova.getActivity().runOnUiThread(() -> pluginManager.postMessage("spinner", "stop")); + } else { + LOG.d(TAG, "Cordova activity does not exist."); } + } catch (InterruptedException e) { } }); t.start(); diff --git a/framework/src/org/apache/cordova/CoreAndroid.java b/framework/src/org/apache/cordova/CoreAndroid.java index 158e46dbbf..a55f1053e5 100755 --- a/framework/src/org/apache/cordova/CoreAndroid.java +++ b/framework/src/org/apache/cordova/CoreAndroid.java @@ -19,8 +19,6 @@ Licensed to the Apache Software Foundation (ASF) under one package org.apache.cordova; -import org.apache.cordova.BuildHelper; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -87,12 +85,7 @@ else if (action.equals("show")) { // This gets called from JavaScript onCordovaReady to show the WebView. // I recommend we change the name of the Message as spinner/stop is not // indicative of what this actually does (shows the WebView). - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - webView.getPluginManager().postMessage("spinner", "stop"); - } - }); + cordova.getActivity().runOnUiThread(() -> webView.getPluginManager().postMessage("spinner", "stop")); } else if (action.equals("loadUrl")) { this.loadUrl(args.getString(0), args.optJSONObject(1)); @@ -146,12 +139,7 @@ else if (action.equals("messageChannel")) { * Clear the resource cache. */ public void clearCache() { - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - webView.clearCache(); - } - }); + cordova.getActivity().runOnUiThread(() -> webView.clearCache()); } /** @@ -168,7 +156,7 @@ public void loadUrl(String url, JSONObject props) throws JSONException { boolean clearHistory = false; // If there are properties, then set them on the Activity - HashMap params = new HashMap(); + HashMap params = new HashMap<>(); if (props != null) { JSONArray keys = props.names(); for (int i = 0; i < keys.length(); i++) { @@ -188,13 +176,13 @@ else if (key.equalsIgnoreCase("clearhistory")) { } else if (value.getClass().equals(String.class)) { - params.put(key, (String)value); + params.put(key, value); } else if (value.getClass().equals(Boolean.class)) { - params.put(key, (Boolean)value); + params.put(key, value); } else if (value.getClass().equals(Integer.class)) { - params.put(key, (Integer)value); + params.put(key, value); } } } @@ -218,12 +206,7 @@ else if (value.getClass().equals(Integer.class)) { * Clear page history for the app. */ public void clearHistory() { - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - webView.clearHistory(); - } - }); + cordova.getActivity().runOnUiThread(() -> webView.clearHistory()); } /** @@ -231,12 +214,7 @@ public void run() { * This is the same as pressing the backbutton on Android device. */ public void backHistory() { - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - webView.backHistory(); - } - }); + cordova.getActivity().runOnUiThread(() -> webView.backHistory()); } /** @@ -295,7 +273,7 @@ public void exitApp() { private void initTelephonyReceiver() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); - //final CordovaInterface mycordova = this.cordova; + //final CordovaInterface myCordova = this.cordova; this.telephonyReceiver = new BroadcastReceiver() { @Override diff --git a/framework/src/org/apache/cordova/ExposedJsApi.java b/framework/src/org/apache/cordova/ExposedJsApi.java index acc65c6fcf..3cc04d9ef5 100644 --- a/framework/src/org/apache/cordova/ExposedJsApi.java +++ b/framework/src/org/apache/cordova/ExposedJsApi.java @@ -25,7 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one * Any exposed Javascript API MUST implement these three things! */ public interface ExposedJsApi { - public String exec(int bridgeSecret, String service, String action, String callbackId, String arguments) throws JSONException, IllegalAccessException; - public void setNativeToJsBridgeMode(int bridgeSecret, int value) throws IllegalAccessException; - public String retrieveJsMessages(int bridgeSecret, boolean fromOnlineEvent) throws IllegalAccessException; + String exec(int bridgeSecret, String service, String action, String callbackId, String arguments) throws JSONException, IllegalAccessException; + void setNativeToJsBridgeMode(int bridgeSecret, int value) throws IllegalAccessException; + String retrieveJsMessages(int bridgeSecret, boolean fromOnlineEvent) throws IllegalAccessException; } diff --git a/framework/src/org/apache/cordova/ICordovaClientCertRequest.java b/framework/src/org/apache/cordova/ICordovaClientCertRequest.java index 601be9b9f6..006570758d 100644 --- a/framework/src/org/apache/cordova/ICordovaClientCertRequest.java +++ b/framework/src/org/apache/cordova/ICordovaClientCertRequest.java @@ -29,32 +29,32 @@ public interface ICordovaClientCertRequest { /** * Cancel this request */ - public void cancel(); + void cancel(); /** * @return the host name of the server requesting the certificate. */ - public String getHost(); + String getHost(); /** * @return the acceptable types of asymmetric keys (can be null). */ - public String[] getKeyTypes(); + String[] getKeyTypes(); /** * @return the port number of the server requesting the certificate. */ - public int getPort(); + int getPort(); /** * @return the acceptable certificate issuers for the certificate matching the private key (can be null). */ - public Principal[] getPrincipals(); + Principal[] getPrincipals(); /** * Ignore the request for now. Do not remember user's choice. */ - public void ignore(); + void ignore(); /** * Proceed with the specified private key and client certificate chain. Remember the user's positive choice and use it for future requests. @@ -62,5 +62,5 @@ public interface ICordovaClientCertRequest { * @param privateKey The privateKey * @param chain The certificate chain */ - public void proceed(PrivateKey privateKey, X509Certificate[] chain); + void proceed(PrivateKey privateKey, X509Certificate[] chain); } \ No newline at end of file diff --git a/framework/src/org/apache/cordova/ICordovaCookieManager.java b/framework/src/org/apache/cordova/ICordovaCookieManager.java index e776194f29..9358f13943 100644 --- a/framework/src/org/apache/cordova/ICordovaCookieManager.java +++ b/framework/src/org/apache/cordova/ICordovaCookieManager.java @@ -21,13 +21,13 @@ Licensed to the Apache Software Foundation (ASF) under one public interface ICordovaCookieManager { - public void setCookiesEnabled(boolean accept); + void setCookiesEnabled(boolean accept); - public void setCookie(final String url, final String value); + void setCookie(final String url, final String value); - public String getCookie(final String url); + String getCookie(final String url); - public void clearCookies(); + void clearCookies(); - public void flush(); -}; + void flush(); +} diff --git a/framework/src/org/apache/cordova/ICordovaHttpAuthHandler.java b/framework/src/org/apache/cordova/ICordovaHttpAuthHandler.java index c89e5b9a21..e074215b38 100644 --- a/framework/src/org/apache/cordova/ICordovaHttpAuthHandler.java +++ b/framework/src/org/apache/cordova/ICordovaHttpAuthHandler.java @@ -26,7 +26,7 @@ public interface ICordovaHttpAuthHandler { /** * Instructs the WebView to cancel the authentication request. */ - public void cancel (); + void cancel(); /** * Instructs the WebView to proceed with the authentication with the given credentials. @@ -34,5 +34,5 @@ public interface ICordovaHttpAuthHandler { * @param username The user name * @param password The password */ - public void proceed (String username, String password); + void proceed(String username, String password); } \ No newline at end of file diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index 60a1acb4fc..8ec8e33636 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -40,7 +40,7 @@ public class NativeToJsMessageQueue { // to send to the JavaScript in one shot. // This currently only chops up on message boundaries. // It may be useful to split and reassemble response messages someday. - private static int COMBINED_RESPONSE_CUTOFF = 16 * 1024 * 1024; + private static final int COMBINED_RESPONSE_CUTOFF = 16 * 1024 * 1024; /** * When true, the active listener is not fired upon enqueue. When set to false, @@ -51,12 +51,12 @@ public class NativeToJsMessageQueue { /** * The list of JavaScript statements to be sent to JavaScript. */ - private final LinkedList queue = new LinkedList(); + private final LinkedList queue = new LinkedList<>(); /** * The array of listeners that can be used to send messages to JS. */ - private ArrayList bridgeModes = new ArrayList(); + private final ArrayList bridgeModes = new ArrayList<>(); /** * When null, the bridge is disabled. This occurs during page transitions. @@ -162,8 +162,7 @@ public String popAndEncode(boolean fromOnlineEvent) { // Attach a char to indicate that there are more messages pending. sb.append('*'); } - String ret = sb.toString(); - return ret; + return sb.toString(); } } @@ -209,8 +208,7 @@ public String popAndEncodeAsJs() { for (int i = willSendAllMessages ? 1 : 0; i < numMessagesToSend; ++i) { sb.append('}'); } - String ret = sb.toString(); - return ret; + return sb.toString(); } } @@ -299,13 +297,10 @@ public LoadUrlBridgeMode(CordovaWebViewEngine engine, CordovaInterface cordova) @Override public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) { - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - String js = queue.popAndEncodeAsJs(); - if (js != null) { - engine.loadUrl("javascript:" + js, false); - } + cordova.getActivity().runOnUiThread(() -> { + String js = queue.popAndEncodeAsJs(); + if (js != null) { + engine.loadUrl("javascript:" + js, false); } }); } @@ -328,26 +323,20 @@ public OnlineEventsBridgeMode(OnlineEventsBridgeModeDelegate delegate) { @Override public void reset() { - delegate.runOnUiThread(new Runnable() { - @Override - public void run() { - online = false; - // If the following call triggers a notifyOfFlush, then ignore it. - ignoreNextFlush = true; - delegate.setNetworkAvailable(true); - } + delegate.runOnUiThread(() -> { + online = false; + // If the following call triggers a notifyOfFlush, then ignore it. + ignoreNextFlush = true; + delegate.setNetworkAvailable(true); }); } @Override public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) { - delegate.runOnUiThread(new Runnable() { - @Override - public void run() { - if (!queue.isEmpty()) { - ignoreNextFlush = false; - delegate.setNetworkAvailable(online); - } + delegate.runOnUiThread(() -> { + if (!queue.isEmpty()) { + ignoreNextFlush = false; + delegate.setNetworkAvailable(online); } }); } @@ -372,13 +361,10 @@ public EvalBridgeMode(CordovaWebViewEngine engine, CordovaInterface cordova) { @Override public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) { - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - String js = queue.popAndEncodeAsJs(); - if (js != null) { - engine.evaluateJavascript(js, null); - } + cordova.getActivity().runOnUiThread(() -> { + String js = queue.popAndEncodeAsJs(); + if (js != null) { + engine.evaluateJavascript(js, null); } }); } @@ -505,9 +491,9 @@ void buildJsMessage(StringBuilder sb) { case PluginResult.MESSAGE_TYPE_MULTIPART: int size = pluginResult.getMultipartMessagesSize(); for (int i=0; i */ public class PluginManager { - private static String TAG = "PluginManager"; + private static final String TAG = "PluginManager"; // @todo same as ConfigXmlParser. Research centralizing ideas, maybe create CordovaConstants - private static String SCHEME_HTTPS = "https"; + private static final String SCHEME_HTTPS = "https"; // @todo same as ConfigXmlParser. Research centralizing ideas, maybe create CordovaConstants - private static String DEFAULT_HOSTNAME = "localhost"; + private static final String DEFAULT_HOSTNAME = "localhost"; private static final int SLOW_EXEC_WARNING_THRESHOLD = Debug.isDebuggerConnected() ? 60 : 16; // List of service entries - private final Map pluginMap = Collections.synchronizedMap(new LinkedHashMap()); - private final Map entryMap = Collections.synchronizedMap(new LinkedHashMap()); + private final Map pluginMap = Collections.synchronizedMap(new LinkedHashMap<>()); + private final Map entryMap = Collections.synchronizedMap(new LinkedHashMap<>()); private final CordovaInterface ctx; private final CordovaWebView app; @@ -609,7 +608,7 @@ public Bundle onSaveInstanceState() { * @return list of PathHandlers in no particular order */ public ArrayList getPluginPathHandlers() { - ArrayList handlers = new ArrayList(); + ArrayList handlers = new ArrayList<>(); for (CordovaPlugin plugin : this.pluginMap.values()) { if (plugin != null && plugin.getPathHandler() != null) { handlers.add(plugin.getPathHandler()); diff --git a/framework/src/org/apache/cordova/PluginResult.java b/framework/src/org/apache/cordova/PluginResult.java index a9696fb4be..55cb69626d 100644 --- a/framework/src/org/apache/cordova/PluginResult.java +++ b/framework/src/org/apache/cordova/PluginResult.java @@ -169,7 +169,7 @@ public String toErrorCallbackString(String callbackId) { public static final int MESSAGE_TYPE_BINARYSTRING = 7; public static final int MESSAGE_TYPE_MULTIPART = 8; - public static String[] StatusMessages = new String[] { + public static final String[] StatusMessages = new String[] { "No result", "OK", "Class not found", diff --git a/framework/src/org/apache/cordova/ResumeCallback.java b/framework/src/org/apache/cordova/ResumeCallback.java index 49a43b5d46..39a57440da 100644 --- a/framework/src/org/apache/cordova/ResumeCallback.java +++ b/framework/src/org/apache/cordova/ResumeCallback.java @@ -18,7 +18,6 @@ Licensed to the Apache Software Foundation (ASF) under one */ package org.apache.cordova; - import org.json.JSONException; import org.json.JSONObject; @@ -27,8 +26,8 @@ Licensed to the Apache Software Foundation (ASF) under one public class ResumeCallback extends CallbackContext { private final String TAG = "CordovaResumeCallback"; - private String serviceName; - private PluginManager pluginManager; + private final String serviceName; + private final PluginManager pluginManager; public ResumeCallback(String serviceName, PluginManager pluginManager) { super("resumecallback", null); @@ -66,7 +65,7 @@ public void sendPluginResult(PluginResult pluginResult) { // the PluginResult passed to this CallbackContext into JSON twice. // The results are combined into an event payload before the event is // fired on the js side of things (see platform.js) - List result = new ArrayList(); + List result = new ArrayList<>(); result.add(eventResult); result.add(pluginResult); diff --git a/framework/src/org/apache/cordova/SplashScreenPlugin.java b/framework/src/org/apache/cordova/SplashScreenPlugin.java index 8f02d5219a..39c8dd1588 100644 --- a/framework/src/org/apache/cordova/SplashScreenPlugin.java +++ b/framework/src/org/apache/cordova/SplashScreenPlugin.java @@ -92,7 +92,7 @@ public boolean execute( JSONArray args, CallbackContext callbackContext ) throws JSONException { - if (action.equals("hide") && autoHide == false) { + if (action.equals("hide") && !autoHide) { /* * The `.hide()` method can only be triggered if the `splashScreenAutoHide` * is set to `false`. diff --git a/framework/src/org/apache/cordova/allowlist/index.html b/framework/src/org/apache/cordova/allowlist/index.html deleted file mode 100755 index 24cac6eb33..0000000000 --- a/framework/src/org/apache/cordova/allowlist/index.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - Cordova Tests - - - - - -

Allow List Page 1

-
-

Cordova:  

-

Deviceready:  

-
-
- Loading Page 2 should be successful.
- Loading Page 3 should be in web browser.
- Loading Page 2 with target=_blank should be in web browser?
- (THIS DOESN'T HAPPEN.) https://issues.apache.org/jira/browse/CB-362 -
- Page 2 - Page 3 - Page 2 with target=_blank - - diff --git a/framework/src/org/apache/cordova/allowlist/index2.html b/framework/src/org/apache/cordova/allowlist/index2.html deleted file mode 100755 index bb475a8774..0000000000 --- a/framework/src/org/apache/cordova/allowlist/index2.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - Cordova Tests - - - - - -

Allow List Page 2

-
-

Cordova:  

-

Deviceready:  

-
-
- Press "backbutton" -
- - diff --git a/framework/src/org/apache/cordova/engine/SystemCookieManager.java b/framework/src/org/apache/cordova/engine/SystemCookieManager.java index 16cf548250..5e589f2e08 100644 --- a/framework/src/org/apache/cordova/engine/SystemCookieManager.java +++ b/framework/src/org/apache/cordova/engine/SystemCookieManager.java @@ -65,4 +65,4 @@ public void clearCookies() { public void flush() { cookieManager.flush(); } -}; +} diff --git a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index 6ed2bdaa99..b8f9b6798d 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -59,16 +59,16 @@ Licensed to the Apache Software Foundation (ASF) under one */ public class SystemWebChromeClient extends WebChromeClient { - private static final int FILECHOOSER_RESULTCODE = 5173; + private static final int FILE_CHOOSER_RESULT_CODE = 5173; private static final String LOG_TAG = "SystemWebChromeClient"; - private long MAX_QUOTA = 100 * 1024 * 1024; + private final long MAX_QUOTA = 100 * 1024 * 1024; protected final SystemWebViewEngine parentEngine; // the video progress view private View mVideoProgressView; - private CordovaDialogsHelper dialogsHelper; - private Context appContext; + private final CordovaDialogsHelper dialogsHelper; + private final Context appContext; private WebChromeClient.CustomViewCallback mCustomViewCallback; private View mCustomView; @@ -84,13 +84,11 @@ public SystemWebChromeClient(SystemWebViewEngine parentEngine) { */ @Override public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { - dialogsHelper.showAlert(message, new CordovaDialogsHelper.Result() { - @Override public void gotResult(boolean success, String value) { - if (success) { - result.confirm(); - } else { - result.cancel(); - } + dialogsHelper.showAlert(message, (success, value) -> { + if (success) { + result.confirm(); + } else { + result.cancel(); } }); return true; @@ -101,14 +99,11 @@ public boolean onJsAlert(WebView view, String url, String message, final JsResul */ @Override public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { - dialogsHelper.showConfirm(message, new CordovaDialogsHelper.Result() { - @Override - public void gotResult(boolean success, String value) { - if (success) { - result.confirm(); - } else { - result.cancel(); - } + dialogsHelper.showConfirm(message, (success, value) -> { + if (success) { + result.confirm(); + } else { + result.cancel(); } }); return true; @@ -129,14 +124,11 @@ public boolean onJsPrompt(WebView view, String origin, String message, String de if (handledRet != null) { result.confirm(handledRet); } else { - dialogsHelper.showPrompt(message, defaultValue, new CordovaDialogsHelper.Result() { - @Override - public void gotResult(boolean success, String value) { - if (success) { - result.confirm(value); - } else { - result.cancel(); - } + dialogsHelper.showPrompt(message, defaultValue, (success, value) -> { + if (success) { + result.confirm(value); + } else { + result.cancel(); } }); } @@ -275,7 +267,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Handle result Uri[] result = null; if (resultCode == Activity.RESULT_OK) { - List uris = new ArrayList(); + List uris = new ArrayList<>(); if (intent != null && intent.getData() != null) { // single file LOG.v(LOG_TAG, "Adding file (single): " + intent.getData()); @@ -302,7 +294,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) { } filePathsCallback.onReceiveValue(result); } - }, chooserIntent, FILECHOOSER_RESULTCODE); + }, chooserIntent, FILE_CHOOSER_RESULT_CODE); } catch (ActivityNotFoundException e) { LOG.w(LOG_TAG, "No activity found to handle file chooser intent.", e); filePathsCallback.onReceiveValue(null); @@ -311,15 +303,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) { } private File createTempFile(Context context) throws IOException { - // Create an image file name - File tempFile = File.createTempFile("temp", ".jpg", context.getCacheDir()); - return tempFile; + // Create a temp image file name + return File.createTempFile("temp", ".jpg", context.getCacheDir()); } private Uri createUriForFile(Context context, File tempFile) throws IOException { String appId = context.getPackageName(); - Uri uri = FileProvider.getUriForFile(context, appId + ".cdv.core.file.provider", tempFile); - return uri; + return FileProvider.getUriForFile(context, appId + ".cdv.core.file.provider", tempFile); } @Override diff --git a/framework/src/org/apache/cordova/engine/SystemWebView.java b/framework/src/org/apache/cordova/engine/SystemWebView.java index 01c2f00058..f8b787c49c 100644 --- a/framework/src/org/apache/cordova/engine/SystemWebView.java +++ b/framework/src/org/apache/cordova/engine/SystemWebView.java @@ -81,7 +81,7 @@ public void setWebChromeClient(WebChromeClient client) { public boolean dispatchKeyEvent(KeyEvent event) { Boolean ret = parentEngine.client.onDispatchKeyEvent(event); if (ret != null) { - return ret.booleanValue(); + return ret; } return super.dispatchKeyEvent(event); } diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java index dcf3beed72..7e286e20fe 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java @@ -68,7 +68,7 @@ public class SystemWebViewClient extends WebViewClient { boolean isCurrentlyLoading; /** The authorization tokens. */ - private Hashtable authenticationTokens = new Hashtable(); + private final Hashtable authenticationTokens = new Hashtable<>(); public SystemWebViewClient(SystemWebViewEngine parentEngine) { this.parentEngine = parentEngine; @@ -88,7 +88,7 @@ public SystemWebViewClient(SystemWebViewEngine parentEngine) { if (response != null) { return response; } - }; + } } } diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java index 2387836571..5ed73a6b6d 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java @@ -20,13 +20,11 @@ Licensed to the Apache Software Foundation (ASF) under one package org.apache.cordova.engine; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; -import android.os.Build; import android.view.View; import android.webkit.ValueCallback; import android.webkit.WebSettings; @@ -44,9 +42,6 @@ Licensed to the Apache Software Foundation (ASF) under one import org.apache.cordova.NativeToJsMessageQueue; import org.apache.cordova.PluginManager; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - /** * Glue class between CordovaWebView (main Cordova logic) and SystemWebView (the actual View). @@ -178,13 +173,13 @@ private void initWebViewSettings() { // The default is to use the module's debuggable state to decide if the WebView inspector // should be enabled. However, users can configure InspectableWebView preference to forcefully enable // or disable the WebView inspector. - String inspectableWebview = preferences.getString("InspectableWebview", null); + String inspectableWebView = preferences.getString("InspectableWebView", null); boolean shouldEnableInspector = false; - if (inspectableWebview == null) { + if (inspectableWebView == null) { ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo(); shouldEnableInspector = (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; } - else if ("true".equals(inspectableWebview)) { + else if ("true".equals(inspectableWebView)) { shouldEnableInspector = true; }