This repository was archived by the owner on Dec 18, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +26
-8
lines changed
topl-service/src/main/java/io/matthewnelson/topl_service Expand file tree Collapse file tree 3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -491,26 +491,31 @@ class ServiceNotification internal constructor(
491491 private set
492492
493493 @Synchronized
494- internal fun startForeground (torService : BaseService ): ServiceNotification {
495- if (! inForeground) {
494+ internal fun startForeground (torService : BaseService ): Boolean {
495+ return if (! inForeground) {
496496 notificationBuilder?.let {
497497 torService.startForeground(notificationID, it.build())
498498 inForeground = true
499+ return true
499500 }
501+ false
502+ } else {
503+ false
500504 }
501- return serviceNotification
502505 }
503506
504507 @Synchronized
505- internal fun stopForeground (torService : BaseService ): ServiceNotification {
506- if (inForeground) {
508+ internal fun stopForeground (torService : BaseService ): Boolean {
509+ return if (inForeground) {
507510 torService.stopForeground(! showNotification)
508511 inForeground = false
509512 notificationBuilder?.let {
510513 notify(torService, it)
511514 }
515+ true
516+ } else {
517+ false
512518 }
513- return serviceNotification
514519 }
515520
516521
Original file line number Diff line number Diff line change @@ -315,10 +315,10 @@ internal abstract class BaseService: Service() {
315315 fun removeNotificationActions () {
316316 serviceNotification.removeActions(this )
317317 }
318- fun startForegroundService (): ServiceNotification {
318+ open fun startForegroundService (): Boolean {
319319 return serviceNotification.startForeground(this )
320320 }
321- fun stopForegroundService (): ServiceNotification {
321+ open fun stopForegroundService (): Boolean {
322322 return serviceNotification.stopForeground(this )
323323 }
324324 fun updateNotificationContentText (string : String ) {
Original file line number Diff line number Diff line change @@ -161,6 +161,19 @@ internal class TorService: BaseService() {
161161
162162 // See BaseService
163163
164+ override fun startForegroundService (): Boolean {
165+ val wasStarted = super .startForegroundService()
166+ if (wasStarted)
167+ broadcastLogger.debug(" Service sent to Foreground" )
168+ return wasStarted
169+ }
170+ override fun stopForegroundService (): Boolean {
171+ val wasStopped = super .stopForegroundService()
172+ if (wasStopped)
173+ broadcastLogger.debug(" Service sent to Background" )
174+ return wasStopped
175+ }
176+
164177
165178 // ///////////////
166179 // / TOPL-Core ///
You can’t perform that action at this time.
0 commit comments