@capgo/capacitor-updater 7.2.20 → 7.2.21
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/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +128 -134
- package/android/src/main/java/ee/forgr/capacitor_updater/{CapacitorUpdater.java → CapgoUpdater.java} +18 -18
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipherV2.java +7 -7
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +21 -24
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +1 -1
- package/ios/Plugin/AES.swift +2 -2
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +93 -93
- package/ios/Plugin/{CapacitorUpdater.swift → CapgoUpdater.swift} +67 -67
- package/ios/Plugin/CryptoCipherV2.swift +25 -25
- package/ios/Plugin/DelayUpdateUtils.swift +23 -23
- package/package.json +1 -1
|
@@ -59,12 +59,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
59
59
|
private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
|
|
60
60
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
61
61
|
|
|
62
|
-
private final String PLUGIN_VERSION = "7.2.
|
|
62
|
+
private final String PLUGIN_VERSION = "7.2.21";
|
|
63
63
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
64
64
|
|
|
65
65
|
private SharedPreferences.Editor editor;
|
|
66
66
|
private SharedPreferences prefs;
|
|
67
|
-
protected
|
|
67
|
+
protected CapgoUpdater implementation;
|
|
68
68
|
|
|
69
69
|
private Integer appReadyTimeout = 10000;
|
|
70
70
|
private Integer counterActivityCreate = 0;
|
|
@@ -125,7 +125,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
125
125
|
this.editor = this.prefs.edit();
|
|
126
126
|
|
|
127
127
|
try {
|
|
128
|
-
this.implementation = new
|
|
128
|
+
this.implementation = new CapgoUpdater() {
|
|
129
129
|
@Override
|
|
130
130
|
public void notifyDownload(final String id, final int percent) {
|
|
131
131
|
CapacitorUpdaterPlugin.this.notifyDownload(id, percent);
|
|
@@ -162,10 +162,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
162
162
|
CapacitorUpdaterPlugin.this::installNext
|
|
163
163
|
);
|
|
164
164
|
} catch (final PackageManager.NameNotFoundException e) {
|
|
165
|
-
Log.e(
|
|
165
|
+
Log.e(CapgoUpdater.TAG, "Error instantiating implementation", e);
|
|
166
166
|
return;
|
|
167
167
|
} catch (final Exception e) {
|
|
168
|
-
Log.e(
|
|
168
|
+
Log.e(CapgoUpdater.TAG, "Error getting current native app version", e);
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
171
|
final CapConfig config = CapConfig.loadDefault(this.getActivity());
|
|
@@ -178,7 +178,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
178
178
|
"appId is missing in capacitor.config.json or plugin config, and cannot be retrieved from the native app, please add it globally or in the plugin config"
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
|
-
Log.i(
|
|
181
|
+
Log.i(CapgoUpdater.TAG, "appId: " + implementation.appId);
|
|
182
182
|
this.implementation.publicKey = this.getConfig().getString("publicKey", "");
|
|
183
183
|
this.implementation.statsUrl = this.getConfig().getString("statsUrl", statsUrlDefault);
|
|
184
184
|
this.implementation.channelUrl = this.getConfig().getString("channelUrl", channelUrlDefault);
|
|
@@ -198,8 +198,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
198
198
|
this.implementation.deviceID = this.prefs.getString("appUUID", UUID.randomUUID().toString()).toLowerCase();
|
|
199
199
|
this.editor.putString("appUUID", this.implementation.deviceID);
|
|
200
200
|
this.editor.commit();
|
|
201
|
-
Log.i(
|
|
202
|
-
Log.i(
|
|
201
|
+
Log.i(CapgoUpdater.TAG, "init for device " + this.implementation.deviceID);
|
|
202
|
+
Log.i(CapgoUpdater.TAG, "version native " + this.currentVersionNative.getOriginalString());
|
|
203
203
|
this.autoDeleteFailed = this.getConfig().getBoolean("autoDeleteFailed", true);
|
|
204
204
|
this.autoDeletePrevious = this.getConfig().getBoolean("autoDeletePrevious", true);
|
|
205
205
|
this.updateUrl = this.getConfig().getString("updateUrl", updateUrlDefault);
|
|
@@ -217,14 +217,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
private void semaphoreWait(Number waitTime) {
|
|
220
|
-
// Log.i(
|
|
220
|
+
// Log.i(CapgoUpdater.TAG, "semaphoreWait " + waitTime);
|
|
221
221
|
try {
|
|
222
|
-
// Log.i(
|
|
222
|
+
// Log.i(CapgoUpdater.TAG, "semaphoreReady count " + CapacitorUpdaterPlugin.this.semaphoreReady.getCount());
|
|
223
223
|
semaphoreReady.awaitAdvanceInterruptibly(semaphoreReady.getPhase(), waitTime.longValue(), TimeUnit.SECONDS);
|
|
224
|
-
// Log.i(
|
|
225
|
-
Log.i(
|
|
224
|
+
// Log.i(CapgoUpdater.TAG, "semaphoreReady await " + res);
|
|
225
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady count " + semaphoreReady.getPhase());
|
|
226
226
|
} catch (InterruptedException e) {
|
|
227
|
-
Log.i(
|
|
227
|
+
Log.i(CapgoUpdater.TAG, "semaphoreWait InterruptedException");
|
|
228
228
|
e.printStackTrace();
|
|
229
229
|
} catch (TimeoutException e) {
|
|
230
230
|
throw new RuntimeException(e);
|
|
@@ -232,25 +232,25 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
private void semaphoreUp() {
|
|
235
|
-
Log.i(
|
|
235
|
+
Log.i(CapgoUpdater.TAG, "semaphoreUp");
|
|
236
236
|
semaphoreReady.register();
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
private void semaphoreDown() {
|
|
240
|
-
Log.i(
|
|
241
|
-
Log.i(
|
|
240
|
+
Log.i(CapgoUpdater.TAG, "semaphoreDown");
|
|
241
|
+
Log.i(CapgoUpdater.TAG, "semaphoreDown count " + semaphoreReady.getPhase());
|
|
242
242
|
semaphoreReady.arriveAndDeregister();
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
private void sendReadyToJs(final BundleInfo current, final String msg) {
|
|
246
|
-
Log.i(
|
|
246
|
+
Log.i(CapgoUpdater.TAG, "sendReadyToJs");
|
|
247
247
|
final JSObject ret = new JSObject();
|
|
248
248
|
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
249
249
|
ret.put("status", msg);
|
|
250
250
|
startNewThread(() -> {
|
|
251
|
-
Log.i(
|
|
251
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady sendReadyToJs");
|
|
252
252
|
semaphoreWait(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
253
|
-
Log.i(
|
|
253
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady sendReadyToJs done");
|
|
254
254
|
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
255
255
|
});
|
|
256
256
|
}
|
|
@@ -269,23 +269,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
269
269
|
!"".equals(previous.getOriginalString()) &&
|
|
270
270
|
!Objects.equals(this.currentVersionNative.getOriginalString(), previous.getOriginalString())
|
|
271
271
|
) {
|
|
272
|
-
Log.i(
|
|
272
|
+
Log.i(CapgoUpdater.TAG, "New native version detected: " + this.currentVersionNative);
|
|
273
273
|
this.implementation.reset(true);
|
|
274
274
|
final List<BundleInfo> installed = this.implementation.list(false);
|
|
275
275
|
for (final BundleInfo bundle : installed) {
|
|
276
276
|
try {
|
|
277
|
-
Log.i(
|
|
277
|
+
Log.i(CapgoUpdater.TAG, "Deleting obsolete bundle: " + bundle.getId());
|
|
278
278
|
this.implementation.delete(bundle.getId());
|
|
279
279
|
} catch (final Exception e) {
|
|
280
|
-
Log.e(
|
|
280
|
+
Log.e(CapgoUpdater.TAG, "Failed to delete: " + bundle.getId(), e);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
} catch (final Exception e) {
|
|
285
|
-
Log.e(
|
|
285
|
+
Log.e(CapgoUpdater.TAG, "Could not determine the current version", e);
|
|
286
286
|
}
|
|
287
287
|
} catch (final Exception e) {
|
|
288
|
-
Log.e(
|
|
288
|
+
Log.e(CapgoUpdater.TAG, "Error calculating previous native version", e);
|
|
289
289
|
}
|
|
290
290
|
this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
|
|
291
291
|
this.editor.commit();
|
|
@@ -312,20 +312,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
} catch (final Exception e) {
|
|
315
|
-
Log.e(
|
|
315
|
+
Log.e(CapgoUpdater.TAG, "Could not notify listeners", e);
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
@PluginMethod
|
|
320
320
|
public void setUpdateUrl(final PluginCall call) {
|
|
321
321
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
322
|
-
Log.e(
|
|
322
|
+
Log.e(CapgoUpdater.TAG, "setUpdateUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
323
323
|
call.reject("setUpdateUrl not allowed");
|
|
324
324
|
return;
|
|
325
325
|
}
|
|
326
326
|
final String url = call.getString("url");
|
|
327
327
|
if (url == null) {
|
|
328
|
-
Log.e(
|
|
328
|
+
Log.e(CapgoUpdater.TAG, "setUpdateUrl called without url");
|
|
329
329
|
call.reject("setUpdateUrl called without url");
|
|
330
330
|
return;
|
|
331
331
|
}
|
|
@@ -336,13 +336,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
336
336
|
@PluginMethod
|
|
337
337
|
public void setStatsUrl(final PluginCall call) {
|
|
338
338
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
339
|
-
Log.e(
|
|
339
|
+
Log.e(CapgoUpdater.TAG, "setStatsUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
340
340
|
call.reject("setStatsUrl not allowed");
|
|
341
341
|
return;
|
|
342
342
|
}
|
|
343
343
|
final String url = call.getString("url");
|
|
344
344
|
if (url == null) {
|
|
345
|
-
Log.e(
|
|
345
|
+
Log.e(CapgoUpdater.TAG, "setStatsUrl called without url");
|
|
346
346
|
call.reject("setStatsUrl called without url");
|
|
347
347
|
return;
|
|
348
348
|
}
|
|
@@ -353,13 +353,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
353
353
|
@PluginMethod
|
|
354
354
|
public void setChannelUrl(final PluginCall call) {
|
|
355
355
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
356
|
-
Log.e(
|
|
356
|
+
Log.e(CapgoUpdater.TAG, "setChannelUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
357
357
|
call.reject("setChannelUrl not allowed");
|
|
358
358
|
return;
|
|
359
359
|
}
|
|
360
360
|
final String url = call.getString("url");
|
|
361
361
|
if (url == null) {
|
|
362
|
-
Log.e(
|
|
362
|
+
Log.e(CapgoUpdater.TAG, "setChannelUrl called without url");
|
|
363
363
|
call.reject("setChannelUrl called without url");
|
|
364
364
|
return;
|
|
365
365
|
}
|
|
@@ -374,7 +374,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
374
374
|
ret.put("version", this.implementation.versionBuild);
|
|
375
375
|
call.resolve(ret);
|
|
376
376
|
} catch (final Exception e) {
|
|
377
|
-
Log.e(
|
|
377
|
+
Log.e(CapgoUpdater.TAG, "Could not get version", e);
|
|
378
378
|
call.reject("Could not get version", e);
|
|
379
379
|
}
|
|
380
380
|
}
|
|
@@ -386,7 +386,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
386
386
|
ret.put("deviceId", this.implementation.deviceID);
|
|
387
387
|
call.resolve(ret);
|
|
388
388
|
} catch (final Exception e) {
|
|
389
|
-
Log.e(
|
|
389
|
+
Log.e(CapgoUpdater.TAG, "Could not get device id", e);
|
|
390
390
|
call.reject("Could not get device id", e);
|
|
391
391
|
}
|
|
392
392
|
}
|
|
@@ -395,7 +395,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
395
395
|
public void setCustomId(final PluginCall call) {
|
|
396
396
|
final String customId = call.getString("customId");
|
|
397
397
|
if (customId == null) {
|
|
398
|
-
Log.e(
|
|
398
|
+
Log.e(CapgoUpdater.TAG, "setCustomId called without customId");
|
|
399
399
|
call.reject("setCustomId called without customId");
|
|
400
400
|
return;
|
|
401
401
|
}
|
|
@@ -409,7 +409,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
409
409
|
ret.put("version", this.PLUGIN_VERSION);
|
|
410
410
|
call.resolve(ret);
|
|
411
411
|
} catch (final Exception e) {
|
|
412
|
-
Log.e(
|
|
412
|
+
Log.e(CapgoUpdater.TAG, "Could not get plugin version", e);
|
|
413
413
|
call.reject("Could not get plugin version", e);
|
|
414
414
|
}
|
|
415
415
|
}
|
|
@@ -419,7 +419,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
419
419
|
final Boolean triggerAutoUpdate = call.getBoolean("triggerAutoUpdate", false);
|
|
420
420
|
|
|
421
421
|
try {
|
|
422
|
-
Log.i(
|
|
422
|
+
Log.i(CapgoUpdater.TAG, "unsetChannel triggerAutoUpdate: " + triggerAutoUpdate);
|
|
423
423
|
startNewThread(() ->
|
|
424
424
|
CapacitorUpdaterPlugin.this.implementation.unsetChannel(res -> {
|
|
425
425
|
JSObject jsRes = mapToJSObject(res);
|
|
@@ -427,7 +427,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
427
427
|
call.reject(jsRes.getString("error"));
|
|
428
428
|
} else {
|
|
429
429
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
430
|
-
Log.i(
|
|
430
|
+
Log.i(CapgoUpdater.TAG, "Calling autoupdater after channel change!");
|
|
431
431
|
backgroundDownload();
|
|
432
432
|
}
|
|
433
433
|
call.resolve(jsRes);
|
|
@@ -435,7 +435,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
435
435
|
})
|
|
436
436
|
);
|
|
437
437
|
} catch (final Exception e) {
|
|
438
|
-
Log.e(
|
|
438
|
+
Log.e(CapgoUpdater.TAG, "Failed to unsetChannel: ", e);
|
|
439
439
|
call.reject("Failed to unsetChannel: ", e);
|
|
440
440
|
}
|
|
441
441
|
}
|
|
@@ -446,12 +446,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
446
446
|
final Boolean triggerAutoUpdate = call.getBoolean("triggerAutoUpdate", false);
|
|
447
447
|
|
|
448
448
|
if (channel == null) {
|
|
449
|
-
Log.e(
|
|
449
|
+
Log.e(CapgoUpdater.TAG, "setChannel called without channel");
|
|
450
450
|
call.reject("setChannel called without channel");
|
|
451
451
|
return;
|
|
452
452
|
}
|
|
453
453
|
try {
|
|
454
|
-
Log.i(
|
|
454
|
+
Log.i(CapgoUpdater.TAG, "setChannel " + channel + " triggerAutoUpdate: " + triggerAutoUpdate);
|
|
455
455
|
startNewThread(() ->
|
|
456
456
|
CapacitorUpdaterPlugin.this.implementation.setChannel(channel, res -> {
|
|
457
457
|
JSObject jsRes = mapToJSObject(res);
|
|
@@ -459,7 +459,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
459
459
|
call.reject(jsRes.getString("error"));
|
|
460
460
|
} else {
|
|
461
461
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
462
|
-
Log.i(
|
|
462
|
+
Log.i(CapgoUpdater.TAG, "Calling autoupdater after channel change!");
|
|
463
463
|
backgroundDownload();
|
|
464
464
|
}
|
|
465
465
|
call.resolve(jsRes);
|
|
@@ -467,7 +467,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
467
467
|
})
|
|
468
468
|
);
|
|
469
469
|
} catch (final Exception e) {
|
|
470
|
-
Log.e(
|
|
470
|
+
Log.e(CapgoUpdater.TAG, "Failed to setChannel: " + channel, e);
|
|
471
471
|
call.reject("Failed to setChannel: " + channel, e);
|
|
472
472
|
}
|
|
473
473
|
}
|
|
@@ -475,7 +475,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
475
475
|
@PluginMethod
|
|
476
476
|
public void getChannel(final PluginCall call) {
|
|
477
477
|
try {
|
|
478
|
-
Log.i(
|
|
478
|
+
Log.i(CapgoUpdater.TAG, "getChannel");
|
|
479
479
|
startNewThread(() ->
|
|
480
480
|
CapacitorUpdaterPlugin.this.implementation.getChannel(res -> {
|
|
481
481
|
JSObject jsRes = mapToJSObject(res);
|
|
@@ -487,7 +487,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
487
487
|
})
|
|
488
488
|
);
|
|
489
489
|
} catch (final Exception e) {
|
|
490
|
-
Log.e(
|
|
490
|
+
Log.e(CapgoUpdater.TAG, "Failed to getChannel", e);
|
|
491
491
|
call.reject("Failed to getChannel", e);
|
|
492
492
|
}
|
|
493
493
|
}
|
|
@@ -499,17 +499,17 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
499
499
|
final String sessionKey = call.getString("sessionKey", "");
|
|
500
500
|
final String checksum = call.getString("checksum", "");
|
|
501
501
|
if (url == null) {
|
|
502
|
-
Log.e(
|
|
502
|
+
Log.e(CapgoUpdater.TAG, "Download called without url");
|
|
503
503
|
call.reject("Download called without url");
|
|
504
504
|
return;
|
|
505
505
|
}
|
|
506
506
|
if (version == null) {
|
|
507
|
-
Log.e(
|
|
507
|
+
Log.e(CapgoUpdater.TAG, "Download called without version");
|
|
508
508
|
call.reject("Download called without version");
|
|
509
509
|
return;
|
|
510
510
|
}
|
|
511
511
|
try {
|
|
512
|
-
Log.i(
|
|
512
|
+
Log.i(CapgoUpdater.TAG, "Downloading " + url);
|
|
513
513
|
startNewThread(() -> {
|
|
514
514
|
try {
|
|
515
515
|
final BundleInfo downloaded = CapacitorUpdaterPlugin.this.implementation.download(url, version, sessionKey, checksum);
|
|
@@ -519,7 +519,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
519
519
|
call.resolve(mapToJSObject(downloaded.toJSONMap()));
|
|
520
520
|
}
|
|
521
521
|
} catch (final Exception e) {
|
|
522
|
-
Log.e(
|
|
522
|
+
Log.e(CapgoUpdater.TAG, "Failed to download from: " + url, e);
|
|
523
523
|
call.reject("Failed to download from: " + url, e);
|
|
524
524
|
final JSObject ret = new JSObject();
|
|
525
525
|
ret.put("version", version);
|
|
@@ -529,7 +529,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
529
529
|
}
|
|
530
530
|
});
|
|
531
531
|
} catch (final Exception e) {
|
|
532
|
-
Log.e(
|
|
532
|
+
Log.e(CapgoUpdater.TAG, "Failed to download from: " + url, e);
|
|
533
533
|
call.reject("Failed to download from: " + url, e);
|
|
534
534
|
final JSObject ret = new JSObject();
|
|
535
535
|
ret.put("version", version);
|
|
@@ -542,7 +542,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
542
542
|
protected boolean _reload() {
|
|
543
543
|
final String path = this.implementation.getCurrentBundlePath();
|
|
544
544
|
this.semaphoreUp();
|
|
545
|
-
Log.i(
|
|
545
|
+
Log.i(CapgoUpdater.TAG, "Reloading: " + path);
|
|
546
546
|
|
|
547
547
|
AtomicReference<URL> url = new AtomicReference<>();
|
|
548
548
|
if (this.keepUrlPathAfterReload) {
|
|
@@ -553,7 +553,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
553
553
|
try {
|
|
554
554
|
url.set(new URL(this.bridge.getWebView().getUrl()));
|
|
555
555
|
} catch (Exception e) {
|
|
556
|
-
Log.e(
|
|
556
|
+
Log.e(CapgoUpdater.TAG, "Error executing on main thread", e);
|
|
557
557
|
}
|
|
558
558
|
mainThreadSemaphore.release();
|
|
559
559
|
});
|
|
@@ -562,11 +562,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
562
562
|
try {
|
|
563
563
|
url.set(new URL(this.bridge.getWebView().getUrl()));
|
|
564
564
|
} catch (Exception e) {
|
|
565
|
-
Log.e(
|
|
565
|
+
Log.e(CapgoUpdater.TAG, "Error executing on main thread", e);
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
} catch (InterruptedException e) {
|
|
569
|
-
Log.e(
|
|
569
|
+
Log.e(CapgoUpdater.TAG, "Error waiting for main thread or getting the current URL from webview", e);
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
572
|
|
|
@@ -588,7 +588,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
588
588
|
this.bridge.getWebView().clearHistory();
|
|
589
589
|
});
|
|
590
590
|
} catch (MalformedURLException e) {
|
|
591
|
-
Log.e(
|
|
591
|
+
Log.e(CapgoUpdater.TAG, "Cannot get finalUrl from capacitor bridge", e);
|
|
592
592
|
|
|
593
593
|
if (this.implementation.isUsingBuiltin()) {
|
|
594
594
|
this.bridge.setServerAssetPath(path);
|
|
@@ -615,11 +615,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
615
615
|
if (this._reload()) {
|
|
616
616
|
call.resolve();
|
|
617
617
|
} else {
|
|
618
|
-
Log.e(
|
|
618
|
+
Log.e(CapgoUpdater.TAG, "Reload failed");
|
|
619
619
|
call.reject("Reload failed");
|
|
620
620
|
}
|
|
621
621
|
} catch (final Exception e) {
|
|
622
|
-
Log.e(
|
|
622
|
+
Log.e(CapgoUpdater.TAG, "Could not reload", e);
|
|
623
623
|
call.reject("Could not reload", e);
|
|
624
624
|
}
|
|
625
625
|
}
|
|
@@ -628,20 +628,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
628
628
|
public void next(final PluginCall call) {
|
|
629
629
|
final String id = call.getString("id");
|
|
630
630
|
if (id == null) {
|
|
631
|
-
Log.e(
|
|
631
|
+
Log.e(CapgoUpdater.TAG, "Next called without id");
|
|
632
632
|
call.reject("Next called without id");
|
|
633
633
|
return;
|
|
634
634
|
}
|
|
635
635
|
try {
|
|
636
|
-
Log.i(
|
|
636
|
+
Log.i(CapgoUpdater.TAG, "Setting next active id " + id);
|
|
637
637
|
if (!this.implementation.setNextBundle(id)) {
|
|
638
|
-
Log.e(
|
|
638
|
+
Log.e(CapgoUpdater.TAG, "Set next id failed. Bundle " + id + " does not exist.");
|
|
639
639
|
call.reject("Set next id failed. Bundle " + id + " does not exist.");
|
|
640
640
|
} else {
|
|
641
641
|
call.resolve(mapToJSObject(this.implementation.getBundleInfo(id).toJSONMap()));
|
|
642
642
|
}
|
|
643
643
|
} catch (final Exception e) {
|
|
644
|
-
Log.e(
|
|
644
|
+
Log.e(CapgoUpdater.TAG, "Could not set next id " + id, e);
|
|
645
645
|
call.reject("Could not set next id: " + id, e);
|
|
646
646
|
}
|
|
647
647
|
}
|
|
@@ -650,21 +650,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
650
650
|
public void set(final PluginCall call) {
|
|
651
651
|
final String id = call.getString("id");
|
|
652
652
|
if (id == null) {
|
|
653
|
-
Log.e(
|
|
653
|
+
Log.e(CapgoUpdater.TAG, "Set called without id");
|
|
654
654
|
call.reject("Set called without id");
|
|
655
655
|
return;
|
|
656
656
|
}
|
|
657
657
|
try {
|
|
658
|
-
Log.i(
|
|
658
|
+
Log.i(CapgoUpdater.TAG, "Setting active bundle " + id);
|
|
659
659
|
if (!this.implementation.set(id)) {
|
|
660
|
-
Log.i(
|
|
660
|
+
Log.i(CapgoUpdater.TAG, "No such bundle " + id);
|
|
661
661
|
call.reject("Update failed, id " + id + " does not exist.");
|
|
662
662
|
} else {
|
|
663
|
-
Log.i(
|
|
663
|
+
Log.i(CapgoUpdater.TAG, "Bundle successfully set to " + id);
|
|
664
664
|
this.reload(call);
|
|
665
665
|
}
|
|
666
666
|
} catch (final Exception e) {
|
|
667
|
-
Log.e(
|
|
667
|
+
Log.e(CapgoUpdater.TAG, "Could not set id " + id, e);
|
|
668
668
|
call.reject("Could not set id " + id, e);
|
|
669
669
|
}
|
|
670
670
|
}
|
|
@@ -673,21 +673,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
673
673
|
public void delete(final PluginCall call) {
|
|
674
674
|
final String id = call.getString("id");
|
|
675
675
|
if (id == null) {
|
|
676
|
-
Log.e(
|
|
676
|
+
Log.e(CapgoUpdater.TAG, "missing id");
|
|
677
677
|
call.reject("missing id");
|
|
678
678
|
return;
|
|
679
679
|
}
|
|
680
|
-
Log.i(
|
|
680
|
+
Log.i(CapgoUpdater.TAG, "Deleting id " + id);
|
|
681
681
|
try {
|
|
682
682
|
final Boolean res = this.implementation.delete(id);
|
|
683
683
|
if (res) {
|
|
684
684
|
call.resolve();
|
|
685
685
|
} else {
|
|
686
|
-
Log.e(
|
|
686
|
+
Log.e(CapgoUpdater.TAG, "Delete failed, id " + id + " does not exist");
|
|
687
687
|
call.reject("Delete failed, id " + id + " does not exist or it cannot be deleted (perhaps it is the 'next' bundle)");
|
|
688
688
|
}
|
|
689
689
|
} catch (final Exception e) {
|
|
690
|
-
Log.e(
|
|
690
|
+
Log.e(CapgoUpdater.TAG, "Could not delete id " + id, e);
|
|
691
691
|
call.reject("Could not delete id " + id, e);
|
|
692
692
|
}
|
|
693
693
|
}
|
|
@@ -704,7 +704,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
704
704
|
ret.put("bundles", values);
|
|
705
705
|
call.resolve(ret);
|
|
706
706
|
} catch (final Exception e) {
|
|
707
|
-
Log.e(
|
|
707
|
+
Log.e(CapgoUpdater.TAG, "Could not list bundles", e);
|
|
708
708
|
call.reject("Could not list bundles", e);
|
|
709
709
|
}
|
|
710
710
|
}
|
|
@@ -733,11 +733,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
733
733
|
this.implementation.reset();
|
|
734
734
|
|
|
735
735
|
if (toLastSuccessful && !fallback.isBuiltin()) {
|
|
736
|
-
Log.i(
|
|
736
|
+
Log.i(CapgoUpdater.TAG, "Resetting to: " + fallback);
|
|
737
737
|
return this.implementation.set(fallback) && this._reload();
|
|
738
738
|
}
|
|
739
739
|
|
|
740
|
-
Log.i(
|
|
740
|
+
Log.i(CapgoUpdater.TAG, "Resetting to native.");
|
|
741
741
|
return this._reload();
|
|
742
742
|
}
|
|
743
743
|
|
|
@@ -749,10 +749,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
749
749
|
call.resolve();
|
|
750
750
|
return;
|
|
751
751
|
}
|
|
752
|
-
Log.e(
|
|
752
|
+
Log.e(CapgoUpdater.TAG, "Reset failed");
|
|
753
753
|
call.reject("Reset failed");
|
|
754
754
|
} catch (final Exception e) {
|
|
755
|
-
Log.e(
|
|
755
|
+
Log.e(CapgoUpdater.TAG, "Reset failed", e);
|
|
756
756
|
call.reject("Reset failed", e);
|
|
757
757
|
}
|
|
758
758
|
}
|
|
@@ -766,7 +766,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
766
766
|
ret.put("native", this.currentVersionNative);
|
|
767
767
|
call.resolve(ret);
|
|
768
768
|
} catch (final Exception e) {
|
|
769
|
-
Log.e(
|
|
769
|
+
Log.e(CapgoUpdater.TAG, "Could not get current bundle", e);
|
|
770
770
|
call.reject("Could not get current bundle", e);
|
|
771
771
|
}
|
|
772
772
|
}
|
|
@@ -782,7 +782,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
782
782
|
|
|
783
783
|
call.resolve(mapToJSObject(bundle.toJSONMap()));
|
|
784
784
|
} catch (final Exception e) {
|
|
785
|
-
Log.e(
|
|
785
|
+
Log.e(CapgoUpdater.TAG, "Could not get next bundle", e);
|
|
786
786
|
call.reject("Could not get next bundle", e);
|
|
787
787
|
}
|
|
788
788
|
}
|
|
@@ -800,18 +800,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
800
800
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
801
801
|
JSObject jsRes = mapToJSObject(res);
|
|
802
802
|
if (jsRes.has("error")) {
|
|
803
|
-
Log.e(
|
|
803
|
+
Log.e(CapgoUpdater.TAG, Objects.requireNonNull(jsRes.getString("error")));
|
|
804
804
|
} else if (jsRes.has("version")) {
|
|
805
805
|
String newVersion = jsRes.getString("version");
|
|
806
806
|
String currentVersion = String.valueOf(CapacitorUpdaterPlugin.this.implementation.getCurrentBundle());
|
|
807
807
|
if (!Objects.equals(newVersion, currentVersion)) {
|
|
808
|
-
Log.i(
|
|
808
|
+
Log.i(CapgoUpdater.TAG, "New version found: " + newVersion);
|
|
809
809
|
CapacitorUpdaterPlugin.this.backgroundDownload();
|
|
810
810
|
}
|
|
811
811
|
}
|
|
812
812
|
});
|
|
813
813
|
} catch (final Exception e) {
|
|
814
|
-
Log.e(
|
|
814
|
+
Log.e(CapgoUpdater.TAG, "Failed to check for update", e);
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
817
|
},
|
|
@@ -825,15 +825,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
825
825
|
try {
|
|
826
826
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
827
827
|
this.implementation.setSuccess(bundle, this.autoDeletePrevious);
|
|
828
|
-
Log.i(
|
|
829
|
-
Log.i(
|
|
828
|
+
Log.i(CapgoUpdater.TAG, "Current bundle loaded successfully. ['notifyAppReady()' was called] " + bundle);
|
|
829
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady countDown");
|
|
830
830
|
this.semaphoreDown();
|
|
831
|
-
Log.i(
|
|
831
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady countDown done");
|
|
832
832
|
final JSObject ret = new JSObject();
|
|
833
833
|
ret.put("bundle", mapToJSObject(bundle.toJSONMap()));
|
|
834
834
|
call.resolve(ret);
|
|
835
835
|
} catch (final Exception e) {
|
|
836
|
-
Log.e(
|
|
836
|
+
Log.e(CapgoUpdater.TAG, "Failed to notify app ready state. [Error calling 'notifyAppReady()']", e);
|
|
837
837
|
call.reject("Failed to commit app ready state.", e);
|
|
838
838
|
}
|
|
839
839
|
}
|
|
@@ -843,7 +843,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
843
843
|
try {
|
|
844
844
|
final JSONArray delayConditions = call.getData().optJSONArray("delayConditions");
|
|
845
845
|
if (delayConditions == null) {
|
|
846
|
-
Log.e(
|
|
846
|
+
Log.e(CapgoUpdater.TAG, "setMultiDelay called without delayCondition");
|
|
847
847
|
call.reject("setMultiDelay called without delayCondition");
|
|
848
848
|
return;
|
|
849
849
|
}
|
|
@@ -861,7 +861,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
861
861
|
call.reject("Failed to delay update");
|
|
862
862
|
}
|
|
863
863
|
} catch (final Exception e) {
|
|
864
|
-
Log.e(
|
|
864
|
+
Log.e(CapgoUpdater.TAG, "Failed to delay update, [Error calling 'setMultiDelay()']", e);
|
|
865
865
|
call.reject("Failed to delay update", e);
|
|
866
866
|
}
|
|
867
867
|
}
|
|
@@ -880,7 +880,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
880
880
|
String serverUrl = config.getServerUrl();
|
|
881
881
|
if (serverUrl != null && !serverUrl.isEmpty()) {
|
|
882
882
|
// log warning autoupdate disabled when serverUrl is set
|
|
883
|
-
Log.w(
|
|
883
|
+
Log.w(CapgoUpdater.TAG, "AutoUpdate is automatic disabled when serverUrl is set.");
|
|
884
884
|
}
|
|
885
885
|
return (
|
|
886
886
|
CapacitorUpdaterPlugin.this.autoUpdate &&
|
|
@@ -896,7 +896,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
896
896
|
ret.put("enabled", this._isAutoUpdateEnabled());
|
|
897
897
|
call.resolve(ret);
|
|
898
898
|
} catch (final Exception e) {
|
|
899
|
-
Log.e(
|
|
899
|
+
Log.e(CapgoUpdater.TAG, "Could not get autoUpdate status", e);
|
|
900
900
|
call.reject("Could not get autoUpdate status", e);
|
|
901
901
|
}
|
|
902
902
|
}
|
|
@@ -910,7 +910,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
910
910
|
ret.put("available", serverUrl == null || serverUrl.isEmpty());
|
|
911
911
|
call.resolve(ret);
|
|
912
912
|
} catch (final Exception e) {
|
|
913
|
-
Log.e(
|
|
913
|
+
Log.e(CapgoUpdater.TAG, "Could not get autoUpdate availability", e);
|
|
914
914
|
call.reject("Could not get autoUpdate availability", e);
|
|
915
915
|
}
|
|
916
916
|
}
|
|
@@ -922,7 +922,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
922
922
|
}
|
|
923
923
|
this.appReadyCheck = startNewThread(new DeferredNotifyAppReadyCheck());
|
|
924
924
|
} catch (final Exception e) {
|
|
925
|
-
Log.e(
|
|
925
|
+
Log.e(CapgoUpdater.TAG, "Failed to start " + DeferredNotifyAppReadyCheck.class.getName(), e);
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
928
|
|
|
@@ -938,7 +938,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
938
938
|
private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
|
|
939
939
|
if (error) {
|
|
940
940
|
Log.i(
|
|
941
|
-
|
|
941
|
+
CapgoUpdater.TAG,
|
|
942
942
|
"endBackGroundTaskWithNotif error: " +
|
|
943
943
|
error +
|
|
944
944
|
" current: " +
|
|
@@ -956,7 +956,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
956
956
|
this.notifyListeners("noNeedUpdate", ret);
|
|
957
957
|
this.sendReadyToJs(current, msg);
|
|
958
958
|
this.backgroundDownloadTask = null;
|
|
959
|
-
Log.i(
|
|
959
|
+
Log.i(CapgoUpdater.TAG, "endBackGroundTaskWithNotif " + msg);
|
|
960
960
|
}
|
|
961
961
|
|
|
962
962
|
private Thread backgroundDownload() {
|
|
@@ -964,13 +964,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
964
964
|
? "Update will occur now."
|
|
965
965
|
: "Update will occur next time app moves to background.";
|
|
966
966
|
return startNewThread(() -> {
|
|
967
|
-
Log.i(
|
|
967
|
+
Log.i(CapgoUpdater.TAG, "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
968
968
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
969
969
|
JSObject jsRes = mapToJSObject(res);
|
|
970
970
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
971
971
|
try {
|
|
972
972
|
if (jsRes.has("message")) {
|
|
973
|
-
Log.i(
|
|
973
|
+
Log.i(CapgoUpdater.TAG, "API message: " + jsRes.get("message"));
|
|
974
974
|
if (jsRes.has("major") && jsRes.getBoolean("major") && jsRes.has("version")) {
|
|
975
975
|
final JSObject majorAvailable = new JSObject();
|
|
976
976
|
majorAvailable.put("version", jsRes.getString("version"));
|
|
@@ -988,9 +988,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
988
988
|
final String latestVersionName = jsRes.getString("version");
|
|
989
989
|
|
|
990
990
|
if ("builtin".equals(latestVersionName)) {
|
|
991
|
-
Log.i(
|
|
991
|
+
Log.i(CapgoUpdater.TAG, "Latest version is builtin");
|
|
992
992
|
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
|
|
993
|
-
Log.i(
|
|
993
|
+
Log.i(CapgoUpdater.TAG, "Direct update to builtin version");
|
|
994
994
|
this._reset(false);
|
|
995
995
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
996
996
|
"Updated to builtin version",
|
|
@@ -999,7 +999,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
999
999
|
false
|
|
1000
1000
|
);
|
|
1001
1001
|
} else {
|
|
1002
|
-
Log.i(
|
|
1002
|
+
Log.i(CapgoUpdater.TAG, "Setting next bundle to builtin");
|
|
1003
1003
|
CapacitorUpdaterPlugin.this.implementation.setNextBundle(BundleInfo.ID_BUILTIN);
|
|
1004
1004
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1005
1005
|
"Next update will be to builtin version",
|
|
@@ -1012,7 +1012,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1012
1012
|
}
|
|
1013
1013
|
|
|
1014
1014
|
if (!jsRes.has("url") || !CapacitorUpdaterPlugin.this.isValidURL(jsRes.getString("url"))) {
|
|
1015
|
-
Log.e(
|
|
1015
|
+
Log.e(CapgoUpdater.TAG, "Error no url or wrong format");
|
|
1016
1016
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1017
1017
|
"Error no url or wrong format",
|
|
1018
1018
|
current.getVersionName(),
|
|
@@ -1030,7 +1030,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1030
1030
|
final JSObject ret = new JSObject();
|
|
1031
1031
|
ret.put("bundle", mapToJSObject(latest.toJSONMap()));
|
|
1032
1032
|
if (latest.isErrorStatus()) {
|
|
1033
|
-
Log.e(
|
|
1033
|
+
Log.e(CapgoUpdater.TAG, "Latest bundle already exists, and is in error state. Aborting update.");
|
|
1034
1034
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1035
1035
|
"Latest bundle already exists, and is in error state. Aborting update.",
|
|
1036
1036
|
latestVersionName,
|
|
@@ -1040,17 +1040,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1040
1040
|
return;
|
|
1041
1041
|
}
|
|
1042
1042
|
if (latest.isDownloaded()) {
|
|
1043
|
-
Log.i(
|
|
1044
|
-
CapacitorUpdater.TAG,
|
|
1045
|
-
"Latest bundle already exists and download is NOT required. " + messageUpdate
|
|
1046
|
-
);
|
|
1043
|
+
Log.i(CapgoUpdater.TAG, "Latest bundle already exists and download is NOT required. " + messageUpdate);
|
|
1047
1044
|
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
|
|
1048
1045
|
Gson gson = new Gson();
|
|
1049
1046
|
String delayUpdatePreferences = prefs.getString(DelayUpdateUtils.DELAY_CONDITION_PREFERENCES, "[]");
|
|
1050
1047
|
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1051
1048
|
ArrayList<DelayCondition> delayConditionList = gson.fromJson(delayUpdatePreferences, type);
|
|
1052
1049
|
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1053
|
-
Log.i(
|
|
1050
|
+
Log.i(CapgoUpdater.TAG, "Update delayed until delay conditions met");
|
|
1054
1051
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1055
1052
|
"Update delayed until delay conditions met",
|
|
1056
1053
|
latestVersionName,
|
|
@@ -1081,23 +1078,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1081
1078
|
}
|
|
1082
1079
|
if (latest.isDeleted()) {
|
|
1083
1080
|
Log.i(
|
|
1084
|
-
|
|
1081
|
+
CapgoUpdater.TAG,
|
|
1085
1082
|
"Latest bundle already exists and will be deleted, download will overwrite it."
|
|
1086
1083
|
);
|
|
1087
1084
|
try {
|
|
1088
1085
|
final Boolean deleted = CapacitorUpdaterPlugin.this.implementation.delete(latest.getId(), true);
|
|
1089
1086
|
if (deleted) {
|
|
1090
|
-
Log.i(
|
|
1087
|
+
Log.i(CapgoUpdater.TAG, "Failed bundle deleted: " + latest.getVersionName());
|
|
1091
1088
|
}
|
|
1092
1089
|
} catch (final IOException e) {
|
|
1093
|
-
Log.e(
|
|
1090
|
+
Log.e(CapgoUpdater.TAG, "Failed to delete failed bundle: " + latest.getVersionName(), e);
|
|
1094
1091
|
}
|
|
1095
1092
|
}
|
|
1096
1093
|
}
|
|
1097
1094
|
startNewThread(() -> {
|
|
1098
1095
|
try {
|
|
1099
1096
|
Log.i(
|
|
1100
|
-
|
|
1097
|
+
CapgoUpdater.TAG,
|
|
1101
1098
|
"New bundle: " +
|
|
1102
1099
|
latestVersionName +
|
|
1103
1100
|
" found. Current is: " +
|
|
@@ -1131,7 +1128,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1131
1128
|
);
|
|
1132
1129
|
}
|
|
1133
1130
|
} catch (final Exception e) {
|
|
1134
|
-
Log.e(
|
|
1131
|
+
Log.e(CapgoUpdater.TAG, "error downloading file", e);
|
|
1135
1132
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1136
1133
|
"Error downloading file",
|
|
1137
1134
|
latestVersionName,
|
|
@@ -1141,11 +1138,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1141
1138
|
}
|
|
1142
1139
|
});
|
|
1143
1140
|
} else {
|
|
1144
|
-
Log.i(
|
|
1141
|
+
Log.i(CapgoUpdater.TAG, "No need to update, " + current.getId() + " is the latest bundle.");
|
|
1145
1142
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif("No need to update", latestVersionName, current, false);
|
|
1146
1143
|
}
|
|
1147
1144
|
} catch (final JSONException e) {
|
|
1148
|
-
Log.e(
|
|
1145
|
+
Log.e(CapgoUpdater.TAG, "error parsing JSON", e);
|
|
1149
1146
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1150
1147
|
"Error parsing JSON",
|
|
1151
1148
|
current.getVersionName(),
|
|
@@ -1164,7 +1161,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1164
1161
|
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1165
1162
|
ArrayList<DelayCondition> delayConditionList = gson.fromJson(delayUpdatePreferences, type);
|
|
1166
1163
|
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1167
|
-
Log.i(
|
|
1164
|
+
Log.i(CapgoUpdater.TAG, "Update delayed until delay conditions met");
|
|
1168
1165
|
return;
|
|
1169
1166
|
}
|
|
1170
1167
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
@@ -1172,16 +1169,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1172
1169
|
|
|
1173
1170
|
if (next != null && !next.isErrorStatus() && !next.getId().equals(current.getId())) {
|
|
1174
1171
|
// There is a next bundle waiting for activation
|
|
1175
|
-
Log.d(
|
|
1172
|
+
Log.d(CapgoUpdater.TAG, "Next bundle is: " + next.getVersionName());
|
|
1176
1173
|
if (this.implementation.set(next) && this._reload()) {
|
|
1177
|
-
Log.i(
|
|
1174
|
+
Log.i(CapgoUpdater.TAG, "Updated to bundle: " + next.getVersionName());
|
|
1178
1175
|
this.implementation.setNextBundle(null);
|
|
1179
1176
|
} else {
|
|
1180
|
-
Log.e(
|
|
1177
|
+
Log.e(CapgoUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
|
|
1181
1178
|
}
|
|
1182
1179
|
}
|
|
1183
1180
|
} catch (final Exception e) {
|
|
1184
|
-
Log.e(
|
|
1181
|
+
Log.e(CapgoUpdater.TAG, "Error during onActivityStopped", e);
|
|
1185
1182
|
}
|
|
1186
1183
|
}
|
|
1187
1184
|
|
|
@@ -1190,14 +1187,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1190
1187
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
1191
1188
|
|
|
1192
1189
|
if (current.isBuiltin()) {
|
|
1193
|
-
Log.i(
|
|
1190
|
+
Log.i(CapgoUpdater.TAG, "Built-in bundle is active. We skip the check for notifyAppReady.");
|
|
1194
1191
|
return;
|
|
1195
1192
|
}
|
|
1196
|
-
Log.d(
|
|
1193
|
+
Log.d(CapgoUpdater.TAG, "Current bundle is: " + current);
|
|
1197
1194
|
|
|
1198
1195
|
if (BundleStatus.SUCCESS != current.getStatus()) {
|
|
1199
|
-
Log.e(
|
|
1200
|
-
Log.i(
|
|
1196
|
+
Log.e(CapgoUpdater.TAG, "notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
1197
|
+
Log.i(CapgoUpdater.TAG, "Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
1201
1198
|
final JSObject ret = new JSObject();
|
|
1202
1199
|
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
1203
1200
|
this.notifyListeners("updateFailed", ret);
|
|
@@ -1205,18 +1202,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1205
1202
|
this.implementation.setError(current);
|
|
1206
1203
|
this._reset(true);
|
|
1207
1204
|
if (CapacitorUpdaterPlugin.this.autoDeleteFailed && !current.isBuiltin()) {
|
|
1208
|
-
Log.i(
|
|
1205
|
+
Log.i(CapgoUpdater.TAG, "Deleting failing bundle: " + current.getVersionName());
|
|
1209
1206
|
try {
|
|
1210
1207
|
final Boolean res = this.implementation.delete(current.getId(), false);
|
|
1211
1208
|
if (res) {
|
|
1212
|
-
Log.i(
|
|
1209
|
+
Log.i(CapgoUpdater.TAG, "Failed bundle deleted: " + current.getVersionName());
|
|
1213
1210
|
}
|
|
1214
1211
|
} catch (final IOException e) {
|
|
1215
|
-
Log.e(
|
|
1212
|
+
Log.e(CapgoUpdater.TAG, "Failed to delete failed bundle: " + current.getVersionName(), e);
|
|
1216
1213
|
}
|
|
1217
1214
|
}
|
|
1218
1215
|
} else {
|
|
1219
|
-
Log.i(
|
|
1216
|
+
Log.i(CapgoUpdater.TAG, "notifyAppReady was called. This is fine: " + current.getId());
|
|
1220
1217
|
}
|
|
1221
1218
|
}
|
|
1222
1219
|
|
|
@@ -1225,15 +1222,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1225
1222
|
@Override
|
|
1226
1223
|
public void run() {
|
|
1227
1224
|
try {
|
|
1228
|
-
Log.i(
|
|
1229
|
-
CapacitorUpdater.TAG,
|
|
1230
|
-
"Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady"
|
|
1231
|
-
);
|
|
1225
|
+
Log.i(CapgoUpdater.TAG, "Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady");
|
|
1232
1226
|
Thread.sleep(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
1233
1227
|
CapacitorUpdaterPlugin.this.checkRevert();
|
|
1234
1228
|
CapacitorUpdaterPlugin.this.appReadyCheck = null;
|
|
1235
1229
|
} catch (final InterruptedException e) {
|
|
1236
|
-
Log.i(
|
|
1230
|
+
Log.i(CapgoUpdater.TAG, DeferredNotifyAppReadyCheck.class.getName() + " was interrupted.");
|
|
1237
1231
|
}
|
|
1238
1232
|
}
|
|
1239
1233
|
}
|
|
@@ -1249,7 +1243,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1249
1243
|
) {
|
|
1250
1244
|
this.backgroundDownloadTask = this.backgroundDownload();
|
|
1251
1245
|
} else {
|
|
1252
|
-
Log.i(
|
|
1246
|
+
Log.i(CapgoUpdater.TAG, "Auto update is disabled");
|
|
1253
1247
|
this.sendReadyToJs(current, "disabled");
|
|
1254
1248
|
}
|
|
1255
1249
|
this.checkAppReady();
|
|
@@ -1258,14 +1252,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1258
1252
|
public void appMovedToBackground() {
|
|
1259
1253
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1260
1254
|
CapacitorUpdaterPlugin.this.implementation.sendStats("app_moved_to_background", current.getVersionName());
|
|
1261
|
-
Log.i(
|
|
1255
|
+
Log.i(CapgoUpdater.TAG, "Checking for pending update");
|
|
1262
1256
|
try {
|
|
1263
1257
|
// We need to set "backgrounded time"
|
|
1264
1258
|
this.delayUpdateUtils.setBackgroundTimestamp(System.currentTimeMillis());
|
|
1265
1259
|
this.delayUpdateUtils.checkCancelDelay(DelayUpdateUtils.CancelDelaySource.BACKGROUND);
|
|
1266
1260
|
this.installNext();
|
|
1267
1261
|
} catch (final Exception e) {
|
|
1268
|
-
Log.e(
|
|
1262
|
+
Log.e(CapgoUpdater.TAG, "Error during onActivityStopped", e);
|
|
1269
1263
|
}
|
|
1270
1264
|
}
|
|
1271
1265
|
|
|
@@ -1293,7 +1287,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1293
1287
|
}
|
|
1294
1288
|
|
|
1295
1289
|
private void appKilled() {
|
|
1296
|
-
Log.d(
|
|
1290
|
+
Log.d(CapgoUpdater.TAG, "onActivityDestroyed: all activity destroyed");
|
|
1297
1291
|
this.delayUpdateUtils.checkCancelDelay(DelayUpdateUtils.CancelDelaySource.KILLED);
|
|
1298
1292
|
}
|
|
1299
1293
|
|
|
@@ -1302,7 +1296,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1302
1296
|
if (isPreviousMainActivity) {
|
|
1303
1297
|
this.appMovedToForeground();
|
|
1304
1298
|
}
|
|
1305
|
-
Log.i(
|
|
1299
|
+
Log.i(CapgoUpdater.TAG, "onActivityStarted " + getActivity().getClass().getName());
|
|
1306
1300
|
isPreviousMainActivity = true;
|
|
1307
1301
|
}
|
|
1308
1302
|
|
|
@@ -1329,7 +1323,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1329
1323
|
|
|
1330
1324
|
@Override
|
|
1331
1325
|
public void handleOnDestroy() {
|
|
1332
|
-
Log.i(
|
|
1326
|
+
Log.i(CapgoUpdater.TAG, "onActivityDestroyed " + getActivity().getClass().getName());
|
|
1333
1327
|
this.implementation.activity = getActivity();
|
|
1334
1328
|
counterActivityCreate--;
|
|
1335
1329
|
if (counterActivityCreate == 0) {
|