2

I am going to write a project that can hide another apps. I do research and find some useful code and it work well to hide my app. You can see my code below:

            PackageManager pm = getPackageManager();
            pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

And the problem is that, I don't know how can I hide another apps. I have tried to do lot of research but I still cannot find any solution. So you can look at my code below (but it is not working to hide another apps, but to hide my own is working well):

            PackageManager p = getPackageManager();
            ComponentName com = new ComponentName("com.example.pro",  "com.example.pro.classname");
            p.setComponentEnabledSetting(com, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

I know that the first parameter for ComponentName is a package name of the app, and second parameter is a main activity name of the app that I want to hide. But it always force close every time i changed both of this parameters to another value. But if I change the first parameter to package name of my app and second parameter to the main activity name of my app, it work well like the first code I show above.

And I have some log that i got when my app force close below:

04-01 22:56:32.884 13339-13339/com.example.pro D/AndroidRuntime: Shutting down VM  04-01 22:56:32.884 13339-13339/com.example.pro E/AndroidRuntime: FATAL EXCEPTION:         main Process: com.example.pro, PID: 13339
    java.lang.SecurityException: Permission Denial: attempt to change component state from pid=13339, uid=10613, package uid=10464
    at android.os.Parcel.readException(Parcel.java:1540)
    at android.os.Parcel.readException(Parcel.java:1493)
    at android.content.pm.IPackageManager$Stub$Proxy.setComponentEnabledSetting(IPackageManager.java:4073)
    at android.app.ApplicationPackageManager.setComponentEnabledSetting(ApplicationPackageManager.java:1839)
    at com.example.pro.MainActivity$1.onClick(MainActivity.java:142)
    at android.view.View.performClick(View.java:5191)
    at android.view.View$PerformClick.run(View.java:20931)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5944)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

So the problem is that, how can I hide another apps ? Any other code/method/suggest/example is fine. And i'd appreciate your help. Thanks.

Nara Na
  • 101
  • 1
  • 2
  • 10

1 Answers1

2

I don't know how can I hide another apps

Fortunately, you cannot do that from an ordinary SDK app, for obvious security reasons. Ransomware authors would love the ability to do what you are proposing.

There are some hooks for doing what amounts to "hide another apps" in the device owner APIs IIRC, but they require the app be a device owner app, and that requires special work at the time the phone or tablet is first powered on after being purchased.

You may be able to accomplish what you want on a rooted device, and you certainly can do it with your own custom ROM. You could also create a home screen that "hides" apps by simply not showing them in its own launcher.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So do you know any clue to do so on rooted device ? If you do, please give me some examples. Anyway thank for this answer. It help me to understand more lot. – Nara Na Apr 05 '16 at 13:06
  • @NaraNa: "So do you know any clue to do so on rooted device ?" -- no, sorry. I presume that it is possible, as you can pretty much do anything on a rooted device, but I do not know the specific techniques. – CommonsWare Apr 05 '16 at 13:13
  • @CommonsWare you mentioned "You could also create a home screen that "hides" apps by simply not showing them in its own launcher" can you elaborate on how someone might achieve this. I want to play around with something like this. – arias_JC Nov 20 '17 at 20:35
  • @arias_JC: Um, well, a home screen queries Android, via `PackageManager` and `queryIntentActivities()`, to find all of the launchable activities. You could have a feature in your home screen that allows the user to hide apps. You would then remove those apps' activities from the list you get from `PackageManager`, and use the filtered list for populating your launcher. – CommonsWare Nov 20 '17 at 20:44
  • @arias_JC: No -- that is covered in my answer. – CommonsWare Nov 20 '17 at 21:39