InputMethodManager输入法窗口为啥dumpsys是全屏?千里马带你疑难解惑输入法相关

【问题分析】WMS无焦点窗口的ANR问题【Android 14】 Monkey跑出的 Launcher ANR,场景为在Launcher的Recents界面下一个Activity启动又快速销毁导致的无焦点窗口问题。 阅读详情

背景:

hi,粉丝朋友:
大家好!近来陆续有粉丝朋友在群里讨论到输入法,这个部分其实马哥之前也是研究过的,所以相对来说比较熟悉,其实android设计输入法的思路其实和壁纸是一模一样的。大体设计图如下:
在这里插入图片描述

一般看到的输入法界面就是输入法进程,一般都是实现了InputMethodService的子类实现,这里面会创建对应的输入法窗口展示,所以这里要说明输入法它不是个Activity哈,只是个全局窗口而已,和状态栏啥的一样。

刚好有个同学问了一个输入法的疑问,为啥dumpsys window windows和dumpsys SurfaceFlinger时候明明看到输入法是全屏,这个是怎么回事?

1、dumpsys相关SurfaceFlinger和window看看全屏情况

以下是winsocpe的SurfaceFlinger图层情况
在这里插入图片描述确实这里看到的SurfaceFlinger中对应的InputMethod的windowstate的activebuffer确实是全屏的:

activeBuffer : w:1440, h:2876, stride:2816, format:1

再看看对应的window相关的信息:
在这里插入图片描述也展示出来的大小是
frame : (0, 84) - (1440, 2960)
也都是全屏。

2、疑问点既然输入法全屏为啥activity还可以响应事件

首先显示部分遮盖理解:

这个部分相对比较好理解,因为窗口虽然是占全屏幕,但是可以又一部分透明透看到底部的窗口

其次触摸部分:

层级结构看输入法应该是盖在Activity的窗口上面,而且输入法又是全屏的,那么理论上所有的触摸事件就应该到输入法的窗口,而不应该到Activity的窗口。
但是实际情况又是如下图所示:
在这里插入图片描述

即只有输入法显示的部分才是输入法可以触摸的,触摸activity的部分那么activity就会响应对应的触摸事件。

需要回答这个问题就又需要使用我们input课程的知识:
需要试看课程的可以点击这里:https://www.bilibili.com/video/BV1YS4y1K7rj/
也可以+w:androidframework007 找我
在这里插入图片描述
要学回查看dumpsys input输出信息:


