@capacitor/android 8.3.5-nightly-20260601T165419.0 → 8.3.6

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.
@@ -7,16 +7,20 @@ package com.getcapacitor;
7
7
  import android.content.Context;
8
8
  import android.content.res.AssetManager;
9
9
  import android.net.Uri;
10
+ import android.os.Environment;
10
11
  import android.util.TypedValue;
11
12
  import java.io.File;
12
13
  import java.io.FileInputStream;
14
+ import java.io.FileNotFoundException;
13
15
  import java.io.IOException;
14
16
  import java.io.InputStream;
17
+ import java.util.ArrayList;
15
18
  import java.util.List;
16
19
 
17
20
  public class AndroidProtocolHandler {
18
21
 
19
22
  private Context context;
23
+ private List<File> appStorageRoots;
20
24
 
21
25
  public AndroidProtocolHandler(Context context) {
22
26
  this.context = context;
@@ -69,6 +73,125 @@ public class AndroidProtocolHandler {
69
73
  return new FileInputStream(localFile);
70
74
  }
71
75
 
76
+ /**
77
+ * Opens a file served from the base path the app is hosted from (see {@code setServerBasePath}).
78
+ * The request path is decoded by {@link Uri#getPath()}, so an encoded slash ({@code %2F}) can carry
79
+ * {@code ..} segments that the browser did not resolve. The resolved file must therefore sit inside
80
+ * the base path, or the request would read any file the app can read.
81
+ *
82
+ * @param basePath the directory the app is hosted from
83
+ * @param filePath the base path followed by the request path
84
+ * @throws FileNotFoundException if the resolved file is outside of the base path
85
+ */
86
+ public InputStream openBasePathFile(String basePath, String filePath) throws IOException {
87
+ String base = new File(basePath).getCanonicalPath();
88
+ File file = new File(filePath).getCanonicalFile();
89
+ String resolved = file.getPath();
90
+ if (!resolved.equals(base) && !resolved.startsWith(base.endsWith(File.separator) ? base : base + File.separator)) {
91
+ throw new FileNotFoundException("File is outside of the base path: " + filePath);
92
+ }
93
+ return new FileInputStream(file);
94
+ }
95
+
96
+ /**
97
+ * Opens a file whose location was chosen by a {@link RouteProcessor}. The processor may map requests
98
+ * outside the base path on purpose, so containment is not checked here. The request path is decoded
99
+ * by {@link Uri#getPath()}, so an encoded slash ({@code %2F}) can still carry {@code ..} segments that
100
+ * the browser did not resolve and that a processor would pass on; such requests are refused.
101
+ *
102
+ * @param requestPath the decoded request path
103
+ * @param processedPath the file path returned by the route processor
104
+ * @throws FileNotFoundException if the request path contains a parent-directory segment
105
+ */
106
+ public InputStream openRoutedFile(String requestPath, String processedPath) throws IOException {
107
+ for (String segment : requestPath.split("/")) {
108
+ if (segment.equals("..")) {
109
+ throw new FileNotFoundException("Parent-directory segment in request path: " + requestPath);
110
+ }
111
+ }
112
+ return openFile(processedPath);
113
+ }
114
+
115
+ /**
116
+ * Opens a file requested through the {@link Bridge#CAPACITOR_FILE_START} proxy route.
117
+ * Unlike {@link #openFile(String)}, the resolved path must sit inside the app's own storage or
118
+ * shared/external storage, so the route cannot expose app-private data (shared_prefs, databases)
119
+ * or system files such as /proc or /etc.
120
+ *
121
+ * @param filePath the request path, starting with {@link Bridge#CAPACITOR_FILE_START}
122
+ * @throws IOException if the file cannot be opened or its location is not allowed
123
+ */
124
+ public InputStream openProxiedFile(String filePath) throws IOException {
125
+ String realPath = filePath.startsWith(Bridge.CAPACITOR_FILE_START)
126
+ ? filePath.substring(Bridge.CAPACITOR_FILE_START.length())
127
+ : filePath;
128
+ // Canonicalizing resolves ".." segments and symlinks; open the resolved file so the checked path is the read one.
129
+ File canonicalFile = new File(realPath).getCanonicalFile();
130
+ if (!isInAllowedLocation(canonicalFile)) {
131
+ throw new IOException("Path is outside the locations served by the file proxy: " + realPath);
132
+ }
133
+ return new FileInputStream(canonicalFile);
134
+ }
135
+
136
+ private boolean isInAllowedLocation(File canonicalFile) throws IOException {
137
+ String path = canonicalFile.getPath();
138
+ for (File root : getAllowedRoots()) {
139
+ String rootPath = root.getCanonicalPath();
140
+ if (path.equals(rootPath) || path.startsWith(rootPath + File.separator)) {
141
+ return true;
142
+ }
143
+ }
144
+ return false;
145
+ }
146
+
147
+ @SuppressWarnings("deprecation")
148
+ /**
149
+ * The app's files and cache directories (Filesystem Data/Library/Cache, Camera temporary images). They do not
150
+ * change while the app runs, unlike the external storage roots, so they are looked up once.
151
+ */
152
+ private List<File> getAppStorageRoots() {
153
+ List<File> roots = appStorageRoots;
154
+ if (roots == null) {
155
+ roots = new ArrayList<>();
156
+ addIfNotNull(roots, context.getFilesDir());
157
+ addIfNotNull(roots, context.getCacheDir());
158
+ appStorageRoots = roots;
159
+ }
160
+ return roots;
161
+ }
162
+
163
+ private List<File> getAllowedRoots() {
164
+ List<File> roots = new ArrayList<>(getAppStorageRoots());
165
+ // Primary shared storage (Filesystem Documents/ExternalStorage, gallery and media picks)
166
+ addIfNotNull(roots, Environment.getExternalStorageDirectory());
167
+ // App-specific external dirs, and the root of every other volume (e.g. SD cards) they live on
168
+ List<File> externalDirs = new ArrayList<>();
169
+ for (File dir : context.getExternalFilesDirs(null)) {
170
+ externalDirs.add(dir);
171
+ }
172
+ for (File dir : context.getExternalCacheDirs()) {
173
+ externalDirs.add(dir);
174
+ }
175
+ for (File dir : externalDirs) {
176
+ if (dir == null) {
177
+ continue;
178
+ }
179
+ roots.add(dir);
180
+ String dirPath = dir.getPath();
181
+ int androidDirIndex = dirPath.indexOf("/Android/");
182
+ if (androidDirIndex > 0) {
183
+ roots.add(new File(dirPath.substring(0, androidDirIndex)));
184
+ }
185
+ }
186
+ return roots;
187
+ }
188
+
189
+ private static void addIfNotNull(List<File> roots, File dir) {
190
+ if (dir != null) {
191
+ roots.add(dir);
192
+ }
193
+ }
194
+
72
195
  public InputStream openContentUrl(Uri uri) throws IOException {
73
196
  Integer port = uri.getPort();
74
197
  String baseUrl = uri.getScheme() + "://" + uri.getHost();
@@ -80,7 +203,10 @@ public class AndroidProtocolHandler {
80
203
  InputStream stream = null;
81
204
  try {
82
205
  stream = context.getContentResolver().openInputStream(Uri.parse(realPath));
83
- } catch (SecurityException e) {
206
+ } catch (RuntimeException e) {
207
+ // The target provider runs in this process and may throw unchecked exceptions for a malformed or
208
+ // unknown path (e.g. FileProvider throws IllegalArgumentException, older versions
209
+ // StringIndexOutOfBoundsException). Left uncaught they crash the app, so report "not found" instead.
84
210
  Logger.error("Unable to open content URL: " + uri, e);
85
211
  }
86
212
  return stream;
@@ -386,7 +386,26 @@ public class Bridge {
386
386
  return 0;
387
387
  }
388
388
 
389
+ /**
390
+ * Whether the path targets the local file or content proxy routes.
391
+ */
392
+ static boolean isLocalFilePath(String path) {
393
+ return path != null && (path.startsWith(CAPACITOR_FILE_START) || path.startsWith(CAPACITOR_CONTENT_START));
394
+ }
395
+
396
+ /**
397
+ * Whether the path targets one of the internal proxy routes (file, content, http interceptor).
398
+ */
399
+ static boolean isInternalProxyPath(String path) {
400
+ return isLocalFilePath(path) || (path != null && path.startsWith(CAPACITOR_HTTP_INTERCEPTOR_START));
401
+ }
402
+
389
403
  public boolean launchIntent(Uri url) {
404
+ // The proxy routes return data at the app origin, so block navigating to them before plugins can allow it.
405
+ if (isInternalProxyPath(url.getPath())) {
406
+ return true;
407
+ }
408
+
390
409
  /*
391
410
  * Give plugins the chance to handle the url
392
411
  */
@@ -1003,7 +1003,8 @@ public class Plugin {
1003
1003
  * Give the plugins a chance to take control when a URL is about to be loaded in the WebView.
1004
1004
  * Returning true causes the WebView to abort loading the URL.
1005
1005
  * Returning false causes the WebView to continue loading the URL.
1006
- * Returning null will defer to the default Capacitor policy
1006
+ * Returning null will defer to the default Capacitor policy.
1007
+ * Not called for Capacitor's internal HTTP proxy path, which is always blocked.
1007
1008
  */
1008
1009
  @SuppressWarnings("unused")
1009
1010
  public Boolean shouldOverrideLoad(Uri url) {
@@ -65,17 +65,6 @@ public class PluginConfig {
65
65
  return JSONUtils.getInt(config, configKey, defaultValue);
66
66
  }
67
67
 
68
- /**
69
- * Get a double value for a plugin in the Capacitor config.
70
- *
71
- * @param configKey The key of the value to retrieve
72
- * @param defaultValue A default value to return if the key does not exist in the config
73
- * @return The value from the config, if key exists. Default value returned if not
74
- */
75
- public double getDouble(String configKey, double defaultValue) {
76
- return JSONUtils.getDouble(config, configKey, defaultValue);
77
- }
78
-
79
68
  /**
80
69
  * Get a string array value for a plugin in the Capacitor config.
81
70
  *
@@ -25,6 +25,7 @@ import android.webkit.WebResourceRequest;
25
25
  import android.webkit.WebResourceResponse;
26
26
  import com.getcapacitor.plugin.util.CapacitorHttpUrlConnection;
27
27
  import com.getcapacitor.plugin.util.HttpRequestHandler;
28
+ import java.io.ByteArrayInputStream;
28
29
  import java.io.IOException;
29
30
  import java.io.InputStream;
30
31
  import java.net.HttpURLConnection;
@@ -184,7 +185,17 @@ public class WebViewLocalServer {
184
185
  public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
185
186
  Uri loadingUrl = request.getUrl();
186
187
 
188
+ if (Bridge.isInternalProxyPath(loadingUrl.getPath()) && !isProxyRequestAllowed(request)) {
189
+ // Internal proxy routes are only for sub-resources requested at the app's own origin.
190
+ Logger.warn("Blocked request to internal proxy route: " + loadingUrl);
191
+ return buildBlockedResponse();
192
+ }
193
+
187
194
  if (null != loadingUrl.getPath() && loadingUrl.getPath().startsWith(Bridge.CAPACITOR_HTTP_INTERCEPTOR_START)) {
195
+ boolean httpEnabled = bridge.getConfig().getPluginConfiguration("CapacitorHttp").getBoolean("enabled", false);
196
+ if (!httpEnabled) {
197
+ return null;
198
+ }
188
199
  Logger.debug("Handling CapacitorHttp request: " + loadingUrl);
189
200
  try {
190
201
  return handleCapacitorHttpRequest(request);
@@ -210,9 +221,67 @@ public class WebViewLocalServer {
210
221
  }
211
222
  }
212
223
 
224
+ /**
225
+ * Internal proxy routes (file, content, http interceptor) return data at the app origin, so they must only
226
+ * serve sub-resource requests (img, media, fetch/XHR) made to the app's own origin. A document would run
227
+ * the returned content with the app's privileges, and a request to any other origin has no business here.
228
+ */
229
+ private boolean isProxyRequestAllowed(WebResourceRequest request) {
230
+ return isAppOrigin(request.getUrl()) && !isDocumentRequest(request);
231
+ }
232
+
233
+ private boolean isAppOrigin(Uri uri) {
234
+ String localUrl = bridge.getLocalUrl();
235
+ if (localUrl == null || uri.getScheme() == null || uri.getHost() == null) {
236
+ return false;
237
+ }
238
+ Uri appOrigin = Uri.parse(localUrl);
239
+ return (
240
+ uri.getScheme().equalsIgnoreCase(appOrigin.getScheme()) &&
241
+ uri.getHost().equalsIgnoreCase(appOrigin.getHost()) &&
242
+ getEffectivePort(uri) == getEffectivePort(appOrigin)
243
+ );
244
+ }
245
+
246
+ /**
247
+ * The WebView hands over request URLs without a default port, while the configured app URL may spell it out
248
+ * (e.g. server.url "http://host:80"), so a missing port is treated as the scheme's default.
249
+ */
250
+ private static int getEffectivePort(Uri uri) {
251
+ int port = uri.getPort();
252
+ if (port != -1) {
253
+ return port;
254
+ }
255
+ String scheme = uri.getScheme();
256
+ if ("https".equalsIgnoreCase(scheme)) {
257
+ return 443;
258
+ }
259
+ if ("http".equalsIgnoreCase(scheme)) {
260
+ return 80;
261
+ }
262
+ return -1;
263
+ }
264
+
265
+ /** isForMainFrame() is false for an iframe and a fetch alike; only navigations send this header. */
266
+ private boolean isDocumentRequest(WebResourceRequest request) {
267
+ if (request.isForMainFrame()) {
268
+ return true;
269
+ }
270
+ Map<String, String> headers = request.getRequestHeaders();
271
+ if (headers == null) {
272
+ // The proxy needs the headers too, so the request fails there anyway.
273
+ return false;
274
+ }
275
+ for (String header : headers.keySet()) {
276
+ if ("Upgrade-Insecure-Requests".equalsIgnoreCase(header)) {
277
+ return true;
278
+ }
279
+ }
280
+ return false;
281
+ }
282
+
213
283
  private boolean isLocalFile(Uri uri) {
214
- String path = uri.getPath();
215
- return path.startsWith(capacitorContentStart) || path.startsWith(capacitorFileStart);
284
+ return Bridge.isLocalFilePath(uri.getPath());
216
285
  }
217
286
 
218
287
  private boolean isErrorUrl(Uri uri) {
@@ -316,7 +385,9 @@ public class WebViewLocalServer {
316
385
  encoding = encodingParts[1].trim();
317
386
  }
318
387
  }
319
- } else {
388
+ } else if (!"Access-Control-Allow-Origin".equalsIgnoreCase(entry.getKey())) {
389
+ // The target's CORS grant is not forwarded: the request is made natively (with the app's cookies), so a
390
+ // grant meant for the target's own callers would let another origin read the response.
320
391
  responseHeaders.put(entry.getKey(), builder.toString());
321
392
  }
322
393
  }
@@ -333,9 +404,33 @@ public class WebViewLocalServer {
333
404
  int responseCode = connection.getResponseCode();
334
405
  String reasonPhrase = getReasonPhraseFromResponseCode(responseCode);
335
406
 
407
+ // Nothing should render this. If anything does, sandbox keeps it inert and off the app origin.
408
+ responseHeaders.put("Content-Security-Policy", "sandbox; frame-ancestors 'none'");
409
+
336
410
  return new WebResourceResponse(mimeType, encoding, responseCode, reasonPhrase, responseHeaders, inputStream);
337
411
  }
338
412
 
413
+ /**
414
+ * A fixed rejection for a blocked proxy route request. Returning null would let the WebView send the request
415
+ * to the network itself, which for a remote server.url puts the local path in a request to that server.
416
+ */
417
+ private WebResourceResponse buildBlockedResponse() {
418
+ Map<String, String> headers = new HashMap<>();
419
+ headers.put("Content-Security-Policy", "sandbox; frame-ancestors 'none'");
420
+ headers.put("Cache-Control", "no-store");
421
+ return new WebResourceResponse("text/plain", "UTF-8", 403, "Forbidden", headers, new ByteArrayInputStream(new byte[0]));
422
+ }
423
+
424
+ /**
425
+ * Files served through the file/content proxy routes are data, not pages. If anything ends up rendering one,
426
+ * the sandbox keeps it inert and off the app origin, and it cannot be framed.
427
+ */
428
+ void addProxyRouteSecurityHeaders(Uri uri, Map<String, String> responseHeaders) {
429
+ if (isLocalFile(uri)) {
430
+ responseHeaders.put("Content-Security-Policy", "sandbox; frame-ancestors 'none'");
431
+ }
432
+ }
433
+
339
434
  private WebResourceResponse handleLocalRequest(WebResourceRequest request, PathHandler handler) {
340
435
  String path = request.getUrl().getPath();
341
436
 
@@ -349,15 +444,22 @@ public class WebViewLocalServer {
349
444
  int statusCode = 206;
350
445
  try {
351
446
  int totalRange = responseStream.available();
352
- String[] parts = rangeString.split("=");
353
- String[] streamParts = parts[1].split("-");
354
- String fromRange = streamParts[0];
355
- int range = totalRange - 1;
356
- if (streamParts.length > 1) {
357
- range = Integer.parseInt(streamParts[1]);
447
+ if (totalRange == -1) {
448
+ // No stream (missing or refused file): not a partial response.
449
+ statusCode = 404;
450
+ addProxyRouteSecurityHeaders(request.getUrl(), tempResponseHeaders);
451
+ } else {
452
+ String[] parts = rangeString.split("=");
453
+ String[] streamParts = parts[1].split("-");
454
+ String fromRange = streamParts[0];
455
+ int range = totalRange - 1;
456
+ if (streamParts.length > 1) {
457
+ range = Integer.parseInt(streamParts[1]);
458
+ }
459
+ tempResponseHeaders.put("Accept-Ranges", "bytes");
460
+ tempResponseHeaders.put("Content-Range", "bytes " + fromRange + "-" + range + "/" + totalRange);
461
+ addProxyRouteSecurityHeaders(request.getUrl(), tempResponseHeaders);
358
462
  }
359
- tempResponseHeaders.put("Accept-Ranges", "bytes");
360
- tempResponseHeaders.put("Content-Range", "bytes " + fromRange + "-" + range + "/" + totalRange);
361
463
  } catch (IOException e) {
362
464
  statusCode = 404;
363
465
  }
@@ -375,12 +477,14 @@ public class WebViewLocalServer {
375
477
  InputStream responseStream = new LollipopLazyInputStream(handler, request);
376
478
  String mimeType = getMimeType(request.getUrl().getPath(), responseStream);
377
479
  int statusCode = getStatusCode(responseStream, handler.getStatusCode());
480
+ Map<String, String> localResponseHeaders = handler.buildDefaultResponseHeaders();
481
+ addProxyRouteSecurityHeaders(request.getUrl(), localResponseHeaders);
378
482
  return new WebResourceResponse(
379
483
  mimeType,
380
484
  handler.getEncoding(),
381
485
  statusCode,
382
486
  handler.getReasonPhrase(),
383
- handler.buildDefaultResponseHeaders(),
487
+ localResponseHeaders,
384
488
  responseStream
385
489
  );
386
490
  }
@@ -654,13 +758,14 @@ public class WebViewLocalServer {
654
758
  if (path.startsWith(capacitorContentStart)) {
655
759
  stream = protocolHandler.openContentUrl(url);
656
760
  } else if (path.startsWith(capacitorFileStart)) {
657
- stream = protocolHandler.openFile(path);
761
+ stream = protocolHandler.openProxiedFile(path);
658
762
  } else if (!isAsset) {
659
763
  if (routeProcessor == null) {
660
- path = basePath + url.getPath();
764
+ // The decoded path can contain ".." that must not leave the base path.
765
+ stream = protocolHandler.openBasePathFile(basePath, basePath + url.getPath());
766
+ } else {
767
+ stream = protocolHandler.openRoutedFile(url.getPath(), path);
661
768
  }
662
-
663
- stream = protocolHandler.openFile(path);
664
769
  } else if (ignoreAssetPath) {
665
770
  stream = protocolHandler.openAsset(path);
666
771
  } else {
@@ -70,12 +70,14 @@ public class MockCordovaWebViewImpl implements CordovaWebView {
70
70
 
71
71
  @Override
72
72
  public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) {
73
- cordova.getActivity().runOnUiThread(() -> {
74
- String js = queue.popAndEncodeAsJs();
75
- if (js != null) {
76
- webView.evaluateJavascript(js, null);
77
- }
78
- });
73
+ cordova
74
+ .getActivity()
75
+ .runOnUiThread(() -> {
76
+ String js = queue.popAndEncodeAsJs();
77
+ if (js != null) {
78
+ webView.evaluateJavascript(js, null);
79
+ }
80
+ });
79
81
  }
80
82
  }
81
83
 
@@ -16,7 +16,6 @@ import androidx.core.view.WindowCompat;
16
16
  import androidx.core.view.WindowInsetsCompat;
17
17
  import androidx.core.view.WindowInsetsControllerCompat;
18
18
  import androidx.webkit.WebViewCompat;
19
- import com.getcapacitor.Logger;
20
19
  import com.getcapacitor.Plugin;
21
20
  import com.getcapacitor.PluginCall;
22
21
  import com.getcapacitor.PluginMethod;
@@ -33,7 +32,6 @@ public class SystemBars extends Plugin {
33
32
  static final String BAR_STATUS_BAR = "StatusBar";
34
33
  static final String BAR_GESTURE_BAR = "NavigationBar";
35
34
 
36
- // TODO: In Cap 9, add an additional option "full"
37
35
  static final String INSETS_HANDLING_CSS = "css";
38
36
  static final String INSETS_HANDLING_DISABLE = "disable";
39
37
 
@@ -55,7 +53,7 @@ public class SystemBars extends Plugin {
55
53
  capacitorSystemBarsCheckMetaViewport();
56
54
  """;
57
55
 
58
- private String insetsHandling = INSETS_HANDLING_CSS;
56
+ private boolean insetHandlingEnabled = true;
59
57
  private boolean hasViewportCover = false;
60
58
 
61
59
  private String currentStatusBarStyle = STYLE_DEFAULT;
@@ -96,15 +94,9 @@ public class SystemBars extends Plugin {
96
94
  String style = getConfig().getString("style", STYLE_DEFAULT).toUpperCase(Locale.US);
97
95
  boolean hidden = getConfig().getBoolean("hidden", false);
98
96
 
99
- String configuredInsetsHandling = getConfig().getString("insetsHandling", INSETS_HANDLING_CSS);
100
- if (INSETS_HANDLING_CSS.equals(configuredInsetsHandling) || INSETS_HANDLING_DISABLE.equals(configuredInsetsHandling)) {
101
- insetsHandling = configuredInsetsHandling;
102
- } else {
103
- Logger.warn(
104
- "SystemBars",
105
- "Unknown insetsHandling value '" + configuredInsetsHandling + "'. Falling back to '" + INSETS_HANDLING_CSS + "'."
106
- );
107
- insetsHandling = INSETS_HANDLING_CSS;
97
+ String insetsHandling = getConfig().getString("insetsHandling", "css");
98
+ if (insetsHandling.equals(INSETS_HANDLING_DISABLE)) {
99
+ insetHandlingEnabled = false;
108
100
  }
109
101
 
110
102
  initWindowInsetsListener();
@@ -154,15 +146,13 @@ public class SystemBars extends Plugin {
154
146
 
155
147
  @JavascriptInterface
156
148
  public void onDOMReady() {
157
- if (INSETS_HANDLING_CSS.equals(insetsHandling)) {
158
- getActivity().runOnUiThread(() -> {
159
- this.bridge.getWebView().evaluateJavascript(viewportMetaJSFunction, (res) -> {
160
- hasViewportCover = res.equals("true");
149
+ getActivity().runOnUiThread(() -> {
150
+ this.bridge.getWebView().evaluateJavascript(viewportMetaJSFunction, (res) -> {
151
+ hasViewportCover = res.equals("true");
161
152
 
162
- getBridge().getWebView().requestApplyInsets();
163
- });
153
+ getBridge().getWebView().requestApplyInsets();
164
154
  });
165
- }
155
+ });
166
156
  }
167
157
 
168
158
  private Insets calcSafeAreaInsets(WindowInsetsCompat insets) {
@@ -174,16 +164,9 @@ public class SystemBars extends Plugin {
174
164
  }
175
165
 
176
166
  private void initSafeAreaCSSVariables() {
177
- if (INSETS_HANDLING_CSS.equals(insetsHandling)) {
178
- WindowInsetsCompat insets;
179
-
180
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
181
- View v = (View) this.getBridge().getWebView().getParent();
182
- insets = ViewCompat.getRootWindowInsets(v);
183
- } else {
184
- insets = WindowInsetsCompat.CONSUMED;
185
- }
186
-
167
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && insetHandlingEnabled) {
168
+ View v = (View) this.getBridge().getWebView().getParent();
169
+ WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(v);
187
170
  if (insets != null) {
188
171
  Insets safeAreaInsets = calcSafeAreaInsets(insets);
189
172
  injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
@@ -192,10 +175,6 @@ public class SystemBars extends Plugin {
192
175
  }
193
176
 
194
177
  private void initWindowInsetsListener() {
195
- if (INSETS_HANDLING_DISABLE.equals(insetsHandling)) {
196
- return;
197
- }
198
-
199
178
  ViewCompat.setOnApplyWindowInsetsListener((View) getBridge().getWebView().getParent(), (v, insets) -> {
200
179
  boolean shouldPassthroughInsets = getWebViewMajorVersion() >= WEBVIEW_VERSION_WITH_SAFE_AREA_FIX && hasViewportCover;
201
180
 
@@ -207,8 +186,10 @@ public class SystemBars extends Plugin {
207
186
  // We need to correct for a possible shown IME
208
187
  v.setPadding(0, 0, 0, keyboardVisible ? imeInsets.bottom : 0);
209
188
 
210
- Insets safeAreaInsets = calcSafeAreaInsets(insets);
211
- injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
189
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && hasViewportCover && insetHandlingEnabled) {
190
+ Insets safeAreaInsets = calcSafeAreaInsets(insets);
191
+ injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
192
+ }
212
193
 
213
194
  return new WindowInsetsCompat.Builder(insets)
214
195
  .setInsets(
@@ -240,8 +221,10 @@ public class SystemBars extends Plugin {
240
221
  .setInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(), Insets.of(0, 0, 0, 0))
241
222
  .build();
242
223
 
243
- Insets safeAreaInsets = calcSafeAreaInsets(newInsets);
244
- injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
224
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && hasViewportCover && insetHandlingEnabled) {
225
+ Insets safeAreaInsets = calcSafeAreaInsets(newInsets);
226
+ injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
227
+ }
245
228
 
246
229
  return newInsets;
247
230
  });
@@ -75,26 +75,6 @@ public class JSONUtils {
75
75
  return defaultValue;
76
76
  }
77
77
 
78
- /**
79
- * Get a double value from the given JSON object.
80
- *
81
- * @param jsonObject A JSON object to search
82
- * @param key A key to fetch from the JSON object
83
- * @param defaultValue A default value to return if the key cannot be found
84
- * @return The value at the given key in the JSON object, or the default value
85
- */
86
- public static double getDouble(JSONObject jsonObject, String key, double defaultValue) {
87
- String k = getDeepestKey(key);
88
- try {
89
- JSONObject o = getDeepestObject(jsonObject, key);
90
- return o.getDouble(k);
91
- } catch (JSONException ignore) {
92
- // value was not found
93
- }
94
-
95
- return defaultValue;
96
- }
97
-
98
78
  /**
99
79
  * Get a JSON object value from the given JSON object.
100
80
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
3
- "version": "8.3.5-nightly-20260601T165419.0",
3
+ "version": "8.3.6",
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)",
@@ -23,7 +23,7 @@
23
23
  "verify": "./gradlew clean lint build test -b capacitor/build.gradle"
24
24
  },
25
25
  "peerDependencies": {
26
- "@capacitor/core": "^8.3.0-nightly-20260601T165419.0"
26
+ "@capacitor/core": "^8.3.0"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"