native-update-capacitor 0.0.0-stage → 4.3.0
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/AI-INTEGRATION-GUIDE.md +578 -0
- package/LICENSE +25 -0
- package/NativeUpdate.podspec +19 -0
- package/README.md +574 -2
- package/android/build.gradle +125 -0
- package/android/consumer-rules.pro +9 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/android/gradle.properties +17 -0
- package/android/manifest-additions.xml +28 -0
- package/android/proguard-rules.pro +26 -0
- package/android/settings.gradle +2 -0
- package/android/src/main/AndroidManifest.xml +13 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +159 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +314 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +406 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +48 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +343 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +236 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/JsonOptional.kt +26 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1249 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +404 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +107 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +240 -0
- package/android/variables.gradle +5 -0
- package/cli/commands/backend-create.js +623 -0
- package/cli/commands/bundle-create.js +145 -0
- package/cli/commands/bundle-sign.js +64 -0
- package/cli/commands/bundle-verify.js +58 -0
- package/cli/commands/init.js +146 -0
- package/cli/commands/keys-generate.js +58 -0
- package/cli/commands/monitor.js +89 -0
- package/cli/commands/remote-shared.js +262 -0
- package/cli/commands/remote.js +622 -0
- package/cli/commands/server-start.js +96 -0
- package/cli/index.js +605 -0
- package/cli/package.json +21 -0
- package/dist/esm/app-review/app-review-manager.d.ts +24 -0
- package/dist/esm/app-review/app-review-manager.js +194 -0
- package/dist/esm/app-review/index.d.ts +5 -0
- package/dist/esm/app-review/index.js +5 -0
- package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
- package/dist/esm/app-review/platform-review-handler.js +137 -0
- package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
- package/dist/esm/app-review/review-conditions-checker.js +154 -0
- package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
- package/dist/esm/app-review/review-rate-limiter.js +163 -0
- package/dist/esm/app-review/types.d.ts +41 -0
- package/dist/esm/app-review/types.js +1 -0
- package/dist/esm/app-update/app-update-checker.d.ts +58 -0
- package/dist/esm/app-update/app-update-checker.js +227 -0
- package/dist/esm/app-update/app-update-installer.d.ts +20 -0
- package/dist/esm/app-update/app-update-installer.js +134 -0
- package/dist/esm/app-update/app-update-manager.d.ts +28 -0
- package/dist/esm/app-update/app-update-manager.js +198 -0
- package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
- package/dist/esm/app-update/app-update-notifier.js +99 -0
- package/dist/esm/app-update/index.d.ts +6 -0
- package/dist/esm/app-update/index.js +6 -0
- package/dist/esm/app-update/platform-app-update.d.ts +19 -0
- package/dist/esm/app-update/platform-app-update.js +138 -0
- package/dist/esm/app-update/types.d.ts +58 -0
- package/dist/esm/app-update/types.js +11 -0
- package/dist/esm/background-update/background-scheduler.d.ts +63 -0
- package/dist/esm/background-update/background-scheduler.js +332 -0
- package/dist/esm/background-update/index.d.ts +3 -0
- package/dist/esm/background-update/index.js +2 -0
- package/dist/esm/background-update/notification-manager.d.ts +29 -0
- package/dist/esm/background-update/notification-manager.js +88 -0
- package/dist/esm/config/support.d.ts +9 -0
- package/dist/esm/config/support.js +9 -0
- package/dist/esm/core/analytics.d.ts +83 -0
- package/dist/esm/core/analytics.js +151 -0
- package/dist/esm/core/cache-manager.d.ts +72 -0
- package/dist/esm/core/cache-manager.js +274 -0
- package/dist/esm/core/config.d.ts +69 -0
- package/dist/esm/core/config.js +107 -0
- package/dist/esm/core/errors.d.ts +56 -0
- package/dist/esm/core/errors.js +85 -0
- package/dist/esm/core/event-emitter.d.ts +30 -0
- package/dist/esm/core/event-emitter.js +80 -0
- package/dist/esm/core/logger.d.ts +21 -0
- package/dist/esm/core/logger.js +108 -0
- package/dist/esm/core/performance.d.ts +53 -0
- package/dist/esm/core/performance.js +153 -0
- package/dist/esm/core/plugin-manager.d.ts +88 -0
- package/dist/esm/core/plugin-manager.js +224 -0
- package/dist/esm/core/security.d.ts +123 -0
- package/dist/esm/core/security.js +361 -0
- package/dist/esm/core/update-check.d.ts +121 -0
- package/dist/esm/core/update-check.js +127 -0
- package/dist/esm/definitions.d.ts +872 -0
- package/dist/esm/definitions.js +104 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/live-update/bundle-manager.d.ts +102 -0
- package/dist/esm/live-update/bundle-manager.js +344 -0
- package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
- package/dist/esm/live-update/certificate-pinning.js +77 -0
- package/dist/esm/live-update/delta-processor.d.ts +84 -0
- package/dist/esm/live-update/delta-processor.js +257 -0
- package/dist/esm/live-update/download-manager.d.ts +106 -0
- package/dist/esm/live-update/download-manager.js +412 -0
- package/dist/esm/live-update/rollout-checker.d.ts +86 -0
- package/dist/esm/live-update/rollout-checker.js +304 -0
- package/dist/esm/live-update/update-manager.d.ts +63 -0
- package/dist/esm/live-update/update-manager.js +321 -0
- package/dist/esm/live-update/version-manager.d.ts +93 -0
- package/dist/esm/live-update/version-manager.js +390 -0
- package/dist/esm/plugin.d.ts +3 -0
- package/dist/esm/plugin.js +848 -0
- package/dist/esm/security/crypto.d.ts +88 -0
- package/dist/esm/security/crypto.js +228 -0
- package/dist/esm/security/validator.d.ts +60 -0
- package/dist/esm/security/validator.js +142 -0
- package/dist/esm/types/app-identity.d.ts +36 -0
- package/dist/esm/types/app-identity.js +1 -0
- package/dist/esm/types/rollout.d.ts +91 -0
- package/dist/esm/types/rollout.js +25 -0
- package/dist/esm/web.d.ts +130 -0
- package/dist/esm/web.js +981 -0
- package/dist/plugin.cjs +1 -0
- package/dist/plugin.esm.js +1 -0
- package/dist/plugin.js +2 -0
- package/docs/CHANGELOG.md +993 -0
- package/docs/KNOWN_LIMITATIONS.md +235 -0
- package/docs/MIGRATION.md +391 -0
- package/docs/protocol/CLIENT-PROTOCOL.md +178 -0
- package/docs/server-requirements.md +211 -0
- package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
- package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +249 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +333 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +464 -0
- package/ios/Plugin/Info.plist +43 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1286 -0
- package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
- package/ios/Plugin/NativeUpdatePlugin.m +53 -0
- package/ios/Plugin/NativeUpdatePlugin.swift +315 -0
- package/ios/Plugin/Security/SecurityManager.swift +289 -0
- package/package.json +135 -4
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
package com.aoneahsan.nativeupdate
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject
|
|
4
|
+
import com.getcapacitor.Plugin
|
|
5
|
+
import com.getcapacitor.PluginCall
|
|
6
|
+
import com.getcapacitor.PluginMethod
|
|
7
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
8
|
+
|
|
9
|
+
// Plugin writes only to context.filesDir (the app sandbox), so it does
|
|
10
|
+
// not need WRITE_EXTERNAL_STORAGE. Declaring an unused dangerous
|
|
11
|
+
// permission is a Play Store rejection trap.
|
|
12
|
+
@CapacitorPlugin(name = "NativeUpdate")
|
|
13
|
+
class NativeUpdatePlugin : Plugin() {
|
|
14
|
+
|
|
15
|
+
private lateinit var liveUpdatePlugin: LiveUpdatePlugin
|
|
16
|
+
private lateinit var appUpdatePlugin: AppUpdatePlugin
|
|
17
|
+
private lateinit var appReviewPlugin: AppReviewPlugin
|
|
18
|
+
private lateinit var backgroundUpdatePlugin: BackgroundUpdatePlugin
|
|
19
|
+
private lateinit var securityManager: SecurityManager
|
|
20
|
+
private var isInitialized = false
|
|
21
|
+
|
|
22
|
+
/** The configuration that took the lock, so an identical repeat can be told apart from a change (ISSUE-16). */
|
|
23
|
+
private var appliedConfiguration: String? = null
|
|
24
|
+
|
|
25
|
+
override fun load() {
|
|
26
|
+
super.load()
|
|
27
|
+
|
|
28
|
+
// Initialize sub-plugins
|
|
29
|
+
liveUpdatePlugin = LiveUpdatePlugin(activity, context)
|
|
30
|
+
appUpdatePlugin = AppUpdatePlugin(activity, context)
|
|
31
|
+
appReviewPlugin = AppReviewPlugin(activity, context)
|
|
32
|
+
backgroundUpdatePlugin = BackgroundUpdatePlugin(context)
|
|
33
|
+
securityManager = SecurityManager(context)
|
|
34
|
+
|
|
35
|
+
// Set up app update event listener
|
|
36
|
+
appUpdatePlugin.setEventListener { eventName, data ->
|
|
37
|
+
notifyListeners(eventName, data)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Register plugins with manager for background access
|
|
41
|
+
BackgroundUpdateManager.registerLiveUpdatePlugin(liveUpdatePlugin)
|
|
42
|
+
BackgroundUpdateManager.registerAppUpdatePlugin(appUpdatePlugin)
|
|
43
|
+
|
|
44
|
+
// Set up listeners
|
|
45
|
+
liveUpdatePlugin.setProgressListener { progress ->
|
|
46
|
+
notifyListeners("downloadProgress", progress)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
liveUpdatePlugin.setStateChangeListener { state ->
|
|
50
|
+
notifyListeners("updateStateChanged", state)
|
|
51
|
+
}
|
|
52
|
+
backgroundUpdatePlugin.setEventListener { event, data ->
|
|
53
|
+
notifyListeners(event, data)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Wire the WebView retargeting hook. set() calls this with the
|
|
57
|
+
// extracted bundle's www/ path; we pass it to the Capacitor
|
|
58
|
+
// Bridge so subsequent loads serve the new bundle.
|
|
59
|
+
liveUpdatePlugin.setWebViewPathListener { path ->
|
|
60
|
+
bridge?.setServerBasePath(path)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Boot-time integrity re-verify + crash-loop auto-rollback. Runs
|
|
64
|
+
// before any host-app code touches the WebView so a tampered or
|
|
65
|
+
// crash-looping bundle never gets a chance to load.
|
|
66
|
+
try {
|
|
67
|
+
liveUpdatePlugin.verifyActiveBundleOnBoot()
|
|
68
|
+
} catch (e: Exception) {
|
|
69
|
+
// Never let boot verification crash the plugin itself — fall
|
|
70
|
+
// through and let a later sync() surface the problem.
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Re-apply the active bundle's path so the WebView serves the
|
|
74
|
+
// last-set OTA bundle on cold start (otherwise process death
|
|
75
|
+
// would silently revert to the bundled-in www/).
|
|
76
|
+
try {
|
|
77
|
+
liveUpdatePlugin.applyActiveBundlePathIfPresent()
|
|
78
|
+
} catch (e: Exception) {
|
|
79
|
+
// Same rationale as above.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@PluginMethod
|
|
84
|
+
fun initialize(call: PluginCall) {
|
|
85
|
+
try {
|
|
86
|
+
val config = call.getObject("config") ?: call.data
|
|
87
|
+
if (isInitialized) {
|
|
88
|
+
rejectUnlessSameConfiguration(call, config)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
applyConfiguration(config)
|
|
92
|
+
appliedConfiguration = configurationFingerprint(config)
|
|
93
|
+
isInitialized = true
|
|
94
|
+
call.resolve()
|
|
95
|
+
} catch (e: Exception) {
|
|
96
|
+
call.reject("Initialization failed", e)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@PluginMethod
|
|
101
|
+
fun isInitialized(call: PluginCall) {
|
|
102
|
+
call.resolve(JSObject().put("initialized", isInitialized))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@PluginMethod
|
|
106
|
+
fun cleanup(call: PluginCall) {
|
|
107
|
+
try {
|
|
108
|
+
// Clean up any resources
|
|
109
|
+
liveUpdatePlugin.cleanup()
|
|
110
|
+
backgroundUpdatePlugin.cancelAllBackgroundWork()
|
|
111
|
+
call.resolve()
|
|
112
|
+
} catch (e: Exception) {
|
|
113
|
+
call.reject("Cleanup failed", e)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@PluginMethod
|
|
118
|
+
fun configure(call: PluginCall) {
|
|
119
|
+
// Accept BOTH documented shapes (v3.1.3):
|
|
120
|
+
// configure({ config: PluginInitConfig }) — wrapped
|
|
121
|
+
// initialize(PluginInitConfig) — flat (top-level keys)
|
|
122
|
+
// configure(UpdateConfig) — nested sections
|
|
123
|
+
// Before this fix, only the wrapped shape reached native, so the
|
|
124
|
+
// flat initialize() every consumer uses configured NOTHING here.
|
|
125
|
+
val config = call.getObject("config") ?: call.data
|
|
126
|
+
if (isInitialized) {
|
|
127
|
+
rejectUnlessSameConfiguration(call, config)
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
applyConfiguration(config)
|
|
133
|
+
appliedConfiguration = configurationFingerprint(config)
|
|
134
|
+
isInitialized = true
|
|
135
|
+
call.resolve()
|
|
136
|
+
} catch (e: Exception) {
|
|
137
|
+
call.reject("Configuration failed", e)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The lock refuses a CHANGED configuration only. An OTA apply reloads the WebView while this plugin instance
|
|
143
|
+
* lives on, so the new bundle's boot sends the same configure() again; rejecting it switched OTA off in every
|
|
144
|
+
* freshly applied bundle and skipped its notifyAppReady() (ISSUE-16).
|
|
145
|
+
*/
|
|
146
|
+
private fun rejectUnlessSameConfiguration(call: PluginCall, config: JSObject) {
|
|
147
|
+
if (configurationFingerprint(config) == appliedConfiguration) {
|
|
148
|
+
call.resolve()
|
|
149
|
+
} else {
|
|
150
|
+
call.reject("Configuration is locked after initialization; call reset() first")
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** A stable comparison form; injected JS objects (filesystem, preferences) arrive as {} and compare equal. */
|
|
155
|
+
private fun configurationFingerprint(config: JSObject): String = config.toString()
|
|
156
|
+
|
|
157
|
+
private fun applyConfiguration(config: JSObject) {
|
|
158
|
+
securityManager.configure(config)
|
|
159
|
+
normalizeLiveUpdateConfig(config)?.let(liveUpdatePlugin::configure)
|
|
160
|
+
config.getJSObject("appUpdate")?.let(appUpdatePlugin::configure)
|
|
161
|
+
config.getJSObject("appReview")?.let(appReviewPlugin::configure)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Normalize a flat PluginInitConfig (serverUrl/baseUrl, apiKey, appId,
|
|
166
|
+
* channel, publicKey at the top level) into the liveUpdate config shape
|
|
167
|
+
* the sub-plugin reads. Returns null when the payload carries no
|
|
168
|
+
* live-update fields at all.
|
|
169
|
+
*/
|
|
170
|
+
private fun buildFlatLiveUpdateConfig(config: JSObject): JSObject? {
|
|
171
|
+
val serverUrl = config.getString("serverUrl") ?: config.getString("baseUrl")
|
|
172
|
+
val apiKey = config.getString("apiKey")
|
|
173
|
+
if (serverUrl == null && apiKey == null) {
|
|
174
|
+
return null
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
val liveUpdate = JSObject()
|
|
178
|
+
serverUrl?.let { liveUpdate.put("serverUrl", it) }
|
|
179
|
+
apiKey?.let { liveUpdate.put("apiKey", it) }
|
|
180
|
+
config.getString("appId")?.let { liveUpdate.put("appId", it) }
|
|
181
|
+
config.getString("channel")?.let { liveUpdate.put("channel", it) }
|
|
182
|
+
config.getString("publicKey")?.let { liveUpdate.put("publicKey", it) }
|
|
183
|
+
config.getBool("requireSignature")?.let { liveUpdate.put("requireSignature", it) }
|
|
184
|
+
config.getBool("allowUnsignedDevelopmentUpdates")?.let {
|
|
185
|
+
liveUpdate.put("allowUnsignedDevelopmentUpdates", it)
|
|
186
|
+
}
|
|
187
|
+
config.getString("checksumAlgorithm")?.let { liveUpdate.put("checksumAlgorithm", it) }
|
|
188
|
+
config.longOrNull("maxBundleSize")?.let { liveUpdate.put("maxBundleSize", it) }
|
|
189
|
+
config.longOrNull("maxUncompressedBundleSize")?.let {
|
|
190
|
+
liveUpdate.put("maxUncompressedBundleSize", it)
|
|
191
|
+
}
|
|
192
|
+
config.getBool("enableDeltaUpdates")?.let { liveUpdate.put("enableDeltaUpdates", it) }
|
|
193
|
+
config.arrayOrNull("allowedHosts")?.let { liveUpdate.put("allowedHosts", it) }
|
|
194
|
+
config.getJSObject("security")?.let { liveUpdate.put("security", it) }
|
|
195
|
+
return liveUpdate
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Merge root security controls into both documented configuration shapes. */
|
|
199
|
+
private fun normalizeLiveUpdateConfig(config: JSObject): JSObject? {
|
|
200
|
+
val liveUpdate = config.getJSObject("liveUpdate") ?: buildFlatLiveUpdateConfig(config) ?: return null
|
|
201
|
+
if (!liveUpdate.has("security")) {
|
|
202
|
+
config.getJSObject("security")?.let { liveUpdate.put("security", it) }
|
|
203
|
+
}
|
|
204
|
+
if (!liveUpdate.has("publicKey")) {
|
|
205
|
+
config.getString("publicKey")?.let { liveUpdate.put("publicKey", it) }
|
|
206
|
+
}
|
|
207
|
+
if (!liveUpdate.has("requireSignature")) {
|
|
208
|
+
config.getBool("requireSignature")?.let { liveUpdate.put("requireSignature", it) }
|
|
209
|
+
}
|
|
210
|
+
if (!liveUpdate.has("allowUnsignedDevelopmentUpdates")) {
|
|
211
|
+
config.getBool("allowUnsignedDevelopmentUpdates")?.let {
|
|
212
|
+
liveUpdate.put("allowUnsignedDevelopmentUpdates", it)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (!liveUpdate.has("maxUncompressedBundleSize")) {
|
|
216
|
+
config.longOrNull("maxUncompressedBundleSize")?.let {
|
|
217
|
+
liveUpdate.put("maxUncompressedBundleSize", it)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (!liveUpdate.has("enableDeltaUpdates")) {
|
|
221
|
+
config.getBool("enableDeltaUpdates")?.let { liveUpdate.put("enableDeltaUpdates", it) }
|
|
222
|
+
}
|
|
223
|
+
return liveUpdate
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@PluginMethod
|
|
227
|
+
fun getSecurityInfo(call: PluginCall) {
|
|
228
|
+
call.resolve(securityManager.getSecurityInfo())
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Live Update Methods
|
|
232
|
+
|
|
233
|
+
@PluginMethod
|
|
234
|
+
fun sync(call: PluginCall) {
|
|
235
|
+
liveUpdatePlugin.sync(call)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@PluginMethod
|
|
239
|
+
fun download(call: PluginCall) {
|
|
240
|
+
// No runtime permission required — bundle storage is in app sandbox.
|
|
241
|
+
liveUpdatePlugin.download(call)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@PluginMethod
|
|
245
|
+
fun set(call: PluginCall) {
|
|
246
|
+
liveUpdatePlugin.set(call)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
@PluginMethod
|
|
250
|
+
fun reload(call: PluginCall) {
|
|
251
|
+
liveUpdatePlugin.reload(call)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
@PluginMethod
|
|
255
|
+
fun reset(call: PluginCall) {
|
|
256
|
+
try {
|
|
257
|
+
// Reset plugin state
|
|
258
|
+
liveUpdatePlugin.reset(call)
|
|
259
|
+
isInitialized = false
|
|
260
|
+
appliedConfiguration = null
|
|
261
|
+
} catch (e: Exception) {
|
|
262
|
+
call.reject("Reset failed", e)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
@PluginMethod
|
|
267
|
+
fun current(call: PluginCall) {
|
|
268
|
+
liveUpdatePlugin.current(call)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@PluginMethod
|
|
272
|
+
fun list(call: PluginCall) {
|
|
273
|
+
liveUpdatePlugin.list(call)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
@PluginMethod
|
|
277
|
+
fun delete(call: PluginCall) {
|
|
278
|
+
liveUpdatePlugin.delete(call)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@PluginMethod
|
|
282
|
+
fun notifyAppReady(call: PluginCall) {
|
|
283
|
+
liveUpdatePlugin.notifyAppReady(call)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
@PluginMethod
|
|
287
|
+
fun getLatest(call: PluginCall) {
|
|
288
|
+
liveUpdatePlugin.getLatest(call)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
@PluginMethod
|
|
292
|
+
fun getAppIdentity(call: PluginCall) {
|
|
293
|
+
liveUpdatePlugin.getAppIdentity(call)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
@PluginMethod
|
|
297
|
+
fun setChannel(call: PluginCall) {
|
|
298
|
+
liveUpdatePlugin.setChannel(call)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@PluginMethod
|
|
302
|
+
fun setUpdateUrl(call: PluginCall) {
|
|
303
|
+
liveUpdatePlugin.setUpdateUrl(call)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@PluginMethod
|
|
307
|
+
fun validateUpdate(call: PluginCall) {
|
|
308
|
+
liveUpdatePlugin.validateUpdate(call)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@PluginMethod
|
|
312
|
+
fun cancelDownload(call: PluginCall) = liveUpdatePlugin.cancelDownload(call)
|
|
313
|
+
|
|
314
|
+
@PluginMethod
|
|
315
|
+
fun cancelAllDownloads(call: PluginCall) = liveUpdatePlugin.cancelAllDownloads(call)
|
|
316
|
+
|
|
317
|
+
@PluginMethod
|
|
318
|
+
fun isDownloading(call: PluginCall) = liveUpdatePlugin.isDownloading(call)
|
|
319
|
+
|
|
320
|
+
@PluginMethod
|
|
321
|
+
fun getActiveDownloadCount(call: PluginCall) = liveUpdatePlugin.getActiveDownloadCount(call)
|
|
322
|
+
|
|
323
|
+
// App Update Methods
|
|
324
|
+
|
|
325
|
+
@PluginMethod
|
|
326
|
+
fun getAppUpdateInfo(call: PluginCall) {
|
|
327
|
+
appUpdatePlugin.getAppUpdateInfo(call)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
@PluginMethod
|
|
331
|
+
fun performImmediateUpdate(call: PluginCall) {
|
|
332
|
+
appUpdatePlugin.performImmediateUpdate(call)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
@PluginMethod
|
|
336
|
+
fun startFlexibleUpdate(call: PluginCall) {
|
|
337
|
+
appUpdatePlugin.startFlexibleUpdate(call)
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
@PluginMethod
|
|
341
|
+
fun completeFlexibleUpdate(call: PluginCall) {
|
|
342
|
+
appUpdatePlugin.completeFlexibleUpdate(call)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
@PluginMethod
|
|
346
|
+
fun openAppStore(call: PluginCall) {
|
|
347
|
+
appUpdatePlugin.openAppStore(call)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// App Review Methods
|
|
351
|
+
|
|
352
|
+
@PluginMethod
|
|
353
|
+
fun requestReview(call: PluginCall) {
|
|
354
|
+
appReviewPlugin.requestReview(call)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
@PluginMethod
|
|
358
|
+
fun canRequestReview(call: PluginCall) {
|
|
359
|
+
appReviewPlugin.canRequestReview(call)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Background Update Methods
|
|
363
|
+
|
|
364
|
+
@PluginMethod
|
|
365
|
+
fun enableBackgroundUpdates(call: PluginCall) {
|
|
366
|
+
backgroundUpdatePlugin.enableBackgroundUpdates(call)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
@PluginMethod
|
|
370
|
+
fun disableBackgroundUpdates(call: PluginCall) {
|
|
371
|
+
backgroundUpdatePlugin.disableBackgroundUpdates(call)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
@PluginMethod
|
|
375
|
+
fun getBackgroundUpdateStatus(call: PluginCall) {
|
|
376
|
+
backgroundUpdatePlugin.getBackgroundUpdateStatus(call)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
@PluginMethod
|
|
380
|
+
fun scheduleBackgroundCheck(call: PluginCall) {
|
|
381
|
+
backgroundUpdatePlugin.scheduleBackgroundCheck(call)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
@PluginMethod
|
|
385
|
+
fun triggerBackgroundCheck(call: PluginCall) {
|
|
386
|
+
backgroundUpdatePlugin.triggerBackgroundCheck(call)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
@PluginMethod
|
|
390
|
+
fun setNotificationPreferences(call: PluginCall) {
|
|
391
|
+
backgroundUpdatePlugin.setNotificationPreferences(call)
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
@PluginMethod
|
|
395
|
+
fun getNotificationPermissions(call: PluginCall) {
|
|
396
|
+
backgroundUpdatePlugin.getNotificationPermissions(call)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
@PluginMethod
|
|
400
|
+
fun requestNotificationPermissions(call: PluginCall) {
|
|
401
|
+
backgroundUpdatePlugin.requestNotificationPermissions(call)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
package com.aoneahsan.nativeupdate
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.content.Intent
|
|
6
|
+
import android.util.Log
|
|
7
|
+
import androidx.work.BackoffPolicy
|
|
8
|
+
import androidx.work.ExistingWorkPolicy
|
|
9
|
+
import androidx.work.OneTimeWorkRequestBuilder
|
|
10
|
+
import androidx.work.WorkManager
|
|
11
|
+
import androidx.work.workDataOf
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Handles notification actions for background updates
|
|
15
|
+
*/
|
|
16
|
+
class NotificationActionReceiver : BroadcastReceiver() {
|
|
17
|
+
|
|
18
|
+
companion object {
|
|
19
|
+
const val ACTION_INSTALL_NOW = "com.aoneahsan.nativeupdate.ACTION_INSTALL_NOW"
|
|
20
|
+
const val ACTION_INSTALL_LATER = "com.aoneahsan.nativeupdate.ACTION_INSTALL_LATER"
|
|
21
|
+
const val ACTION_DISMISS = "com.aoneahsan.nativeupdate.ACTION_DISMISS"
|
|
22
|
+
|
|
23
|
+
const val EXTRA_UPDATE_TYPE = "update_type"
|
|
24
|
+
const val EXTRA_BUNDLE_ID = "bundle_id"
|
|
25
|
+
const val EXTRA_VERSION = "version"
|
|
26
|
+
|
|
27
|
+
private const val TAG = "NotificationActionReceiver"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun onReceive(context: Context, intent: Intent) {
|
|
31
|
+
val action = intent.action ?: return
|
|
32
|
+
|
|
33
|
+
Log.d(TAG, "Received action: $action")
|
|
34
|
+
|
|
35
|
+
when (action) {
|
|
36
|
+
ACTION_INSTALL_NOW -> handleInstallNow(context, intent)
|
|
37
|
+
ACTION_INSTALL_LATER -> handleInstallLater(context, intent)
|
|
38
|
+
ACTION_DISMISS -> handleDismiss(context, intent)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Cancel the notification
|
|
42
|
+
BackgroundNotificationManager.cancelNotificationStatic(context)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private fun handleInstallNow(context: Context, intent: Intent) {
|
|
46
|
+
val updateType = intent.getStringExtra(EXTRA_UPDATE_TYPE) ?: return
|
|
47
|
+
|
|
48
|
+
when (updateType) {
|
|
49
|
+
"live_update" -> {
|
|
50
|
+
val bundleId = intent.getStringExtra(EXTRA_BUNDLE_ID) ?: return
|
|
51
|
+
// Trigger immediate installation through WorkManager.
|
|
52
|
+
// Exponential backoff keeps an ailing network or server
|
|
53
|
+
// from burning battery; matches the policy used by
|
|
54
|
+
// BackgroundUpdatePlugin.triggerBackgroundCheck.
|
|
55
|
+
val workRequest = OneTimeWorkRequestBuilder<BackgroundUpdateWorker>()
|
|
56
|
+
.setInputData(workDataOf(
|
|
57
|
+
"action" to "install_bundle",
|
|
58
|
+
"bundle_id" to bundleId
|
|
59
|
+
))
|
|
60
|
+
.setBackoffCriteria(
|
|
61
|
+
BackoffPolicy.EXPONENTIAL,
|
|
62
|
+
30,
|
|
63
|
+
java.util.concurrent.TimeUnit.SECONDS
|
|
64
|
+
)
|
|
65
|
+
.build()
|
|
66
|
+
|
|
67
|
+
WorkManager.getInstance(context).enqueueUniqueWork(
|
|
68
|
+
"install_update_$bundleId",
|
|
69
|
+
ExistingWorkPolicy.REPLACE,
|
|
70
|
+
workRequest
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
Log.d(TAG, "Scheduled immediate installation for bundle: $bundleId")
|
|
74
|
+
}
|
|
75
|
+
"app_update" -> {
|
|
76
|
+
// Open Play Store for app update
|
|
77
|
+
try {
|
|
78
|
+
val packageName = context.packageName
|
|
79
|
+
val playStoreIntent = Intent(Intent.ACTION_VIEW).apply {
|
|
80
|
+
data = android.net.Uri.parse("market://details?id=$packageName")
|
|
81
|
+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
82
|
+
}
|
|
83
|
+
context.startActivity(playStoreIntent)
|
|
84
|
+
} catch (e: Exception) {
|
|
85
|
+
Log.e(TAG, "Failed to open Play Store", e)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private fun handleInstallLater(context: Context, intent: Intent) {
|
|
92
|
+
// Store preference to install later
|
|
93
|
+
val prefs = context.getSharedPreferences("capacitor_native_update", Context.MODE_PRIVATE)
|
|
94
|
+
prefs.edit().apply {
|
|
95
|
+
putBoolean("pending_update", true)
|
|
96
|
+
putLong("deferred_until", System.currentTimeMillis() + 24 * 60 * 60 * 1000) // 24 hours
|
|
97
|
+
apply()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Log.d(TAG, "Update deferred for 24 hours")
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private fun handleDismiss(context: Context, intent: Intent) {
|
|
104
|
+
// Just dismiss the notification, already handled in onReceive
|
|
105
|
+
Log.d(TAG, "Update notification dismissed")
|
|
106
|
+
}
|
|
107
|
+
}
|