InputMonitor notes, enableinputmonitor

Source: Internet
Author: User

InputMonitor notes, enableinputmonitor

The article only records your own understanding and is for your reference only.

1. mInputFocus

WMS. addWindow () --> WMS. finishUpdateFocusedWindowAfterAssignLayersLocked () --> InputMonitor. setInputFocusLw () --> mInputFocus = newWindow;

When you add a window, the focus window will be searched again and saved in WMS. mCurrentFocus. The focus window will also be saved to InputMonitor. mInputFocus. Key code:

<span style="font-size:18px;">addWindow(){            ……            boolean focusChanged = false;            if (win.canReceiveKeys()) {                focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,                        false /*updateInputWindows*/);                if (focusChanged) {                    imMayMove = false;                }            }            if (imMayMove) {                moveInputMethodWindowsIfNeededLocked(false);            }            assignLayersLocked(displayContent.getWindowList());            // Don't do layout here, the window must call            // relayout to be displayed, so we'll do it there.            if (focusChanged) {                finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);            }            mInputMonitor.updateInputWindowsLw(false /*force*/);           …………}</span>
Although these lines of code are short, the logic is simple, but many methods are called. For canReceiveKeys () functions:

<span style="font-size:18px;">public final boolean canReceiveKeys() {        return isVisibleOrAdding()                && (mViewVisibility == View.VISIBLE)                && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);    }</span>

If the WindowManager. LayoutParams. FLAG_NOT_FOCUSABLE attribute is set in the window, the window cannot obtain the focus. That is, canReceiveKeys () returns false, which means that the focus window will not be changed. For floating windows, focus is not required. Therefore, the WindowManager. LayoutParams. FLAG_NOT_FOCUSABLE attribute is usually set. Otherwise, some problems may occur. If the window can accept the key event (this key event is a bit ambiguous, rather than only the button event), call updateFocusedWindowLocked () and study it later. If the focus window changes, call moveInputMethodWindowsIfNeededLocked (false) to move the input window to a proper position.

The window saved in mInputFocus is finally set to InputDispatcher. mfocused#whandle when InputMonitor. updateInputWindowsLw () is called.

2. mInputDispatchFrozen

Freeze the InputDispatcher flag, "When true, prevents input dispatch from proceeding until set to false again .".

① WMS. startFreezingDisplayLocked () --> InputMonitor. freezeInputDispatchingLw () --> mInputDispatchFrozen = true; updateInputDispatchModeLw ();

② WMS. stopFreezingDisplayLocked () --> InputMonitor. thawInputDispatchingLw () --> mInputDispatchFrozen = false; updateInputDispatchModeLw (); --> InputManagerService. setInputDispatchMode () --> InputDispatcher. setInputDispatchMode (bool enabled, bool frozen) --> mDispatchFrozen = frozen;

<span style="font-size:18px;">void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {    nsecs_t currentTime = now();    // Reset the key repeat timer whenever we disallow key events, even if the next event    // is not a key.  This is to ensure that we abort a key repeat if the device is just coming    // out of sleep.    if (!mPolicy->isKeyRepeatEnabled()) {        resetKeyRepeatLocked();    }    // If dispatching is frozen, do not process timeouts or try to deliver any new events.    if (mDispatchFrozen) {#if DEBUG_FOCUS        ALOGD("Dispatch frozen.  Waiting some more.");#endif        return;}……….}</span>
When dispatchOnceInnerLocked () is called to distribute events, return directly. The call logic above shows that the InputDispatcher distribution process will be frozen when the screen is frozen/restored.

3. mInputDispatchEnabled

A java layer controls the InputDispatcher switch.

① WMS. setEventDispatching () --> InputMonitor. setEventDispatchingLw ()

② WMS. performEnableScreen () --> InputMonitor. setEventDispatchingLw () --> mInputDispatchEnabled = enabled; updateInputDispatchModeLw (); --> InputManagerService. setInputDispatchMode () --> InputDispatcher. setInputDispatchMode (bool enabled, bool frozen) --> mDispatchEnabled = enabled;

How can I enable InputDispatcher?

<span style="font-size:18px;">if (!mDispatchEnabled) {        dropReason = DROP_REASON_DISABLED;    }</span>
DropReason is set in dispatchOnceInnerLocked (). If dropReason is not set to 0, the input event is discarded and not distributed.
Google's source code explains this as follows: "When true, input dispatch proceeds normally. otherwise all events are dropped. initially false, so that input does not get dispatched until boot is finished at which point the ActivityManager will enable dispatching."

4. mUpdateInputWindowsNeeded

Whether to update the flag from the window information to InputDispatcher. To update window information to InputDispatcher, you must first call InputMonitor. setUpdateInputWindowsNeededLw () to set the flag, and then call InputMonitor. updateInputWindowsLw (). You do not need to set this variable when you forcibly update the window information to InputDispatcher.

5. notifyInputChannelBroken ()

InputManager notifies WMS of the broken function of the input channel.

<span style="font-size:18px;">    public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {        if (inputWindowHandle == null) {            return;        }        synchronized (mService.mWindowMap) {            WindowState windowState = (WindowState) inputWindowHandle.windowState;            if (windowState != null) {                Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState);                mService.removeWindowLocked(windowState.mSession, windowState);            }        }    }</span>
The function processing logic is very simple, that is, to directly call removeWindowLocked () to remove the window with a broken input channel.
Call process: InputDispatcher. startdispatchpolicelocked () --> InputDispatcher. abortbrokendispatchpolicelocked () --> InputDispatcher. onDispatchCycleBrokenLocked () --> InputDispatcher. doNotifyInputChannelBrokenLockedInterruptible () --> NativeInputManager. policyinputchannelbroken () --> InputManagerService. policyinputchannelbroken () --> InputMonitor. notifyInputChannelBroken ();