Input Dispatcher State:
  DispatchEnabled: true
  DispatchFrozen: false
  InputFilterEnabled: false
  FocusedDisplayId: 0
  FocusedApplications:
    displayId=0, name='ActivityRecord{49e3140 u0 com.android.quicksearchbox/.SearchActivity} t439}', dispatchingTimeout=5000ms
  FocusedWindows:
    displayId=0, name='313a198 com.android.quicksearchbox/com.android.quicksearchbox.SearchActivity'
  FocusRequests:
    displayId=0, name='313a198 com.android.quicksearchbox/com.android.quicksearchbox.SearchActivity' result='OK'
  Pointer Capture Requested: false
  Current Window with Pointer Capture: None
  TouchStates: <no displays touched>
  Display: 0
    logicalSize=1440x2960
        transform (ROT_0) (IDENTITY)
    Windows:
      0: name='[Gesture Monitor] swipe-up', id=106, displayId=0, inputConfig=NOT_FOCUSABLE | TRUSTED_OVERLAY | SPY, alpha=1.00, frame=[0,0][0,0], globalScale=1.000000, applicationInfo.name=[Gesture Monitor] swipe-up, applicationInfo.token=<null>, touchableRegion=[-14399,-29599][14400,29600], ownerPid=1047, ownerUid=10097, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      1: name='[Gesture Monitor] edge-swipe', id=81, displayId=0, inputConfig=NOT_FOCUSABLE | TRUSTED_OVERLAY | SPY, alpha=1.00, frame=[0,0][0,0], globalScale=1.000000, applicationInfo.name=[Gesture Monitor] edge-swipe, applicationInfo.token=<null>, touchableRegion=[-14399,-29599][14400,29600], ownerPid=762, ownerUid=10099, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      2: name='StrictModeFlash', id=93, displayId=0, inputConfig=NO_INPUT_CHANNEL | NOT_VISIBLE | NOT_FOCUSABLE | NOT_TOUCHABLE | PREVENT_SPLITTING | TRUSTED_OVERLAY, alpha=1.00, frame=[0,0][1440,2960], globalScale=1.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=<empty>, ownerPid=0, ownerUid=0, dispatchingTimeout=0ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      3: name='4b4d6f1 PointerLocation - display 0', id=49, displayId=0, inputConfig=NO_INPUT_CHANNEL | NOT_FOCUSABLE | NOT_TOUCHABLE | PREVENT_SPLITTING | TRUSTED_OVERLAY, alpha=1.00, frame=[0,0][1440,2960], globalScale=1.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=<empty>, ownerPid=572, ownerUid=1000, dispatchingTimeout=0ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      4: name='6f6f2e3 NavigationBar0', id=86, displayId=0, inputConfig=NOT_FOCUSABLE | TRUSTED_OVERLAY | WATCH_OUTSIDE_TOUCH, alpha=1.00, frame=[0,2792][1440,2960], globalScale=1.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=<empty>, ownerPid=762, ownerUid=10099, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (TRANSLATE)
            1.0000  0.0000  -0.0000
            0.0000  1.0000  -2792.0000
            0.0000  0.0000  1.0000
      5: name='1afd988 StatusBar', id=87, displayId=0, inputConfig=NOT_FOCUSABLE | TRUSTED_OVERLAY, alpha=1.00, frame=[0,0][1440,84], globalScale=1.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=[0,0][1440,84], ownerPid=762, ownerUid=10099, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      6: name='recents_animation_input_consumer', id=101, displayId=0, inputConfig=NOT_VISIBLE | TRUSTED_OVERLAY, alpha=1.00, frame=[0,0][1440,2960], globalScale=1.000000, applicationInfo.name=recents_animation_input_consumer, applicationInfo.token=0x77cb0493d7d0, touchableRegion=[0,0][1440,2960], ownerPid=572, ownerUid=1000, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      7: name='99d71b InputMethod', id=278, displayId=0, inputConfig=NOT_FOCUSABLE | TRUSTED_OVERLAY, alpha=1.00, frame=[0,84][1440,2960], globalScale=1.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=[0,1759][1440,2960], ownerPid=1194, ownerUid=10081, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (TRANSLATE)
            1.0000  -0.0000  0.0000
            -0.0000  1.0000  -84.0000
            0.0000  0.0000  1.0000
      8: name='313a198 com.android.quicksearchbox/com.android.quicksearchbox.SearchActivity', id=273, displayId=0, inputConfig=0x0, alpha=1.00, frame=[0,0][1440,2960], globalScale=1.000000, applicationInfo.name=ActivityRecord{49e3140 u0 com.android.quicksearchbox/.SearchActivity} t439}, applicationInfo.token=0x77cb04980b50, touchableRegion=[0,0][1440,2960], ownerPid=1441, ownerUid=10084, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      9: name='c6a010e ActivityRecordInputSink com.android.quicksearchbox/.SearchActivity', id=120, displayId=0, inputConfig=NO_INPUT_CHANNEL | NOT_FOCUSABLE, alpha=1.00, frame=[0,0][0,0], globalScale=0.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=[-14399,-29599][14400,29600], ownerPid=572, ownerUid=1000, dispatchingTimeout=0ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      10: name='efb17ce ActivityRecordInputSink com.android.camera2/com.android.camera.CameraActivity', id=141, displayId=0, inputConfig=NO_INPUT_CHANNEL | NOT_VISIBLE | NOT_FOCUSABLE | NOT_TOUCHABLE, alpha=1.00, frame=[0,0][0,0], globalScale=0.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=[-14399,-29599][14400,29600], ownerPid=572, ownerUid=1000, dispatchingTimeout=0ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      11: name='8dd0f70 ActivityRecordInputSink com.android.settings/.SubSettings', id=213, displayId=0, inputConfig=NO_INPUT_CHANNEL | NOT_VISIBLE | NOT_FOCUSABLE | NOT_TOUCHABLE, alpha=1.00, frame=[0,0][0,0], globalScale=0.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=[0,0][1440,2960], ownerPid=572, ownerUid=1000, dispatchingTimeout=0ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      12: name='214bf5f ActivityRecordInputSink com.android.settings/.SubSettings', id=196, displayId=0, inputConfig=NO_INPUT_CHANNEL | NOT_VISIBLE | NOT_FOCUSABLE | NOT_TOUCHABLE, alpha=1.00, frame=[0,0][0,0], globalScale=0.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=[0,0][1440,2960], ownerPid=572, ownerUid=1000, dispatchingTimeout=0ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      13: name='2001b8f ActivityRecordInputSink com.android.settings/.homepage.SettingsHomepageActivity', id=178, displayId=0, inputConfig=NO_INPUT_CHANNEL | NOT_VISIBLE | NOT_FOCUSABLE | NOT_TOUCHABLE, alpha=1.00, frame=[0,0][0,0], globalScale=0.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=[0,0][1440,2960], ownerPid=572, ownerUid=1000, dispatchingTimeout=0ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      14: name='edb3266 com.android.launcher3/com.android.launcher3.uioverrides.QuickstepLauncher', id=266, displayId=0, inputConfig=DUPLICATE_TOUCH_TO_WALLPAPER, alpha=1.00, frame=[0,0][1440,2960], globalScale=1.000000, applicationInfo.name=ActivityRecord{c22322a u0 com.android.launcher3/.uioverrides.QuickstepLauncher} t437}, applicationInfo.token=0x77cb049417f0, touchableRegion=[0,0][1440,2960], ownerPid=1047, ownerUid=10097, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      15: name='91a1ad2 ActivityRecordInputSink com.android.launcher3/.uioverrides.QuickstepLauncher', id=109, displayId=0, inputConfig=NO_INPUT_CHANNEL | NOT_FOCUSABLE, alpha=1.00, frame=[0,0][0,0], globalScale=0.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=[-14399,-29599][14400,29600], ownerPid=572, ownerUid=1000, dispatchingTimeout=0ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (IDENTITY)
      16: name='Wallpaper BBQ wrapper#79', id=79, displayId=0, inputConfig=NO_INPUT_CHANNEL, alpha=1.00, frame=[-71,-147][1760,3108], globalScale=1.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=<empty>, ownerPid=762, ownerUid=10099, dispatchingTimeout=5000ms, hasToken=false, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (SCALE TRANSLATE)
            0.5160  -0.0000  37.1499
            -0.0000  0.5160  76.3636
            0.0000  0.0000  1.0000
      17: name='b2dd605 com.android.systemui.ImageWallpaper', id=78, displayId=0, inputConfig=NOT_FOCUSABLE | NOT_TOUCHABLE | PREVENT_SPLITTING | IS_WALLPAPER, alpha=1.00, frame=[-71,-147][-71,-147], globalScale=1.000000, applicationInfo.name=, applicationInfo.token=<null>, touchableRegion=<empty>, ownerPid=762, ownerUid=10099, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
        transform (ROT_0) (SCALE TRANSLATE)
            0.5160  -0.0000  37.1499
            -0.0000  0.5160  76.3636
            0.0000  0.0000  1.0000


