Android AIDL生成的文件

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值