0

I know you can run an adb command to make an app to be a device owner:

adb shell dpm set-device-owner com.example.app/.AdminReceiver

I have made com.example.app a privileged app. Is there a way that I can set this app up as a device owner in the ASOP ROM? So that when the device boots up for the first time or after a factory reset, the app will be automatically provisioned as the device owner.

Due to some limitations, I cannot modify this privileged app. So I'm looking for solutions that can be done outside the app.

Grace Huang
  • 5,355
  • 5
  • 30
  • 52

1 Answers1

0

Since you're a privileged app, you should have no problem enabling it by default.

You'll need a boot receiver (make sure to include the specified permission).

You'll also need to add

<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />

Then, inside your boot receiver, you can run this:

DevicePolicyManager manager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
manager.setActiveAdmin(
    new ComponentName(context, YourAdminReceiverClass.class),
    true
);
TheWanderer
  • 16,775
  • 6
  • 49
  • 63