AlarmSoundService logging
This commit is contained in:
parent
561ba72bf0
commit
7c109d78e0
1 changed files with 11 additions and 6 deletions
|
@ -18,6 +18,7 @@ import kotlin.math.ln
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
|
||||||
class AlarmSoundService : DaggerService() {
|
class AlarmSoundService : DaggerService() {
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var notificationHolder: NotificationHolderInterface
|
@Inject lateinit var notificationHolder: NotificationHolderInterface
|
||||||
|
@ -27,6 +28,7 @@ class AlarmSoundService : DaggerService() {
|
||||||
private var resourceId = R.raw.error
|
private var resourceId = R.raw.error
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val VOLUME_INCREASE_STEPS = 40 // Total number of steps to increase volume with
|
private const val VOLUME_INCREASE_STEPS = 40 // Total number of steps to increase volume with
|
||||||
private const val VOLUME_INCREASE_INITIAL_SILENT_TIME_MILLIS = 3_000L // Number of milliseconds that the notification should initially be silent
|
private const val VOLUME_INCREASE_INITIAL_SILENT_TIME_MILLIS = 3_000L // Number of milliseconds that the notification should initially be silent
|
||||||
private const val VOLUME_INCREASE_BASE_DELAY_MILLIS = 15_000 // Base delay between volume increments
|
private const val VOLUME_INCREASE_BASE_DELAY_MILLIS = 15_000 // Base delay between volume increments
|
||||||
|
@ -47,17 +49,20 @@ class AlarmSoundService : DaggerService() {
|
||||||
override fun onBind(intent: Intent): IBinder? = null
|
override fun onBind(intent: Intent): IBinder? = null
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
|
||||||
aapsLogger.debug(LTag.CORE, "onCreate")
|
aapsLogger.debug(LTag.CORE, "onCreate")
|
||||||
|
super.onCreate()
|
||||||
|
aapsLogger.debug(LTag.CORE, "onCreate parent called")
|
||||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||||
|
aapsLogger.debug(LTag.CORE, "onCreate End")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
aapsLogger.debug(LTag.CORE, "onStartCommand")
|
||||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||||
|
aapsLogger.debug(LTag.CORE, "onStartCommand Foreground called")
|
||||||
|
|
||||||
player?.let { if (it.isPlaying) it.stop() }
|
player?.let { if (it.isPlaying) it.stop() }
|
||||||
|
|
||||||
aapsLogger.debug(LTag.CORE, "onStartCommand")
|
|
||||||
if (intent?.hasExtra("soundid") == true) resourceId = intent.getIntExtra("soundid", R.raw.error)
|
if (intent?.hasExtra("soundid") == true) resourceId = intent.getIntExtra("soundid", R.raw.error)
|
||||||
player = MediaPlayer()
|
player = MediaPlayer()
|
||||||
try {
|
try {
|
||||||
|
@ -80,19 +85,19 @@ class AlarmSoundService : DaggerService() {
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
aapsLogger.error("Unhandled exception", e)
|
aapsLogger.error("Unhandled exception", e)
|
||||||
}
|
}
|
||||||
|
aapsLogger.debug(LTag.CORE, "onStartCommand End")
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
aapsLogger.debug(LTag.CORE, "onDestroy")
|
||||||
increaseVolumeHandler.removeCallbacks(volumeUpdater)
|
increaseVolumeHandler.removeCallbacks(volumeUpdater)
|
||||||
player?.stop()
|
player?.stop()
|
||||||
player?.release()
|
player?.release()
|
||||||
aapsLogger.debug(LTag.CORE, "onDestroy")
|
aapsLogger.debug(LTag.CORE, "onDestroy End")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAudioManager(): AudioManager {
|
private fun getAudioManager() = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
return getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO replace with VolumeShaper when min API level >= 26
|
// TODO replace with VolumeShaper when min API level >= 26
|
||||||
private val volumeUpdater = object : Runnable {
|
private val volumeUpdater = object : Runnable {
|
||||||
|
|
Loading…
Reference in a new issue