关于AIDL通讯在魅族16Xs的兼容性问题

在魅族16Xs和16s上遇到AIDL服务绑定问题,表现为无法正常绑定服务,但能调起程序。通过对日志分析,发现pid不匹配,可能是魅族OEM软件限制了Context.BIND_AUTO_CREATE。解决方案是在程序A的application.onCreate()中手动启动服务,从而实现兼容。
摘要由CSDN通过智能技术生成

关于AIDL通讯在魅族16Xs的兼容性问题

最近在项目中遇到一个AIDL兼容魅族手机(16Xs,16s)问题,记录一下,以便下次后续翻阅。

1.设定好统一接口ICpMessage
2.程序A(com.xxx.xxxA)设定AIDL需要绑定的服务, 在AndroidManifest.xml中声明服务。

<service android:name=".XxxAidlService"
            android:exported="true"/>

3.程序B(com.xxx.xxxB)(对外提供的SDK包)绑定程序A所提供的服务

Intent intent = new Intent();
intent.setClassName("com.xxx.xxxA", "com.xxx.xxxA.XxxAidlService");
activity.bindService(intent, mConn, Context.BIND_AUTO_CREATE);

具体问题如下:
程序B(SDK)在调用程序A时,无法进行服务的绑定,但是可以调起程序A。

在华为,三星,Vivo, Oppo等手机(也包含Android 9.0)均表现正常,唯独在魅族的16Xs,16s(Android 9.0)无法进行绑定,出现如下异常:

03-31 22:15:54.681 I/Interception( 1590): third procedure runType: retrieve_service caller: com.xxx.xxxB callee: com.xxx.xxxA fg: true processName: com.xxx.xxxA calleeCalss: com.xxx.xxxA.XxxAidlService intent: Intent { cmp=com.xxx.xxxA/.XxxAidlService }
03-31 22:15:54.681 D/Interception( 1590): V4 isInterceptByRule realCallingPid: 8041 isMatch: false, runType=retrieve_service|||callerPkg=com.xxx.xxxB|||calleePkg=com.xxx.xxxA|||calleeClass=com.xxx.xxxA.XxxAidlService|||processName=com.xxx.xxxA|||action=|||data===|||extras===*|||interaction=fg|||intercept result=0
03-31 22:15:54.681 W/Interception( 1590): Link isInterceptAsUsual, caller com.xxx.xxxB call com.xxx.xxxA interception default intercept as true!
03-31 22:15:54.681 W/Interception( 1590): reason:6)finally, intercept as usual, interception = true details<<runType:retrieve_service isFgAction:true callerPkg:com.xxx.xxxB calleePkg:com.xxx.xxxA processName:com.xxx.xxxA Intent { cmp=com.xxx.xxxA/.XxxAidlService }>>

看到log中第一行,intent: Intent { cmp=com.xxx.xxxA/.XxxAidlService },觉得并无异常,component已经是正确的了,所以不觉得setClassName()有问题。
第二行的log,明确说明了callee 的pid not match(isMatch:false), 但是在程序运行后检查pid与log提示的pid 也就是说问题出在了intent的参数上面,所以才会出现几第三行和第四行的intercept.
接着修改intent, 将packageName,className使用ComponentName进行设置传递,添加的时候没有把握,所以添加了setPackage()。具体如下:

Intent intent = new Intent();
intent.setPackage("com.xxx.xxxA");
ComponentName componentName = new ComponentName("com.xxx.xxxA", "com.xxx.xxxA.XxxAidlService");
intent.setComponent(componentName);
activity.bindService(intent, mConn, Context.BIND_AUTO_CREATE);

修改之后,sdk却依然不能唤起服务。
参考网上一些文章进行分析,怀疑可能是魅族OEM软体对该bindService的动作进行了限制(Android原生:bindService动作会检索所有程序包含的服务(不管是否启动),如果服务未启动,通过判断Context.BIND_AUTO_CREATE的设置,进行启动。)
而魅族的OEM软体可能对此作了修改,使Context.BIND_AUTO_CREATE无效,也就是说,只能对已经启动的服务进行bindService操作。
带着这个想法,在程序A的application->onCreate()函数中添加服务的启动代码:

startService(new Intent(this, XxxAidlService.class));

修改之后,sdk就能兼容魅族16Xs和16s.

总结:对于兼容性适配问题,多分析给出的log,在确保代码无误的情况下,可以对framework的修改进行假设,尝试对应的修改来对自己的假设进行验证。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值