@capgo/capacitor-updater 9.0.0 → 9.0.1

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.
Files changed (109) hide show
  1. package/CapgoCapacitorUpdater.podspec +3 -6
  2. package/Package.swift +30 -0
  3. package/README.md +2382 -292
  4. package/android/build.gradle +37 -15
  5. package/android/consumer-rules.pro +48 -0
  6. package/android/proguard-rules.pro +23 -0
  7. package/android/src/main/AndroidManifest.xml +0 -1
  8. package/android/src/main/java/ee/forgr/capacitor_updater/AndroidAppExitReporter.java +92 -0
  9. package/android/src/main/java/ee/forgr/capacitor_updater/AppLifecycleObserver.java +115 -0
  10. package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +227 -195
  11. package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +24 -23
  12. package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +13 -0
  13. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +7435 -1243
  14. package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +5144 -0
  15. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +564 -121
  16. package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +44 -0
  17. package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +43 -49
  18. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +4 -4
  19. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +427 -0
  20. package/android/src/main/java/ee/forgr/capacitor_updater/DeviceIdHelper.java +230 -0
  21. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +1969 -118
  22. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +278 -0
  23. package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +385 -0
  24. package/android/src/main/java/ee/forgr/capacitor_updater/Http3.java +356 -0
  25. package/android/src/main/java/ee/forgr/capacitor_updater/HttpEngineTransport.java +553 -0
  26. package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +79 -0
  27. package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +419 -0
  28. package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
  29. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeDetector.java +72 -0
  30. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +959 -0
  31. package/android/src/main/java/ee/forgr/capacitor_updater/StatsBatchFailureDiagnostics.java +40 -0
  32. package/android/src/main/java/ee/forgr/capacitor_updater/ThreeFingerPinchDetector.java +323 -0
  33. package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
  34. package/dist/docs.json +4431 -840
  35. package/dist/esm/definitions.d.ts +2607 -225
  36. package/dist/esm/definitions.js +103 -1
  37. package/dist/esm/definitions.js.map +1 -1
  38. package/dist/esm/history.d.ts +1 -0
  39. package/dist/esm/history.js +283 -0
  40. package/dist/esm/history.js.map +1 -0
  41. package/dist/esm/index.d.ts +3 -2
  42. package/dist/esm/index.js +5 -4
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/web.d.ts +53 -42
  45. package/dist/esm/web.js +180 -37
  46. package/dist/esm/web.js.map +1 -1
  47. package/dist/plugin.cjs.js +570 -37
  48. package/dist/plugin.cjs.js.map +1 -1
  49. package/dist/plugin.js +570 -37
  50. package/dist/plugin.js.map +1 -1
  51. package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +262 -0
  52. package/ios/Sources/CapacitorUpdaterPlugin/AppHealthTracker.swift +82 -0
  53. package/ios/Sources/CapacitorUpdaterPlugin/BundleInfo.swift +185 -0
  54. package/ios/Sources/CapacitorUpdaterPlugin/BundleStatus.swift +127 -0
  55. package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +5642 -0
  56. package/ios/Sources/CapacitorUpdaterPlugin/CapgoRawRsa.swift +36 -0
  57. package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +162 -0
  58. package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +4572 -0
  59. package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +380 -0
  60. package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +343 -0
  61. package/ios/Sources/CapacitorUpdaterPlugin/DeviceIdHelper.swift +120 -0
  62. package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +452 -0
  63. package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +380 -0
  64. package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
  65. package/ios/Sources/CapacitorUpdaterPlugin/RSA.swift +96 -0
  66. package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +97 -0
  67. package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +871 -0
  68. package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/UserDefaultsExtension.swift +0 -2
  69. package/ios/Sources/CapacitorUpdaterPlugin/WKWebView+CapgoObjcBridge.swift +20 -0
  70. package/ios/Sources/CapacitorUpdaterPlugin/WebViewStatsReporter.swift +304 -0
  71. package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
  72. package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
  73. package/ios/Tests/CapacitorUpdaterPluginTests/BuiltinHashesTests.swift +210 -0
  74. package/ios/Tests/CapacitorUpdaterPluginTests/BundleHardeningTests.swift +292 -0
  75. package/ios/Tests/CapacitorUpdaterPluginTests/CapacitorUpdaterPluginTests.swift +3905 -0
  76. package/ios/Tests/CapacitorUpdaterPluginTests/CapgoSemanticVersionTests.swift +64 -0
  77. package/ios/Tests/CapacitorUpdaterPluginTests/ChecksumRequiredTests.swift +151 -0
  78. package/ios/Tests/CapacitorUpdaterPluginTests/CliCryptoFixtureTests.swift +249 -0
  79. package/ios/Tests/CapacitorUpdaterPluginTests/HttpsOnlyBuiltinMinimumTests.swift +528 -0
  80. package/ios/Tests/CapacitorUpdaterPluginTests/InstallPerfTests.swift +174 -0
  81. package/ios/Tests/CapacitorUpdaterPluginTests/ListChannelsTests.swift +74 -0
  82. package/ios/Tests/CapacitorUpdaterPluginTests/LoggerSecurityTests.swift +149 -0
  83. package/ios/Tests/CapacitorUpdaterPluginTests/NativeContractTests.swift +160 -0
  84. package/ios/Tests/CapacitorUpdaterPluginTests/NetworkTransportTests.swift +1095 -0
  85. package/ios/Tests/CapacitorUpdaterPluginTests/PopulateDeltaCacheTests.swift +573 -0
  86. package/ios/Tests/CapacitorUpdaterPluginTests/RedirectPolicyTests.swift +63 -0
  87. package/ios/Tests/CapacitorUpdaterPluginTests/RsaContractTests.swift +281 -0
  88. package/ios/Tests/CapacitorUpdaterPluginTests/SessionKeyRequiredTests.swift +192 -0
  89. package/ios/Tests/CapacitorUpdaterPluginTests/TestZipWriter.swift +235 -0
  90. package/ios/Tests/CapacitorUpdaterPluginTests/UpdateLifecycleTests.swift +454 -0
  91. package/ios/Tests/CapacitorUpdaterPluginTests/WebKitOverlayGuardTests.swift +32 -0
  92. package/ios/Tests/CapacitorUpdaterPluginTests/ZipArchiveReaderTests.swift +302 -0
  93. package/ios/Tests/CapacitorUpdaterPluginTests/ZipBundleExtractionTests.swift +122 -0
  94. package/package.json +80 -43
  95. package/scripts/builtin-hashes-lib.mjs +148 -0
  96. package/scripts/capacitor-builtin-hashes-hook.mjs +65 -0
  97. package/scripts/resolve-real-path.mjs +25 -0
  98. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +0 -1130
  99. package/ios/Plugin/BundleInfo.swift +0 -113
  100. package/ios/Plugin/BundleStatus.swift +0 -48
  101. package/ios/Plugin/CapacitorUpdater.swift +0 -858
  102. package/ios/Plugin/CapacitorUpdaterPlugin.h +0 -10
  103. package/ios/Plugin/CapacitorUpdaterPlugin.m +0 -27
  104. package/ios/Plugin/CapacitorUpdaterPlugin.swift +0 -677
  105. package/ios/Plugin/CryptoCipher.swift +0 -240
  106. /package/{LICENCE → LICENSE} +0 -0
  107. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayCondition.swift +0 -0
  108. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayUntilNext.swift +0 -0
  109. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/Info.plist +0 -0
