From b95c2dd8704e5a22b6d9c326a4834a933da69d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Thu, 5 Dec 2024 18:10:56 +0900 Subject: [PATCH 01/16] chore: remove allowlist index.html files from framework --- .../org/apache/cordova/allowlist/index.html | 45 ------------------- .../org/apache/cordova/allowlist/index2.html | 39 ---------------- 2 files changed, 84 deletions(-) delete mode 100755 framework/src/org/apache/cordova/allowlist/index.html delete mode 100755 framework/src/org/apache/cordova/allowlist/index2.html 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" -
- - From 59c71475c3b1c212bdd68e514aaa49edfff4697c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Thu, 5 Dec 2024 18:23:44 +0900 Subject: [PATCH 02/16] refactor: java 5 migration aid - remove unnecessary boxing --- framework/src/org/apache/cordova/CordovaPreferences.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/CordovaPreferences.java b/framework/src/org/apache/cordova/CordovaPreferences.java index 96c219c9e7..8dc5d23057 100644 --- a/framework/src/org/apache/cordova/CordovaPreferences.java +++ b/framework/src/org/apache/cordova/CordovaPreferences.java @@ -84,7 +84,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; } From 6a9493a95b04dd6b4f642e85c737190a6098d6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Thu, 5 Dec 2024 18:24:23 +0900 Subject: [PATCH 03/16] refactor: java 5 migration aid - remove unnecessary unboxing --- framework/src/org/apache/cordova/engine/SystemWebView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } From e843a4f7f03f01da9de7a55e4f756b109a2ec16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Thu, 5 Dec 2024 18:24:54 +0900 Subject: [PATCH 04/16] refactor: java 5 migration aid - use for loop --- framework/src/org/apache/cordova/AllowList.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/AllowList.java b/framework/src/org/apache/cordova/AllowList.java index 4b4bafcce9..55cb9d014a 100644 --- a/framework/src/org/apache/cordova/AllowList.java +++ b/framework/src/org/apache/cordova/AllowList.java @@ -157,9 +157,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; } From a426b039d1ae9601c96a270db4b20f2007de1530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Thu, 5 Dec 2024 18:25:32 +0900 Subject: [PATCH 05/16] refactor: java 7 migration aid - replace explicit type with <> --- framework/src/org/apache/cordova/AllowList.java | 2 +- framework/src/org/apache/cordova/CallbackMap.java | 4 ++-- framework/src/org/apache/cordova/ConfigXmlParser.java | 2 +- framework/src/org/apache/cordova/CordovaPreferences.java | 2 +- framework/src/org/apache/cordova/CordovaWebViewImpl.java | 4 ++-- framework/src/org/apache/cordova/CoreAndroid.java | 2 +- .../src/org/apache/cordova/NativeToJsMessageQueue.java | 4 ++-- framework/src/org/apache/cordova/PluginManager.java | 6 +++--- framework/src/org/apache/cordova/ResumeCallback.java | 2 +- .../org/apache/cordova/engine/SystemWebChromeClient.java | 2 +- .../src/org/apache/cordova/engine/SystemWebViewClient.java | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/framework/src/org/apache/cordova/AllowList.java b/framework/src/org/apache/cordova/AllowList.java index 55cb9d014a..27e3f5338a 100644 --- a/framework/src/org/apache/cordova/AllowList.java +++ b/framework/src/org/apache/cordova/AllowList.java @@ -97,7 +97,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) diff --git a/framework/src/org/apache/cordova/CallbackMap.java b/framework/src/org/apache/cordova/CallbackMap.java index b825610c5d..5dab8b8d28 100644 --- a/framework/src/org/apache/cordova/CallbackMap.java +++ b/framework/src/org/apache/cordova/CallbackMap.java @@ -31,7 +31,7 @@ public class CallbackMap { private 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/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java index 0b92e96b63..9d4a768db4 100644 --- a/framework/src/org/apache/cordova/ConfigXmlParser.java +++ b/framework/src/org/apache/cordova/ConfigXmlParser.java @@ -39,7 +39,7 @@ public class ConfigXmlParser { private String launchUrl; private String contentSrc; private CordovaPreferences prefs = new CordovaPreferences(); - private ArrayList pluginEntries = new ArrayList(20); + private ArrayList pluginEntries = new ArrayList<>(20); public CordovaPreferences getPreferences() { return prefs; diff --git a/framework/src/org/apache/cordova/CordovaPreferences.java b/framework/src/org/apache/cordova/CordovaPreferences.java index 8dc5d23057..0ed3cb89d5 100644 --- a/framework/src/org/apache/cordova/CordovaPreferences.java +++ b/framework/src/org/apache/cordova/CordovaPreferences.java @@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one import android.os.Bundle; public class CordovaPreferences { - private HashMap prefs = new HashMap(20); + private HashMap prefs = new HashMap<>(20); private Bundle preferencesBundleExtras; public void setPreferencesBundle(Bundle extras) { diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java index 087ed3748b..68a1acf366 100644 --- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java +++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java @@ -72,7 +72,7 @@ public class CordovaWebViewImpl implements CordovaWebView { private View mCustomView; private WebChromeClient.CustomViewCallback mCustomViewCallback; - private Set boundKeyCodes = new HashSet(); + private Set boundKeyCodes = new HashSet<>(); public static CordovaWebViewEngine createEngine(Context context, CordovaPreferences preferences) { String className = preferences.getString("webview", SystemWebViewEngine.class.getCanonicalName()); @@ -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") diff --git a/framework/src/org/apache/cordova/CoreAndroid.java b/framework/src/org/apache/cordova/CoreAndroid.java index 158e46dbbf..73dc286edb 100755 --- a/framework/src/org/apache/cordova/CoreAndroid.java +++ b/framework/src/org/apache/cordova/CoreAndroid.java @@ -168,7 +168,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++) { diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index 60a1acb4fc..ed3ab16259 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -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 ArrayList bridgeModes = new ArrayList<>(); /** * When null, the bridge is disabled. This occurs during page transitions. diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java index 24560c2f36..4e6ec600c8 100755 --- a/framework/src/org/apache/cordova/PluginManager.java +++ b/framework/src/org/apache/cordova/PluginManager.java @@ -52,8 +52,8 @@ public class PluginManager { 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 +609,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/ResumeCallback.java b/framework/src/org/apache/cordova/ResumeCallback.java index 49a43b5d46..25e0723f20 100644 --- a/framework/src/org/apache/cordova/ResumeCallback.java +++ b/framework/src/org/apache/cordova/ResumeCallback.java @@ -66,7 +66,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/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index 6ed2bdaa99..a5543672c9 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -275,7 +275,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()); diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java index dcf3beed72..f5a84d9df6 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 Hashtable authenticationTokens = new Hashtable<>(); public SystemWebViewClient(SystemWebViewEngine parentEngine) { this.parentEngine = parentEngine; From 2b5407e1d59f0416b05d2a1a872cba1aa24df4cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Thu, 5 Dec 2024 18:25:56 +0900 Subject: [PATCH 06/16] refactor: java 7 migration aid - collapse identical catch --- framework/src/org/apache/cordova/ConfigXmlParser.java | 4 +--- framework/src/org/apache/cordova/CordovaBridge.java | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java index 9d4a768db4..00f7afc209 100644 --- a/framework/src/org/apache/cordova/ConfigXmlParser.java +++ b/framework/src/org/apache/cordova/ConfigXmlParser.java @@ -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/CordovaBridge.java b/framework/src/org/apache/cordova/CordovaBridge.java index a8e8369232..99d260b2c9 100644 --- a/framework/src/org/apache/cordova/CordovaBridge.java +++ b/framework/src/org/apache/cordova/CordovaBridge.java @@ -136,9 +136,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 +146,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 ""; From 067b642fcaa700a8c95600a135ce0ff0baab2c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Thu, 5 Dec 2024 18:30:32 +0900 Subject: [PATCH 07/16] refactor: java 8 migration aid - replace with lambda --- .../org/apache/cordova/CordovaActivity.java | 58 +++++------- .../apache/cordova/CordovaDialogsHelper.java | 89 ++++++------------- .../apache/cordova/CordovaWebViewImpl.java | 62 +++++-------- .../src/org/apache/cordova/CoreAndroid.java | 28 +----- .../cordova/NativeToJsMessageQueue.java | 46 ++++------ .../cordova/engine/SystemWebChromeClient.java | 38 ++++---- 6 files changed, 107 insertions(+), 214 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 50d6b3232c..24dac13ef9 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -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(); } }); } diff --git a/framework/src/org/apache/cordova/CordovaDialogsHelper.java b/framework/src/org/apache/cordova/CordovaDialogsHelper.java index f74ad8e74e..f418608d82 100644 --- a/framework/src/org/apache/cordova/CordovaDialogsHelper.java +++ b/framework/src/org/apache/cordova/CordovaDialogsHelper.java @@ -42,31 +42,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 +64,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 +101,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(); } diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java index 68a1acf366..40fd76e4d6 100644 --- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java +++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java @@ -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."); @@ -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 73dc286edb..5eac5d4cfd 100755 --- a/framework/src/org/apache/cordova/CoreAndroid.java +++ b/framework/src/org/apache/cordova/CoreAndroid.java @@ -87,12 +87,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 +141,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()); } /** @@ -218,12 +208,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 +216,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()); } /** diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index ed3ab16259..0136ad4fa4 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -299,13 +299,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 +325,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 +363,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); } }); } diff --git a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index a5543672c9..1ec36cb811 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -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(); } }); } From 7e5e3b9bfaf6d885bdc8db5bcbc4341c70927c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 01:41:40 +0900 Subject: [PATCH 08/16] refactor: remove redundant casting --- framework/src/org/apache/cordova/CoreAndroid.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/CoreAndroid.java b/framework/src/org/apache/cordova/CoreAndroid.java index 5eac5d4cfd..277c4f9f3e 100755 --- a/framework/src/org/apache/cordova/CoreAndroid.java +++ b/framework/src/org/apache/cordova/CoreAndroid.java @@ -178,13 +178,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); } } } From 0b40daf4e073731c6c9fe259ace09951e3126ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 02:42:28 +0900 Subject: [PATCH 09/16] refactor: remove pointless boolean expression --- framework/src/org/apache/cordova/SplashScreenPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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`. From 8e161e8557274be8fc700bcabd92be2ce6a53791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 02:44:13 +0900 Subject: [PATCH 10/16] refactor: remove redundant local variable --- .../src/org/apache/cordova/NativeToJsMessageQueue.java | 6 ++---- .../org/apache/cordova/engine/SystemWebChromeClient.java | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index 0136ad4fa4..036f661114 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -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(); } } diff --git a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index 1ec36cb811..2ac248c73d 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -303,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 From 31f9ade9897df7e66c5f88a5530406e5ab94a252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 02:48:35 +0900 Subject: [PATCH 11/16] refactor: update onRequestPermissionsResult to match w/ FragmentActivity --- framework/src/org/apache/cordova/CordovaActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 24dac13ef9..6b4e9cc3f7 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -41,6 +41,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; @@ -508,8 +509,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 From f44f3cfb5dc40257158c9ecdf3e7e6f65329414a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 03:00:06 +0900 Subject: [PATCH 12/16] refactor: use StandardCharsets and remove redundant try-catch --- framework/src/org/apache/cordova/CordovaResourceApi.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaResourceApi.java b/framework/src/org/apache/cordova/CordovaResourceApi.java index 1d6fd6f221..e207c40f82 100644 --- a/framework/src/org/apache/cordova/CordovaResourceApi.java +++ b/framework/src/org/apache/cordova/CordovaResourceApi.java @@ -40,6 +40,7 @@ Licensed to the Apache Software Foundation (ASF) under one 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 +463,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); From 7a73f4b5953e32a60d098c92569f94eb2aab8baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 03:01:31 +0900 Subject: [PATCH 13/16] refactor: remove unnecessary semicolon --- framework/src/org/apache/cordova/ICordovaCookieManager.java | 2 +- .../src/org/apache/cordova/engine/SystemCookieManager.java | 2 +- .../src/org/apache/cordova/engine/SystemWebViewClient.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/ICordovaCookieManager.java b/framework/src/org/apache/cordova/ICordovaCookieManager.java index e776194f29..dfd1795db2 100644 --- a/framework/src/org/apache/cordova/ICordovaCookieManager.java +++ b/framework/src/org/apache/cordova/ICordovaCookieManager.java @@ -30,4 +30,4 @@ public interface ICordovaCookieManager { public void clearCookies(); public void flush(); -}; +} 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/SystemWebViewClient.java b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java index f5a84d9df6..6bfb25283a 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java @@ -88,7 +88,7 @@ public SystemWebViewClient(SystemWebViewEngine parentEngine) { if (response != null) { return response; } - }; + } } } From b507a67f022f02b346c557d7a19a2c569f49fe70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 02:55:26 +0900 Subject: [PATCH 14/16] refactor: update variable & method modifiers --- .../org/apache/cordova/AllowListPlugin.java | 2 +- .../src/org/apache/cordova/BuildHelper.java | 2 +- .../org/apache/cordova/CallbackContext.java | 4 ++-- .../src/org/apache/cordova/CallbackMap.java | 2 +- .../org/apache/cordova/ConfigXmlParser.java | 12 ++++++------ .../org/apache/cordova/CordovaActivity.java | 8 ++++---- .../src/org/apache/cordova/CordovaArgs.java | 2 +- .../src/org/apache/cordova/CordovaBridge.java | 4 ++-- .../apache/cordova/CordovaDialogsHelper.java | 2 +- .../org/apache/cordova/CordovaInterface.java | 18 +++++++++--------- .../apache/cordova/CordovaInterfaceImpl.java | 12 ++++++------ .../org/apache/cordova/CordovaPreferences.java | 2 +- .../apache/cordova/CordovaWebViewEngine.java | 4 ++-- .../org/apache/cordova/CordovaWebViewImpl.java | 4 ++-- .../src/org/apache/cordova/ExposedJsApi.java | 6 +++--- .../cordova/ICordovaClientCertRequest.java | 14 +++++++------- .../apache/cordova/ICordovaCookieManager.java | 10 +++++----- .../cordova/ICordovaHttpAuthHandler.java | 4 ++-- .../apache/cordova/NativeToJsMessageQueue.java | 4 ++-- .../src/org/apache/cordova/PluginManager.java | 6 +++--- .../src/org/apache/cordova/PluginResult.java | 2 +- .../src/org/apache/cordova/ResumeCallback.java | 4 ++-- .../cordova/engine/SystemWebChromeClient.java | 6 +++--- .../cordova/engine/SystemWebViewClient.java | 2 +- 24 files changed, 68 insertions(+), 68 deletions(-) diff --git a/framework/src/org/apache/cordova/AllowListPlugin.java b/framework/src/org/apache/cordova/AllowListPlugin.java index e85f8ecded..d563403923 100644 --- a/framework/src/org/apache/cordova/AllowListPlugin.java +++ b/framework/src/org/apache/cordova/AllowListPlugin.java @@ -74,7 +74,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..fce600a4e1 100644 --- a/framework/src/org/apache/cordova/BuildHelper.java +++ b/framework/src/org/apache/cordova/BuildHelper.java @@ -35,7 +35,7 @@ Licensed to the Apache Software Foundation (ASF) under one 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..b0d55c7258 100644 --- a/framework/src/org/apache/cordova/CallbackContext.java +++ b/framework/src/org/apache/cordova/CallbackContext.java @@ -27,8 +27,8 @@ Licensed to the Apache Software Foundation (ASF) under one 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 5dab8b8d28..5551d13c41 100644 --- a/framework/src/org/apache/cordova/CallbackMap.java +++ b/framework/src/org/apache/cordova/CallbackMap.java @@ -28,7 +28,7 @@ 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<>(); diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java index 00f7afc209..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; diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 6b4e9cc3f7..be73d67c7a 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -76,14 +76,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 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 99d260b2c9..2e83c1318c 100644 --- a/framework/src/org/apache/cordova/CordovaBridge.java +++ b/framework/src/org/apache/cordova/CordovaBridge.java @@ -32,8 +32,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) { diff --git a/framework/src/org/apache/cordova/CordovaDialogsHelper.java b/framework/src/org/apache/cordova/CordovaDialogsHelper.java index f418608d82..1c4b0536ef 100644 --- a/framework/src/org/apache/cordova/CordovaDialogsHelper.java +++ b/framework/src/org/apache/cordova/CordovaDialogsHelper.java @@ -117,6 +117,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..3384a51c21 100644 --- a/framework/src/org/apache/cordova/CordovaInterfaceImpl.java +++ b/framework/src/org/apache/cordova/CordovaInterfaceImpl.java @@ -40,12 +40,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 +199,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/CordovaPreferences.java b/framework/src/org/apache/cordova/CordovaPreferences.java index 0ed3cb89d5..2352036b85 100644 --- a/framework/src/org/apache/cordova/CordovaPreferences.java +++ b/framework/src/org/apache/cordova/CordovaPreferences.java @@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one 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) { 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 40fd76e4d6..ad124a1e4f 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,7 +72,7 @@ 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()); 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 dfd1795db2..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 036f661114..c687a95524 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, @@ -56,7 +56,7 @@ public class NativeToJsMessageQueue { /** * 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. diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java index 4e6ec600c8..9d882d69ea 100755 --- a/framework/src/org/apache/cordova/PluginManager.java +++ b/framework/src/org/apache/cordova/PluginManager.java @@ -42,12 +42,12 @@ Licensed to the Apache Software Foundation (ASF) under one * from JavaScript.

*/ 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; 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 25e0723f20..4f05add8ac 100644 --- a/framework/src/org/apache/cordova/ResumeCallback.java +++ b/framework/src/org/apache/cordova/ResumeCallback.java @@ -27,8 +27,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); diff --git a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index 2ac248c73d..88921a5000 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -61,14 +61,14 @@ public class SystemWebChromeClient extends WebChromeClient { private static final int FILECHOOSER_RESULTCODE = 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; diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java index 6bfb25283a..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; From a609d7a16790140b56a0acc154c9f70e1274e652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 03:20:14 +0900 Subject: [PATCH 15/16] refactor: remove unused imports --- framework/src/org/apache/cordova/AllowList.java | 3 --- framework/src/org/apache/cordova/AllowListPlugin.java | 5 ----- framework/src/org/apache/cordova/BuildHelper.java | 2 -- framework/src/org/apache/cordova/CallbackContext.java | 3 --- framework/src/org/apache/cordova/CordovaActivity.java | 1 - framework/src/org/apache/cordova/CordovaBridge.java | 2 -- framework/src/org/apache/cordova/CordovaDialogsHelper.java | 1 - framework/src/org/apache/cordova/CordovaInterfaceImpl.java | 1 - framework/src/org/apache/cordova/CordovaPlugin.java | 6 ------ framework/src/org/apache/cordova/CordovaPreferences.java | 3 --- framework/src/org/apache/cordova/CordovaResourceApi.java | 1 - framework/src/org/apache/cordova/CoreAndroid.java | 2 -- framework/src/org/apache/cordova/PluginEntry.java | 2 -- framework/src/org/apache/cordova/PluginManager.java | 1 - framework/src/org/apache/cordova/ResumeCallback.java | 1 - .../src/org/apache/cordova/engine/SystemWebViewEngine.java | 5 ----- 16 files changed, 39 deletions(-) diff --git a/framework/src/org/apache/cordova/AllowList.java b/framework/src/org/apache/cordova/AllowList.java index 27e3f5338a..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 { diff --git a/framework/src/org/apache/cordova/AllowListPlugin.java b/framework/src/org/apache/cordova/AllowListPlugin.java index d563403923..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; diff --git a/framework/src/org/apache/cordova/BuildHelper.java b/framework/src/org/apache/cordova/BuildHelper.java index fce600a4e1..a738af510e 100644 --- a/framework/src/org/apache/cordova/BuildHelper.java +++ b/framework/src/org/apache/cordova/BuildHelper.java @@ -26,12 +26,10 @@ 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 { diff --git a/framework/src/org/apache/cordova/CallbackContext.java b/framework/src/org/apache/cordova/CallbackContext.java index b0d55c7258..e708957a8c 100644 --- a/framework/src/org/apache/cordova/CallbackContext.java +++ b/framework/src/org/apache/cordova/CallbackContext.java @@ -19,9 +19,6 @@ 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 { diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index be73d67c7a..67d7724348 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; diff --git a/framework/src/org/apache/cordova/CordovaBridge.java b/framework/src/org/apache/cordova/CordovaBridge.java index 2e83c1318c..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; diff --git a/framework/src/org/apache/cordova/CordovaDialogsHelper.java b/framework/src/org/apache/cordova/CordovaDialogsHelper.java index 1c4b0536ef..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; diff --git a/framework/src/org/apache/cordova/CordovaInterfaceImpl.java b/framework/src/org/apache/cordova/CordovaInterfaceImpl.java index 3384a51c21..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; 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 2352036b85..56dd22f141 100644 --- a/framework/src/org/apache/cordova/CordovaPreferences.java +++ b/framework/src/org/apache/cordova/CordovaPreferences.java @@ -23,9 +23,6 @@ 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 { diff --git a/framework/src/org/apache/cordova/CordovaResourceApi.java b/framework/src/org/apache/cordova/CordovaResourceApi.java index e207c40f82..80ac61ee7e 100644 --- a/framework/src/org/apache/cordova/CordovaResourceApi.java +++ b/framework/src/org/apache/cordova/CordovaResourceApi.java @@ -36,7 +36,6 @@ 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; diff --git a/framework/src/org/apache/cordova/CoreAndroid.java b/framework/src/org/apache/cordova/CoreAndroid.java index 277c4f9f3e..63e8b1a241 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; diff --git a/framework/src/org/apache/cordova/PluginEntry.java b/framework/src/org/apache/cordova/PluginEntry.java index 1b5199596d..8d13e1cb53 100755 --- a/framework/src/org/apache/cordova/PluginEntry.java +++ b/framework/src/org/apache/cordova/PluginEntry.java @@ -18,8 +18,6 @@ Licensed to the Apache Software Foundation (ASF) under one */ package org.apache.cordova; -import org.apache.cordova.CordovaPlugin; - /** * This class represents a service entry object. */ diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java index 9d882d69ea..7fa9ed7f38 100755 --- a/framework/src/org/apache/cordova/PluginManager.java +++ b/framework/src/org/apache/cordova/PluginManager.java @@ -31,7 +31,6 @@ Licensed to the Apache Software Foundation (ASF) under one import android.net.Uri; import android.os.Bundle; import android.os.Debug; -import android.os.Build; import android.webkit.RenderProcessGoneDetail; import android.webkit.WebView; diff --git a/framework/src/org/apache/cordova/ResumeCallback.java b/framework/src/org/apache/cordova/ResumeCallback.java index 4f05add8ac..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; diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java index 2387836571..eefaeab165 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). From 6bd9636fea699fb33acffdc8a9ec6f574b6ba872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Sun, 29 Dec 2024 14:42:07 +0900 Subject: [PATCH 16/16] refactor: cleanup typos --- framework/src/org/apache/cordova/Config.java | 2 +- framework/src/org/apache/cordova/CordovaActivity.java | 2 +- framework/src/org/apache/cordova/CordovaWebViewImpl.java | 6 +++--- framework/src/org/apache/cordova/CoreAndroid.java | 2 +- .../src/org/apache/cordova/NativeToJsMessageQueue.java | 6 +++--- .../org/apache/cordova/engine/SystemWebChromeClient.java | 4 ++-- .../src/org/apache/cordova/engine/SystemWebViewEngine.java | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) 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/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 67d7724348..3f81446e91 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -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"); diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java index ad124a1e4f..db4d9531e8 100644 --- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java +++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java @@ -75,13 +75,13 @@ public class CordovaWebViewImpl implements CordovaWebView { 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); } } @@ -222,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; } } diff --git a/framework/src/org/apache/cordova/CoreAndroid.java b/framework/src/org/apache/cordova/CoreAndroid.java index 63e8b1a241..a55f1053e5 100755 --- a/framework/src/org/apache/cordova/CoreAndroid.java +++ b/framework/src/org/apache/cordova/CoreAndroid.java @@ -273,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/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index c687a95524..8ec8e33636 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -491,9 +491,9 @@ void buildJsMessage(StringBuilder sb) { case PluginResult.MESSAGE_TYPE_MULTIPART: int size = pluginResult.getMultipartMessagesSize(); for (int i=0; i