最新消息:20210917 已从crifan.com换到crifan.org

【已解决】rcsjta的RI运行报错:java.lang.SecurityException Not allowed to bind to service Intent

Java crifan 683浏览 0评论
折腾:
【无法解决】调试rcsjta的settings以触发setActivationMode设置激活模式以去找RCS服务启动逻辑
期间,通过重新
调试RI+运行core
的方式去调试,发现点击Service Status去获取状态时报错:
D/[RCS][RcsServiceControl]: isCompatible: Request(CapabilityService)
D/[RCS][RcsServiceControl]: Waiting for result for com.gsma.services.rcs.action.GET_COMPATIBILITY during max 2000ms
D/[RCS][RcsServiceControl]: isCompatible: Response(CapabilityService) -> true (in 4ms)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.gsma.rcs.ri, PID: 28598
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gsma.rcs.ri/com.gsma.rcs.ri.service.ServiceStatus}: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.gsma.services.rcs.capability.ICapabilityService pkg=com.gsma.rcs }
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2977)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3114)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6831)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:927)
     Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.gsma.services.rcs.capability.ICapabilityService pkg=com.gsma.rcs }
        at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1688)
        at android.app.ContextImpl.bindService(ContextImpl.java:1623)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:708)
        at com.gsma.services.rcs.capability.CapabilityService.connect(CapabilityService.java:111)
        at com.gsma.rcs.ri.service.ServiceStatus.onCreate(ServiceStatus.java:104)
        at android.app.Activity.performCreate(Activity.java:7224)
        at android.app.Activity.performCreate(Activity.java:7213)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3114) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.app.ActivityThread.main(ActivityThread.java:6831) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:927) 
E/MQSEventManagerDelegate: failed to get MQSService.
I/Process: Sending signal. PID: 28598 SIG: 9
Disconnected from the target VM, address: 'localhost:8607', transport: 'socket'
看来这个也是导致RI重新初始化的原因
去找找错误原因,相关代码是啥
java.lang.SecurityException Not allowed to bind to service Intent
java.lang.SecurityException: Not allowed to bind to service Intent – 简书
Android开发中一些疑难异常解决_goup的专栏-CSDN博客_java.lang.securityexception: not allowed to bind t
Not allowed to bind to service Intent 解决办法_zhangxp_xml的博客-CSDN博客_not allowed to bind to service intent
提到:
android:exported="true"
和:
android:process=":remote"
此处去看看此处相关代码
点击跳转到对应代码:
src/main/java/com/gsma/services/rcs/capability/CapabilityService.java
/**
 * Connects to the API
 * 
 * @throws RcsPermissionDeniedException
 */
public final void connect() throws RcsPermissionDeniedException {
    if (!sApiCompatible) {
        try {
            sApiCompatible = mRcsServiceControl.isCompatible(this);
            if (!sApiCompatible) {
                throw new RcsPermissionDeniedException(
                        "The TAPI client version of the capability service is not compatible with the TAPI service implementation version on this device!");
            }
        } catch (RcsServiceException e) {
            throw new RcsPermissionDeniedException(
                    "The compatibility of TAPI client version with the TAPI service implementation version of this device cannot be checked for the capability service!",
                    e);
        }
    }
    Intent serviceIntent = new Intent(ICapabilityService.class.getName());
    serviceIntent.setPackage(RcsServiceControl.RCS_STACK_PACKAGENAME);
    mCtx.bindService(serviceIntent, apiConnection, 0);
}
代码中都写了,可能会抛出:RcsPermissionDeniedException 的异常
此处:
public final static String RCS_STACK_PACKAGENAME = "com.gsma.rcs";
前面调用代码是:
src/com/gsma/rcs/ri/service/ServiceStatus.java
public class ServiceStatus extends RcsActivity implements RcsServiceListener {

