Skip to content

Commit 455e072

Browse files
committed
Update sample and README.
1 parent 0bd06ae commit 455e072

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ dependencies {
4141

4242
## Getting Started
4343

44-
Define a normal java Interface with `@ClassName` and `@MethodName` annotation, and implements the interface.
44+
Define a normal java Interface with `@RemoteInterface` annotation, and implements the interface.
4545

4646
```java
47-
@ClassName("com.example.andlinker.IRemoteService")
47+
@RemoteInterface
4848
public interface IRemoteService {
4949

50-
@MethodName("getPid")
5150
int getPid();
5251

53-
@MethodName("basicTypes")
5452
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
5553
double aDouble, String aString);
5654
}
@@ -141,13 +139,11 @@ AndLinker supports all AIDL data types:
141139
You can modify the client side app's remote service interface, wrap the return type of the method.
142140

143141
```java
144-
@ClassName("com.example.andlinker.IRemoteService")
142+
@RemoteInterface
145143
public interface IRemoteService {
146144

147-
@MethodName("getPid")
148145
Observable<Integer> getPid();
149146

150-
@MethodName("basicTypes")
151147
Call<Void> basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
152148
double aDouble, String aString);
153149
}
@@ -164,21 +160,19 @@ new AndLinker.Builder(this)
164160
```
165161

166162
### Deal with callbacks
167-
Define callback interface to receive callbacks from the remote service with `@ClassName` and `@MethodName` annotation.
163+
Define callback interface to receive callbacks from the remote service with `@RemoteInterface` annotation.
168164

169165
```java
170-
@ClassName("com.example.andlinker.IRemoteCallback")
166+
@RemoteInterface
171167
public interface IRemoteCallback {
172168

173-
@MethodName("onValueChange")
174169
void onValueChange(int value);
175170
}
176171
```
177172

178173
Use `@Callback` annotation for callback parameter.
179174

180175
```java
181-
@MethodName("registerCallback")
182176
void registerCallback(@Callback IRemoteCallback callback);
183177
```
184178

@@ -198,7 +192,6 @@ mLinker.registerObject(mRemoteCallback);
198192
You can specify `@In`, `@Out`, or `@Inout` annotation for parameter, indicating which way the data goes, same as AIDL.
199193

200194
```java
201-
@MethodName("directionalParamMethod")
202195
void directionalParamMethod(@In KeyEvent event, @Out int[] arr, @Inout Rect rect);
203196
```
204197

@@ -210,11 +203,19 @@ void directionalParamMethod(@In KeyEvent event, @Out int[] arr, @Inout Rect rect
210203
You can use `@OneWay` for a method which modifies the behavior of remote calls. When used, a remote call does not block, it simply sends the transaction data and immediately returns, same as AIDL.
211204

212205
```java
213-
@MethodName("onewayMethod")
214206
@OneWay
215207
void onewayMethod(String msg);
216208
```
217209

210+
## Proguard Configuration
211+
212+
Add following rules to `proguard-rules.pro` file, keep classes that will be serialized/deserialized over AndLinker.
213+
```
214+
-keep class com.example.andlinker.model.** {
215+
public void readFromParcel(android.os.Parcel);
216+
}
217+
```
218+
218219
## Feedback
219220

220221
Any issues or PRs are welcome!

README_CN.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ dependencies {
3333

3434
## 快速开始
3535

36-
使用注解`@ClassName``@MethodName`修饰远程服务接口`IRemoteService`,并实现它
36+
使用注解`@RemoteInterface`修饰远程服务接口`IRemoteService`,并实现它
3737

3838
```java
39-
@ClassName("com.example.andlinker.IRemoteService")
39+
@RemoteInterface
4040
public interface IRemoteService {
4141

42-
@MethodName("getPid")
4342
int getPid();
4443

45-
@MethodName("basicTypes")
4644
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
4745
double aDouble, String aString);
4846
}
@@ -133,13 +131,11 @@ AndLinker支持AIDL所有数据类型:
133131
在客户端App中,你可以copy并修改远程服务接口,包装方法的返回值
134132

135133
```java
136-
@ClassName("com.example.andlinker.IRemoteService")
134+
@RemoteInterface
137135
public interface IRemoteService {
138136

139-
@MethodName("getPid")
140137
Observable<Integer> getPid();
141138

142-
@MethodName("basicTypes")
143139
Call<Void> basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
144140
double aDouble, String aString);
145141
}
@@ -156,21 +152,19 @@ new AndLinker.Builder(this)
156152
```
157153

158154
### 处理远程服务接口回调
159-
使用`@ClassName``@MethodName`注解修饰远程服务回调接口`IRemoteCallback`
155+
使用`@RemoteInterface`注解修饰远程服务回调接口`IRemoteCallback`
160156

161157
```java
162-
@ClassName("com.example.andlinker.IRemoteCallback")
158+
@RemoteInterface
163159
public interface IRemoteCallback {
164160

165-
@MethodName("onValueChange")
166161
void onValueChange(int value);
167162
}
168163
```
169164

170165
在远程方法中使用`@Callback`注解修饰callback参数
171166

172167
```java
173-
@MethodName("registerCallback")
174168
void registerCallback(@Callback IRemoteCallback callback);
175169
```
176170

@@ -190,7 +184,6 @@ mLinker.registerObject(mRemoteCallback);
190184
你可以为远程方法的参数指定`@In``@Out`,或者`@Inout`注解,它标记了数据在底层Binder中的流向,跟AIDL中的用法一致
191185

192186
```java
193-
@MethodName("directionalParamMethod")
194187
void directionalParamMethod(@In KeyEvent event, @Out int[] arr, @Inout Rect rect);
195188
```
196189

@@ -202,11 +195,19 @@ void directionalParamMethod(@In KeyEvent event, @Out int[] arr, @Inout Rect rect
202195
你可以在远程方法上使用`@OneWay`注解,这会修改远程方法调用的行为。当使用它时,远程方法调用不会堵塞,它只是简单的发送数据并立即返回,跟AIDL中的用法一致
203196

204197
```java
205-
@MethodName("onewayMethod")
206198
@OneWay
207199
void onewayMethod(String msg);
208200
```
209201

202+
## Proguard配置
203+
204+
`proguard-rules.pro`文件中添加如下混淆规则,将需要序列化/反序列化的model类给keep掉
205+
```
206+
-keep class com.example.andlinker.model.** {
207+
public void readFromParcel(android.os.Parcel);
208+
}
209+
```
210+
210211
## 反馈
211212

212213
欢迎各位提issues和PRs!

sample/src/main/java/com/example/andlinker/BindingActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public void onFailure(Call<Integer> call, Throwable t) {
111111
@Override
112112
protected void onDestroy() {
113113
super.onDestroy();
114+
mLinker.unRegisterObject(mRemoteCallback);
114115
mLinker.unbind();
115116
}
116117

sample/src/main/java/com/example/andlinker/RemoteService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public IBinder onBind(Intent intent) {
3636
return mLinkerBinder;
3737
}
3838

39+
@Override
40+
public void onDestroy() {
41+
super.onDestroy();
42+
Log.d(TAG, "Service onDestroy()");
43+
mLinkerBinder.unRegisterObject(mRemoteService);
44+
mLinkerBinder.unRegisterObject(mRemoteTask);
45+
}
46+
3947
private final IRemoteService mRemoteService = new IRemoteService() {
4048

4149
@Override

0 commit comments

Comments
 (0)