Search code examples
androidandroid-source

Disable mouse cursor inactivity hide


The default behavior when using an external mouse with Android is to hide the cursor/mouse pointer after ~15 seconds.

How can I disable this functionality, so the cursor is shown at all times?

I'm building from AOSP source.


Solution

  • Figured it out.

    The file to look in is:

    frameworks/base/services/input/PointerController.cpp
    

    The file on AndroidXRef

    The inactivity timeout is defined on line 39 (Android 4.2.2):

    static const nsecs_t INACTIVITY_TIMEOUT_DELAY_TIME_NORMAL = 15 * 1000 * 1000000LL; // 15 seconds
    

    The method used for fading the cursor:

    void PointerController::fade(Transition transition) {
        AutoMutex _l(mLock);
    
        // Remove the inactivity timeout, since we are fading now.
        removeInactivityTimeoutLocked();
    
        // Start fading.
        if (transition == TRANSITION_IMMEDIATE) {
            mLocked.pointerFadeDirection = 0;
            mLocked.pointerAlpha = 0.0f;
            updatePointerLocked();
        } else {
            mLocked.pointerFadeDirection = -1;
            startAnimationLocked();
        }
    }
    

    Commented out everything in the method except:

    removeInactivityTimeoutLocked();
    

    Since there's no point in having the inactivity timeout running in the background, when it isn't used.