@capgo/capacitor-updater 9.0.0 → 9.0.2
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/CapgoCapacitorUpdater.podspec +3 -6
- package/Package.swift +30 -0
- package/README.md +2406 -291
- package/android/build.gradle +37 -17
- package/android/consumer-rules.pro +48 -0
- package/android/proguard-rules.pro +23 -0
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/AndroidAppExitReporter.java +92 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/AppLifecycleObserver.java +115 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +227 -195
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +24 -23
- package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +13 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +7927 -1243
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +5785 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +564 -121
- package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +44 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +43 -49
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +4 -4
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +427 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DeviceIdHelper.java +230 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +2041 -118
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +301 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +569 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Http3.java +436 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/HttpEngineTransport.java +604 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +79 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +419 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeDetector.java +72 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +963 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/StatsBatchFailureDiagnostics.java +40 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ThreeFingerPinchDetector.java +323 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
- package/dist/docs.json +4431 -840
- package/dist/esm/definitions.d.ts +2641 -225
- package/dist/esm/definitions.js +103 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/history.d.ts +1 -0
- package/dist/esm/history.js +283 -0
- package/dist/esm/history.js.map +1 -0
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +5 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +53 -42
- package/dist/esm/web.js +180 -37
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +570 -37
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +570 -37
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +262 -0
- package/ios/Sources/CapacitorUpdaterPlugin/AppHealthTracker.swift +82 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BundleInfo.swift +185 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BundleStatus.swift +127 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +6813 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoRawRsa.swift +36 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +200 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +5099 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +387 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +343 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DeviceIdHelper.swift +120 -0
- package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +452 -0
- package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +380 -0
- package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RSA.swift +96 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +97 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +876 -0
- package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/UserDefaultsExtension.swift +0 -2
- package/ios/Sources/CapacitorUpdaterPlugin/WKWebView+CapgoObjcBridge.swift +20 -0
- package/ios/Sources/CapacitorUpdaterPlugin/WebViewStatsReporter.swift +304 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/BuiltinHashesTests.swift +210 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/BundleHardeningTests.swift +292 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CapacitorUpdaterPluginTests.swift +6533 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CapgoSemanticVersionTests.swift +64 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ChecksumRequiredTests.swift +156 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CliCryptoFixtureTests.swift +314 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/HttpsOnlyBuiltinMinimumTests.swift +653 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/InstallPerfTests.swift +174 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ListChannelsTests.swift +74 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/LoggerSecurityTests.swift +149 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/NativeContractTests.swift +160 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/NetworkTransportTests.swift +1109 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/PopulateDeltaCacheTests.swift +573 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/RedirectPolicyTests.swift +63 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/RsaContractTests.swift +281 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/SessionKeyRequiredTests.swift +196 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/TestZipWriter.swift +235 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/UpdateLifecycleTests.swift +470 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/WebKitOverlayGuardTests.swift +32 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ZipArchiveReaderTests.swift +302 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ZipBundleExtractionTests.swift +122 -0
- package/package.json +80 -43
- 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/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +0 -1130
- package/ios/Plugin/BundleInfo.swift +0 -113
- package/ios/Plugin/BundleStatus.swift +0 -48
- package/ios/Plugin/CapacitorUpdater.swift +0 -858
- package/ios/Plugin/CapacitorUpdaterPlugin.h +0 -10
- package/ios/Plugin/CapacitorUpdaterPlugin.m +0 -27
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +0 -677
- package/ios/Plugin/CryptoCipher.swift +0 -240
- /package/{LICENCE → LICENSE} +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayCondition.swift +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayUntilNext.swift +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/Info.plist +0 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
package ee.forgr.capacitor_updater;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.os.Build;
|
|
5
|
+
import androidx.work.BackoffPolicy;
|
|
6
|
+
import androidx.work.Configuration;
|
|
7
|
+
import androidx.work.Constraints;
|
|
8
|
+
import androidx.work.Data;
|
|
9
|
+
import androidx.work.ExistingWorkPolicy;
|
|
10
|
+
import androidx.work.NetworkType;
|
|
11
|
+
import androidx.work.OneTimeWorkRequest;
|
|
12
|
+
import androidx.work.OutOfQuotaPolicy;
|
|
13
|
+
import androidx.work.WorkInfo;
|
|
14
|
+
import androidx.work.WorkManager;
|
|
15
|
+
import androidx.work.WorkRequest;
|
|
16
|
+
import java.util.HashSet;
|
|
17
|
+
import java.util.List;
|
|
18
|
+
import java.util.Set;
|
|
19
|
+
import java.util.concurrent.ExecutorService;
|
|
20
|
+
import java.util.concurrent.Executors;
|
|
21
|
+
import java.util.concurrent.Future;
|
|
22
|
+
import java.util.concurrent.TimeUnit;
|
|
23
|
+
import java.util.concurrent.TimeoutException;
|
|
24
|
+
|
|
25
|
+
public class DownloadWorkerManager {
|
|
26
|
+
|
|
27
|
+
private static volatile Logger logger;
|
|
28
|
+
private static final Object LOGGER_LOCK = new Object();
|
|
29
|
+
|
|
30
|
+
public static void setLogger(Logger loggerInstance) {
|
|
31
|
+
synchronized (LOGGER_LOCK) {
|
|
32
|
+
logger = loggerInstance;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static void setLoggerIfAbsent(Logger loggerInstance) {
|
|
37
|
+
if (loggerInstance == null) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
synchronized (LOGGER_LOCK) {
|
|
41
|
+
if (logger == null) {
|
|
42
|
+
logger = loggerInstance;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static Logger getLogger() {
|
|
48
|
+
return logger;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private static volatile boolean isInitialized = false;
|
|
52
|
+
private static final ExecutorService cancelExecutor = Executors.newSingleThreadExecutor();
|
|
53
|
+
|
|
54
|
+
private static synchronized void initializeIfNeeded(Context context) {
|
|
55
|
+
if (!isInitialized) {
|
|
56
|
+
try {
|
|
57
|
+
Configuration config = new Configuration.Builder().setMinimumLoggingLevel(android.util.Log.INFO).build();
|
|
58
|
+
WorkManager.initialize(context, config);
|
|
59
|
+
isInitialized = true;
|
|
60
|
+
} catch (IllegalStateException e) {
|
|
61
|
+
// WorkManager was already initialized, ignore
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public static boolean isVersionDownloading(Context context, String version) {
|
|
67
|
+
initializeIfNeeded(context.getApplicationContext());
|
|
68
|
+
try {
|
|
69
|
+
return WorkManager.getInstance(context)
|
|
70
|
+
.getWorkInfosByTag(version)
|
|
71
|
+
.get()
|
|
72
|
+
.stream()
|
|
73
|
+
.anyMatch((workInfo) -> !workInfo.getState().isFinished());
|
|
74
|
+
} catch (Exception e) {
|
|
75
|
+
logger.error("Error checking download status: " + e.getMessage());
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public static void enqueueDownload(
|
|
81
|
+
Context context,
|
|
82
|
+
String url,
|
|
83
|
+
String id,
|
|
84
|
+
String documentsDir,
|
|
85
|
+
String dest,
|
|
86
|
+
String version,
|
|
87
|
+
String sessionKey,
|
|
88
|
+
String checksum,
|
|
89
|
+
String publicKey,
|
|
90
|
+
boolean isManifest,
|
|
91
|
+
boolean isEmulator,
|
|
92
|
+
String appId,
|
|
93
|
+
String pluginVersion,
|
|
94
|
+
boolean isProd,
|
|
95
|
+
String installSource,
|
|
96
|
+
String statsUrl,
|
|
97
|
+
String deviceId,
|
|
98
|
+
String versionBuild,
|
|
99
|
+
String versionCode,
|
|
100
|
+
String versionOs,
|
|
101
|
+
String customId,
|
|
102
|
+
String defaultChannel
|
|
103
|
+
) {
|
|
104
|
+
initializeIfNeeded(context.getApplicationContext());
|
|
105
|
+
|
|
106
|
+
// Use unique work name for this bundle to prevent duplicates
|
|
107
|
+
String uniqueWorkName = "bundle_" + id + "_" + version;
|
|
108
|
+
|
|
109
|
+
// Create input data
|
|
110
|
+
Data inputData = new Data.Builder()
|
|
111
|
+
.putString(DownloadService.URL, url)
|
|
112
|
+
.putString(DownloadService.ID, id)
|
|
113
|
+
.putString(DownloadService.DOCDIR, documentsDir)
|
|
114
|
+
.putString(DownloadService.FILEDEST, dest)
|
|
115
|
+
.putString(DownloadService.VERSION, version)
|
|
116
|
+
.putString(DownloadService.SESSIONKEY, sessionKey)
|
|
117
|
+
.putString(DownloadService.CHECKSUM, checksum)
|
|
118
|
+
.putBoolean(DownloadService.IS_MANIFEST, isManifest)
|
|
119
|
+
.putString(DownloadService.PUBLIC_KEY, publicKey)
|
|
120
|
+
.putString(DownloadService.APP_ID, appId)
|
|
121
|
+
.putString(DownloadService.pluginVersion, pluginVersion)
|
|
122
|
+
.putString(DownloadService.INSTALL_SOURCE, installSource)
|
|
123
|
+
.putString(DownloadService.STATS_URL, statsUrl)
|
|
124
|
+
.putString(DownloadService.DEVICE_ID, deviceId)
|
|
125
|
+
.putString(DownloadService.VERSION_BUILD, versionBuild)
|
|
126
|
+
.putString(DownloadService.VERSION_CODE, versionCode)
|
|
127
|
+
.putString(DownloadService.VERSION_OS, versionOs)
|
|
128
|
+
.putString(DownloadService.CUSTOM_ID, customId)
|
|
129
|
+
.putString(DownloadService.DEFAULT_CHANNEL, defaultChannel)
|
|
130
|
+
.putBoolean(DownloadService.IS_PROD, isProd)
|
|
131
|
+
.putBoolean(DownloadService.IS_EMULATOR, isEmulator)
|
|
132
|
+
// A job WorkManager resumes in a fresh process runs before any config is loaded.
|
|
133
|
+
.putBoolean(DownloadService.HTTP3, Http3.isEnabled())
|
|
134
|
+
.build();
|
|
135
|
+
|
|
136
|
+
// Create network constraints - be more lenient on emulators
|
|
137
|
+
Constraints.Builder constraintsBuilder = new Constraints.Builder();
|
|
138
|
+
if (isEmulator) {
|
|
139
|
+
logger.info("Emulator detected - using lenient network constraints");
|
|
140
|
+
// On emulators, use NOT_REQUIRED to avoid background network issues
|
|
141
|
+
constraintsBuilder.setRequiredNetworkType(NetworkType.NOT_REQUIRED);
|
|
142
|
+
} else {
|
|
143
|
+
constraintsBuilder.setRequiredNetworkType(NetworkType.CONNECTED);
|
|
144
|
+
}
|
|
145
|
+
Constraints constraints = constraintsBuilder.build();
|
|
146
|
+
|
|
147
|
+
// Create work request with tags for tracking
|
|
148
|
+
OneTimeWorkRequest.Builder workRequestBuilder = new OneTimeWorkRequest.Builder(DownloadService.class)
|
|
149
|
+
.setConstraints(constraints)
|
|
150
|
+
.setInputData(inputData)
|
|
151
|
+
.addTag(id)
|
|
152
|
+
.addTag(version)
|
|
153
|
+
.addTag("capacitor_updater_download");
|
|
154
|
+
// Android 12+ expedited jobs skip the WorkManager delay without a
|
|
155
|
+
// foreground service. Older APIs require getForegroundInfo().
|
|
156
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
157
|
+
workRequestBuilder.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// More aggressive retry policy for emulators
|
|
161
|
+
if (isEmulator) {
|
|
162
|
+
workRequestBuilder.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 30, TimeUnit.SECONDS);
|
|
163
|
+
} else {
|
|
164
|
+
workRequestBuilder.setBackoffCriteria(BackoffPolicy.LINEAR, WorkRequest.MIN_BACKOFF_MILLIS, TimeUnit.MILLISECONDS);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
OneTimeWorkRequest workRequest = workRequestBuilder.build();
|
|
168
|
+
|
|
169
|
+
// Use beginUniqueWork to prevent duplicate downloads
|
|
170
|
+
WorkManager.getInstance(context)
|
|
171
|
+
.beginUniqueWork(
|
|
172
|
+
uniqueWorkName,
|
|
173
|
+
ExistingWorkPolicy.KEEP, // Don't start if already running
|
|
174
|
+
workRequest
|
|
175
|
+
)
|
|
176
|
+
.enqueue();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public static void cancelVersionDownload(Context context, String version) {
|
|
180
|
+
initializeIfNeeded(context.getApplicationContext());
|
|
181
|
+
cancelExecutor.execute(() -> cancelVersionDownloadInternal(context, version, false));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public static boolean cancelVersionDownloadAndAwait(Context context, String version) {
|
|
185
|
+
initializeIfNeeded(context.getApplicationContext());
|
|
186
|
+
Future<?> future = cancelExecutor.submit(() -> cancelVersionDownloadInternal(context, version, true));
|
|
187
|
+
try {
|
|
188
|
+
future.get(10, TimeUnit.SECONDS);
|
|
189
|
+
return true;
|
|
190
|
+
} catch (TimeoutException e) {
|
|
191
|
+
future.cancel(true);
|
|
192
|
+
logger.error("Timed out awaiting version download cancel");
|
|
193
|
+
return false;
|
|
194
|
+
} catch (Exception e) {
|
|
195
|
+
logger.error("Error awaiting version download cancel: " + e.getMessage());
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private static Set<String> collectManifestIdsForVersion(WorkManager workManager, String version) {
|
|
201
|
+
Set<String> downloadIds = new HashSet<>();
|
|
202
|
+
try {
|
|
203
|
+
List<WorkInfo> workInfos = workManager.getWorkInfosByTag(version).get();
|
|
204
|
+
for (WorkInfo workInfo : workInfos) {
|
|
205
|
+
for (String tag : workInfo.getTags()) {
|
|
206
|
+
if (!"capacitor_updater_download".equals(tag) && !version.equals(tag)) {
|
|
207
|
+
downloadIds.add(tag);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
} catch (InterruptedException e) {
|
|
212
|
+
Thread.currentThread().interrupt();
|
|
213
|
+
throw new IllegalStateException("Interrupted while collecting manifest ids before version cancel", e);
|
|
214
|
+
} catch (Exception e) {
|
|
215
|
+
logger.error("Error collecting manifest ids before version cancel: " + e.getMessage());
|
|
216
|
+
}
|
|
217
|
+
return downloadIds;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private static void clearManifestIds(Set<String> downloadIds) {
|
|
221
|
+
for (String downloadId : downloadIds) {
|
|
222
|
+
DataManager.getInstance().clearManifest(downloadId);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private static void cancelVersionDownloadInternal(Context context, String version, boolean awaitFinished) {
|
|
227
|
+
if (Thread.currentThread().isInterrupted()) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
WorkManager workManager = WorkManager.getInstance(context);
|
|
231
|
+
Set<String> downloadIds = collectManifestIdsForVersion(workManager, version);
|
|
232
|
+
workManager.cancelAllWorkByTag(version);
|
|
233
|
+
clearManifestIds(downloadIds);
|
|
234
|
+
if (awaitFinished) {
|
|
235
|
+
awaitVersionWorkFinished(workManager, version);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private static void awaitVersionWorkFinished(WorkManager workManager, String version) {
|
|
240
|
+
for (int i = 0; i < 100; i++) {
|
|
241
|
+
if (Thread.currentThread().isInterrupted()) {
|
|
242
|
+
throw new IllegalStateException("Interrupted while waiting for version download cancel");
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
boolean anyActive = workManager
|
|
246
|
+
.getWorkInfosByTag(version)
|
|
247
|
+
.get()
|
|
248
|
+
.stream()
|
|
249
|
+
.anyMatch((workInfo) -> !workInfo.getState().isFinished());
|
|
250
|
+
if (!anyActive) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
Thread.sleep(100);
|
|
254
|
+
} catch (InterruptedException e) {
|
|
255
|
+
Thread.currentThread().interrupt();
|
|
256
|
+
throw new IllegalStateException("Interrupted while waiting for download cancel", e);
|
|
257
|
+
} catch (Exception e) {
|
|
258
|
+
throw new IllegalStateException("Error waiting for download cancel: " + e.getMessage(), e);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
throw new IllegalStateException("Timed out waiting for version download cancel: " + version);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Whether any work of this bundle attempt (tagged with its id) has not finished yet, for example a cancelled worker
|
|
266
|
+
* still returning from doWork. Unknown state counts as unfinished so callers keep their cleanup records.
|
|
267
|
+
*/
|
|
268
|
+
public static boolean isBundleWorkUnfinished(Context context, String id) {
|
|
269
|
+
if (context == null || id == null || id.isEmpty()) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
initializeIfNeeded(context.getApplicationContext());
|
|
273
|
+
try {
|
|
274
|
+
return WorkManager.getInstance(context)
|
|
275
|
+
.getWorkInfosByTag(id)
|
|
276
|
+
.get()
|
|
277
|
+
.stream()
|
|
278
|
+
.anyMatch((workInfo) -> !workInfo.getState().isFinished());
|
|
279
|
+
} catch (Exception e) {
|
|
280
|
+
if (logger != null) {
|
|
281
|
+
logger.error("Error checking bundle work status: " + e.getMessage());
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public static void cancelBundleDownload(Context context, String id, String version) {
|
|
288
|
+
String uniqueWorkName = "bundle_" + id + "_" + version;
|
|
289
|
+
initializeIfNeeded(context.getApplicationContext());
|
|
290
|
+
WorkManager workManager = WorkManager.getInstance(context);
|
|
291
|
+
workManager.cancelUniqueWork(uniqueWorkName);
|
|
292
|
+
DataManager.getInstance().clearManifest(id);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public static void cancelAllDownloads(Context context) {
|
|
296
|
+
initializeIfNeeded(context.getApplicationContext());
|
|
297
|
+
WorkManager workManager = WorkManager.getInstance(context);
|
|
298
|
+
workManager.cancelAllWorkByTag("capacitor_updater_download");
|
|
299
|
+
DataManager.getInstance().clearAllManifests();
|
|
300
|
+
}
|
|
301
|
+
}
|