1

I'm building an xposed module and i want to hook a method only if certain process (app) called this method. I can get the process pid and uid using Binder, but I can't find a way to get the package name without having a context (i'm running my code in a class that can't get any Context as parameter).

How can I get it?

Thanks, Gidi

Sharas
  • 1,985
  • 3
  • 20
  • 43
  • This could resolve your problem: http://stackoverflow.com/questions/8542326/android-how-to-get-the-processname-or-packagename-by-using-pid – smarroufin Aug 17 '14 at 21:36
  • Thanks, but now i see that i didn't mention that i don't have any context to get the package manager – Sharas Aug 19 '14 at 09:03

1 Answers1

1

There is a solution working for me in the case you don't have Context:

BufferedReader cmdlineReader = null;
try {
    cmdlineReader = new BufferedReader(new InputStreamReader(
        new FileInputStream(
            "/proc/" + android.os.Process.myPid() + "/cmdline"),
        "iso-8859-1"));
    int c;
    StringBuilder processName = new StringBuilder();
    while ((c = cmdlineReader.read()) > 0) {
        processName.append((char) c);
    }
    return processName.toString();
} finally {
    if (cmdlineReader != null) {
        cmdlineReader.close();
    }
}

Source: Is there a way to get current process name in Android

Community
  • 1
  • 1
smarroufin
  • 135
  • 1
  • 9