@@ -0,0 +1,356 @@
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
+ package ee.forgr.capacitor_updater;
7
+
8
+ import android.content.Context;
9
+ import android.os.Build;
10
+ import android.os.ext.SdkExtensions;
11
+ import androidx.annotation.NonNull;
12
+ import androidx.annotation.Nullable;
13
+ import java.io.IOException;
14
+ import java.net.SocketTimeoutException;
15
+ import java.util.List;
16
+ import java.util.Locale;
17
+ import java.util.Map;
18
+ import java.util.concurrent.TimeUnit;
19
+ import okhttp3.Call;
20
+ import okhttp3.Headers;
21
+ import okhttp3.HttpUrl;
22
+ import okhttp3.Interceptor;
23
+ import okhttp3.Protocol;
24
+ import okhttp3.Request;
25
+ import okhttp3.Response;
26
+
27
+ /**
28
+ * HTTP/3 for bundle and manifest downloads.
29
+ *
30
+ * <p>Where the device has the platform {@code android.net.http.HttpEngine} (Android 14+, or Android 12 and 13
31
+ * with the S extension at level 7), https downloads tagged with {@link #markDownload} run on one shared engine.
32
+ * The engine speaks HTTP/3 when the server advertises it through Alt-Svc and falls back to HTTP/2 on its own when
33
+ * QUIC is blocked. Its storage path and {@code HTTP_CACHE_DISK_NO_HTTP} cache keep the Alt-Svc entries across
34
+ * launches without caching any response, so the next process goes straight to HTTP/3 (finding from
35
+ * https://github.com/Cap-go/capacitor-updater/issues/1027, credit autopylotben).
36
+ *
37
+ * <p>Everything else stays on OkHttp: API calls, requests with a body, plain http, devices without HttpEngine,
38
+ * an engine that failed to start, and apps that set {@code http3: false}.
39
+ */
40
+ final class Http3 {
41
+
42
+ /** Request tag for downloads allowed to run on HttpEngine. */
43
+ static final class Download {
44
+
45
+ static final Download TAG = new Download();
46
+
47
+ private Download() {}
48
+ }
49
+
50
+ /** Runs one tagged download outside OkHttp's network stack. */
51
+ interface Transport {
52
+ @NonNull
53
+ Response execute(@NonNull Request request, int connectTimeoutMs, int readTimeoutMs, @Nullable Call call) throws IOException;
54
+ }
55
+
56
+ interface TransportFactory {
57
+ @NonNull
58
+ Transport create(@NonNull Context context, @Nullable Logger logger);
59
+ }
60
+
61
+ /**
62
+ * The engine made no progress at all (no callback for any request) for {@link #STALL_MS} while a download
63
+ * waited on it. Seen on an Android 16 emulator (HttpEngine 133): right after a large receive burst the QUIC session
64
+ * stops answering, and the engine only gives up on it after its own 6 to 40 s timeout.
65
+ */
66
+ static final class EngineStalledException extends SocketTimeoutException {
67
+
68
+ EngineStalledException(String message) {
69
+ super(message);
70
+ }
71
+ }
72
+
73
+ /**
74
+ * How long the whole engine may stay silent, while downloads wait on it, before they move to OkHttp. A live
75
+ * connection with requests in flight answers in a few round trips, far below this.
76
+ */
77
+ static final long STALL_MS = 500;
78
+ /** After a stall, new downloads skip the engine for this long instead of each paying the stall again. */
79
+ static final long STALL_COOLDOWN_MS = 60_000;
80
+
81
+ private static volatile Transport transport;
82
+ private static volatile boolean enabled = true;
83
+ // System.nanoTime() until which downloads skip the engine after a stall; only read while stalledOnce is true.
84
+ private static volatile long suspendedUntilNanos;
85
+ private static volatile boolean stalledOnce;
86
+ // True once the plugin or the headless worker applied the http3 config in this process.
87
+ private static volatile boolean configured;
88
+ // Guards the configured check plus the enabled write, kept apart from init() so it never waits on engine setup.
89
+ private static final Object OPTION_LOCK = new Object();
90
+ private static boolean initialized;
91
+
92
+ private Http3() {}
93
+
94
+ /** The http3 config value, applied by plugin load and the headless worker. Wins over saved job values. */
95
+ static void setEnabled(boolean value) {
96
+ synchronized (OPTION_LOCK) {
97
+ enabled = value;
98
+ configured = true;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * The http3 value saved with a WorkManager job. Only used when this process has not loaded the config yet
104
+ * (a job resumed in a fresh process), so a stale job never overrides the current config.
105
+ */
106
+ static void restoreSavedOption(boolean value) {
107
+ synchronized (OPTION_LOCK) {
108
+ if (!configured) {
109
+ enabled = value;
110
+ }
111
+ }
112
+ }
113
+
114
+ static boolean isEnabled() {
115
+ return enabled;
116
+ }
117
+
118
+ /** HttpEngine is public API from 34, and ships to 31-33 through the S extension at level 7. */
119
+ static boolean isHttpEngineAvailable(int sdkInt, int sExtensionVersion) {
120
+ return sdkInt >= 34 || (sdkInt >= 31 && sExtensionVersion >= 7);
121
+ }
122
+
123
+ private static int sExtensionVersion() {
124
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
125
+ return 0;
126
+ }
127
+ return SdkExtensions.getExtensionVersion(Build.VERSION_CODES.S);
128
+ }
129
+
130
+ /** Builds the shared engine once per process. Safe to call before every download. */
131
+ static void init(@NonNull Context context, @Nullable Logger logger) {
132
+ if (transport != null || !enabled) {
133
+ return;
134
+ }
135
+ int sdkInt = Build.VERSION.SDK_INT;
136
+ int extension;
137
+ try {
138
+ extension = sExtensionVersion();
139
+ } catch (RuntimeException e) {
140
+ extension = 0;
141
+ }
142
+ init(context, logger, sdkInt, extension, HttpEngineTransport::create);
143
+ }
144
+
145
+ static synchronized void init(
146
+ @NonNull Context context,
147
+ @Nullable Logger logger,
148
+ int sdkInt,
149
+ int sExtensionVersion,
150
+ @NonNull TransportFactory factory
151
+ ) {
152
+ if (initialized || !enabled) {
153
+ return;
154
+ }
155
+ initialized = true;
156
+ if (!isHttpEngineAvailable(sdkInt, sExtensionVersion)) {
157
+ debug(logger, "HttpEngine not available (API " + sdkInt + "), downloads stay on OkHttp");
158
+ return;
159
+ }
160
+ try {
161
+ transport = factory.create(context.getApplicationContext() != null ? context.getApplicationContext() : context, logger);
162
+ debug(logger, "HttpEngine ready, HTTP/3 enabled for bundle downloads");
163
+ } catch (RuntimeException | LinkageError e) {
164
+ // LinkageError: a device that reports the extension but cannot load the engine classes.
165
+ transport = null;
166
+ if (logger != null) {
167
+ logger.warn("HttpEngine failed to start, downloads stay on OkHttp: " + e.getMessage());
168
+ }
169
+ }
170
+ }
171
+
172
+ @Nullable
173
+ static Transport transport() {
174
+ return transport;
175
+ }
176
+
177
+ /** Called when the engine stalled: downloads use OkHttp for {@link #STALL_COOLDOWN_MS}. */
178
+ static void suspendAfterStall(long nowNanos) {
179
+ suspendedUntilNanos = nowNanos + TimeUnit.MILLISECONDS.toNanos(STALL_COOLDOWN_MS);
180
+ stalledOnce = true;
181
+ }
182
+
183
+ static boolean isSuspended(long nowNanos) {
184
+ return stalledOnce && nowNanos - suspendedUntilNanos < 0;
185
+ }
186
+
187
+ /** Test hook: forget the engine so the next init() starts over. */
188
+ static synchronized void resetForTest() {
189
+ transport = null;
190
+ initialized = false;
191
+ stalledOnce = false;
192
+ synchronized (OPTION_LOCK) {
193
+ enabled = true;
194
+ configured = false;
195
+ }
196
+ }
197
+
198
+ @NonNull
199
+ static Request.Builder markDownload(@NonNull Request.Builder builder) {
200
+ return builder.tag(Download.class, Download.TAG);
201
+ }
202
+
203
+ static boolean shouldUseEngine(@NonNull Request request) {
204
+ return (
205
+ enabled &&
206
+ request.tag(Download.class) != null &&
207
+ "GET".equals(request.method()) &&
208
+ request.body() == null &&
209
+ // HTTP/3 only exists over TLS, so plain http (local dev servers) keeps the OkHttp path.
210
+ request.isHttps() &&
211
+ !isSuspended(System.nanoTime())
212
+ );
213
+ }
214
+
215
+ /**
216
+ * Last application interceptor on the shared client, so User-Agent and the httpsOnly gate already ran.
217
+ * The engine follows redirects itself, and checks every hop with {@link #redirectError}.
218
+ */
219
+ static final class EngineInterceptor implements Interceptor {
220
+
221
+ @NonNull
222
+ @Override
223
+ public Response intercept(@NonNull Chain chain) throws IOException {
224
+ Request request = chain.request();
225
+ Transport current = transport;
226
+ if (current == null || !shouldUseEngine(request)) {
227
+ Response response = chain.proceed(request);
228
+ if (request.tag(Download.class) != null) {
229
+ logProtocol("OkHttp", response.protocol().toString(), request.url(), response.code());
230
+ }
231
+ return response;
232
+ }
233
+ try {
234
+ return current.execute(request, chain.connectTimeoutMillis(), chain.readTimeoutMillis(), chain.call());
235
+ } catch (EngineStalledException stall) {
236
+ // No response headers yet, so nothing reached the caller: retry this download on OkHttp right away.
237
+ suspendAfterStall(System.nanoTime());
238
+ Logger logger = DownloadService.logger();
239
+ if (logger != null) {
240
+ logger.warn("HttpEngine stalled, download moved to OkHttp: " + stall.getMessage());
241
+ }
242
+ Response response = chain.proceed(request);
243
+ logProtocol("OkHttp", response.protocol().toString(), request.url(), response.code());
244
+ return response;
245
+ }
246
+ }
247
+ }
248
+
249
+ /** Maps HttpEngine's ALPN name (h3, h2, http/1.1, quic/1+spdy/3...) to the closest OkHttp protocol. */
250
+ @NonNull
251
+ static Protocol protocolFor(@Nullable String negotiated) {
252
+ if (negotiated == null) {
253
+ return Protocol.HTTP_1_1;
254
+ }
255
+ String value = negotiated.toLowerCase(Locale.ROOT);
256
+ if (value.startsWith("h3") || value.startsWith("quic")) {
257
+ return Protocol.QUIC;
258
+ }
259
+ if (value.equals("h2")) {
260
+ return Protocol.HTTP_2;
261
+ }
262
+ if (value.equals("http/1.0")) {
263
+ return Protocol.HTTP_1_0;
264
+ }
265
+ return Protocol.HTTP_1_1;
266
+ }
267
+
268
+ /**
269
+ * HttpEngine always negotiates gzip/br and hands back the decoded body, but keeps the encoded headers. Drop
270
+ * Content-Encoding and Content-Length then, as OkHttp does after transparent gzip, so callers see an unknown
271
+ * length instead of a wrong one (the checksum still verifies the bytes).
272
+ */
273
+ @NonNull
274
+ static Headers responseHeaders(@NonNull List<Map.Entry<String, String>> fields) {
275
+ boolean decoded = false;
276
+ for (Map.Entry<String, String> field : fields) {
277
+ if (field.getKey() != null && field.getKey().equalsIgnoreCase("Content-Encoding") && isContentCoding(field.getValue())) {
278
+ decoded = true;
279
+ break;
280
+ }
281
+ }
282
+ Headers.Builder headers = new Headers.Builder();
283
+ for (Map.Entry<String, String> field : fields) {
284
+ String name = field.getKey();
285
+ if (name == null || field.getValue() == null) {
286
+ continue;
287
+ }
288
+ if (decoded && (name.equalsIgnoreCase("Content-Encoding") || name.equalsIgnoreCase("Content-Length"))) {
289
+ continue;
290
+ }
291
+ headers.addUnsafeNonAscii(name, field.getValue());
292
+ }
293
+ return headers.build();
294
+ }
295
+
296
+ /** {@code identity} (or an empty value) means no coding was applied, so the Content-Length stays valid. */
297
+ private static boolean isContentCoding(@Nullable String value) {
298
+ if (value == null) {
299
+ return false;
300
+ }
301
+ String coding = value.trim();
302
+ return !coding.isEmpty() && !coding.equalsIgnoreCase("identity");
303
+ }
304
+
305
+ /** Host only, for log and error messages: a signed download URL carries credentials in its query. */
306
+ @NonNull
307
+ static String safeHost(@Nullable String url) {
308
+ HttpUrl parsed = url == null ? null : HttpUrl.parse(url);
309
+ return parsed != null ? parsed.host() : "unknown host";
310
+ }
311
+
312
+ /** Same policy as the shared client's network interceptor, for redirects the engine follows itself. */
313
+ @Nullable
314
+ static IOException redirectError(@Nullable String from, @Nullable String to) {
315
+ return redirectError(from, to, DownloadService.httpsOnly, DownloadService.isAllowHttpsToHttpRedirect());
316
+ }
317
+
318
+ @Nullable
319
+ static IOException redirectError(@Nullable String from, @Nullable String to, boolean httpsOnly, boolean allowHttpsToHttp) {
320
+ HttpUrl target = to == null ? null : HttpUrl.parse(to);
321
+ if (target == null) {
322
+ return new IOException("Invalid redirect location");
323
+ }
324
+ if (httpsOnly && !target.isHttps()) {
325
+ return new IOException(CapgoUpdater.httpsOnlyMessage(to));
326
+ }
327
+ HttpUrl source = from == null ? null : HttpUrl.parse(from);
328
+ if (source != null && source.isHttps() && !target.isHttps() && !allowHttpsToHttp) {
329
+ return new DownloadService.BlockedRedirectException();
330
+ }
331
+ return null;
332
+ }
333
+
334
+ static void logProtocol(String transportName, @Nullable String protocol, @NonNull HttpUrl url, int code) {
335
+ Logger logger = DownloadService.logger();
336
+ if (logger != null) {
337
+ logger.debug(
338
+ "Download protocol " +
339
+ (protocol == null || protocol.isEmpty() ? "unknown" : protocol) +
340
+ " via " +
341
+ transportName +
342
+ " (HTTP " +
343
+ code +
344
+ ") " +
345
+ url.host() +
346
+ url.encodedPath()
347
+ );
348
+ }
349
+ }
350
+
351
+ private static void debug(@Nullable Logger logger, String message) {
352
+ if (logger != null) {
353
+ logger.debug(message);
354
+ }
355
+ }
356
+ }