Android SecurityException: Admin does not own the profile
Asked Answered
V

4

11

I have a device manager application and I am trying to use setScreenCaptureDisabled(..) function of DevicePolicyManager class available since API 21.

DevicePolicyManager pManager = (android.app.admin.DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
pManager.setScreenCaptureDisabled(admin.getReceiverName(), true);

I am getting the following error:

03-30 13:50:24.623: E/AndroidRuntime(11564): 
java.lang.SecurityException: Admin 
ComponentInfo{com.example.xxv/com.example.xxv.DeviceAdminReceiver} 
does not own the profile

Any idea how I can solve this problem?

If there is any permission required, can you please indicate what it is.

Voletta answered 30/3, 2015 at 12:33 Comment(0)
T
12

Your app needs to become either the device owner or profile owner. The easiest way to do this for one device is to use adb as here:

http://florent-dupont.blogspot.co.uk/2015/01/android-shell-command-dpm-device-policy.html

Basically from a command prompt

adb shell 
dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr

where com.foo.deviceowner is your app package, and DeviceAdminRcvr is the DeviceAdminReceiver in your package. Note that you will get a java.lang.IllegalStateException unless you have removed all accounts from the device (Settings > Accounts).

The other method is to create a NFC provisioning app as:

https://source.android.com/devices/tech/admin/provision.html

Torry answered 8/2, 2017 at 17:6 Comment(3)
can we execute 'dpm set-device-owner' command pro-grammatically...?Airlift
@Dhruv no, you cannot. You only can manage a device via adb (either via usb or nfc).Dyan
is still this command working in android 10 or does it need an EMM account!Afterclap
F
1

I think that you need to setup Profile with this code

Intent intent = new Intent(**ACTION_PROVISION_MANAGED_PROFILE**);
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
activity.getApplicationContext().getPackageName());
if (intent.resolveActivity(activity.getPackageManager()) != null) {
    startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE);
    activity.finish();
} else {
    Toast.makeText(activity, "Stopping.",Toast.LENGTH_SHORT).show();
}
Furtherance answered 7/7, 2015 at 22:59 Comment(0)
H
0

Are you correctly Registered as DeviceAdminReceiver?

As per the Android Documentation HERE, The calling device admin must be a device or profile owner. If it is not, a security exception will be thrown.

And from the Logs it is clear that you don't OWN the Profile!

Hutcherson answered 25/4, 2015 at 18:39 Comment(1)
@AshokBijoyDebnath did you ever find out this answer? How to own the profile?Psychoactive
D
0

Adding this for anyone researching a solution in the future.

My case was that I was updating an old app to a new application.

The new application needs to have the same Java package path. Which means that if your old application had: com.org.app/package.path.SomethingAdminReceiver then you have to have the package path package.path.SomethingAdminReceiver in your new app.

Develop answered 29/7 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.