0

I'm looking to implement the new autobackup feature introduced in Android M, as detailed in the docs here: http://developer.android.com/training/backup/autosyncapi.html#testing

I'm after easily restoring player database and shared preferences between installs, which this feature purports to enable for Android M. I'm not implementing the android backup service at this time.

The docs claim it's basically enabled by default, no need to write backup management classes and the like, at least for Android M devices - however, I can't get it to work.

abd shell bmgr enabled returns Backup Manager currently enabled

adb shell bmgr run doesn't say anything, but when I then run adb shell bmgr restore com.xyz.abc I get told:

Unable to restore package com.xyz.abc done

The docs say adb shell setprop log.tag.BackupXmlParserLogging VERBOSE will enable logging, but I can see literally no effect in the terminal or in logcat, and I can't think of another place that it would log to!

My manifest has android:fullBackupContent="@xml/backupscheme" in the application tag, as per the docs, and backupscheme.xml contains

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <include domain="database" path="database.db"/>
    <include domain="sharedpref" path="com.xyz.abc_preferences.xml"/>
    <exclude domain="external"/>
</full-backup-content>

The database and shareed preferences paths came from checking the decompiled app, and I've tried with this xml stripped back to nothing - nothing changes.

As far as I can tell from the docs, that should be sufficient for it to work, and yet I'm seeing nothing being persisted when I uninstall and reinstall the app.

Am I overlooking something? Are there any assumptions I'm making that I haven't questioned? Why doesn't it just work?! There's so little information out there, I really hope someone else is implementing this and has some guidance here!

Jez
  • 1,146
  • 8
  • 11

2 Answers2

1

First things first, I was overlooking logcat filters! Simply disabling filters allowed me to see the error message.

The first issue was Rejecting full data backup. user has not seen up to date legal text - this is apparently because old, existing google accounts aren't opted in to the backup service. This is slightly horrifying, as there's no simple way to opt in; how on earth users are going to get access to this I do not know.

To resolve this, remove all Google accounts from the device then turn it off and on again (if you don't restart, it won't allow any added account to act as a backup account!).

Once it's restarted, it should pop up a notification complaining that no account is setup for backups: just add your google account back, enable backups and hopefully you'll finally have it working.

This didn't fix everything for me - I'm still having issues getting it to recognise the gms transport - but the initial issue has been resolved.

Jez
  • 1,146
  • 8
  • 11
0

Am I overlooking something?

The recipe for a manual backup for testing is:

adb shell setprop log.tag.BackupXmlParserLogging VERBOSE
adb shell bmgr run
adb shell bmgr fullbackup ...

where ... is the application ID of the app to be backed up. I do not see where you ran adb shell bmgr fullbackup.

Note that the device has to have backups enabled in Settings.

Your LogCat should then contain lines like:

14936-14936/? D/AndroidRuntime: Calling main entry com.android.commands.bmgr.Bmgr
800-2345/? D/BackupManagerService: fullTransportBackup()
800-14960/? I/PFTBT: Initiating full-data transport backup of ...
800-14961/? D/BackupManagerService: Binding to full backup agent : ...
800-14961/? D/BackupManagerService: awaiting agent for ApplicationInfo{...}
800-810/? D/BackupManagerService: agentConnected pkg=com.commonsware...
800-14961/? I/BackupManagerService: got agent android.app.IBackupAgent$Stub$Proxy@e17804c
800-14961/? I/BackupRestoreController: Getting widget state for user: 0
800-14962/? I/file_backup_helper:    Name: apps/com.commonsware.android...
800-14962/? D/BackupManagerService: Calling doFullBackup() on com.commonsware...
9380-9391/com.commonsware.android.backup I/file_backup_helper:    Name: ...
800-14960/? I/PFTBT: Transport suggested backoff=0
800-14960/? I/PFTBT: Full backup completed.
9380-9380/? I/Process: Sending signal. PID: 9380 SIG: 9
800-2345/? D/BackupManagerService: Done with full transport backup.

(sorry, the lines are truncated to ensure that they fit the pages in my book).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the response. I had called that once, then forgot about it in my frustration at trying everything else out. It unfortunately makes no difference to call the commands as you've written there, followed by `adb shell bmgr restore ...` - just get the same "Unable to restore package ..." message with no elaboration. The setprop command really doesn't appear to do anything for me - what logging are you seeing? – Jez Feb 16 '16 at 12:36
  • @Jez: See updated answer. You might also get rid of ``, as what you have should be superfluous, and the system seems to quietly fail if it doesn't like the XML. Given that you have 1+ `` elements, the only things that will be backed up are those that you have specified via ``, nothing else, which is why `` is not needed here. – CommonsWare Feb 16 '16 at 12:46
  • thanks for the logcat contents - my mistake was leaving it filtered to app logging, and that put me on the right path! The issue is apparently "user has not seen up to date legal text" - and it sounds like a pain to actually get to view said text, but at least I know what's going wrong. Thanks for you assistance! – Jez Feb 16 '16 at 17:41
  • @Jez: Yeah, I think that wound up clearing up for me with a factory reset, though hopefully there is a less-intrusive approach. – CommonsWare Feb 16 '16 at 18:10
  • Yeah - from somewhere else I stumbled upon the instructions to remove google account(s), restart the device and then add the account(s) back, making sure to allow backups on the one you want to use. More gentle than a factory reset, but I have no idea how this feature is going to see adoption if every android m user has to do that to enable it! – Jez Feb 17 '16 at 11:22