If the publish event in startdispatchreceivelocked () fails, the following logic is displayed:

<span style="font-size:18px;">        if (status) {            if (status == WOULD_BLOCK) {                if (connection->waitQueue.isEmpty()) {                    ALOGE("channel '%s' ~ Could not publish event because the pipe is full. "                            "This is unexpected because the wait queue is empty, so the pipe "                            "should be empty and we shouldn't have any problems writing an "                            "event to it, status=%d", connection->getInputChannelName(), status);                    abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/);                } else {                    // Pipe is full and we are waiting for the app to finish process some events                    // before sending more events to it.#if DEBUG_DISPATCH_CYCLE                    ALOGD("channel '%s' ~ Could not publish event because the pipe is full, "                            "waiting for the application to catch up",                            connection->getInputChannelName());#endif                    connection->inputPublisherBlocked = true;                }            } else {                ALOGE("channel '%s' ~ Could not publish event due to an unexpected error, "                        "status=%d", connection->getInputChannelName(), status);                abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/);            }            return;        }</span>
In normal pipe full mode, abortbrokendispatchreceivelocked () is not called. In other cases, abortbrokendispatchreceivelocked () is called for processing.

<span style="font-size:18px;">void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime,        const sp<Connection>& connection, bool notify) {#if DEBUG_DISPATCH_CYCLE    ALOGD("channel '%s' ~ abortBrokenDispatchCycle - notify=%s",            connection->getInputChannelName(), toString(notify));#endif    // Clear the dispatch queues.    drainDispatchQueueLocked(&connection->outboundQueue);    traceOutboundQueueLengthLocked(connection);    drainDispatchQueueLocked(&connection->waitQueue);    traceWaitQueueLengthLocked(connection);    // The connection appears to be unrecoverably broken.    // Ignore already broken or zombie connections.    if (connection->status == Connection::STATUS_NORMAL) {        connection->status = Connection::STATUS_BROKEN;        if (notify) {            // Notify other system components.            onDispatchCycleBrokenLocked(currentTime, connection);        }    }}</span>
The function clears messages in the outboundQueue and waitQueue queues, and then calls onDispatchCycleBrokenLocked () -->... to notify WMS to remove the corresponding window.

OutboundQueue: Queue of events that need to be published to the connection.

WaitQueue: Queue of events that have been published to the connection but that have not yet has ed a "finished" response from the application.
The input event is delivered successfully only when the finished message that receives the application response is sent.

6. notifyANR ()

The source code comments to this function are already very clear:

<span style="font-size:18px;">/* Notifies the window manager about an application that is not responding.     * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.     *      * Called by the InputManager.</span>

Call process: InputDispatcher. findFocusedWindowTargetsLocked (); InputDispatcher. findTouchedWindowTargetsLocked () --> InputDispatcher. handleTargetsNotReadyLocked () --> InputDispatcher. onANRLocked () --> InputDispatcher. doNotifyANRLockedInterruptible () --> NativeInputManager. notifyANR () --> InputManagerService. notifyANR () --> InputMonitor. notifyANR ();

The handler () and findTouchedWindowTargetsLocked () functions of InputDispatcher have many exceptions. The target window is not ready to accept events. In this case, handleTargetsNotReadyLocked () must be called to handle the event () wait for a certain period of time. If the final timeout occurs, onANRLocked () is called to report ANR.

InputDispatcher. mongoyanr () function processing is also very simple, and will eventually call ActivityManagerNative. getDefault (). inputDispatchingTimedOut (windowState. mSession. mPid, aboveSystem, reason); to pull an ANR dialog box.

7. interceptKeyBeforeQueueing (), interceptKeyBeforeDispatching ()

① InputDispatcher. policykey () --> NativeInputManager. interceptKeyBeforeQueueing () --> InputManagerService. Handle () --> InputMonitor. Handle () --> PhoneWindowManager. Handle ()

② InputDispatcher. dispatchKeyLocked () --> InputDispatcher. doInterceptKeyBeforeDispatchingLockedInterruptible () --> NativeInputManager. interceptKeyBeforeDispatching () --> InputManagerService. interceptKeyBeforeDispatching () --> InputMonitor. interceptKeyBeforeDispatching () --> PhoneWindowManager. interceptKeyBeforeDispatching ()

From the perspective of the function name and calling process, one is called before joining the queue, and the other is called during delivery. The power key event goes through one of these two functions.

8. interceptMotionBeforeQueueingWhenScreenOff ()

InputDispatcher. policymotion () --> NativeInputManager. interceptMotionBeforeQueueing () --> InputManagerService. Handle () --> InputMonitor. Handle () --> PhoneWindowManager. Handle ()

<span style="font-size:18px;">void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {    // Policy:    // - Ignore untrusted events and pass them along.    // - No special filtering for injected events required at this time.    // - Filter normal events based on screen state.    // - For normal events brighten (but do not wake) the screen if currently dim.    if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {        if (isScreenOn()) {            policyFlags |= POLICY_FLAG_PASS_TO_USER;            if (!isScreenBright()) {                policyFlags |= POLICY_FLAG_BRIGHT_HERE;            }        } else {            JNIEnv* env = jniEnv();            jint wmActions = env->CallIntMethod(mServiceObj,                        gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,                        policyFlags);            if (checkAndClearExceptionFromCallback(env,                    "interceptMotionBeforeQueueingWhenScreenOff")) {                wmActions = 0;            }            policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;            handleInterceptActions(wmActions, when, /*byref*/ policyFlags);        }    } else {        policyFlags |= POLICY_FLAG_PASS_TO_USER;    }}</span>
When the received input event comes from the device rather than the event injected by the upper-layer application, if the screen is in the off-screen status, the interceptMotionBeforeQueueingWhenScreenOff () function is called for processing.

