I have a service in an application, and I can reach this service from different applications. And when applications are tried to bind this service I want to know which appli
I was looking how LocationManagerService restricts access, and here is what I found:
// android.location.ILocationService
Location getLastLocation(LocationRequest request, String packageName) throws RemoteException;
// com.android.server.LocationManagerService
public Location getLastLocation(LocationRequest r, String packageName) {
...
checkPackageName(packageName);
// From this point on we assume that the provided packageName is the real one
if (mBlacklist.isBlacklisted(packageName)) {
if (D) {
Log.d(TAG, "not returning last loc for blacklisted app: "
+ packageName);
}
return null;
}
...
}
...
private void checkPackageName(String packageName) {
if (packageName == null) {
throw new SecurityException("invalid package name: " + null);
}
int uid = Binder.getCallingUid();
String[] packages = mPackageManager.getPackagesForUid(uid);
if (packages == null) {
throw new SecurityException("invalid UID " + uid);
}
for (String pkg : packages) {
if (packageName.equals(pkg)) return;
}
throw new SecurityException("invalid package name: " + packageName);
}
I guess, this is satisfactory, because for the apps to share uid they need to be signed with the same key, so could be equally trusted