<commit_before>package de.troido.bleacon.service

import android.app.AlarmManager
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import android.os.SystemClock
import de.troido.bleacon.scanner.BleaconScanner

private const val RESTART_DELAY: Long = 100

abstract class BleaconService : Service() {
    class BleaconBinder(val service: BleaconService) : Binder()

    protected abstract val scanner: BleaconScanner

    override fun onBind(intent: Intent?): IBinder = BleaconBinder(this)

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
            START_STICKY

    override fun onCreate() {
        super.onCreate()
        scanner.start()
    }

    override fun onTaskRemoved(rootIntent: Intent?) {
        super.onTaskRemoved(rootIntent)
        scanner.stop()
        (applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager).set(
                AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + RESTART_DELAY,
                PendingIntent.getService(
                        applicationContext,
                        1,
                        Intent(applicationContext, javaClass),
                        PendingIntent.FLAG_ONE_SHOT
                )
        )
    }
}<commit_msg>Adds an onDestroy to BleaconService which stops the scanner.<commit_after>package de.troido.bleacon.service

import android.app.AlarmManager
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import android.os.SystemClock
import de.troido.bleacon.scanner.BleaconScanner

private const val RESTART_DELAY: Long = 100

abstract class BleaconService : Service() {
    class BleaconBinder(val service: BleaconService) : Binder()

    protected abstract val scanner: BleaconScanner

    override fun onBind(intent: Intent?): IBinder = BleaconBinder(this)

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
            START_STICKY

    override fun onCreate() {
        super.onCreate()
        scanner.start()
    }

    override fun onTaskRemoved(rootIntent: Intent?) {
        super.onTaskRemoved(rootIntent)
        scanner.stop()
        (applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager).set(
                AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + RESTART_DELAY,
                PendingIntent.getService(
                        applicationContext,
                        1,
                        Intent(applicationContext, javaClass),
                        PendingIntent.FLAG_ONE_SHOT
                )
        )
    }

    override fun onDestroy() {
        scanner.stop()
        super.onDestroy()
    }
}
{'fraction_non_alphanumeric': 0.07610921501706484, 'fraction_numerical': 0.0027303754266211604, 'mean_word_length': 2.5919117647058822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1216577', 'n_tokens_mistral': 835, 'n_tokens_neox': 784, 'n_words': 171}