2025年08.音频系统-第003课_Linux音频驱动程序-第002节_在状态栏显示耳麦图标

08.音频系统-第003课_Linux音频驱动程序-第002节_在状态栏显示耳麦图标在上小节编写了一个耳麦插拔的驱动程序 按理说接上耳麦的时候 我们应该声音通道 让声音从耳机中输出出来 我们需改修改一下源代码 让他在状态栏显示耳麦的图标 我们需要做以下事情 1 确定在状态栏上图标的位置 2 创建图标文件 3 修改源代码 当接受到消息时 显示或者清除图标 4

大家好,我是讯享网,很高兴认识大家。

在上小节编写了一个耳麦插拔的驱动程序,按理说接上耳麦的时候,我们应该声音通道,让声音从耳机中输出出来,我们需改修改一下源代码,让他在状态栏显示耳麦的图标。我们需要做以下事情:
1.确定在状态栏上图标的位置
2.创建图标文件
3.修改源代码,当接受到消息时,显示或者清除图标
4.编译文件,然后替换单板的源文件。

修改文件frameworks\base\core\res\res\values\config.xml

 <item><xliff:g id="id">@string/status_bar_secure</xliff:g></item> <item><xliff:g id="id">@string/status_bar_clock</xliff:g></item> + <item><xliff:g id="id">@string/status_bar_headset</xliff:g></item> </string-array> 

讯享网

在55行添加代码<xliff:g id=“id”>@string/status_bar_headset</xliff:g>,这个是用来确定图标的位置的,源码中有注释:

讯享网 <!-- Do not translate. Defines the slots for the right-hand side icons. That is to say, the icons in the status bar that are not notifications. --> 

然后打开frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\PhoneStatusBarPolicy.java文件添加如下代码:


讯享网

 } else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) { 
    updateTTY(intent) + } else if (action.equals(Intent.ACTION_HEADSET_PLUG)) { 
    + updateHeadset(intent); }else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) || filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE); filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED); + filter.addAction(Intent.ACTION_HEADSET_PLUG); mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); } else { 
    // TTY is off if (DEBUG) Log.v(TAG, "updateTTY: set TTY off"); mIconController.setIconVisibility(mSlotTty, false); } } + private final void updateHeadset(Intent intent) { 
    + final String action = intent.getAction(); + final int state = intent.getIntExtra("state", 4); + final int mic = intent.getIntExtra("microphone", 4); + switch (state) { 
    + case 0: + mService.setIconVisibility("headset", false); + break; + case 1: + if (mic == 1) { 
    + mService.setIcon("headset", R.drawable.stat_sys_headset_with_mic, null); + } else { 
    + mService.setIcon("headset", R.drawable.stat_sys_headset_without_mic, null); + } + mService.setIconVisibility("headset", true); + break; + } + } private void updateCast() { 
    boolean isCasting = false; 

修改完成之后,执行:
mmm frameworks/base/core/res // 编译config.xml
得到 out/target/product/tiny4412/system/framework/framework-res.apk
mmm frameworks/base/packages/SystemUI // 编译图标文件, 编译源码
得到 out/target/product/tiny4412/system/priv-app/SystemUI/SystemUI.apk

重新烧写system.img文件之后,使用一下命令测试:

测试
触发上报headset插入: echo 4 1 > /sys/class/input/input0/test_input
触发上报headset取下: echo 4 0 > /sys/class/input/input0/test_input
触发上报headphone插入: echo 2 1 > /sys/class/input/input0/test_input
触发上报headphone取下: echo 2 0 > /sys/class/input/input0/test_input
触发上报lineout插入: echo 6 1 > /sys/class/input/input0/test_input
触发上报lineout取下: echo 6 0 > /sys/class/input/input0/test_input

小讯
上一篇 2025-03-26 16:30
下一篇 2025-01-17 21:42

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/15223.html