Android应用程序键盘(Keyboard)消息处理机制分析(11)
- void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) {
- Vector<InputWindow> windows;
- jsize length = env->GetArrayLength(windowObjArray);
- for (jsize i = 0; i < length; i++) {
- jobject inputTargetObj = env->GetObjectArrayElement(windowObjArray, i);
- if (! inputTargetObj) {
- break; // found null element indicating end of used portion of the array
- }
- windows.push();
- InputWindow& window = windows.editTop();
- bool valid = populateWindow(env, inputTargetObj, window);
- if (! valid) {
- windows.pop();
- }
- env->DeleteLocalRef(inputTargetObj);
- }
- mInputManager->getDispatcher()->setInputWindows(windows);
- }
- void InputDispatcher::setInputWindows(const Vector<InputWindow>& inputWindows) {
- ......
- { // acquire lock
- AutoMutex _l(mLock);
- // Clear old window pointers.
- sp<InputChannel> oldFocusedWindowChannel;
- if (mFocusedWindow) {
- oldFocusedWindowChannel = mFocusedWindow->inputChannel;
- mFocusedWindow = NULL;
- }
- mWindows.clear();
- // Loop over new windows and rebuild the necessary window pointers for
- // tracking focus and touch.
- mWindows.appendVector(inputWindows);
- size_t numWindows = mWindows.size();
- for (size_t i = 0; i < numWindows; i++) {
- const InputWindow* window = & mWindows.itemAt(i);
- if (window->hasFocus) {
- mFocusedWindow = window;
- break;
- }
- }
- ......
- } // release lock
- ......
- }
- mInputChannel = new InputChannel();
- try {
- res = sWindowSession.add(mWindow, mWindowAttributes,
- getHostVisibility(), mAttachInfo.mContentInsets,
- mInputChannel);
- } catch (RemoteException e) {
- ......
- } finally {
- ......
- }
- public class WindowManagerService extends IWindowManager.Stub
- implements Watchdog.Monitor {
- ......
- private final class Session extends IWindowSession.Stub
- implements IBinder.DeathRecipient {
- ......
- public int add(IWindow window, WindowManager.LayoutParams attrs,
- int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
- return addWindow(this, window, attrs, viewVisibility, outContentInsets,
- outInputChannel);
- }
- ......
- }
- ......
- }
- public class WindowManagerService extends IWindowManager.Stub
- implements Watchdog.Monitor {
- ......
- public int addWindow(Session session, IWindow client,
- WindowManager.LayoutParams attrs, int viewVisibility,
- Rect outContentInsets, InputChannel outInputChannel) {
- ......
- WindowState win = null;
- synchronized(mWindowMap) {
- ......
- win = new WindowState(session, client, token,
- attachedWindow, attrs, viewVisibility);
- ......
- if (outInputChannel != null) {
- String name = win.makeInputChannelName();
- InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
- win.mInputChannel = inputChannels[0];
- inputChannels[1].transferToBinderOutParameter(outInputChannel);
- mInputManager.registerInputChannel(win.mInputChannel);
- }
- ......
- }
- ......
- }
- ......
- }
这里的outInputChannel即为前面在Step 1中创建的InputChannel,它不为NULL,因此,这里会通过InputChannel.openInputChannelPair函数来创建一对输入通道,其中一个位于WindowManagerService中,另外一个通过outInputChannel参数返回到应用程序中:
- inputChannels[1].transferToBinderOutParameter(outInputChannel);
创建输入通道之前,WindowManagerService会为当前Activity窗口创建一个WindowState对象win,用来记录这个Activity窗口的状态信息。当创建这对输入管道成功以后,也会把其中的一个管道保存在这个WindowState对象win的成员变量mInputChannel中,后面要注销这个管道的时候,就是从这个WindownState对象中取回这个管道的:
- win.mInputChannel = inputChannels[0];
接下来我们就看一下InputChannel.openInputChannelPair函数的实现。
Android应用程序键盘(Keyboard)消息处理机制分析(11)相关推荐
- Android系统中的Binder通信机制分析(7)- Java 层的 Binder 机制
声明 其实对于Android系统Binder通信的机制早就有分析的想法,记得2019年6.7月份Mr.Deng离职期间约定一起对其进行研究的,但因为我个人问题没能实施这个计划,留下些许遗憾- 文中参考 ...
- Android应用程序键盘(Keyboard)消息处理机制分析(3)
Step 15. Looper.pollOnce 这个函数定义在frameworks/base/libs/utils/Looper.cpp文件中,具体可以参考前面Android应用程序消息处理机制(L ...
- Android应用程序键盘(Keyboard)消息处理机制分析(12)
Step 12. InputChannel.openInputChannelPair 这个函数定义在frameworks/base/core/java/android/view/InputChanne ...
- Android应用程序线程消息循环模型分析(5)
从AsyncTask的实现可以看出,当我们第一次创建一个AsyncTask对象时,首先会执行下面静态初始化代码创建一个线程池sExecutor: private static final Bloc ...
- Android应用程序线程消息循环模型分析
出自:http://blog.csdn.net/luoshengyang/article/details/6905587 我们知道,Android应用程序是通过消息来驱动的,即在应用程序的主线程(UI ...
- 以下未发布-Android的多线程以及异步消息处理机制,android移动开发基础案例教程源码
1.Message: Message 是在线程之间传递的消息,它可以在内部携带少量的信息,用于在不同线程之间进行数据交换.除了 what 字段,还可以使用 arg1 和 arg2 来携带整型数据,使用 ...
- Android应用程序键盘(Keyboard)消息处理机制分析(20)
Step 24. InputQueue.dispatchKeyEvent 这个函数定义在frameworks/base/core/java/android/view/InputQueue.java文件 ...
- Android应用程序键盘(Keyboard)消息处理机制分析(26)
Step 7. LocalWindowManager.removeViewImmediate 这个函数定义在frameworks/base/core/java/android/view/Window. ...
- Android应用程序键盘(Keyboard)消息处理机制分析(17)
Step 11. InputDispatcher.dispatchOnceInnerLocked 这个函数定义在frameworks/base/libs/ui/InputDispatcher.cpp文 ...
- Android应用程序键盘(Keyboard)消息处理机制分析(14)
3. InputManager分发键盘消息给应用程序的过程分析 在分析InputManager分发键盘消息给应用程序的过程之前,我们先假设现在没有键盘事件发生,因此,InputManager中的Inp ...
最新文章
- 数据结构实践——队列数组
- python3菜鸟教程中文-Python3 日期和时间
- 带密匙的php加密解密示例分享
- python电脑推荐_6款Python必备的可视化工具推荐
- 《Java核心技术 卷Ⅱ 高级特性(原书第10版)》一2.4.6 为克隆使用序列化
- 对于 APM 用户的一次真实调查分析(下)
- 【Java】浅析Math类
- AE物体表面跟踪特效合成高级插件:Lockdown for Mac 支持ae2021
- Visual Studio中从应用程序中调试SQL脚本
- 最新sfc模拟器安卓汉化版_卡车模拟器山货运卡车3D游戏安卓最新版 v1.0 卡车模拟器山货运卡车3D游戏下载...
- 单片机c语言fft函数,单片机ADC采样FFT计算试验
- Linux Shell Weevely
- launcher3的具体学习
- Vue中插入jQuery插件
- php mongodb方法,PHP 操作mongodb api大部分方法
- 2112731-59-4,N-(Azido-PEG2)-N-Biotin-PEG3-acid末端羧酸可在活化剂(例如EDC或HATU)存在下与伯氨基反应
- AlarmClock
- react-native android 识别读取NFC卡信息
- 工作室课题—质因数2
- 网络安全工程师要学习哪些编程语言?哪里学网络安全知识可靠?
热门文章
- mysql front 视图_mysql 视图
- java发送qq消息_Java点餐系统和点餐小程序新加微信消息推送功能
- 21天Jenkins打卡Day6安装插件
- matlab电力系统潮流计算软件matpower_衡真课堂 | 电力系统稳态与暂态分析
- linux16.04设置网络,ubuntu16.04之后网络IP配置
- install openni2 on ubuntu
- 改进的EfficientNet-B4用于黑色素瘤检测
- 混淆矩阵(TP+FN+FP+TN)
- 【matlab】元胞数组(使用celldisp显示元胞数组)
- controller层没反应_一脚踏空就没命!57岁民警33层楼顶飞身救人