@capgo/capacitor-updater 8.52.1-beta.pr937.1951.1 → 8.53.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/CapgoCapacitorUpdater.podspec +0 -2
- package/Package.swift +0 -5
- package/README.md +199 -67
- package/android/build.gradle +9 -88
- package/android/src/main/java/ee/forgr/capacitor_updater/AndroidAppExitReporter.java +60 -32
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +246 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +45 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +13 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +5539 -1066
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +3754 -494
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +496 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +44 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +56 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +14 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +427 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DeviceIdHelper.java +6 -23
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +1541 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +258 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +318 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +45 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +1 -6
- package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +417 -217
- package/android/src/main/java/ee/forgr/capacitor_updater/ThreeFingerPinchDetector.java +1 -3
- package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
- package/dist/docs.json +379 -28
- package/dist/esm/definitions.d.ts +209 -10
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- 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 +5247 -199
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoRawRsa.swift +36 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +3878 -365
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +328 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayCondition.swift +74 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUntilNext.swift +30 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +343 -0
- package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +471 -0
- package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RSA.swift +96 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +53 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +221 -63
- package/ios/Sources/CapacitorUpdaterPlugin/UserDefaultsExtension.swift +46 -0
- package/ios/Sources/CapacitorUpdaterPlugin/WebViewStatsReporter.swift +147 -5
- package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
- package/package.json +15 -19
- package/android/consumer-rules.pro +0 -15
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoCore.java +0 -67
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoCoreNative.java +0 -97
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoDownloadWorker.java +0 -188
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoEngine.java +0 -114
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoEngineHolder.java +0 -59
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoEngineHost.java +0 -118
- package/android/src/main/java/ee/forgr/capacitor_updater/EngineMethodLanes.java +0 -168
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin+AppStore.swift +0 -171
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin+Methods.swift +0 -168
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin+Overlays.swift +0 -285
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin+WebView.swift +0 -134
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoCore.swift +0 -61
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoEngine.swift +0 -319
package/android/build.gradle
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
ext {
|
|
2
2
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
3
|
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
okhttpVersion = project.hasProperty('okhttpVersion') ? rootProject.ext.okhttpVersion : '4.12.0'
|
|
4
7
|
}
|
|
5
8
|
|
|
6
9
|
buildscript {
|
|
@@ -23,7 +26,7 @@ android {
|
|
|
23
26
|
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
24
27
|
versionCode 1
|
|
25
28
|
versionName "1.0"
|
|
26
|
-
|
|
29
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
27
30
|
}
|
|
28
31
|
buildTypes {
|
|
29
32
|
release {
|
|
@@ -54,100 +57,18 @@ dependencies {
|
|
|
54
57
|
implementation "com.google.android.gms:play-services-tasks:18.4.1"
|
|
55
58
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
56
59
|
implementation project(':capacitor-android')
|
|
57
|
-
// BridgeActivity extends AppCompatActivity: the plugin needs AppCompat on its compile classpath.
|
|
58
60
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
59
61
|
// Play Core library for in-app updates
|
|
60
62
|
implementation 'com.google.android.play:app-update:2.1.0'
|
|
61
63
|
testImplementation "junit:junit:$junitVersion"
|
|
62
|
-
testImplementation "androidx.work:work-testing:$work_version"
|
|
63
64
|
testImplementation 'org.mockito:mockito-core:5.24.0'
|
|
64
65
|
testImplementation 'org.json:json:20250517'
|
|
65
66
|
testImplementation 'org.robolectric:robolectric:4.17'
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def capgoCoreDir = file("../core")
|
|
72
|
-
|
|
73
|
-
// Some ld releases end the indirect symbol table of the host dylib on a 4-byte boundary and
|
|
74
|
-
// put the string table right after it; newer dyld refuses that ("mis-aligned LINKEDIT string
|
|
75
|
-
// pool"). Host test library only: move the string table to an 8-byte boundary and re-sign.
|
|
76
|
-
def alignMachOStringTable = { File dylib ->
|
|
77
|
-
def read = { java.nio.ByteBuffer.wrap(dylib.bytes).order(java.nio.ByteOrder.LITTLE_ENDIAN) }
|
|
78
|
-
def stringTableOffset = { java.nio.ByteBuffer buffer ->
|
|
79
|
-
int offset = 32
|
|
80
|
-
for (int index = 0; index < buffer.getInt(16); index++) {
|
|
81
|
-
if (buffer.getInt(offset) == 0x2) {
|
|
82
|
-
return offset
|
|
83
|
-
}
|
|
84
|
-
offset += buffer.getInt(offset + 4)
|
|
85
|
-
}
|
|
86
|
-
return -1
|
|
87
|
-
}
|
|
88
|
-
def buffer = read()
|
|
89
|
-
if (buffer.getInt(0) != (int) 0xfeedfacf) {
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
int symtab = stringTableOffset(buffer)
|
|
93
|
-
if (symtab < 0 || buffer.getInt(symtab + 16) % 8 == 0) {
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
def sign = { List<String> args ->
|
|
97
|
-
def process = (["codesign"] + args + [dylib.absolutePath]).execute()
|
|
98
|
-
process.waitForProcessOutput(System.out, System.err)
|
|
99
|
-
if (process.exitValue() != 0) {
|
|
100
|
-
throw new GradleException("codesign ${args} failed for ${dylib}")
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
sign(["--remove-signature"])
|
|
104
|
-
buffer = read()
|
|
105
|
-
int stroff = buffer.getInt(symtab + 16)
|
|
106
|
-
int pad = 8 - stroff % 8
|
|
107
|
-
byte[] original = buffer.array()
|
|
108
|
-
byte[] patched = new byte[original.length + pad]
|
|
109
|
-
System.arraycopy(original, 0, patched, 0, stroff)
|
|
110
|
-
System.arraycopy(original, stroff, patched, stroff + pad, original.length - stroff)
|
|
111
|
-
def out = java.nio.ByteBuffer.wrap(patched).order(java.nio.ByteOrder.LITTLE_ENDIAN)
|
|
112
|
-
out.putInt(symtab + 16, stroff + pad)
|
|
113
|
-
int offset = 32
|
|
114
|
-
for (int index = 0; index < out.getInt(16); index++) {
|
|
115
|
-
if (out.getInt(offset) == 0x19 && new String(patched, offset + 8, 10, "US-ASCII") == "__LINKEDIT") {
|
|
116
|
-
long filesize = out.getLong(offset + 48) + pad
|
|
117
|
-
out.putLong(offset + 48, filesize)
|
|
118
|
-
out.putLong(offset + 32, Math.max(out.getLong(offset + 32), (filesize + 0x3fff) & ~0x3fffL))
|
|
119
|
-
}
|
|
120
|
-
offset += out.getInt(offset + 4)
|
|
121
|
-
}
|
|
122
|
-
dylib.bytes = patched
|
|
123
|
-
sign(["-s", "-", "-f"])
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (capgoCoreDir.exists()) {
|
|
127
|
-
def capgoCoreHostLibDir = new File(capgoCoreDir, "target/host/release")
|
|
128
|
-
def buildCapgoCoreHost = tasks.register("buildCapgoCoreHost", Exec) {
|
|
129
|
-
description = "Builds the Capgo Rust core for the host JVM (unit tests)"
|
|
130
|
-
workingDir capgoCoreDir
|
|
131
|
-
def cargoHome = System.getenv("CARGO_HOME") ?: "${System.getProperty('user.home')}/.cargo"
|
|
132
|
-
def rustupCargo = new File(cargoHome, "bin/cargo")
|
|
133
|
-
executable rustupCargo.exists() ? rustupCargo.absolutePath : "cargo"
|
|
134
|
-
args "build", "--release", "--locked", "--features", "jni", "--target-dir", "target/host"
|
|
135
|
-
inputs.dir(new File(capgoCoreDir, "src"))
|
|
136
|
-
inputs.file(new File(capgoCoreDir, "Cargo.toml"))
|
|
137
|
-
inputs.file(new File(capgoCoreDir, "Cargo.lock"))
|
|
138
|
-
outputs.dir(capgoCoreHostLibDir)
|
|
139
|
-
doLast {
|
|
140
|
-
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
|
|
141
|
-
alignMachOStringTable(new File(capgoCoreHostLibDir, System.mapLibraryName("capgo_updater_core")))
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
tasks.withType(Test).configureEach {
|
|
146
|
-
dependsOn buildCapgoCoreHost
|
|
147
|
-
// Re-run the JVM tests whenever the core library changes.
|
|
148
|
-
inputs.files(buildCapgoCoreHost)
|
|
149
|
-
systemProperty "capgo.core.hostLibrary", new File(capgoCoreHostLibDir, System.mapLibraryName("capgo_updater_core")).absolutePath
|
|
150
|
-
}
|
|
67
|
+
testImplementation 'androidx.arch.core:core-testing:2.2.0'
|
|
68
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
69
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
70
|
+
implementation 'org.brotli:dec:0.1.2'
|
|
71
|
+
implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
|
|
151
72
|
}
|
|
152
73
|
|
|
153
74
|
tasks.withType(Test) {
|
|
@@ -10,55 +10,83 @@ import android.annotation.TargetApi;
|
|
|
10
10
|
import android.app.ActivityManager;
|
|
11
11
|
import android.app.ApplicationExitInfo;
|
|
12
12
|
import android.content.Context;
|
|
13
|
+
import android.content.SharedPreferences;
|
|
13
14
|
import android.os.Build;
|
|
15
|
+
import java.util.HashMap;
|
|
14
16
|
import java.util.List;
|
|
15
|
-
import
|
|
16
|
-
import org.json.JSONObject;
|
|
17
|
+
import java.util.Map;
|
|
17
18
|
|
|
18
|
-
/**
|
|
19
|
-
* Reads the previous process exits ({@link ApplicationExitInfo}, API 30+) for the engine, which reports the
|
|
20
|
-
* ones worth a statistic ({@code previousExits} of {@code pluginLoad}). Kept out of the plugin class so older
|
|
21
|
-
* Android versions never resolve {@link ApplicationExitInfo} while reflecting plugin methods.
|
|
22
|
-
*/
|
|
23
19
|
@TargetApi(Build.VERSION_CODES.R)
|
|
24
20
|
final class AndroidAppExitReporter {
|
|
25
21
|
|
|
26
|
-
private static final int MAX_EXITS = 8;
|
|
27
|
-
|
|
28
22
|
private AndroidAppExitReporter() {}
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
final
|
|
24
|
+
static void reportPreviousAppExitReasons(
|
|
25
|
+
final Context context,
|
|
26
|
+
final SharedPreferences prefs,
|
|
27
|
+
final CapgoUpdater implementation,
|
|
28
|
+
final Logger logger,
|
|
29
|
+
final String lastReportedAppExitTimestampPrefKey
|
|
30
|
+
) {
|
|
33
31
|
try {
|
|
34
32
|
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
35
33
|
if (activityManager == null) {
|
|
36
|
-
return
|
|
34
|
+
return;
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
|
|
37
|
+
final List<ApplicationExitInfo> exitReasons = activityManager.getHistoricalProcessExitReasons(context.getPackageName(), 0, 8);
|
|
38
|
+
if (exitReasons == null || exitReasons.isEmpty()) {
|
|
39
|
+
return;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
|
|
42
|
+
final long lastReportedTimestamp = prefs.getLong(lastReportedAppExitTimestampPrefKey, 0L);
|
|
43
|
+
long newestReportedTimestamp = lastReportedTimestamp;
|
|
44
|
+
final BundleInfo current = implementation.getCurrentBundle();
|
|
45
|
+
final String versionName = current == null ? "" : current.getVersionName();
|
|
46
|
+
|
|
47
|
+
for (final ApplicationExitInfo exitInfo : exitReasons) {
|
|
48
|
+
if (exitInfo == null || exitInfo.getTimestamp() <= lastReportedTimestamp) {
|
|
44
49
|
continue;
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
);
|
|
51
|
+
|
|
52
|
+
final String action = CapacitorUpdaterPlugin.statsActionForApplicationExitReason(exitInfo.getReason());
|
|
53
|
+
if (action == null) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
implementation.sendStats(action, versionName, "", buildApplicationExitMetadata(exitInfo));
|
|
58
|
+
newestReportedTimestamp = Math.max(newestReportedTimestamp, exitInfo.getTimestamp());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (newestReportedTimestamp > lastReportedTimestamp) {
|
|
62
|
+
prefs.edit().putLong(lastReportedAppExitTimestampPrefKey, newestReportedTimestamp).apply();
|
|
58
63
|
}
|
|
59
64
|
} catch (final Exception e) {
|
|
60
|
-
logger.warn("Unable to
|
|
65
|
+
logger.warn("Unable to report previous app exit reason: " + e.getMessage());
|
|
61
66
|
}
|
|
62
|
-
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private static Map<String, String> buildApplicationExitMetadata(final ApplicationExitInfo exitInfo) {
|
|
70
|
+
final Map<String, String> metadata = new HashMap<>();
|
|
71
|
+
metadata.put("exit_reason", CapacitorUpdaterPlugin.applicationExitReasonName(exitInfo.getReason()));
|
|
72
|
+
metadata.put("exit_reason_code", Integer.toString(exitInfo.getReason()));
|
|
73
|
+
metadata.put("exit_status", Integer.toString(exitInfo.getStatus()));
|
|
74
|
+
metadata.put("exit_importance", Integer.toString(exitInfo.getImportance()));
|
|
75
|
+
metadata.put("exit_timestamp", Long.toString(exitInfo.getTimestamp()));
|
|
76
|
+
metadata.put("pid", Integer.toString(exitInfo.getPid()));
|
|
77
|
+
metadata.put("pss_kb", Long.toString(exitInfo.getPss()));
|
|
78
|
+
metadata.put("rss_kb", Long.toString(exitInfo.getRss()));
|
|
79
|
+
|
|
80
|
+
final String processName = exitInfo.getProcessName();
|
|
81
|
+
if (processName != null && !processName.isEmpty()) {
|
|
82
|
+
metadata.put("process_name", CapacitorUpdaterPlugin.truncateStatsMetadataValue(processName, 128));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
final String description = exitInfo.getDescription();
|
|
86
|
+
if (description != null && !description.isEmpty()) {
|
|
87
|
+
metadata.put("exit_description", CapacitorUpdaterPlugin.truncateStatsMetadataValue(description, 512));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return metadata;
|
|
63
91
|
}
|
|
64
92
|
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package ee.forgr.capacitor_updater;
|
|
8
|
+
|
|
9
|
+
import java.text.SimpleDateFormat;
|
|
10
|
+
import java.util.Date;
|
|
11
|
+
import java.util.HashMap;
|
|
12
|
+
import java.util.Map;
|
|
13
|
+
import java.util.Objects;
|
|
14
|
+
import java.util.TimeZone;
|
|
15
|
+
import org.json.JSONException;
|
|
16
|
+
import org.json.JSONObject;
|
|
17
|
+
import org.json.JSONTokener;
|
|
18
|
+
|
|
19
|
+
public class BundleInfo {
|
|
20
|
+
|
|
21
|
+
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
|
22
|
+
|
|
23
|
+
public static final String ID_BUILTIN = "builtin";
|
|
24
|
+
public static final String VERSION_UNKNOWN = "unknown";
|
|
25
|
+
public static final String DOWNLOADED_BUILTIN = "1970-01-01T00:00:00.000Z";
|
|
26
|
+
|
|
27
|
+
private final String downloaded;
|
|
28
|
+
private final String id;
|
|
29
|
+
private final String version;
|
|
30
|
+
private final String checksum;
|
|
31
|
+
private final BundleStatus status;
|
|
32
|
+
private final String link;
|
|
33
|
+
private final String comment;
|
|
34
|
+
|
|
35
|
+
static {
|
|
36
|
+
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public BundleInfo(final BundleInfo source) {
|
|
40
|
+
this(source.id, source.version, source.status, source.downloaded, source.checksum, source.link, source.comment);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public BundleInfo(final String id, final String version, final BundleStatus status, final Date downloaded, final String checksum) {
|
|
44
|
+
this(id, version, status, sdf.format(downloaded), checksum, null, null);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public BundleInfo(
|
|
48
|
+
final String id,
|
|
49
|
+
final String version,
|
|
50
|
+
final BundleStatus status,
|
|
51
|
+
final Date downloaded,
|
|
52
|
+
final String checksum,
|
|
53
|
+
final String link,
|
|
54
|
+
final String comment
|
|
55
|
+
) {
|
|
56
|
+
this(id, version, status, sdf.format(downloaded), checksum, link, comment);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public BundleInfo(final String id, final String version, final BundleStatus status, final String downloaded, final String checksum) {
|
|
60
|
+
this(id, version, status, downloaded, checksum, null, null);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public BundleInfo(
|
|
64
|
+
final String id,
|
|
65
|
+
final String version,
|
|
66
|
+
final BundleStatus status,
|
|
67
|
+
final String downloaded,
|
|
68
|
+
final String checksum,
|
|
69
|
+
final String link,
|
|
70
|
+
final String comment
|
|
71
|
+
) {
|
|
72
|
+
this.downloaded = downloaded != null ? downloaded.trim() : "";
|
|
73
|
+
this.id = id != null ? id : "";
|
|
74
|
+
this.version = version;
|
|
75
|
+
this.checksum = checksum != null ? checksum : "";
|
|
76
|
+
this.status = status != null ? status : BundleStatus.ERROR;
|
|
77
|
+
this.link = link;
|
|
78
|
+
this.comment = comment;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public Boolean isBuiltin() {
|
|
82
|
+
return ID_BUILTIN.equals(this.id);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public Boolean isUnknown() {
|
|
86
|
+
return VERSION_UNKNOWN.equals(this.id);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public Boolean isErrorStatus() {
|
|
90
|
+
return BundleStatus.ERROR == this.status;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public Boolean isDeleted() {
|
|
94
|
+
return BundleStatus.DELETED == this.status;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public Boolean isDeleting() {
|
|
98
|
+
return BundleStatus.DELETING == this.status;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public boolean isDownloaded() {
|
|
102
|
+
return !this.isBuiltin() && this.downloaded != null && !this.downloaded.isEmpty() && !this.isDeleted() && !this.isDeleting();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public String getDownloaded() {
|
|
106
|
+
return this.isBuiltin() ? DOWNLOADED_BUILTIN : this.downloaded != null ? this.downloaded : "";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public BundleInfo setDownloaded(Date downloaded) {
|
|
110
|
+
return new BundleInfo(this.id, this.version, this.status, downloaded, this.checksum, this.link, this.comment);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public String getChecksum() {
|
|
114
|
+
return this.isBuiltin() ? "" : this.checksum != null ? this.checksum : "";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public BundleInfo setChecksum(String checksum) {
|
|
118
|
+
return new BundleInfo(this.id, this.version, this.status, this.downloaded, checksum, this.link, this.comment);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public String getId() {
|
|
122
|
+
return this.isBuiltin() ? ID_BUILTIN : this.id;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public BundleInfo setId(String id) {
|
|
126
|
+
return new BundleInfo(id, this.version, this.status, this.downloaded, this.checksum, this.link, this.comment);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public String getVersionName() {
|
|
130
|
+
return this.version == null ? ID_BUILTIN : this.version;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public BundleInfo setVersionName(String version) {
|
|
134
|
+
return new BundleInfo(this.id, version, this.status, this.downloaded, this.checksum, this.link, this.comment);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public BundleStatus getStatus() {
|
|
138
|
+
if (this.isBuiltin()) {
|
|
139
|
+
return BundleStatus.SUCCESS;
|
|
140
|
+
}
|
|
141
|
+
return this.status != null ? this.status : BundleStatus.ERROR;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public BundleInfo setStatus(BundleStatus status) {
|
|
145
|
+
return new BundleInfo(this.id, this.version, status, this.downloaded, this.checksum, this.link, this.comment);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public String getLink() {
|
|
149
|
+
return this.link;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public BundleInfo setLink(String link) {
|
|
153
|
+
return new BundleInfo(this.id, this.version, this.status, this.downloaded, this.checksum, link, this.comment);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public String getComment() {
|
|
157
|
+
return this.comment;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public BundleInfo setComment(String comment) {
|
|
161
|
+
return new BundleInfo(this.id, this.version, this.status, this.downloaded, this.checksum, this.link, comment);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public static BundleInfo fromJSON(final String jsonString) throws JSONException {
|
|
165
|
+
JSONObject json = new JSONObject(new JSONTokener(jsonString));
|
|
166
|
+
return new BundleInfo(
|
|
167
|
+
json.has("id") ? json.getString("id") : "",
|
|
168
|
+
json.has("version") ? json.getString("version") : BundleInfo.VERSION_UNKNOWN,
|
|
169
|
+
json.has("status") ? BundleStatus.fromString(json.getString("status")) : BundleStatus.PENDING,
|
|
170
|
+
json.has("downloaded") ? json.getString("downloaded") : "",
|
|
171
|
+
json.has("checksum") ? json.getString("checksum") : "",
|
|
172
|
+
json.has("link") ? json.getString("link") : null,
|
|
173
|
+
json.has("comment") ? json.getString("comment") : null
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public Map<String, Object> toJSONMap() {
|
|
178
|
+
final Map<String, Object> result = new HashMap<>();
|
|
179
|
+
result.put("id", this.getId());
|
|
180
|
+
result.put("version", this.getVersionName());
|
|
181
|
+
result.put("downloaded", this.getDownloaded());
|
|
182
|
+
result.put("checksum", this.getChecksum());
|
|
183
|
+
result.put("status", this.getStatus().toString());
|
|
184
|
+
if (this.link != null && !this.link.isEmpty()) {
|
|
185
|
+
result.put("link", this.link);
|
|
186
|
+
}
|
|
187
|
+
if (this.comment != null && !this.comment.isEmpty()) {
|
|
188
|
+
result.put("comment", this.comment);
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@Override
|
|
194
|
+
public boolean equals(final Object o) {
|
|
195
|
+
if (this == o) return true;
|
|
196
|
+
if (!(o instanceof BundleInfo)) return false;
|
|
197
|
+
final BundleInfo that = (BundleInfo) o;
|
|
198
|
+
return this.getId().equals(that.getId());
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@Override
|
|
202
|
+
public int hashCode() {
|
|
203
|
+
return Objects.hash(this.version);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
@Override
|
|
207
|
+
public String toString() {
|
|
208
|
+
try {
|
|
209
|
+
// Build JSON manually with extra safety checks
|
|
210
|
+
StringBuilder json = new StringBuilder();
|
|
211
|
+
json.append("{");
|
|
212
|
+
|
|
213
|
+
// Safe ID access
|
|
214
|
+
String safeId = this.id != null ? this.id : "";
|
|
215
|
+
if (this.isBuiltin()) safeId = ID_BUILTIN;
|
|
216
|
+
json.append("\"id\":\"").append(safeId).append("\",");
|
|
217
|
+
|
|
218
|
+
// Safe version access
|
|
219
|
+
String safeVersion = this.version != null ? this.version : ID_BUILTIN;
|
|
220
|
+
json.append("\"version\":\"").append(safeVersion).append("\",");
|
|
221
|
+
|
|
222
|
+
// Safe downloaded access
|
|
223
|
+
String safeDownloaded = this.downloaded != null ? this.downloaded : "";
|
|
224
|
+
if (this.isBuiltin()) safeDownloaded = DOWNLOADED_BUILTIN;
|
|
225
|
+
json.append("\"downloaded\":\"").append(safeDownloaded).append("\",");
|
|
226
|
+
|
|
227
|
+
// Safe checksum access
|
|
228
|
+
String safeChecksum = this.checksum != null ? this.checksum : "";
|
|
229
|
+
json.append("\"checksum\":\"").append(safeChecksum).append("\",");
|
|
230
|
+
|
|
231
|
+
// Safe status access
|
|
232
|
+
BundleStatus safeStatus = this.status != null ? this.status : BundleStatus.ERROR;
|
|
233
|
+
if (this.isBuiltin()) safeStatus = BundleStatus.SUCCESS;
|
|
234
|
+
json.append("\"status\":\"").append(safeStatus.toString()).append("\"");
|
|
235
|
+
|
|
236
|
+
json.append("}");
|
|
237
|
+
return json.toString();
|
|
238
|
+
} catch (Exception e) {
|
|
239
|
+
// Log the error for debugging but still return valid JSON
|
|
240
|
+
System.err.println("BundleInfo toString() error: " + e.getMessage());
|
|
241
|
+
e.printStackTrace();
|
|
242
|
+
// Return absolute minimal JSON
|
|
243
|
+
return "{\"id\":\"" + (this.id != null ? this.id : "unknown") + "\",\"status\":\"error\"}";
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package ee.forgr.capacitor_updater;
|
|
8
|
+
|
|
9
|
+
import java.util.HashMap;
|
|
10
|
+
import java.util.Map;
|
|
11
|
+
|
|
12
|
+
public enum BundleStatus {
|
|
13
|
+
SUCCESS("success"),
|
|
14
|
+
ERROR("error"),
|
|
15
|
+
PENDING("pending"),
|
|
16
|
+
DELETED("deleted"),
|
|
17
|
+
DELETING("deleting"),
|
|
18
|
+
DOWNLOADING("downloading");
|
|
19
|
+
|
|
20
|
+
public final String label;
|
|
21
|
+
|
|
22
|
+
private static final Map<String, BundleStatus> BY_LABEL = new HashMap<>();
|
|
23
|
+
|
|
24
|
+
static {
|
|
25
|
+
for (final BundleStatus e : values()) {
|
|
26
|
+
BY_LABEL.put(e.label, e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
BundleStatus(final String label) {
|
|
31
|
+
this.label = label;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Override
|
|
35
|
+
public String toString() {
|
|
36
|
+
return this.label;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public static BundleStatus fromString(final String status) {
|
|
40
|
+
if (status == null || status.isEmpty()) {
|
|
41
|
+
return BundleStatus.PENDING;
|
|
42
|
+
}
|
|
43
|
+
return BundleStatus.BY_LABEL.get(status);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package ee.forgr.capacitor_updater;
|
|
8
|
+
|
|
9
|
+
import java.util.Map;
|
|
10
|
+
|
|
11
|
+
public interface Callback {
|
|
12
|
+
void callback(Map<String, Object> result);
|
|
13
|
+
}
|