44import android .os .RemoteCallbackList ;
55import android .os .RemoteException ;
66
7- import com .codezjx .andlinker .annotation .ClassName ;
8- import com .codezjx .andlinker .annotation .MethodName ;
7+ import com .codezjx .andlinker .annotation .RemoteInterface ;
98
109import java .lang .annotation .Annotation ;
1110import java .lang .reflect .InvocationHandler ;
@@ -31,14 +30,14 @@ final class Invoker {
3130 }
3231
3332 private void handleCallbackClass (Class <?> clazz , boolean isRegister ) {
34- ClassName className = clazz .getAnnotation (ClassName .class );
35- if (className == null ) {
36- throw new IllegalArgumentException ("Callback interface doesn't has any annotation." );
33+ if (!clazz .isAnnotationPresent (RemoteInterface .class )) {
34+ throw new IllegalArgumentException ("Callback interface doesn't has @RemoteInterface annotation." );
3735 }
36+ String className = clazz .getSimpleName ();
3837 if (isRegister ) {
39- mCallbackClassTypes .putIfAbsent (className . value () , clazz );
38+ mCallbackClassTypes .putIfAbsent (className , clazz );
4039 } else {
41- mCallbackClassTypes .remove (className . value () );
40+ mCallbackClassTypes .remove (className );
4241 }
4342 }
4443
@@ -51,11 +50,11 @@ private void handleObject(Object target, boolean isRegister) {
5150 throw new IllegalArgumentException ("Remote object must extend just one interface." );
5251 }
5352 Class <?> clazz = interfaces [0 ];
54- ClassName classNameAnnotation = clazz .getAnnotation (ClassName .class );
55- if (classNameAnnotation == null ) {
56- throw new IllegalArgumentException ("Interface doesn't has any annotation." );
53+ if (!clazz .isAnnotationPresent (RemoteInterface .class )) {
54+ throw new IllegalArgumentException ("Interface doesn't has @RemoteInterface annotation." );
5755 }
5856 // Cache all annotation method
57+ String clsName = clazz .getSimpleName ();
5958 Method [] methods = clazz .getDeclaredMethods ();
6059 for (Method method : methods ) {
6160 // The compiler sometimes creates synthetic bridge methods as part of the
@@ -65,21 +64,17 @@ private void handleObject(Object target, boolean isRegister) {
6564 if (method .isBridge ()) {
6665 continue ;
6766 }
68- MethodName methodNameAnnotation = method .getAnnotation (MethodName .class );
69- if (methodNameAnnotation != null ) {
70- String clsName = classNameAnnotation .value ();
71- String methodName = methodNameAnnotation .value ();
72- String key = createMethodExecutorKey (clsName , methodName );
73- if (isRegister ) {
74- MethodExecutor executor = new MethodExecutor (target , method );
75- MethodExecutor preExecutor = mMethodExecutors .putIfAbsent (key , executor );
76- if (preExecutor != null ) {
77- throw new IllegalStateException ("Key conflict with class:" + clsName + " method:" + methodName
78- + ". Please try another class/method name with annotation @ClassName/@MethodName." );
79- }
80- } else {
81- mMethodExecutors .remove (key );
67+ String methodName = method .getName ();
68+ String key = createMethodExecutorKey (clsName , methodName );
69+ if (isRegister ) {
70+ MethodExecutor executor = new MethodExecutor (target , method );
71+ MethodExecutor preExecutor = mMethodExecutors .putIfAbsent (key , executor );
72+ if (preExecutor != null ) {
73+ throw new IllegalStateException ("Key conflict with class:" + clsName + " method:" + methodName
74+ + ". Please try another class/method name." );
8275 }
76+ } else {
77+ mMethodExecutors .remove (key );
8378 }
8479 // Cache callback class if exist
8580 Class <?>[] paramCls = method .getParameterTypes ();
@@ -156,7 +151,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
156151 int cookiePid = (int ) mCallbackList .getBroadcastCookie (i );
157152 if (cookiePid == pid ) {
158153 try {
159- Request request = createCallbackRequest (parseClassName ( service ), parseMethodName ( method ), args );
154+ Request request = createCallbackRequest (service . getSimpleName ( ), method . getName ( ), args );
160155 Response response = mCallbackList .getBroadcastItem (i ).callback (request );
161156 result = response .getResult ();
162157 if (response .getStatusCode () != Response .STATUS_CODE_SUCCESS ) {
@@ -182,24 +177,6 @@ private Request createCallbackRequest(String targetClass, String methodName, Obj
182177 return new Request (targetClass , methodName , wrappers );
183178 }
184179
185- private String parseClassName (Class <?> clazz ) {
186- ClassName className = clazz .getAnnotation (ClassName .class );
187- String classNameStr = "" ;
188- if (className != null ) {
189- classNameStr = className .value ();
190- }
191- return classNameStr ;
192- }
193-
194- private String parseMethodName (Method method ) {
195- MethodName methodName = method .getAnnotation (MethodName .class );
196- String methodNameStr = "" ;
197- if (methodName != null ) {
198- methodNameStr = methodName .value ();
199- }
200- return methodNameStr ;
201- }
202-
203180 private Class <?> getCallbackClass (String className ) {
204181 return mCallbackClassTypes .get (className );
205182 }
0 commit comments