Andotp: "Export to external storage failed" when exporting to an external SD

Created on 31 Jul 2018  路  9Comments  路  Source: andOTP/andOTP

I'm using the latest version from the Play store, Android 8.0. I've configured the backups to use password and to add date to the name.

  • Auto backup to external SD card (/storage/9106-4FE8/Folder) says "Export to external storage failed".
  • Auto backup to internal SD card (/storage/emulated/0/Folder) works fine.
  • Manual backup to any place works fine (and produces files).
  • If I choose a non-existent folder on an external SD it says "Failed to create backup directory"

Log:

07-31 12:23:34.000 19829 19829 W System.err: java.io.FileNotFoundException: open failed: EACCES (Permission denied)
07-31 12:23:34.000 19829 19829 W System.err:    at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:313)
07-31 12:23:34.000 19829 19829 W System.err:    at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:211)
07-31 12:23:34.000 19829 19829 W System.err:    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1248)
07-31 12:23:34.000 19829 19829 W System.err:    at android.content.ContentResolver.openOutputStream(ContentResolver.java:1013)
07-31 12:23:34.000 19829 19829 W System.err:    at android.content.ContentResolver.openOutputStream(ContentResolver.java:989)
07-31 12:23:34.000 19829 19829 W System.err:    at org.shadowice.flocke.andotp.Utilities.FileHelper.writeBytesToFile(FileHelper.java:117)
07-31 12:23:34.000 19829 19829 W System.err:    at org.shadowice.flocke.andotp.Activities.BackupActivity.doBackupCrypt(BackupActivity.java:468)
07-31 12:23:34.000 19829 19829 W System.err:    at org.shadowice.flocke.andotp.Activities.BackupActivity.showSaveFileSelector(BackupActivity.java:324)
07-31 12:23:34.000 19829 19829 W System.err:    at org.shadowice.flocke.andotp.Activities.BackupActivity.saveFileWithPermissions(BackupActivity.java:343)
07-31 12:23:34.000 19829 19829 W System.err:    at org.shadowice.flocke.andotp.Activities.BackupActivity.access$200(BackupActivity.java:67)
07-31 12:23:34.000 19829 19829 W System.err:    at org.shadowice.flocke.andotp.Activities.BackupActivity$3.onClick(BackupActivity.java:136)
07-31 12:23:34.000 19829 19829 W System.err:    at android.view.View.performClick(View.java:6897)
07-31 12:23:34.000 19829 19829 W System.err:    at android.view.View$PerformClick.run(View.java:26101)
07-31 12:23:34.000 19829 19829 W System.err:    at android.os.Handler.handleCallback(Handler.java:789)
07-31 12:23:34.000 19829 19829 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:98)
07-31 12:23:34.000 19829 19829 W System.err:    at android.os.Looper.loop(Looper.java:164)
07-31 12:23:34.000 19829 19829 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:6944)
07-31 12:23:34.000 19829 19829 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
07-31 12:23:34.000 19829 19829 W System.err:    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
07-31 12:23:34.001 19829 19829 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
07-31 12:23:34.017  3168  3201 V MARsPolicyManager: handelAlertToastWindowStarted pkgName = org.shadowice.flocke.andotp, userId = 0

Maybe this is the reason:
https://developer.android.com/guide/topics/providers/document-provider#permissions

I don't understand Android permission system well, but if I'm getting it right, I guess andOTP should ask for the "persistent backup folder" via some system intent, and then takePersistableUriPermission(FLAG_GRANT_PERSISTABLE_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION | FLAG_GRANT_PREFIX_URI_PERMISSION) ?

https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_PREFIX_URI_PERMISSION

bug

Most helpful comment

Implemented persistent storage access in 356815d7e76bca3c63b5c6572162d46a293cd87b. You will need to select the backup folder again in the settings after the next update to get the persistent permissions.

All 9 comments

Apps cant access the SD card storage unless under a specific folder (something like /Android/Data/com.flocke/andotp )

@RichyHBM: but saving does work when I specify the file manually. It seems apps can access SD card, but they have to do the above dances.

The issue here is that when selecting to save it manually andOTP passes the save operation onto the android file manager rather than saving it itself

@flocke I'm glad to see you're on track on this issue.
I'm facing exactly the same problem.

Neither automatically saving to /sdcard/, /sdcard/andOTP, /storage/emulated/0 nor /storage/emulated/0 work.

When creating an encrypted backup a notification pops up which says Export to external storage successful but no file is created actually.
When creating a plain-text backup a notification pops up which says Export to external storage failed.

When enabling Ask for filename everything works as expected.

That most likely has to do with Androids new storage permissions. They disallow direct access (e.g. when entering a path directly) and want you yo go through their storage access framework. This is the major point I want to address in the next major release. But I don't really have time to work on andOTP currently, so it will take a while...

I feel you - I'm having a stressful time lately, too - I'll go see whether I can drop a PR sometime.

Thanks for your rapid answer :D

I'm just playing with AndOTP today (first time, nice app - thx!) - and I'm seeing this also.
However, I'm also finding when using google drive that when I backup, it saves a new copy of the file with the same filename - it doesn't overwrite the previous one? GDrive does it's own versioning so not sure what's happening here

Implemented persistent storage access in 356815d7e76bca3c63b5c6572162d46a293cd87b. You will need to select the backup folder again in the settings after the next update to get the persistent permissions.

Awesome, thanks :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RichyHBM picture RichyHBM  路  3Comments

MartinX3 picture MartinX3  路  4Comments

xiazeyu picture xiazeyu  路  3Comments

iTrooz picture iTrooz  路  4Comments

BoFFire picture BoFFire  路  4Comments