Question

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>
Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top