@capgo/capacitor-updater 8.51.11 → 8.51.12
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 +1 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +7 -63
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +3 -3
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +10 -29
- package/package.json +1 -1
|
@@ -146,7 +146,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
146
146
|
static final int APPLICATION_EXIT_REASON_USER_REQUESTED = 10;
|
|
147
147
|
static final int APPLICATION_EXIT_REASON_DEPENDENCY_DIED = 12;
|
|
148
148
|
|
|
149
|
-
private final String pluginVersion = "8.51.
|
|
149
|
+
private final String pluginVersion = "8.51.12";
|
|
150
150
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
151
151
|
|
|
152
152
|
private SharedPreferences.Editor editor;
|
|
@@ -12,11 +12,9 @@ package ee.forgr.capacitor_updater;
|
|
|
12
12
|
* references: http://stackoverflow.com/questions/12471999/rsa-encryption-decryption-in-android
|
|
13
13
|
*/
|
|
14
14
|
import android.util.Base64;
|
|
15
|
-
import java.io.BufferedReader;
|
|
16
15
|
import java.io.File;
|
|
17
16
|
import java.io.FileInputStream;
|
|
18
17
|
import java.io.FileOutputStream;
|
|
19
|
-
import java.io.FileReader;
|
|
20
18
|
import java.io.IOException;
|
|
21
19
|
import java.io.InputStream;
|
|
22
20
|
import java.security.GeneralSecurityException;
|
|
@@ -174,8 +172,7 @@ public class CryptoCipher {
|
|
|
174
172
|
File tempFile = File.createTempFile("capgo-aes-", ".tmp", file.getParentFile());
|
|
175
173
|
try {
|
|
176
174
|
byte[] inBuf = new byte[ioBufferBytes()];
|
|
177
|
-
// Reuse one output buffer. cipher.update(in) allocates a new byte[] per chunk
|
|
178
|
-
// and 64 workers * 5MB was why AES barely won on heap in local benches.
|
|
175
|
+
// Reuse one output buffer. cipher.update(in) allocates a new byte[] per chunk.
|
|
179
176
|
byte[] outBuf = new byte[inBuf.length + 16];
|
|
180
177
|
try (FileInputStream fis = new FileInputStream(file); FileOutputStream fos = new FileOutputStream(tempFile)) {
|
|
181
178
|
int n;
|
|
@@ -330,73 +327,20 @@ public class CryptoCipher {
|
|
|
330
327
|
}
|
|
331
328
|
}
|
|
332
329
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
private static final long EIGHT_GIB = 8L * 1024 * 1024 * 1024;
|
|
337
|
-
private static final int FLAGSHIP_IO_BUFFER_BYTES = 5 * 1024 * 1024;
|
|
338
|
-
private static volatile long cachedPhysicalRamBytes = -1;
|
|
339
|
-
|
|
340
|
-
// Checksum and copy share one ladder. 64-wide peak RAM = 64 * buffer.
|
|
341
|
-
// <2GB: 64KB. <3GB: 256KB. <4GB: 512KB. <8GB: 1MB. Else 5MB (flagship / unknown).
|
|
342
|
-
static int ioBufferBytes(long physicalRamBytes) {
|
|
343
|
-
if (physicalRamBytes <= 0) {
|
|
344
|
-
return FLAGSHIP_IO_BUFFER_BYTES;
|
|
345
|
-
}
|
|
346
|
-
if (physicalRamBytes < TWO_GIB) {
|
|
347
|
-
return 64 * 1024;
|
|
348
|
-
}
|
|
349
|
-
if (physicalRamBytes < THREE_GIB) {
|
|
350
|
-
return 256 * 1024;
|
|
351
|
-
}
|
|
352
|
-
if (physicalRamBytes < FOUR_GIB) {
|
|
353
|
-
return 512 * 1024;
|
|
354
|
-
}
|
|
355
|
-
if (physicalRamBytes < EIGHT_GIB) {
|
|
356
|
-
return 1024 * 1024;
|
|
357
|
-
}
|
|
358
|
-
return FLAGSHIP_IO_BUFFER_BYTES;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
static int checksumBufferBytes(long physicalRamBytes) {
|
|
362
|
-
return ioBufferBytes(physicalRamBytes);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
static int copyBufferBytes(long physicalRamBytes) {
|
|
366
|
-
return ioBufferBytes(physicalRamBytes);
|
|
367
|
-
}
|
|
330
|
+
// 256 KiB: one size for checksum, copy, and decode.
|
|
331
|
+
// 64 workers * 256 KiB = 16 MiB for one buffer; AES/Brotli hold two (~32 MiB).
|
|
332
|
+
static final int IO_BUFFER_BYTES = 256 * 1024;
|
|
368
333
|
|
|
369
334
|
static int ioBufferBytes() {
|
|
370
|
-
return
|
|
335
|
+
return IO_BUFFER_BYTES;
|
|
371
336
|
}
|
|
372
337
|
|
|
373
338
|
static int checksumBufferBytes() {
|
|
374
|
-
return
|
|
339
|
+
return IO_BUFFER_BYTES;
|
|
375
340
|
}
|
|
376
341
|
|
|
377
342
|
static int copyBufferBytes() {
|
|
378
|
-
return
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
static long physicalRamBytes() {
|
|
382
|
-
long cached = cachedPhysicalRamBytes;
|
|
383
|
-
if (cached >= 0) {
|
|
384
|
-
return cached;
|
|
385
|
-
}
|
|
386
|
-
long parsed = 0;
|
|
387
|
-
try (BufferedReader reader = new BufferedReader(new FileReader("/proc/meminfo"))) {
|
|
388
|
-
String line = reader.readLine();
|
|
389
|
-
if (line != null && line.startsWith("MemTotal:")) {
|
|
390
|
-
String[] parts = line.split("\\s+");
|
|
391
|
-
if (parts.length >= 2) {
|
|
392
|
-
parsed = Long.parseLong(parts[1]) * 1024L;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
} catch (Exception ignored) {
|
|
396
|
-
parsed = 0;
|
|
397
|
-
}
|
|
398
|
-
cachedPhysicalRamBytes = parsed;
|
|
399
|
-
return parsed;
|
|
343
|
+
return IO_BUFFER_BYTES;
|
|
400
344
|
}
|
|
401
345
|
|
|
402
346
|
public static String calcChecksum(File file) {
|
|
@@ -1047,14 +1047,14 @@ public class DownloadService extends Worker {
|
|
|
1047
1047
|
}
|
|
1048
1048
|
|
|
1049
1049
|
/**
|
|
1050
|
-
* Atomically write a stream to a file using the
|
|
1050
|
+
* Atomically write a stream to a file using the 256 KiB IO buffer.
|
|
1051
1051
|
*/
|
|
1052
1052
|
static void writeFileAtomic(File targetFile, InputStream inputStream, String expectedChecksum) throws IOException {
|
|
1053
1053
|
File tempFile = File.createTempFile("capgo-", ".tmp", targetFile.getParentFile());
|
|
1054
1054
|
|
|
1055
1055
|
try {
|
|
1056
|
-
// Okio's default segment is
|
|
1057
|
-
//
|
|
1056
|
+
// Okio's default segment is 8 KiB. Copy with 256 KiB so 8 MiB wrapper unwraps
|
|
1057
|
+
// are not 1000 tiny writes.
|
|
1058
1058
|
byte[] buffer = new byte[CryptoCipher.ioBufferBytes()];
|
|
1059
1059
|
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
|
|
1060
1060
|
int n;
|
|
@@ -96,7 +96,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
96
96
|
deinit {
|
|
97
97
|
implementation.shutdown()
|
|
98
98
|
}
|
|
99
|
-
private let pluginVersion: String = "8.51.
|
|
99
|
+
private let pluginVersion: String = "8.51.12"
|
|
100
100
|
private let launchStartedAtMs = Int64(Date().timeIntervalSince1970 * 1000)
|
|
101
101
|
static let updateUrlDefault = "https://plugin.capgo.app/updates"
|
|
102
102
|
static let statsUrlDefault = "https://plugin.capgo.app/stats"
|
|
@@ -141,39 +141,20 @@ public struct CryptoCipher {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
/// Checksum and copy share one ladder. 64-wide peak RAM = 64 * buffer.
|
|
151
|
-
/// <2GB: 64KB. <3GB: 256KB. <4GB: 512KB. <8GB: 1MB. Else 5MB (flagship / unknown).
|
|
152
|
-
static func ioBufferBytes(_ physicalRamBytes: UInt64 = ProcessInfo.processInfo.physicalMemory) -> Int {
|
|
153
|
-
if physicalRamBytes == 0 {
|
|
154
|
-
return flagshipIoBufferBytes
|
|
155
|
-
}
|
|
156
|
-
if physicalRamBytes < twoGiB {
|
|
157
|
-
return 64 * 1024
|
|
158
|
-
}
|
|
159
|
-
if physicalRamBytes < threeGiB {
|
|
160
|
-
return 256 * 1024
|
|
161
|
-
}
|
|
162
|
-
if physicalRamBytes < fourGiB {
|
|
163
|
-
return 512 * 1024
|
|
164
|
-
}
|
|
165
|
-
if physicalRamBytes < eightGiB {
|
|
166
|
-
return 1024 * 1024
|
|
167
|
-
}
|
|
168
|
-
return flagshipIoBufferBytes
|
|
144
|
+
/// 256 KiB: one size for checksum, copy, and decode.
|
|
145
|
+
/// 64 workers * 256 KiB = 16 MiB for one buffer; AES/Brotli hold two (~32 MiB).
|
|
146
|
+
static let ioBufferBytesValue = 256 * 1024
|
|
147
|
+
|
|
148
|
+
static func ioBufferBytes() -> Int {
|
|
149
|
+
return ioBufferBytesValue
|
|
169
150
|
}
|
|
170
151
|
|
|
171
|
-
static func checksumBufferBytes(
|
|
172
|
-
return
|
|
152
|
+
static func checksumBufferBytes() -> Int {
|
|
153
|
+
return ioBufferBytesValue
|
|
173
154
|
}
|
|
174
155
|
|
|
175
|
-
static func copyBufferBytes(
|
|
176
|
-
return
|
|
156
|
+
static func copyBufferBytes() -> Int {
|
|
157
|
+
return ioBufferBytesValue
|
|
177
158
|
}
|
|
178
159
|
|
|
179
160
|
public static func calcChecksum(filePath: URL) -> String {
|