Android 14 CarAudioService

文章目录

新功能

  • AudioMirring

简单的说就是两个bus输出的是同一个音频数据。

构建的流程是: 一个输入src的bus,和两个输出dst的bus。 通过setParamter 设置到hal。 hal解析这些参数,将输入bus

的音频数据拷贝输出到两个dst的bus。

  • CarOemService

可以外部注册对应的carAudioFocusService、CarAudioVolumeService、CarAudioDuckingService.

分别为焦点请求,音量设置、音频闪避。

也就是oem 根据自己的需要去控制这三个方面的音频功能。

当有定义这三个service的时候,相应的处理会调用到对应的服务。 调用过程是基于binder 的 是需要IPC调用。

这一部处理是在java层处理。

  • 对于按键的处理

新增了CarInputService, 可以通过监听不同的InputService 来处理按键。 补齐了12上面无法多屏幕按键控制。

这个按键需要OEM 自己定义 通过vhal hal 上报到CarInputService。 然后audio这边去监听相关的按键事件。

vehicle hal中可以携带三个参数 是int类型的数组

第一个参数 是按键事件的代码 1001 - 1007

第二个是屏幕 可以主屏副屏等等。音量调节的时候 可以从这个display ID 获取zoneID。

AudioMirring

  • 如何配置mirror的区域
    • mirror的工作原理

首先在配置文件中添加的配置为, 在carAudioService 中进行标签的解析,然后设置mirror的device。

复制代码
    <mirroringDevices>
        <mirroringDevice address="mirror_bus_device_1"/>
        <mirroringDevice address="mirror_bus_device_2"/>
    </mirroringDevices>
  • 基本的原理:

    在CarService 这一层是构造类似下面这样的keyvalue序列,然后这个序列通过AudioManager的setParameters给到hal。

    mirroring_src=bus_1000;mirroring_dest=bus_10,bus_20.

    而上述的keyValue 序列是要求hal层 实现所有写入到mirroring_src bus的数据 都要拷贝到bus_10 和bus_20进行输出。其中bus_10 和 bus_20是需要在zondID 中进行定义的,是已经有的输出设备。

详细来说: 首先解析xml中mirroringDevice,这个device 同时也需要在audio_policy_configuration.xml中定义。 跟正常的device address一样。在CarService 中

  1. 判断是不是支持mirror(通过判断mirroringDevice是不是至少有一个存在),支持的话,构造一个mix,将这个mix添加到audioPolicy当中。
  2. 构造mix,这个mix 的device是mirroringDevice,attribute是music。现有只支持music类型共享。mix添加到audiopolicy 说明 后续的音频
    数据通过mix线程都会写到mirror的device address。
  3. 构造parameter 参数列表(怎么构建的?)外部的接口是
    enableMirrorForAudioZones,传递的参数是需要mirror的zone id列表。carAudioService 中会经过一系列的判断确认zoneID可用时,
    通过zoneId来获取USAGE_MEDIA的DeviceAddress。
    然后将mirrorDevice 和 获取到的DeviceAddress 组成paramter传递给hal。
  • Hal 层的实现

    在有paramete的情况下。解析获取mirror src dst的address。 但不是打开的src的address,而是打开dst的address。

    然后将数据分别写入到这两个地址中。mirror的src相当于一个中转的地址。

oemCarService

  • oemCarService的作用

使用一个app的service 替换原生的focusrequest、duck和volume。

复制代码
    private OemCarAudioFocusResult evaluateFocusRequestLocked(FocusEntry replacedCurrentEntry,
            AudioFocusInfo audioFocusInfo) {
        return isExternalFocusEnabled()
                ? evaluateFocusRequestExternallyLocked(audioFocusInfo, replacedCurrentEntry) :
                evaluateFocusRequestInternallyLocked(audioFocusInfo, replacedCurrentEntry);
    }
  • 如何启用

配置应用的的名字。比如想用 test的这个com.android.car.oemcarservice.testapp.OemCarServiceImpl

将名字config 到xml,然后编译这个应用 push到system/priv-app目录底下。

