@capgo/capacitor-updater 8.53.1 → 8.54.1
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/README.md +55 -15
- package/android/build.gradle +1 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +187 -16
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +278 -25
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +82 -19
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +314 -30
- package/android/src/main/java/ee/forgr/capacitor_updater/StatsBatchFailureDiagnostics.java +40 -0
- package/dist/docs.json +34 -2
- package/dist/esm/definitions.d.ts +46 -2
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +44 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +368 -61
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +59 -33
- package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +0 -19
- package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +20 -0
- package/package.json +8 -4
- package/scripts/builtin-hashes-lib.mjs +148 -0
- package/scripts/capacitor-builtin-hashes-hook.mjs +65 -0
- package/scripts/resolve-real-path.mjs +25 -0
package/README.md
CHANGED
|
@@ -212,6 +212,20 @@ npm install @capgo/capacitor-updater@lts-v5
|
|
|
212
212
|
npm install @capgo/capacitor-updater@lts-v4
|
|
213
213
|
```
|
|
214
214
|
|
|
215
|
+
### Android: keep web assets uncompressed
|
|
216
|
+
|
|
217
|
+
On `npx cap copy`, the plugin writes `ota-builtin-hashes.json` next to your web assets so the native code can reuse builtin files without hashing them. On Android the size check uses `AssetManager.openFd()`, which cannot open compressed assets, so compressed files silently fall back to full hashing. To get the fast path, keep web asset extensions uncompressed in `android/app/build.gradle`:
|
|
218
|
+
|
|
219
|
+
```groovy
|
|
220
|
+
android {
|
|
221
|
+
androidResources {
|
|
222
|
+
noCompress += ['html', 'js', 'css', 'json', 'svg', 'woff', 'woff2', 'ttf', 'eot', 'map', 'png', 'jpg', 'jpeg', 'webp', 'gif', 'ico', 'wasm', 'txt', 'xml']
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
This only affects speed: without it, updates still verify every builtin file by checksum.
|
|
228
|
+
|
|
215
229
|
## Auto-update setup
|
|
216
230
|
|
|
217
231
|
Create your account in [capgo.app](https://capgo.app) and get your [API key](https://console.capgo.app/dashboard/apikeys)
|
|
@@ -230,6 +244,10 @@ npx @capgo/cli@latest bundle upload --delta
|
|
|
230
244
|
|
|
231
245
|
They also require `@capacitor/splash-screen` and `autoSplashscreen: true` with `SplashScreen.launchAutoHide: false`. See [Update Behavior](https://capgo.app/docs/live-updates/update-behavior/).
|
|
232
246
|
|
|
247
|
+
On iOS, use at least `@capgo/capacitor-updater@8.51.22`. The same fix is in the LTS lines from `7.51.21`, `6.51.21`, and `5.51.21`. The Capacitor 4 line (`@lts-v4`) never shipped `autoSplashscreen`, so this rejection does not apply there.
|
|
248
|
+
|
|
249
|
+
Earlier 5, 6, 7, and 8 builds compiled `autoSplashscreen` so it built the splash screen `show` / `hide` selector at runtime with `NSSelectorFromString`, then called it with `responds(to:)` and `perform`. App Review rejected that binary under [Guideline 2.5.2](https://developer.apple.com/app-store/review/guidelines/#software-requirements). The rejection names code that passes arbitrary parameters to dynamic methods such as `respondsToSelector:` and `performSelector:`, next to a plugin that downloads a remote bundle. See [#913](https://github.com/Cap-go/capacitor-updater/issues/913). Those calls stay in the binary when `autoSplashscreen` is off, so turning the option off does not clear the rejection. Upgrade to the latest plugin for your Capacitor major and submit a new native build.
|
|
250
|
+
|
|
233
251
|
## No Cloud setup
|
|
234
252
|
|
|
235
253
|
Download update distribution zipfiles from a custom URL. Manually control the entire update process.
|
|
@@ -297,27 +315,25 @@ TIP: If you prefer a secure and automated way to update your app, you can use [c
|
|
|
297
315
|
|
|
298
316
|
### Store Guideline Compliance
|
|
299
317
|
|
|
300
|
-
|
|
318
|
+
Live updates of JavaScript, HTML, and CSS are allowed on Google Play and the App Store. This plugin replaces the web bundle that already runs in the WebView. It does not download or install native executable code.
|
|
319
|
+
|
|
320
|
+
#### Google Play
|
|
301
321
|
|
|
302
|
-
|
|
322
|
+
[Device and Network Abuse](https://support.google.com/googleplay/android-developer/answer/13315670) forbids an app from updating itself outside Google Play or from downloading executable code (dex, JAR, `.so`). The same policy exempts the web layer:
|
|
303
323
|
|
|
304
|
-
|
|
305
|
-
> This restriction does not apply to code that runs in a virtual machine and has limited access to Android APIs (such as JavaScript in a web view or browser).
|
|
324
|
+
> This restriction does not apply to code that runs in a virtual machine or an interpreter where either provides indirect access to Android APIs (such as JavaScript in a webview or browser).
|
|
306
325
|
|
|
307
|
-
|
|
326
|
+
JavaScript loaded at runtime must still respect the rest of the Play policies. Capacitor-updater only ships that JavaScript bundle. It cannot change native code, permissions, or the store binary.
|
|
308
327
|
|
|
309
328
|
#### App Store
|
|
310
329
|
|
|
311
|
-
|
|
330
|
+
Section **3.3.1(B) Executable Code** of the [Apple Developer Program License Agreement](https://developer.apple.com/support/terms/apple-developer-program-license-agreement/) allows interpreted code:
|
|
312
331
|
|
|
313
|
-
|
|
332
|
+
> Except as set forth in the next paragraph, an Application may not download or install executable code. Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application (b) does not bypass signing, sandbox, or other security features of the OS; and (c) for Applications distributed on the App Store, does not create a store or storefront for other Applications.
|
|
314
333
|
|
|
315
|
-
|
|
316
|
-
- (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store
|
|
317
|
-
- (b) does not create a store or storefront for other code or applications
|
|
318
|
-
- (c) does not bypass signing, sandbox, or other security features of the OS.
|
|
334
|
+
A bundle that keeps the app's reviewed purpose, stays in the sandbox, and does not open a store for other apps is inside that rule.
|
|
319
335
|
|
|
320
|
-
|
|
336
|
+
A reviewer can still misread the binary or the launch UI and reject the build. On iOS that usually arrives as [Guideline 2.5.2](https://developer.apple.com/app-store/review/guidelines/#software-requirements). It is rare. Reply in the store console and explain that the plugin downloads interpreted JavaScript, HTML, and CSS for the existing WebView, which the rules above permit, and that it does not download native executable code. Following the recommendations in this README is what keeps that from happening: ship a plugin build new enough that the old `autoSplashscreen` selector code is gone, and do not mention updates, live updates, or remote updates anywhere in the app.
|
|
321
337
|
|
|
322
338
|
To further remain in compliance with Apple's guidelines, we suggest that App Store-distributed apps don't enable the `Force update` scenario, since in the [App Store Review Guidelines](https://developer.apple.com/app-store/review/guidelines/) it is written that:
|
|
323
339
|
|
|
@@ -325,6 +341,24 @@ To further remain in compliance with Apple's guidelines, we suggest that App Sto
|
|
|
325
341
|
|
|
326
342
|
This is not a problem for the default behavior of background update, since it won't force the user to apply the new version until the next app close, but at least you should be aware of that ruling if you decide to show it.
|
|
327
343
|
|
|
344
|
+
#### Prevent live updates during Apple and Google review
|
|
345
|
+
|
|
346
|
+
Keep the app on the web assets shipped in the submitted native binary throughout Apple App Store and Google Play review. Applying a live update during review can reload the app, interrupt the reviewer's session, or change the behavior they are reviewing.
|
|
347
|
+
|
|
348
|
+
Capgo Cloud blocks update requests from known Apple and Google datacenter networks by default to prevent live updates from reaching review devices on those networks. Keep the app's **Block provider infrastructure requests** setting enabled. This protection runs on Capgo's server and depends on recognizing the request's network; it does not detect every review session or pause updates for all users while a store review is in progress.
|
|
349
|
+
|
|
350
|
+
If you self-host, manage updates manually, or disable this protection, you must provide your own way to prevent live updates from disturbing review. The same applies if review traffic does not use a recognized network. For example, pause update delivery for the submitted native version or use a dedicated channel that serves no live updates until review is complete. In manual flows, guard calls such as `download()`, `next()`, and `set()`, and prevent already downloaded or queued bundles from being applied during review. Hiding an update message does not prevent the update itself.
|
|
351
|
+
|
|
352
|
+
Before submitting, test a fresh install and an upgrade from the previous store version. Confirm that the submitted build keeps running its bundled web assets across launches and background/foreground transitions while the review hold is active.
|
|
353
|
+
|
|
354
|
+
#### Good practice for App Store review
|
|
355
|
+
|
|
356
|
+
Do not tell the user the app is updating. In any UI the user can see, including copy on top of the splash screen, settings, and buttons, do not say "update", "live update", "remote update", "OTA", "downloading", or "installing". A progress bar is fine when its label describes tailoring the experience, for example "Tailoring your experience…". Calling that wait an update reads as the app installing behavior that was not in the reviewed binary.
|
|
357
|
+
|
|
358
|
+
Do not add a button such as "Update the app" or "Apply update" to trigger the bundle. If you need the user to continue, the furthest the UI should go is asking them to reopen the app, for example "Please reopen the app". Do not say that reopening applies an update.
|
|
359
|
+
|
|
360
|
+
For the iOS plugin version that removes the `autoSplashscreen` code App Review flags, see [Instant apply](#instant-apply-always-atinstall-onlaunch).
|
|
361
|
+
|
|
328
362
|
### Packaging `dist.zip` update bundles
|
|
329
363
|
|
|
330
364
|
Capacitor Updater works by unzipping a compiled app bundle to the native device filesystem. Whatever you choose to name the file you upload/download from your release/update server URL (via either manual or automatic updating), this `.zip` bundle must meet the following requirements:
|
|
@@ -355,7 +389,7 @@ CapacitorUpdater can be configured with these options:
|
|
|
355
389
|
| **`updateUrl`** | <code>string</code> | Configure the URL / endpoint to which update checks are sent. Only available for Android and iOS. | <code>https://plugin.capgo.app/updates</code> | |
|
|
356
390
|
| **`channelUrl`** | <code>string</code> | Configure the URL / endpoint for channel operations. Only available for Android and iOS. | <code>https://plugin.capgo.app/channel_self</code> | |
|
|
357
391
|
| **`statsUrl`** | <code>string</code> | Configure the URL / endpoint to which update statistics are sent. Only available for Android and iOS. Set to "" to disable stats reporting. Native stats include update lifecycle events, app health signals such as crashes, Android ANRs, low-memory exits, iOS memory warnings, and WebView health signals such as JavaScript errors, unhandled promise rejections, resource load failures, WebView renderer exits, unclean WebView restarts, app launch readiness timing, and WebView load milestones when available. Failed background update checks that never start a download (network errors, timeouts, non-2xx responses, unreadable payloads) are reported as `update_check_error` with `metadata.error` and optional `metadata.status_code`, not as `download_fail`. Self-hosted Capgo backends must allow the `update_check_error` stats action. | <code>https://plugin.capgo.app/stats</code> | |
|
|
358
|
-
| **`publicKey`** | <code>string</code> | Configure the public key for end to end live update encryption Version 2 Only available for Android and iOS.
|
|
392
|
+
| **`publicKey`** | <code>string</code> | Configure the public key for end to end live update encryption Version 2. What it guarantees: a bundle can only be installed when its checksum and session key were produced with the matching private key. Capgo never holds that key, so Capgo cannot create, modify or decrypt an update for your app. It does NOT make the bundle unreadable to someone who has your app binary: the public key ships inside the app, and anyone holding the app can recover the session key and read the bundle. If you also need Capgo to be unable to find your app (and so its public key), use a Capgo app id that is not your store bundle id (`appId` in this plugin config) so the app is not identifiable from the dashboard. Only available for Android and iOS. | <code>undefined</code> | 6.2.0 |
|
|
359
393
|
| **`version`** | <code>string</code> | Configure the current version of the app. This will be used for the first update request. If not set, the plugin will get the version from the native code. Only available for Android and iOS. | <code>undefined</code> | 4.17.48 |
|
|
360
394
|
| **`directUpdate`** | <code>boolean \| 'always' \| 'atInstall' \| 'onLaunch'</code> | Configure when the plugin should direct install updates. Only for autoUpdate mode. Instant apply (`atInstall`, `onLaunch`, `always`) should be uploaded with `--delta` so the update does not slow the user experience. A full zip, especially over 10MB, is relatively slow for users. These modes require `autoSplashscreen: true` and `@capacitor/splash-screen` installed with `launchAutoHide: false`. This flag makes the CLI upload delta in CI and ask for confirmation in local uploads. - false: Never do direct updates - atInstall: Same as `"atInstall"` for {@link autoUpdate} - onLaunch: Same as `"onLaunch"` for {@link autoUpdate} - always: Same as `"always"` for {@link autoUpdate} - true: (deprecated) Same as "always" for backward compatibility | <code>false</code> | 5.1.0 |
|
|
361
395
|
| **`autoSplashscreen`** | <code>boolean</code> | Automatically hide the splashscreen after instant apply updates finish, or when no update is needed. Required when using instant apply modes (`"atInstall"`, `"onLaunch"`, `"always"`), including the deprecated `directUpdate` values `"atInstall"`, `"onLaunch"`, `"always"`, and `true`. `@capacitor/splash-screen` must be installed and configured with `launchAutoHide: false`. This removes the need to manually listen for appReady events and call SplashScreen.hide(). Only available for Android and iOS. | <code>false</code> | 7.6.0 |
|
|
@@ -370,7 +404,9 @@ CapacitorUpdater can be configured with these options:
|
|
|
370
404
|
| **`localApi`** | <code>string</code> | Configure the CLI to use a local api for testing. | <code>undefined</code> | 6.3.3 |
|
|
371
405
|
| **`localApiFiles`** | <code>string</code> | Configure the CLI to use a local file api for testing. | <code>undefined</code> | 6.3.3 |
|
|
372
406
|
| **`allowModifyUrl`** | <code>boolean</code> | Allow the plugin to modify the updateUrl, statsUrl and channelUrl dynamically from the JavaScript side. | <code>false</code> | 5.4.0 |
|
|
373
|
-
| **`allowHttpsToHttpRedirect`** | <code>boolean</code> | Allow the plugin to follow redirects from HTTPS to plain HTTP for its own network requests (update checks, stats, channel calls, and bundle/manifest downloads). Blocked by default so a redirect can never downgrade updater traffic to an unencrypted connection. Only enable this if your self-hosted update server or CDN must redirect to an HTTP URL. Direct HTTP URLs (for example `localApi` during development) are
|
|
407
|
+
| **`allowHttpsToHttpRedirect`** | <code>boolean</code> | Allow the plugin to follow redirects from HTTPS to plain HTTP for its own network requests (update checks, stats, channel calls, and bundle/manifest downloads). Blocked by default so a redirect can never downgrade updater traffic to an unencrypted connection. Only enable this if your self-hosted update server or CDN must redirect to an HTTP URL. `httpsOnly` (default `true`) rejects every non-https URL and redirect hop regardless of this setting, so an HTTP redirect also needs `httpsOnly: false`. Direct HTTP URLs (for example `localApi` during development) are only allowed with `httpsOnly: false` as well. Only available for Android and iOS. | <code>false</code> | 8.52.0 |
|
|
408
|
+
| **`httpsOnly`** | <code>boolean</code> | Require https for every URL the plugin talks to: `updateUrl`, `statsUrl`, `channelUrl` (from config, persisted values and `setUpdateUrl` / `setStatsUrl` / `setChannelUrl`), bundle zip URLs, every manifest `download_url`, preview payload URLs and every redirect hop. When enabled it overrides `allowHttpsToHttpRedirect`. A non-https URL fails the call or download with `httpsOnly is enabled and <url> is not https`. Set to `false` only for local development servers (for example a plain-http `localApi` on loopback) or a self-hosted plain-http update server you control. Upgrading with a plain-http `updateUrl`, `statsUrl`, `channelUrl` or `allowHttpsToHttpRedirect: true` requires setting this to `false` explicitly. Only available for Android and iOS. | <code>true</code> | 8.54.0 |
|
|
409
|
+
| **`builtinMinimum`** | <code>boolean</code> | Refuse to download or install a bundle whose version is lower than the native app version (`version` config override, else `CFBundleShortVersionString` / `versionName`). This is the on-device counterpart of the Capgo channel setting "disable auto update under native" and protects against a replayed old update response rolling the app back below its store version. Only the numeric `major.minor.patch` part is compared (a `1.2.3-beta.1` bundle is accepted on native `1.2.3`), and versions that do not parse as semver skip the check. Rejections are reported as the `version_below_native` stat. Keep it off if you version web bundles independently of the native app (for example native `2.0.0` with bundle `1.4.7`). Future-major default candidate: `true`. Only available for Android and iOS. | <code>false</code> | 8.54.0 |
|
|
374
410
|
| **`allowModifyAppId`** | <code>boolean</code> | Allow the plugin to modify the appId dynamically from the JavaScript side. | <code>false</code> | 7.14.0 |
|
|
375
411
|
| **`allowManualBundleError`** | <code>boolean</code> | Allow marking bundles as errored from JavaScript while using manual update flows. When enabled, {@link CapacitorUpdaterPlugin.setBundleError} can change a bundle status to `error`. | <code>false</code> | 7.20.0 |
|
|
376
412
|
| **`allowPreview`** | <code>boolean</code> | Allow JavaScript to start a native preview session and temporarily request updates for another app id. This is intended for trusted container apps that implement Expo Go-style preview flows. Only available for Android and iOS. | <code>false</code> | 8.47.0 |
|
|
@@ -428,6 +464,8 @@ In `capacitor.config.json`:
|
|
|
428
464
|
"localApiFiles": undefined,
|
|
429
465
|
"allowModifyUrl": undefined,
|
|
430
466
|
"allowHttpsToHttpRedirect": undefined,
|
|
467
|
+
"httpsOnly": undefined,
|
|
468
|
+
"builtinMinimum": undefined,
|
|
431
469
|
"allowModifyAppId": undefined,
|
|
432
470
|
"allowManualBundleError": undefined,
|
|
433
471
|
"allowPreview": undefined,
|
|
@@ -491,6 +529,8 @@ const config: CapacitorConfig = {
|
|
|
491
529
|
localApiFiles: undefined,
|
|
492
530
|
allowModifyUrl: undefined,
|
|
493
531
|
allowHttpsToHttpRedirect: undefined,
|
|
532
|
+
httpsOnly: undefined,
|
|
533
|
+
builtinMinimum: undefined,
|
|
494
534
|
allowModifyAppId: undefined,
|
|
495
535
|
allowManualBundleError: undefined,
|
|
496
536
|
allowPreview: undefined,
|
|
@@ -3087,7 +3127,7 @@ CapacitorUpdater.addListener('download', (info: any) => {
|
|
|
3087
3127
|
});
|
|
3088
3128
|
```
|
|
3089
3129
|
|
|
3090
|
-
On iOS,
|
|
3130
|
+
On iOS, a progress bar is fine. Do not label it as an update, a live update, a remote update, or a download, and do not add an "Apply update" button. Describe the wait as tailoring the experience, for example "Tailoring your experience…". If the user must continue, ask them to reopen the app. See [Good practice for App Store review](#good-practice-for-app-store-review).
|
|
3091
3131
|
|
|
3092
3132
|
### Inspiration
|
|
3093
3133
|
|
package/android/build.gradle
CHANGED
|
@@ -65,6 +65,7 @@ dependencies {
|
|
|
65
65
|
testImplementation 'org.json:json:20250517'
|
|
66
66
|
testImplementation 'org.robolectric:robolectric:4.17'
|
|
67
67
|
testImplementation 'androidx.arch.core:core-testing:2.2.0'
|
|
68
|
+
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
|
|
68
69
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
69
70
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
70
71
|
implementation 'org.brotli:dec:0.1.2'
|
|
@@ -202,6 +202,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
202
202
|
private Boolean allowManualBundleError = false;
|
|
203
203
|
private Boolean allowPreview = false;
|
|
204
204
|
Boolean allowSetDefaultChannel = true;
|
|
205
|
+
static final ThreadLocal<Boolean> reloadFailedDueToAppReadyTimeout = ThreadLocal.withInitial(() -> false);
|
|
205
206
|
|
|
206
207
|
String getUpdateUrl() {
|
|
207
208
|
return this.updateUrl;
|
|
@@ -952,6 +953,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
952
953
|
this.implementation.timeout = (int) Math.min(Integer.MAX_VALUE, responseTimeoutMillis);
|
|
953
954
|
DownloadService.applyHttpTimeouts(this.implementation.timeout);
|
|
954
955
|
DownloadService.setAllowHttpsToHttpRedirect(this.getConfig().getBoolean("allowHttpsToHttpRedirect", false));
|
|
956
|
+
// httpsOnly overrides allowHttpsToHttpRedirect: no hop may leave https while it is on.
|
|
957
|
+
final boolean httpsOnly = this.getConfig().getBoolean("httpsOnly", true);
|
|
958
|
+
this.implementation.httpsOnly = httpsOnly;
|
|
959
|
+
DownloadService.setHttpsOnly(httpsOnly);
|
|
960
|
+
this.implementation.builtinMinimum = this.getConfig().getBoolean("builtinMinimum", false);
|
|
961
|
+
// Do not crash at load: requests to a non-https URL fail later with the same message.
|
|
962
|
+
this.warnIfNotHttps("updateUrl", this.updateUrl);
|
|
963
|
+
this.warnIfNotHttps("statsUrl", this.implementation.statsUrl);
|
|
964
|
+
this.warnIfNotHttps("channelUrl", this.implementation.channelUrl);
|
|
955
965
|
this.shakeMenuEnabled = this.getConfig().getBoolean("shakeMenu", false);
|
|
956
966
|
this.shakeChannelSelectorEnabled = this.getConfig().getBoolean("allowShakeChannelSelector", false);
|
|
957
967
|
this.shakeMenuGesture = normalizedShakeMenuGesture(this.getConfig().getString("shakeMenuGesture", SHAKE_MENU_GESTURE_SHAKE));
|
|
@@ -1070,6 +1080,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1070
1080
|
}
|
|
1071
1081
|
|
|
1072
1082
|
private boolean semaphoreWait(final int phase, Number waitTime) {
|
|
1083
|
+
return this.semaphoreWait(phase, waitTime, false);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
private boolean semaphoreWait(final int phase, Number waitTime, final boolean trackReloadAppReadyTimeout) {
|
|
1087
|
+
if (trackReloadAppReadyTimeout) {
|
|
1088
|
+
CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.set(false);
|
|
1089
|
+
}
|
|
1073
1090
|
try {
|
|
1074
1091
|
semaphoreReady.awaitAdvanceInterruptibly(phase, waitTime.longValue(), TimeUnit.MILLISECONDS);
|
|
1075
1092
|
logger.info("semaphoreReady count " + semaphoreReady.getPhase());
|
|
@@ -1082,8 +1099,41 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1082
1099
|
} catch (TimeoutException e) {
|
|
1083
1100
|
logger.error("Semaphore timeout: " + e.getMessage());
|
|
1084
1101
|
cleanupTimedOutSemaphoreWait(phase);
|
|
1102
|
+
if (trackReloadAppReadyTimeout) {
|
|
1103
|
+
CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.set(true);
|
|
1104
|
+
}
|
|
1105
|
+
return false;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
static boolean shouldRestoreStateAfterPendingBundleReloadFailure(
|
|
1110
|
+
final boolean reloadFailedDueToAppReadyTimeout,
|
|
1111
|
+
final BundleInfo activeBundle,
|
|
1112
|
+
final boolean watchdogRollbackInProgress,
|
|
1113
|
+
final BundleInfo attemptedBundle,
|
|
1114
|
+
final boolean previewModeSkipsWatchdogRollback
|
|
1115
|
+
) {
|
|
1116
|
+
if (!reloadFailedDueToAppReadyTimeout) {
|
|
1117
|
+
return true;
|
|
1118
|
+
}
|
|
1119
|
+
if (watchdogRollbackInProgress) {
|
|
1085
1120
|
return false;
|
|
1086
1121
|
}
|
|
1122
|
+
if (attemptedBundle != null && activeBundle != null && !attemptedBundle.getId().equals(activeBundle.getId())) {
|
|
1123
|
+
return false;
|
|
1124
|
+
}
|
|
1125
|
+
if (previewModeSkipsWatchdogRollback) {
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
// checkRevert skips builtin bundles and SUCCESS current bundles, so reload() must restore on its own.
|
|
1129
|
+
if (activeBundle != null && activeBundle.isBuiltin()) {
|
|
1130
|
+
return true;
|
|
1131
|
+
}
|
|
1132
|
+
if (activeBundle != null && BundleStatus.SUCCESS == activeBundle.getStatus()) {
|
|
1133
|
+
return true;
|
|
1134
|
+
}
|
|
1135
|
+
// App-ready watchdog and reload()/performReset share the same timeout. Restoring here races performReset.
|
|
1136
|
+
return false;
|
|
1087
1137
|
}
|
|
1088
1138
|
|
|
1089
1139
|
private int semaphoreUp() {
|
|
@@ -2542,8 +2592,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
2542
2592
|
return true;
|
|
2543
2593
|
}
|
|
2544
2594
|
|
|
2545
|
-
|
|
2546
|
-
|
|
2595
|
+
if (
|
|
2596
|
+
CapacitorUpdaterPlugin.shouldRestoreStateAfterPendingBundleReloadFailure(
|
|
2597
|
+
CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.get(),
|
|
2598
|
+
latest,
|
|
2599
|
+
false,
|
|
2600
|
+
latest,
|
|
2601
|
+
false
|
|
2602
|
+
)
|
|
2603
|
+
) {
|
|
2604
|
+
this.implementation.restoreResetState(previousState);
|
|
2605
|
+
this.restoreLiveBundleStateAfterFailedReload();
|
|
2606
|
+
}
|
|
2547
2607
|
logger.error("Direct update reload failed after staging bundle: " + latest.toString());
|
|
2548
2608
|
return false;
|
|
2549
2609
|
}
|
|
@@ -2700,6 +2760,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
2700
2760
|
call.reject("setUpdateUrl called without url");
|
|
2701
2761
|
return;
|
|
2702
2762
|
}
|
|
2763
|
+
if (this.rejectIfNotHttps(call, url)) {
|
|
2764
|
+
return;
|
|
2765
|
+
}
|
|
2703
2766
|
if (Boolean.TRUE.equals(this.persistModifyUrl)) {
|
|
2704
2767
|
this.editor.putString(UPDATE_URL_PREF_KEY, url);
|
|
2705
2768
|
if (!this.editor.commit()) {
|
|
@@ -2725,6 +2788,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
2725
2788
|
call.reject("setStatsUrl called without url");
|
|
2726
2789
|
return;
|
|
2727
2790
|
}
|
|
2791
|
+
if (this.rejectIfNotHttps(call, url)) {
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2728
2794
|
if (Boolean.TRUE.equals(this.persistModifyUrl)) {
|
|
2729
2795
|
this.editor.putString(STATS_URL_PREF_KEY, url);
|
|
2730
2796
|
if (!this.editor.commit()) {
|
|
@@ -2750,6 +2816,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
2750
2816
|
call.reject("setChannelUrl called without url");
|
|
2751
2817
|
return;
|
|
2752
2818
|
}
|
|
2819
|
+
if (this.rejectIfNotHttps(call, url)) {
|
|
2820
|
+
return;
|
|
2821
|
+
}
|
|
2753
2822
|
if (Boolean.TRUE.equals(this.persistModifyUrl)) {
|
|
2754
2823
|
this.editor.putString(CHANNEL_URL_PREF_KEY, url);
|
|
2755
2824
|
if (!this.editor.commit()) {
|
|
@@ -3020,6 +3089,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
3020
3089
|
this.implementation.sendStats("checksum_required");
|
|
3021
3090
|
throw new IOException("Checksum required");
|
|
3022
3091
|
}
|
|
3092
|
+
// https / builtinMinimum gates run before any network IO and before waiting on cleanup.
|
|
3093
|
+
this.implementation.runPreDownloadSecurityGates(url, version, manifest);
|
|
3023
3094
|
// Manual/preview downloads must wait too — launch orphan sweep can delete their temps.
|
|
3024
3095
|
waitForCleanupIfNeeded();
|
|
3025
3096
|
if (manifest != null) {
|
|
@@ -3213,7 +3284,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
3213
3284
|
this.notifyListeners("appReloaded", new JSObject(), false);
|
|
3214
3285
|
|
|
3215
3286
|
// Wait for the reload to complete (until notifyAppReady is called)
|
|
3216
|
-
return this.semaphoreWait(phase, waitTimeMs);
|
|
3287
|
+
return this.semaphoreWait(phase, waitTimeMs, true);
|
|
3217
3288
|
}
|
|
3218
3289
|
|
|
3219
3290
|
/**
|
|
@@ -3266,8 +3337,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
3266
3337
|
call.resolve();
|
|
3267
3338
|
return;
|
|
3268
3339
|
}
|
|
3269
|
-
|
|
3270
|
-
|
|
3340
|
+
if (
|
|
3341
|
+
CapacitorUpdaterPlugin.shouldRestoreStateAfterPendingBundleReloadFailure(
|
|
3342
|
+
CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.get(),
|
|
3343
|
+
this.implementation.getCurrentBundle(),
|
|
3344
|
+
false,
|
|
3345
|
+
next,
|
|
3346
|
+
false
|
|
3347
|
+
)
|
|
3348
|
+
) {
|
|
3349
|
+
this.implementation.restoreResetState(previousState);
|
|
3350
|
+
this.restoreLiveBundleStateAfterFailedReload();
|
|
3351
|
+
}
|
|
3271
3352
|
logger.error("Reload failed after applying pending bundle: " + next.getVersionName());
|
|
3272
3353
|
call.reject("Reload failed after applying pending bundle: " + next.getVersionName());
|
|
3273
3354
|
return;
|
|
@@ -4485,6 +4566,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
4485
4566
|
}
|
|
4486
4567
|
|
|
4487
4568
|
private boolean performReset(final Boolean toLastSuccessful, final Boolean usePendingBundle, final boolean internal) {
|
|
4569
|
+
return this.performResetBody(toLastSuccessful, usePendingBundle, internal);
|
|
4570
|
+
}
|
|
4571
|
+
|
|
4572
|
+
private boolean performResetBody(final Boolean toLastSuccessful, final Boolean usePendingBundle, final boolean internal) {
|
|
4488
4573
|
final BundleInfo fallback = this.implementation.getFallbackBundle();
|
|
4489
4574
|
final BundleInfo pending = this.implementation.getNextBundle();
|
|
4490
4575
|
final CapgoUpdater.ResetState previousState = this.implementation.captureResetState();
|
|
@@ -4507,14 +4592,30 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
4507
4592
|
} else {
|
|
4508
4593
|
didApplyPendingBundle = this.implementation.set(pending);
|
|
4509
4594
|
}
|
|
4595
|
+
if (didApplyPendingBundle && !pending.isBuiltin()) {
|
|
4596
|
+
this.implementation.preserveFallbackForWatchdog(previousState);
|
|
4597
|
+
}
|
|
4510
4598
|
if (didApplyPendingBundle && this._reload()) {
|
|
4511
4599
|
this.implementation.finalizeResetTransition(previousBundleName, internal);
|
|
4512
4600
|
this.notifyBundleSet(pending);
|
|
4513
4601
|
this.implementation.setNextBundle(null);
|
|
4514
4602
|
return true;
|
|
4515
4603
|
}
|
|
4516
|
-
|
|
4517
|
-
|
|
4604
|
+
if (
|
|
4605
|
+
CapacitorUpdaterPlugin.shouldRestoreStateAfterPendingBundleReloadFailure(
|
|
4606
|
+
CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.get(),
|
|
4607
|
+
this.implementation.getCurrentBundle(),
|
|
4608
|
+
internal,
|
|
4609
|
+
pending,
|
|
4610
|
+
this.isPreviewSessionStateActive()
|
|
4611
|
+
)
|
|
4612
|
+
) {
|
|
4613
|
+
this.implementation.restoreResetState(previousState);
|
|
4614
|
+
this.restoreLiveBundleStateAfterFailedReload();
|
|
4615
|
+
} else if (CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.get()) {
|
|
4616
|
+
// prepareResetStateForTransition cleared fallback; checkRevert needs the previous target.
|
|
4617
|
+
this.implementation.preserveFallbackForWatchdog(previousState);
|
|
4618
|
+
}
|
|
4518
4619
|
return false;
|
|
4519
4620
|
}
|
|
4520
4621
|
|
|
@@ -4522,14 +4623,32 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
4522
4623
|
if (this.implementation.canSet(fallback)) {
|
|
4523
4624
|
this.implementation.prepareResetStateForTransition();
|
|
4524
4625
|
logger.info("Resetting to: " + fallback);
|
|
4525
|
-
if (this.implementation.set(fallback)
|
|
4526
|
-
this.implementation.
|
|
4527
|
-
this.
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4626
|
+
if (this.implementation.set(fallback)) {
|
|
4627
|
+
this.implementation.preserveFallbackForWatchdog(previousState);
|
|
4628
|
+
if (this._reload()) {
|
|
4629
|
+
this.implementation.finalizeResetTransition(previousBundleName, internal);
|
|
4630
|
+
this.notifyBundleSet(fallback);
|
|
4631
|
+
return true;
|
|
4632
|
+
}
|
|
4633
|
+
if (
|
|
4634
|
+
!internal &&
|
|
4635
|
+
CapacitorUpdaterPlugin.shouldRestoreStateAfterPendingBundleReloadFailure(
|
|
4636
|
+
CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.get(),
|
|
4637
|
+
this.implementation.getCurrentBundle(),
|
|
4638
|
+
internal,
|
|
4639
|
+
fallback,
|
|
4640
|
+
this.isPreviewSessionStateActive()
|
|
4641
|
+
)
|
|
4642
|
+
) {
|
|
4643
|
+
this.implementation.restoreResetState(previousState);
|
|
4644
|
+
this.restoreLiveBundleStateAfterFailedReload();
|
|
4645
|
+
return false;
|
|
4646
|
+
}
|
|
4647
|
+
if (!internal && CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.get()) {
|
|
4648
|
+
return false;
|
|
4649
|
+
}
|
|
4650
|
+
} else if (!internal) {
|
|
4531
4651
|
this.implementation.restoreResetState(previousState);
|
|
4532
|
-
this.restoreLiveBundleStateAfterFailedReload();
|
|
4533
4652
|
return false;
|
|
4534
4653
|
}
|
|
4535
4654
|
logger.warn("Fallback reload failed during internal reset, resetting to native instead");
|
|
@@ -4544,7 +4663,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
4544
4663
|
this.implementation.finalizeResetTransition(previousBundleName, internal);
|
|
4545
4664
|
return true;
|
|
4546
4665
|
}
|
|
4547
|
-
if (
|
|
4666
|
+
if (
|
|
4667
|
+
!internal &&
|
|
4668
|
+
CapacitorUpdaterPlugin.shouldRestoreStateAfterPendingBundleReloadFailure(
|
|
4669
|
+
CapacitorUpdaterPlugin.reloadFailedDueToAppReadyTimeout.get(),
|
|
4670
|
+
this.implementation.getCurrentBundle(),
|
|
4671
|
+
internal,
|
|
4672
|
+
null,
|
|
4673
|
+
this.isPreviewSessionStateActive()
|
|
4674
|
+
)
|
|
4675
|
+
) {
|
|
4548
4676
|
this.implementation.restoreResetState(previousState);
|
|
4549
4677
|
this.restoreLiveBundleStateAfterFailedReload();
|
|
4550
4678
|
}
|
|
@@ -4943,10 +5071,31 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
4943
5071
|
private boolean isValidURL(String urlStr) {
|
|
4944
5072
|
try {
|
|
4945
5073
|
new URL(urlStr);
|
|
4946
|
-
return true;
|
|
4947
5074
|
} catch (MalformedURLException e) {
|
|
4948
5075
|
return false;
|
|
4949
5076
|
}
|
|
5077
|
+
if (this.implementation.httpsOnly && !CapgoUpdater.isHttpsUrl(urlStr)) {
|
|
5078
|
+
logger.error(CapgoUpdater.httpsOnlyMessage(urlStr));
|
|
5079
|
+
return false;
|
|
5080
|
+
}
|
|
5081
|
+
return true;
|
|
5082
|
+
}
|
|
5083
|
+
|
|
5084
|
+
private void warnIfNotHttps(final String name, final String url) {
|
|
5085
|
+
if (this.implementation.httpsOnly && url != null && !url.isEmpty() && !CapgoUpdater.isHttpsUrl(url)) {
|
|
5086
|
+
logger.error(CapgoUpdater.httpsOnlyMessage(url) + " (" + name + ")");
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
|
|
5090
|
+
/** httpsOnly check for setUpdateUrl / setStatsUrl / setChannelUrl: rejects the call and returns true. */
|
|
5091
|
+
private boolean rejectIfNotHttps(final PluginCall call, final String url) {
|
|
5092
|
+
if (this.implementation.httpsOnly && !CapgoUpdater.isHttpsUrl(url)) {
|
|
5093
|
+
final String message = CapgoUpdater.httpsOnlyMessage(url);
|
|
5094
|
+
logger.error(message);
|
|
5095
|
+
call.reject(message);
|
|
5096
|
+
return true;
|
|
5097
|
+
}
|
|
5098
|
+
return false;
|
|
4950
5099
|
}
|
|
4951
5100
|
|
|
4952
5101
|
static String normalizedUpdateResponseKind(final String kind) {
|
|
@@ -5119,6 +5268,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
5119
5268
|
this.implementation.sendStats("checksum_required", latestVersionName);
|
|
5120
5269
|
return "Checksum required";
|
|
5121
5270
|
}
|
|
5271
|
+
try {
|
|
5272
|
+
this.implementation.runPreDownloadSecurityGates(
|
|
5273
|
+
latest.getString("url", ""),
|
|
5274
|
+
latestVersionName,
|
|
5275
|
+
latest.optJSONArray("manifest")
|
|
5276
|
+
);
|
|
5277
|
+
} catch (final IOException e) {
|
|
5278
|
+
return e.getMessage() == null ? "Download blocked" : e.getMessage();
|
|
5279
|
+
}
|
|
5122
5280
|
return null;
|
|
5123
5281
|
}
|
|
5124
5282
|
|
|
@@ -5283,6 +5441,19 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
5283
5441
|
if (
|
|
5284
5442
|
latestVersionName != null && !latestVersionName.isEmpty() && !current.getVersionName().equals(latestVersionName)
|
|
5285
5443
|
) {
|
|
5444
|
+
// builtinMinimum also covers an already-downloaded bundle reused without a new download.
|
|
5445
|
+
try {
|
|
5446
|
+
CapacitorUpdaterPlugin.this.implementation.requireVersionNotBelowBuiltin(latestVersionName);
|
|
5447
|
+
} catch (final IOException e) {
|
|
5448
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
5449
|
+
e.getMessage() == null ? "Download blocked" : e.getMessage(),
|
|
5450
|
+
latestVersionName,
|
|
5451
|
+
current,
|
|
5452
|
+
true,
|
|
5453
|
+
plannedDirectUpdate
|
|
5454
|
+
);
|
|
5455
|
+
return;
|
|
5456
|
+
}
|
|
5286
5457
|
final BundleInfo latest = CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
|
|
5287
5458
|
if (latest != null) {
|
|
5288
5459
|
final JSObject ret = new JSObject();
|