我已经创建了一个JobIntentSerivce,并且在MyService类的清单文件中没有指定BIND_JOB_SERVICE权限。因此,当我为这个服务排队工作时,它抛出了运行时错误"MyService不需要android.permission.BIND_JOB_SERVICE权限“。如果我在android清单中给MyService权限,它会解决这个问题。但我的疑问是,为什么显示“不需要许可”的错误,是打字错误还是背后的逻辑原因?
发布于 2018-09-06 19:48:35
JobIntentService必须受BIND_JOB_SERVICE权限的保护,但在清单中添加权限时,将android:exported设置为true将解决这个令人困惑的错误
<service android:name="com.example.jobscheduler.MyService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>发布于 2018-09-06 20:21:11
看一下源代码,JobSchedulerStub中的enforceValidJobRequest(int uid, JobInfo job)方法的注释确实在某种程度上解释了它所检查的内容:
JobSchedulerService.JobSchedulerStub:
// Enforce that only the app itself (or shared uid participant) can schedule a // job that runs one of the app's services, as well as verifying that the // named service properly requires the BIND_JOB_SERVICE permission private void enforceValidJobRequest(int uid, JobInfo job) { .. }
在这个方法中,它肯定会检查JobInfo (jobinfo.getService())中的Service是否具有权限BIND_JOB_SERVICE --如果没有权限,就会抛出错误,这会给我带来一些误导性的消息。它还检查只有系统或应用程序uid可以入队工作,这显然是出于安全原因。
https://stackoverflow.com/questions/52203311
复制相似问题