android 系统服务介绍,Android Framework:系统服务未获得权限

我在

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

}

}

};

}

在此先感谢您的任何帮助或意见!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值