1. 备份的数据 包括应用程序的一些数据, settings 的一些状态, wifi密码等等。
2. 保存的目的地可以是本地存储空间, 也可以是网络。
3. 当你重新安装实现backup 功能的应用程序时,或者你手机丢失的时候, 你可以restore 之前backup的数据,而不用重新设置就回到你自己喜欢的手机使用状态。
4. 不是所有的应用程序都可以backup, 只有实现了 Backup Agent 的应用程序才具备此功能。 具体实现参考文档。
5. 默认备份到本地, 定义在xml中, 服务器的话要给相应的app添加service key, minifest.xml中
1. Introduction
Menu option: Settings/Privacy/Back up my data
Android's backup service allows you to copy your persistent application data to remote "cloud" storage, in order to provide a restore point for the application data and settings. If a user performs a factory reset or converts to a new Android-powered device, the system automatically restores your backup data when the application is re-installed. This way, your users don't need to reproduce their previous data or application settings. This process is completely transparent to the user and does not affect the functionality or user experience in your application.
2. What data is backed up?
You can backup your application data, such as WIFI passwords, bookmarks of browser, Volume setting, airplane state, BT state and other settings.
Note: The backup service is not designed for synchronizing application data with other clients or saving data that you'd like to access during the normal application lifecycle. You cannot read or write backup data on demand and cannot access it in any way other than through the APIs provided by the Backup Manager.
3. Where to store?
The Data backup should give you another options to store on local SD Card or Online cloud storage. If you want to store it on cloud, you should first add an account for it.
Now, on our tequila product, the backup data will be stored on local storage by default. The data for application can be located and viewed by adb shell command on the following path. Take browser application for example, the file path is
“cache/backup/com.android.browser/”. You can find the data for browser on the file.
Now, there is no UI option to set where to store the data, and the default one is defined in the xml file.
//frameworks/base/packages/SettingsProvider/default.xml
<string name="def_backup_transport" translatable="false">android/com.android.internal.backup.LocalTransport</string> -->local
<string name="def_backup_transport" translatable="false">com.google.android.backup/.BackupTransportService</string> -->cloud
However, you can select the transport by adb shell command:
Set to local:
adb shell bmgr transport android/com.android.internal.backup.LocalTransport
Set to cloud:
adb shell bmgr transport com.google.android.backup/.BackupTransportService
4. What should be done for a backup & restore application?
Declaring the Backup Agent in Your Manifest file.
Registering for Android Backup Service key.
Extending BackupAgent, Required Methods onBackup() & onRestore().
Requesting Backup
Requesting Restore
5. How backup & restore process has been tested?
Once you've implemented your backup agent, you can test the backup and restore functionality with the following procedure, using bmgr.
We take com.android.browser package for example.
1) On local
a) Make a new bookmark "Baidu" for "http://baidu.com" .
b) run adb shell command
adb shell bmgr backup com.android.browser
adb shell bmgr run
If sucessful, you can view the new bookmark you added on “cache/backup/com.android.browser/X2Jvb2ttYXJrc18=”
such as following:
=http://www.google.com/m?client=ms-unknown&source=android-home Google http://www.facebook.comFacebook http://www.wikipedia.org/ Wikipedia http://www.ebay.com/ eBay http://www.nytimes.comNY Times9http://picasaweb.google.com/m/viewer?source=androidclient Picasa http://espn.com/ ESPN http://www.amazon.com/ Amazon http://www.weather.com/Weather Channel http://www.bbc.co.uk/ BBC http://www.yahoo.com/Yahoo http://www.msn.com/ MSN http://www.myspace.com/MySpace http://baidu.com/ 0�N�� 0����Baidu
c) Delete the bookmark "Baidu" you added, then run the following adb command to restore.
adb shell bmgr restore com.android.browser
d) Check the the bookmark, if successful, the bookmark "Baidu" will be restored and display again.
2) On cloud
a) Modify the default backup transprot for cloud or modify the Database of settings.db.
backup_transport: com.google.android.backup/.BackupTransportService
b) Registering for Android Backup Service. Modify the manifest file for browser, the service key can be got from
http://code.google.com/android/backup/index.html
<meta-data android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIcAjp6zRLRNMRQO4y290PxLiwDk2j67eMJM1K1g" />
c) make and generate a new sw then flash.
d) Add a new account, the data for backup and restore is dependent of the account.
e) Test it as the similar steps on Local above, but you can not view the data stored on cloud.