bright-tools / androidphotobackup

Android application to perform over-the-air encrypted backups of photos to cloud services
Apache License 2.0
3 stars 1 forks source link

Photos re-uploaded after time-zone or DST change #11

Open bright-tools opened 9 years ago

bright-tools commented 9 years ago

It was observed that after change to DST, photos were being re-uploaded due to the fact that the timestamp appeared to have changed by 1 hour.

e.g. originally uploaded file:

20150314_155612.jpg.1426348572.zip

file re-uploaded after DST change:

20150314_155612.jpg.1426344972.zip

The photos in question were stored on an external SD card.

bright-tools commented 9 years ago

Investigation suggests that:

  1. The application currently uses MediaStore.Images.Media.DATE_MODIFIED to determine the timestamp at which an image was last modified
  2. This field is populated by the Android MediaScanner based on the information in the image's EXIF block
  3. The image in the EXIF block does not have a timezone associated with it
  4. The Android MediaScanner re-scans the external SD card when it is re-mounted

Due to this, it seems that each time the image is processed by the MediaScanner, the date information is extracted from the EXIF and converted to Epoch time based on the current timezone. If the timezone has changed since the image being taken (or has shifted due to DST), this means that the calculated Epoch time will be different (e.g. the Epoch time of 13:01:01 on Jan 1st 2015 will be calculated differently for a phone set to GMT as compared to a phone set to CET).

The solution would seem to be to use the file's timestamp rather than the data from the MediaStore/EXIF.

bright-tools commented 9 years ago

Unfortunately getting the time from the filestamp doesn't work in a reliable way in the case that the SDcard is FAT formatted. FAT timestamps are interpreted as being in 'local time' (unless various mount options are used to change that, such as tz or time_offset). This means that rebooting the unit after the timezone has changed will result in the timestamp of all files on the SDcard seeming to change, referenced to the new timezone.