复制代码
String componentName = res.getString(R.string.config_oemCarService);

        Intent intent = (new Intent())
                .setComponent(ComponentName.unflattenFromString(mComponentName));
        Slogf.i(TAG, "Binding to Oem Service with intent: %s", intent);
        mHandlerThread = CarServiceUtils.getHandlerThread("car_oem_service");
        mHandler = handler == null ? new Handler(mHandlerThread.getLooper()) : handler;
        mIsOemServiceBound = mContext.bindServiceAsUser(intent, mCarOemServiceConnection,
                Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT, UserHandle.SYSTEM);


    private boolean isExternalFocusEnabled() {
        CarOemProxyService proxy = CarLocalServices.getService(CarOemProxyService.class);
        if (!proxy.isOemServiceEnabled()) {
            return false;
        }
        if (!proxy.isOemServiceReady()) {
            logFocusEvent("Focus was called but OEM service is not yet ready.");
            return false;
        }
        return proxy.getCarOemAudioFocusService() != null;
    }
  • 如何调用

    bindServiceAsUser的作用是什么?https://bbs.huaweicloud.com/blogs/325746

    • 客户端服务端都继承.stub.

    • 服务端实现具体的AIDL接口,主要是下面的这些接口。

      复制代码
          IOemCarAudioFocusService getOemAudioFocusService();
          IOemCarAudioVolumeService getOemAudioVolumeService();
          IOemCarAudioDuckingService getOemAudioDuckingService();
    • 在配置config中国oemCarService 后,现有的实现是packages/services/Car/tests/OemCarServiceTestApp/src/com/android/car/oemcarservice/testapp/OemCarServiceImpl.java。

    • 客户端获取服务, 通过package的名字构造一个intent,然后bindServiceAsUser。发送intent

      在onServiceConnected 通过binder获取到远程的mOemCarService。外部通过getService

      的方式获取CarOemProxyService的服务。 然后通过这个服务调用HIDL的接口。

      复制代码
           CarOemProxyService proxy = CarLocalServices.getService(CarOemProxyService.class);
           public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
              Slogf.i(TAG, "onServiceConnected: %s, %s", componentName, iBinder);
              synchronized (mLock) {
                  if (mOemCarService == IOemCarService.Stub.asInterface(iBinder)) {
                      return; // already connected.
                  }
                  Slogf.i(TAG, "car oem service binder changed, was %s now: %s",
                          mOemCarService, iBinder);
                  mOemCarService = IOemCarService.Stub.asInterface(iBinder);
                  Slogf.i(TAG, "**CarOemService connected**");
                  mIsOemServiceConnected = true;
                  mLock.notifyAll();
              }
          }
  • 如何配置

  1. 在config.xml 中配置componet name

    com.android.car.oemcarservice.testapp/com.android.car.oemcarservice.testapp.OemCarServiceImpl

    componet name 根据app的package和service name一起组成的。

    形式为package name/service name 这两个名字可以从源码的AndroidManifest.xml中获取到。

  2. 编译carService 和 test app push 到system/priv_app即可。

    复制代码
     <!-- This is the component name for the OEM customization service. OEM can choose to implement
          this service to customize car service behavior for different policies. If OEMs choose to
          implement it, they have to implement a service extending OemCarService exposed by car-lib,
          and implement the needed component services.
          If the component name is invalid, CarService would not connect to any OEM service.
          Component name can not be a third party package. It should be pre-installed -->
    <string name="config_oemCarService" translatable="false">com.android.car.oemcarservice.testapp/com.android.car.oemcarservice.testapp.OemCarServiceImpl</string>

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.car.oemcarservice.testapp">
    <uses-permission android:name="android.car.permission.CAR_CONTROL_AUDIO_SETTINGS" />
    <uses-permission android:name="android.car.permission.CAR_CONTROL_AUDIO_VOLUME" />
    <application>
    <service android:name="com.android.car.oemcarservice.testapp.OemCarServiceImpl" android:directBootAware="true" android:permission="android.car.permission.BIND_OEM_CAR_SERVICE" android:exported="true">
    </service>
    </application>
    </manifest>

相关推荐
哲科软件37 分钟前
跨平台开发的抉择:Flutter vs 原生安卓(Kotlin)的优劣对比与选型建议
android·flutter·kotlin
DuelCode1 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
优创学社21 小时前
基于springboot的社区生鲜团购系统
java·spring boot·后端
幽络源小助理1 小时前
SpringBoot基于Mysql的商业辅助决策系统设计与实现
java·vue.js·spring boot·后端·mysql·spring
猴哥源码1 小时前
基于Java+springboot 的车险理赔信息管理系统
java·spring boot
YuTaoShao2 小时前
【LeetCode 热题 100】48. 旋转图像——转置+水平翻转
java·算法·leetcode·职场和发展
Dcs2 小时前
超强推理不止“大”——手把手教你部署 Mistral Small 3.2 24B 大模型
java
东阳马生架构2 小时前
订单初版—1.分布式订单系统的简要设计文档
java
Code blocks3 小时前
使用Jenkins完成springboot项目快速更新
java·运维·spring boot·后端·jenkins
荔枝吻3 小时前
【沉浸式解决问题】idea开发中mapper类中突然找不到对应实体类
java·intellij-idea·mybatis