CHRE: hardware/interfaces/contexthub/1.0

该路径下包含:

hal文件:IContexthub, IContexthubCallback 和type.hal

其中Ixxx类型的hal文件会生成文件interface, 实现interface的service/ client, type.hal生成进程传输的对应数据处理的文件。

对Ixx文件生成:

public interface Ixxx extends android.hidl.base.V1_0.IBase {

  public static final class Proxy implements Ixxx{}
  public static abstract class Stub extends android.os.HwBinder implements Ixxx{}

}

abstract class说的什么,需要实现abstract的接口才能使用?

final class意思是说这个类可以被实例化,而abstract不行?

从该目录下的Android.bp得知srcs:被处理的源文件,生成接口的名字由name决定 基于Ixxx对应的接口生成了实现该接口的Client/Service, 但该Service现在还是abstract的?

android.hardware.contexthub@1.0::IContexthub, android.hardware.contexthub@1.0::IContexthubCallback

hidl_interface {
    name: "android.hardware.contexthub@1.0",
    root: "android.hardware",
    vndk: {
        enabled: true,
    },
    srcs: [
        "types.hal",
        "IContexthub.hal",
        "IContexthubCallback.hal",
    ],
    interfaces: [
        "android.hidl.base@1.0",
    ],
    types: [
        "AsyncEventType",
        "ContextHub",
        "ContextHubMsg",
        "HostEndPoint",
        "HubAppInfo",
        "HubMemoryFlag",
        "HubMemoryType",
        "MemRange",
        "NanoAppBinary",
        "NanoAppFlags",
        "PhysicalSensor",
        "Result",
        "SensorType",
        "TransactionResult",
    ],
    gen_java: true,
}

IContexthub.hal

/**
 * context hub hal提供了和低功耗DSP交互的接口
 * The Context Hub HAL provides an interface to a separate low-power processing
 * domain that has direct access to contextual information, such as sensors.
 * nanoapps运行在CHRE中、低功耗DSP中
 * Native applications that run within a context hub are known as nanoapps, and
 * they execute within the Context Hub Runtime Environment (CHRE), which is
 * standardized via the CHRE API, defined elsewhere.
 */
interface IContexthub {
    /**支持CHRE的低功耗DSP,可以有多个
     * Enumerate all available context hubs on the system.
     */
    getHubs() generates (vec<ContextHub> hubs);

    /**
     * Register a callback for the HAL implementation to send asynchronous
     * messages to the service from a context hub. There can be a maximum of
     * one callback registered with the HAL. A call to this function when a
     * callback has already been registered must override the previous
     * registration.
     */
     registerCallback(uint32_t hubId, IContexthubCallback cb) generates (Result result);

    /**
     * Send a message to a hub
     */
    sendMessageToHub(uint32_t hubId, ContextHubMsg msg)
            generates (Result result);

    /**
     * Loads a nanoApp. After loading, the nanoApp's init method must be called.
     * After the init method for nanoApp returns success, this must be indicated
     * to the service by an asynchronous call to handleTxnResult.
     *
     * Loading a nanoapp must not take more than 30 seconds.
     */
    loadNanoApp(uint32_t hubId,NanoAppBinary appBinary,
                uint32_t transactionId)
            generates (Result result);

    /**
     * Unloads a nanoApp. Before the unload, the apps deinit method is called.
     * After this, success must be indicated to the service through an
     * asynchronous call to handleTxnResult.
     *
     * Unloading a nanoapp must not take more than 5 seconds.
     */
    unloadNanoApp(uint32_t hubId, uint64_t appId, uint32_t transactionId)
            generates (Result result);

    /**
     * Enables a nanoApp. The app's init method is called.
     * After this, success must be indicated to the service through an
     * asynchronous message.
     */
    enableNanoApp(uint32_t hubId, uint64_t appId, uint32_t transactionId)
            generates (Result result);

    /**
     * Disables a nanoApp. The app's deinit method is called.
     * After this, success must be indicated to the service through an
     * asynchronous message.
     * Disabling a nanoapp must not take more than 5 seconds.
     */
    disableNanoApp(uint32_t hubId, uint64_t appId, uint32_t transactionId)
            generates (Result result);

    /**
     * Queries for Loaded apps on the hub
     */
    queryApps(uint32_t hubId) generates (Result result);
};

编译hal的android.bp

hidl_interface {
    name: "android.hardware.contexthub@1.0",
    root: "android.hardware",
    vndk: {
        enabled: true,
    },
    srcs: [
        "types.hal",
        "IContexthub.hal",
        "IContexthubCallback.hal",
    ],
    interfaces: [
        "android.hidl.base@1.0",
    ],
    types: [
        "AsyncEventType",
        "ContextHub",
        "ContextHubMsg",
        "HostEndPoint",
        "HubAppInfo",
        "HubMemoryFlag",
        "HubMemoryType",
        "MemRange",
        "NanoAppBinary",
        "NanoAppFlags",
        "PhysicalSensor",
        "Result",
        "SensorType",
        "TransactionResult",
    ],
    gen_java: true,
}

生成的文件 IContexthub.java

public interface IContexthub extends android.hidl.base.V1_0.IBase {
    public static final String kInterfaceName = "android.hardware.contexthub@1.0::IContexthub";

    /* package private */ static IContexthub asInterface(android.os.IHwBinder binder) {
    }

    @Override
    public android.os.IHwBinder asBinder();

    public static IContexthub getService(String serviceName, boolean retry) {
    }

         xxxxx

    public static final class Proxy implements IContexthub{}     
    public static abstract class Stub extends android.os.HwBinder implements IContexthub{}

}

IContexthubCallback.hal

