0

Edit 2:

Issue:

Modification time of file as shown by stat in Linux for files copied from Android via usb is effected by changing of time zone setting on Android after file was created.

Reperformance:

  1. Boot Ubuntu 20.4 (or Linux Mint 21) from live USB.
  2. On Android (I had version 11, also observed the effect for 9) set datetime and time zone to manual, put in offline mode.
  3. Connect Android to Linux via usb.
  4. Pick a file on Android, copy via file manager to location_1 on Linux.
  5. Run stat on copied file (one in location_1).
  6. Disconnect usb (important).
  7. Change time zone on Android by several hours.
  8. Reconnect usb.
  9. Copy same file from Android to location_2.
  10. Run stat on copied file (one in location_2).
  11. Observe difference on line with Modify of several hours.

OP:

There was a question asked in 2013 How do I transfer files between Android and Linux over USB?. Updated answer dated 2018 states that mtp works:

it seems most Linux distros are now working with MTP fairly well. I know in my experience, Mint (Ubuntu based) works out of the box

Indeed I connect device via USB, click in Nemo (GUI) on an icon, storage mounts and I can transfer files in GUI.

However I just noted time zone matters. When I change time zone on a phone files modification times change. And copied to Linux, they remain with those times and Linux time zone (per stat), regardless of device's time zone, so files' "original" (phone's) time zone correction info is just lost. IMO not a desired effect, albeit rarely manifested as usually devices in close physical proximity have same time zone set.

Does that effect is due to how mtp works or it might depend on something else? Any advice how to copy with correct times w/out making sure both devices have same time zone set at the time of copying files? TIA

P.S. I think I want to report a bug, but not sure where: Mint, Ubuntu, Debian, kernel, else?

Added example:

A file on Android with time zone +1, Linux time zone +1

Android modification time as seen in both Android file manager and mtp mount in Linux Mint 21 based system in Nemo, say: 9:45:00.

After copy to ext4 fs stat shows for Modify:
9:45:00.000000000 +0100
Change time zone on Android to +3 (maybe unmount/replug usb/remount just in case), copy same file to other location on ext4, stat shows
11:45:00.000000000 +0100
Change time zone on Linux to +3. For second copy stat shows:
13:45:00.000000000 +0300

Note: when time zones are selected via GUI by city (I don't know other way in my Linux BTW) due to possibility of date savings results might differ even more or less by one hour.

8
  • Please edit your question and add specific examples, including the full date information from both devices. It is hard to see what you mean without examples.
    – terdon
    Sep 21, 2023 at 17:26
  • The metadata stored at the filesystem level has no concept of timezones and I don't see any indication that stat returns timezone information. You might compare ls -l .bash_profile with TZ=gmt ls -l .bash_profile. Check the same with stat instead of ls -l. Essentially, a file does not have a "original time zone".
    – doneal24
    Sep 21, 2023 at 19:04
  • @tendon, I've edited the title and added an example. Due to me doing such time experiments on another PC it's not copy-paste but I hope now effect is clear. Sep 22, 2023 at 1:16
  • @doneal24, on my Linux Mint 21 based system stat outputs time along with time zone, see added example. Now for some zone I even see time corrections differ for access and modify times (I guess due to one being during daytime savings other not). Sep 22, 2023 at 1:19
  • @doneal24, P.S. yes, AFAIK on ext fs datetime is stored as seconds since epoch. Sep 22, 2023 at 1:34

1 Answer 1

1

Original timestamp on Android: 9:45:00.000000000 +0100 = 8:45:00 UTC.

After changing the timezone of Android to +0300 and transferring the file to Linux:

11:45:00.000000000 +0100 = 10:45:00 UTC

The MTP protocol specification (page 22 of MTPforUSB-IFv1.1.pdf within the ZIP file) indicates the protocol handles timestamps as ISO 8601-compliant DateTime strings; however the indication of time zone is unfortunately optional.

The fact that the timestamp changed in transfer indicates the Android MTP implementation did not use the actual filesystem timestamp (which presumably is in UTC-equivalent form) but the localized timestamp presented in the Android UI.

I see three possible mechanisms for this error to happen:

  • Android could be erroneously converting the localized timestamp back to UTC for transfer using the current Android timezone, instead of transferring the raw filesystem timestamp which is already in UTC. In this case, Android MTP implementation will include the information that the timestamp is in UTC and Linux implementation is using it as such.
  • Android transferring the timestamp using the local time in Android's current timezone, but not specifying the timezone in the MTP DateTime string, causing Linux to assume the timestamp is in its own local timezone.
  • Android transferring the timestamp using the local time in Android's current timezone and specifying the timezone in the DateTime string, but the Linux MTP implementation not using the timezone information, assuming its own local timezone.

Dumping the USB traffic with e.g. Wireshark + Linux usbmon kernel module should allow a conclusive identification of the cause of error.

Second copy after changing the timezone on Linux too:

13:45:00.000000000 +0300 = 10:45:00 UTC = 11:45:00 +0100

The actual Linux-side timestamp (and so the error) is exactly the same as in the first copy, as both 13:45:00 +0300 and 11:45:00 +0100 refer to the same instant in time, i.e. 10:45:00 UTC. The same timestamp is just presented using a different local timezone.

If you look at the timestamp of the first transferred file on Linux, its modification time should also now say 13:45:00 +0300, as all timestamps formatted for local time will now be displayed using the +0300 timezone.

4
  • Thanks, second copy was added for completeness during back and forth in comments, it is as I expect to work. I have limited wireshark experience and do not understand how to apply "Linux usbmon kernel module". Could you please elaborate on how test could be made? In the meantime I'm going to try to understand myself. Sep 27, 2023 at 10:07
  • I changed time zones both on Android and Linux and modify timestanp of copied files became different by total delta - changes in both timezones effected the result. Per my understanding of your answer it rules out 1st option. Sep 27, 2023 at 14:53
  • If you first convert both the original's and the copy's timestamps to UTC and then compare them, was the difference in UTC 1x or 2x the magnitude of the timezone change?
    – telcoM
    Sep 27, 2023 at 18:34
  • Maybe I wrote imprecisely. "original's and the copy...1x or 2x the magnitude of the timezone change?" In comment above I've talked about two copies. I've made one, then changed time zones on both Android and Linux and recopied. Say were +7 / +1, became +6 / +2. Difference between 1st and 2nd copy (+7 - 1) - (+6 -2)= 2 hours. Sep 29, 2023 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .