AIDL
1.流向
- in作為定向 tag 表示數(shù)據(jù)變更只能由調(diào)用方流向接收方,out 反之,inout 則為數(shù)據(jù)可以雙向流通變更。
- 返回值不需要流向修飾符
- 回調(diào):in,因為一般回調(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);
- 自定義序列化對象內(nèi)含有Map,支持已支持的數(shù)據(jù)類型 private Map<Integer,Another> map;
- 自定義序列化對象內(nèi)嵌一個序列化對象
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進程)跑,其他外圍代碼都在調(diào)用進程跑;同時,不同的queryBinder是在主線程,其他都是在Research_data的不同線程
- binder進程主進程阻塞,影響其他queryBinder(不同Binder,是會影響,還是因為我們公用一個binderpool?)queryBinder的AIDL實現(xiàn)也是在Binder的線程池
- 同步文件阻塞20s,阻塞的是主進程嗎? 每個Binder運行的獨立的進程or線程?
- 調(diào)用方在不同線程or相同主線程?不影響。調(diào)用獲取到一次Binder,就在一個新的線程(interface.asBinder重新創(chuàng)建了),哪怕是來獲取同一個Binder(不然怎么支持多方調(diào)用)
- 不同進程,用同一個ServiceConnection?同一個進程重復(fù)綁定會異常嗎?不同進程重復(fù)綁定會異常嗎?- 目前代碼是每次init都重新初始化instance,且沒銷毀之前的service connection,所以現(xiàn)在是可以重復(fù)注冊,之前的DataManagerBinderPool.getInstance()也是可以正常工作