4

I try to use my application, which contains usage of Android Backup Service with my own BackupAgent, on Android Emulator. But backup doesn't work, despite of permission written in AndroidManifest.xml.

Permission: <uses-permission android:name="android.permission.BACKUP"/>

Warning in log: 09-17 09:05:58.553: WARN/PackageManager(73): Not granting permission android.permission.BACKUP to package my.package (protectionLevel=3 flags=0x1be46)

Exception in log (when I try to call requestRestore()): java.lang.SecurityException: getCurrentTransport: Neither user 10040 nor current process has android.permission.BACKUP.

What's wrong in my code?

UPD: My manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.package">

<uses-permission android:name="android.permission.BACKUP"/>

<application android:name="my.package.MyApplicationName" android:backupAgent="my.package.MyBackupAgent">

<meta-data android:name="com.google.android.backup.api_key" android:value="my_backup_api_key">

</application>

</manifest>
HitOdessit
  • 7,198
  • 4
  • 36
  • 59
Zakhar Fadeev
  • 307
  • 4
  • 15

2 Answers2

5

Official Android documentation of Manifest permissions knows nothing about permission

<uses-permission android:name="android.permission.BACKUP"/>

So, you should remove it from your Manifest. Android Backup Service doesn't require additional permissions.

However, specified permission can be used, but only by "system" applications, because it requires PROTECTION_SIGNATURE or PROTECTION_SIGNATURE_OR_SYSTEM level of permissions.

Such permission needed only when calling method BackupManager.dataChanged(String packageName), but usually this method is not needed when implementing Backup Service.

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
1

The android.permission.BACKUP permission is not needed for normal BackupAgent operations. Remove it from your manifest - though it shouldn't stop your BackupAgent from working.

Make sure to call BackupManager.dataChanged() method when you need to do a backup otherwise your BackupAgent will be called once but never again. It does not need android.permission.BACKUP either.

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
Hayes Haugen
  • 822
  • 1
  • 7
  • 7