@capacitor/android 8.3.6 → 8.3.8

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.
@@ -15,11 +15,24 @@
15
15
 
16
16
  -keep public class * extends com.getcapacitor.Plugin { *; }
17
17
 
18
+ # The annotation types are read at runtime via reflection. If they are not kept, R8 full mode
19
+ # treats them as never instantiated and optimizes the annotation cached in PluginHandle to null,
20
+ # even with -keepattributes *Annotation*.
21
+ -keep @interface com.getcapacitor.annotation.** { *; }
22
+ -keep @interface com.getcapacitor.PluginMethod { *; }
23
+
24
+ # Callback methods are found by reflection, including on non-public base classes.
25
+ -keepclassmembers class * extends com.getcapacitor.Plugin {
26
+ @com.getcapacitor.annotation.ActivityCallback <methods>;
27
+ @com.getcapacitor.annotation.PermissionCallback <methods>;
28
+ }
29
+
18
30
  # Rules for Capacitor v2 plugins and annotations
19
31
  # These are deprecated but can still be used with Capacitor for now
20
32
  -keep @com.getcapacitor.NativePlugin public class * {
21
33
  @com.getcapacitor.PluginMethod public <methods>;
22
34
  }
35
+ -keep @interface com.getcapacitor.NativePlugin { *; }
23
36
 
24
37
  # Rules for Cordova plugins
