Binder

作者: ttyttytty | 来源:发表于2022-04-20 17:14 被阅读0次

AIDL
1.流向

  • in作为定向 tag 表示数据变更只能由调用方流向接收方,out 反之,inout 则为数据可以双向流通变更。
  • 返回值不需要流向修饰符
  • 回调:in,因为一般回调的调用是服务端,数据的流向就是从调用方(服务端)流向接收方(客户端)。
   Book addBookIn(in Book book);
   Book addBookOut(out Book book);
   Book addBookInout(inout Book book);

2.传递类型

  • 枚举/注解的传递=>不支持。考虑AIDL里定义成String,公开以为@String的类
  • List<泛型>,支持
   Another  implements Parcelable ;
   private List<Another> anothers;   
   anothers = in.createTypedArrayList(Another.CREATOR);  
   dest.writeTypedList(anothers);
  • Map<泛型>=>不支持泛型,支持已支持的数据类型
   private Map<String, float[]> channelDataMap=new HashMap<>();   
   in.readMap(channelDataMap, getClass().getClassLoader());   
   dest.writeMap(channelDataMap);
  • 自定义序列化对象内含有Map,支持已支持的数据类型 private Map<Integer,Another> map;
  • 自定义序列化对象内嵌一个序列化对象
   Another  implements Parcelable ;
   private Another another; 
   another = in.readParcelable(Another.class.getClassLoader());   
   dest.writeParcelable(another,0);

传递类型

3.AIDL的兼容性:插件A使用Data:1,插件B使用Data_V2;ResearchApp本身Data_V3; 如何保证正常AIDL通信?
—— 不修改已对外公布的接口定义。

  • 新增AIDL类 =》可以通信
  • 类中新增AIDL接口 =》可以通信
  • 类中修改AIDL接口=》无法通信

4.每一个AIDL接口都是子线程。只有Binder里面的代码才是在(Binder进程)跑,其他外围代码都在调用进程跑;同时,不同的queryBinder是在主线程,其他都是在Research_data的不同线程

  • binder进程主进程阻塞,影响其他queryBinder(不同Binder,是会影响,还是因为我们公用一个binderpool?)queryBinder的AIDL实现也是在Binder的线程池
  • 同步文件阻塞20s,阻塞的是主进程吗? 每个Binder运行的独立的进程or线程?
  • 调用方在不同线程or相同主线程?不影响。调用获取到一次Binder,就在一个新的线程(interface.asBinder重新创建了),哪怕是来获取同一个Binder(不然怎么支持多方调用)
  • 不同进程,用同一个ServiceConnection?同一个进程重复绑定会异常吗?不同进程重复绑定会异常吗?- 目前代码是每次init都重新初始化instance,且没销毁之前的service connection,所以现在是可以重复注册,之前的DataManagerBinderPool.getInstance()也是可以正常工作

相关文章

网友评论

      本文标题:Binder

      本文链接:https://www.haomeiwen.com/subject/mywvertx.html