@capacitor/android 9.0.0-alpha.6 → 9.0.0-alpha.7

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.
@@ -1,10 +1,10 @@
1
1
  ext {
2
- androidxActivityVersion = project.hasProperty('androidxActivityVersion') ? rootProject.ext.androidxActivityVersion : '1.11.0'
2
+ androidxActivityVersion = project.hasProperty('androidxActivityVersion') ? rootProject.ext.androidxActivityVersion : '1.13.0'
3
3
  androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
4
  androidxCoordinatorLayoutVersion = project.hasProperty('androidxCoordinatorLayoutVersion') ? rootProject.ext.androidxCoordinatorLayoutVersion : '1.3.0'
5
- androidxCoreVersion = project.hasProperty('androidxCoreVersion') ? rootProject.ext.androidxCoreVersion : '1.17.0'
5
+ androidxCoreVersion = project.hasProperty('androidxCoreVersion') ? rootProject.ext.androidxCoreVersion : '1.19.0'
6
6
  androidxFragmentVersion = project.hasProperty('androidxFragmentVersion') ? rootProject.ext.androidxFragmentVersion : '1.8.9'
7
- androidxWebkitVersion = project.hasProperty('androidxWebkitVersion') ? rootProject.ext.androidxWebkitVersion : '1.14.0'
7
+ androidxWebkitVersion = project.hasProperty('androidxWebkitVersion') ? rootProject.ext.androidxWebkitVersion : '1.16.0'
8
8
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
9
9
  androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
10
10
  androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
@@ -14,9 +14,3 @@
14
14
  }
15
15
 
16
16
  -keep public class * extends com.getcapacitor.Plugin { *; }
17
-
18
- # Rules for Capacitor v2 plugins and annotations
19
- # These are deprecated but can still be used with Capacitor for now
20
- -keep @com.getcapacitor.NativePlugin public class * {
21
- @com.getcapacitor.PluginMethod public <methods>;
22
- }
@@ -367,12 +367,6 @@ var nativeBridge = (function (exports) {
367
367
  }
368
368
  };
369
369
  const platform = getPlatformId(win);