    public void onCreate(Bundle savedInstanceState) {
    
        mApi.connect();
android – Providing a background service for other apps – Stack Overflow
不过别人回复的是:
A 用到了B
但是之前是先安装了A 后安装的B
解决办法是:卸载重装A -》即确保了B先(已)安装,再安装的B,即可。
此处,RI用到了core
或许是:之前先安装了RI,后安装的core?
不清楚,那么去:(已安装core前提下)卸载再重新安装RI,看看效果
不过这么操作之前,也去看看此处2个apk的manifest的xml中定义如何
/rcsjta/RI/AndroidManifest.xml
此处RI中,倒是有不少service但是都是exported是false
<service
    android:name="com.gsma.rcs.ri.messaging.filetransfer.FileTransferIntentService"
    android:exported="false”/>

<service
    android:name="com.gsma.rcs.ri.messaging.chat.single.SingleChatIntentService"
    android:exported="false"/>
<service
    android:name="com.gsma.rcs.ri.messaging.chat.group.GroupChatIntentService"
    android:exported="false”/>

。。。
且service貌似和此处也没太大关系?
RCS/rcsjta/core/AndroidManifest.xml
<application
    android:icon="@drawable/rcs_icon"
    android:label="@string/rcs_core_application_title">


    <!-- RCS service -->


    <service
        android:name="com.gsma.rcs.service.RcsCoreService"
        android:permission="com.gsma.services.permission.RCS">
        <intent-filter>
            <action android:name="com.gsma.rcs.SERVICE"/>
            <action android:name="com.gsma.services.rcs.contact.IContactService"/>
            <action android:name="com.gsma.services.rcs.capability.ICapabilityService"/>
            <action android:name="com.gsma.services.rcs.chat.IChatService"/>
            <action android:name="com.gsma.services.rcs.filetransfer.IFileTransferService"/>
            <action android:name="com.gsma.services.rcs.sharing.video.IVideoSharingService"/>
            <action android:name="com.gsma.services.rcs.sharing.image.IImageSharingService"/>
            <action android:name="com.gsma.services.rcs.sharing.geoloc.IGeolocSharingService"/>
            <action android:name="com.gsma.services.rcs.history.IHistoryService"/>
            <action android:name="com.gsma.services.rcs.extension.IMultimediaSessionService"/>
            <action android:name="com.gsma.services.rcs.upload.IFileUploadService"/>
        </intent-filter>
    </service>
这个核心的RcsCoreService的service
没有exported=true
不过其下有intent-filter
其中有
com.gsma.services.rcs.capability.ICapabilityService
是不是意思就是:支持ICapabilityService去调用?
其他还有几个service,好像和此处没关系就不贴了
另外还看到回复说了:
应该在service中加上 intent-filter
<service
    android:name=".WeatherService"
    android:exported="true" >
    <intent-filter>
        <action android:name="this.is.my.custom.ACTION" />
    </intent-filter>
</service>
代码中用:
new Intent("this.is.my.custom.ACTION")
即可。
此处应该去加上个exported=“true”
不过去找找官网,现在最新的定义中
AndroidManifest.xml
中的service中 默认 exported如何
androidmanifest.xml service exported
<service>  |  Android 开发者  |  Android Developers
“android:exported
其他应用的组件是否能调用服务或与之交互 —“true”表示可以,“false”表示不可以。当该值为“false”时,只有同一个应用或具有相同用户 ID 的应用的组件可以启动服务或绑定到服务。
默认值取决于服务是否包含 Intent 过滤器。没有任何过滤器意味着服务只能通过指定其确切的类名称进行调用。这意味着服务专供应用内部使用(因为其他应用不知晓其类名称)。因此,在这种情况下,默认值为“false”。另一方面,至少存在一个过滤器意味着服务专供外部使用,因此默认值为“true”。
此属性并非是唯一限制向其他应用披露服务的方式。您还可使用权限来限制哪些外部实体可以与服务交互(请参阅 permission 属性)。”
service的exported
表示服务是否可以被其他调用
默认是false
如果包含了intent-filter,默认是true
“android:permission
实体启动服务或绑定到服务所必需的权限的名称。如果 startService()、bindService() 或 stopService() 的调用者尚未获得此权限,该方法将不起作用,且系统不会将 Intent 对象传送给服务。
如果未设置该属性,则对服务应用由 <application> 元素的 permission 属性所设置的权限。如果二者均未设置,则服务不受权限保护。
如需了解有关权限的详细信息,请参阅简介的权限部分,以及单独的安全与权限文档。”
和:
“android:process
将运行服务的进程的名称。正常情况下,应用的所有组件都会在为应用创建的默认进程中运行。该名称与应用软件包的名称相同。<application> 元素的 process 属性可为所有组件设置不同的默认进程名称。不过,组件可以使用自己的 process 属性替换默认值,让您可以将应用散布到多个进程中。
如果为此属性分配的名称以冒号(“:”)开头,则系统会在需要时创建应用专用的新进程,并且服务会在该进程中运行。如果进程名称以小写字符开头,则服务将在使用该名称的全局进程中运行,前提是它拥有相应的权限。如此一来,不同应用中的组件便可共享进程,从而减少资源使用。”
先去重装RI吧
结果真的解决了,没有了此处的 重新初始化的问题了。
【总结】
此处有2个apk
RI和core
其中RI依赖于 会调用core中的service
之前:一直运行没问题
现在:RI调用core时,报错:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gsma.rcs.ri/com.gsma.rcs.ri.service.ServiceStatus}: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.gsma.services.rcs.capability.ICapabilityService pkg=com.gsma.rcs }
原因:要确保先安装被调用的(core),再安装要调用别人的(RI)
否则就会导致这种,要调用别人的apk,调用被调用的apk中service时,报错
Not allowed to bind to service Intent
解决办法:卸载和重装要调用别人的(RI),即可。

转载请注明:在路上 » 【已解决】rcsjta的RI运行报错:java.lang.SecurityException Not allowed to bind to service Intent

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.193 seconds, using 23.34MB memory