private void addProxyDestroyMethods ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "destroyStub" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( Override . class ) . addParameter ( Object . class , "object" ) . returns ( TypeName . VOID ) . beginControlFlow ( "if(object != null)" ) . beginControlFlow ( "synchronized (stubMap)" ) . addStatement ( "IBinder binder = stubMap.get(object)" ) . beginControlFlow ( "if (binder != null)" ) . addStatement ( "(($T)binder).destroyStub()" , RemoterStub . class ) . addStatement ( "stubMap.remove(object)" ) . endControlFlow ( ) . endControlFlow ( ) . endControlFlow ( ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; methodBuilder = MethodSpec . methodBuilder ( "__checkProxy" ) . addModifiers ( Modifier . PRIVATE ) . returns ( TypeName . VOID ) . addStatement ( "if(mRemote == null) throw new RuntimeException(\"Trying to use a destroyed Proxy\")" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; methodBuilder = MethodSpec . methodBuilder ( "destroyProxy" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( Override . class ) . returns ( TypeName . VOID ) . addStatement ( "this.mRemote = null" ) . addStatement ( "unRegisterProxyListener(null)" ) . beginControlFlow ( "synchronized (stubMap)" ) . beginControlFlow ( "for(IBinder binder:stubMap.values())" ) . addStatement ( "((RemoterStub)binder).destroyStub()" ) . endControlFlow ( ) . addStatement ( "stubMap.clear()" ) . endControlFlow ( ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method for destroystub