mrrfv / open-android-backup

Back up your device without vendor lock-ins, using insecure software or root. Supports encryption and compression out of the box. Works cross-platform.
http://openandroidbackup.me/
GNU General Public License v3.0
674 stars 37 forks source link

Script aborts when exporting contacts #1

Closed 77 closed 2 years ago

77 commented 2 years ago

Exporting contacts (as vCard). adb: error: failed to stat remote object '/storage/emulated/0/linux-android-backup-temp': No such file or directory

I went into the adb shell and that file/folder does not exist.

77 commented 2 years ago

Cannot list the apps data directory because it's not debuggable.

1|sargo:/ $ run-as com.example.companion_app run-as: package not debuggable: com.example.companion_app

mrrfv commented 2 years ago

Didn't expect anyone to use this script so early in development :o

I noticed the exact same issue on my Android 6.0 test device (albeit the app works just fine on my Android 10 phone, odd). The problem is caused by the companion app not getting sufficient permissions to save contacts to the internal storage. Even though it has checks for this, it seems that the permission handler library says they've been granted anyway.

https://github.com/mrrfv/linux-android-backup/blob/f9f6655d52fe24a93144638ab68329a7708c0ce0/companion_app/lib/main.dart#L61-L66

I can build a debug .apk for you if needed.

Some questions before we continue:

  1. Did you follow the instructions (i.e. did you press the 'export data' button before the script tried to pull the contacts from internal storage)?
  2. What version of Android are you on?
  3. Did you try to manually grant storage permissions to the app (settings->apps->companion app->permissions)?
  4. Upon pressing the "Export Data" button in the app, can you see a snackbar saying that the data has been exported?
mrrfv commented 2 years ago

I've changed the library used for handling permissions and the app is working without problems on my phone running Android 10. Try installing it (download from Releases, but deleting the .apk downloaded by the script should also work), press "Export Data" and check if a directory called linux-android-backup-temp is created in the internal storage.

77 commented 2 years ago

I've been looking for a way to backup everything and ran across your repo yesterday. Happy to help you with testing.

I'm on a Pixel 3a running Android 11. My hunch is the files were stored in internal app storage instead the the absolute path you specified but I couldn't confirm without debugging the companion app. I'm not familiar with Flutter or Dart but they seem straightforward enough that I can contribute. By the way I'm running your app on Win10 under WSL2. Took a little while to get ADB working but the script runs fine under WSL.

77 commented 2 years ago

I had to manually uninstall the companion app because adb was giving an error about version mismatch. Once I did that the app ran and it did ask for permissions to contacts and media. However, I'm still seeing the same error.

Exporting contacts (as vCard).
adb: error: failed to stat remote object '/storage/emulated/0/linux-android-backup-temp': No such file or directory

Checked the filesystem and there is no file there.

sargo:/ $ ls -al /storage/emulated/0/
total 133
drwxrwx---  4 root everybody  3488 2021-03-12 06:22 .backups
-rw-rw----  1 root everybody    36 2019-08-07 14:57 .profig.os
drwxrwx---  2 root everybody  3488 2019-05-23 21:05 Alarms
drwxrwx---  5 root everybody  3488 2019-09-24 15:39 Android
drwxrwx---  2 root everybody  3488 2020-09-23 18:09 Audiobooks
drwxrwx---  2 root everybody  3488 2019-08-16 15:44 Books
drwxrwx---  2 root everybody  3488 2019-08-05 15:35 Cardboard
drwxrwx---  4 root everybody  3488 2020-07-12 14:17 DCIM
drwxrwx---  3 root everybody  3488 2021-04-13 15:41 Documents
drwxrwx---  4 root everybody  4096 2021-11-20 11:48 Download
drwxrwx---  3 root everybody  3488 2019-12-04 13:19 Movies
drwxrwx---  3 root everybody  3488 2019-09-28 09:18 Music
drwxrwx---  2 root everybody  3488 2019-05-23 21:05 Notifications
drwxrwx--- 12 root everybody  3488 2021-05-06 13:07 Pictures
drwxrwx---  2 root everybody  3488 2020-03-03 17:02 Podcasts
drwxrwx---  2 root everybody  3488 2019-05-23 21:05 Ringtones
drwxrwx---  2 root everybody  3488 2021-12-23 08:10 com.wondershare.mobilego_ACache
drwxrwx---  3 root everybody  3488 2019-05-28 08:11 data
drwxrwx---  2 root everybody  3488 2019-08-16 15:44 kindle
drwxrwx---  3 root everybody  3488 2019-12-11 17:04 netease
-rw-rw----  1 root everybody 69369 2020-09-22 04:00 ota
drwxrwx---  2 root everybody  3488 2019-08-05 10:03 panoramas
sargo:/ $

