Skip to content

Commit 50e398f

Browse files
committed
Reduce lint & fix condition for start service
Signed-off-by: alperozturk <[email protected]>
1 parent 08c2c3a commit 50e398f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

app/src/main/java/com/nextcloud/client/jobs/transfer/FileTransferService.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ class FileTransferService : LifecycleService() {
9595

9696
override fun onCreate() {
9797
AndroidInjection.inject(this)
98+
super.onCreate()
9899
}
99100

100101
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
102+
super.onStartCommand(intent, flags, startId)
101103
if (intent == null || intent.action != ACTION_TRANSFER) {
102104
return START_NOT_STICKY
103105
}
104106

105-
if (!isRunning && lifecycle.currentState == Lifecycle.State.STARTED) {
107+
if (!isRunning && lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
106108
ForegroundServiceHelper.startService(
107109
this,
108110
AppNotificationManager.TRANSFER_NOTIFICATION_ID,
@@ -112,15 +114,18 @@ class FileTransferService : LifecycleService() {
112114
}
113115

114116
val request: Request = intent.getParcelableArgument(EXTRA_REQUEST, Request::class.java)!!
115-
val transferManager = getTransferManager(request.user)
116-
transferManager.enqueue(request)
117+
118+
getTransferManager(request.user).run {
119+
enqueue(request)
120+
}
117121

118122
logger.d(TAG, "Enqueued new transfer: ${request.uuid} ${request.file.remotePath}")
119123

120124
return START_NOT_STICKY
121125
}
122126

123127
override fun onBind(intent: Intent): IBinder? {
128+
super.onBind(intent)
124129
val user = intent.getParcelableArgument(EXTRA_USER, User::class.java) ?: return null
125130
return Binder(getTransferManager(user), this)
126131
}
@@ -129,7 +134,7 @@ class FileTransferService : LifecycleService() {
129134
if (!isRunning) {
130135
logger.d(TAG, "All downloads completed")
131136
notificationsManager.cancelTransferNotification()
132-
stopForeground(true)
137+
stopForeground(STOP_FOREGROUND_DETACH)
133138
stopSelf()
134139
} else if (transfer.direction == Direction.DOWNLOAD) {
135140
notificationsManager.postDownloadTransferProgress(

0 commit comments

Comments
 (0)