Skip to content

Commit

Permalink
fix: Only inject assist data once per logging session
Browse files Browse the repository at this point in the history
Fixes #648
  • Loading branch information
barbeau committed Aug 11, 2023
1 parent 9afca7a commit fd26076
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ import com.android.gpstest.library.util.FormatUtils.toNotificationTitle
import com.android.gpstest.library.util.IOUtils.*
import com.android.gpstest.library.util.LibUIUtils.toNotificationSummary
import com.android.gpstest.library.util.PreferenceUtil
import com.android.gpstest.library.util.PreferenceUtil.injectPsdsWhenLogging
import com.android.gpstest.library.util.PreferenceUtil.injectTimeWhenLogging
import com.android.gpstest.library.util.PreferenceUtil.isCsvLoggingEnabled
import com.android.gpstest.library.util.PreferenceUtil.isJsonLoggingEnabled
import com.android.gpstest.library.util.PreferenceUtil.writeAntennaInfoToFileCsv
Expand Down Expand Up @@ -128,6 +126,7 @@ class ForegroundOnlyLocationService : LifecycleService() {
private val loggingSettingListener: SharedPreferences.OnSharedPreferenceChangeListener =
PreferenceUtil.newFileLoggingListener(app, { initLogging() }, prefs)
private var deletedFiles = false
private var injectedAssistData = false

override fun onCreate() {
super.onCreate()
Expand Down Expand Up @@ -593,16 +592,10 @@ class ForegroundOnlyLocationService : LifecycleService() {
* file permissions. So we need to call this on each update in case the user just granted file
* permissions but logging hasn't been started yet.
*/
@Synchronized
private fun initLogging() {
val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager

// Inject time and/or PSDS to make sure timestamps and assistance are as updated as possible
if (injectTimeWhenLogging(app, prefs)) {
forceTimeInjection(app, locationManager)
}
if (injectPsdsWhenLogging(app, prefs)) {
forcePsdsInjection(app, locationManager)
}
maybeInjectAssistData()

val date = Date()
if (!csvFileLogger.isStarted && isCsvLoggingEnabled(app, prefs)) {
Expand All @@ -616,6 +609,21 @@ class ForegroundOnlyLocationService : LifecycleService() {
maybeDeleteFiles()
}

private fun maybeInjectAssistData() {
if (injectedAssistData) {
// Only inject once per logging session
return
}
val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
if (PreferenceUtil.injectTimeWhenLogging(app, prefs)) {
forceTimeInjection(app, locationManager)
}
if (PreferenceUtil.injectPsdsWhenLogging(app, prefs)) {
forcePsdsInjection(app, locationManager)
}
injectedAssistData = true
}

private fun maybeDeleteFiles() {
if (deletedFiles) {
// If we've already deleted files on this application execution, don't do it again
Expand Down

0 comments on commit fd26076

Please sign in to comment.