Skip to content

Upgrade uriToNetworkPacket to reliably get file lastModified information

Simon Redman requested to merge sredman/kdeconnect-android:lastmodified into master

Summary

Get last modified information for shared files

This turns out to be quite tricky because, depending on the source of the file, different columns might be defined. Without a better way to know the URI's source, I just check for the existence of the columns that I know about and read the one that I find.

See comments in FilesHelper.getLastModifiedTime for more information

This MR also includes some refactoring of uriToNetworkPacket based on me having dug ever deeper into the documentation for these APIs

This patch is the result of several iterations between @piyushaggarwal and myself. If it seems tricky and complicated, that's because it is!

Test Plan

(Desktop side has not yet been implemented, so we use breakpoints for verification)

  1. Put breakpoint on FilesHelper line 189
  2. Run app under debugger
  3. Share file:
  • For devices running Android >=4.4 (SAF):
    1. Configure storage locations for SAF
    2. Browse filesystem and select file
  • For devices running Android <4.4 (No SAF):
    1. Select file by using a file browser app
  • For any device:
    1. Select file using the Gallery app
    • This produces a different behavior. I see a content:// URI generated by the MediaStore, as opposed to a Document provider
  1. Verify that the value of lastModified at line 189 is not zero (for bonus points, check that the timestamp is correct)

I have tested this on Android 9.0 and 4.2.2 -- More testing is always appreciated!

Merge request reports

Loading