0

I am implementing an application that uses DevicePolicyManager. I have provisioned my device using adb and my app is running on device admin mode.

I am using setApplicationHidden method to hide/unhide applications using their package name. I want to do a whitelist system where I can specify a few apps to not disable and I want to disable the rest of the apps installed on the phone. I can hide the apps that are not on my whitelist but once they are hidden I cannot get any info about them using packagemanager or any other method.

All I can get the information about unhidden applications.

Is there a way I can retrive this information without storing the package names of the apps I've hidden somewhere?

dogauzun
  • 133
  • 2
  • 10
  • 1
    Maybe store the package info before hiding them? Does using the MATCH_DISABLED_COMPONENTS (or its earlier equiv.) flag work? – Keilaron Apr 28 '17 at 19:12
  • 1
    Actually, it seems MATCH_UNINSTALLED_PACKAGES should work. You'll probably still need to know the package names though. – Keilaron Apr 28 '17 at 19:40

2 Answers2

3

So, the correct answer was actually given in the comments. Just have tested it and it works perfectly fine, including getting the ApplicationInfo and label.

To get the full list of packages on a device (including hidden by DevicePolicyManger) you should include flags: MATCH_DISABLED_COMPONENTS | MATCH_UNINSTALLED_PACKAGES

context.getPackageManager().getInstalledPackages(MATCH_DISABLED_COMPONENTS | MATCH_UNINSTALLED_PACKAGES);
Carlos Fonseca
  • 7,881
  • 1
  • 17
  • 13
Pavel Luzhetskiy
  • 789
  • 1
  • 8
  • 26
2

I too have been searching for this answer.

This is not ideal but will return all packages to include hidden and disabled.

Runtime.getRuntime("pm list packages -u").exec();

here is how I use it

StringBuffer output = new StringBuffer();
    Process p;
    try {
        p = Runtime.getRuntime().exec(command);
        p.waitFor();
        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

        String line = "";
        while ((line = reader.readLine())!= null) {
            output.append(line + "\n");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    String response = output.toString();

That gives you a all package names, however if you try and use them with PackageManager you will get a NameNotFoundException unless you unhide them first.

RRiVEN
  • 2,519
  • 2
  • 14
  • 13