# Remoter
Remoter - An alternative to Android AIDL for Android Remote IPC services using plain java interfaces
Remoter makes developing android **remote services** intuitive **without messing with AIDL**.
## Android IPC through AIDL
Android supports remote IPC using [AIDL](https://developer.android.com/guide/components/aidl.html). This process of using "aidl" is painful and limited.
Some of the **problems and limitations of AIDL** are :
* Unlike the intuitive way of defining an inteface defintions as an **interface**, AIDL forces you to define the interface in an "**.aidl**" file
* The .aidl file is usually in a different folder than your normal source
* You lose most of the IDE capability for the "**.aidl**"
* You can't use an existing interface class and convert that to a remote interface -- it has to be defined seperately as ".aidl"
* Only limited predefined data types are supported in aidl
* Any custom Parcelable class that you want to pass through the interface has to be defined again as another ".aidl" file!
* No overloaded methods!- Methods with same name fail
* Can't extend an aidl with another
* Can't throw custom exceptions
## Remoter - An intuitive way for Android IPC
Remoter solves the above problems in AIDL by allowing you to define the remote interface using plain java **interface**, and implement it using plain java implementation of the interface.
All you have to do is annotate the interface using **@Remoter**
```java
@Remoter
public interface ISampleService {
...
}
```
* No messy **.aidl**, just plain simple **interface**
* Implement the interface directly using intuitive normal java way, instead of extending Stub
* **Fully interoperable with AIDL**. Remoter creates the same serialized data as created by AIDL, so it is fully interoperable with AIDL
* Supports more data types than AIDL, everything supported by [Parceler](https://github.com/johncarl81/parceler)
* Make an interface that extends other interfaces as @Remoter
* Interface methods can throw any exceptions. Clients will get the same exception that is thrown.
* Remoter interface can be templated
* Remoter is an **annotation processor** that generates two helper classes during build time -- a client side Proxy and a service side Stub that allows you to wrap your interface and implementation
* **Support kotlin coroutines!**
**At the client side**
* Simply wrap the binder that you got from the ServiceConnection with the autogenerated **Proxy** for your interface
```java
ISampleService sampleService = new ISampleService_Proxy( binder );
```
**At the service side**
* Wrap the implementation with the autogenerated **Stub** to covert it as a remote Binder and return that from your service
```java
Binder binder = new ISampleService_Stub( sampleServiceImpl );
```
That's it!
**Annotations**
* **@Remoter** Annotate on an interface to make it a remote interface
* You an also use a marker interface that can provide a list of interfaces for which to generate the Remoter Proxy/Stub classes. For this, annotate @Remoter on the marker interface and specify the list of classes for "**classesToWrap**"
```java
/**
* Example of a marker remoter interface that specifies other interfaces that should generate remoter proxy stub
* <p>
* In this case no proxy/stub gets generate for Marker, but it gets generated for IBaseA and IBaseB
*/
@Remoter(classesToWrap = {IBaseA.class, IBaseB.class})
private interface Marker {
}
```
* **@ParamIn** Mark an array or Parcelable parameter as an **input only** parameter(**in** of aidl). By **default** they are **input and output** (inout of aidl)
* **@ParamOut** Mark an array or Parcelable parameter as an **output only** parameter(**out** of aidl).
* **@Oneway** Annotate on a method (in the @Remoter interface) with void return to make it an asynchronous method.
* **@NullableType** Used to annotate a type parameter or suspend function return as nullable. See below for more details
## Kotlin Support with suspend functions
Remoter supports Kotlin interfaces with suspend functions. If your interface (marked with @Remoter) has any suspend functions, then the generated Proxy and Stub will be in Kotlin, enabling to call your remoter service method from coroutines.
* The suspend functions will be dispatched using the [Dispatcher.IO](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html) context
* Kotlin Proxy can be created using the optional constructor that accepts [IServiceConnector](http://josesamuel.com/remoter/javadoc/remoter-builder/remoter-builder/remoter.builder/-i-service-connector/index.html) which moves service connection to a suspendable coroutine
##### Kotlin Example
* Define interface in kotlin as suspend
```kotlin
@Remoter
interface ISampleService {
/**
* A suspend function which will be implemented by a service
*/
suspend fun authenticate(userName:String, password:String) : Boolean
}
```
* Include the depednecy for RemoterBuilder to take advantage of suspended service connection
```kotlin
implementation 'com.josesamuel:remoter-builder:<VERSION>'
```
* From your coroutine, call the remote service call as follows
```kotlin
//From your coroutine context -
//create service using serviceintent
val service = ISampleService_Proxy(context, SERVICE_INTENT)
//call the suspend function
val authenticated = service.authenticate(userName, password)
//The above call will
- suspend the current context
- connect to service,
- make the remote call,
all sequentially without blocking the calling thread!
```
* No need to take care of service connection!
* No need to move to background thread for service call and then to main thred to update UI!
##### Notes on Kotlin support
* Add remoter-builder dependency to get support for suspendable service connection using [IServiceConnector](http://josesamuel.com/remoter/javadoc/remoter-builder/remoter-builder/remoter.builder/-i-service-connector/index.html)
* vararg is not supported. Either use array or non suspend
* If any return is nullable type on a suspend function, explicitly mark the method with @[NullableType](https://josesamuel.com/remoter/javadoc/remoter/annotations/NullableType.html)
* If any types in a generic parameter is nullable, explicitly mnark those parameter with @[NullableType](https://josesamuel.com/remoter/javadoc/remoter/annotations/NullableType.html) optionally specifying which indexex of that type parameter are nullable
Getting Remoter
--------
Gradle dependency
```groovy
dependencies {
implementation 'com.josesamuel:remoter-annotations:2.0.6'
kapt 'com.josesamuel:remoter:2.0.5'
//If using kotlin coroutines, include following
//to make even the service connection simpler -
implementation 'com.josesamuel:remoter-builder:2.0.6'
}
```
License
-------
Copyright 2017 Joseph Samuel
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
没有合适的资源?快使用搜索试试~ 我知道了~
Remoter:Android 远程 IPC 服务的替代方案
共252个文件
java:86个
kt:48个
html:37个
需积分: 0 0 下载量 167 浏览量
2024-09-09
23:10:21
上传
评论
收藏 415KB ZIP 举报
温馨提示
在 Android 开发中,跨进程通信(IPC)是一个常见的需求。传统的 AIDL 是实现 IPC 的一种方式,但它通常被认为是复杂和难以使用的。Remoter 是一个旨在简化这一过程的库,它允许开发者通过普通的 Java 接口实现远程 IPC 服务。 Remoter 简介 Remoter 是一个开源库,由 Jose Samuel 创建,旨在为 Android 提供一种更简单的 IPC 机制。与传统的 AIDL 相比,Remoter 允许开发者使用普通的 Java 接口定义服务,而不需要编写额外的接口描述文件。 功能特点 简化 IPC:使用普通的 Java 接口定义远程服务,无需 AIDL 文件。 易于使用:简化了 IPC 的实现过程,使得开发者可以更专注于业务逻辑。 灵活性:支持多种数据类型,包括基本类型、集合和自定义对象。 性能:优化了通信过程,提供了高效的 IPC 解决方案。
资源推荐
资源详情
资源评论
收起资源包目录
Remoter:Android 远程 IPC 服务的替代方案 (252个子文件)
ISampleService.aidl 2KB
ISampleServiceListener.aidl 190B
FooParcelable.aidl 57B
gradlew.bat 2KB
stylesheet.css 13KB
style.css 4KB
.gitignore 125B
.gitignore 7B
.gitignore 7B
gradle-mvn-push.gradle 9KB
build.gradle 4KB
build.gradle 3KB
build.gradle 3KB
build.gradle 2KB
build.gradle 2KB
build.gradle 1KB
build.gradle 1005B
build.gradle 761B
settings.gradle 216B
gradlew 5KB
index-outline.html 12KB
RemoterProxy.html 11KB
index-all.html 9KB
help-doc.html 8KB
package-summary.html 7KB
RemoterProxyListener.html 7KB
RemoterStub.html 7KB
NullableType.html 7KB
ParamOut.html 6KB
ParamIn.html 6KB
Oneway.html 6KB
Remoter.html 6KB
overview-tree.html 5KB
package-tree.html 5KB
package-summary.html 5KB
index.html 5KB
package-tree.html 4KB
overview-summary.html 4KB
constant-values.html 4KB
deprecated-list.html 3KB
of.html 3KB
index.html 3KB
default.html 2KB
index.html 2KB
allclasses-frame.html 2KB
allclasses-noframe.html 1KB
package-frame.html 1KB
index.html 1KB
package-frame.html 1KB
get-service.html 1005B
get-service.html 964B
overview-frame.html 899B
disconnect-all.html 877B
disconnect.html 855B
disconnect.html 814B
index.html 790B
index.html 407B
gradle-wrapper.jar 52KB
MethodBuilder.java 34KB
RemoterClientToRemoterServerTest.java 24KB
RemoterClientToAidlServerTest.java 13KB
AIDLClientToRemoterServerTest.java 12KB
BindingManager.java 11KB
ParcelerParamBuilder.java 9KB
ClassBuilder.java 9KB
SampleServiceImpl.java 8KB
ParcellableParamBuilder.java 8KB
BinderParamBuilder.java 7KB
ListOfParcelerParamBuilder.java 7KB
FieldBuilder.java 6KB
RemoterProcessor.java 6KB
SampleServiceImpl.java 5KB
TestUnEqualClientServerInterfaces.java 4KB
ListParamBuilder.java 4KB
RemoteBuilder.java 4KB
GenericParamBuilder.java 3KB
ParamBuilder.java 3KB
CharSequenceParamBuilder.java 3KB
BooleanParamBuilder.java 3KB
StringParamBuilder.java 3KB
DoubleParamBuilder.java 3KB
FloatParamBuilder.java 3KB
CharParamBuilder.java 3KB
LongParamBuilder.java 3KB
ByteParamBuilder.java 3KB
IntParamBuilder.java 3KB
ISampleService.java 3KB
ISampleService.java 3KB
MapParamBuilder.java 3KB
VariableElementWrapper.java 3KB
ShortParamBuilder.java 2KB
package-info.java 2KB
SimpleParcelable.java 2KB
FooParcelable.java 1KB
FooParcelable.java 1KB
SampleService.java 1KB
FooParcelable.java 1KB
CustomData.java 1KB
CustomData.java 1KB
ExtEImpl.java 1KB
共 252 条
- 1
- 2
- 3
资源评论
Unity打怪升级
- 粉丝: 1w+
- 资源: 208
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功