上面是所有的触摸window的在input中的情况,我们重点关注是InputMethod这个窗口:

7: name=‘99d71b InputMethod’, id=278, displayId=0, inputConfig=NOT_FOCUSABLE | TRUSTED_OVERLAY, alpha=1.00, frame=[0,84][1440,2960], globalScale=1.000000, applicationInfo.name=, applicationInfo.token=, touchableRegion=[0,1759][1440,2960], ownerPid=1194, ownerUid=10081, dispatchingTimeout=5000ms, hasToken=true, touchOcclusionMode=BLOCK_UNTRUSTED
transform (ROT_0) (TRANSLATE)
1.0000 -0.0000 0.0000
-0.0000 1.0000 -84.0000
0.0000 0.0000 1.0000

可以看到的它的画面大小确实是frame=[0,84][1440,2960],但是有一个touchableRegion=[0,1759][1440,2960],这个区域才是真正的触摸区域,这里我们就看出了猫腻,这里y是从1759的位置才开始可以触摸了,也就是我们上面看到的输入法的键盘区域。
即这个touchableRegion就解答了为啥上部分区域触摸事件没有给输入法窗口,因为输入法窗口触摸区域就不包含那一部分,所以触摸事件在上部分区域就会继续传递到下面的窗口即Activity窗口。
那么问题来了请问这个touchableRegion是在哪里进行的设置呢?

