參考PhoneWindowManager.java的adjustConfigurationLw()方法,可以找出以下關鍵因素:
config_lidKeyboardAccessibility:在frameworks/base/core/res/res/values/config.xml中定義,含義如下:
Indicate whether the lid state impacts the accessibility of the physical keyboard.
0 means it doesn't,
1 means it is accessible when the lid is open,
2 means it is accessible when the lid is closed.
The default is 1.
意爲物理鍵盤是否受滑蓋影響,0表示不受滑蓋影響,1表示當滑蓋打開時物理鍵盤可用,2表示滑蓋關閉時物理鍵盤可用。
另外PhoneWindowManager.java還有個常量也對物理鍵盤的狀態有影響:
// Debugging: set this to have the system act like there is no hard keyboard.
static final boolean KEYBOARD_ALWAYS_HIDDEN = false;
InputMethodService.java: 判斷是否顯示軟鍵盤的代碼:
onShowInputRequested() {
if (!onEvaluateInputViewShown()) {
return false;
}
......................
}
public boolean onEvaluateInputViewShown() {
Configuration config = getResources().getConfiguration();
return config.keyboard == Configuration.KEYBOARD_NOKEYS
|| config.hardKeyboardHidden == Configuration.KEYBOARDHIDDEN_YES;
}
其中兩項config.hardKeyboardHidden就是framworks中config.xml的config_lidKeyboardAccessibility取值
物理鍵盤映射過程:
手機/system/usr/keylayout/*.kl :內核將keyCode映射成有含義的字符串
KeycodeLabels.h : framework 將字符串映射成keyEvent的keyCode
frameworks/.../res/values/attrs.xml