关于adt:什么是“android:allowBackup”?

What is “android:allowBackup”?

自从新的ADT预览版本(版本21)以来,它们有一个新的lint警告,它告诉我清单文件(在应用程序标记中)的下一件事:

Should explicitly set android:allowBackup to true or false (it's true by default, and that can have some security implications for the application's data)

在官方网站上,他们写道:

A couple of new checks: you must explicitly decide whether your app allows backups, and a label check. There's a new command line flag for setting the library path. Many improvements to the incremental lint analysis while editing.

这警告是什么?什么是备份功能,以及如何使用它?

另外,为什么警告告诉我它有安全隐患?禁用此功能有哪些缺点和优点?

清单有两种备份概念:

  • "android:allowBackup"允许通过adb进行备份和恢复,如下所示:

Whether to allow the application to participate in the backup and
restore infrastructure. If this attribute is set to false, no backup
or restore of the application will ever be performed, even by a
full-system backup that would otherwise cause all application data to
be saved via adb. The default value of this attribute is true.

这被认为是一个安全问题,因为人们可以通过ADB备份您的应用,然后将您应用的私人数据导入他们的PC。

但是,我认为这不是一个问题,因为大多数用户不知道什么是adb,如果他们这样做,他们也会知道如何根设备。 ADB功能仅在设备启用了调试功能时才有效,这需要用户启用它。

因此,只有将其设备连接到PC并启用调试功能的用户才会受到影响。如果他们的PC上有使用ADB工具的恶意应用程序,这可能会有问题,因为应用程序可以读取私有存储数据。

我认为Google应该在开发者类别中添加默认禁用的功能,以允许通过ADB备份和恢复应用。

  • "android:backupAgent"允许使用云的备份和恢复功能,如下所示:

The name of the class that implement's the application's backup agent,
a subclass of BackupAgent. The attribute value should be a fully
qualified class name (such as,"com.example.project.MyBackupAgent").
However, as a shorthand, if the first character of the name is a
period (for example,".MyBackupAgent"), it is appended to the package
name specified in the element. There is no default. The
name must be specified.

这不是安全问题。


对于此lint警告以及所有其他lint警告,请注意您可以获得更全面的解释,而不仅仅是单行错误消息中的内容;您无需在网上搜索更多信息。

如果您通过Eclipse使用lint,请打开lint警告视图,在那里您可以选择lint错误并查看更长的解释,或者在错误行上调用quickfix(Ctrl-1),其中一个建议是"Explain"这个问题",这也将提供更全面的解释。如果您不使用Eclipse,则可以从lint(lint --html )生成HTML报告,其中包含警告旁边的完整说明,或者您可以要求lint解释特定问题。例如,与allowBackup相关的问题具有id"AllowBackup"(显示在错误消息的末尾),因此更全面的解释是:

1
2
3
4
5
6
7
8
9
$ ./lint --show AllowBackup
AllowBackup
-----------
Summary: Ensure that allowBackup is explicitly set in the application's
manifest

Priority: 3 / 10
Severity: Warning
Category: Security

allowBackup属性确定是否可以备份应用程序的数据
并恢复。这里记录在案。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
By default, this flag is set to true. When this flag is set to true,
application data can be backed up and restored by the user using adb backup
and adb restore.

This may have security consequences for an application. adb backup allows
users who have enabled USB debugging to copy application data off of the
device. Once backed up, all application data can be read by the user. adb
restore allows creation of application data from a source specified by the
user. Following a restore, applications should not assume that the data, file
permissions, and directory permissions were created by the application
itself.

Setting `allowBackup="false"` opts an application out of both backup and
restore.

To fix this warning, decide whether your application should support backup,
and explicitly set `android:allowBackup=(true|false)`"

点击这里查看更多信息


以下是这种意义上的备份真正意味着:

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.

?来自http://developer.android.com/guide/topics/data/backup.html

您可以在此处以开发人员身份注册此备份服务:
https://developer.android.com/google/backup/signup.html

可以备份的数据类型是文件,数据库,sharedPreferences,缓存和lib。这些通常存储在设备的/data/data/[com.myapp]目录中,该目录是读保护的,除非您具有root权限,否则无法访问。

更新:
您可以在BackupManager的api doc:BackupManager上看到此标志


这没有明确提到,但基于以下文档,我认为应用程序需要声明并实现BackupAgent才能使数据备份正常工作,即使在allowBackup设置为true的情况下(这是默认值)。

http://developer.android.com/reference/android/R.attr.html#allowBackup
http://developer.android.com/reference/android/app/backup/BackupManager.html
http://developer.android.com/guide/topics/data/backup.html


这是隐私问题。如果应用程序包含敏感数据,建议禁止用户备份该应用程序。有权访问备份文件(即android:allowBackup="true"时),即使在非root设备上也可以修改/读取应用程序的内容。

解决方案 - 在清单文件中使用android:allowBackup="false"

您可以阅读这篇文章以获取更多信息:
使用备份技术破解Android应用程序