3、touchableRegion设置追踪

这里我们知道一般input中的window是由InputMonitor设置的:
frameworks/base/services/core/java/com/android/server/wm/InputMonitor.java
中搜索到如下类似代码:

            inputWindowHandle.setTouchableRegion(mTmpRegion);

在这个方法加入对应的堆栈打印
frameworks/base/services/core/java/com/android/server/wm/InputWindowHandleWrapper.java

   void setTouchableRegion(Region region) {
        if (mHandle.touchableRegion.equals(region)) {
            return;
        }
      if (region.getBounds().top > 1000) {
            android.util.Log.i("lsm111","setTouchableRegion " + region + " mHandle = "+mHandle,new Exception());
       }
        mHandle.touchableRegion.set(region);
        mChanged = true;
    }

相关的堆栈setTouchableRegion

* daemon started successfully
--------- beginning of main
09-15 11:59:46.669   572   593 I lsm111  : setTouchableRegion SkRegion((0,1675,1440,2876))
09-15 11:59:46.669   572   593 I lsm111  : java.lang.Exception
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.InputWindowHandleWrapper.setTouchableRegion(InputWindowHandleWrapper.java:146)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.InputMonitor.populateInputWindowHandle(InputMonitor.java:315)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.InputMonitor$UpdateInputForAllWindowsConsumer.accept(InputMonitor.java:636)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.InputMonitor$UpdateInputForAllWindowsConsumer.accept(InputMonitor.java:508)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer$ForAllWindowsConsumerWrapper.apply(WindowContainer.java:2624)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer$ForAllWindowsConsumerWrapper.apply(WindowContainer.java:2614)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowState.applyInOrderWithImeWindows(WindowState.java:4903)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowState.forAllWindows(WindowState.java:4747)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.DisplayContent$ImeContainer.forAllWindowForce(DisplayContent.java:5175)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.DisplayContent.forAllImeWindows(DisplayContent.java:2814)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowState.applyImeWindowsIfNeeded(WindowState.java:4896)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowState.applyInOrderWithImeWindows(WindowState.java:4902)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowState.forAllWindows(WindowState.java:4747)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1611)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1628)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.InputMonitor$UpdateInputForAllWindowsConsumer.updateInputWindows(InputMonitor.java:548)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.InputMonitor$UpdateInputForAllWindowsConsumer.-$$Nest$mupdateInputWindows(Unknown Source:0)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.wm.InputMonitor$UpdateInputWindows.run(InputMonitor.java:134)
09-15 11:59:46.669   572   593 I lsm111  : 	at android.os.Handler.handleCallback(Handler.java:942)
09-15 11:59:46.669   572   593 I lsm111  : 	at android.os.Handler.dispatchMessage(Handler.java:99)
09-15 11:59:46.669   572   593 I lsm111  : 	at android.os.Looper.loopOnce(Looper.java:201)
09-15 11:59:46.669   572   593 I lsm111  : 	at android.os.Looper.loop(Looper.java:288)
09-15 11:59:46.669   572   593 I lsm111  : 	at android.os.HandlerThread.run(HandlerThread.java:67)
09-15 11:59:46.669   572   593 I lsm111  : 	at com.android.server.ServiceThread.run(ServiceThread.java:44)

