0

I am trying to disable one of the app from my app. I have created a launcher app and trying to use following method of package manager

pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

But I'm getting SecurityException as SecurityException: Permission Denial: attempt to change component state from pid=20217, uid=10066, package uid=10067

Note: Somewhere I found the solution to this is to mention below permission in manifest

But I'm getting a warning in this permission that this permission is only granted to system apps.

  • "I am trying to disable one of the app from my app" -- why? "But I'm getting a warning in this permission that this permission is only granted to system apps" -- correct. Otherwise, malware authors would readily disable all sorts of apps, as part of a ransomware attacks. – CommonsWare May 24 '17 at 13:04
  • Yes you are right. But then what is the correct way to change the component state? – Vishakha Gahukar May 24 '17 at 13:40
  • You don't change the component state. You do something else. Since you did not bother to answer the "why?" question from my original comment, I have no way to advise you as to possible alternatives. – CommonsWare May 24 '17 at 13:47
  • "I am trying to disable one of the app from my app" -- why? - The purpose for creating such app is to achieve mobile device management through launcher app.My app is only for particular organization. – Vishakha Gahukar May 25 '17 at 05:28
  • If you are truly implementing an MDM solution, you are welcome to look at the device admin and device owner APIs. – CommonsWare May 25 '17 at 10:24
  • Can we run such apps(device owner) on avd? Because I was not able to encrypt my device (avd). Also I want to know whether it is required to create profile if we have created device owner app? – Vishakha Gahukar May 25 '17 at 14:24

1 Answers1

0

In order to disable/enable other apps your app must have system privileges. To achieve privileges you should do these steps.

Add this line to your manifest header android:sharedUserId="android.uid.system"

Add this permission to the manifest "android.permission.CHANGE_COMPONENT_ENABLED_STATE"

Sign your app with a system key.

I checked it in my launcher app.

Pavel Bobkov
  • 101
  • 2
  • 5