callback is passed by the Contexthub service to the HAL implementation to allow the HAL to send asynchronous messages back to serive

interface IContexthubCallback {
    /**
     * This callback is passed by the Contexthub service to the HAL
     * implementation to allow the HAL to send asynchronous messages back
     * to the service and registered clients of the ContextHub service.
     */
     handleClientMsg(ContextHubMsg msg);

    /**
     * This callback is passed by the Contexthub service to the HAL
     * implementation to allow the HAL to send the response for a
     * transaction.
     */
     handleTxnResult(uint32_t txnId, TransactionResult result);

    /**
     * This callback is passed by the Contexthub service to the HAL
     * implementation to allow the HAL to send an asynchronous event
     * to the ContextHub service.
     */
     handleHubEvent(AsyncEventType evt);

    /**
     * This callback is passed by the Contexthub service to the HAL
     * implementation to allow the HAL to send a notification to the service
     * that a nanp-app has aborted.
     * This method must be called when a nanoapp invokes chreAbort(...)).
     */
     handleAppAbort(uint64_t appId, uint32_t abortCode);

     /**
      * This callback is passed by the Contexthub service to the HAL
      * implementation to allow the HAL to send information about the
      * currently loaded and active nanoapps on the hub.
      */
      handleAppsInfo(vec<HubAppInfo> appInfo);
};

calback是service passed by serive to HAL implement to allow HAL send a  message to service为什么还是实现成client/server的形式?  

client睡眠等待server回应(调用注册callback后)

public interface IContexthubCallback extends android.hidl.base.V1_0.IBase {
上面的接口:client/server都要实现

public static abstract class Stub extends android.os.HwBinder implements IContexthubCallback{
public void onTransact(int _hidl_code, android.os.HwParcel _hidl_request, final android.os.HwParcel _hidl_reply, int _hidl_flags)
        throws android.os.RemoteException {
    switch (_hidl_code) {
        case 1 /* handleClientMsg */:
        {
          
android.hardware.contexthub.V1_0.ContextHubMsg msg = new android.hardware.contexthub.V1_0.ContextHubMsg();
            msg.readFromParcel(_hidl_request);
            handleClientMsg(msg);
            _hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);
            _hidl_reply.send();
            break;
        }

};
public static final class Proxy implements IContexthubCallback {
public void handleClientMsg(android.hardware.contexthub.V1_0.ContextHubMsg msg){
    android.os.HwParcel _hidl_request = new android.os.HwParcel();
    _hidl_request.writeInterfaceToken(android.hardware.contexthub.V1_0.IContexthubCallback.kInterfaceName);
    msg.writeToParcel(_hidl_request);

    android.os.HwParcel _hidl_reply = new android.os.HwParcel();
    try {
        mRemote.transact(1 /* handleClientMsg */, _hidl_request, _hidl_reply, 0 /* flags */);
        _hidl_reply.verifySuccess();
        _hidl_request.releaseTemporaryStorage();
    }
}

}

请用实例说明下callback的调用过程,需要先注册?

type.hal

进程间传输的数据类型,生成对应的类

struct NanoAppBinary {
    uint64_t appId;            // Nanoapp identifier
    uint32_t appVersion;       // Version of the app (semantics defined by app)
    bitfield<NanoAppFlags> flags;

    // The version of the CHRE API that this nanoApp was compiled against. See
    // the CHRE API header file chre/version.h for more information. The hub
    // implementation must use this to confirm compatibility before loading
    // this nanoApp.
    uint8_t targetChreApiMajorVersion;
    uint8_t targetChreApiMinorVersion;

    // Implementation-specific binary nanoapp data. This does not include the
    // common nanoapp header that contains the app ID, etc., as this data is
    // explicitly passed through the other fields in this struct.
    vec<uint8_t> customBinary;
};
NanoAppBinary.java
public final class NanoAppBinary {
    public long appId;
    public int appVersion;
    public int flags;
    public byte targetChreApiMajorVersion;
    public byte targetChreApiMinorVersion;
    public final java.util.ArrayList<Byte> customBinary = new java.util.ArrayList<Byte>();
public final void readFromParcel(android.os.HwParcel parcel) {
    android.os.HwBlob blob = parcel.readBuffer(40/* size */);
    readEmbeddedFromParcel(parcel, blob, 0 /* parentOffset */);
}
public final void readEmbeddedFromParcel(
        android.os.HwParcel parcel, android.os.HwBlob _hidl_blob, long _hidl_offset) {
    appId = _hidl_blob.getInt64(_hidl_offset + 0);
    appVersion = _hidl_blob.getInt32(_hidl_offset + 8);
    flags = _hidl_blob.getInt32(_hidl_offset + 12);
    targetChreApiMajorVersion = _hidl_blob.getInt8(_hidl_offset + 16);
    targetChreApiMinorVersion = _hidl_blob.getInt8(_hidl_offset + 17);
    {
        int _hidl_vec_size = _hidl_blob.getInt32(_hidl_offset + 24 + 8 /* offsetof(hidl_vec<T>, mSize) */);
        android.os.HwBlob childBlob = parcel.readEmbeddedBuffer(
                _hidl_vec_size * 1,_hidl_blob.handle(),
                _hidl_offset + 24 + 0 /* offsetof(hidl_vec<T>, mBuffer) */,true /* nullable */);

        customBinary.clear();
        for (int _hidl_index_0 = 0; _hidl_index_0 < _hidl_vec_size; ++_hidl_index_0) {
            byte _hidl_vec_element;
            _hidl_vec_element = childBlob.getInt8(_hidl_index_0 * 1);
            customBinary.add(_hidl_vec_element);
        }
    }
}

 

 

         

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值