问题现象:连接蓝牙设备会提示配置键盘
问题分析:刚开始测试说android11存在这个问题,android10没有。
再android10上通知的地方打log看
通知必走的地方
NotificationManagerService 发现是被我们屏蔽了,问题就清楚了 不是平台差异的问题
void enqueueNotificationInternal(final String pkg, final String opPkg, final int callingUid,
final int callingPid, final String tag, final int id, final Notification notification,
int incomingUserId) {
}
回到问题 InputManagerService 输入服务
设备添加的流程
EventHub.cpp
status_t EventHub::openDeviceLocked(const char* devicePath) {
char buffer[80];// 'Q' key support = cheap test of whether this is an alpha-capable kbd
if (hasKeycodeLocked(device, AKEYCODE_Q)) {//xuanyutag 外接键盘设备标识
device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
}
InputReader.cpp
if (classes & INPUT_DEVICE_CLASS_ALPHAKEY) { INPUT_DEVICE_CLASS_ALPHAKEY =2
keyboardType = AINPUT_KEYBOARD_TYPE_ALPHABETIC; =2 也就是外接键盘
}
再看看上层怎么处理这个class
InputManagerService
// Must be called on handler.
private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) {
if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
Log.d("cxyi","notifyInputDevicesChanged 5.2 inputDevice="+inputDevice.getId()+"add in mTempFullKeyboards");
if (!containsInputDeviceWithDescriptor(oldInputDevices,
inputDevice.getDescriptor())) {
mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice);
} else {
mTempFullKeyboards.add(inputDevice);
}
}
public boolean isFullKeyboard() {
return (mSources & SOURCE_KEYBOARD) == SOURCE_KEYBOARD
&& mKeyboardType == KEYBOARD_TYPE_ALPHABETIC;
}
接着会从mTempFullKeyboards 里面拿id 根据vid pid去找对应的键盘布局,找不到那就弹框提示你配置键盘
问题就这么找到了。是设备带了这个属性导致系统认为是输入设备,而又找不到对应的布局
网友评论