adb shell dpm set-device-owner fails on Mi TV Stick with Android 9 TV

268 Views Asked by At

I have a Kiosk application and I want it to be able to update itself. To this end I am trying to run the application as a Device Owner on a Mi TV Stick. The model is MiTV-AESP0 and the kernel is 4.9.113

Please the dpm command works when I run it against an emulator with Android TV 9 on.

I have set up a Receiver for the admin service

public class DeviceAdminBroadcastReceiver extends DeviceAdminReceiver {
    private static final String TAG = DeviceAdminBroadcastReceiver.class.getSimpleName();
    public static ComponentName getComponentName(Context context) {
        return new ComponentName(context.getApplicationContext(), DeviceAdminBroadcastReceiver.class);
    }

    @Override
    public void onEnabled(Context context, Intent intent) {
        super.onEnabled(context, intent);
        Log.d(TAG, "Device Owner Turned ON");
    }
    @Override
    public void onDisabled(Context context, Intent intent) {
        super.onDisabled(context, intent);
        Log.d(TAG, "Device Owner Turned OFF");
    }
    @Override
    public void onLockTaskModeEntering(Context context, Intent intent, String pkg) {
        // invoked when any app enters "kiosk" mode
    }
    @Override
    public void onLockTaskModeExiting(Context context, Intent intent) {
        // invoked when exiting "kiosk" mode
    }
}

In my manifest file I have declared the receiver

        <receiver
            android:name=".receivers.DeviceAdminBroadcastReceiver"
            android:exported="true"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_DEVICE_ADMIN" >
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin" />
            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
                <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
            </intent-filter>
        </receiver>

in my res/xml folder I have a device_admin.xml file

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
</device-admin>

If I try to run it against the TV Stick I get the following:

adb shell dpm set-device-owner com.tfsdisplays.packagemanager.local/com.tfsdisplays.packagemanager.receivers.DeviceAdminBroadcastReceiver                
java.lang.RuntimeException: Can't set package ComponentInfo{com.tfsdisplays.packagemanager.local/com.tfsdisplays.packagemanager.receivers.DeviceAdminBroadcastReceiver} as device owner.
        at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:177)
        at com.android.commands.dpm.Dpm.onRun(Dpm.java:106)
        at com.android.internal.os.BaseCommand.run(BaseCommand.java:54)
        at com.android.commands.dpm.Dpm.main(Dpm.java:41)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)

The same command work against the emulator is it is connected to ADB. I have tried USB debugging with a cable and WIFI. ADB versions 40 and 41.

I have done a factory reset on TV stick as well, nothing seems to make a difference. There is no accounts on the Stick and a device_policy dump shows the following:

adb shell dumpsys device_policy                                                                                                                           
Current Device Policy Manager state:

  Enabled Device Admins (User 0, provisioningState: 0):

    mPasswordOwner=-1

  Constants:
    DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC: 3600
    DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE: 2.0
    DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC: 86400

  Stats:
    LockGuard.guard(): count=0, total=0.0ms, avg=0.000ms, max calls/s=0 max dur/s=0.0ms max time=0.0ms

  Encryption Status: per-user

Please, I am at my wits end here, does anyone have any idea? Thank you in advance

0

There are 0 best solutions below