|
@@ -7,10 +7,11 @@
|
|
|
*/
|
|
|
package com.nextcloud.client.jobs.transfer
|
|
|
|
|
|
-import android.app.Service
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
import android.os.IBinder
|
|
|
+import androidx.lifecycle.Lifecycle
|
|
|
+import androidx.lifecycle.LifecycleService
|
|
|
import com.nextcloud.client.account.User
|
|
|
import com.nextcloud.client.core.AsyncRunner
|
|
|
import com.nextcloud.client.core.LocalBinder
|
|
@@ -23,10 +24,8 @@ import com.nextcloud.client.logger.Logger
|
|
|
import com.nextcloud.client.network.ClientFactory
|
|
|
import com.nextcloud.client.network.ConnectivityService
|
|
|
import com.nextcloud.client.notifications.AppNotificationManager
|
|
|
-import com.nextcloud.model.AppLifecycle
|
|
|
import com.nextcloud.utils.ForegroundServiceHelper
|
|
|
import com.nextcloud.utils.extensions.getParcelableArgument
|
|
|
-import com.owncloud.android.MainApp
|
|
|
import com.owncloud.android.datamodel.FileDataStorageManager
|
|
|
import com.owncloud.android.datamodel.ForegroundServiceType
|
|
|
import com.owncloud.android.datamodel.UploadsStorageManager
|
|
@@ -34,7 +33,7 @@ import dagger.android.AndroidInjection
|
|
|
import javax.inject.Inject
|
|
|
import javax.inject.Named
|
|
|
|
|
|
-class FileTransferService : Service() {
|
|
|
+class FileTransferService : LifecycleService() {
|
|
|
|
|
|
companion object {
|
|
|
const val TAG = "DownloaderService"
|
|
@@ -98,12 +97,12 @@ class FileTransferService : Service() {
|
|
|
AndroidInjection.inject(this)
|
|
|
}
|
|
|
|
|
|
- override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
|
|
- if (intent.action != ACTION_TRANSFER) {
|
|
|
+ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
|
|
+ if (intent == null || intent.action != ACTION_TRANSFER) {
|
|
|
return START_NOT_STICKY
|
|
|
}
|
|
|
|
|
|
- if (!isRunning && MainApp.getAppLifeCycle() == AppLifecycle.Foreground) {
|
|
|
+ if (!isRunning && lifecycle.currentState == Lifecycle.State.STARTED) {
|
|
|
ForegroundServiceHelper.startService(
|
|
|
this,
|
|
|
AppNotificationManager.TRANSFER_NOTIFICATION_ID,
|
|
@@ -121,8 +120,8 @@ class FileTransferService : Service() {
|
|
|
return START_NOT_STICKY
|
|
|
}
|
|
|
|
|
|
- override fun onBind(intent: Intent?): IBinder? {
|
|
|
- val user = intent?.getParcelableArgument(EXTRA_USER, User::class.java) ?: return null
|
|
|
+ override fun onBind(intent: Intent): IBinder? {
|
|
|
+ val user = intent.getParcelableArgument(EXTRA_USER, User::class.java) ?: return null
|
|
|
return Binder(getTransferManager(user), this)
|
|
|
}
|
|
|
|