9. pauseDispatchingLw () and resumeDispatchingLw ()

These two functions are very simple: Set WindowToken. paused and force update to InputDispatcher.

<span style="font-size:18px;">    public void pauseDispatchingLw(WindowToken window) {        if (! window.paused) {            if (WindowManagerService.DEBUG_INPUT) {                Slog.v(WindowManagerService.TAG, "Pausing WindowToken " + window);            }                        window.paused = true;            updateInputWindowsLw(true /*force*/);        }    }        public void resumeDispatchingLw(WindowToken window) {        if (window.paused) {            if (WindowManagerService.DEBUG_INPUT) {                Slog.v(WindowManagerService.TAG, "Resuming WindowToken " + window);            }                        window.paused = false;            updateInputWindowsLw(true /*force*/);        }    }</span>
In InputDispatcher, if the target window found in findFocusedWindowTargetsLocked () and findTouchedWindowTargetsLocked () is in the paused state, handleTargetsNotReadyLocked () is called to wait.
<span style="font-size:18px;">if (touchedWindow.windowHandle->getInfo()->paused) {                injectionResult = handleTargetsNotReadyLocked(currentTime, entry,                        NULL, touchedWindow.windowHandle, nextWakeupTime,                        "Waiting because the touched window is paused.");                goto Unresponsive;            }</span>
.


A laptop needs to be connected to a TV. Only the VIDEMO, AV1, AV2, MONITOR, AUDIO, SVHS, INPUT, and out put interfaces are available on the TV. What should I do?

There is an SVIDEO interface on the notebook. You need to find the root VIDEO line. Generally, a TV or notebook is equipped with an SVIDEO interface for one notebook, and one is inserted into the MONITOR. If not, try another jack, I can't remember it. I should have done it.

Input monitor cannot be adjusted !!

Are you an HD sound card?

Download and install this patch.

: Microsoft HD Audio bus driver (kb888111)

Www.52z.com/soft/12900.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.