@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
|
@@ -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 DelayUntilNext.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 DelayUntilNext.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 DelayUntilNext.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 DelayUntilNext.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
|
+
}
|
|
@@ -66,7 +66,7 @@ public class DeviceIdHelper {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// Migration: Check legacy SharedPreferences for existing device ID
|
|
69
|
-
deviceId =
|
|
69
|
+
deviceId = legacyPrefs.getString(LEGACY_PREFS_KEY, null);
|
|
70
70
|
|
|
71
71
|
if (deviceId == null || deviceId.isEmpty()) {
|
|
72
72
|
// Generate new device ID if none exists
|
|
@@ -210,31 +210,14 @@ public class DeviceIdHelper {
|
|
|
210
210
|
* @return Device ID string
|
|
211
211
|
*/
|
|
212
212
|
private static String getFallbackDeviceId(SharedPreferences legacyPrefs) {
|
|
213
|
-
|
|
214
|
-
try {
|
|
215
|
-
String deviceId = readLegacyDeviceId(legacyPrefs);
|
|
213
|
+
String deviceId = legacyPrefs.getString(LEGACY_PREFS_KEY, null);
|
|
216
214
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return deviceId.toLowerCase();
|
|
223
|
-
} catch (RuntimeException e) {
|
|
224
|
-
return UUID.randomUUID().toString();
|
|
215
|
+
if (deviceId == null || deviceId.isEmpty()) {
|
|
216
|
+
deviceId = UUID.randomUUID().toString();
|
|
217
|
+
saveLegacyDeviceId(legacyPrefs, deviceId);
|
|
225
218
|
}
|
|
226
|
-
}
|
|
227
219
|
|
|
228
|
-
|
|
229
|
-
* The legacy ID, {@code null} when absent. A value stored with another type makes getString throw
|
|
230
|
-
* ClassCastException: it is no device ID (as text, "true" would be shared by many devices), so a new one replaces it.
|
|
231
|
-
*/
|
|
232
|
-
static String readLegacyDeviceId(SharedPreferences legacyPrefs) {
|
|
233
|
-
try {
|
|
234
|
-
return legacyPrefs.getString(LEGACY_PREFS_KEY, null);
|
|
235
|
-
} catch (ClassCastException e) {
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
220
|
+
return deviceId.toLowerCase();
|
|
238
221
|
}
|
|
239
222
|
|
|
240
223
|
private static void saveLegacyDeviceId(SharedPreferences legacyPrefs, String deviceId) {
|