native-update 3.4.2 → 4.0.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.
Files changed (46) hide show
  1. package/AI-INTEGRATION-GUIDE.md +26 -16
  2. package/NativeUpdate.podspec +2 -2
  3. package/README.md +24 -20
  4. package/android/build.gradle +37 -33
  5. package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  6. package/android/proguard-rules.pro +0 -3
  7. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +45 -49
  8. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +12 -10
  9. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +12 -21
  10. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +3 -34
  11. package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +206 -72
  12. package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +74 -37
  13. package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +169 -179
  14. package/android/variables.gradle +2 -2
  15. package/cli/commands/bundle-verify.js +4 -1
  16. package/cli/commands/keys-generate.js +12 -46
  17. package/cli/index.js +4 -7
  18. package/cli/package.json +2 -1
  19. package/dist/esm/core/config.d.ts +3 -0
  20. package/dist/esm/core/config.js +17 -0
  21. package/dist/esm/core/plugin-manager.js +4 -2
  22. package/dist/esm/core/security.js +2 -5
  23. package/dist/esm/core/update-check.d.ts +2 -0
  24. package/dist/esm/core/update-check.js +5 -3
  25. package/dist/esm/definitions.d.ts +43 -2
  26. package/dist/esm/live-update/delta-processor.d.ts +6 -20
  27. package/dist/esm/live-update/delta-processor.js +75 -119
  28. package/dist/esm/plugin.d.ts +0 -3
  29. package/dist/esm/plugin.js +172 -12
  30. package/dist/esm/security/crypto.js +2 -5
  31. package/dist/esm/web.d.ts +1 -9
  32. package/dist/esm/web.js +4 -56
  33. package/dist/plugin.cjs +1 -1
  34. package/dist/plugin.esm.js +1 -1
  35. package/dist/plugin.js +2 -2
  36. package/docs/CHANGELOG.md +49 -0
  37. package/docs/KNOWN_LIMITATIONS.md +4 -3
  38. package/docs/MIGRATION.md +32 -3
  39. package/docs/server-requirements.md +40 -29
  40. package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +6 -2
  41. package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +21 -30
  42. package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +269 -61
  43. package/ios/Plugin/NativeUpdatePlugin.m +8 -1
  44. package/ios/Plugin/NativeUpdatePlugin.swift +71 -34
  45. package/ios/Plugin/Security/SecurityManager.swift +100 -99
  46. package/package.json +25 -13
@@ -6,8 +6,6 @@ Quick reference for AI development agents (Claude Code, Cursor, Copilot, etc.) t
6
6
 
7
7
  ```bash
8
8
  yarn add native-update
9
- # or
10
- npm install native-update
11
9
  ```
12
10
 
13
11
  ## Core Concepts
