Device-Owner now disables the Backup service
Asked Answered
K

2

4

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!

Kail answered 20/5, 2015 at 7:38 Comment(1)
I should add also an important information: when provisioning the device, priori to 5.1 I had to setup my google account, choose a restoration option if needed, then apply the NFC Provisioning beam... Now the NFC has to be applied before the google account, otherwise once the google account setup it says it's too late the device has already been provisioned... This issue could be related to this new behavior, but how to avoid that... ?Kail
T
6

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

Thick answered 11/4, 2017 at 20:38 Comment(0)
C
0

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://mcmap.net/q/99680/-view-contents-of-database-file-in-android-studio

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.

Cheju answered 17/4, 2016 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.