我在
Android框架中添加了一个系统服务(不是应用程序)(因此在system_process中运行).通过Binder.getCallingUid()我可以确定调用进程/应用程序.到现在为止还挺好.
但是如果我的服务尝试使用其他系统服务(例如LocationManager),则抛出SecurityException,因为LocationManager认为它是由调用我的服务的原始应用程序调用的.
根据我的理解,系统服务默认拥有所有权限,所以不应该这样,是吗?
From programming4.us/Mobile/1304.aspx:
Binder services are free to make other
binder calls,but these calls always
occur with the service’s own identity
(UID and PID) and not the identity of
the caller.
这里有一些代码来说明问题:
public class MyService implements IInterface {
public IBinder asBinder() {
return mBinder;
}
private final IMyService.Stub mBinder = new IMyService.Stub() {
public void doSomething() {
int uid = Binder.getCallingUid(); // uid of the calling app
int myUid = Process.myUid(); // my uid == 1000
...
try {
ILocationManager lm = ILocationManager.Stub.asInterface(ServiceManager.getService("location"));
Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} catch (Exception e) {
SecurityException is thrown. Requires ACCESS_FINE_LOCATION
}
}
};
}
在此先感谢您的任何帮助或意见!