4

The manifest file can be found here.

DeviceAdminReceiver class can be found here

agent_device_xml is as defined below:

<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
    <limit-password />
    <watch-login />
    <reset-password />
    <force-lock />
    <wipe-data />
    <expire-password />
    <encrypted-storage />
    <disable-camera />
</uses-policies>

Command executed and error:

adb shell dpm set-device-owner org.wso2.iot.agent.services/.AgentDeviceAdminReceiver
Error: Unknown admin: ComponentInfo{org.wso2.iot.agent.services/org.wso2.iot.agent.services.AgentDeviceAdminReceiver}

This is the logcat.

06-21 13:58:54.053 11499-12787/org.wso2.iot.agent E/Volley: [714] NetworkDispatcher.run: Unhandled exception java.lang.SecurityException: Admin ComponentInfo{org.wso2.iot.agent/org.wso2.iot.agent.services.AgentDeviceAdminReceiver} does not own the device
                                                        java.lang.SecurityException: Admin ComponentInfo{org.wso2.iot.agent/org.wso2.iot.agent.services.AgentDeviceAdminReceiver} does not own the device
                                                            at android.os.Parcel.readException(Parcel.java:1689)
                                                            at android.os.Parcel.readException(Parcel.java:1641)
                                                            at android.app.admin.IDevicePolicyManager$Stub$Proxy.setAutoTimeRequired(IDevicePolicyManager.java:6759)
                                                            at android.app.admin.DevicePolicyManager.setAutoTimeRequired(DevicePolicyManager.java:3377)
                                                            at org.wso2.iot.agent.services.operation.OperationManagerDeviceOwner.setAutoTimeRequired(OperationManagerDeviceOwner.java:681)
                                                            at org.wso2.iot.agent.services.operation.OperationProcessor.doTask(OperationProcessor.java:219)
                                                            at org.wso2.iot.agent.services.operation.OperationProcessor.setPolicyBundle(OperationProcessor.java:267)
                                                            at org.wso2.iot.agent.services.operation.OperationProcessor.doTask(OperationProcessor.java:125)
                                                            at org.wso2.iot.agent.services.MessageProcessor.performOperation(MessageProcessor.java:130)
                                                            at org.wso2.iot.agent.services.MessageProcessor.onReceiveAPIResult(MessageProcessor.java:327)
                                                            at org.wso2.iot.agent.proxy.APIController$9.parseNetworkResponse(APIController.java:383)
                                                            at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:123)
06-21 13:58:54.054 11499-11499/org.wso2.iot.agent E/APIController: com.android.volley.VolleyError: java.lang.SecurityException: Admin ComponentInfo{org.wso2.iot.agent/org.wso2.iot.agent.services.AgentDeviceAdminReceiver} does not own the device

How can i fix this isssue to make the application a device owner.

Community
  • 1
  • 1

4 Answers4

9

At a quick glance it looks like you're missing the ".services" in the receiver's name and the package name should not contain ".services".

Try: adb shell dpm set-device-owner org.wso2.iot.agent/.services.AgentDeviceAdminReceiver

Steve Miskovetz
  • 2,360
  • 13
  • 29
6

It's late, but what solved for me was changing the package name for the applicationId when running the ADB command.

What I was trying to do:

adb shell dpm set-device-owner com.package.name/com.package.name.MyDeviceAdminReceiver

What worked:

adb shell dpm set-device-owner applicationId/com.package.name.MyDeviceAdminReceiver
manoellribeiro
  • 187
  • 2
  • 5
  • And how do you get the applicationId? – Martin R. Nov 18 '21 at 17:31
  • @MartinR. you can find it on your app build.gradle file. android { defaultConfig { applicationId "hereIsYourApplicationId" } } – manoellribeiro Nov 19 '21 at 18:45
  • this seems to be the correct answer because in my case the application id changes for different stages (dev/test/prod) and then you also can't use /.MyDeviceAdminReceiver, you have to specify it directly. perfect, this saved my day. – Veit Dec 29 '22 at 11:48
4

I know its a bit late, but I got solved the error by changing the receiver name in the Manifest file from com.packageName.util.reciever.AdminReceiver to .AdminReceiver - followed by directly putting the Device Admin Receiver in the root of the package

After that Installing the app and running the command from ADB like ADB shell dpm set-device-owner com.package.package/.AdminReceiver

Marcello B.
  • 4,177
  • 11
  • 45
  • 65
Deeps
  • 41
  • 4
0

My Package name is au.com.rightwayitservices.kiosk as defined in Manifest file and my application id is au.com.rightwayitservices.kiosk as in build.gradle file and my class that extends DeviceAdminReceiver name is DeviceAdminReceiver

Manifest file.

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="au.com.rightwayitservices.kiosk" >

    <uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.REORDER_TASKS"/>

    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" tools:ignore="ProtectedPermissions"/>
    <uses-permission android:name="android.permission.CALL_PHONE"/>
    <uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">

        <activity
            android:name="au.com.rightwayitservices.kiosk.MainActivity"
            android:screenOrientation="portrait"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="au.com.rightwayitservices.kiosk.LockedActivity"
            android:label="@string/title_activity_locked"
            android:screenOrientation="portrait"
            android:enabled="false">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <receiver
            android:name="au.com.rightwayitservices.kiosk.DeviceAdminReceiver"
            android:description="@string/app_name"
            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_receiver" />
            <intent-filter>
                <action android:name="android.intent.action.DEVICE_ADMIN_ENABLED"/>
                <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
                <action android:name="android.intent.action.PROFILE_PROVISIONING_COMPLETE"/>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

    </application>
</manifest>


Sam
  • 1
  • 1