android hal aidl升级部分-android framework车载手机系统开发

背景:

第一版本的aidl没有指定版本,只有一个aidl_api下面current文件夹即默认就是版本v1,那么如果后面有相关的接口修改呢?
那么应该怎么办,怎么操作?

修改aidl

在修改接口前记得把老版本的aidl进行冻结一下
冻结命令:
m android.hardware.mytest-freeze-api
执行后相关的aidl_api目录多个一个版本目录
在这里插入图片描述

可以看到这里的版本多了版本1,而且还带有hash号文件

接下来既可以修改aidl文件了

package android.hardware.mytest; 
import android.hardware.mytest.MyTestObj; 
@VintfStability 
interface IMyTest {
    MyTestObj test();
    void addTest(int a,int b); //增加了一个接口方法
}



注意这里修改aidl接口也不是随意修改的哈,官方有相关要求:

In addition, you need to manage ToT version's API definition. Whenever an API is updated, run foo-update-api to update aidl_api/name/current which contains ToT version's API definition.

To maintain the stability of an interface, owners can add new:

Methods to the end of an interface (or methods with explicitly defined new serials)
Elements to the end of a parcelable (requires a default to be added for each element)
Constant values
In Android 11, enumerators
In Android 12, fields to the end of a union
No other actions are permitted, and no one else can modify an interface (otherwise they risk collision with changes that an owner makes).

大概就是修改时候一定要考虑老版本的兼容问题,一般不删除原来接口和修改
然后执行命令:

m android.hardware.mytest-update-api

可以看到out临时文件目录多了V2相关的库

test@test:~/nx563j_xiaomi/out/soong/.intermediates/hardware/interfaces/mytest/aidl$ ll
total 40
drwxrwxr-x 10 test test 4096 Dec 13 20:57 ./
drwxrwxr-x  3 test test 4096 Dec 13 20:57 ../
drwxrwxr-x  4 test test 4096 Dec 13 20:57 android.hardware.mytest-V1-ndk/
drwxrwxr-x  3 test test 4096 Dec 13 20:57 android.hardware.mytest-V1-ndk-source/
drwxrwxr-x  4 test test 4096 Dec 13 20:57 android.hardware.mytest-V2-ndk/
drwxrwxr-x  3 test test 4096 Dec 13 20:57 android.hardware.mytest-V2-ndk-source/

修改实现代码的和android.bp

MyTestImpl.h增加相关方法引入

class MyTestImpl : public BnMyTest {
  public:
    ::aidl::android::hardware::mytest::MyTestObj  mObj = {"hello",1};
    ::ndk::ScopedAStatus test(::aidl::android::hardware::mytest::MyTestObj* _aidl_return) override;
    ::ndk::ScopedAStatus addTest(int32_t in_a, int32_t in_b) override;

};

MyTestImpl.cpp增加相关方法实现


namespace aidl::android::hardware::mytest {
    
::ndk::ScopedAStatus MyTestImpl::test(::aidl::android::hardware::mytest::MyTestObj* _aidl_return) {
        *_aidl_return = mObj;
        ALOGE(" MyTestImpl::test ok");
        return ::ndk::ScopedAStatus::ok();
}
  ::ndk::ScopedAStatus  MyTestImpl::addTest(int32_t in_a, int32_t in_b) {
        ALOGE(" MyTestImpl::test ok a %d  b %d",in_a,in_b);
        return ::ndk::ScopedAStatus::ok();
  }


}  // namespace aidl::android::hardware::mytest

Android.bp需要把原来V1版本的库变成V2
在这里插入图片描述
本文章对应视频手把手教你学framework:
https://mp.weixin.qq.com/s/LbVLnu1udqExHVKxd74ILg

私聊作者+v(androidframework007)

点击这里 https://mp.weixin.qq.com/s/Qv8zjgQ0CkalKmvi8tMGaw

视频:https://www.bilibili.com/video/BV1wc41117L4/
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值