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
751 stars 40 forks source link

Companion App doesn't work on privacy-focused Android distributions (CalyxOS, GrapheneOS) #55

Open mrrfv opened 1 year ago

mrrfv commented 1 year ago

Discussed in https://github.com/mrrfv/linux-android-backup/discussions/39

Originally posted by **onley** November 27, 2022 > Does this still work under Android 12? I have tried to perform a backup twice, once using tar export and once using adb export and both times it failed at "Exporting contacts (as vCard)". When using adb export there was also an error message >adb: error: failed to stat remote object '/storage/emulated/0/linux-android-backup-temp/.': No such file or directory > apparently the companion app is unable to write to the device.

Report any possible clues regarding this problem as well as workarounds under this issue. Unfortunately I don't have any devices that could run either of these operating systems, so I'm unable to debug this without your help.

mrrfv commented 1 year ago

Can't test, but one possible solution is to disable Storage Scopes for Linux Android Backup and grant the storage permissions manually.

It's possible to do this by going to Settings -> Apps & notifications -> See all apps -> Linux Android Backup Companion -> Permissions -> Storage Scopes and toggling it off.

Then, storage permissions can be granted by going to Settings -> Apps & notifications -> See all apps -> Linux Android Backup Companion -> Permissions -> Files and media and choosing Allow management of all files.

alex27riva commented 1 year ago

I related issue: I did a backup on my Pixel 6a with stock Android and I restored it on GrapheneOS (on the same phone, after flashing it). Apps are restored correctly, but some crash at startup. A reinstallation of the app fixes the problem. Also, the internal storage data was not copied due to permission problems, I had to copy the folders manually using "adb push".

mrrfv commented 1 year ago

What permission errors were you getting?

alex27riva commented 1 year ago

What permission errors were you getting?

Unfortunately, I didn't take a screenshot. But it was a very general error message. If you don't have a Pixel phone with Graphene you can emulate it in Android Studio, although the steps to do the system build are not simple.

lemzwerg commented 1 year ago

I get the same problem on my Samsung Galaxy A40 that uses Android 11 (last automatic system update was in March 2023) . Running the backup script from the git repository I took the brute-force way of commenting out the offending code that tries to back up SMS and Contact information, and it continued.

diff --git a/functions/backup_func.sh b/functions/backup_func.sh
index 0a714da..81e37f9 100644
--- a/functions/backup_func.sh
+++ b/functions/backup_func.sh
@@ -55,13 +55,13 @@ function backup_func() {
   done

   # Export contacts and SMS messages
-  cecho "Exporting contacts (as vCard) and SMS messages (as CSV)."
-  mkdir ./backup-tmp/Contacts
-  get_file /storage/emulated/0/open-android-backup-temp . ./backup-tmp/Contacts
-  mkdir ./backup-tmp/SMS
-  mv ./backup-tmp/Contacts/SMS_Messages.csv ./backup-tmp/SMS
-  cecho "Removing temporary files created by the companion app."
-  adb shell rm -rf /storage/emulated/0/open-android-backup-temp
+#  cecho "Exporting contacts (as vCard) and SMS messages (as CSV)."
+#  mkdir ./backup-tmp/Contacts
+#  get_file /storage/emulated/0/open-android-backup-temp . ./backup-tmp/Contacts
+#  mkdir ./backup-tmp/SMS
+#  mv ./backup-tmp/Contacts/SMS_Messages.csv ./backup-tmp/SMS
+#  cecho "Removing temporary files created by the companion app."
+#  adb shell rm -rf /storage/emulated/0/open-android-backup-temp

   # Export internal storage
   cecho "Exporting internal storage - this will take a while."

Funnily, I still see 'Exporting contacts (as vCard) and SMS messages (as CSV).' on the terminal inspite of being commented out; I have no idea how this can happen...

Similarly, 'Exporting call logs' doesn't seem to work; I see

Exporting call logs.
Error while accessing provider:call_log
java.lang.SecurityException: Permission Denial: \
  opening provider com.android.providers.contacts.CallLogProvider from (null) (pid=18813, uid=2000) \
  requires android.permission.READ_CALL_LOG or android.permission.WRITE_CALL_LOG
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2386)
        ...

but this didn't make the script abort.

mrrfv commented 1 year ago

@lemzwerg Thanks for the info! However, to troubleshoot the issue you are facing, I need to see the logs when the script is run with no modifications. Could you please run the script as it is and send me the logs as an attachment or a link? This will help me understand what is going wrong and how to fix it. If you're worried the logs could contain identifying information, you can email them to me - my e-mail address can be found in my GitHub profile.

lemzwerg commented 1 year ago

Sorry for the late replay. Here it is.

~/samsung a40> LANG= LANGUAGE= .../git/open-android-backup/backup.sh
[...]
Couldn't find srm, a command provided by the 'secure-delete' package on Debian and Ubuntu. Secure removal of sensitive temporary files created by the script is unavailable - encrypting your disks is recommended.
Open Android Backup will install a companion app on your device, which will allow for contacts and other data to be backed up and restored.
The companion app is open-source, and you can see what it's doing under the hood on GitHub.
Companion app already downloaded.
Attempting to uninstall companion app.
Installing companion app.
Performing Streamed Install
Success
Granting required permissions to companion app.
Couldn't find any temporary files to cleanup, continuing. This is not an error.
Starting: Intent { cmp=mrrfv.backup.companion/.MainActivity }
The companion app has been opened on your device. Please press the 'Export Data' button - this will export contacts to the internal storage, allowing this script to backup them. Press Enter to continue.

Attempting to uninstall companion app.
Exporting apps.
Backing up app: com.skype.raider
[...many packages...]
Exporting contacts (as vCard) and SMS messages (as CSV).
0.00 B 0:00:00 [0.00 B/s] [<=>                                                                                  ]
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
Errors occurred while backing up . - this file (or multiple files) might've been ignored.
mv: cannot stat './backup-tmp/Contacts/SMS_Messages.csv': No such file or directory
mrrfv commented 1 year ago

Just to confirm, did you press the "Export data" button when the Companion App was automatically opened on your device? This error usually shows up when this button isn't pressed.

Related issue: https://github.com/mrrfv/open-android-backup/discussions/63

lemzwerg commented 1 year ago

Yep, I did that.

mrrfv commented 7 months ago

I can't reproduce this on the latest GrapheneOS 🙁

lemzwerg commented 7 months ago

Good news: I've just done a full backup without any problems of my Galaxy S40 (Android 11, Kernel 4.4.177 from 2023-Mar-24) on my GNU/Linux box using current git (f2c7e83dadd6344849e92ca0eba095648e8abfa2).

In other words, the problem, whatever it was, has been solved for me.