@kesha-antonov/react-native-background-downloader 4.8.0 → 5.0.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.
Files changed (66) hide show
  1. package/README.md +10 -5
  2. package/android/build.gradle +5 -1
  3. package/android/consumer-rules.pro +14 -0
  4. package/android/src/main/AndroidManifest.xml +18 -1
  5. package/android/src/main/java/com/eko/UIDTDownloadJobService.kt +5 -567
  6. package/android/src/main/java/com/eko/uidt/CancelDownloadReceiver.kt +4 -58
  7. package/android/src/main/java/com/{eko → kesha_antonov}/DownloadConstants.kt +1 -1
  8. package/android/src/main/java/com/{eko → kesha_antonov}/DownloadEventEmitter.kt +1 -1
  9. package/android/src/main/java/com/{eko → kesha_antonov}/DownloadResult.kt +1 -1
  10. package/android/src/main/java/com/{eko → kesha_antonov}/Downloader.kt +2 -2
  11. package/android/src/main/java/com/{eko → kesha_antonov}/ProgressReporter.kt +1 -1
  12. package/android/src/main/java/com/{eko → kesha_antonov}/PromiseExtensions.kt +1 -1
  13. package/android/src/main/java/com/{eko → kesha_antonov}/RNBGDTaskConfig.kt +1 -1
  14. package/android/src/main/java/com/{eko → kesha_antonov}/RNBGDUploadTaskConfig.kt +1 -1
  15. package/android/src/main/java/com/{eko → kesha_antonov}/RNBackgroundDownloaderModuleImpl.kt +9 -9
  16. package/android/src/main/java/com/{eko → kesha_antonov}/RNBackgroundDownloaderPackage.kt +1 -1
  17. package/android/src/main/java/com/{eko → kesha_antonov}/ResumableDownloadService.kt +11 -9
  18. package/android/src/main/java/com/{eko → kesha_antonov}/ResumableDownloader.kt +2 -2
  19. package/android/src/main/java/com/kesha_antonov/UIDTDownloadJobService.kt +590 -0
  20. package/android/src/main/java/com/{eko → kesha_antonov}/UnmeteredNetworkGate.kt +2 -2
  21. package/android/src/main/java/com/{eko → kesha_antonov}/UploadEventEmitter.kt +1 -1
  22. package/android/src/main/java/com/{eko → kesha_antonov}/Uploader.kt +2 -2
  23. package/android/src/main/java/com/{eko → kesha_antonov}/handlers/OnBegin.kt +4 -4
  24. package/android/src/main/java/com/{eko → kesha_antonov}/handlers/OnBeginState.kt +1 -1
  25. package/android/src/main/java/com/{eko → kesha_antonov}/handlers/OnProgress.kt +4 -4
  26. package/android/src/main/java/com/{eko → kesha_antonov}/handlers/OnProgressState.kt +1 -1
  27. package/android/src/main/java/com/{eko → kesha_antonov}/interfaces/BeginCallback.kt +1 -1
  28. package/android/src/main/java/com/{eko → kesha_antonov}/interfaces/ProgressCallback.kt +1 -1
  29. package/android/src/main/java/com/kesha_antonov/uidt/CancelDownloadReceiver.kt +68 -0
  30. package/android/src/main/java/com/{eko → kesha_antonov}/uidt/RNBGDFileProvider.kt +1 -1
  31. package/android/src/main/java/com/{eko → kesha_antonov}/uidt/UIDTJobIds.kt +9 -4
  32. package/android/src/main/java/com/{eko → kesha_antonov}/uidt/UIDTJobManager.kt +6 -6
  33. package/android/src/main/java/com/{eko → kesha_antonov}/uidt/UIDTJobState.kt +7 -5
  34. package/android/src/main/java/com/{eko → kesha_antonov}/uidt/UIDTNotificationIds.kt +1 -1
  35. package/android/src/main/java/com/{eko → kesha_antonov}/uidt/UIDTNotificationManager.kt +18 -10
  36. package/android/src/main/java/com/{eko → kesha_antonov}/utils/FileUtils.kt +1 -1
  37. package/android/src/main/java/com/{eko → kesha_antonov}/utils/HeaderUtils.kt +2 -2
  38. package/android/src/main/java/com/{eko → kesha_antonov}/utils/NetworkRequestUtils.kt +1 -1
  39. package/android/src/main/java/com/kesha_antonov/utils/NotificationUtils.kt +24 -0
  40. package/android/src/main/java/com/{eko → kesha_antonov}/utils/ProgressUtils.kt +1 -1
  41. package/android/src/main/java/com/{eko → kesha_antonov}/utils/ReadableConverters.kt +1 -1
  42. package/android/src/main/java/com/{eko → kesha_antonov}/utils/RedirectResolver.kt +3 -3
  43. package/android/src/main/java/com/{eko → kesha_antonov}/utils/StorageManager.kt +5 -5
  44. package/android/src/main/java/com/{eko → kesha_antonov}/utils/TempFileUtils.kt +2 -2
  45. package/android/src/newarch/java/com/{eko → kesha_antonov}/RNBackgroundDownloaderModule.kt +1 -1
  46. package/android/src/oldarch/java/com/{eko → kesha_antonov}/RNBackgroundDownloaderModule.kt +1 -1
  47. package/android/src/test/java/com/{eko → kesha_antonov}/DownloadCompleteReceiverTest.kt +1 -1
  48. package/android/src/test/java/com/{eko → kesha_antonov}/DownloaderRecoveryTest.kt +2 -2
  49. package/android/src/test/java/com/{eko → kesha_antonov}/DownloaderResumeTest.kt +3 -3
  50. package/android/src/test/java/com/{eko → kesha_antonov}/ResumableDownloaderConcurrencyTest.kt +1 -1
  51. package/android/src/test/java/com/{eko → kesha_antonov}/ResumableDownloaderRedirectTest.kt +1 -1
  52. package/android/src/test/java/com/{eko → kesha_antonov}/ResumableDownloaderStallTest.kt +1 -1
  53. package/android/src/test/java/com/{eko → kesha_antonov}/UnmeteredNetworkGateTest.kt +1 -1
  54. package/android/src/test/java/com/{eko → kesha_antonov}/UploadPartRangesTest.kt +1 -1
  55. package/android/src/test/java/com/{eko → kesha_antonov}/UploaderMultipartTest.kt +1 -1
  56. package/android/src/test/java/com/{eko → kesha_antonov}/UploaderPartsTest.kt +1 -1
  57. package/android/src/test/java/com/{eko → kesha_antonov}/UploaderResponseTest.kt +1 -1
  58. package/android/src/test/java/com/{eko → kesha_antonov}/handlers/OnBeginTest.kt +2 -2
  59. package/android/src/test/java/com/{eko → kesha_antonov}/uidt/CancelDownloadReceiverTest.kt +25 -2
  60. package/android/src/test/java/com/{eko → kesha_antonov}/uidt/UIDTJobIdsTest.kt +13 -2
  61. package/android/src/test/java/com/{eko → kesha_antonov}/uidt/UIDTJobManagerTest.kt +1 -1
  62. package/android/src/test/java/com/{eko → kesha_antonov}/uidt/UIDTNotificationIdsTest.kt +1 -1
  63. package/android/src/test/java/com/{eko → kesha_antonov}/utils/RedirectResolverTest.kt +1 -1
  64. package/bin/react-native-background-downloader.js +197 -0
  65. package/ios/RNBackgroundDownloader.mm +25 -5
  66. package/package.json +5 -2
