mendhak/gpslogger

Auto upload works only every 5 minutes when screen is turned off

Closed this issue · 2 comments

When the screen is turned on, the location is updated and automatic upload happens every minute as defined in settings. When the screen is turned off, a new location is added to the csv file every minute, but the SFTP upload happens only every 5 minutes. This behavior started after the phone was updated from an older MIUI 13 version to 13.0.6.0.

The debuglog.txt contains this every five minutes when the screen is off (except private data is removed):

13:00:29 INFO  GpsLoggingService.handleIntent:202 - Intent received - Get Next Point
13:00:29 INFO  GpsLoggingService.startGpsManager:621 - Requesting GPS location updates
13:00:29 INFO  GpsLoggingService.startGpsManager:643 - Requesting cell and wifi location updates
13:00:29 INFO  GeneralLocationListener.onGpsStatusChanged:141 - GPS elindult, várjon a pontos pozícióra
13:00:31 DEBUG GeneralLocationListener.onGpsStatusChanged:136 - 0 satellites
13:00:32 DEBUG GeneralLocationListener.onGpsStatusChanged:136 - 31 satellites
13:00:32 DEBUG GpsLoggingService.onLocationChanged:817 - Has description? false, Single point? false, Last timestamp: 1660388368134, Current timestamp: 1660388432133
13:00:32 DEBUG GpsLoggingService.onLocationChanged:902 - ***
13:00:32 INFO  GpsLoggingService.onLocationChanged:903 - ***
Magasság:*** méter
Pontosság:12,861 méter
13:00:32 INFO  GpsLoggingService.resetCurrentFileName:779 - Filename: 20220813
13:00:32 DEBUG GpsLoggingService.writeToFile:1028 - Calling file writers
13:00:32 DEBUG Gpx10WriteHandler.run:238 - Finished writing to GPX10 file
13:00:32 DEBUG GpsLoggingService.stopGpsManager:714 - Removing towerLocationManager updates
13:00:32 DEBUG GpsLoggingService.stopGpsManager:719 - Removing gpsLocationManager updates
13:00:32 DEBUG GpsLoggingService.setAlarmForNextPoint:1001 - Set alarm for 60 seconds
13:00:51 DEBUG AlarmReceiver.onReceive:42 - Alarm received
13:00:51 DEBUG GpsLoggingService.autoSendLogFile:365 - Filename: null
13:00:51 INFO  FileSenderFactory.autoSendFiles:86 - Auto-sending file 20220813
13:00:51 DEBUG FileSenderFactory.autoSendFiles:130 - Sender: com.mendhak.gpslogger.senders.sftp.SFTPManager
13:00:51 DEBUG GpsLoggingService.setupAutoSendTimers:304 - Setting up autosend timers. Auto Send Enabled - true, Auto Send Delay - 1.0
13:00:51 DEBUG GpsLoggingService.setupAutoSendTimers:321 - Autosend alarm has been set
13:00:51 DEBUG SFTPJob.onAdded:59 - SFTP Job added
13:00:51 DEBUG SFTPJob.onRun:64 - SFTP Job onRun
13:00:51 DEBUG SFTPJob.onAdded:59 - SFTP Job added
13:00:51 DEBUG SFTPJob.onRun:89 - Connecting...
13:00:51 DEBUG SFTPJob$SftpLogger.log:171 - Connecting to ***
13:00:51 DEBUG SFTPJob$SftpLogger.log:171 - Connection established
... some other sftp related logs
13:00:53 DEBUG SFTPJob.onRun:100 - Uploading 20220813.csv to remote server
13:00:53 DEBUG SFTPJob.onRun:103 - Disconnecting
13:00:53 DEBUG SFTPJob$SftpLogger.log:171 - Disconnecting from ***
13:00:53 INFO  SFTPJob.onRun:108 - SFTP - file uploaded
13:00:53 DEBUG SFTPJob$SftpLogger.log:171 - Caught an exception, leaving main loop due to Socket closed
13:00:53 DEBUG GpsMainActivity.onEventMainThread:1638 - SFTP Event completed, success: true
13:00:53 DEBUG SFTPJob.onRun:64 - SFTP Job onRun
13:00:53 DEBUG SFTPJob.onRun:89 - Connecting...
13:00:53 DEBUG SFTPJob$SftpLogger.log:171 - Connecting to ***
13:00:53 DEBUG SFTPJob$SftpLogger.log:171 - Connection established
... some other sftp related logs
13:00:53 DEBUG SFTPJob.onRun:100 - Uploading 20220813.gpx to remote server
13:00:53 DEBUG SFTPJob.onRun:103 - Disconnecting
13:00:53 DEBUG SFTPJob$SftpLogger.log:171 - Disconnecting from ***
13:00:53 INFO  SFTPJob.onRun:108 - SFTP - file uploaded
13:00:53 DEBUG SFTPJob$SftpLogger.log:171 - Caught an exception, leaving main loop due to Socket closed
13:00:53 DEBUG GpsMainActivity.onEventMainThread:1638 - SFTP Event completed, success: true