可以看出这里的setTouchableRegion设置是由触发
InputMonitor$UpdateInputForAllWindowsConsumer.updateInputWindows

那么Region来自哪里呢?

   if (!useSurfaceBoundsAsTouchRegion) {
   //实际是调用了WindowState的getSurfaceTouchableRegion方法
            w.getSurfaceTouchableRegion(mTmpRegion, w.mAttrs);
            inputWindowHandle.setTouchableRegion(mTmpRegion);
        }

这里又回调用到WindowState的getTouchableRegion方法:

    /** Get the touchable region in global coordinates. */
    void getTouchableRegion(Region outRegion) {
        final Rect frame = mWindowFrames.mFrame;
        switch (mTouchableInsets) {//关键的mTouchableInsets决定取哪个区域
            default:
            case TOUCHABLE_INSETS_FRAME:
                outRegion.set(frame);
                break;
            case TOUCHABLE_INSETS_CONTENT:
                applyInsets(outRegion, frame, mGivenContentInsets);
                break;
            case TOUCHABLE_INSETS_VISIBLE:
                applyInsets(outRegion, frame, mGivenVisibleInsets);
                break;
            case TOUCHABLE_INSETS_REGION: {//输入法执行到这里
                outRegion.set(mGivenTouchableRegion);
                if (frame.left != 0 || frame.top != 0) {
                    outRegion.translate(frame.left, frame.top);
                }
                break;
            }
        }
        cropRegionToRootTaskBoundsIfNeeded(outRegion);
        subtractTouchExcludeRegionIfNeeded(outRegion);
    }

问题就是mGivenTouchableRegion来自哪里?哈哈这里经过寻找发现在WindowManagerService进行赋值的,具体堆栈如下:

09-15 16:09:34.367   551  1330 I lsm111  : Window{e201e2f u0 InputMethod} touchableRegion = SkRegion((0,1675,1440,2876))
09-15 16:09:34.367   551  1330 I lsm111  : java.lang.Exception
09-15 16:09:34.367   551  1330 I lsm111  : 	at com.android.server.wm.WindowManagerService.setInsetsWindow(WindowManagerService.java:2165)
09-15 16:09:34.367   551  1330 I lsm111  : 	at com.android.server.wm.Session.setInsets(Session.java:279)
09-15 16:09:34.367   551  1330 I lsm111  : 	at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:813)
09-15 16:09:34.367   551  1330 I lsm111  : 	at com.android.server.wm.Session.onTransact(Session.java:175)
09-15 16:09:34.367   551  1330 I lsm111  : 	at android.os.Binder.execTransactInternal(Binder.java:1285)
09-15 16:09:34.367   551  1330 I lsm111  : 	at android.os.Binder.execTransact(Binder.java:1244)

是客户端发起的调用设置的Inset,这里就相当于到了Inset部分了,和类是状态栏,导航栏那个是一回事,在这就不深入分析了。

Android R WindowManagerService模块(5) 焦点窗口和InputWindows的更新 private final ToBooleanFunction mFindFocusedWindow = w -> { // 当前处于前台的ActivityRecord final ActivityRecord focusedApp = mFocusedApp; // 如果窗口无法接收key事件,则不能作为焦点窗口,返回false if (!w.canReceiveKeys()) { return false; } final ActivityRecord activity = w.mActivity 阅读详情

相关推荐

【问题分析】InputDispatcher无焦点窗口ANR问题【Android 14】

Monkey跑出的无焦点窗口的ANR问题。特点:1)、上层WMS有焦点窗口,为Launcher。2)、native层InputDispacher无焦点窗口,上层为”recents_animation_input_consumer“请求了焦点,但是”recents_animation_input_consumer“最终没有成为焦点窗口,原因是”NO_WINDOW“。

ukynho的博客 3825

