Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp: Cordova-Android 14 & SDK 35 Test PR #1745

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions framework/src/org/apache/cordova/AllowList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -97,7 +94,7 @@ public boolean matches(Uri uri) {
public static final String TAG = "CordovaAllowList";

public AllowList() {
this.allowList = new ArrayList<URLPattern>();
this.allowList = new ArrayList<>();
}

/* Match patterns (from http://developer.chrome.com/extensions/match_patterns.html)
Expand Down Expand Up @@ -157,9 +154,7 @@ public boolean isUrlAllowListed(String uri) {

Uri parsedUri = Uri.parse(uri);
// Look for match in allow list
Iterator<URLPattern> pit = allowList.iterator();
while (pit.hasNext()) {
URLPattern p = pit.next();
for (URLPattern p : allowList) {
if (p.matches(parsedUri)) {
return true;
}
Expand Down
7 changes: 1 addition & 6 deletions framework/src/org/apache/cordova/AllowListPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions framework/src/org/apache/cordova/BuildHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions framework/src/org/apache/cordova/CallbackContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions framework/src/org/apache/cordova/CallbackMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ Licensed to the Apache Software Foundation (ASF) under one
*/
public class CallbackMap {
private int currentCallbackId = 0;
private SparseArray<Pair<CordovaPlugin, Integer>> callbacks;
private final SparseArray<Pair<CordovaPlugin, Integer>> callbacks;

public CallbackMap() {
this.callbacks = new SparseArray<Pair<CordovaPlugin, Integer>>();
this.callbacks = new SparseArray<>();
}

/**
Expand All @@ -45,7 +45,7 @@ public CallbackMap() {
*/
public synchronized int registerCallback(CordovaPlugin receiver, int requestCode) {
int mappedId = this.currentCallbackId++;
callbacks.put(mappedId, new Pair<CordovaPlugin, Integer>(receiver, requestCode));
callbacks.put(mappedId, new Pair<>(receiver, requestCode));
return mappedId;
}

Expand Down
2 changes: 1 addition & 1 deletion framework/src/org/apache/cordova/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginEntry> getPluginEntries() {
Expand Down
16 changes: 7 additions & 9 deletions framework/src/org/apache/cordova/ConfigXmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginEntry> pluginEntries = new ArrayList<PluginEntry>(20);
private final CordovaPreferences prefs = new CordovaPreferences();
private final ArrayList<PluginEntry> pluginEntries = new ArrayList<>(20);

public CordovaPreferences getPreferences() {
return prefs;
Expand Down Expand Up @@ -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();
}
}
Expand Down
74 changes: 30 additions & 44 deletions framework/src/org/apache/cordova/CordovaActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -75,14 +75,14 @@ Licensed to the Apache Software Foundation (ASF) under one
* <p>The use of the set*Property() methods is deprecated in favor of the config.xml file.</p>
*/
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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
});
}
Expand All @@ -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();
}
});
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion framework/src/org/apache/cordova/CordovaArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions framework/src/org/apache/cordova/CordovaBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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 "";
Expand All @@ -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 "";
Expand Down
Loading