and this for every minute which is not a multiple of 5:

13:01:32 INFO  GpsLoggingService.handleIntent:202 - Intent received - Get Next Point
13:01:32 INFO  GpsLoggingService.startGpsManager:621 - Requesting GPS location updates
13:01:32 INFO  GpsLoggingService.startGpsManager:643 - Requesting cell and wifi location updates
13:01:32 INFO  GeneralLocationListener.onGpsStatusChanged:141 - GPS elindult, várjon a pontos pozícióra
13:01:34 DEBUG GeneralLocationListener.onGpsStatusChanged:136 - 0 satellites
13:01:34 DEBUG GpsLoggingService.onLocationChanged:817 - Has description? false, Single point? false, Last timestamp: 1660388432139, Current timestamp: 1660388494599
13:01:34 DEBUG GpsLoggingService.onLocationChanged:902 - ***
13:01:34 INFO  GpsLoggingService.onLocationChanged:903 - ***
Magasság:*** méter
Pontosság:12,904 méter
13:01:34 INFO  GpsLoggingService.resetCurrentFileName:779 - Filename: 20220813
13:01:34 DEBUG GpsLoggingService.writeToFile:1028 - Calling file writers
13:01:34 DEBUG Gpx10WriteHandler.run:238 - Finished writing to GPX10 file
13:01:34 DEBUG GpsLoggingService.stopGpsManager:714 - Removing towerLocationManager updates
13:01:34 DEBUG GpsLoggingService.stopGpsManager:719 - Removing gpsLocationManager updates
13:01:34 DEBUG GpsLoggingService.setAlarmForNextPoint:1001 - Set alarm for 60 seconds

When I noticed the problem I was using GPSLogger version 121. With that version the location update was also happened only every 5 minutes, which was visible from the location csv file. After updating to version 122, the location is correctly logged every minute, and only the upload interval issue remained. I assume the log interval was fixed with ee96c9b or e952181. Could be that the upload has a similar issue related to the condition with Systems.isDozing in GpsLoggingService.setupAutoSendTimers.

  • Settings

    • Android
      • For the app the battery optimization is disabled, auto start enabled.
      • Global battery saver is in Performance mode.
    • GPSLogger
      • Logging details
        • GPX and CSV logging enabled
      • Performance
        • Logging interval: 60s
        • Distance filter: 0 m
        • Accuracy filter 40 m
        • Duration to match accuracy: 60s
        • Absolute time to GPS fix: 120s
      • Upload settings
        • How often? 1 min
        • SFTP enabled
  • Version info:

    • MIUI: 13.0.6.0(SKIEUXM)
    • Android: 12 SKQ1.211006.001
    • GPSLogger: 122 (installed from F-Droid)

Related to #966 and #969.

I tried out with changing the condition in GpsLoggingService.setupAutoSendTimers
from:

if(Systems.isDozing(this)) {
    am.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, sender);
} else {
    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, sender);
}

to:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    am.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, sender);
} else {
    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, sender);
}

This way the auto sending worked every minute as defined in the auto send interval setting. However I can't decide if changing to exact alarm is okay in this case. It would drain more battery, on the other hand the user should be aware of that when setting a small value for auto send interval.
@mendhak What is your opinion, should I create a pull request for this change?

As another solution for this issue I switched from sftp upload to logging to custom url. I saw the logging already uses exact alarm. This runs as frequently as defined in the log interval setting even when the screen if off for longer time.

@andras3189 Nice find, yes that would be cool if your PR is a simple change like you've shown. I think this original code must have been some original guidelines from the Google Play days, where I was used to get the app banned for not following specific doze related guidelines.

But just to be sure I'll do some testing, just want to make sure everything still runs as expected.

Yes I agree, if a user has set 1 minute uploads... then they should expect a faster battery drain.