@@ -1,4 +1,4 @@
1
- package com.eko.interfaces
1
+ package com.kesha_antonov.interfaces
2
2
 
3
3
  fun interface ProgressCallback {
4
4
  fun onProgress(configId: String, bytesDownloaded: Long, bytesTotal: Long)
@@ -0,0 +1,68 @@
1
+ package com.kesha_antonov.uidt
2
+
3
+ import android.content.BroadcastReceiver
4
+ import android.content.Context
5
+ import android.content.Intent
6
+ import android.os.Build
7
+ import androidx.annotation.RequiresApi
8
+ import com.kesha_antonov.RNBackgroundDownloaderModuleImpl
9
+
10
+ /**
11
+ * Receives the cancel action fired from the download progress notification.
12
+ * The action carries the download's [EXTRA_CONFIG_ID] as a string extra; on
13
+ * receive we stop the download and dispatch a downloadFailed event so JS can
14
+ * clean up.
15
+ *
16
+ * Cancelling from the shade must leave exactly the same state behind as
17
+ * `task.stop()` from JS, so the work is delegated to the module's stopTask
18
+ * (progress tracking, resumable + DownloadManager cancellation, persisted
19
+ * maps and paused records). Only when the module is not up - a cold start
20
+ * triggered by this very broadcast - do we fall back to cancelling the UIDT
21
+ * job on its own.
22
+ */
23
+ @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
24
+ open class CancelDownloadReceiver : BroadcastReceiver() {
25
+
26
+ override fun onReceive(context: Context, intent: Intent) {
27
+ if (intent.action != ACTION_CANCEL_DOWNLOAD && intent.action != LEGACY_ACTION_CANCEL_DOWNLOAD) return
28
+ val configId = intent.getStringExtra(EXTRA_CONFIG_ID) ?: return
29
+
30
+ RNBackgroundDownloaderModuleImpl.logD(
31
+ UIDTConstants.TAG,
32
+ "CancelDownloadReceiver: cancelling $configId",
33
+ )
34
+
35
+ // Snapshot liveness first: stopTask tears the job down, so afterwards we
36
+ // can no longer tell an active download from an already-finished one.
37
+ // A job the system stopped (e.g. waiting for Wi-Fi) is no longer active but still
38
+ // scheduled, and its notification with this action stays up - that counts too.
39
+ val wasActive = UIDTJobRegistry.isActiveJob(configId) || UIDTJobManager.isScheduledJob(context, configId)
40
+
41
+ if (!RNBackgroundDownloaderModuleImpl.stopTaskFromNative(configId)) {
42
+ RNBackgroundDownloaderModuleImpl.logD(
43
+ UIDTConstants.TAG,
44
+ "CancelDownloadReceiver: module not initialized, cancelling job directly",
45
+ )
46
+ UIDTJobManager.cancelJob(context, configId)
47
+ }
48
+
49
+ // Only notify JS when a live job was actually cancelled. If the download
50
+ // already finished there is nothing to clean up, and dispatching here
51
+ // would emit a spurious downloadFailed for an already-completed task.
52
+ if (wasActive) {
53
+ // Notify JS so the in-memory task map can be cleaned and the
54
+ // .error() handler runs (lib uses CANCELLED errorCode = -1).
55
+ UIDTJobRegistry.downloadListener?.onError(configId, CANCELLED_MESSAGE, CANCELLED_ERROR_CODE)
56
+ }
57
+ }
58
+
59
+ companion object {
60
+ const val ACTION_CANCEL_DOWNLOAD = "com.kesha_antonov.uidt.ACTION_CANCEL_DOWNLOAD"
61
+ // The action of notifications posted before v5.0.0
62
+ const val LEGACY_ACTION_CANCEL_DOWNLOAD = "com.eko.uidt.ACTION_CANCEL_DOWNLOAD"
63
+ const val EXTRA_CONFIG_ID = "config_id"
64
+
65
+ private const val CANCELLED_MESSAGE = "Download cancelled by user"
66
+ private const val CANCELLED_ERROR_CODE = -1
67
+ }
68
+ }
@@ -1,4 +1,4 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import androidx.core.content.FileProvider
4
4
 
@@ -1,9 +1,9 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import android.app.job.JobInfo
4
4
  import android.os.Build
5
5
  import androidx.annotation.RequiresApi
6
- import com.eko.UIDTDownloadJobService
6
+ import com.kesha_antonov.UIDTDownloadJobService
7
7
 
8
8
  /**
9
9
  * Assigns the JobScheduler job IDs used for UIDT downloads.
@@ -32,7 +32,12 @@ internal object UIDTJobIds {
32
32
  /** configId -> ID picked but not yet handed to the JobScheduler. */
33
33
  private val reservations = mutableMapOf<String, Int>()
34
34
 
35
- private val serviceName = UIDTDownloadJobService::class.java.name
35
+ // Jobs scheduled before v5.0.0 name the service by its old class, which
36
+ // still runs them (com.eko.UIDTDownloadJobService)
37
+ private val serviceNames = setOf(
38
+ UIDTDownloadJobService::class.java.name,
39
+ "com.eko.UIDTDownloadJobService",
40
+ )
36
41
 
37
42
  /**
38
43
  * The ID a download would have had before IDs were assigned. Still the
@@ -45,7 +50,7 @@ internal object UIDTJobIds {
45
50
 
46
51
  /** The download a scheduled job belongs to, or null if it isn't one of ours. */
47
52
  fun configIdOf(job: JobInfo): String? {
48
- if (job.service.className != serviceName) return null
53
+ if (job.service.className !in serviceNames) return null
49
54
  return job.extras.getString(UIDTConstants.KEY_DOWNLOAD_ID)
50
55
  }
51
56
 
@@ -1,4 +1,4 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import android.app.DownloadManager
4
4
  import android.app.NotificationManager
@@ -7,14 +7,14 @@ import android.app.job.JobScheduler
7
7
  import android.app.job.JobService
8
8
  import android.content.ComponentName
9
9
  import android.content.Context
10
- import com.eko.utils.NetworkRequestUtils
10
+ import com.kesha_antonov.utils.NetworkRequestUtils
11
11
  import android.os.Build
12
12
  import android.os.PersistableBundle
13
13
  import androidx.annotation.RequiresApi
14
- import com.eko.RNBackgroundDownloaderModuleImpl
15
- import com.eko.ResumableDownloader
16
- import com.eko.UIDTDownloadJobService
17
- import com.eko.utils.ProgressUtils
14
+ import com.kesha_antonov.RNBackgroundDownloaderModuleImpl
15
+ import com.kesha_antonov.ResumableDownloader
16
+ import com.kesha_antonov.UIDTDownloadJobService
17
+ import com.kesha_antonov.utils.ProgressUtils
18
18
 
19
19
  /**
20
20
  * Manages UIDT job scheduling, cancellation, pause and resume operations.
@@ -1,9 +1,9 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import android.app.job.JobParameters
4
4
  import android.content.Context
5
- import com.eko.RNBackgroundDownloaderModuleImpl
6
- import com.eko.ResumableDownloader
5
+ import com.kesha_antonov.RNBackgroundDownloaderModuleImpl
6
+ import com.kesha_antonov.ResumableDownloader
7
7
  import org.json.JSONObject
8
8
  import java.util.concurrent.ConcurrentHashMap
9
9
 
@@ -21,6 +21,8 @@ data class JobState(
21
21
  val customTitle: String = "",
22
22
  var lastNotifiedProgress: Int = -1,
23
23
  var lastNotificationUpdateTime: Long = 0,
24
+ // When the byte position was last written to disk (see UIDTDownloadJobService.RESUME_SAVE_INTERVAL_MS)
25
+ var lastResumeSaveTime: Long = 0,
24
26
  // Track download progress for summary notification
25
27
  @Volatile var bytesDownloaded: Long = 0L,
26
28
  @Volatile var bytesTotal: Long = -1L
@@ -121,7 +123,7 @@ object UIDTConstants {
121
123
  const val NOTIFICATION_CHANNEL_FINISHED_ID = "uidt_download_channel_finished"
122
124
 
123
125
  // Notification group for grouping all download notifications together
124
- const val NOTIFICATION_GROUP_KEY = "com.eko.DOWNLOAD_GROUP"
126
+ const val NOTIFICATION_GROUP_KEY = "com.kesha_antonov.DOWNLOAD_GROUP"
125
127
 
126
128
  // Summary notification ID (used to group all download notifications)
127
129
  const val SUMMARY_NOTIFICATION_ID = 19999
@@ -224,7 +226,7 @@ object UIDTJobRegistry {
224
226
 
225
227
  // Store service instance reference for notification updates
226
228
  @Volatile
227
- var serviceInstance: com.eko.UIDTDownloadJobService? = null
229
+ var serviceInstance: com.kesha_antonov.UIDTDownloadJobService? = null
228
230
 
229
231
  // Notification configuration
230
232
  val notificationConfig = NotificationConfig()
@@ -1,4 +1,4 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import android.os.Build
4
4
  import androidx.annotation.RequiresApi
@@ -1,4 +1,4 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import android.app.Notification
4
4
  import android.app.NotificationChannel
@@ -13,9 +13,10 @@ import android.os.Build
13
13
  import androidx.annotation.RequiresApi
14
14
  import androidx.core.app.NotificationCompat
15
15
  import androidx.core.content.FileProvider
16
- import com.eko.RNBackgroundDownloaderModuleImpl
17
- import com.eko.UIDTDownloadJobService
18
- import com.eko.utils.ProgressUtils
16
+ import com.kesha_antonov.RNBackgroundDownloaderModuleImpl
17
+ import com.kesha_antonov.UIDTDownloadJobService
18
+ import com.kesha_antonov.utils.NotificationUtils.applyOpenAppIntent
19
+ import com.kesha_antonov.utils.ProgressUtils
19
20
  import java.io.File
20
21
  import java.net.URLConnection
21
22
 
@@ -203,6 +204,7 @@ object UIDTNotificationManager {
203
204
  .setProgress(0, 0, true)
204
205
 
205
206
  applyCancelAction(builder, context, configId)
207
+ applyOpenAppIntent(builder, context)
206
208
 
207
209
  // Apply grouping when enabled and groupId is provided
208
210
  if (config.groupingEnabled && groupId.isNotEmpty()) {
@@ -257,6 +259,7 @@ object UIDTNotificationManager {
257
259
  .setProgress(100, progress, bytesTotal <= 0)
258
260
 
259
261
  applyCancelAction(builder, context, configId)
262
+ applyOpenAppIntent(builder, context)
260
263
 
261
264
  // Apply grouping when enabled
262
265
  if (config.groupingEnabled && jobState.groupId.isNotEmpty()) {
@@ -285,7 +288,7 @@ object UIDTNotificationManager {
285
288
  config.getText("downloadTitle")
286
289
  }
287
290
 
288
- val notification = NotificationCompat.Builder(context, UIDTConstants.NOTIFICATION_CHANNEL_ID)
291
+ val pausedBuilder = NotificationCompat.Builder(context, UIDTConstants.NOTIFICATION_CHANNEL_ID)
289
292
  .setContentTitle(title)
290
293
  .setContentText(config.getText("downloadPaused"))
291
294
  .setSmallIcon(android.R.drawable.stat_sys_download_done)
@@ -294,7 +297,8 @@ object UIDTNotificationManager {
294
297
  .setOnlyAlertOnce(true)
295
298
  .setShowWhen(false)
296
299
  .setProgress(100, progress, false)
297
- .build()
300
+ applyOpenAppIntent(pausedBuilder, context)
301
+ val notification = pausedBuilder.build()
298
302
 
299
303
  val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
300
304
  notificationManager.notify(notificationId, notification)
@@ -332,6 +336,8 @@ object UIDTNotificationManager {
332
336
  .setShowWhen(false)
333
337
  .setProgress(100, progress, bytesTotal <= 0)
334
338
 
339
+ applyCancelAction(builder, context, configId)
340
+ applyOpenAppIntent(builder, context)
335
341
  val notification = builder.build()
336
342
 
337
343
  val service = UIDTJobRegistry.serviceInstance
@@ -398,7 +404,7 @@ object UIDTNotificationManager {
398
404
  val title = groupName.ifEmpty { config.getText("groupTitle") }
399
405
  val text = config.getText("groupText", "count" to groupDownloads)
400
406
 
401
- val summaryNotification = NotificationCompat.Builder(context, UIDTConstants.NOTIFICATION_CHANNEL_ID)
407
+ val summaryBuilder = NotificationCompat.Builder(context, UIDTConstants.NOTIFICATION_CHANNEL_ID)
402
408
  .setContentTitle(title)
403
409
  .setContentText(text)
404
410
  .setSmallIcon(android.R.drawable.stat_sys_download)
@@ -408,7 +414,8 @@ object UIDTNotificationManager {
408
414
  .setOngoing(true)
409
415
  .setOnlyAlertOnce(true)
410
416
  .setShowWhen(false)
411
- .build()
417
+ applyOpenAppIntent(summaryBuilder, context)
418
+ val summaryNotification = summaryBuilder.build()
412
419
 
413
420
  notificationManager.notify(summaryNotificationId, summaryNotification)
414
421
  }
@@ -478,7 +485,7 @@ object UIDTNotificationManager {
478
485
 
479
486
  // Create a standalone progress notification (NOT part of the group)
480
487
  // This ensures progress bar is visible in collapsed view
481
- val progressNotification = NotificationCompat.Builder(context, UIDTConstants.NOTIFICATION_CHANNEL_ID)
488
+ val progressBuilder = NotificationCompat.Builder(context, UIDTConstants.NOTIFICATION_CHANNEL_ID)
482
489
  .setContentTitle(title)
483
490
  .setContentText(text)
484
491
  .setSmallIcon(android.R.drawable.stat_sys_download)
@@ -488,7 +495,8 @@ object UIDTNotificationManager {
488
495
  .setOnlyAlertOnce(true)
489
496
  .setShowWhen(false)
490
497
  .setProgress(100, progress, indeterminate)
491
- .build()
498
+ applyOpenAppIntent(progressBuilder, context)
499
+ val progressNotification = progressBuilder.build()
492
500
 
493
501
  notificationManager.notify(summaryNotificationId, progressNotification)
494
502
 
@@ -1,4 +1,4 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
3
  import java.io.File
4
4
  import java.io.FileInputStream
@@ -1,7 +1,7 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
3
  import android.app.DownloadManager
4
- import com.eko.DownloadConstants
4
+ import com.kesha_antonov.DownloadConstants
5
5
  import com.facebook.react.bridge.ReadableMap
6
6
  import java.net.HttpURLConnection
7
7
 
@@ -1,4 +1,4 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
3
  import android.net.NetworkCapabilities
4
4
  import android.net.NetworkRequest
@@ -0,0 +1,24 @@
1
+ package com.kesha_antonov.utils
2
+
3
+ import android.app.PendingIntent
4
+ import android.content.Context
5
+ import androidx.core.app.NotificationCompat
6
+
7
+ object NotificationUtils {
8
+ /**
9
+ * Tapping the notification brings the host app to the front (the launcher
10
+ * intent reuses the running task instead of starting a second one).
11
+ * Does nothing when the app has no launcher activity.
12
+ */
13
+ fun applyOpenAppIntent(builder: NotificationCompat.Builder, context: Context) {
14
+ val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName) ?: return
15
+ builder.setContentIntent(
16
+ PendingIntent.getActivity(
17
+ context,
18
+ 0,
19
+ launchIntent,
20
+ PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
21
+ )
22
+ )
23
+ }
24
+ }
@@ -1,4 +1,4 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
3
  /**
4
4
  * Utility functions for calculating download progress.
@@ -1,4 +1,4 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
3
  import com.facebook.react.bridge.ReadableArray
4
4
  import com.facebook.react.bridge.ReadableMap
@@ -1,7 +1,7 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
- import com.eko.DownloadConstants
4
- import com.eko.RNBackgroundDownloaderModuleImpl
3
+ import com.kesha_antonov.DownloadConstants
4
+ import com.kesha_antonov.RNBackgroundDownloaderModuleImpl
5
5
  import com.facebook.react.bridge.ReadableMap
6
6
  import java.net.HttpURLConnection
7
7
  import java.net.URL
@@ -1,11 +1,11 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
3
  import android.content.Context
4
4
  import android.content.SharedPreferences
5
- import com.eko.Downloader
6
- import com.eko.RNBackgroundDownloaderModuleImpl
7
- import com.eko.RNBGDTaskConfig
8
- import com.eko.RNBGDUploadTaskConfig
5
+ import com.kesha_antonov.Downloader
6
+ import com.kesha_antonov.RNBackgroundDownloaderModuleImpl
7
+ import com.kesha_antonov.RNBGDTaskConfig
8
+ import com.kesha_antonov.RNBGDUploadTaskConfig
9
9
  import com.google.gson.Gson
10
10
  import com.google.gson.reflect.TypeToken
11
11
  import com.tencent.mmkv.MMKV
@@ -1,6 +1,6 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
- import com.eko.RNBackgroundDownloaderModuleImpl
3
+ import com.kesha_antonov.RNBackgroundDownloaderModuleImpl
4
4
  import java.io.File
5
5
 
6
6
  /**
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
4
  import com.facebook.react.bridge.ReactMethod
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import com.facebook.react.bridge.Promise
4
4
  import com.facebook.react.bridge.ReactApplicationContext
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import android.app.Application
4
4
  import android.app.DownloadManager
@@ -1,8 +1,8 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import android.content.Context
4
4
  import androidx.test.core.app.ApplicationProvider
5
- import com.eko.utils.StorageManager
5
+ import com.kesha_antonov.utils.StorageManager
6
6
  import org.junit.Assert.assertEquals
7
7
  import org.junit.Assert.assertTrue
8
8
  import org.junit.Rule
@@ -1,10 +1,10 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import android.app.job.JobScheduler
4
4
  import android.content.Context
5
5
  import androidx.test.core.app.ApplicationProvider
6
- import com.eko.uidt.UIDTConstants
7
- import com.eko.uidt.UIDTJobRegistry
6
+ import com.kesha_antonov.uidt.UIDTConstants
7
+ import com.kesha_antonov.uidt.UIDTJobRegistry
8
8
  import org.junit.Assert.assertEquals
9
9
  import org.junit.Assert.assertTrue
10
10
  import org.junit.Before
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import okhttp3.mockwebserver.Dispatcher
4
4
  import okhttp3.mockwebserver.MockResponse
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import okhttp3.mockwebserver.MockResponse
4
4
  import okhttp3.mockwebserver.MockWebServer
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import okhttp3.mockwebserver.Dispatcher
4
4
  import okhttp3.mockwebserver.MockResponse
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import android.content.Context
4
4
  import android.net.ConnectivityManager
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import org.junit.Assert.assertEquals
4
4
  import org.junit.Assert.assertNull
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import androidx.test.core.app.ApplicationProvider
4
4
  import okhttp3.mockwebserver.MockResponse
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import androidx.test.core.app.ApplicationProvider
4
4
  import okhttp3.mockwebserver.Dispatcher
@@ -1,4 +1,4 @@
1
- package com.eko
1
+ package com.kesha_antonov
2
2
 
3
3
  import org.junit.Assert.assertEquals
4
4
  import org.junit.Test
@@ -1,6 +1,6 @@
1
- package com.eko.handlers
1
+ package com.kesha_antonov.handlers
2
2
 
3
- import com.eko.RNBGDTaskConfig
3
+ import com.kesha_antonov.RNBGDTaskConfig
4
4
  import okhttp3.mockwebserver.MockResponse
5
5
  import okhttp3.mockwebserver.MockWebServer
6
6
  import org.junit.After
@@ -1,10 +1,13 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
+ import android.app.job.JobInfo
3
4
  import android.app.job.JobScheduler
5
+ import android.content.ComponentName
4
6
  import android.content.Context
5
7
  import android.content.Intent
8
+ import android.os.PersistableBundle
6
9
  import androidx.test.core.app.ApplicationProvider
7
- import com.eko.ResumableDownloader
10
+ import com.kesha_antonov.ResumableDownloader
8
11
  import org.junit.After
9
12
  import org.junit.Assert.assertEquals
10
13
  import org.junit.Assert.assertTrue
@@ -75,6 +78,26 @@ class CancelDownloadReceiverTest {
75
78
  assertTrue(jobScheduler.allPendingJobs.isEmpty())
76
79
  }
77
80
 
81
+ @Test
82
+ fun `the Cancel button of a notification from before the package rename still cancels`() {
83
+ // A job v4.x scheduled names the old service class
84
+ jobScheduler.schedule(
85
+ JobInfo.Builder(34567, ComponentName(context, "com.eko.UIDTDownloadJobService"))
86
+ .setExtras(PersistableBundle().apply { putString(UIDTConstants.KEY_DOWNLOAD_ID, "old") })
87
+ .setMinimumLatency(1000)
88
+ .build()
89
+ )
90
+
91
+ com.eko.uidt.CancelDownloadReceiver().onReceive(
92
+ context,
93
+ Intent(CancelDownloadReceiver.LEGACY_ACTION_CANCEL_DOWNLOAD)
94
+ .putExtra(CancelDownloadReceiver.EXTRA_CONFIG_ID, "old")
95
+ )
96
+
97
+ assertEquals(listOf("old" to -1), errors)
98
+ assertTrue(jobScheduler.allPendingJobs.isEmpty())
99
+ }
100
+
78
101
  @Test
79
102
  fun `cancelling a download that already ended reports nothing`() {
80
103
  cancel("finished")
@@ -1,11 +1,11 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import android.app.job.JobInfo
4
4
  import android.content.ComponentName
5
5
  import android.content.Context
6
6
  import android.os.PersistableBundle
7
7
  import androidx.test.core.app.ApplicationProvider
8
- import com.eko.UIDTDownloadJobService
8
+ import com.kesha_antonov.UIDTDownloadJobService
9
9
  import org.junit.Assert.assertEquals
10
10
  import org.junit.Assert.assertNotEquals
11
11
  import org.junit.Assert.assertNull
@@ -69,6 +69,17 @@ class UIDTJobIdsTest {
69
69
  assertNull(UIDTJobIds.configIdOf(jobs.first()))
70
70
  }
71
71
 
72
+ @Test
73
+ fun `a download scheduled before the package rename is still ours`() {
74
+ val legacyJob = JobInfo.Builder(34567, ComponentName(context, "com.eko.UIDTDownloadJobService"))
75
+ .setExtras(PersistableBundle().apply { putString(UIDTConstants.KEY_DOWNLOAD_ID, "a") })
76
+ .setMinimumLatency(1000)
77
+ .build()
78
+
79
+ assertEquals("a", UIDTJobIds.configIdOf(legacyJob))
80
+ assertEquals(34567, UIDTJobIds.jobIdFor("a", listOf(legacyJob)))
81
+ }
82
+
72
83
  @Test
73
84
  fun `colliding downloads reserve different job IDs`() {
74
85
  val first = UIDTJobIds.reserveJobId(colliding.first, emptyList())
@@ -1,4 +1,4 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import android.app.DownloadManager
4
4
  import android.app.job.JobInfo
@@ -1,4 +1,4 @@
1
- package com.eko.uidt
1
+ package com.kesha_antonov.uidt
2
2
 
3
3
  import org.junit.Assert.assertEquals
4
4
  import org.junit.Assert.assertNotEquals
@@ -1,4 +1,4 @@
1
- package com.eko.utils
1
+ package com.kesha_antonov.utils
2
2
 
3
3
  import okhttp3.mockwebserver.Dispatcher
4
4
  import okhttp3.mockwebserver.MockResponse