native-update-capacitor 0.0.0-stage → 4.4.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/flutter-patch.js +107 -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 +264 -0
- package/cli/commands/remote.js +634 -0
- package/cli/commands/server-start.js +96 -0
- package/cli/index.js +625 -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 +1016 -0
- package/docs/KNOWN_LIMITATIONS.md +240 -0
- package/docs/MIGRATION.md +391 -0
- package/docs/protocol/CLIENT-PROTOCOL.md +199 -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 +133 -4
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
package com.aoneahsan.nativeupdate
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.content.Intent
|
|
6
|
+
import android.net.Uri
|
|
7
|
+
import com.getcapacitor.JSObject
|
|
8
|
+
import com.getcapacitor.PluginCall
|
|
9
|
+
import com.google.android.play.core.appupdate.AppUpdateInfo
|
|
10
|
+
import com.google.android.play.core.appupdate.AppUpdateManager
|
|
11
|
+
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
|
|
12
|
+
import com.google.android.play.core.appupdate.AppUpdateOptions
|
|
13
|
+
import com.google.android.play.core.install.InstallState
|
|
14
|
+
import com.google.android.play.core.install.InstallStateUpdatedListener
|
|
15
|
+
import com.google.android.play.core.install.model.AppUpdateType
|
|
16
|
+
import com.google.android.play.core.install.model.InstallStatus
|
|
17
|
+
import com.google.android.play.core.install.model.UpdateAvailability
|
|
18
|
+
import com.google.android.play.core.ktx.isFlexibleUpdateAllowed
|
|
19
|
+
import com.google.android.play.core.ktx.isImmediateUpdateAllowed
|
|
20
|
+
import com.google.android.gms.tasks.Tasks
|
|
21
|
+
import kotlinx.coroutines.tasks.await
|
|
22
|
+
|
|
23
|
+
class AppUpdatePlugin(
|
|
24
|
+
private val activity: Activity,
|
|
25
|
+
private val context: Context
|
|
26
|
+
) {
|
|
27
|
+
private var eventListener: ((String, JSObject) -> Unit)? = null
|
|
28
|
+
private val appUpdateManager: AppUpdateManager = AppUpdateManagerFactory.create(context)
|
|
29
|
+
private var config: JSObject? = null
|
|
30
|
+
private var updateInfo: AppUpdateInfo? = null
|
|
31
|
+
|
|
32
|
+
companion object {
|
|
33
|
+
const val REQUEST_CODE_UPDATE = 12345
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private val installStateUpdatedListener = InstallStateUpdatedListener { state ->
|
|
37
|
+
handleInstallState(state)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
init {
|
|
41
|
+
appUpdateManager.registerListener(installStateUpdatedListener)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun configure(config: JSObject) {
|
|
45
|
+
this.config = config
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fun setEventListener(listener: (String, JSObject) -> Unit) {
|
|
49
|
+
this.eventListener = listener
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun getAppUpdateInfo(call: PluginCall) {
|
|
53
|
+
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
|
|
54
|
+
|
|
55
|
+
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
|
|
56
|
+
this.updateInfo = appUpdateInfo
|
|
57
|
+
|
|
58
|
+
val result = JSObject()
|
|
59
|
+
result.put("updateAvailable", appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE)
|
|
60
|
+
result.put("currentVersion", getCurrentAppVersion())
|
|
61
|
+
result.put("availableVersion", appUpdateInfo.availableVersionCode().toString())
|
|
62
|
+
result.put("updatePriority", appUpdateInfo.updatePriority())
|
|
63
|
+
result.put("immediateUpdateAllowed", appUpdateInfo.isImmediateUpdateAllowed)
|
|
64
|
+
result.put("flexibleUpdateAllowed", appUpdateInfo.isFlexibleUpdateAllowed)
|
|
65
|
+
result.put("clientVersionStalenessDays", appUpdateInfo.clientVersionStalenessDays() ?: -1)
|
|
66
|
+
|
|
67
|
+
// Add install status if update is in progress
|
|
68
|
+
if (appUpdateInfo.installStatus() != InstallStatus.UNKNOWN) {
|
|
69
|
+
result.put("installStatus", getInstallStatusString(appUpdateInfo.installStatus()))
|
|
70
|
+
result.put("bytesDownloaded", appUpdateInfo.bytesDownloaded())
|
|
71
|
+
result.put("totalBytesToDownload", appUpdateInfo.totalBytesToDownload())
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Emit available event if update is available
|
|
75
|
+
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
|
|
76
|
+
val availableData = JSObject()
|
|
77
|
+
availableData.put("currentVersion", getCurrentAppVersion())
|
|
78
|
+
availableData.put("availableVersion", appUpdateInfo.availableVersionCode().toString())
|
|
79
|
+
availableData.put("updatePriority", appUpdateInfo.updatePriority())
|
|
80
|
+
eventListener?.invoke("appUpdateAvailable", availableData)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
call.resolve(result)
|
|
84
|
+
}.addOnFailureListener { e ->
|
|
85
|
+
call.reject("UPDATE_CHECK_FAILED", e.message)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fun performImmediateUpdate(call: PluginCall) {
|
|
90
|
+
val appUpdateInfo = updateInfo
|
|
91
|
+
|
|
92
|
+
if (appUpdateInfo == null) {
|
|
93
|
+
// Need to check for updates first
|
|
94
|
+
appUpdateManager.appUpdateInfo.addOnSuccessListener { info ->
|
|
95
|
+
this.updateInfo = info
|
|
96
|
+
startImmediateUpdate(info, call)
|
|
97
|
+
}.addOnFailureListener { e ->
|
|
98
|
+
call.reject("UPDATE_CHECK_FAILED", e.message)
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
startImmediateUpdate(appUpdateInfo, call)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fun startFlexibleUpdate(call: PluginCall) {
|
|
106
|
+
val appUpdateInfo = updateInfo
|
|
107
|
+
|
|
108
|
+
if (appUpdateInfo == null) {
|
|
109
|
+
// Need to check for updates first
|
|
110
|
+
appUpdateManager.appUpdateInfo.addOnSuccessListener { info ->
|
|
111
|
+
this.updateInfo = info
|
|
112
|
+
startFlexibleUpdateFlow(info, call)
|
|
113
|
+
}.addOnFailureListener { e ->
|
|
114
|
+
call.reject("UPDATE_CHECK_FAILED", e.message)
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
startFlexibleUpdateFlow(appUpdateInfo, call)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
fun completeFlexibleUpdate(call: PluginCall) {
|
|
122
|
+
appUpdateManager.completeUpdate()
|
|
123
|
+
call.resolve()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
fun openAppStore(call: PluginCall) {
|
|
127
|
+
try {
|
|
128
|
+
val packageName = call.getString("appId") ?: context.packageName
|
|
129
|
+
|
|
130
|
+
// Try to open in Play Store app first
|
|
131
|
+
try {
|
|
132
|
+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName"))
|
|
133
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
134
|
+
context.startActivity(intent)
|
|
135
|
+
} catch (e: Exception) {
|
|
136
|
+
// Fallback to web browser
|
|
137
|
+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageName"))
|
|
138
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
139
|
+
context.startActivity(intent)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
call.resolve()
|
|
143
|
+
} catch (e: Exception) {
|
|
144
|
+
call.reject("OPEN_STORE_FAILED", e.message)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private fun startImmediateUpdate(appUpdateInfo: AppUpdateInfo, call: PluginCall) {
|
|
149
|
+
if (!appUpdateInfo.isImmediateUpdateAllowed) {
|
|
150
|
+
call.reject("UPDATE_NOT_ALLOWED", "Immediate update is not allowed")
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
val updateOptions = AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE).build()
|
|
156
|
+
|
|
157
|
+
appUpdateManager.startUpdateFlow(
|
|
158
|
+
appUpdateInfo,
|
|
159
|
+
activity,
|
|
160
|
+
updateOptions
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
call.resolve()
|
|
164
|
+
} catch (e: Exception) {
|
|
165
|
+
call.reject("UPDATE_FAILED", e.message)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private fun startFlexibleUpdateFlow(appUpdateInfo: AppUpdateInfo, call: PluginCall) {
|
|
170
|
+
if (!appUpdateInfo.isFlexibleUpdateAllowed) {
|
|
171
|
+
call.reject("UPDATE_NOT_ALLOWED", "Flexible update is not allowed")
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
val updateOptions = AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build()
|
|
177
|
+
|
|
178
|
+
appUpdateManager.startUpdateFlow(
|
|
179
|
+
appUpdateInfo,
|
|
180
|
+
activity,
|
|
181
|
+
updateOptions
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
call.resolve()
|
|
185
|
+
} catch (e: Exception) {
|
|
186
|
+
call.reject("UPDATE_FAILED", e.message)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private fun handleInstallState(state: InstallState) {
|
|
191
|
+
// Emit state change event
|
|
192
|
+
val eventData = JSObject()
|
|
193
|
+
eventData.put("status", getInstallStatusString(state.installStatus()))
|
|
194
|
+
eventListener?.invoke("appUpdateStateChanged", eventData)
|
|
195
|
+
|
|
196
|
+
// Emit progress event for downloads
|
|
197
|
+
if (state.installStatus() == InstallStatus.DOWNLOADING) {
|
|
198
|
+
val progressData = JSObject()
|
|
199
|
+
progressData.put("percent", if (state.totalBytesToDownload() > 0)
|
|
200
|
+
((state.bytesDownloaded() * 100) / state.totalBytesToDownload()).toInt() else 0)
|
|
201
|
+
progressData.put("bytesDownloaded", state.bytesDownloaded())
|
|
202
|
+
progressData.put("totalBytes", state.totalBytesToDownload())
|
|
203
|
+
eventListener?.invoke("appUpdateProgress", progressData)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
when (state.installStatus()) {
|
|
207
|
+
InstallStatus.DOWNLOADED -> {
|
|
208
|
+
// Update has been downloaded, prompt user to restart
|
|
209
|
+
popupSnackbarForCompleteUpdate()
|
|
210
|
+
|
|
211
|
+
// Emit ready event
|
|
212
|
+
val readyData = JSObject()
|
|
213
|
+
readyData.put("message", "Update downloaded and ready to install")
|
|
214
|
+
eventListener?.invoke("appUpdateReady", readyData)
|
|
215
|
+
}
|
|
216
|
+
InstallStatus.INSTALLED -> {
|
|
217
|
+
// Update installed, cleanup
|
|
218
|
+
appUpdateManager.unregisterListener(installStateUpdatedListener)
|
|
219
|
+
}
|
|
220
|
+
InstallStatus.FAILED -> {
|
|
221
|
+
// Update failed
|
|
222
|
+
val failedData = JSObject()
|
|
223
|
+
failedData.put("error", "Update installation failed")
|
|
224
|
+
failedData.put("code", "INSTALL_FAILED")
|
|
225
|
+
eventListener?.invoke("appUpdateFailed", failedData)
|
|
226
|
+
}
|
|
227
|
+
else -> {
|
|
228
|
+
// Handle other states
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private fun popupSnackbarForCompleteUpdate() {
|
|
234
|
+
// In a real implementation, show a snackbar or notification
|
|
235
|
+
// For now, we'll just complete the update
|
|
236
|
+
appUpdateManager.completeUpdate()
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private fun getCurrentAppVersion(): String {
|
|
240
|
+
return try {
|
|
241
|
+
val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
|
242
|
+
packageInfo.versionName ?: "Unknown"
|
|
243
|
+
} catch (e: Exception) {
|
|
244
|
+
"Unknown"
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private fun getInstallStatusString(status: Int): String {
|
|
249
|
+
return when (status) {
|
|
250
|
+
InstallStatus.PENDING -> "PENDING"
|
|
251
|
+
InstallStatus.DOWNLOADING -> "DOWNLOADING"
|
|
252
|
+
InstallStatus.DOWNLOADED -> "DOWNLOADED"
|
|
253
|
+
InstallStatus.INSTALLING -> "INSTALLING"
|
|
254
|
+
InstallStatus.INSTALLED -> "INSTALLED"
|
|
255
|
+
InstallStatus.FAILED -> "FAILED"
|
|
256
|
+
InstallStatus.CANCELED -> "CANCELED"
|
|
257
|
+
else -> "UNKNOWN"
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
fun onActivityResult(requestCode: Int, resultCode: Int) {
|
|
262
|
+
if (requestCode == REQUEST_CODE_UPDATE) {
|
|
263
|
+
when (resultCode) {
|
|
264
|
+
Activity.RESULT_OK -> {
|
|
265
|
+
// Update flow completed successfully
|
|
266
|
+
}
|
|
267
|
+
Activity.RESULT_CANCELED -> {
|
|
268
|
+
// User cancelled the update
|
|
269
|
+
}
|
|
270
|
+
else -> {
|
|
271
|
+
// Update flow failed
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
fun onResume() {
|
|
278
|
+
// Check if update is waiting to be installed
|
|
279
|
+
appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo ->
|
|
280
|
+
if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
|
|
281
|
+
// Resume the update
|
|
282
|
+
val updateOptions = AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE).build()
|
|
283
|
+
appUpdateManager.startUpdateFlow(
|
|
284
|
+
appUpdateInfo,
|
|
285
|
+
activity,
|
|
286
|
+
updateOptions
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Async method for background update checks
|
|
293
|
+
suspend fun getAppUpdateInfoAsync(): AppUpdateStatus? {
|
|
294
|
+
return try {
|
|
295
|
+
val appUpdateInfo = appUpdateManager.appUpdateInfo.await()
|
|
296
|
+
|
|
297
|
+
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
|
|
298
|
+
AppUpdateStatus(
|
|
299
|
+
updateAvailable = true,
|
|
300
|
+
currentVersion = getCurrentAppVersion(),
|
|
301
|
+
availableVersion = appUpdateInfo.availableVersionCode().toString()
|
|
302
|
+
)
|
|
303
|
+
} else {
|
|
304
|
+
AppUpdateStatus(
|
|
305
|
+
updateAvailable = false,
|
|
306
|
+
currentVersion = getCurrentAppVersion(),
|
|
307
|
+
availableVersion = null
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
} catch (e: Exception) {
|
|
311
|
+
null
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|