9

Final intention here is to have a device in 'kiosk mod'.

They say you don't need NFC nor rooting to achieve application becoming device owner. I've yet to see a full example of this method but lets try:

adb shell dpm set-device-owner <package>/.<ReceiverImplementation>

should do... So I do so, and get:

java.lang.SecurityException: 
Neither user 2000 nor current process has android.permission.BIND_DEVICE_ADMIN.

Following code, therefore, returns false.

((DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE))
   .isDeviceOwnerApp(getApplicationContext().getPackageName())

This STO question poses a similar question but doesn't specify an actual failure..

Manifest file and the rest of the source is mostly inspired from this google sample

<manifest
    package="com.example.android.deviceowner"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="1"
    android:versionName="1.0">

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <receiver
            android:name=".DeviceOwnerReceiver"
            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_owner_receiver"/>
            <intent-filter>
                <action android:name="android.app.action.ACTION_DEVICE_ADMIN_ENABLED"/>
            </intent-filter>
        </receiver>

    </application>

</manifest>

Device I am trying to do this currently is LG G Pad.

Community
  • 1
  • 1
Rin malavi
  • 809
  • 1
  • 12
  • 25
  • Just to clarify... your receiver has android.permission.BIND_DEVICE_ADMIN in manifest but you still are getting this exception? – Okas Apr 23 '15 at 12:12
  • Yes, I'll edit the question to show this. – Rin malavi Apr 23 '15 at 12:23
  • One more question. What is in your device_owner_receiver.xml file? – Okas Apr 23 '15 at 12:49
  • Haven't changed that one – Rin malavi Apr 23 '15 at 12:54
  • 1
    The android docs state: `To deploy and activate a device owner, you must perform an NFC data transfer...` @ http://developer.android.com/about/versions/android-5.0.html#DeviceOwner – Randy Apr 23 '15 at 16:29
  • I've noticed that line, and shared links state that option as one possibility. I was hoping, dpm is here go around this. – Rin malavi Apr 23 '15 at 16:37
  • I think you need to explicity state `` at the beginning of the manifest so `pm` (package manager) picks it up as an app-wide permission. – Aaron Gillion Apr 27 '15 at 12:25
  • Nope, tried that... idea actually notes that it can only be given to the system app. – Rin malavi Apr 27 '15 at 14:29
  • Try to take the source code of a minimalist Device Owner App that I set here : https://github.com/florentdupont/AndroidScreenPinning/tree/master/DeviceOwnerApp. I know for sure that this app can be set as a device owner using the dpm command on a Nexus 9. – Florent Dupont Apr 28 '15 at 11:09
  • @Rinmalavi I have been having similar issue and contacted LG support. But havent heard back yet. You can take a look at error logs and such as this post. [link] (http://stackoverflow.com/questions/30163964/device-owner-issue-using-adb-method-with-lg-devices-only) – kash May 11 '15 at 09:49
  • @kash Seems like its a same issue. – Rin malavi May 11 '15 at 09:58
  • @Rinmalavi you were saying something about rooting? I am in touch with LG devs, and yours suggestions might be helpful. – kash May 11 '15 at 10:57
  • There is another way to accomplish this. That is to add /data/system/device_owner.xml, on a rooted device, but rooting is not on the scope of this problem. – Rin malavi May 11 '15 at 11:13
  • @FlorentDupont that repository says you have to enable device admin to use his demo properly. But this does not demonstrate how to enable device admin or device profile. – portfoliobuilder Jun 07 '17 at 00:24
  • you can check out this article http://florent-dupont.blogspot.fr/2015/02/10-things-to-know-about-device-owner.html – Florent Dupont Jun 07 '17 at 19:30

2 Answers2

3

Your manifest file seems correct. You should be aware that it may come from the state of your system when you are executing this command. Many points should be checked before running the dpm command successfully :

  • Make sure your app is already installed, like any other casual app
  • Make sure that no account is already set for the current user (make sure no account is set in Settings > Accounts) before its use.
  • there shouldn't be an existing device owner already registered

The best thing to do (That's what I did when experimenting indeed) is to completely factory-reboot your phone and avoid most configuration steps (except the mandatories steps "configure Wi-Fi", and "Name"), and do not associate any Google account.
Once provisioned, you are sure to be in a clean state. Then,

  1. Activate Debugging
  2. install your app with your IDE (or with pm install...)
  3. run the command adb shell dpm set-device-owner ...

I've written an article explaining most of these steps on my blog, take a look at it, it may be useful in your case.

Florent Dupont
  • 1,758
  • 18
  • 24
  • I've followed instructions, factory reset, no set accounts, users.. owners... Problem seems to persist, and at this point I'm sure its with the device choice. Thanks for your response. – Rin malavi Apr 28 '15 at 11:58
  • Could you share a minimalist test case source code (through github for instance) that doesn't work in your case ? I'd be interested in testing on a Nexus 9 (and confirm if this is really depending on the vendor's implementation of the provisioning app). – Florent Dupont May 01 '15 at 14:03
  • One of the test cases was yours github.com/florentdupont/AndroidScreenPinning/tree/master/DeviceOwnerApp, with the mentioned Exception when dpm called of course. – Rin malavi May 01 '15 at 14:34
  • OK. no other idea then.. Maybe you should contact LG's support ? – Florent Dupont May 04 '15 at 05:49
1

I am not sure if this is going to help you, but if not you, maybe someone else will use this solution. I had a very similar problem with Samsung Tab A. I could not set the ownership to my application. Always while running:

adb shell dpm set-device-owner cy.com.myapp/.AdminReceiver

I was getting:

java.lang.SecurityException: Neither user 2000 nor current process has 
com.sec.enterprise.permission.MDM_PROXY_ADMIN_INTERNAL.

After long search I finally found that I needed to add to my manifest permissions special permissions of Samsung:

<uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK" />

That did the trick and now my app can go to the kiosk mode on demand. Possibly you are looking at a similar problem - maybe there is one or more permission setting that you need to set for your LG. My solution worked for a non-rooted device (and obviously without any account added - fresh after factory reset).

mikeyy
  • 835
  • 1
  • 10
  • 18
  • 2
    Do you have a source for that permission? I am working with exactly the same device as you and it does not work for me. Seems strange that you need a "accessory framework" permission to enable device owner. – Niklas Ekman Nov 03 '16 at 15:39
  • As far as I can remember, I found this on samsung developers' forum, but I cannot remeber where exactly. The topic did not refer to my problem exactly, however after days of searching I was willing to try anything. And since it worked on the tablets I had, I was happy with it. Sorry I cannot be more helpfull. – mikeyy Oct 05 '17 at 07:20
  • We also had that error on a Samsung Tab A, however we were using the wrong package name for our application. It was fixed when we corrected the package name directory. The above addition to manifest wasn't necessary for us – Codelicious Jan 02 '19 at 13:02