ActivityRecordInputSink深入剖析全网独家分析

可以看到Activity的窗口显示大小就是touchableRegion=[0,0][1080,2160]即和屏幕大小一样,而ActivityRecordInputSink大小是touchableRegion=[-10799,-21599][10800,21600]明显比手机屏幕大很多,这种Activity大小和手机手机屏幕一样,触摸事件正常都不可能到这里。上图展示的Activity大小和手机屏幕大小一样,所以手机触摸事件根本到达不了ActivityRecordInputSink这个地方。

liaosongmao1的专栏 518

安卓4老电视/盒子输入法失效?ADB排查与安装实战指南

在安卓系统中,输入法通过IME框架与系统交互,用户能否正常打字取决于输入法是否被系统识别、启用并设为默认。安卓4老电视和盒子常因厂商裁剪、默认输入法未配置或第三方APK兼容性问题,导致搜索框无法唤出键盘。解决这类问题通常不需要刷机,而是借助ADB调试工具检查系统已安装的输入法列表,再通过应用商店、U盘或ADB命令完成安装与默认设置。从系统设置入口到IME服务状态验证,掌握基础的ADB命令和APK兼容性判断,能为老设备维护提供高效的排查路径。本文给出的完整流程,覆盖从环境准备到批量部署的各个环节,适用于家用老

weixin_33816821的博客 407

android认识窗口

这里我按照自己的理解画了一下Android架构图,主要是对看下Framework这块:顶层是基于ApplicationFramework层的Apps层,ApplicationFramework是运行在App进程的Framework代码,如四大组件,各种Manager。在这一层,屏幕上的一块显示区域,典型代表是Activity,但是Activity毕竟是一个综合性比较强的概念,具体到内容显示这块还是由Window类负责,Window则是容纳View对象的容器。

Rainman博的专栏 834

Android输入子系统全链路剖析:从物理触摸到应用响应

在移动应用开发中,输入事件的处理是用户交互的基础。Android系统从物理触摸到界面响应,依赖一条贯穿Linux内核、系统服务与应用框架的完整链路。其核心机制包括以InputManagerService为中心的窗口信息管理,以及InputReader与InputDispatcher协同完成的事件读取与分发。深入理解这套流程,有助于开发者掌握触摸事件分发、焦点分配和ANR产生的底层原因。实际工程中,通过getevent可观察原始事件流,利用dumpsys input可定位分发状态,从而高效排查触摸失效、输入卡

weixin_34408624的博客 454

安卓Imgui Mod管理器开发指南:从原理到实战部署

在安卓应用与游戏开发中,运行时调试与参数实时调整是提升开发效率的关键需求。传统UI方案往往笨重且难以集成,而基于Immediate Mode GUI(即时模式图形界面)的技术,通过其轻量级、高性能的渲染特性,为动态叠加界面提供了新的解决方案。其核心原理在于,将UI控件的绘制逻辑与状态管理直接嵌入到应用的主渲染循环中,实现帧级别的界面更新。这种技术价值在于,它允许开发者在无需修改目标应用原生布局的前提下,快速构建出可交互的调试面板或配置菜单,极大地简化了Mod(游戏模组)或辅助工具的界面开发流程。在应用场景上

weixin_34099526的博客 401

多屏模式输入法可以正确切换屏幕展示原理剖析

整个多屏输入法的流程涉及到了3个进程---->焦点app发起startInputAsyncOnWindowFocusGain------>systemserver stop老的service,start新service-------->输入法进程创建新的service onCreate执行------->输入法创建带有display的context-------->创建对于输入法窗口带有新的display更多framework干货获取相关可以 私聊+v(androidframework007)

learnframework的博客 3491

React Native Android软键盘适配:windowSoftInputMode配置详解

软键盘行为是移动应用基础交互的核心环节,其本质涉及Android窗口管理器(Window Manager)对Activity DecorView的重绘调度。理解android:windowSoftInputMode的adjustResize与adjustPan两种模式原理,是解决输入框遮挡、ScrollView无法自动滚动、状态栏异常等UI问题的关键技术前提。该配置直接影响RN渲染管线与原生系统协同效率,具备跨Android 5.0–14及华为EMUI、小米MIUI等主流厂商ROM的兼容价值。典型应用场景包

