My app is running as a system app on a custom AOSP image. I am able to uninstall/install other APKs that I'm downloading from my backend. However, I cannot uninstall other system apps (which is a hard requirement for my purpose). My current mechanism is to use the deletePackage mechanism from the Android package manager via reflection:
val cPackageManager = Class.forName("android.content.pm.PackageManager")
cPackageDeleteObserver = Class.forName("android.content.pm.IPackageDeleteObserver")
deletePackage = cPackageManager.getMethod("deletePackage", String::class.java, cPackageDeleteObserver, Integer.TYPE)
deletePackage!!.invoke(context.packageManager, packageName, deleteObserver, DELETE_ALL_USERS)
Does anybody know how to achieve what I'm trying to do?
Don't you need to be a rooted device to uninstall System apps
, or have you found a way to do this without any rooting?
You must remount
the system, since you run SELinux, to be able to rearrange the locked files in the system.
3.You can run this code in your app instead
try{
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("pm uninstall com.package.name");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush();
su.waitFor();
}catch(IOException e){
throw new Exception(e);
}catch(InterruptedException e){
throw new Exception(e);
}
if pm uninstall
doesn't work, use the rm -rf path/deletefolder
then reboot the system
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.