@capacitor/android 3.5.0 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,28 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [3.5.0](https://github.com/ionic-team/capacitor/compare/3.4.3...3.5.0) (2022-04-22)
6
+ # [4.0.0-alpha.2](https://github.com/ionic-team/capacitor/compare/3.4.1...4.0.0-alpha.2) (2022-05-12)
7
7
 
8
8
 
9
- ### Features
9
+ ### Bug Fixes
10
10
 
11
- * **android:** Add overridable routing for WebViewLocalServer ([#5553](https://github.com/ionic-team/capacitor/issues/5553)) ([3bb288e](https://github.com/ionic-team/capacitor/commit/3bb288e848c5c0e49c1e58c0782e0b1ffd7b1f31))
11
+ * **android:** make removeAllListeners return a promise ([#5527](https://github.com/ionic-team/capacitor/issues/5527)) ([6f4d858](https://github.com/ionic-team/capacitor/commit/6f4d858ea879d97109c0c7da2d664d04806adc2a))
12
+ * **android:** prevent app from loading if server.url is invalid ([d4a0dea](https://github.com/ionic-team/capacitor/commit/d4a0deaa37eda4476f0be030e266c2c1260fc6e8))
12
13
 
13
14
 
15
+ ### Features
14
16
 
17
+ * **android:** don't allow server.androidScheme to be set to schemes handled by WebView ([01285ba](https://github.com/ionic-team/capacitor/commit/01285ba253d602b08a41240ad2ccf370730d51a3))
18
+ * **android:** set default targetSDK to 31 ([#5442](https://github.com/ionic-team/capacitor/issues/5442)) ([4442459](https://github.com/ionic-team/capacitor/commit/4442459b24cdbac25cb1e4de11583d22c21452b3))
19
+ * **android:** Upgrade gradle to 7.4 ([#5445](https://github.com/ionic-team/capacitor/issues/5445)) ([28eaf18](https://github.com/ionic-team/capacitor/commit/28eaf1851fa7a912917dbb40c68fb4dd583d08ad))
20
+ * **android:** Use java 11 ([#5552](https://github.com/ionic-team/capacitor/issues/5552)) ([e47959f](https://github.com/ionic-team/capacitor/commit/e47959fcbd6a89b97b1275a5814fdb4e7ce30672))
15
21
 
16
22
 
17
- ## [3.4.3](https://github.com/ionic-team/capacitor/compare/3.4.2...3.4.3) (2022-03-04)
18
23
 
19
- **Note:** Version bump only for package @capacitor/android
20
24
 
21
25
 
26
+ # [4.0.0-alpha.1](https://github.com/ionic-team/capacitor/compare/3.4.1...4.0.0-alpha.1) (2022-03-25)
22
27
 
23
28
 
29
+ ### Features
24
30
 
25
- ## [3.4.2](https://github.com/ionic-team/capacitor/compare/3.4.1...3.4.2) (2022-03-03)
26
-
27
- **Note:** Version bump only for package @capacitor/android
31
+ * **android:** set default targetSDK to 31 ([#5442](https://github.com/ionic-team/capacitor/issues/5442)) ([4442459](https://github.com/ionic-team/capacitor/commit/4442459b24cdbac25cb1e4de11583d22c21452b3))
32
+ * **android:** Upgrade gradle to 7.4 ([#5445](https://github.com/ionic-team/capacitor/issues/5445)) ([28eaf18](https://github.com/ionic-team/capacitor/commit/28eaf1851fa7a912917dbb40c68fb4dd583d08ad))
28
33
 
29
34
 
30
35
 
@@ -1,13 +1,13 @@
1
1
  ext {
2
- androidxActivityVersion = project.hasProperty('androidxActivityVersion') ? rootProject.ext.androidxActivityVersion : '1.2.0'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
4
- androidxCoordinatorLayoutVersion = project.hasProperty('androidxCoordinatorLayoutVersion') ? rootProject.ext.androidxCoordinatorLayoutVersion : '1.1.0'
5
- androidxCoreVersion = project.hasProperty('androidxCoreVersion') ? rootProject.ext.androidxCoreVersion : '1.3.2'
6
- androidxFragmentVersion = project.hasProperty('androidxFragmentVersion') ? rootProject.ext.androidxFragmentVersion : '1.3.0'
7
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
8
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
9
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
10
- cordovaAndroidVersion = project.hasProperty('cordovaAndroidVersion') ? rootProject.ext.cordovaAndroidVersion : '7.0.0'
2
+ androidxActivityVersion = project.hasProperty('androidxActivityVersion') ? rootProject.ext.androidxActivityVersion : '1.4.0'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.1'
4
+ androidxCoordinatorLayoutVersion = project.hasProperty('androidxCoordinatorLayoutVersion') ? rootProject.ext.androidxCoordinatorLayoutVersion : '1.2.0'
5
+ androidxCoreVersion = project.hasProperty('androidxCoreVersion') ? rootProject.ext.androidxCoreVersion : '1.7.0'
6
+ androidxFragmentVersion = project.hasProperty('androidxFragmentVersion') ? rootProject.ext.androidxFragmentVersion : '1.4.1'
7
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
8
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
9
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
10
+ cordovaAndroidVersion = project.hasProperty('cordovaAndroidVersion') ? rootProject.ext.cordovaAndroidVersion : '10.1.1'
11
11
  }
12
12
 
13
13
 
@@ -17,7 +17,7 @@ buildscript {
17
17
  mavenCentral()
18
18
  }
19
19
  dependencies {
20
- classpath 'com.android.tools.build:gradle:4.2.1'
20
+ classpath 'com.android.tools.build:gradle:7.1.1'
21
21
  }
22
22
  }
23
23
 
@@ -26,10 +26,10 @@ tasks.withType(Javadoc).all { enabled = false }
26
26
  apply plugin: 'com.android.library'
27
27
 
28
28
  android {
29
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
29
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 31
30
30
  defaultConfig {
31
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
32
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
31
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
32
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 31
33
33
  versionCode 1
34
34
  versionName "1.0"
35
35
  consumerProguardFiles 'proguard-rules.pro'
@@ -47,15 +47,14 @@ android {
47
47
  warningsAsErrors true
48
48
  }
49
49
  compileOptions {
50
- sourceCompatibility JavaVersion.VERSION_1_8
51
- targetCompatibility JavaVersion.VERSION_1_8
50
+ sourceCompatibility JavaVersion.VERSION_11
51
+ targetCompatibility JavaVersion.VERSION_11
52
52
  }
53
53
  }
54
54
 
55
55
  repositories {
56
56
  google()
57
57
  mavenCentral()
58
- jcenter()
59
58
  }
60
59
 
61
60
  dependencies {
@@ -130,9 +130,6 @@ public class Bridge {
130
130
  // A list of listeners that trigger when webView events occur
131
131
  private List<WebViewListener> webViewListeners = new ArrayList<>();
132
132
 
133
- // An interface to manipulate route resolving
134
- private RouteProcessor routeProcessor;
135
-
136
133
  /**
137
134
  * Create the Bridge with a reference to the main {@link Activity} for the
138
135
  * app, and a reference to the {@link WebView} our app will use.
@@ -218,7 +215,10 @@ public class Bridge {
218
215
  try {
219
216
  URL appUrlObject = new URL(appUrlConfig);
220
217
  authorities.add(appUrlObject.getAuthority());
221
- } catch (Exception ex) {}
218
+ } catch (Exception ex) {
219
+ Logger.error("Provided server url is invalid: " + ex.getMessage());
220
+ return;
221
+ }
222
222
  localUrl = appUrlConfig;
223
223
  appUrl = appUrlConfig;
224
224
  } else {
@@ -1193,14 +1193,6 @@ public class Bridge {
1193
1193
  this.webViewListeners = webViewListeners;
1194
1194
  }
1195
1195
 
1196
- RouteProcessor getRouteProcessor() {
1197
- return routeProcessor;
1198
- }
1199
-
1200
- void setRouteProcessor(RouteProcessor routeProcessor) {
1201
- this.routeProcessor = routeProcessor;
1202
- }
1203
-
1204
1196
  /**
1205
1197
  * Add a listener that the WebViewClient can trigger on certain events.
1206
1198
  * @param webViewListener A {@link WebViewListener} to add.
@@ -1224,7 +1216,6 @@ public class Bridge {
1224
1216
  private List<Class<? extends Plugin>> plugins = new ArrayList<>();
1225
1217
  private AppCompatActivity activity;
1226
1218
  private Fragment fragment;
1227
- private RouteProcessor routeProcessor;
1228
1219
  private final List<WebViewListener> webViewListeners = new ArrayList<>();
1229
1220
 
1230
1221
  public Builder(AppCompatActivity activity) {
@@ -1277,11 +1268,6 @@ public class Bridge {
1277
1268
  return this;
1278
1269
  }
1279
1270
 
1280
- public Builder setRouteProcessor(RouteProcessor routeProcessor) {
1281
- this.routeProcessor = routeProcessor;
1282
- return this;
1283
- }
1284
-
1285
1271
  public Bridge create() {
1286
1272
  // Cordova initialization
1287
1273
  ConfigXmlParser parser = new ConfigXmlParser();
@@ -1305,7 +1291,6 @@ public class Bridge {
1305
1291
  Bridge bridge = new Bridge(activity, fragment, webView, plugins, cordovaInterface, pluginManager, preferences, config);
1306
1292
  bridge.setCordovaWebView(mockWebView);
1307
1293
  bridge.setWebViewListeners(webViewListeners);
1308
- bridge.setRouteProcessor(routeProcessor);
1309
1294
 
1310
1295
  if (instanceState != null) {
1311
1296
  bridge.restoreInstanceState(instanceState);
@@ -12,11 +12,11 @@ public class BridgeActivity extends AppCompatActivity {
12
12
 
13
13
  protected Bridge bridge;
14
14
  protected boolean keepRunning = true;
15
- protected CapConfig config;
15
+ private CapConfig config;
16
16
 
17
- protected int activityDepth = 0;
18
- protected List<Class<? extends Plugin>> initialPlugins = new ArrayList<>();
19
- protected final Bridge.Builder bridgeBuilder = new Bridge.Builder(this);
17
+ private int activityDepth = 0;
18
+ private List<Class<? extends Plugin>> initialPlugins = new ArrayList<>();
19
+ private final Bridge.Builder bridgeBuilder = new Bridge.Builder(this);
20
20
 
21
21
  @Override
22
22
  protected void onCreate(Bundle savedInstanceState) {
@@ -66,7 +66,7 @@ public class BridgeActivity extends AppCompatActivity {
66
66
  this.load();
67
67
  }
68
68
 
69
- protected void load() {
69
+ private void load() {
70
70
  Logger.debug("Starting BridgeActivity");
71
71
 
72
72
  bridge = bridgeBuilder.addPlugins(initialPlugins).setConfig(config).create();
@@ -286,8 +286,10 @@ public class BridgeWebChromeClient extends WebChromeClient {
286
286
  callback.invoke(origin, true, false);
287
287
  } else {
288
288
  final String[] coarsePermission = { Manifest.permission.ACCESS_COARSE_LOCATION };
289
- // TODO replace with Build.VERSION_CODES.S once we target SDK 31
290
- if (Build.VERSION.SDK_INT >= 31 && PermissionHelper.hasPermissions(bridge.getContext(), coarsePermission)) {
289
+ if (
290
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
291
+ PermissionHelper.hasPermissions(bridge.getContext(), coarsePermission)
292
+ ) {
291
293
  callback.invoke(origin, true, false);
292
294
  } else {
293
295
  callback.invoke(origin, false, false);
@@ -9,8 +9,10 @@ import android.content.res.AssetManager;
9
9
  import androidx.annotation.Nullable;
10
10
  import com.getcapacitor.util.JSONUtils;
11
11
  import java.io.IOException;
12
+ import java.util.Arrays;
12
13
  import java.util.HashMap;
13
14
  import java.util.Iterator;
15
+ import java.util.List;
14
16
  import java.util.Locale;
15
17
  import java.util.Map;
16
18
  import org.json.JSONException;
@@ -105,7 +107,11 @@ public class CapConfig {
105
107
  this.html5mode = builder.html5mode;
106
108
  this.serverUrl = builder.serverUrl;
107
109
  this.hostname = builder.hostname;
108
- this.androidScheme = builder.androidScheme;
110
+
111
+ if (this.validateScheme(builder.androidScheme)) {
112
+ this.androidScheme = builder.androidScheme;
113
+ }
114
+
109
115
  this.allowNavigation = builder.allowNavigation;
110
116
 
111
117
  // Android Config
@@ -148,7 +154,12 @@ public class CapConfig {
148
154
  html5mode = JSONUtils.getBoolean(configJSON, "server.html5mode", html5mode);
149
155
  serverUrl = JSONUtils.getString(configJSON, "server.url", null);
150
156
  hostname = JSONUtils.getString(configJSON, "server.hostname", hostname);
151
- androidScheme = JSONUtils.getString(configJSON, "server.androidScheme", androidScheme);
157
+
158
+ String configSchema = JSONUtils.getString(configJSON, "server.androidScheme", androidScheme);
159
+ if (this.validateScheme(configSchema)) {
160
+ androidScheme = configSchema;
161
+ }
162
+
152
163
  allowNavigation = JSONUtils.getArray(configJSON, "server.allowNavigation", null);
153
164
 
154
165
  // Android
@@ -191,6 +202,16 @@ public class CapConfig {
191
202
  pluginsConfiguration = deserializePluginsConfig(JSONUtils.getObject(configJSON, "plugins"));
192
203
  }
193
204
 
205
+ private boolean validateScheme(String scheme) {
206
+ List<String> invalidSchemes = Arrays.asList("file", "ftp", "ftps", "ws", "wss", "about", "blob", "data");
207
+ if (invalidSchemes.contains(scheme)) {
208
+ Logger.warn(scheme + " is not an allowed scheme. Defaulting to http.");
209
+ return false;
210
+ }
211
+
212
+ return true;
213
+ }
214
+
194
215
  public boolean isHTML5Mode() {
195
216
  return html5mode;
196
217
  }
@@ -94,7 +94,7 @@ public class JSExport {
94
94
  return readFile(context.getAssets(), path);
95
95
  }
96
96
  } catch (IOException ex) {
97
- Logger.error("Unable to read file at path " + path);
97
+ Logger.warn("Unable to read file at path " + path);
98
98
  }
99
99
  return builder.toString();
100
100
  }
@@ -745,9 +745,10 @@ public class Plugin {
745
745
  * @param call
746
746
  */
747
747
  @SuppressWarnings("unused")
748
- @PluginMethod(returnType = PluginMethod.RETURN_NONE)
748
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
749
749
  public void removeAllListeners(PluginCall call) {
750
750
  eventListeners.clear();
751
+ call.resolve();
751
752
  }
752
753
 
753
754
  /**
@@ -24,6 +24,7 @@ import android.webkit.WebResourceResponse;
24
24
  import java.io.IOException;
25
25
  import java.io.InputStream;
26
26
  import java.net.HttpURLConnection;
27
+ import java.net.SocketTimeoutException;
27
28
  import java.net.URL;
28
29
  import java.net.URLConnection;
29
30
  import java.nio.charset.StandardCharsets;
@@ -255,10 +256,6 @@ public class WebViewLocalServer {
255
256
  InputStream responseStream;
256
257
  try {
257
258
  String startPath = this.basePath + "/index.html";
258
- if (bridge.getRouteProcessor() != null) {
259
- startPath = this.basePath + bridge.getRouteProcessor().process("/index.html");
260
- }
261
-
262
259
  if (isAsset) {
263
260
  responseStream = protocolHandler.openAsset(startPath);
264
261
  } else {
@@ -470,13 +467,6 @@ public class WebViewLocalServer {
470
467
  public InputStream handle(Uri url) {
471
468
  InputStream stream = null;
472
469
  String path = url.getPath();
473
-
474
- // Pass path to routeProcessor if present
475
- RouteProcessor routeProcessor = bridge.getRouteProcessor();
476
- if (routeProcessor != null) {
477
- path = bridge.getRouteProcessor().process(path);
478
- }
479
-
480
470
  try {
481
471
  if (path.startsWith(capacitorContentStart)) {
482
472
  stream = protocolHandler.openContentUrl(url);
@@ -12,7 +12,6 @@ class CapacitorCordovaCookieManager implements ICordovaCookieManager {
12
12
  public CapacitorCordovaCookieManager(WebView webview) {
13
13
  webView = webview;
14
14
  cookieManager = CookieManager.getInstance();
15
- CookieManager.setAcceptFileSchemeCookies(true);
16
15
  cookieManager.setAcceptThirdPartyCookies(webView, true);
17
16
  }
18
17
 
@@ -33,7 +32,7 @@ class CapacitorCordovaCookieManager implements ICordovaCookieManager {
33
32
 
34
33
  @Override
35
34
  public void clearCookies() {
36
- cookieManager.removeAllCookie();
35
+ cookieManager.removeAllCookies(null);
37
36
  }
38
37
 
39
38
  @Override
@@ -112,6 +112,7 @@ public class MockCordovaWebViewImpl implements CordovaWebView {
112
112
  @Override
113
113
  public void clearCache() {}
114
114
 
115
+ @Deprecated
115
116
  @Override
116
117
  public void clearCache(boolean b) {}
117
118
 
@@ -181,6 +182,7 @@ public class MockCordovaWebViewImpl implements CordovaWebView {
181
182
  this.pluginManager.onDestroy();
182
183
  }
183
184
 
185
+ @Deprecated
184
186
  @Override
185
187
  public void sendJavascript(String statememt) {
186
188
  nativeToJsMessageQueue.addJavaScript(statememt);
@@ -198,14 +200,17 @@ public class MockCordovaWebViewImpl implements CordovaWebView {
198
200
  @Override
199
201
  public void showWebPage(String url, boolean openExternal, boolean clearHistory, Map<String, Object> params) {}
200
202
 
203
+ @Deprecated
201
204
  @Override
202
205
  public boolean isCustomViewShowing() {
203
206
  return false;
204
207
  }
205
208
 
209
+ @Deprecated
206
210
  @Override
207
211
  public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {}
208
212
 
213
+ @Deprecated
209
214
  @Override
210
215
  public void hideCustomView() {}
211
216
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
3
- "version": "3.5.0",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
@@ -22,10 +22,10 @@
22
22
  "verify": "./gradlew clean lint build test -b capacitor/build.gradle"
23
23
  },
24
24
  "peerDependencies": {
25
- "@capacitor/core": "^3.5.0"
25
+ "@capacitor/core": "^3.4.0"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "f03e1a67140c8af25288456f9e99dd6234b50f25"
30
+ "gitHead": "5c588d5bd15b2b939c6efc25b7db9d6af29afae0"
31
31
  }
@@ -1,8 +0,0 @@
1
- package com.getcapacitor;
2
-
3
- /**
4
- * An interface used in the processing of routes
5
- */
6
- public interface RouteProcessor {
7
- String process(String path);
8
- }