weixin_30312563的博客 4970

Android窗口焦点机制详解:从WMS到实战避坑指南

在Android应用开发中,输入事件能否准确分发、软键盘是否按预期弹出,背后都依赖一套系统级的裁决机制——窗口焦点。窗口焦点由WindowManagerService统一管理,决定当前哪个窗口能接收按键与触摸事件。理解mCurrentFocus与mFocusedApp的区别,掌握FLAG_NOT_FOCUSABLE等关键Flag的用法,是解决悬浮窗抢焦点、Dialog关闭后按键失灵、软键盘异常弹出等高频问题的核心前提。同时,onWindowFocusChanged与onResume的时序差异、分屏与画中画场

weixin_34198881的博客 423

HTB_Bike靶机之模板注入

船到桥头自然直 文章目录信息收集模板引擎SSIT 模板注入后放答案 信息收集 日常 A 扫描,两个端口 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.4 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 48:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae (RSA) | 256 b7:89:6c:0b:20:ed:49:b2:c1:86:7c:.

网络安全学习 802

Cursor 被封解决方案 - 8元轻松搞定永久账号

最近两天很多这种问题,比如:Access blocked,please contact your admin,本文亲测解决有效

欲穷java洞的博客 2万+

Android输入法调试指南:adb ime命令详解与实战应用

在Android开发中,输入法框架(Input Method Framework, IMF)是处理用户文本输入的核心系统组件。其工作原理涉及应用、系统服务和输入法编辑器(IME)之间的协同通信,通过焦点管理、事件分发和窗口合成实现软键盘的显示与交互。掌握输入法调试技术对于保障应用兼容性、提升用户体验和进行自动化测试具有重要价值,尤其在处理键盘无法弹出、输入焦点异常等常见问题时。本文聚焦于adb ime这一系统级调试工具,通过详解其命令集与实战场景,帮助开发者快速定位和解决输入法相关问题。

weixin_30319153的博客 480

LabVIEW实战:3步搞定Excel模板数据填充(附完整VI源码)

本文提供了一个高效的LabVIEW Excel报表自动化方案,通过使用命名区域定位和动态文件管理,实现数据的精准、动态填充。文章详细阐述了如何构建可复用的数据填充引擎,包括文本、表格数据及图表的写入,并分享了主程序流程、错误处理及性能优化等进阶技巧,帮助工程师彻底摆脱手动操作,提升工作效率。

weixin_29233333的博客 281

Android输入法子系统深度解析

Android输入法框架的源码是一个教科书级别的C/S架构与Binder通信实战案例。它通过掌控全局,通过充当App代理,最终由落地为可视化的键盘界面。理解这套“服务-代理-执行体”的三层结构及其Token安全校验、异步文本提交机制,是解决各种输入法疑难杂症的基础。如果你对文中的某个特定模块有更深入的兴趣——比如InputConnection 的跨进程对象泄漏问题Android 15 上预测性手势与键盘收起的冲突处理,或是多窗口/分屏模式下的输入法焦点抢占。

天空之城 188

C#实现串口通讯程序

