AIDL File: ILights.aidl
package android.hardware.light;
import android.hardware.light.HwLightState;
import android.hardware.light.HwLight;
/**
* Allows controlling logical lights/indicators, mapped to LEDs in a
* hardware-specific manner by the HAL implementation.
*/
@VintfStability
interface ILights {
/**
* Set light identified by id to the provided state.
*
* If control over an invalid light is requested, this method exists with
* EX_UNSUPPORTED_OPERATION. Control over supported lights is done on a
* device-specific best-effort basis and unsupported sub-features will not
* be reported.
*
* @param id ID of logical light to set as returned by getLights()
* @param state describes what the light should look like.
*/
void setLightState(in int id, in HwLightState state);
/**
* Discover what lights are supported by the HAL implementation.
*
* @return List of available lights
*/
HwLight[] getLights();
}
ILights的类结构
ILights.java是个 Interface class, 其中包含了内部类Sub, 而Proxy又是Sub的内部类,Sub和Proxy都 implement ILights接口,但Proxy没有继承Binder, Proxy是通过成员变量mRemote去请求服务。
代理类的创建肯定要得到Stub的应用,Proxy接口函数的实现通过mRemote.transact(Stub.TRANSACTION_setLightState, _data, _reply, 0) 调用到 Stub的实现, 这是标准的Client/Server架构和 代理设计模式
// 因为可能跨进程传输(即使不跨进程)也要进行打包解包(编解码)防止数据传输过程错误
@Override
public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
{
java.lang.String descriptor = DESCRIPTOR;
switch (code)
{
case TRANSACTION_setLightState:
{
data.enforceInterface(descriptor);
int _arg0;
_arg0 = data.readInt();
android.hardware.light.HwLightState _arg1;
if ((0!=data.readInt())) {
_arg1 = android.hardware.light.HwLightState.CREATOR.createFromParcel(data);
}
else {
_arg1 = null;
}
this.setLightState(_arg0, _arg1); // server端去完成接口具体的实现
reply.writeNoException();
return true;
}
}
生成的ILights.java
/*
* This file is auto-generated. DO NOT