3

I tried to set my application the device_owner of my tablet (without ROOT or NFC), with the command:

adb shell dpm set-device-owner com.test.my_device_owner_app/.MyDeviceAdminReceiver

like is written on many sites (because i have to make a KIOSK APP). First of all i made a factory reset, then i installed my app, and then i wrote this command on shell, but the answer is:

java.lang.IllegalStateException: Trying to set device owner but device is already provisioned.
  at android.os.Parcel.readException(Parcel.java:1554)
  at android.os.Parcel.readException(Parcel.java:1499)
  at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:3212)
  at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:114)
  at com.android.commands.dpm.Dpm.onRun(Dpm.java:82)
  at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
  at com.android.commands.dpm.Dpm.main(Dpm.java:38)
  at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
  at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:249)

Now, how can i resolve this problem without rooting the tablet?

Kirill
  • 7,580
  • 6
  • 44
  • 95
mf87
  • 75
  • 9
  • did you figure out how to solve the problem? I have the lenovo a10-30. Seems like there is a hidden account that lenovo creates during setup so it says the device is already provisioned. – kash Oct 10 '16 at 16:20
  • nope....at the moment i still cannot set device_owner on this tablet. – mf87 Oct 12 '16 at 07:58

1 Answers1

0

I've got the same problem with Lenovo Yoga 2 Tablet.

Here is some snipped of the dpm source that I found while researching this problem.

    if (!allowedToSetDeviceOwnerOnDevice()) {
        throw new IllegalStateException(
                "Trying to set device owner but device is already provisioned.");
    }

    if (mDeviceOwner != null && mDeviceOwner.hasDeviceOwner()) {
        throw new IllegalStateException(
                "Trying to set device owner but device owner is already set.");
    }

And here is the allowedToSetDeviceOwnerOnDevice implementation

/**
 * Device owner can only be set on an unprovisioned device, unless it was initiated by "adb", in
 * which case we allow it if no account is associated with the device.
 */
private boolean allowedToSetDeviceOwnerOnDevice() {
    int callingId = Binder.getCallingUid();
    if (callingId == Process.SHELL_UID || callingId == Process.ROOT_UID) {
        return AccountManager.get(mContext).getAccounts().length == 0;
    } else {
        return Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.DEVICE_PROVISIONED, 0) == 0;
    }
}

So first make sure that all accounts are removed. Check Settings > Accounts. Lenovos bloat ware has created the Local Calendar account by default. You have to remove it.

For those who have root access

See the SO answer for manually creating the device_owner.xml. As I can see from the implementation, dpm is doing the same thing as described in the answer. By the way, I leave the name attribute with no problems.

When you look in the else case, you can bypass the test by calling

settings put global device_provisioned 0

My experience with Yoga tablet

Even I have root access, doing factory reset and trying the device_owner.xml method I haven't success yesterday.

What I've done today was to login with a google account (yesterday I've skipped this part) and after remove also this account in Settings > Accounts I was able (as su) to run the dpm command successfully.

Update

I've got another Yoga 2 tablet without root access and without login with my google account and have successfully set the device owner.

One think I can recommend you: Try to close Android Studio after installing your kiosk mode app. Maybe this causes another Binder.getCallingUid().

Vertex
  • 2,682
  • 3
  • 29
  • 43