AIDL2


Source link: https://github.com/chdir/aidl2

Branch Build Status
Master
Dev

AIDL2

Traditionally "aidl" refers to several related but distinct concepts:

  • the AIDL interface definition language;
  • .aidl files (which contain AIDL);
  • the aidl generator which transforms AIDL into client/server IPC interfaces.

This is a replacement for Google's aidl generator tool. Instead of parsing very limited DSL AIDL2 uses Java annotation processing framework to generate Java implementation, based on Java interface code. This allows you to extend from other interfaces, annotate your interface classes, use generics and other features of Java language.

AIDL2 and Android aidl tool

Unlike Google's code generator, which is implemented as standalone C++ executable, AIDL2 is an annotation processor, that is — a plugin for Java compiler. It works automatically by adding jar file to project dependencies.

Better integration with compiler gives aidl2 complete understanding of involved types. In addition to types, supported by aidl tool, AIDL2 allows use of

  • Generic Collections and Maps
  • IInterface subtypes (both from AIDL2 and aidl tool)
  • Externalizable/Serializable types
  • Multi-dimensional arrays
  • Void — ignored during (de)serialization, always evaluates to null

All generated code is human-readable and well-formatted.

You can learn more about project features in project wiki.

Current status

This project is in alpha stage. It is not nearly as well-tested as original aidl tool, but all features are there. If you decide to use it, make sure to read the generated code, to avoid any unpleasant surprises.

Usage

Add the library to project:

dependencies {

compile 'net.sf.aidl2:compiler:0.4.0' 
}

Write an interface with required methods. It must extend android.os.IInterface. Furthermore, each method must declare android.os.RemoteException to be thrown. Annotate the interface with @AIDL.

@AIDL public interface RemoteApi extends IInterface {

String sayHello() throws RemoteException; 
}

Retrive generated proxy/stub using InterfaceLoader.

Service code:

public IBinder onBind(Intent intent) {

RemoteApi serviceApi = new RemoteApi() {

  public String sayHello() {

 return "Hello world";
  
}

public IBinder asBinder() {

 return InterfaceLoader.asBinder(this, RemoteApi.class);

  
}

}
;
return serviceApi.asBinder();
 
}

Caller code:

public void onServiceConnected(ComponentName name, IBinder serviceBinder) {

try {

  final RemoteApi serviceApi = InterfaceLoader.asInterface(serviceBinder, RemoteApi.class);

 final String callResult = serviceApi.sayHello();

Toast.makeText(this, "Received message \"" + callResult + '"', Toast.LENGTH_SHORT).show();

}
 catch (RemoteException e) {

  Toast.makeText(this, "Service error: " + e.getMessage(), Toast.LENGTH_SHORT).show();

}
 
}

Defining an interface

You can specify any number of parameters, including varargs. Parameters and return values must be of types, supported by android.os.Parcel as well as extra types, listed above. You can use tricky generic types if you want, but make sure, that those can be interpreted as one of supported types:

@AIDL public interface RemoteApi extends IInterface {

<T extends Runnable> void exampleMethod(T runnableParameter) throws RemoteException; 
}

will fail to compile with error, because Parcel does not support Runnables.

@AIDL public interface RemoteApi extends IInterface {

<T extends Runnable & Parcelable> T exampleMethod() throws RemoteException; 
}

will compile and generate code, using writeParcelable and readParcelable to pass "runnableParameter" between processes.

@AIDL public interface RemoteApi extends IInterface {

  void exampleMethod(Date[] dateArray) throws RemoteException; 
}

will compile and use readSerializable and writeSerializable to passs "dateArray" between processes.

Other documentation

Read project wiki for in-depth documentations and some useful links.

Resources

This project allows to create pretty sticker views.

Periscope like HeartLayout.

This library adds a layer on top of SQLBrite by providing basically two modules:

  • ObjectMapper
  • Dao

BusyIndicator is a progress indicator with determined and indeterminate state.

Fast Access (Floating Toolbox)

A simple Android library to create Debugging menu.

Debot offers features that are useful to debug Android applications. Those features can be added to any activity that has the toolbar menu. Also, developers can easily add their own custom debugging features with simple steps.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes