I am writing a system app (a service) and its job is to monitor android app installs (on Android 12) and if required uninstall it silently. I was able to setup a Broadcast receiver for "Intent.ACTION_PACKAGE_ADDED" and this works - I get notified on any app install.
However when I try to uninstall the application I am not able to. I have been searching this and other places for a week and have tried several options like below
- Runtime.getRuntime().exec("su -c 'pm uninstall " + packageName + "'"); [Needs rooting]
- uninstallIntent = Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI) [Activies are not allowed from background service - even it were allowed it would have not been silent]
- PackageInstaller.uninstall(appPackage, sender.intentSender) [Runs but no action is taken - probably because it requires device owner or profile owner]
So, before proceeding with more such trials, I am trying to check with the broader community if there is even a possibility of a solution for a System Service to silently uninstall an APK that it has not installed. Appreciate your time/effort in answering this. Thanks