ARTICLE AD BOX
I am developing a custom DPC (Device Policy Controller) app.
My uninstall logic works correctly on fully managed devices (Device Owner), but it does not work on BYOD devices (Work Profile / Profile Owner).
Context
On fully managed devices → uninstall works fine.
On BYOD (work profile) → the method runs without crashing, but the app is not uninstalled.
The app was installed from the managed Google Play (work profile Play Store).
Code
public static boolean uninstallPackages(Context context, String... packages) { if (DPCUtils.isDeviceOwner(context) || DPCUtils.isProfileOwner(context)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); for (String pkg : packages) { packageInstaller.uninstall( pkg, PendingIntent.getBroadcast( context, 0, new Intent(), Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_IMMUTABLE : 0 ).getIntentSender() ); } return true; } } return false; }According to the documentation
PackageInstaller.uninstall() is available to:
the installer of record
the device owner
the affiliated profile owner
In BYOD, I am the Profile Owner (not affiliated).
What is the correct and supported approach to silently uninstall applications in a BYOD work profile setup?