370
- if (platform == 'android' && typeof win.CapacitorSystemBarsAndroidInterface !== 'undefined') {
371
- // add DOM ready listener for System Bars
372
- document.addEventListener('DOMContentLoaded', function () {
373
- win.CapacitorSystemBarsAndroidInterface.onDOMReady();
374
- });
375
- }
376
370
  if (platform == 'android' || platform == 'ios') {
377
371
  // patch document.cookie on Android/iOS
378
372
  win.CapacitorCookiesDescriptor =
@@ -87,11 +87,6 @@ public class Bridge {
87
87
  public static final String CAPACITOR_FILE_START = "/_capacitor_file_";
88
88
  public static final String CAPACITOR_CONTENT_START = "/_capacitor_content_";
89
89
  public static final String CAPACITOR_HTTP_INTERCEPTOR_START = "/_capacitor_http_interceptor_";
90
-
91
- /** @deprecated CAPACITOR_HTTPS_INTERCEPTOR_START is no longer required. All proxied requests are handled via CAPACITOR_HTTP_INTERCEPTOR_START instead */
92
- @Deprecated
93
- public static final String CAPACITOR_HTTPS_INTERCEPTOR_START = "/_capacitor_https_interceptor_";
94
-
95
90
  public static final String CAPACITOR_HTTP_INTERCEPTOR_URL_PARAM = "u";
96
91
 
97
92
  public static final int DEFAULT_ANDROID_WEBVIEW_VERSION = 60;
@@ -308,6 +303,12 @@ public class Bridge {
308
303
  }
309
304
 
310
305
  public boolean launchIntent(Uri url) {
306
+ // The proxy returns a remote body at the app origin, so block it before plugins can allow it.
307
+ String path = url.getPath();
308
+ if (path != null && path.startsWith(CAPACITOR_HTTP_INTERCEPTOR_START)) {
309
+ return true;
310
+ }
311
+
311
312
  /*
312
313
  * Give plugins the chance to handle the url
313
314
  */
@@ -379,22 +380,20 @@ public class Bridge {
379
380
  return null;
380
381
  }
381
382
 
382
- public boolean isDeployDisabled() {
383
+ public boolean shouldKeepRunning() {
383
384
  Plugin cordova = this.cordova();
384
- if (cordova != null) {
385
- return cordova.hasPermission("DisableDeploy");
386
- } else {
387
- return false;
385
+ if (cordova instanceof CordovaBridgeConfig) {
386
+ return ((CordovaBridgeConfig) cordova).shouldKeepRunning();
388
387
  }
388
+ return false;
389
389
  }
390
390
 
391
- public boolean shouldKeepRunning() {
391
+ public boolean isDeployDisabled() {
392
392
  Plugin cordova = this.cordova();
393
- if (cordova != null) {
394
- return cordova.hasPermission("KeepRunning");
395
- } else {
396
- return false;
393
+ if (cordova instanceof CordovaBridgeConfig) {
394
+ return ((CordovaBridgeConfig) cordova).isDeployDisabled();
397
395
  }
396
+ return false;
398
397
  }
399
398
 
400
399
  public void handleAppUrlLoadError(Exception ex) {
@@ -625,17 +624,6 @@ public class Bridge {
625
624
  }
626
625
  }
627
626
 
628
- @SuppressWarnings("deprecation")
629
- private String getLegacyPluginName(Class<? extends Plugin> pluginClass) {
630
- NativePlugin legacyPluginAnnotation = pluginClass.getAnnotation(NativePlugin.class);
631
- if (legacyPluginAnnotation == null) {
632
- Logger.error("Plugin doesn't have the @CapacitorPlugin annotation. Please add it");
633
- return null;
634
- }
635
-
636
- return legacyPluginAnnotation.name();
637
- }
638
-
639
627
  /**
640
628
  * Register a plugin class
641
629
  * @param pluginClass a class inheriting from Plugin
@@ -678,20 +666,17 @@ public class Bridge {
678
666
  }
679
667
 
680
668
  private String pluginName(Class<? extends Plugin> clazz) {
681
- String pluginName;
682
669
  CapacitorPlugin pluginAnnotation = clazz.getAnnotation(CapacitorPlugin.class);
683
670
  if (pluginAnnotation == null) {
684
- pluginName = this.getLegacyPluginName(clazz);
685
- } else {
686
- pluginName = pluginAnnotation.name();
671
+ Logger.error("Plugin doesn't have the @CapacitorPlugin annotation. Please add it");
672
+ return null;
687
673
  }
688
-
689
- return pluginName;
674
+ return pluginAnnotation.name();
690
675
  }
691
676
 
692
677
  private void logInvalidPluginException(Class<? extends Plugin> clazz) {
693
678
  Logger.error(
694
- "NativePlugin " +
679
+ "Plugin " +
695
680
  clazz.getName() +
696
681
  " is invalid. Ensure the @CapacitorPlugin annotation exists on the plugin class and" +
697
682
  " the class extends Plugin"
@@ -699,7 +684,7 @@ public class Bridge {
699
684
  }
700
685
 
701
686
  private void logPluginLoadException(Class<? extends Plugin> clazz, Exception ex) {
702
- Logger.error("NativePlugin " + clazz.getName() + " failed to load", ex);
687
+ Logger.error("Plugin " + clazz.getName() + " failed to load", ex);
703
688
  }
704
689
 
705
690
  public PluginHandle getPlugin(String pluginId) {
@@ -713,38 +698,16 @@ public class Bridge {
713
698
  * @return
714
699
  */
715
700
  @Deprecated
716
- @SuppressWarnings("deprecation")
717
701
  public PluginHandle getPluginWithRequestCode(int requestCode) {
718
702
  for (PluginHandle handle : this.plugins.values()) {
719
- int[] requestCodes;
720
-
721
703
  CapacitorPlugin pluginAnnotation = handle.getPluginAnnotation();
722
704
  if (pluginAnnotation == null) {
723
- // Check for legacy plugin annotation, @NativePlugin
724
- NativePlugin legacyPluginAnnotation = handle.getLegacyPluginAnnotation();
725
- if (legacyPluginAnnotation == null) {
726
- continue;
727
- }
728
-
729
- if (legacyPluginAnnotation.permissionRequestCode() == requestCode) {
705
+ continue;
706
+ }
707
+ for (int rc : pluginAnnotation.requestCodes()) {
708
+ if (rc == requestCode) {
730
709
  return handle;
731
710
  }
732
-
733
- requestCodes = legacyPluginAnnotation.requestCodes();
734
-
735
- for (int rc : requestCodes) {
736
- if (rc == requestCode) {
737
- return handle;
738
- }
739
- }
740
- } else {
741
- requestCodes = pluginAnnotation.requestCodes();
742
-
743
- for (int rc : requestCodes) {
744
- if (rc == requestCode) {
745
- return handle;
746
- }
747
- }
748
711
  }
749
712
  }
750
713
  return null;
@@ -1049,18 +1012,8 @@ public class Bridge {
1049
1012
  }
1050
1013
  }
1051
1014
 
1052
- @Deprecated
1053
- @SuppressWarnings("deprecation")
1054
- public void startActivityForPluginWithResult(PluginCall call, Intent intent, int requestCode) {
1055
- Logger.debug("Starting activity for result");
1056
-
1057
- pluginCallForLastActivity = call;
1058
-
1059
- getActivity().startActivityForResult(intent, requestCode);
1060
- }
1061
-
1062
1015
  /**
1063
- * Check for legacy Capacitor or Cordova plugins that may have registered to handle a permission
1016
+ * Check for Cordova plugins that may have registered to handle a permission
1064
1017
  * request, and handle them if so. If not handled, false is returned.
1065
1018
  *
1066
1019
  * @param requestCode the code that was requested
@@ -1086,12 +1039,6 @@ public class Bridge {
1086
1039
  return permissionHandled;
1087
1040
  }
1088
1041
 
1089
- // Call deprecated method if using deprecated NativePlugin annotation
1090
- if (plugin.getPluginAnnotation() == null) {
1091
- plugin.getInstance().handleRequestPermissionsResult(requestCode, permissions, grantResults);
1092
- return true;
1093
- }
1094
-
1095
1042
  return false;
1096
1043
  }
1097
1044
 
@@ -1160,45 +1107,51 @@ public class Bridge {
1160
1107
  protected Map<String, PermissionState> getPermissionStates(Plugin plugin) {
1161
1108
  Map<String, PermissionState> permissionsResults = new HashMap<>();
1162
1109
  CapacitorPlugin annotation = plugin.getPluginHandle().getPluginAnnotation();
1163
- for (Permission perm : annotation.permissions()) {
1164
- // If a permission is defined with no permission constants, return GRANTED for it.
1165
- // Otherwise, get its true state.
1166
- if (perm.strings().length == 0 || (perm.strings().length == 1 && perm.strings()[0].isEmpty())) {
1167
- String key = perm.alias();
1168
- if (!key.isEmpty()) {
1169
- PermissionState existingResult = permissionsResults.get(key);
1170
-
1171
- // auto set permission state to GRANTED if the alias is empty.
1172
- if (existingResult == null) {
1173
- permissionsResults.put(key, PermissionState.GRANTED);
1174
- }
1175
- }
1176
- } else {
1177
- for (String permString : perm.strings()) {
1178
- String key = perm.alias().isEmpty() ? permString : perm.alias();
1179
- PermissionState permissionStatus;
1180
- if (ActivityCompat.checkSelfPermission(this.getContext(), permString) == PackageManager.PERMISSION_GRANTED) {
1181
- permissionStatus = PermissionState.GRANTED;
1182
- } else {
1183
- permissionStatus = PermissionState.PROMPT;
1184
-
1185
- // Check if there is a cached permission state for the "Never ask again" state
1186
- SharedPreferences prefs = getContext().getSharedPreferences(PERMISSION_PREFS_NAME, Activity.MODE_PRIVATE);
1187
- String state = prefs.getString(permString, null);
1188
-
1189
- if (state != null) {
1190
- permissionStatus = PermissionState.byState(state);
1110
+ if (annotation != null) {
1111
+ for (Permission perm : annotation.permissions()) {
1112
+ // If a permission is defined with no permission constants, return GRANTED for it.
1113
+ // Otherwise, get its true state.
1114
+ if (perm.strings().length == 0 || (perm.strings().length == 1 && perm.strings()[0].isEmpty())) {
1115
+ String key = perm.alias();
1116
+ if (!key.isEmpty()) {
1117
+ PermissionState existingResult = permissionsResults.get(key);
1118
+
1119
+ // auto set permission state to GRANTED if the alias is empty.
1120
+ if (existingResult == null) {
1121
+ permissionsResults.put(key, PermissionState.GRANTED);
1191
1122
  }
1192
1123
  }
1124
+ } else {
1125
+ for (String permString : perm.strings()) {
1126
+ String key = perm.alias().isEmpty() ? permString : perm.alias();
1127
+ PermissionState permissionStatus;
1128
+ if (ActivityCompat.checkSelfPermission(this.getContext(), permString) == PackageManager.PERMISSION_GRANTED) {
1129
+ permissionStatus = PermissionState.GRANTED;
1130
+ } else {
1131
+ permissionStatus = PermissionState.PROMPT;
1132
+
1133
+ // Check if there is a cached permission state for the "Never ask again" state
1134
+ SharedPreferences prefs = getContext().getSharedPreferences(PERMISSION_PREFS_NAME, Activity.MODE_PRIVATE);
1135
+ String state = prefs.getString(permString, null);
1136
+
1137
+ if (state != null) {
1138
+ permissionStatus = PermissionState.byState(state);
1139
+ }
1140
+ }
1193
1141
 
1194
- PermissionState existingResult = permissionsResults.get(key);
1142
+ PermissionState existingResult = permissionsResults.get(key);
1195
1143
 
1196
- // multiple permissions with the same alias must all be true, otherwise all false.
1197
- if (existingResult == null || existingResult == PermissionState.GRANTED) {
1198
- permissionsResults.put(key, permissionStatus);
1144
+ // multiple permissions with the same alias must all be true, otherwise all false.
1145
+ if (existingResult == null || existingResult == PermissionState.GRANTED) {
1146
+ permissionsResults.put(key, permissionStatus);
1147
+ }
1199
1148
  }
1200
1149
  }
1201
1150
  }
1151
+ } else {
1152
+ Logger.warn(
1153
+ String.format("getPermissionStates: missing @CapacitorPlugin annotation for plugin %s", plugin.getPluginHandle().getId())
1154
+ );
1202
1155
  }
1203
1156
 
1204
1157
  return permissionsResults;
@@ -1227,22 +1180,8 @@ public class Bridge {
1227
1180
  return false;
1228
1181
  }
1229
1182
 
1230
- // deprecated, to be removed
1231
- PluginCall lastCall = plugin.getInstance().getSavedCall();
1232
-
1233
- // If we don't have a saved last call (because our app was killed and restarted, for example),
1234
- // Then we should see if we have any saved plugin call information and generate a new,
1235
- // "dangling" plugin call (a plugin call that doesn't have a corresponding web callback)
1236
- // and then send that to the plugin
1237
- if (lastCall == null && pluginCallForLastActivity != null) {
1238
- plugin.getInstance().saveCall(pluginCallForLastActivity);
1239
- }
1240
-
1241
1183
  plugin.getInstance().handleOnActivityResult(requestCode, resultCode, data);
1242
1184
 
1243
- // Clear the plugin call we may have re-hydrated on app launch
1244
- pluginCallForLastActivity = null;
1245
-
1246
1185
  return true;
1247
1186
  }
1248
1187
 
@@ -69,27 +69,6 @@ public class CapConfig {
69
69
  */
70
70
  private CapConfig() {}
71
71
 
72
- /**
73
- * Get an instance of the Config file object.
74
- * @deprecated use {@link #loadDefault(Context)} to load an instance of the Config object
75
- * from the capacitor.config.json file, or use the {@link CapConfig.Builder} to construct
76
- * a CapConfig for embedded use.
77
- *
78
- * @param assetManager The AssetManager used to load the config file
79
- * @param config JSON describing a configuration to use
80
- */
81
- @Deprecated
82
- public CapConfig(AssetManager assetManager, JSONObject config) {
83
- if (config != null) {
84
- this.configJSON = config;
85
- } else {
86
- // Load the capacitor.config.json
87
- loadConfigFromAssets(assetManager, null);
88
- }
89
-
90
- deserializeConfig(null);
91
- }
92
-
93
72
  /**
94
73
  * Constructs a Capacitor Configuration from config.json file.
95
74
  *
@@ -429,104 +408,6 @@ public class CapConfig {
429
408
  return pluginConfig;
430
409
  }
431
410
 
432
- /**
433
- * Get a JSON object value from the Capacitor config.
434
- * @deprecated use {@link PluginConfig#getObject(String)} to access plugin config values.
435
- * For main Capacitor config values, use the appropriate getter.
436
- *
437
- * @param key A key to fetch from the config
438
- * @return The value from the config, if exists. Null if not
439
- */
440
- @Deprecated
441
- public JSONObject getObject(String key) {
442
- try {
443
- return configJSON.getJSONObject(key);
444
- } catch (Exception ex) {}
445
- return null;
446
- }
447
-
448
- /**
449
- * Get a string value from the Capacitor config.
450
- * @deprecated use {@link PluginConfig#getString(String, String)} to access plugin config
451
- * values. For main Capacitor config values, use the appropriate getter.
452
- *
453
- * @param key A key to fetch from the config
454
- * @return The value from the config, if exists. Null if not
455
- */
456
- @Deprecated
457
- public String getString(String key) {
458
- return JSONUtils.getString(configJSON, key, null);
459
- }
460
-
461
- /**
462
- * Get a string value from the Capacitor config.
463
- * @deprecated use {@link PluginConfig#getString(String, String)} to access plugin config
464
- * values. For main Capacitor config values, use the appropriate getter.
465
- *
466
- * @param key A key to fetch from the config
467
- * @param defaultValue A default value to return if the key does not exist in the config
468
- * @return The value from the config, if key exists. Default value returned if not
469
- */
470
- @Deprecated
471
- public String getString(String key, String defaultValue) {
472
- return JSONUtils.getString(configJSON, key, defaultValue);
473
- }
474
-
475
- /**
476
- * Get a boolean value from the Capacitor config.
477
- * @deprecated use {@link PluginConfig#getBoolean(String, boolean)} to access plugin config
478
- * values. For main Capacitor config values, use the appropriate getter.
479
- *
480
- * @param key A key to fetch from the config
481
- * @param defaultValue A default value to return if the key does not exist in the config
482
- * @return The value from the config, if key exists. Default value returned if not
483
- */
484
- @Deprecated
485
- public boolean getBoolean(String key, boolean defaultValue) {
486
- return JSONUtils.getBoolean(configJSON, key, defaultValue);
487
- }
488
-
489
- /**
490
- * Get an integer value from the Capacitor config.
491
- * @deprecated use {@link PluginConfig#getInt(String, int)} to access the plugin config
492
- * values. For main Capacitor config values, use the appropriate getter.
493
- *
494
- * @param key A key to fetch from the config
495
- * @param defaultValue A default value to return if the key does not exist in the config
496
- * @return The value from the config, if key exists. Default value returned if not
497
- */
498
- @Deprecated
499
- public int getInt(String key, int defaultValue) {
500
- return JSONUtils.getInt(configJSON, key, defaultValue);
501
- }
502
-
503
- /**
504
- * Get a string array value from the Capacitor config.
505
- * @deprecated use {@link PluginConfig#getArray(String)} to access the plugin config
506
- * values. For main Capacitor config values, use the appropriate getter.
507
- *
508
- * @param key A key to fetch from the config
509
- * @return The value from the config, if exists. Null if not
510
- */
511
- @Deprecated
512
- public String[] getArray(String key) {
513
- return JSONUtils.getArray(configJSON, key, null);
514
- }
515
-
516
- /**
517
- * Get a string array value from the Capacitor config.
518
- * @deprecated use {@link PluginConfig#getArray(String, String[])} to access the plugin
519
- * config values. For main Capacitor config values, use the appropriate getter.
520
- *
521
- * @param key A key to fetch from the config
522
- * @param defaultValue A default value to return if the key does not exist in the config
523
- * @return The value from the config, if key exists. Default value returned if not
524
- */
525
- @Deprecated
526
- public String[] getArray(String key, String[] defaultValue) {
527
- return JSONUtils.getArray(configJSON, key, defaultValue);
528
- }
529
-
530
411
  private static Map<String, PluginConfig> deserializePluginsConfig(JSONObject pluginsConfig) {
531
412
  Map<String, PluginConfig> pluginsMap = new HashMap<>();
532
413
 
@@ -0,0 +1,6 @@
1
+ package com.getcapacitor;
2
+
3
+ public interface CordovaBridgeConfig {
4
+ boolean isDeployDisabled();
5
+ boolean shouldKeepRunning();
6
+ }
@@ -45,11 +45,6 @@ public class MessageHandler {
45
45
  }
46
46
  }
47
47
 
48
- @Deprecated
49
- public MessageHandler(Bridge bridge, WebView webView, Object cordovaPluginManager) {
50
- this(bridge, webView);
51
- }
52
-
53
48
  /**
54
49
  * The main message handler that will be called from JavaScript
55
50
  * to send a message to the native bridge.