实现P931项目蓝牙键盘静音键功能以及打印F1,F2键信息打印 准备工作: 1.下载android4.0.3系统 git clone gitolite@scm:vc0882/sdk_4.0 (使用git pull可以更新本地文件) 2.修改代码 修改思路:Android已经定义了比较丰富、完整的标准按键。在一般情况下,不需要为Android系统增加按键,只需要根据kl配置按键即可。在系统中有比较奇特按键的时候,需要更改Android系统的框架层来更改按键。 底层驱动已经实现相应按键驱动。 1>.kernel/include/linux/input.h 察看F1,F2,MUTE按键映射到Linux的值 #define KEY_MUTE113 #define KEY_F1 59 #define KEY_F2 60 #define KEY_BRIGHTNESSDOWN 224 #define KEY_BRIGHTNESSUP 225 2>.frameworks/base/data/keyboards/qwerty.kl 将1中查到的的值添加到配置文件qwerty.kl中,以便映射到上层应用 add by huanggenda key 60 F2 key 61 F3 key 113 MUTE key 0x1d0 FN key 224 BRIGHTNESSDOWN key 225 BRIGHTNESSUP #the end by huanggenda 3>.framework/core/res/res/values/attrs.xml 此文件为linux映射到应用的值,以供应用程序调用 <enum name="KEYCODE_F1" value="131" /> <enum name="KEYCODE_F2" value="132" /> <enum name="KEYCODE_VOLUME_MUTE" value="164" /> <!--add by huanggenda--> <enum name="KEY_BRIGHTNESSDOWN" value="211" /> <enum name="KEY_BRIGHTNESSUP" value="212" /> <!--the end add by huanggenda--> 4>.在framework/base/policy/src/com/android/impl/PhoneWindowManager.java 按键code察看调试: //modify false to true for debug if (true) { Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed); } //The function of F2 and F1 add by huanggenda if(keyCode == KeyEvent.KEYCODE_F2) Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " F2"); if(keyCode == KeyEvent.KEYCODE_F3) Log.d(TAG, "interceptKeyTi keyCode=" + keyCode +" F3"); if(keyCode == KeyEvent.KEYCODE_BRIGHTNESSDOWN) Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " BRIGHTNESSDOWN"); if(keyCode == KeyEvent.KEYCODE_BRIGHTNESSUP) Log.d(TAG, "interceptKeyTi keyCode=" + keyCode +" BRIGHTNESSUP"); //The end by huanggenda 5>.framework/base/media/java/android/media/AudioManager.java 处理音量键方法: /** * @hide */ public void handleKeyDown(int keyCode, int stream) { boolean mute = isStreamMute(AudioManager.STREAM_MUSIC); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: /* * * if audio is mute, turn off mute. * Add by huanggenda * */ if (mute) { setStreamMute(AudioManager.STREAM_MUSIC, false); int volume = getStreamVolume(AudioManager.STREAM_MUSIC); if (volume == 0) { if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { setStreamMute(AudioManager.STREAM_MUSIC, true); break; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { setStreamMute(AudioManager.STREAM_SYSTEM, false); setStreamMute(AudioManager.STREAM_NOTIFICATION, false); } } else { setStreamMute(AudioManager.STREAM_SYSTEM, false); setStreamMute(AudioManager.STREAM_NOTIFICATION, false); adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI); break; } } /* The end to add by huanggenda */ /* * Adjust the volume in on key down since it is more * responsive to the user. */ int flags = FLAG_SHOW_UI | FLAG_VIBRATE; if (mVolumeControlStream != -1) { stream = mVolumeControlStream; flags |= FLAG_FORCE_STREAM; } adjustSuggestedStreamVolume( keyCode == KeyEvent.KEYCODE_VOLUME_UP ? ADJUST_RAISE : ADJUST_LOWER, stream, flags); /* * * If the volume is 0, turn on mute. * Add by huanggenda * */ if (stream == AudioManager.STREAM_MUSIC) { int v = getStreamVolume(AudioManager.STREAM_MUSIC); mute = isStreamMute(AudioManager.STREAM_MUSIC); if (!mute && (v == 0)) { setStreamMute(AudioManager.STREAM_SYSTEM, true); setStreamMute(AudioManager.STREAM_MUSIC, true); setStreamMute(AudioManager.STREAM_NOTIFICATION, true); adjustStreamVolume(stream, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI); } } /* The end to add by huanggenda */ break; case KeyEvent.KEYCODE_VOLUME_MUTE: // TODO: Actually handle MUTE. mute = !mute; setStreamMute(AudioManager.STREAM_SYSTEM, mute); setStreamMute(AudioManager.STREAM_MUSIC, mute); setStreamMute(AudioManager.STREAM_NOTIFICATION, mute); adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI); break; } } 3.编译系统 . build/envsetup.sh lunch 3 (android4.0.1是10,android4.0.3是4) make clean make 4.系统烧录工具, nand_tool_new,packet_tool_4.0,这两个工具是由中星微原厂提供,使用方法: 步骤一:运行packet_tool_4.0中Vortexpacket.exe,加载ubi.cache8k_256_2048.img,ubi.data8k_256_2048.img,ubi.system8k_256_2048.img,ubi.userdata8k_256_2048.img四个文件,这四个文件在out/target/product/vortex/8k_256_2048/ 目录下,然后点击转换按钮进行转换生成vortex.pak文件 步骤二:运行 nand_tool_new中MPTool.exe,设置vortex.pak路径,再扫描设备,在下载系统就可以了。
参考:http://blog.csdn.net/huanggenda568/article/details/7477891