Search code examples
androidbackupandroid-backup-service

Implementing Android M's AutoBackup Feature


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!


Solution

  • 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.