0

I'm trying to stop "com.android.uninstaller.UnistallerActivity" when appeared i use following code:

public static void killThisPackageIfRunning(final Context context, String packageName){
        ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        activityManager.killBackgroundProcesses(packageName);
    }   

and call it like that:

killThisPackageIfRunning(getApplicationContext(),"com.android.uninstaller.UnistallerActivity");
// and
killThisPackageIfRunning(getApplicationContext(),"com.android.uninstaller");

but doesn't work! i'm doing something wrong? or it's not the best way to do that?

I get Invalid packageName: com.android.uninstaller.UnistallerActivity error! is there another name for uninstaller activity, or because it's an activity and killBackgroundProcesses don't kill activities?

i know there another way to kill apps:

Process.sendSignal(pid, Process.SIGNAL_KILL);

but does it gd solution to stop system activity? how to know pid of UnistallerActivity if it's started?

i know it's not something simple but is there a hack (things of superuser permission to do that?)

any indication / idea / discussion would be appreciated.

flx
  • 14,146
  • 11
  • 55
  • 70
Smile2Life
  • 1,921
  • 3
  • 16
  • 30
  • Is there a legitimate reason to prevent a user from uninstalling an app? – stark Feb 24 '14 at 00:12
  • Yes, its work app installed in work phone. if you work already on work PC you don't have to uninstall any app i guess! – Smile2Life Feb 24 '14 at 00:18
  • Then use permissions. Killing the uninstaller might cause unpleasantness, – stark Feb 24 '14 at 00:27
  • Yess, i use the required permission, i know abt unpleasantness thing but that's professional app not for public use, we gonna lose lot of valuable data if the app uninstalled, especially it's used by many employees! – Smile2Life Feb 24 '14 at 00:39

1 Answers1

0

You need to specify the packageName to kill the process.

com.android.uninstaller.UnistallerActivity is not a valid packageName, it doesn't exist. The packageName is com.android.packageinstaller and the Acitivity name (though not needed or useful to kill an app) is com.android.packageinstaller.UninstallerActivity.

Note that killBackgroundProcesses can only be used to kill processes that are not currently visible. It's not possible to kill other apps foreground processes for non-system apps. You could just open another Activity instead (eg. some information that tells the user why he can't uninstall your app).

If you have superuser access however you can kill any app. Just grab it's Process id by looping through ActivityManager.getRunningAppProcesses():

List<ActivityManager.RunningAppProcessInfo> appProcesses = mActivityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo process : appProcesses) {
    if (PACKAGE_INSTALLER.equals(process.processName)) {
        YourFavouriteRootHelper.call("kill -9 "+process.pid);
    }
}

Source: https://github.com/omnirom/android_packages_apps_PackageInstaller/blob/android-4.4/AndroidManifest.xml

Marvin W
  • 434
  • 4
  • 16
  • What do you mean by "doesn't help"? I assume you want to kill the uninstaller if the user tries to use it - that's just not possible (without root), the only thing you can do is to show something else over the uninstaller so the user can't use it. – Marvin W Feb 24 '14 at 01:19
  • i know that's not possible, i'm looking for a hack to do it, even using superuser permissions :) – Smile2Life Feb 24 '14 at 01:21
  • Maybe http://stackoverflow.com/questions/21756180/ask-for-password-before-uninstalling-application is interesting for you? Especially the device admin part (more docs: https://developer.android.com/guide/topics/admin/device-admin.html ) – Marvin W Feb 24 '14 at 01:22
  • I added a way to do it with superuser access. – Marvin W Feb 24 '14 at 13:30