@@ -368,7 +368,7 @@ class KeepAwakeService : Service(), SharedPrefsObserver, ServiceStatusObserver {
368368 override fun onTaskRemoved (rootIntent : Intent ? ) {
369369 super .onTaskRemoved(rootIntent)
370370
371- Log .d(" ${this :: class .simpleName} service removed from task manager! restarting..." )
371+ Log .d(" ${javaClass .simpleName} service removed from task manager! restarting..." )
372372
373373 Intent (this , KeepAwakeService ::class .java).apply {
374374 action = ACTION_RESTART .name
@@ -470,15 +470,16 @@ class KeepAwakeService : Service(), SharedPrefsObserver, ServiceStatusObserver {
470470 * @see [acquireWakeLock]
471471 */
472472 private fun prepareService (startAfter : Duration ? = null) = caffeinateApplication.run {
473- Log .d(" starting ${this @KeepAwakeService::class .simpleName} service..." )
473+ Log .d(" starting ${localizedApplicationContext.getString(R .string.app_name)} with duration: ${timeout.toFormattedTime()} }" )
474+
474475 val status = when (val status = lastStatusUpdate) {
475476 is ServiceStatus .Running -> status.apply { remaining = timeout }
476477 is ServiceStatus .Stopped -> ServiceStatus .Running (timeout)
477478 }
478479
479480 lastStatusUpdate = status
480481
481- Log .d(" status: $ status, selectedDuration : ${ status.remaining.toFormattedTime()} " )
482+ Log .d(" starting status: $status " )
482483
483484 Log .d(" sending foreground notification..." )
484485 startForeground(NOTIFICATION_ID , buildForegroundNotification(status))
@@ -492,7 +493,7 @@ class KeepAwakeService : Service(), SharedPrefsObserver, ServiceStatusObserver {
492493
493494 startCaffeine(status.remaining, startAfter)
494495
495- Log .d(" ${this @KeepAwakeService:: class .simpleName} service started!" )
496+ Log .d(" ${localizedApplicationContext.getString( R .string.app_name)} started!" )
496497 }
497498
498499 /* *
@@ -604,9 +605,9 @@ class KeepAwakeService : Service(), SharedPrefsObserver, ServiceStatusObserver {
604605 val powerManager = getSystemService(Context .POWER_SERVICE ) as PowerManager
605606
606607 wakeLock?.apply {
607- Log .d(" releasing ${this @KeepAwakeService ::wakeLock.name} ..." )
608+ Log .d(" releasing ${::wakeLock.name} ..." )
608609 releaseSafely(::wakeLock.name)
609- Log .d(" ${this @KeepAwakeService ::wakeLock.name} released!" )
610+ Log .d(" ${::wakeLock.name} released!" )
610611 } ? : Log .d(" wakeLock is not held!" )
611612 @Suppress(" DEPRECATION" )
612613 val wakeLockLevel = when {
@@ -625,12 +626,12 @@ class KeepAwakeService : Service(), SharedPrefsObserver, ServiceStatusObserver {
625626 wakeLockLevel,
626627 " ${caffeinateApplication.localizedApplicationContext.getString(R .string.app_name)} :wakeLockTag"
627628 ).apply {
628- Log .d(" acquiring ${this @KeepAwakeService ::wakeLock.name} , isDimmingEnabled: $isDimmingEnabled ..." )
629+ Log .d(" acquiring ${::wakeLock.name} , isDimmingEnabled: $isDimmingEnabled ..." )
629630 when {
630631 duration.isInfinite() -> acquire()
631632 else -> acquire(duration.inWholeMilliseconds)
632633 }
633- Log .d(" ${this @KeepAwakeService ::wakeLock.name} acquired, isDimmingEnabled: $isDimmingEnabled !" )
634+ Log .d(" ${::wakeLock.name} acquired, isDimmingEnabled: $isDimmingEnabled !" )
634635 }
635636 }
636637
@@ -646,25 +647,25 @@ class KeepAwakeService : Service(), SharedPrefsObserver, ServiceStatusObserver {
646647 * @param startAfter [Duration] the duration to delay before starting the service
647648 */
648649 private fun startCaffeine (duration : Duration , startAfter : Duration ? = null) = caffeinateApplication.run {
649- Log .d(" starting ${localizedApplicationContext.getString( R .string.app_name)} with duration: ${duration.toFormattedTime()} , isIndefinite: ${duration.isInfinite()} " )
650+ Log .d(" starting ${this @KeepAwakeService:: class .simpleName} service... " )
650651
651652 acquireWakeLock(duration)
652653
653654 if (isOverlayEnabled) overlayHandler.showOverlay()
654655
655- caffeineTimeoutJob. apply {
656- Log .d(" stopping ${this @KeepAwakeService ::caffeineTimeoutJob.name} ..." )
656+ with ( caffeineTimeoutJob) {
657+ Log .d(" stopping ${::caffeineTimeoutJob.name} ..." )
657658 stop()
658- Log .d(" ${this @KeepAwakeService::caffeineTimeoutJob.name} stopped!" )
659- }
660-
661- Log .d(" starting ${this @KeepAwakeService::caffeineTimeoutJob.name} ..." )
662- caffeineTimeoutJob.start(duration, startAfter)
663- Log .d(" ${this @KeepAwakeService::caffeineTimeoutJob.name} started!" )
659+ Log .d(" ${::caffeineTimeoutJob.name} stopped!" )
664660
665- Log .d(" ${localizedApplicationContext.getString(R .string.app_name)} started!" )
661+ Log .d(" starting ${::caffeineTimeoutJob.name} ..." )
662+ start(duration, startAfter)
663+ Log .d(" ${::caffeineTimeoutJob.name} started!" )
664+ }
666665
667666 sharedPreferences.isServiceRunning = true
667+
668+ Log .d(" ${this @KeepAwakeService::class .simpleName} service started!" )
668669 }
669670
670671 /* *
@@ -679,21 +680,22 @@ class KeepAwakeService : Service(), SharedPrefsObserver, ServiceStatusObserver {
679680 */
680681 private fun stopCaffeine () = caffeinateApplication.run {
681682 Log .d(" stopping ${localizedApplicationContext.getString(R .string.app_name)} ..." )
683+ Log .d(" stopping ${this @KeepAwakeService::class .simpleName} service..." )
682684
683685 wakeLock?.apply {
684- Log .d(" releasing ${this @KeepAwakeService ::wakeLock.name} ..." )
686+ Log .d(" releasing ${::wakeLock.name} ..." )
685687 releaseSafely(::wakeLock.name)
686- Log .d(" ${this @KeepAwakeService ::wakeLock.name} released!" )
688+ Log .d(" ${::wakeLock.name} released!" )
687689 } ? : Log .d(" wakeLock is not held!" )
688690
689691 caffeineTimeoutJob.apply {
690- Log .d(" stopping ${this @KeepAwakeService ::caffeineTimeoutJob.name} ..." )
692+ Log .d(" stopping ${::caffeineTimeoutJob.name} ..." )
691693 stop()
692- Log .d(" ${this @KeepAwakeService ::caffeineTimeoutJob.name} stopped!" )
694+ Log .d(" ${::caffeineTimeoutJob.name} stopped!" )
693695
694- Log .d(" cancelling ${this @KeepAwakeService ::caffeineTimeoutJob.name} ..." )
696+ Log .d(" cancelling ${::caffeineTimeoutJob.name} ..." )
695697 cancel()
696- Log .d(" ${this @KeepAwakeService ::caffeineTimeoutJob.name} cancelled!" )
698+ Log .d(" ${::caffeineTimeoutJob.name} cancelled!" )
697699 }
698700
699701 localeChangeReceiver.isRegistered = false
@@ -706,13 +708,14 @@ class KeepAwakeService : Service(), SharedPrefsObserver, ServiceStatusObserver {
706708
707709 notificationManager.cancel(NOTIFICATION_ID )
708710
709- Log .d(" ${localizedApplicationContext.getString(R .string.app_name)} stopped!" )
710-
711711 if (isOverlayEnabled) overlayHandler.hideOverlay()
712712
713713 sharedPreferences.isServiceRunning = false
714714
715715 stopSelf()
716+
717+ Log .d(" ${this @KeepAwakeService::class .simpleName} service stopped!" )
718+ Log .d(" ${localizedApplicationContext.getString(R .string.app_name)} stopped!" )
716719 }
717720
718721 /* *
0 commit comments