@@ -34,6 +32,8 @@ await NativeUpdate.configure({
34
32
  // Sent as X-API-Key on every check. Mint/copy in the dashboard
35
33
  // (Apps → your app → API Keys). Supported here since v3.1.3.
36
34
  apiKey: 'nu_app_…',
35
+ publicKey: import.meta.env.VITE_NATIVE_UPDATE_PUBLIC_KEY,
36
+ requireSignature: true,
37
37
  channel: 'production', // e.g. 'development' | 'staging' | 'production'
38
38
  autoUpdate: true,
39
39
  updateStrategy: 'background', // 'immediate' | 'background' | 'manual'
@@ -54,15 +54,12 @@ if (result.status === 'UPDATE_INSTALLED') {
54
54
  }
55
55
 
56
56
  // Manual update flow
57
- const latest = await NativeUpdate.getLatest();
58
- if (latest.available && latest.url && latest.version && latest.checksum) {
59
- const bundle = await NativeUpdate.download({
60
- url: latest.url,
61
- version: latest.version,
62
- checksum: latest.checksum,
63
- });
64
- await NativeUpdate.set(bundle);
65
- await NativeUpdate.reload();
57
+ const latest = await NativeUpdate.checkForUpdate();
58
+ if (latest.available) {
59
+ // Fetches the complete signed manifest and uses a compatible NUDELTA/1
60
+ // patch when available, with verified full-bundle fallback.
61
+ await NativeUpdate.downloadUpdate();
62
+ await NativeUpdate.applyUpdate();
66
63
  }
67
64
 
68
65
  // Notify app is stable after update (prevents auto-rollback)
@@ -77,7 +74,7 @@ import { NativeUpdate } from 'native-update';
77
74
  // Check for app store updates
78
75
  const updateInfo = await NativeUpdate.getAppUpdateInfo();
79
76
  if (updateInfo.updateAvailable) {
80
- if (updateInfo.updatePriority >= 4) {
77
+ if ((updateInfo.updatePriority ?? 0) >= 4) {
81
78
  // Critical update - force immediate
82
79
  await NativeUpdate.performImmediateUpdate();
83
80
  } else {
@@ -119,7 +116,7 @@ if (eligibility.canRequest) {
119
116
  | `notifyAppReady()` | Mark update as stable | `Promise<void>` |
120
117
  | `getLatest()` | Check for latest version | `Promise<LatestVersion>` |
121
118
  | `setChannel(channel)` | Switch update channel | `Promise<void>` |
122
- | `setUpdateUrl(url)` | Set update server URL | `Promise<void>` |
119
+ | `setUpdateUrl(url)` | Deprecated no-op; use reset + reinitialize | `Promise<void>` |
123
120
 
124
121
  ### App Update Methods
125
122
 
@@ -158,8 +155,12 @@ interface LiveUpdateConfig {
158
155
  channel?: string; // Update channel (default: 'production')
159
156
  autoUpdate?: boolean; // Auto-check + apply updates
160
157
  updateStrategy?: 'immediate' | 'background' | 'manual';
161
- publicKey?: string; // Public key for signature verification
162
- requireSignature?: boolean; // Reject unsigned bundles
158
+ publicKey?: string; // RSA public key for RSA-SHA256 verification
159
+ requireSignature?: boolean; // Reject unsigned bundles (default: true)
160
+ allowUnsignedDevelopmentUpdates?: boolean; // Explicit debug-only escape hatch
161
+ enableDeltaUpdates?: boolean; // Use verified NUDELTA/1 patches when available
162
+ maxBundleSize?: number; // Maximum compressed download (default: 100 MiB)
163
+ maxUncompressedBundleSize?: number; // Native extraction cap (default: 500 MiB)
163
164
  checksumAlgorithm?: 'SHA-256' | 'SHA-512'; // (default: 'SHA-256')
164
165
  checkInterval?: number; // Auto-check interval
165
166
  }
@@ -229,6 +230,15 @@ Response — `200` with `available: false` when there is no update, `200` with:
229
230
  "downloadUrl": "https://cdn.example.com/bundles/1.2.0.zip",
230
231
  "checksum": "sha256-hex...",
231
232
  "signature": "base64signature...",
233
+ "signatureAlgorithm": "RSA-SHA256",
234
+ "delta": {
235
+ "format": "NUDELTA/1",
236
+ "fromVersion": "1.1.0",
237
+ "patchUrl": "https://cdn.example.com/delta.json",
238
+ "patchSize": 32768,
239
+ "patchChecksum": "sha256-hex...",
240
+ "targetChecksum": "sha256-hex..."
241
+ },
232
242
  "size": 1048576,
233
243
  "mandatory": false,
234
244
  "releaseNotes": "Bug fixes and improvements"
@@ -515,7 +525,7 @@ Web platform supports checking for updates only. Actual OTA updates require nati
515
525
  ## Security Best Practices
516
526
 
517
527
  1. **Always use HTTPS** for update URLs
518
- 2. **Enable signature verification** with RSA/ECDSA keys
528
+ 2. **Keep signature verification enabled** with an RSA key (`RSA-SHA256`, PKCS#1 v1.5)
519
529
  3. **Use checksums** to verify bundle integrity
520
530
  4. **Test rollback** scenarios before production
521
531
  5. **Implement `notifyAppReady()`** to prevent auto-rollback on stable updates
@@ -11,9 +11,9 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '13.0'
14
+ s.ios.deployment_target = '14.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.dependency 'ZIPFoundation', '~> 0.9.19'
17
17
  s.swift_version = '5.9'
18
18
  s.frameworks = 'LocalAuthentication', 'Security'
19
- end
19
+ end
package/README.md CHANGED
@@ -29,11 +29,11 @@ are available as an HTTP API for CI and coding agents.
29
29
 
30
30
  | | |
31
31
  |---|---|
32
- | **Version** | `3.4.2` |
32
+ | **Version** | `4.0.1` |
33
33
  | **License** | MIT |
34
34
  | **Node** | `>=24.16.0` (install + CLI toolchain) |
35
- | **Platforms** | iOS 13+ · Android 5.0+ (API 21) · Web |
36
- | **Package size** | 263 kB tarball · ~1.07 MB unpacked · 136 files |
35
+ | **Platforms** | iOS 14+ · Android 8.0+ (API 26) · Web |
36
+ | **Package size** | 374 kB tarball · ~1.23 MB unpacked · 137 files |
37
37
  | **Types** | Bundled `.d.ts` · ESM + CommonJS entry points |
38
38
  | **Status** | Stable · actively maintained |
39
39
 
@@ -89,8 +89,10 @@ policies is your responsibility — see [Limitations](#limitations).
89
89
  <a id="features"></a>
90
90
  ## ✨ Features&nbsp;[#](#features)
91
91
 
92
- - **Live (OTA) updates** — download and activate a new web bundle at runtime, with checksum and optional
93
- signature verification before it is ever loaded.
92
+ - **Live (OTA) updates** — download and activate a new web bundle at runtime, with mandatory SHA-256 +
93
+ RSA-SHA256 verification before it is ever loaded.
94
+ - **Verified delta updates** — use a bounded `NUDELTA/1` patch from one of the last three compatible
95
+ builds when worthwhile, with automatic full-bundle fallback on any mismatch.
94
96
  - **Automatic rollback** — a bundle that never confirms a healthy boot is reverted by the native layer, so a
95
97
  bad release cannot brick installs.
96
98
  - **Channels** — route development, staging and production installs to different bundles from one backend.
@@ -126,8 +128,8 @@ unavailable rather than pretending. See [Limitations](#limitations).
126
128
  | `@capacitor/core` | `^8.0.1` | peer — the host app owns the Capacitor version |
127
129
  | `@capacitor/filesystem` | `>=8.0.0` | peer — stores and extracts downloaded bundles |
128
130
  | `@capacitor/preferences` | `>=8.0.0` | peer — records which bundle is active and whether it was confirmed |
129
- | iOS | 13.0+ | minimum deployment target of the native plugin |
130
- | Android | 5.0+ (API 21) | minimum SDK of the native plugin |
131
+ | iOS | 14.0+ | minimum deployment target of the native plugin |
132
+ | Android | 8.0+ (API 26) | Capacitor 8.5 minimum; compile/target SDK 36 and Java 21 |
131
133
  | An update server | — | the hosted dashboard, a self-hosted backend, or your own implementation of the HTTP contract |
132
134
 
133
135
  <a id="installation"></a>
@@ -161,6 +163,8 @@ await NativeUpdate.initialize({
161
163
  appId: 'com.example.app',
162
164
  serverUrl: 'https://nativeupdatebe.aoneahsan.com/api',
163
165
  apiKey: import.meta.env.VITE_NATIVE_UPDATE_API_KEY,
166
+ publicKey: import.meta.env.VITE_NATIVE_UPDATE_PUBLIC_KEY,
167
+ requireSignature: true,
164
168
  channel: 'production',
165
169
  });
166
170
 
@@ -259,10 +263,13 @@ Passed to `initialize()`. The complete set is in the
259
263
  | `channel` | `string` | `'production'` | which release channel this install follows |
260
264
  | `autoCheck` | `boolean` | `false` | check for updates without an explicit `sync()` |
261
265
  | `autoUpdate` | `boolean` | `false` | apply what it finds without asking |
262
- | `publicKey` | `string` | — | PEM public key used to verify bundle signatures |
266
+ | `publicKey` | `string` | — | PEM RSA public key used to verify RSA-SHA256 signatures |
263
267
  | `enableSignatureValidation` | `boolean` | `true` | reject a bundle whose signature does not verify |
264
- | `requireSignature` | `boolean` | — | reject a bundle that carries no signature at all |
268
+ | `requireSignature` | `boolean` | `true` | reject a bundle that carries no signature at all |
269
+ | `allowUnsignedDevelopmentUpdates` | `boolean` | `false` | explicit debug-only escape hatch; native release builds ignore it |
270
+ | `enableDeltaUpdates` | `boolean` | `true` | use verified NUDELTA/1 patches when the server offers one |
265
271
  | `maxBundleSize` | `number` | `104857600` | refuse a download larger than this, in bytes |
272
+ | `maxUncompressedBundleSize` | `number` | `524288000` | native ZIP extraction cap for zip-bomb defense |
266
273
  | `downloadTimeout` | `number` | `30000` | per-download timeout in milliseconds |
267
274
  | `retryAttempts` | `number` | `3` | download retries before giving up |
268
275
  | `retryDelay` | `number` | `1000` | milliseconds between retries |
@@ -286,8 +293,8 @@ An index. Signatures and behaviour are documented per method on the docs site.
286
293
  | Security | `getSecurityInfo` · `getAppIdentity` | [→](https://nativeupdate-docs.aoneahsan.com/reference/sdk/security/overview) |
287
294
  | Events | `addListener` · `removeAllListeners` | [→](https://nativeupdate-docs.aoneahsan.com/reference/sdk/live-update/events) |
288
295
 
289
- `setUpdateUrl()` is deprecated and does nothing. The server URL is fixed at `initialize()` so a compromised
290
- WebView cannot repoint updates at another host; call `initialize()` again to switch servers.
296
+ `setUpdateUrl()` is deprecated and does nothing. Configuration is fixed at initialization so a compromised
297
+ WebView cannot repoint updates at another host; call `reset()` and then initialize again to switch servers.
291
298
 
292
299
  <a id="types"></a>
293
300
  ## 🧩 Types&nbsp;[#](#types)
@@ -330,7 +337,7 @@ npx native-update <command> [options]
330
337
  | `bundle create <webDir>` | zip a build directory into a bundle and compute its checksum |
331
338
  | `bundle sign <bundle>` | sign a bundle with a private key |
332
339
  | `bundle verify <bundle>` | verify a bundle's signature against a public key |
333
- | `keys generate` | generate an RSA or EC signing key pair |
340
+ | `keys generate` | generate a supported RSA signing key pair |
334
341
  | `backend create <type>` | scaffold an `express`, `firebase` or `vercel` backend |
335
342
  | `server start` | run a local update server for testing |
336
343
  | `monitor` | watch deployments against a backend |
@@ -404,7 +411,7 @@ Full reference: [CLI docs](https://nativeupdate-docs.aoneahsan.com/reference/cli
404
411
 
405
412
  | Symptom | Cause | Fix |
406
413
  |---|---|---|
407
- | `getDefaultProguardFile('proguard-android.txt') is no longer supported` while building your Android release | The plugin's `android/build.gradle` names a default file the current Android Gradle Plugin removed. Present in 3.4.1 and 3.3.1 | Patch the installed package's `android/build.gradle` to use `proguard-android-optimize.txt` — Yarn's `patch:` protocol handles this — until a release fixes it |
414
+ | `getDefaultProguardFile('proguard-android.txt') is no longer supported` while building your Android release | Fixed in 3.4.2 and later | Upgrade to the latest release and remove any local Yarn patch |
408
415
  | Every update reverts a few minutes after it applies | `notifyAppReady()` is never called, so the native layer treats each boot as failed | Call `notifyAppReady()` once per successful boot, right after `initialize()` |
409
416
  | `require('native-update')` returns `{}` | Fixed in 3.4.1. Earlier versions emitted the CommonJS artifact with a `.js` extension inside a `"type": "module"` package, so Node loaded it as ESM | Upgrade to `3.4.1` or later |
410
417
  | Updates work on web, nothing happens on device | `npx cap sync` was not run after installing | Run `npx cap sync` and rebuild the native app |
@@ -418,10 +425,6 @@ More: [troubleshooting guide](https://nativeupdate-docs.aoneahsan.com/how-to/tro
418
425
  <a id="limitations"></a>
419
426
  ## 🚧 Limitations&nbsp;[#](#limitations)
420
427
 
421
- - **Android release builds currently fail to configure.** `android/build.gradle` references a ProGuard
422
- default file the current Android Gradle Plugin removed, so a consuming app's release build stops while
423
- evaluating this plugin. A workaround is in
424
- [Recovery & Troubleshooting](#recovery-troubleshooting); a fix is pending a release.
425
428
  - **OTA replaces the web layer only.** Anything that changes native code, permissions or the manifest still
426
429
  needs a store release.
427
430
  - **You supply the backend.** This package does not host your bundles. Use the hosted dashboard, self-host
@@ -496,9 +499,10 @@ indexed at [`/raw/manifest.json`](https://nativeupdate-docs.aoneahsan.com/raw/ma
496
499
  <a id="changelog"></a>
497
500
  ## 🔄 Changelog&nbsp;[#](#changelog)
498
501
 
499
- Latest release: **`3.4.2`** — fixed `require('native-update')` returning an empty object for every CommonJS
500
- consumer, pointed `repository` at the real git remote, and stopped internal agent-instruction files shipping
501
- in the tarball.
502
+ Latest release: **`4.0.1`** — adds verified delta delivery with automatic signed-full-bundle fallback,
503
+ standardizes every signer and verifier on RSA-SHA256, hardens native storage and URL validation, and raises
504
+ the supported baseline to Capacitor 8, Node.js 24.16+, and Android API 26+. The patch release also removes
505
+ local Yarn install state from the npm tarball and makes npm-normalized metadata explicit.
502
506
 
503
507
  Full history ships inside the package at `docs/CHANGELOG.md`, so it always matches the version you
504
508
  installed. It is also published as the
@@ -4,32 +4,35 @@ buildscript {
4
4
  mavenCentral()
5
5
  }
6
6
  dependencies {
7
- classpath 'com.android.tools.build:gradle:8.7.2'
8
- classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22'
7
+ classpath 'com.android.tools.build:gradle:8.13.2'
8
+ classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.20'
9
9
  }
10
10
  }
11
11
 
12
12
  ext {
13
- kotlinVersion = '1.9.22'
13
+ kotlinVersion = '2.2.20'
14
14
  compileSdkVersion = 36
15
15
  targetSdkVersion = 36
16
- minSdkVersion = 21
17
- androidxAppCompatVersion = '1.6.1'
18
- androidxCoreVersion = '1.13.1'
19
- androidxWorkVersion = '2.9.0'
16
+ // Capacitor Android 8.5 declares API 26; the plugin cannot advertise or
17
+ // assemble against a lower manifest floor than its required peer.
18
+ minSdkVersion = 26
19
+ androidxAppCompatVersion = '1.7.1'
20
+ // 1.19 requires compileSdk 37 + AGP 9.1; Capacitor 8's supported line is AGP 8/API 36.
21
+ androidxCoreVersion = '1.17.0'
22
+ androidxWorkVersion = '2.11.2'
20
23
  playAppUpdateVersion = '2.1.0'
21
24
  playAppUpdateKtxVersion = '2.1.0'
22
- playReviewVersion = '2.0.1'
23
- playReviewKtxVersion = '2.0.1'
24
- okhttpVersion = '4.12.0'
25
+ playReviewVersion = '2.0.2'
26
+ playReviewKtxVersion = '2.0.2'
27
+ okhttpVersion = '5.4.0'
25
28
  }
26
29
 
27
30
  apply plugin: 'com.android.library'
28
31
  apply plugin: 'kotlin-android'
29
32
 
30
33
  android {
31
- namespace "com.aoneahsan.nativeupdate"
32
- compileSdkVersion project.compileSdkVersion
34
+ namespace = "com.aoneahsan.nativeupdate"
35
+ compileSdk = project.compileSdkVersion
33
36
 
34
37
  defaultConfig {
35
38
  minSdkVersion project.minSdkVersion
@@ -52,16 +55,20 @@ android {
52
55
  }
53
56
 
54
57
  lint {
55
- abortOnError false
58
+ abortOnError = true
59
+ warningsAsErrors = true
60
+ // Capacitor 8 consumers are still on AGP 8; AGP 9 is a deliberate v5 migration.
61
+ // KTX preference hints are style-only and do not affect correctness.
62
+ disable += ['AndroidGradlePluginVersion', 'GradleDependency', 'NewerVersionAvailable', 'UseKtx']
56
63
  }
57
64
 
58
65
  compileOptions {
59
- sourceCompatibility JavaVersion.VERSION_17
60
- targetCompatibility JavaVersion.VERSION_17
66
+ sourceCompatibility JavaVersion.VERSION_21
67
+ targetCompatibility JavaVersion.VERSION_21
61
68
  }
62
69
 
63
70
  kotlinOptions {
64
- jvmTarget = '17'
71
+ jvmTarget = '21'
65
72
  }
66
73
 
67
74
  testOptions {
@@ -82,9 +89,9 @@ dependencies {
82
89
  implementation project(':capacitor-android')
83
90
 
84
91
  // Kotlin
85
- implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22'
86
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
87
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.7.3'
92
+ implementation 'org.jetbrains.kotlin:kotlin-stdlib:2.2.20'
93
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.11.0'
94
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.11.0'
88
95
 
89
96
  // AndroidX
90
97
  implementation "androidx.appcompat:appcompat:${androidxAppCompatVersion}"
@@ -94,26 +101,23 @@ dependencies {
94
101
  // Google Play Services - Using explicit versions to avoid resolution issues
95
102
  implementation 'com.google.android.play:app-update:2.1.0'
96
103
  implementation 'com.google.android.play:app-update-ktx:2.1.0'
97
- implementation 'com.google.android.play:review:2.0.1'
98
- implementation 'com.google.android.play:review-ktx:2.0.1'
104
+ implementation "com.google.android.play:review:${playReviewVersion}"
105
+ implementation "com.google.android.play:review-ktx:${playReviewKtxVersion}"
99
106
 
100
107
  // OkHttp for secure network requests
101
108
  implementation "com.squareup.okhttp3:okhttp:${okhttpVersion}"
102
109
  implementation "com.squareup.okhttp3:okhttp-tls:${okhttpVersion}"
103
110
 
104
- // Security
105
- implementation 'androidx.security:security-crypto:1.1.0-alpha06'
106
-
107
111
  // JSON parsing
108
- implementation 'com.google.code.gson:gson:2.10.1'
112
+ implementation 'com.google.code.gson:gson:2.14.0'
109
113
 
110
114
  // Testing
111
115
  testImplementation 'junit:junit:4.13.2'
112
- testImplementation 'org.mockito:mockito-core:5.8.0'
113
- testImplementation 'org.mockito.kotlin:mockito-kotlin:5.2.1'
114
- testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
115
- testImplementation 'com.google.truth:truth:1.1.5'
116
- testImplementation 'org.robolectric:robolectric:4.11.1'
117
- androidTestImplementation 'androidx.test.ext:junit:1.1.5'
118
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
119
- }
116
+ testImplementation 'org.mockito:mockito-core:5.23.0'
117
+ testImplementation 'org.mockito.kotlin:mockito-kotlin:6.3.0'
118
+ testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0'
119
+ testImplementation 'com.google.truth:truth:1.4.5'
120
+ testImplementation 'org.robolectric:robolectric:4.16.1'
121
+ androidTestImplementation 'androidx.test.ext:junit:1.3.0'
122
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
123
+ }
@@ -1,8 +1,8 @@
1
1
  # Gradle Wrapper Properties
2
2
  distributionBase=GRADLE_USER_HOME
3
3
  distributionPath=wrapper/dists
4
- distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
4
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.5-all.zip
5
5
  networkTimeout=10000
6
6
  validateDistributionUrl=true
7
7
  zipStoreBase=GRADLE_USER_HOME
8
- zipStorePath=wrapper/dists
8
+ zipStorePath=wrapper/dists
@@ -24,6 +24,3 @@
24
24
 
25
25
  # Google Play Services
26
26
  -keep class com.google.android.play.** { *; }
27
-
28
- # Security Crypto
29
- -keep class androidx.security.crypto.** { *; }
@@ -3,6 +3,7 @@ package com.aoneahsan.nativeupdate
3
3
  import android.app.NotificationChannel
4
4
  import android.app.NotificationManager
5
5
  import android.app.PendingIntent
6
+ import android.annotation.SuppressLint
6
7
  import android.content.Context
7
8
  import android.content.Intent
8
9
  import android.content.pm.PackageManager
@@ -15,7 +16,7 @@ import com.getcapacitor.Plugin
15
16
 
16
17
  class BackgroundNotificationManager(
17
18
  private val context: Context,
18
- private val plugin: BackgroundUpdatePlugin
19
+ private val eventListener: (String, JSObject) -> Unit
19
20
  ) {
20
21
 
21
22
  companion object {
@@ -41,47 +42,43 @@ class BackgroundNotificationManager(
41
42
  private var preferences: NotificationPreferences = NotificationPreferences.default()
42
43
 
43
44
  fun createNotificationChannel() {
44
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
45
- val channel = NotificationChannel(
46
- CHANNEL_ID,
47
- CHANNEL_NAME,
48
- NotificationManager.IMPORTANCE_DEFAULT
49
- ).apply {
50
- description = "Notifications for app updates"
51
- enableLights(true)
52
- enableVibration(true)
53
- }
54
-
55
- val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
56
- notificationManager.createNotificationChannel(channel)
45
+ val channel = NotificationChannel(
46
+ CHANNEL_ID,
47
+ CHANNEL_NAME,
48
+ NotificationManager.IMPORTANCE_DEFAULT
49
+ ).apply {
50
+ description = "Notifications for app updates"
51
+ enableLights(true)
52
+ enableVibration(true)
57
53
  }
54
+
55
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
56
+ notificationManager.createNotificationChannel(channel)
58
57
  }
59
58
 
60
59
  fun setPreferences(preferencesData: JSObject) {
61
60
  preferences = NotificationPreferences.fromJSObject(preferencesData)
62
61
 
63
62
  // Update channel if preferences changed
64
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
65
- val channelId = preferences.channelId ?: CHANNEL_ID
66
- val channelName = preferences.channelName ?: CHANNEL_NAME
67
-
68
- val channel = NotificationChannel(
69
- channelId,
70
- channelName,
71
- getNotificationImportance(preferences.priority)
72
- ).apply {
73
- description = "Notifications for app updates"
74
- enableLights(true)
75
- enableVibration(preferences.vibrationEnabled)
76
-
77
- if (!preferences.soundEnabled) {
78
- setSound(null, null)
79
- }
63
+ val channelId = preferences.channelId ?: CHANNEL_ID
64
+ val channelName = preferences.channelName ?: CHANNEL_NAME
65
+
66
+ val channel = NotificationChannel(
67
+ channelId,
68
+ channelName,
69
+ getNotificationImportance(preferences.priority)
70
+ ).apply {
71
+ description = "Notifications for app updates"
72
+ enableLights(true)
73
+ enableVibration(preferences.vibrationEnabled)
74
+
75
+ if (!preferences.soundEnabled) {
76
+ setSound(null, null)
80
77
  }
81
-
82
- val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
83
- notificationManager.createNotificationChannel(channel)
84
78
  }
79
+
80
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
81
+ notificationManager.createNotificationChannel(channel)
85
82
  }
86
83
 
87
84
  fun getPermissionStatus(): NotificationPermissionStatus {
@@ -108,12 +105,16 @@ class BackgroundNotificationManager(
108
105
  return true
109
106
  }
110
107
 
108
+ @SuppressLint("MissingPermission")
111
109
  fun sendUpdateNotification(
112
110
  appUpdate: AppUpdateStatus?,
113
111
  liveUpdate: LatestVersion?
114
112
  ): Boolean {
115
- val permissionStatus = getPermissionStatus()
116
- if (!permissionStatus.granted) {
113
+ if (!getPermissionStatus().granted ||
114
+ (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
115
+ ContextCompat.checkSelfPermission(context, android.Manifest.permission.POST_NOTIFICATIONS) !=
116
+ PackageManager.PERMISSION_GRANTED)
117
+ ) {
117
118
  return false
118
119
  }
119
120
 
@@ -130,11 +131,10 @@ class BackgroundNotificationManager(
130
131
  eventData.put("version", appUpdate?.availableVersion ?: liveUpdate?.version ?: "unknown")
131
132
  eventData.put("action", "shown")
132
133
 
133
- plugin.notifyBackgroundUpdateListeners("backgroundUpdateNotification", eventData)
134
+ eventListener("backgroundUpdateNotification", eventData)
134
135
 
135
136
  return true
136
- } catch (e: Exception) {
137
- android.util.Log.e("BackgroundNotificationManager", "Failed to send notification", e)
137
+ } catch (_: SecurityException) {
138
138
  return false
139
139
  }
140
140
  }
@@ -227,16 +227,12 @@ class BackgroundNotificationManager(
227
227
  }
228
228
 
229
229
  private fun getNotificationImportance(priority: NotificationPriority): Int {
230
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
231
- when (priority) {
232
- NotificationPriority.MIN -> NotificationManager.IMPORTANCE_MIN
233
- NotificationPriority.LOW -> NotificationManager.IMPORTANCE_LOW
234
- NotificationPriority.DEFAULT -> NotificationManager.IMPORTANCE_DEFAULT
235
- NotificationPriority.HIGH -> NotificationManager.IMPORTANCE_HIGH
236
- NotificationPriority.MAX -> NotificationManager.IMPORTANCE_MAX
237
- }
238
- } else {
239
- NotificationManager.IMPORTANCE_DEFAULT
230
+ return when (priority) {
231
+ NotificationPriority.MIN -> NotificationManager.IMPORTANCE_MIN
232
+ NotificationPriority.LOW -> NotificationManager.IMPORTANCE_LOW
233
+ NotificationPriority.DEFAULT -> NotificationManager.IMPORTANCE_DEFAULT
234
+ NotificationPriority.HIGH -> NotificationManager.IMPORTANCE_HIGH
235
+ NotificationPriority.MAX -> NotificationManager.IMPORTANCE_MAX
240
236
  }
241
237
  }
242
238
 
@@ -407,4 +403,4 @@ data class NotificationPermissionStatus(
407
403
  shouldShowRationale?.let { obj.put("shouldShowRationale", it) }
408
404
  return obj
409
405
  }
410
- }
406
+ }
@@ -1,41 +1,43 @@
1
1
  package com.aoneahsan.nativeupdate
2
2
 
3
+ import java.lang.ref.WeakReference
4
+
3
5
  /**
4
6
  * Singleton manager to maintain references to plugin instances
5
7
  * This allows background workers to access plugin functionality
6
8
  */
7
9
  object BackgroundUpdateManager {
8
10
  @Volatile
9
- private var backgroundUpdatePlugin: BackgroundUpdatePlugin? = null
11
+ private var backgroundUpdatePlugin: WeakReference<BackgroundUpdatePlugin>? = null
10
12
 
11
13
  @Volatile
12
- private var liveUpdatePlugin: LiveUpdatePlugin? = null
14
+ private var liveUpdatePlugin: WeakReference<LiveUpdatePlugin>? = null
13
15
 
14
16
  @Volatile
15
- private var appUpdatePlugin: AppUpdatePlugin? = null
17
+ private var appUpdatePlugin: WeakReference<AppUpdatePlugin>? = null
16
18
 
17
19
  fun registerBackgroundUpdatePlugin(plugin: BackgroundUpdatePlugin) {
18
- backgroundUpdatePlugin = plugin
20
+ backgroundUpdatePlugin = WeakReference(plugin)
19
21
  }
20
22
 
21
23
  fun registerLiveUpdatePlugin(plugin: LiveUpdatePlugin) {
22
- liveUpdatePlugin = plugin
24
+ liveUpdatePlugin = WeakReference(plugin)
23
25
  }
24
26
 
25
27
  fun registerAppUpdatePlugin(plugin: AppUpdatePlugin) {
26
- appUpdatePlugin = plugin
28
+ appUpdatePlugin = WeakReference(plugin)
27
29
  }
28
30
 
29
31
  fun getBackgroundUpdatePlugin(): BackgroundUpdatePlugin? {
30
- return backgroundUpdatePlugin
32
+ return backgroundUpdatePlugin?.get()
31
33
  }
32
34
 
33
35
  fun getLiveUpdatePlugin(): LiveUpdatePlugin? {
34
- return liveUpdatePlugin
36
+ return liveUpdatePlugin?.get()
35
37
  }
36
38
 
37
39
  fun getAppUpdatePlugin(): AppUpdatePlugin? {
38
- return appUpdatePlugin
40
+ return appUpdatePlugin?.get()
39
41
  }
40
42
 
41
43
  fun clear() {
@@ -43,4 +45,4 @@ object BackgroundUpdateManager {
43
45
  liveUpdatePlugin = null
44
46
  appUpdatePlugin = null
45
47
  }
46
- }
48
+ }