@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,44 @@
|
|
|
1
|
+
package ee.forgr.capacitor_updater;
|
|
2
|
+
|
|
3
|
+
import java.util.HashMap;
|
|
4
|
+
import java.util.Map;
|
|
5
|
+
import org.json.JSONArray;
|
|
6
|
+
|
|
7
|
+
public class DataManager {
|
|
8
|
+
|
|
9
|
+
private static DataManager instance;
|
|
10
|
+
private final Map<String, JSONArray> manifestsById = new HashMap<>();
|
|
11
|
+
|
|
12
|
+
private DataManager() {}
|
|
13
|
+
|
|
14
|
+
public static synchronized DataManager getInstance() {
|
|
15
|
+
if (instance == null) {
|
|
16
|
+
instance = new DataManager();
|
|
17
|
+
}
|
|
18
|
+
return instance;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public synchronized void setManifest(String downloadId, JSONArray manifest) {
|
|
22
|
+
if (downloadId == null || manifest == null) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.manifestsById.put(downloadId, manifest);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public synchronized JSONArray getAndClearManifest(String downloadId) {
|
|
29
|
+
if (downloadId == null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return this.manifestsById.remove(downloadId);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public synchronized void clearManifest(String downloadId) {
|
|
36
|
+
if (downloadId != null) {
|
|
37
|
+
this.manifestsById.remove(downloadId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public synchronized void clearAllManifests() {
|
|
42
|
+
this.manifestsById.clear();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -6,57 +6,51 @@
|
|
|
6
6
|
|
|
7
7
|
package ee.forgr.capacitor_updater;
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
10
10
|
import java.util.Objects;
|
|
11
11
|
|
|
12
12
|
public class DelayCondition {
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
@Override
|
|
57
|
-
public String toString() {
|
|
58
|
-
return (
|
|
59
|
-
"DelayCondition{" + "kind=" + kind + ", value='" + value + '\'' + '}'
|
|
60
|
-
);
|
|
61
|
-
}
|
|
14
|
+
private DelayUntilNext kind;
|
|
15
|
+
|
|
16
|
+
private String value;
|
|
17
|
+
|
|
18
|
+
public DelayCondition(DelayUntilNext kind, String value) {
|
|
19
|
+
this.kind = kind;
|
|
20
|
+
this.value = value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public DelayUntilNext getKind() {
|
|
24
|
+
return kind;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public void setKind(DelayUntilNext kind) {
|
|
28
|
+
this.kind = kind;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public String getValue() {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public void setValue(String value) {
|
|
36
|
+
this.value = value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public boolean equals(Object o) {
|
|
41
|
+
if (this == o) return true;
|
|
42
|
+
if (!(o instanceof DelayCondition that)) return false;
|
|
43
|
+
return getKind() == that.getKind() && Objects.equals(getValue(), that.getValue());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Override
|
|
47
|
+
public int hashCode() {
|
|
48
|
+
return Objects.hash(getKind(), getValue());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@NonNull
|
|
52
|
+
@Override
|
|
53
|
+
public String toString() {
|
|
54
|
+
return "DelayCondition{" + "kind=" + kind + ", value='" + value + '\'' + '}';
|
|
55
|
+
}
|
|
62
56
|
}
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
package ee.forgr.capacitor_updater;
|
|
2
|
+
|
|
3
|
+
import android.content.SharedPreferences;
|
|
4
|
+
import java.text.ParsePosition;
|
|
5
|
+
import java.text.SimpleDateFormat;
|
|
6
|
+
import java.util.ArrayList;
|
|
7
|
+
import java.util.Date;
|
|
8
|
+
import java.util.Locale;
|
|
9
|
+
import java.util.TimeZone;
|
|
10
|
+
import org.json.JSONArray;
|
|
11
|
+
import org.json.JSONException;
|
|
12
|
+
import org.json.JSONObject;
|
|
13
|
+
|
|
14
|
+
public class DelayUpdateUtils {
|
|
15
|
+
|
|
16
|
+
private final Logger logger;
|
|
17
|
+
|
|
18
|
+
public static final String DELAY_CONDITION_PREFERENCES = "DELAY_CONDITION_PREFERENCES_CAPGO";
|
|
19
|
+
public static final String DELAY_CONDITION_MODE_PREFERENCES = "DELAY_CONDITION_MODE_PREFERENCES_CAPGO";
|
|
20
|
+
public static final String DELAY_CONDITION_MODE_AND = "and";
|
|
21
|
+
public static final String DELAY_CONDITION_MODE_OR = "or";
|
|
22
|
+
public static final String BACKGROUND_TIMESTAMP_KEY = "BACKGROUND_TIMESTAMP_KEY_CAPGO";
|
|
23
|
+
|
|
24
|
+
private final SharedPreferences prefs;
|
|
25
|
+
private final SharedPreferences.Editor editor;
|
|
26
|
+
private final Version currentVersionNative;
|
|
27
|
+
|
|
28
|
+
public DelayUpdateUtils(SharedPreferences prefs, SharedPreferences.Editor editor, Version currentVersionNative, Logger logger) {
|
|
29
|
+
this.prefs = prefs;
|
|
30
|
+
this.editor = editor;
|
|
31
|
+
this.currentVersionNative = currentVersionNative;
|
|
32
|
+
this.logger = logger;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public enum CancelDelaySource {
|
|
36
|
+
KILLED,
|
|
37
|
+
BACKGROUND,
|
|
38
|
+
FOREGROUND
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public void checkCancelDelay(CancelDelaySource source) {
|
|
42
|
+
String delayUpdatePreferences = prefs.getString(DELAY_CONDITION_PREFERENCES, "[]");
|
|
43
|
+
ArrayList<DelayCondition> delayConditionList = parseDelayConditions(delayUpdatePreferences);
|
|
44
|
+
if (delayConditionList.isEmpty()) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
final boolean useOrMode = isOrConditionMode();
|
|
49
|
+
ArrayList<DelayCondition> delayConditionListToKeep = new ArrayList<>(delayConditionList.size());
|
|
50
|
+
int index = 0;
|
|
51
|
+
boolean anyConditionMet = false;
|
|
52
|
+
|
|
53
|
+
for (DelayCondition condition : delayConditionList) {
|
|
54
|
+
ConditionCheckResult result = evaluateCondition(condition, source, index);
|
|
55
|
+
if (result.met) {
|
|
56
|
+
anyConditionMet = true;
|
|
57
|
+
if (!useOrMode) {
|
|
58
|
+
logger.info(result.logMessage);
|
|
59
|
+
}
|
|
60
|
+
} else if (!useOrMode) {
|
|
61
|
+
if (result.keep) {
|
|
62
|
+
delayConditionListToKeep.add(condition);
|
|
63
|
+
}
|
|
64
|
+
if (result.logMessage != null) {
|
|
65
|
+
if (result.error) {
|
|
66
|
+
logger.error(result.logMessage);
|
|
67
|
+
} else {
|
|
68
|
+
logger.info(result.logMessage);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else if (result.keep) {
|
|
72
|
+
delayConditionListToKeep.add(condition);
|
|
73
|
+
}
|
|
74
|
+
index++;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (useOrMode) {
|
|
78
|
+
if (anyConditionMet || delayConditionListToKeep.isEmpty()) {
|
|
79
|
+
logger.info("Delay condition met in OR mode (source: " + source + "), canceling delay");
|
|
80
|
+
this.cancelDelay("checkCancelDelay");
|
|
81
|
+
} else if (delayConditionListToKeep.size() != delayConditionList.size()) {
|
|
82
|
+
this.setMultiDelay(convertDelayConditionsToJson(delayConditionListToKeep));
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (delayConditionListToKeep.isEmpty()) {
|
|
88
|
+
this.cancelDelay("checkCancelDelay");
|
|
89
|
+
} else {
|
|
90
|
+
this.setMultiDelay(convertDelayConditionsToJson(delayConditionListToKeep));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private static final class ConditionCheckResult {
|
|
95
|
+
|
|
96
|
+
final boolean met;
|
|
97
|
+
final boolean keep;
|
|
98
|
+
final boolean error;
|
|
99
|
+
final String logMessage;
|
|
100
|
+
|
|
101
|
+
ConditionCheckResult(boolean met, boolean keep, boolean error, String logMessage) {
|
|
102
|
+
this.met = met;
|
|
103
|
+
this.keep = keep;
|
|
104
|
+
this.error = error;
|
|
105
|
+
this.logMessage = logMessage;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private ConditionCheckResult evaluateCondition(DelayCondition condition, CancelDelaySource source, int index) {
|
|
110
|
+
DelayUntilNext kind = condition.getKind();
|
|
111
|
+
String value = condition.getValue();
|
|
112
|
+
switch (kind) {
|
|
113
|
+
case background:
|
|
114
|
+
if (source == CancelDelaySource.FOREGROUND) {
|
|
115
|
+
long backgroundedAt = getBackgroundTimestamp();
|
|
116
|
+
long now = System.currentTimeMillis();
|
|
117
|
+
long delta = Math.max(0, now - backgroundedAt);
|
|
118
|
+
long longValue = 0L;
|
|
119
|
+
try {
|
|
120
|
+
longValue = Long.parseLong(value);
|
|
121
|
+
} catch (NumberFormatException e) {
|
|
122
|
+
return new ConditionCheckResult(
|
|
123
|
+
false,
|
|
124
|
+
false,
|
|
125
|
+
true,
|
|
126
|
+
"Background condition (value: " +
|
|
127
|
+
value +
|
|
128
|
+
") had an invalid value at index " +
|
|
129
|
+
index +
|
|
130
|
+
". We will likely remove it."
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (delta > longValue) {
|
|
135
|
+
return new ConditionCheckResult(
|
|
136
|
+
true,
|
|
137
|
+
false,
|
|
138
|
+
false,
|
|
139
|
+
"Background condition (value: " +
|
|
140
|
+
value +
|
|
141
|
+
") deleted at index " +
|
|
142
|
+
index +
|
|
143
|
+
". Delta: " +
|
|
144
|
+
delta +
|
|
145
|
+
", longValue: " +
|
|
146
|
+
longValue
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return new ConditionCheckResult(
|
|
150
|
+
false,
|
|
151
|
+
true,
|
|
152
|
+
false,
|
|
153
|
+
"Background delay (value: " + value + ") condition kept at index " + index + " (source: " + source + ")"
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
return new ConditionCheckResult(
|
|
157
|
+
false,
|
|
158
|
+
true,
|
|
159
|
+
false,
|
|
160
|
+
"Background delay (value: " + value + ") condition kept at index " + index + " (source: " + source + ")"
|
|
161
|
+
);
|
|
162
|
+
case kill:
|
|
163
|
+
if (source == CancelDelaySource.KILLED) {
|
|
164
|
+
return new ConditionCheckResult(
|
|
165
|
+
true,
|
|
166
|
+
false,
|
|
167
|
+
false,
|
|
168
|
+
"Kill delay (value: " + value + ") condition removed at index " + index + " after app kill"
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return new ConditionCheckResult(
|
|
172
|
+
false,
|
|
173
|
+
true,
|
|
174
|
+
false,
|
|
175
|
+
"Kill delay (value: " + value + ") condition kept at index " + index + " (source: " + source + ")"
|
|
176
|
+
);
|
|
177
|
+
case date:
|
|
178
|
+
if (!"".equals(value)) {
|
|
179
|
+
Date date = parseDateCondition(value);
|
|
180
|
+
if (date != null) {
|
|
181
|
+
if (new Date().compareTo(date) > 0) {
|
|
182
|
+
return new ConditionCheckResult(
|
|
183
|
+
true,
|
|
184
|
+
false,
|
|
185
|
+
false,
|
|
186
|
+
"Date delay (value: " + value + ") condition removed due to expired date at index " + index
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return new ConditionCheckResult(
|
|
190
|
+
false,
|
|
191
|
+
true,
|
|
192
|
+
false,
|
|
193
|
+
"Date delay (value: " + value + ") condition kept at index " + index
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
return new ConditionCheckResult(
|
|
197
|
+
false,
|
|
198
|
+
false,
|
|
199
|
+
true,
|
|
200
|
+
"Date delay (value: " + value + ") condition removed due to parsing issue at index " + index
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
return new ConditionCheckResult(
|
|
204
|
+
false,
|
|
205
|
+
false,
|
|
206
|
+
false,
|
|
207
|
+
"Date delay (value: " + value + ") condition removed due to empty value at index " + index
|
|
208
|
+
);
|
|
209
|
+
case nativeVersion:
|
|
210
|
+
if (!"".equals(value)) {
|
|
211
|
+
try {
|
|
212
|
+
final Version versionLimit = new Version(value);
|
|
213
|
+
if (this.currentVersionNative.isAtLeast(versionLimit)) {
|
|
214
|
+
return new ConditionCheckResult(
|
|
215
|
+
true,
|
|
216
|
+
false,
|
|
217
|
+
false,
|
|
218
|
+
"Native version delay (value: " + value + ") condition removed due to above limit at index " + index
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
return new ConditionCheckResult(
|
|
222
|
+
false,
|
|
223
|
+
true,
|
|
224
|
+
false,
|
|
225
|
+
"Native version delay (value: " + value + ") condition kept at index " + index
|
|
226
|
+
);
|
|
227
|
+
} catch (final Exception e) {
|
|
228
|
+
return new ConditionCheckResult(
|
|
229
|
+
false,
|
|
230
|
+
false,
|
|
231
|
+
true,
|
|
232
|
+
"Native version delay (value: " +
|
|
233
|
+
value +
|
|
234
|
+
") condition removed due to parsing issue at index " +
|
|
235
|
+
index +
|
|
236
|
+
" " +
|
|
237
|
+
e.getMessage()
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return new ConditionCheckResult(
|
|
242
|
+
false,
|
|
243
|
+
false,
|
|
244
|
+
false,
|
|
245
|
+
"Native version delay (value: " + value + ") condition removed due to empty value at index " + index
|
|
246
|
+
);
|
|
247
|
+
default:
|
|
248
|
+
return new ConditionCheckResult(false, false, true, "Unknown delay condition kind at index " + index);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public boolean isOrConditionMode() {
|
|
253
|
+
return DELAY_CONDITION_MODE_OR.equals(getConditionMode());
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public String getConditionMode() {
|
|
257
|
+
String mode = prefs.getString(DELAY_CONDITION_MODE_PREFERENCES, DELAY_CONDITION_MODE_AND);
|
|
258
|
+
if (DELAY_CONDITION_MODE_OR.equals(mode)) {
|
|
259
|
+
return DELAY_CONDITION_MODE_OR;
|
|
260
|
+
}
|
|
261
|
+
return DELAY_CONDITION_MODE_AND;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public Boolean setConditionMode(String conditionMode) {
|
|
265
|
+
try {
|
|
266
|
+
String normalized = DELAY_CONDITION_MODE_OR.equals(conditionMode) ? DELAY_CONDITION_MODE_OR : DELAY_CONDITION_MODE_AND;
|
|
267
|
+
if (!DELAY_CONDITION_MODE_AND.equals(conditionMode) && !DELAY_CONDITION_MODE_OR.equals(conditionMode)) {
|
|
268
|
+
logger.warn("Unknown delay condition mode '" + conditionMode + "', defaulting to '" + DELAY_CONDITION_MODE_AND + "'");
|
|
269
|
+
}
|
|
270
|
+
this.editor.putString(DELAY_CONDITION_MODE_PREFERENCES, normalized);
|
|
271
|
+
if (!this.editor.commit()) {
|
|
272
|
+
logger.error("Failed to save delay condition mode: commit returned false");
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
logger.info("Delay condition mode saved: " + normalized);
|
|
276
|
+
return true;
|
|
277
|
+
} catch (final Exception e) {
|
|
278
|
+
logger.error("Failed to save delay condition mode: " + e.getMessage());
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
public ArrayList<DelayCondition> parseDelayConditions(String json) {
|
|
284
|
+
ArrayList<DelayCondition> conditions = new ArrayList<>();
|
|
285
|
+
if (json == null || json.isEmpty()) {
|
|
286
|
+
return conditions;
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
JSONArray array = new JSONArray(json);
|
|
290
|
+
for (int i = 0; i < array.length(); i++) {
|
|
291
|
+
JSONObject item = array.optJSONObject(i);
|
|
292
|
+
if (item == null) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
String kindValue = item.optString("kind", "");
|
|
296
|
+
String value = item.optString("value", "");
|
|
297
|
+
if (kindValue.isEmpty()) {
|
|
298
|
+
logger.warn("Delay condition missing kind at index " + i);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
DelayUntilNext kind = DelayUntilNext.valueOf(kindValue);
|
|
303
|
+
conditions.add(new DelayCondition(kind, value));
|
|
304
|
+
} catch (IllegalArgumentException e) {
|
|
305
|
+
logger.warn("Unknown delay condition kind '" + kindValue + "' at index " + i);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
} catch (JSONException e) {
|
|
309
|
+
logger.error("Failed to parse delay conditions: " + e.getMessage());
|
|
310
|
+
}
|
|
311
|
+
return conditions;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private Date parseDateCondition(String value) {
|
|
315
|
+
String[] patterns = {
|
|
316
|
+
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX",
|
|
317
|
+
"yyyy-MM-dd'T'HH:mm:ssXXX",
|
|
318
|
+
"yyyy-MM-dd'T'HH:mm:ss.SSSXX",
|
|
319
|
+
"yyyy-MM-dd'T'HH:mm:ssXX",
|
|
320
|
+
"yyyy-MM-dd'T'HH:mm:ss.SSSX",
|
|
321
|
+
"yyyy-MM-dd'T'HH:mm:ssX",
|
|
322
|
+
"yyyy-MM-dd'T'HH:mm:ss.SSS",
|
|
323
|
+
"yyyy-MM-dd'T'HH:mm:ss"
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
for (String pattern : patterns) {
|
|
327
|
+
Date parsed = parseDateWithPattern(value, pattern);
|
|
328
|
+
if (parsed != null) {
|
|
329
|
+
return parsed;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private Date parseDateWithPattern(String value, String pattern) {
|
|
337
|
+
try {
|
|
338
|
+
SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
|
|
339
|
+
sdf.setLenient(false);
|
|
340
|
+
|
|
341
|
+
// If no timezone is provided, keep historical behavior and interpret as local time.
|
|
342
|
+
if (!pattern.contains("X")) {
|
|
343
|
+
sdf.setTimeZone(TimeZone.getDefault());
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
ParsePosition position = new ParsePosition(0);
|
|
347
|
+
Date parsed = sdf.parse(value, position);
|
|
348
|
+
if (parsed != null && position.getIndex() == value.length()) {
|
|
349
|
+
return parsed;
|
|
350
|
+
}
|
|
351
|
+
} catch (Exception ignored) {}
|
|
352
|
+
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
private String convertDelayConditionsToJson(ArrayList<DelayCondition> conditions) {
|
|
357
|
+
JSONArray array = new JSONArray();
|
|
358
|
+
for (DelayCondition condition : conditions) {
|
|
359
|
+
try {
|
|
360
|
+
JSONObject obj = new JSONObject();
|
|
361
|
+
obj.put("kind", condition.getKind().name());
|
|
362
|
+
obj.put("value", condition.getValue());
|
|
363
|
+
array.put(obj);
|
|
364
|
+
} catch (JSONException e) {
|
|
365
|
+
logger.error("Failed to serialize delay condition: " + e.getMessage());
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return array.toString();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
public Boolean setMultiDelay(String delayConditions) {
|
|
372
|
+
try {
|
|
373
|
+
this.editor.putString(DELAY_CONDITION_PREFERENCES, delayConditions);
|
|
374
|
+
if (!this.editor.commit()) {
|
|
375
|
+
logger.error("Failed to delay update: commit returned false");
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
logger.info("Delay update saved");
|
|
379
|
+
return true;
|
|
380
|
+
} catch (final Exception e) {
|
|
381
|
+
logger.error("Failed to delay update, [Error calling '_setMultiDelay()'] " + e.getMessage());
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
public void setBackgroundTimestamp(long backgroundTimestamp) {
|
|
387
|
+
try {
|
|
388
|
+
this.editor.putLong(BACKGROUND_TIMESTAMP_KEY, backgroundTimestamp);
|
|
389
|
+
this.editor.commit();
|
|
390
|
+
logger.info("Background timestamp set");
|
|
391
|
+
} catch (final Exception e) {
|
|
392
|
+
logger.error("Failed to delay update, [Error calling '_setBackgroundTimestamp()'] " + e.getMessage());
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
public void unsetBackgroundTimestamp() {
|
|
397
|
+
try {
|
|
398
|
+
this.editor.remove(BACKGROUND_TIMESTAMP_KEY);
|
|
399
|
+
this.editor.commit();
|
|
400
|
+
logger.info("Background timestamp unset");
|
|
401
|
+
} catch (final Exception e) {
|
|
402
|
+
logger.error("Failed to delay update, [Error calling '_unsetBackgroundTimestamp()'] " + e.getMessage());
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
private long getBackgroundTimestamp() {
|
|
407
|
+
try {
|
|
408
|
+
return this.prefs.getLong(BACKGROUND_TIMESTAMP_KEY, 0);
|
|
409
|
+
} catch (final Exception e) {
|
|
410
|
+
logger.error("Failed to delay update, [Error calling '_getBackgroundTimestamp()'] " + e.getMessage());
|
|
411
|
+
return 0;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
public boolean cancelDelay(String source) {
|
|
416
|
+
try {
|
|
417
|
+
this.editor.remove(DELAY_CONDITION_PREFERENCES);
|
|
418
|
+
this.editor.remove(DELAY_CONDITION_MODE_PREFERENCES);
|
|
419
|
+
this.editor.commit();
|
|
420
|
+
logger.info("All delays canceled from " + source);
|
|
421
|
+
return true;
|
|
422
|
+
} catch (final Exception e) {
|
|
423
|
+
logger.error("Failed to cancel update delay " + e.getMessage());
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|