bailuk / AAT

Another Activity Tracker for Android
https://bailu.ch/aat
GNU General Public License v3.0
156 stars 41 forks source link

Overpass query failes writing to a public directory #167

Open sebicodes opened 2 weeks ago

sebicodes commented 2 weeks ago

Hello,

concerning v1.26 (40) from f-droid, on an android 13 phone; overpass-queries:

I encounter problems if I change the folder for the internal data to the former ~/aat_data folder:

If I use the restricted /data/data/ch.bailu.aat/files everything works fine - but I don't have access to the files for further use.

If I change the folder for internal files to primary:aat_data (via "Auswählen (SAF)..." and giving read and write access) the the overpass-query fails: I get the red status message #

GET '....': failed°

Interestingly the nominatim query works with both settings, also the saving of tiles and gpx tracks works properly.

Contents of aat_data/query/nominatim with just one xml-file. -rw-r--r-- 1 owner group 9 Sep 03 10:28 edit.txt -rw-r--r-- 1 owner group 1257 Sep 03 10:28 nominatim.xml -rw-r--r-- 1 owner group 9 Sep 03 10:28 query.txt

Contents of aat_data/query/overpass with newly created xml-files every try: -rw-r--r-- 1 owner group 19 Sep 03 10:30 edit.txt -rw-r--r-- 1 owner group 0 Aug 24 14:28 overpass.osm (1).xml -rw-r--r-- 1 owner group 0 Aug 24 14:28 overpass.osm (2).xml -rw-r--r-- 1 owner group 0 Aug 24 14:29 overpass.osm (3).xml -rw-r--r-- 1 owner group 0 Aug 30 10:56 overpass.osm (4).xml -rw-r--r-- 1 owner group 0 Sep 03 10:23 overpass.osm (5).xml -rw-r--r-- 1 owner group 0 Sep 03 10:28 overpass.osm (6).xml -rw-r--r-- 1 owner group 0 Aug 24 14:18 overpass.osm.xml -rw-r--r-- 1 owner group 19 Sep 03 10:28 query.txt (same behaviour if I delete all xml files: After that I have the same reaction with the empty overpass.osm.xml-file)

It looks to me very strongly like an issue in access rights or path names at some point.

Maybe it has something to do with issue #164, especially the problem described by @Xanatos00 in https://github.com/bailuk/AAT/issues/164#issuecomment-2227355255

For some reason, one month ago, AAT was not able to write in my original folder (/emulated/0/t_data/), the only folder working was /data/data/ch.bailu.aat

bailuk commented 1 week ago
    private boolean createDocumentNoException(String mimeType) {
        try {
            return DocumentsContract.createDocument(
                    resolver,
                    uris.getParent(),
                    mimeType,
                    getName()) != null;
        } catch (Exception e) {
            return false;
        }
    }

Document is primary:aat_data/query/overpass/overpass.osm and mimeType is application/xml

    public static String fromName(String name) {
        String suffix = getSuffix(name);

        if ("gpx".equals(suffix)) {
            return "application/gpx+xml";

        } else if ("osm".equals(suffix) || "xml".equals(suffix)) {
            return "application/xml";

        } else if ("png".equals(suffix)) {
            return "image/png";

        } else if ("zip".equals(suffix)) {
            return "application/zip";
        }
        return "text/plain";
    }

So then Android changes the file name to overpass.osm.xml and to make things even worse it also "invents" overpass.osm(1).xml and so on. The error itself comes from overpass.osm not existing.

https://developer.android.com/reference/android/provider/DocumentsContract#createDocument(android.content.ContentResolver,%20android.net.Uri,%20java.lang.String,%20java.lang.String)

I think one workaround is to save overpass results as overpass.xml and hope it works for the next two Android releases.