Android - uninstall other system app as system app
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?
android kotlin android-source android-package-managers
add a comment |
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?
android kotlin android-source android-package-managers
add a comment |
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?
android kotlin android-source android-package-managers
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?
android kotlin android-source android-package-managers
android kotlin android-source android-package-managers
asked Nov 12 '18 at 21:24
phoebus
17913
17913
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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("exitn");
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
1
the device in question is not rooted, so this will probably not work. My app has system privileges though, but I guess it won't be able without remounting the system as you said.
– phoebus
Nov 12 '18 at 21:58
If you still have time to develop then try this here,mount -o rw,remount /system
, Method 2. By terminal you should runt the code above. Try this locally before further development --> android.stackexchange.com/questions/110927/…
– Haroun Hajem
Nov 12 '18 at 22:16
What Android version are you running/targeting?
– Haroun Hajem
Nov 12 '18 at 22:16
1
I'll look into that - thanks for your help. I'm targeting 8.1
– phoebus
Nov 12 '18 at 23:28
This should work in Oreo in my experience. I didmount -o rw,remount /system
all the time
– Haroun Hajem
Nov 13 '18 at 9:44
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270330%2fandroid-uninstall-other-system-app-as-system-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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("exitn");
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
1
the device in question is not rooted, so this will probably not work. My app has system privileges though, but I guess it won't be able without remounting the system as you said.
– phoebus
Nov 12 '18 at 21:58
If you still have time to develop then try this here,mount -o rw,remount /system
, Method 2. By terminal you should runt the code above. Try this locally before further development --> android.stackexchange.com/questions/110927/…
– Haroun Hajem
Nov 12 '18 at 22:16
What Android version are you running/targeting?
– Haroun Hajem
Nov 12 '18 at 22:16
1
I'll look into that - thanks for your help. I'm targeting 8.1
– phoebus
Nov 12 '18 at 23:28
This should work in Oreo in my experience. I didmount -o rw,remount /system
all the time
– Haroun Hajem
Nov 13 '18 at 9:44
add a comment |
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("exitn");
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
1
the device in question is not rooted, so this will probably not work. My app has system privileges though, but I guess it won't be able without remounting the system as you said.
– phoebus
Nov 12 '18 at 21:58
If you still have time to develop then try this here,mount -o rw,remount /system
, Method 2. By terminal you should runt the code above. Try this locally before further development --> android.stackexchange.com/questions/110927/…
– Haroun Hajem
Nov 12 '18 at 22:16
What Android version are you running/targeting?
– Haroun Hajem
Nov 12 '18 at 22:16
1
I'll look into that - thanks for your help. I'm targeting 8.1
– phoebus
Nov 12 '18 at 23:28
This should work in Oreo in my experience. I didmount -o rw,remount /system
all the time
– Haroun Hajem
Nov 13 '18 at 9:44
add a comment |
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("exitn");
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
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("exitn");
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
answered Nov 12 '18 at 21:55
Haroun Hajem
1459
1459
1
the device in question is not rooted, so this will probably not work. My app has system privileges though, but I guess it won't be able without remounting the system as you said.
– phoebus
Nov 12 '18 at 21:58
If you still have time to develop then try this here,mount -o rw,remount /system
, Method 2. By terminal you should runt the code above. Try this locally before further development --> android.stackexchange.com/questions/110927/…
– Haroun Hajem
Nov 12 '18 at 22:16
What Android version are you running/targeting?
– Haroun Hajem
Nov 12 '18 at 22:16
1
I'll look into that - thanks for your help. I'm targeting 8.1
– phoebus
Nov 12 '18 at 23:28
This should work in Oreo in my experience. I didmount -o rw,remount /system
all the time
– Haroun Hajem
Nov 13 '18 at 9:44
add a comment |
1
the device in question is not rooted, so this will probably not work. My app has system privileges though, but I guess it won't be able without remounting the system as you said.
– phoebus
Nov 12 '18 at 21:58
If you still have time to develop then try this here,mount -o rw,remount /system
, Method 2. By terminal you should runt the code above. Try this locally before further development --> android.stackexchange.com/questions/110927/…
– Haroun Hajem
Nov 12 '18 at 22:16
What Android version are you running/targeting?
– Haroun Hajem
Nov 12 '18 at 22:16
1
I'll look into that - thanks for your help. I'm targeting 8.1
– phoebus
Nov 12 '18 at 23:28
This should work in Oreo in my experience. I didmount -o rw,remount /system
all the time
– Haroun Hajem
Nov 13 '18 at 9:44
1
1
the device in question is not rooted, so this will probably not work. My app has system privileges though, but I guess it won't be able without remounting the system as you said.
– phoebus
Nov 12 '18 at 21:58
the device in question is not rooted, so this will probably not work. My app has system privileges though, but I guess it won't be able without remounting the system as you said.
– phoebus
Nov 12 '18 at 21:58
If you still have time to develop then try this here,
mount -o rw,remount /system
, Method 2. By terminal you should runt the code above. Try this locally before further development --> android.stackexchange.com/questions/110927/…– Haroun Hajem
Nov 12 '18 at 22:16
If you still have time to develop then try this here,
mount -o rw,remount /system
, Method 2. By terminal you should runt the code above. Try this locally before further development --> android.stackexchange.com/questions/110927/…– Haroun Hajem
Nov 12 '18 at 22:16
What Android version are you running/targeting?
– Haroun Hajem
Nov 12 '18 at 22:16
What Android version are you running/targeting?
– Haroun Hajem
Nov 12 '18 at 22:16
1
1
I'll look into that - thanks for your help. I'm targeting 8.1
– phoebus
Nov 12 '18 at 23:28
I'll look into that - thanks for your help. I'm targeting 8.1
– phoebus
Nov 12 '18 at 23:28
This should work in Oreo in my experience. I did
mount -o rw,remount /system
all the time– Haroun Hajem
Nov 13 '18 at 9:44
This should work in Oreo in my experience. I did
mount -o rw,remount /system
all the time– Haroun Hajem
Nov 13 '18 at 9:44
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270330%2fandroid-uninstall-other-system-app-as-system-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown