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

在上小节编写了一个耳麦插拔的驱动程序,按理说接上耳麦的时候,我们应该声音通道,让声音从耳机中输出出来,我们需改修改一下源代码,让他在状态栏显示耳麦的图标。我们需要做以下事情:
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

猜你喜欢

转载自blog.csdn.net/weixin_43013761/article/details/89641677
今日推荐