I've had an issue with my device-owner App : before Android 5.1 it was working nicely, but now after the update to Android 5.1, installing a device-owner App disables the Backup Service.
Now in the device settings, when going into the Backup & reset option, the Backup service is greyed out, saying this: Backup service is inactive. This is set by your device policy
I could find this source on the google git repository... The code is not very long and easy to understand, they use android.app.backup.IBackupManager to disable the service... But easier is the commit comment:
Shutdown backup manager service when device owner is set
Here is what they do:
import android.app.backup.IBackupManager;
// Shutting down backup manager service permanently.
long ident = Binder.clearCallingIdentity();
try {
IBackupManager ibm = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
ibm.setBackupServiceActive(UserHandle.USER_OWNER, false);
} catch (RemoteException e) {
throw new IllegalStateException("Failed deactivating backup service.", e);
} finally {
Binder.restoreCallingIdentity(ident);
}
Wow... this makes a serious flaw for my project! No kidding: is it now really impossible for a user to have his data backed up while a device-owner App is installed ?
So, hopefully someone here could have infos or experience to share about this ? Sadly I'm not familiar with this but maybe with reflection this could be fixed afterwards ?
Thank you for reading!
Because this is a top Google search for device owner and backup
Starting with Android O you can enable it using the DevicePolicyManager
setBackupServiceEnabled (ComponentName admin, Boolean enabled)
https://developer.android.com/reference/android/app/admin/DevicePolicyManager.html
You can check if enables with isBackupServiceEnabled
Or set it
I got the same problem, furthermore adb backup would not run because the connection was denied (I assume because the backup service is down). Just as reference, this is one of the errors I saw in the logcat:
W/main(22253): type=1400 audit(0.0:106): avc: denied { ioctl } for path="socket:[76146]" dev="sockfs" ino=76146 ioctlcmd=7704 scontext=u:r:shell:s0tcontext=u:r:adbd:s0 tclass=unix_stream_socket permissive=0
Although I still haven't figured out how to restart the backup service (and I believe there is a way), I found a very helpful alternative to adb backup for accessing the data: https://stackoverflow.com/a/30265804/3317381
I have physical access to the devices running my app so this solution works well in my case. I hope this helps to at least recover your data under a development environment.
来源:https://stackoverflow.com/questions/30343205/device-owner-now-disables-the-backup-service