Cannot check the apps private storage because it's not debuggable.

sargo:/ $ run-as com.example.companion_app
run-as: package not debuggable: com.example.companion_app
mrrfv commented 2 years ago

running Android 11

That's the problem. I've heard that newer versions of Android add very strict restrictions to prevent apps from having full access to the internal storage.

I'll have to rewrite the file saving logic to make use of the newer SAF API. While it'd make things a lot inconvenient (as the user would need to manually tell the script where the contacts were saved), it'll guarantee stability and compatibility with newer versions of Android. Give me a few hours :)

Cannot check the apps private storage because it's not debuggable.

The app doesn't save anything to its private storage.

mrrfv commented 2 years ago

I found a way to make the app work for Android 11 without using SAF, but it's a little harder than I expected it to be (need to find a way to make it compatible with older versions). The update will be released tomorrow (assuming you're in Europe).

mrrfv commented 2 years ago

Just committed a change that should allow for the app to work on Android 11 without SAF. I don't have any devices running Android 11, so I'd appreciate it if you'd test the app again.

https://github.com/mrrfv/linux-android-backup/blob/c9520dc4b0a073f614d919fef88c9cf8a520b5c0/companion_app/lib/main.dart#L87-L92

Edit: adb was giving an error about version mismatch - I committed a fix for this, git pull the changes and try again.

77 commented 2 years ago

This time when I ran the companion app I was prompted to let it manage all files. I enabled that but the script still fails to find the folder on the device

Exporting contacts (as vCard).
adb: error: failed to stat remote object '/storage/emulated/0/linux-android-backup-temp': No such file or directory

I opened a shell and no folder was created under /storage/emulated/0/.

sargo:/storage/emulated/0 $ cd linux-android-backup-temp
/system/bin/sh: cd: /storage/emulated/0/linux-android-backup-temp: No such file or directory
mrrfv commented 2 years ago

I'm quite lost to be honest. Could you try installing Flutter, running the app in Android Studio and sending the debug logs?

77 commented 2 years ago

What logs are you looking for specifically. I ran the app in the debugger and everything appears to run fine. No errors or exceptions are thrown but the files simply are not where you expect them.

mrrfv commented 2 years ago

That's really odd...

I wanted to avoid this, but I'll try to reproduce this myself on a virtual device. I'll be able to download the system image files in a week though, since I'm on a data capped connection.

Could you look into #2 in the meanwhile?

Edit: Just set up Android Studio, Flutter and the virtual device on a new computer. Expect to see an update tomorrow. image

mrrfv commented 2 years ago

I'm sorry that this took so long. The problem was caused by the app not creating the linux-android-backup-temp directory, making the whole script silently fail. I missed this bug when testing on my main device because the folder was created before this bug was introduced.

A fix has been pushed to the repository and the patched app should be already built by the time you're reading this. Let me know if I can close this issue.

77 commented 2 years ago

Appears to have solved the problem.

Exporting contacts (as vCard).
/storage/emulated/0/linux-android-backup-temp/: 130 files pulled, 0 skipped. 0.2 MB/s (373483 bytes in 1.663s)
Removing temporary files created by the companion app.
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-0.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-1.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-11.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-3.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-4.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-16.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-13.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-17.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-8.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-5.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-6.vcf'
rm '/storage/emulated/0/linux-android-backup-temp/linux-android-backup-contact-7.vcf'
mrrfv commented 2 years ago

Awesome. I found some issues with restoring backups and they'll be fixed later today. Thanks for reporting the bug.

Edit: Fixed everything :)