需求:用户点击屏幕后取消原有定时任务,无操作后顺延原来定时任务

简单分析

要想全局监听,那必须是在 framework 中了,应该从哪里切入呢?先看看 log,每点击一次屏幕后发现打印

InputDispatcher: Asynchronous input event injection succeeded.

全局搜索找到 frameworks\native\services\inputflinger\InputDispatcher.cpp 中

这就有点难顶了,cpp 中想要通知 java 层还是有点困难的,一开始尝试了在此处发送广播

#include <unistd.h>

switch (injectionResult) {
case INPUT_EVENT_INJECTION_SUCCEEDED:
ALOGV(“Asynchronous input event injection succeeded.”);

execlp(“am”, “am”, “broadcast”,
“-n”, “com.android.systemui/com.pdd.sutie.CustomerReceiver”,
“-a”, “com.pdd.action.inputevent.inject”,
NULL);
exit(errno);

通过函数 execlp() 调用 am 指令发送广播,尝试后发现会把 system 进程搞挂,看来 execlp() 不能在此使用,那就只能搂底浆了,

从 cpp 往上找,最终找到 frameworks\base\services\core\java\com\android\server\input\InputManagerService.java 中

调用顺序如下

InputManagerService.java
injectInputEventInternal(event, mode)

com_android_server_input_InputManagerService.cpp
im->getInputManager()->getDispatcher()->injectInputEvent(

InputDispatcher.cpp
int32_t InputDispatcher::injectInputEvent(const InputEvent* event,
int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
uint32_t policyFlags)

解决办法

frameworks\base\services\core\java\com\android\server\input\InputManagerService.java

@Override // Binder callpublic boolean injectInputEvent(InputEvent event, int mode) {return injectInputEventInternal(event, mode);}private boolean injectInputEventInternal(InputEvent event, int mode) {if (event == null) {throw new IllegalArgumentException("event must not be null");}if (mode != InputManager.INJECT_INPUT_EVENT_MODE_ASYNC&& mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH&& mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT) {throw new IllegalArgumentException("mode is invalid");}final int pid = Binder.getCallingPid();final int uid = Binder.getCallingUid();final long ident = Binder.clearCallingIdentity();final int result;try {result = nativeInjectInputEvent(mPtr, event, pid, uid, mode,INJECTION_TIMEOUT_MILLIS, WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT);} finally {Binder.restoreCallingIdentity(ident);}switch (result) {case INPUT_EVENT_INJECTION_PERMISSION_DENIED:Slog.w(TAG, "Input event injection from pid " + pid + " permission denied.");throw new SecurityException("Injecting to another application requires INJECT_EVENTS permission");case INPUT_EVENT_INJECTION_SUCCEEDED://cczheng add for listen lcd input startandroid.util.Log.e("InputDispatcher", "Input event injection from pid " + pid + " succeeded.");Intent pIntent = new Intent("com.pdd.action.inputevent.inject");pIntent.setComponent(new android.content.ComponentName("com.android.systemui","com.pdd.sutie.CustomerReceiver"));mContext.sendBroadcast(pIntent);//cczheng add for listen lcd input endreturn true;case INPUT_EVENT_INJECTION_TIMED_OUT:Slog.w(TAG, "Input event injection from pid " + pid + " timed out.");return false;case INPUT_EVENT_INJECTION_FAILED:default:Slog.w(TAG, "Input event injection from pid " + pid + " failed.");return false;}}

Android Input(四) -InputDispatcher分发事件
Android10 InputManagerService事件输入输出

Framework 全局监听屏幕点击事件 INPUT_EVENT_INJECTION相关推荐

  1. touch事件总结,监听屏幕点击事件

    Touch对象--MDN TouchEvent--MDN 一.问题背景 click事件在移动端的300毫秒延迟问题 当需要监听诸如左滑.右滑之类的事件 二.知识点概括 1. 事件类型 touchsta ...

  2. android 触摸监听重写_Android监听屏幕的滑动事件

    实现监听屏幕上下左右滑动事件 前段时间为了实现这个功能在网上找了很多教程,发现很多教程都是很大的篇幅,对于像我这种一点都不了解的人GestureListener的人来说可能很难理解,动不动就是几百行代 ...

  3. Android监听屏幕的滑动事件

    实现监听屏幕上下左右滑动事件 前段时间为了实现这个功能在网上找了很多教程,发现很多教程都是很大的篇幅,对于像我这种一点都不了解的人GestureListener的人来说可能很难理解,动不动就是几百行代 ...

  4. jquery 监听td点击事件_安卓开发监听点击事件的一种方法

    本人是菜鸟一只,学习安卓纯属兴趣.没有真正上过编程课程,所有知识都是在网上获取的.今天分享的是监听点击事件的一个方法,这个方法的好处是代码较简洁. 如图,点击保存时,把上面的数据入库. 实现如下: 在 ...

  5. jquery 监听td点击事件_React 事件 | 1. React 中的事件委托

    说到 React 的事件,也算是 React 的一个非常有亮点的优化,它在原生事件体系的基础上,单独实现了一套事件机制.想要了解这个机制,首先的了解下什么是事件委托以及事件委托的好处. 事件委托 假设 ...

  6. untiy 监听屏幕点击 物体(实现)

    第一种方式: 1.百度的第三方法 using System.Collections; using System.Collections.Generic; using UnityEngine; usin ...

  7. jquery 监听td点击事件_VUE @hook浅析(监听子组件的生命周期钩子) - 古兰精

    一.前言 接触hook是从webhook开始接触的,webhook是git的一个扩展服务,可以在仓库接收到push/commit事件并发送http request至一个开发者可以自定义的URL.通过这 ...

  8. html的 button点击事件无效,InfoWindow里面加button,监听button点击事件无效 求解啊...

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 点击infoWindw中的button按钮,无效果: 覆盖默认的dom结构 html, body, #container { width: 100%; h ...

  9. 微信浏览器返回刷新,监听微信浏览器返回事件,网页防复制,移动端禁止图片长按和vivo手机点击img标签放大图片

    以下代码都经过iphone7,华为MT7 ,谷歌浏览器,微信开发者工具,PC端微信验证.如有bug,还请在评论区留言. demo链接:https://pan.baidu.com/s/1c35mbjM ...

最新文章

  1. 改进YOLO | 可能这才是用Transformer正确打开YOLO的方式吧?
  2. hadoop中datanode无法启动,报Caused by: java.net.NoRouteToHostException: No route to host
  3. 解密小程序云开发数据库
  4. python社区版可以用库么_应用Python,你不但能够得到出色的小区适用和普遍的库集...
  5. 芯片公司急聘嵌入式软件精英人才
  6. Visual Studio Code C++配置文件
  7. docker, docker-compose安装
  8. mysql 查看锁等待
  9. leetcode 第2高的薪水 oracle_詹姆斯本赛季薪水3744万美元排在第6位,比他高的都有谁?...
  10. “恒德”机场智能应急指挥调度系统解决方案
  11. 成分句法分析与依存句法分析
  12. Openssl CA证书生成以及双向认证,及windows系统证书批量导出,android cer转bks
  13. android弹球游戏小球运动,球球跳一跳跳舞弹球
  14. VirtualBox设置桥接网络
  15. 用scratch2.0编写乒乓球游戏
  16. 商汤的AI伴游小精灵(找最多子树)
  17. xman的思维导图快捷键_macz技巧分享:思维导图XMind快捷键汇总
  18. Linux CentOS 7安装之后,ip addr命令无法显示ip地址。ifconfig命令报错:未找到命令!
  19. 离散数学·代数结构【正规子群、商群、群的同态和同构、环与域、格、布尔代数】
  20. DEDE(织梦)插件开发案例(一)

热门文章

  1. C语言基础——编译器工作原理
  2. 心一则技有余——【美】加尔·雷纳德 《演说之禅》 读书笔记
  3. BaseActivity
  4. BLE Hacking:使用Ubertooth one扫描嗅探低功耗蓝牙
  5. N026_只根据转入和转出两列来画桑基图_巡线追踪
  6. 【数字信号处理】傅里叶变换性质 ( 傅里叶变换对称性 | 共轭对称序列 | 共轭反对称序列 )
  7. Intel(R) 处理器产品型号/CPUID标识/签名对照表 (Family — Model)
  8. 托管DirectX,从MDX到SlimDX的转换(转)
  9. 阿里腾讯京东三巨头手握保险牌照 互联网保险要迎来发展春天了吗?
  10. 基于狂神说SpringMVC笔记总结