fix: don't restart alarm sound service automatically

This sets the alarm sound service to not be sticky. If AAPS is stopped while an alarm is playing, the alarm sound service will be started again by the system but there's no built-in way to stop it after this happens. This commit makes it so the alarm sound service won't be restarted by Android, thereby avoiding the aforementioned issue.
This commit is contained in:
p5nbTgip0r 2022-08-01 20:13:05 -07:00
parent dfbe0ba0e6
commit d7ad74056d
No known key found for this signature in database
GPG key ID: 1C70CA9CBFA72B68

View file

@ -74,7 +74,7 @@ class AlarmSoundService : DaggerService() {
if (intent?.hasExtra(ErrorHelperActivity.SOUND_ID) == true) resourceId = intent.getIntExtra(ErrorHelperActivity.SOUND_ID, R.raw.error) if (intent?.hasExtra(ErrorHelperActivity.SOUND_ID) == true) resourceId = intent.getIntExtra(ErrorHelperActivity.SOUND_ID, R.raw.error)
player = MediaPlayer() player = MediaPlayer()
try { try {
val afd = rh.openRawResourceFd(resourceId) ?: return START_STICKY val afd = rh.openRawResourceFd(resourceId) ?: return START_NOT_STICKY
player?.setDataSource(afd.fileDescriptor, afd.startOffset, afd.length) player?.setDataSource(afd.fileDescriptor, afd.startOffset, afd.length)
afd.close() afd.close()
player?.isLooping = true player?.isLooping = true
@ -94,7 +94,7 @@ class AlarmSoundService : DaggerService() {
aapsLogger.error("Unhandled exception", e) aapsLogger.error("Unhandled exception", e)
} }
aapsLogger.debug(LTag.CORE, "onStartCommand End") aapsLogger.debug(LTag.CORE, "onStartCommand End")
return START_STICKY return START_NOT_STICKY
} }
override fun onDestroy() { override fun onDestroy() {