1、自动获取本地串口。2、根据传入串口基本属性参数打开串口。3、串口数据的发送接收功能(ASCII和HEX格式)。4、ASCII和HEX相互转换。csharp体验AI代码助手代码解读复制代码[Category("UserProperty")] [Description("轮廓半径")] public int Radius { get => radius;

2401_89221445的博客 1771

耶鲁大学《博弈论》课程——逆向归纳

耶鲁大学《博弈论》课程——逆向归纳

ZYLer_的博客 7885

Android设备默认输入法自动化设置:ADB命令与系统API实战指南

输入法作为人机交互的核心组件,其默认设置直接影响用户体验与设备管理效率。在Android系统中,输入法框架通过唯一的输入法ID(IME ID)进行标识与管理,开发者可通过ADB命令或系统API实现自动化配置。这项技术对于批量设备部署、自动化测试及企业移动设备管理(MDM)场景具有重要价值,能显著降低手动操作成本并确保配置一致性。本文聚焦于通过ADB命令(如`ime set`、`settings get secure`)和Android系统API(如`InputMethodManager`、`WRITE_SE

weixin_34277853的博客 426

英特尔® NUC迷你电脑实现无人值守自动开机配置指南

本文详细介绍了如何配置英特尔® NUC迷你电脑实现无人值守自动开机功能。从BIOS设置到操作系统级配置,涵盖硬件兼容性确认、电源恢复功能设置及常见问题解决,帮助用户轻松实现设备断电后自动恢复运行,适用于家庭服务器、企业终端等多种场景。

weixin_42638178的博客 485

android系统动态切换输入法

主要获取InputMethodManager中的方法 ((InputMethodManager)myActivity.getSystemService(Context.INPUT_METHOD_SERVICE)) .setInputMethod(null, NewInputMethodName); 如何获取NewInputMethodName 系统的是com.android.inputm

u012904691的博客 4380

MiniQMT国债逆回购策略Python代码全解析

通过本文的介绍,我们不仅学习了如何在MiniQMT平台上使用Python编写国债逆回购策略,还对策略的逻辑构建、代码实现以及风险管理有了深入的了解。国债逆回购策略是一种适合初学者的低风险投资方式,希望本文能帮助你在量化交易的道路上迈出坚实的一步。

木头大左的博客 1923

OpenHarmony AI系列:神经网络处理单元(NPU)驱动架构与实现详解

NPU(Neural Processing Unit,神经网络处理单元)是专门为神经网络计算设计的硬件加速器。在OpenHarmony系统中,NPU驱动是通过NNRT(Neural Network Runtime,神经网络运行时)框架实现的,它作为中间桥梁连接上层AI推理框架和底层NPU硬件,实现AI模型的跨芯片推理计算。

m0_67505153的博客 669

安卓4电视没有输入法?从框架原理到adb绕行调试完整指南

输入法(IME)在安卓系统中并非普通应用,而是依赖InputMethodService的系统服务,需要被系统注册并设置为默认才能弹出键盘。老电视与盒子常因ROM精简、APK版本过旧或CPU架构不匹配,导致安装失败或无法启用,现象即“没有可用输入法”。理解其运行机理后,可通过adb命令检查输入法服务列表、直接安装或设置默认输入法,甚至绕过输入法框架,用input text、剪贴板广播或USB键盘完成文字输入。这套排查思路适用于安卓4.x智能电视、机顶盒的调试场景,也能帮助开发者在TV应用交互设计中规避键盘弹不

weixin_34411563的博客 346

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Android窗口焦点机制:从WMS到InputDispatcher的完整链路

窗口焦点是Android窗口管理中的核心概念,决定了系统按键事件、物理按键和软键盘输入的分发归属。在Android体系中,WindowManagerService负责计算焦点窗口,InputDispatcher根据焦点信息将输入事件派发给指定窗口,而应用层则通过onWindowFocusChanged感知焦点变化。对于开发者而言,理解窗口焦点与触摸目标的本质区别至关重要,FLAG_NOT_FOCUSABLE 是控制窗口是否参与焦点竞争的关键标志。实际开发中,悬浮窗、Dialog、PopupWindow、软键

weixin_34015336的博客 376

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Android 稳定性【篇一:日志调试技能汇总】

Android开发过程中调试和日志分析是必不可少的,当前汇总分析android系统不同类型的日志抓取的原理

qq_27672101的博客 1888

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: android studio platform使用体验分享(as无法跳转c/c++等native源码的福音,强烈推荐)
下一篇: ubunutu20/18/22 编译android 5相关的问题汇总-千里马framework开源代码平板编译过程
千里马学框架
博客等级 码龄6年 1万+粉丝 653原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址