AIDL
1.流向
- in作為定向 tag 表示數(shù)據(jù)變更只能由調(diào)用方流向接收方,out 反之,inout 則為數(shù)據(jù)可以雙向流通變更。
- 返回值不需要流向修飾符
- 回調(diào):in,因?yàn)橐话慊卣{(diào)的調(diào)用是服務(wù)端,數(shù)據(jù)的流向就是從調(diào)用方(服務(wù)端)流向接收方(客戶端)。
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<泛型>=>不支持泛型,支持已支持的數(shù)據(jù)類型
private Map<String, float[]> channelDataMap=new HashMap<>();
in.readMap(channelDataMap, getClass().getClassLoader());
dest.writeMap(channelDataMap);
- 自定義序列化對(duì)象內(nèi)含有Map,支持已支持的數(shù)據(jù)類型 private Map<Integer,Another> map;
- 自定義序列化對(duì)象內(nèi)嵌一個(gè)序列化對(duì)象
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通信?
—— 不修改已對(duì)外公布的接口定義。
- 新增AIDL類 =》可以通信
- 類中新增AIDL接口 =》可以通信
- 類中修改AIDL接口=》無(wú)法通信
4.每一個(gè)AIDL接口都是子線程。只有Binder里面的代碼才是在(Binder進(jìn)程)跑,其他外圍代碼都在調(diào)用進(jìn)程跑;同時(shí),不同的queryBinder是在主線程,其他都是在Research_data的不同線程
- binder進(jìn)程主進(jìn)程阻塞,影響其他queryBinder(不同Binder,是會(huì)影響,還是因?yàn)槲覀児靡粋€(gè)binderpool?)queryBinder的AIDL實(shí)現(xiàn)也是在Binder的線程池
- 同步文件阻塞20s,阻塞的是主進(jìn)程嗎? 每個(gè)Binder運(yùn)行的獨(dú)立的進(jìn)程or線程?
- 調(diào)用方在不同線程or相同主線程?不影響。調(diào)用獲取到一次Binder,就在一個(gè)新的線程(interface.asBinder重新創(chuàng)建了),哪怕是來(lái)獲取同一個(gè)Binder(不然怎么支持多方調(diào)用)
- 不同進(jìn)程,用同一個(gè)ServiceConnection?同一個(gè)進(jìn)程重復(fù)綁定會(huì)異常嗎?不同進(jìn)程重復(fù)綁定會(huì)異常嗎?- 目前代碼是每次init都重新初始化instance,且沒銷毀之前的service connection,所以現(xiàn)在是可以重復(fù)注冊(cè),之前的DataManagerBinderPool.getInstance()也是可以正常工作