From 837fa2c6b4e61653bd4d14a94af8c48d859a7944 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Wed, 3 May 2023 15:40:14 +0000 Subject: 1139: FIX crash in background --- .../data/repositories/TrackersRepository.kt | 12 ++++++++---- .../e/privacymodules/trackers/DNSBlockerService.kt | 12 ++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/TrackersRepository.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/TrackersRepository.kt index b5310e1..ae55371 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/TrackersRepository.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/TrackersRepository.kt @@ -18,12 +18,12 @@ package foundation.e.privacycentralapp.data.repositories import android.content.Context -import android.util.Log import com.google.gson.Gson import foundation.e.privacymodules.trackers.api.Tracker import retrofit2.Retrofit import retrofit2.converter.scalars.ScalarsConverterFactory import retrofit2.http.GET +import timber.log.Timber import java.io.File import java.io.FileInputStream import java.io.FileWriter @@ -45,8 +45,12 @@ class TrackersRepository(private val context: Context) { suspend fun update() { val api = ETrackersApi.build() - saveData(eTrackerFile, api.trackers()) - initTrackersFile() + try { + saveData(eTrackerFile, api.trackers()) + initTrackersFile() + } catch (e: Exception) { + Timber.e("While updating trackers", e) + } } private fun initTrackersFile() { @@ -64,7 +68,7 @@ class TrackersRepository(private val context: Context) { reader.close() inputStream.close() } catch (e: Exception) { - Log.e("TrackersRepository", "While parsing trackers in assets", e) + Timber.e("While parsing trackers in assets", e) } } diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt index 97a0fda..c2ad16b 100644 --- a/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt +++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/DNSBlockerService.kt @@ -40,15 +40,15 @@ class DNSBlockerService : Service() { throw UnsupportedOperationException("Not yet implemented") } - override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { - if (intent.getBooleanExtra(EXTRA_ENABLE_NOTIFICATION, true)) { - ForegroundStarter.startForeground(this) - } - if (ACTION_START == intent.action) { + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + if (ACTION_START == intent?.action) { + if (intent.getBooleanExtra(EXTRA_ENABLE_NOTIFICATION, true)) { + ForegroundStarter.startForeground(this) + } stop() start() } - return START_STICKY + return START_REDELIVER_INTENT } private fun start() { -- cgit v1.2.1