Update to Android 10 - No writing on external SD

Support for Android version of Total Commander

Moderators: white, Hacker, petermad, Stefan2

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Update to Android 10 - No writing on external SD

Post by *ghisler(Author) »

To me it sounds like the usual power saving troubles: All apps need the Android "Files" app to access the external SD card. I guess that when this app is put in sleep, the writing will fail.

So maybe it would help to exclude the Files app from power saving functions?

The mentioned bugfix in the above the linked German thread isn't related to this bug.
Author of Total Commander
https://www.ghisler.com
gemeenteraadslid
Junior Member
Junior Member
Posts: 58
Joined: 2011-11-28, 11:27 UTC

Re: Update to Android 10 - No writing on external SD

Post by *gemeenteraadslid »

Awesome idea, this would explain why write access works sporadically. A first test after excluding "Dateien" app from power saving: yes, now it works! Time wil tell. I really hope this solves it.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Update to Android 10 - No writing on external SD

Post by *ghisler(Author) »

Please keep me updated whether this helps permanently or not.
Author of Total Commander
https://www.ghisler.com
gemeenteraadslid
Junior Member
Junior Member
Posts: 58
Joined: 2011-11-28, 11:27 UTC

Re: Update to Android 10 - No writing on external SD

Post by *gemeenteraadslid »

Unfortunately not, I was ready to declare you as a hero of the Huawei community ;-) I'm quite disappointed. It didn't survive a restart of the device. The internal file manager app "Dateien" is still set to not optimized, but the problem is back.

What I can tell is:

a) Both 3rd party file managers (TC and Ghost Commander) show the same behaviour. Both worked yesterday, both do not work today.

b) GC does the same (create a 0 byte file), but has an error message saying "... Requested path /mnt/media_rw/4A21-0000/testfile.ext doesn't appear under [/system/media, /hw_product/hw_oem/EVR-L29/media, /system/product/media]"

In GC, the drive is called saf:/storage/4A21-000/

There must be some interface or driver not working on OS side, some API thing... idk
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Update to Android 10 - No writing on external SD

Post by *ghisler(Author) »

Could you try accessing the drive via its virtual folder instead of via its directory?

To do this, use "Add custom location" and go to the root if the drive, then press the button at the bottom. It should add a new entry in the home folder like
///_SD-Card
Author of Total Commander
https://www.ghisler.com
gemeenteraadslid
Junior Member
Junior Member
Posts: 58
Joined: 2011-11-28, 11:27 UTC

Re: Update to Android 10 - No writing on external SD

Post by *gemeenteraadslid »

Problem is also there :( , you can see it in my video. Even if I newly add a virtual folder via "+" and allow access to the drive.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Update to Android 10 - No writing on external SD

Post by *ghisler(Author) »

I have borrowed the Huawei P30 of my brother (because myHuawei tablet only has Android 9) and was immediately able to reproduce the problem:
It's not caused by power saving functions. Instead it's a bug in Huawei's implementation of the Storage Access Framework. Fortunately there is a way to work around the bug. Please try beta 16 (released today).

The details are as follows:
- Apps use the function DocumentsContract.createDocument() to create a new file. This command should normally return a content: URL pointing to the newly created file.
- On Huawei devices with Android 10, DocumentsContract.createDocument successfully creates the file, but then causes an exception with the following error description:
Requested path /mnt/media_rw/4A21-0000/Download/file.txt doesn't appear under [/system/media, /hw_product/hw_oem/ELE-L29/media, /system/product/media]
- apparently Huawei hardcoded some paths where the user should be allowed to create files, but made a mistake.

Solution: When the function DocumentsContract.createDocument fails with an exception, try getting the file Uri manually via a simple resolver.query call, see function GetDirectoryListItem below (dataUri=Uri of the folder where the file was created, filename=name of file):

Code: Select all

			...
			try {
				fileUri=DocumentsContract.createDocument(resolver, dataUri, mimeType, filename);
			} catch (Throwable e2) {
				fileUri=GetDirectoryListItem(TcApplication.getApp(), resolver, dataUri, filename);
			}
			if (fileUri != null) {
				OutputStream os = null;
				try {
					os=resolver.openOutputStream(fileUri, "w");  // or use ParcelFileDescriptor.open(fileUri, "w");
					return os;
				} catch (Throwable e) {
				}
			}

	public static Uri GetDirectoryListItem(Context context, ContentResolver resolver, Uri dataUri, String filename) {
		try {
			Cursor cursor = null;
			String subfolder = DocumentsContract.getTreeDocumentId(dataUri);
			Uri testUri = DocumentsContract.buildChildDocumentsUriUsingTree(dataUri, subfolder);
			String[] selectionArgs = new String[1];
			selectionArgs[0] = filename;
			cursor = resolver.query(testUri, new String[]{
							DocumentsContract.Document.COLUMN_DOCUMENT_ID,
							DocumentsContract.Document.COLUMN_DISPLAY_NAME},
					DocumentsContract.Document.COLUMN_DISPLAY_NAME + " = '?'", selectionArgs, null);
			Vector<PluginItem> list = new Vector<PluginItem>(cursor.getCount());
			if (cursor.moveToFirst()) {
				do {
					String name = cursor.getString(1);
					if (name.equals(filename)) {
						Uri ret=DocumentsContract.buildDocumentUriUsingTree(dataUri, cursor.getString(0));
						cursor.close();
						return ret;
					}
				} while (cursor.moveToNext());
				cursor.close();
			}
		} catch (Throwable e) {
			Utilities.shortToast(context, e.getMessage());
		}
		return null;
	}
Author of Total Commander
https://www.ghisler.com
gemeenteraadslid
Junior Member
Junior Member
Posts: 58
Joined: 2011-11-28, 11:27 UTC

Re: Update to Android 10 - No writing on external SD

Post by *gemeenteraadslid »

Seen it in the Play Store, will test it. I can already thank you for investing time into this and describing problem and workaround. So other devs and their users could profit from this as well. All thumbs up.
Would be good if the information could be handed over to Huawei, in whatever way (IDK what's best).
Best regards,
Michael

EDIT: It's already looking very good, after restart copying files is still possible.
gemeenteraadslid
Junior Member
Junior Member
Posts: 58
Joined: 2011-11-28, 11:27 UTC

Re: Update to Android 10 - No writing on external SD

Post by *gemeenteraadslid »

No more problems since beta update.
Post Reply