Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device owner on a nonrooted device (Android L), without NFC, using adb shell, dpm set-device-owner

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.

like image 483
Rin malavi Avatar asked Apr 23 '15 11:04

Rin malavi


2 Answers

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.

like image 135
Florent Dupont Avatar answered Oct 19 '22 18:10

Florent Dupont


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).

like image 41
mikeyy Avatar answered Oct 19 '22 19:10

mikeyy