I am trying to discover the process id or package name of the process that sent me an intent. I don't want to put the process id or package name in an extra (as some other questions have asked) since I don't want to allow spoofing. The code I used is:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secure_file_share);
...
Intent intent = getIntent();
if (intent != null)
{
// get the caller
String callingPackage = getAppNameByPID(getApplicationContext(),
Binder.getCallingPid());
....
}
}
Where getAppNameByPID
translates the PID to the package name. The problem is that Binder.getCallingPid()
always returns the recipient's PID (not the caller's).
How do you get the caller's PID?
take a look at
http://developer.android.com/reference/android/app/ActivityManager.RunningAppProcessInfo.html
I tried this as well and I could only get a result using bound services.
But if you implement the Stub of your AIDL:
PID will be the most reliable one if you want to know which package called it.