25
38
  -keep public class * extends org.apache.cordova.* {
@@ -61,7 +61,8 @@ public class AndroidProtocolHandler {
61
61
  }
62
62
 
63
63
  private static int getFieldId(Context context, String assetType, String assetName)
64
- throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
64
+ throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
65
+ {
65
66
  Class<?> d = context.getClassLoader().loadClass(context.getPackageName() + ".R$" + assetType);
66
67
  java.lang.reflect.Field field = d.getField(assetName);
67
68
  return field.getInt(null);
@@ -87,6 +87,7 @@ public class Bridge {
87
87
  private static final String LAST_BINARY_VERSION_CODE = "lastBinaryVersionCode";
88
88
  private static final String LAST_BINARY_VERSION_NAME = "lastBinaryVersionName";
89
89
  private static final String MINIMUM_ANDROID_WEBVIEW_ERROR = "System WebView is not supported";
90
+ private static final List<String> DISABLEABLE_PLUGINS = Arrays.asList("CapacitorCookies", "CapacitorHttp", "SystemBars");
90
91
 
91
92
  // The name of the directory we use to look for index.html and the rest of our web assets
92
93
  public static final String DEFAULT_WEB_ASSET_DIR = "public";
@@ -719,7 +720,10 @@ public class Bridge {
719
720
  public void registerPlugin(Class<? extends Plugin> pluginClass) {
720
721
  String pluginId = pluginId(pluginClass);
721
722
  if (pluginId == null) return;
722
-
723
+ if (isDisabled(pluginId)) {
724
+ Logger.debug("Not registering disabled plugin: " + pluginId);
725
+ return;
726
+ }
723
727
  try {
724
728
  this.plugins.put(pluginId, new PluginHandle(this, pluginClass));
725
729
  } catch (InvalidPluginException ex) {
@@ -733,7 +737,10 @@ public class Bridge {
733
737
  Class<? extends Plugin> clazz = plugin.getClass();
734
738
  String pluginId = pluginId(clazz);
735
739
  if (pluginId == null) return;
736
-
740
+ if (isDisabled(pluginId)) {
741
+ Logger.debug("Not registering disabled plugin: " + pluginId);
742
+ return;
743
+ }
737
744
  try {
738
745
  this.plugins.put(pluginId, new PluginHandle(this, plugin));
739
746
  } catch (InvalidPluginException ex) {
@@ -741,6 +748,11 @@ public class Bridge {
741
748
  }
742
749
  }
743
750
 
751
+ // Only built-in plugins with their own config section can be disabled; leave npm plugins out with includePlugins.
752
+ private boolean isDisabled(String pluginId) {
753
+ return DISABLEABLE_PLUGINS.contains(pluginId) && config.getPluginConfiguration(pluginId).getBoolean("disabled", false);
754
+ }
755
+
744
756
  private String pluginId(Class<? extends Plugin> clazz) {
745
757
  String pluginName = pluginName(clazz);
746
758
  String pluginId = clazz.getSimpleName();
@@ -282,7 +282,7 @@ public class BridgeWebChromeClient extends WebChromeClient {
282
282
  boolean captureEnabled = fileChooserParams.isCaptureEnabled();
283
283
  boolean capturePhoto = captureEnabled && acceptTypes.contains("image/*");
284
284
  final boolean captureVideo = captureEnabled && acceptTypes.contains("video/*");
285
- if ((capturePhoto || captureVideo)) {
285
+ if (capturePhoto || captureVideo) {
286
286
  if (isMediaCaptureSupported()) {
287
287
  showMediaCaptureOrFilePicker(filePathCallback, fileChooserParams, captureVideo);
288
288
  } else {
@@ -447,7 +447,7 @@ public class BridgeWebChromeClient extends WebChromeClient {
447
447
  }
448
448
 
449
449
  public boolean isValidMsg(String msg) {
450
- return !(msg.contains("%cresult %c") || (msg.contains("%cnative %c")) || msg.equalsIgnoreCase("console.groupEnd"));
450
+ return !(msg.contains("%cresult %c") || msg.contains("%cnative %c") || msg.equalsIgnoreCase("console.groupEnd"));
451
451
  }
452
452
 
453
453
  private Uri createImageFileUri() throws IOException {
@@ -218,7 +218,7 @@ public class FileUtils {
218
218
  Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
219
219
  int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
220
220
  cursor.moveToFirst();
221
- String name = (cursor.getString(nameIndex));
221
+ String name = cursor.getString(nameIndex);
222
222
  String fileName = sanitizeFilename(name);
223
223
  File file = new File(context.getFilesDir(), fileName);
224
224
  try {
@@ -124,7 +124,8 @@ public class PluginHandle {
124
124
  * @throws InvalidPluginMethodException if no method was found on that plugin
125
125
  */
126
126
  public void invoke(String methodName, PluginCall call)
127
- throws PluginLoadException, InvalidPluginMethodException, InvocationTargetException, IllegalAccessException {
127
+ throws PluginLoadException, InvalidPluginMethodException, InvocationTargetException, IllegalAccessException
128
+ {
128
129
  if (this.instance == null) {
129
130
  // Can throw PluginLoadException
130
131
  this.load();
@@ -192,7 +192,8 @@ public class WebViewLocalServer {
192
192
  }
193
193
 
194
194
  if (null != loadingUrl.getPath() && loadingUrl.getPath().startsWith(Bridge.CAPACITOR_HTTP_INTERCEPTOR_START)) {
195
- boolean httpEnabled = bridge.getConfig().getPluginConfiguration("CapacitorHttp").getBoolean("enabled", false);
195
+ PluginConfig httpConfig = bridge.getConfig().getPluginConfiguration("CapacitorHttp");
196
+ boolean httpEnabled = httpConfig.getBoolean("enabled", false) && !httpConfig.getBoolean("disabled", false);
196
197
  if (!httpEnabled) {
197
198
  return null;
198
199
  }
@@ -290,7 +291,7 @@ public class WebViewLocalServer {
290
291
  }
291
292
 
292
293
  private boolean isMainUrl(Uri loadingUrl) {
293
- return (bridge.getServerUrl() == null && loadingUrl.getHost().equalsIgnoreCase(bridge.getHost()));
294
+ return bridge.getServerUrl() == null && loadingUrl.getHost().equalsIgnoreCase(bridge.getHost());
294
295
  }
295
296
 
296
297
  private boolean isAllowedUrl(Uri loadingUrl) {
@@ -827,31 +828,31 @@ public class WebViewLocalServer {
827
828
  @Override
828
829
  public int available() throws IOException {
829
830
  InputStream is = getInputStream();
830
- return (is != null) ? is.available() : -1;
831
+ return is != null ? is.available() : -1;
831
832
  }
832
833
 
833
834
  @Override
834
835
  public int read() throws IOException {
835
836
  InputStream is = getInputStream();
836
- return (is != null) ? is.read() : -1;
837
+ return is != null ? is.read() : -1;
837
838
  }
838
839
 
839
840
  @Override
840
841
  public int read(byte[] b) throws IOException {
841
842
  InputStream is = getInputStream();
842
- return (is != null) ? is.read(b) : -1;
843
+ return is != null ? is.read(b) : -1;
843
844
  }
844
845
 
845
846
  @Override
846
847
  public int read(byte[] b, int off, int len) throws IOException {
847
848
  InputStream is = getInputStream();
848
- return (is != null) ? is.read(b, off, len) : -1;
849
+ return is != null ? is.read(b, off, len) : -1;
849
850
  }
850
851
 
851
852
  @Override
852
853
  public long skip(long n) throws IOException {
853
854
  InputStream is = getInputStream();
854
- return (is != null) ? is.skip(n) : 0;
855
+ return is != null ? is.skip(n) : 0;
855
856
  }
856
857
  }
857
858
 
@@ -70,14 +70,12 @@ public class MockCordovaWebViewImpl implements CordovaWebView {
70
70
 
71
71
  @Override
72
72
  public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) {
73
- cordova
74
- .getActivity()
75
- .runOnUiThread(() -> {
76
- String js = queue.popAndEncodeAsJs();
77
- if (js != null) {
78
- webView.evaluateJavascript(js, null);
79
- }
80
- });
73
+ cordova.getActivity().runOnUiThread(() -> {
74
+ String js = queue.popAndEncodeAsJs();
75
+ if (js != null) {
76
+ webView.evaluateJavascript(js, null);
77
+ }
78
+ });
81
79
  }
82
80
  }
83
81
 
@@ -192,12 +192,12 @@ public class CapacitorCookieManager extends CookieManager {
192
192
  @Override
193
193
  public void put(URI uri, Map<String, List<String>> responseHeaders) {
194
194
  // make sure our args are valid
195
- if ((uri == null) || (responseHeaders == null)) return;
195
+ if (uri == null || responseHeaders == null) return;
196
196
 
197
197
  // go over the headers
198
198
  for (String headerKey : responseHeaders.keySet()) {
199
199
  // ignore headers which aren't cookie related
200
- if ((headerKey == null) || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;
200
+ if (headerKey == null || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;
201
201
 
202
202
  // process each of the headers
203
203
  for (String headerValue : Objects.requireNonNull(responseHeaders.get(headerKey))) {
@@ -215,7 +215,7 @@ public class CapacitorCookieManager extends CookieManager {
215
215
  @Override
216
216
  public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
217
217
  // make sure our args are valid
218
- if ((uri == null) || (requestHeaders == null)) throw new IllegalArgumentException("Argument is null");
218
+ if (uri == null || requestHeaders == null) throw new IllegalArgumentException("Argument is null");
219
219
 
220
220
  // save our url once
221
221
  String url = uri.toString();
@@ -41,17 +41,17 @@ public class SystemBars extends Plugin {
41
41
  private static final int WEBVIEW_VERSION_WITH_SAFE_AREA_KEYBOARD_FIX = 144;
42
42
 
43
43
  static final String viewportMetaJSFunction = """
44
- function capacitorSystemBarsCheckMetaViewport() {
45
- const meta = document.querySelectorAll("meta[name=viewport]");
46
- if (meta.length == 0) {
47
- return false;
48
- }
49
- // get the last found meta viewport tag
50
- const metaContent = meta[meta.length - 1].content;
51
- return metaContent.includes("viewport-fit=cover");
44
+ function capacitorSystemBarsCheckMetaViewport() {
45
+ const meta = document.querySelectorAll("meta[name=viewport]");
46
+ if (meta.length == 0) {
47
+ return false;
52
48
  }
53
- capacitorSystemBarsCheckMetaViewport();
54
- """;
49
+ // get the last found meta viewport tag
50
+ const metaContent = meta[meta.length - 1].content;
51
+ return metaContent.includes("viewport-fit=cover");
52
+ }
53
+ capacitorSystemBarsCheckMetaViewport();
54
+ """;
55
55
 
56
56
  private boolean insetHandlingEnabled = true;
57
57
  private boolean hasViewportCover = false;
@@ -122,7 +122,8 @@ public class HttpRequestHandler {
122
122
  }
123
123
 
124
124
  public HttpURLConnectionBuilder setUrlParams(JSObject params, boolean shouldEncode)
125
- throws URISyntaxException, MalformedURLException {
125
+ throws URISyntaxException, MalformedURLException
126
+ {
126
127
  String initialQuery = url.getQuery();
127
128
  String initialQueryBuilderStr = initialQuery == null ? "" : initialQuery;
128
129
 
@@ -168,8 +169,8 @@ public class HttpRequestHandler {
168
169
  "://" +
169
170
  uri.getAuthority() +
170
171
  uri.getPath() +
171
- ((!urlQuery.equals("")) ? "?" + urlQuery : "") +
172
- ((uri.getFragment() != null) ? uri.getFragment() : "");
172
+ (!urlQuery.equals("") ? "?" + urlQuery : "") +
173
+ (uri.getFragment() != null ? uri.getFragment() : "");
173
174
  this.url = new URL(unEncodedUrlString);
174
175
 
175
176
  return this;
@@ -212,7 +213,8 @@ public class HttpRequestHandler {
212
213
  * @throws JSONException Thrown if the JSON is unable to be parsed
213
214
  */
214
215
  public static JSObject buildResponse(CapacitorHttpUrlConnection connection, ResponseType responseType)
215
- throws IOException, JSONException {
216
+ throws IOException, JSONException
217
+ {
216
218
  int statusCode = connection.getResponseCode();
217
219
 
218
220
  JSObject output = new JSObject();
@@ -383,7 +385,8 @@ public class HttpRequestHandler {
383
385
  * @throws JSONException thrown when the incoming JSON is malformed
384
386
  */
385
387
  public static JSObject request(PluginCall call, String httpMethod, Bridge bridge)
386
- throws IOException, URISyntaxException, JSONException {
388
+ throws IOException, URISyntaxException, JSONException
389
+ {
387
390
  String urlString = call.getString("url", "");
388
391
  JSObject headers = call.getObject("headers", new JSObject());
389
392
  JSObject params = call.getObject("params", new JSObject());
@@ -10,8 +10,11 @@ public class InternalUtils {
10
10
  return InternalUtils.getPackageInfo(pm, packageName, 0);
11
11
  }
12
12
 
13
- public static PackageInfo getPackageInfo(PackageManager pm, String packageName, long flags)
14
- throws PackageManager.NameNotFoundException {
13
+ public static PackageInfo getPackageInfo(
14
+ PackageManager pm,
15
+ String packageName,
16
+ long flags
17
+ ) throws PackageManager.NameNotFoundException {
15
18
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
16
19
  return pm.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags));
17
20
  } else {
@@ -20,8 +23,11 @@ public class InternalUtils {
20
23
  }
21
24
 
22
25
  @SuppressWarnings("deprecation")
23
- private static PackageInfo getPackageInfoLegacy(PackageManager pm, String packageName, long flags)
24
- throws PackageManager.NameNotFoundException {
26
+ private static PackageInfo getPackageInfoLegacy(
27
+ PackageManager pm,
28
+ String packageName,
29
+ long flags
30
+ ) throws PackageManager.NameNotFoundException {
25
31
  return pm.getPackageInfo(packageName, (int) flags);
26
32
  }
27
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
3
- "version": "8.3.6",
3
+ "version": "8.3.8",
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)",