Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc8b3565 authored by Kelly Rossmoyer's avatar Kelly Rossmoyer Committed by Automerger Merge Worker
Browse files

Merge "Revert "Fix input infos are inconsistent between WMS and InputFlinger...

Merge "Revert "Fix input infos are inconsistent between WMS and InputFlinger (1/2)"" into rvc-dev am: 41806b24 am: 27a075aa

Change-Id: I106b12acd2085fd594acec3f0bca4eddea56e444
parents 988d2fb6 27a075aa
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -76,6 +76,7 @@ import android.view.InputChannel;
import android.view.InputDevice;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputEvent;
import android.view.InputMonitor;
import android.view.InputMonitor;
import android.view.InputWindowHandle;
import android.view.KeyEvent;
import android.view.KeyEvent;
import android.view.PointerIcon;
import android.view.PointerIcon;
import android.view.Surface;
import android.view.Surface;
@@ -220,7 +221,8 @@ public class InputManagerService extends IInputManager.Stub
            int policyFlags);
            int policyFlags);
    private static native VerifiedInputEvent nativeVerifyInputEvent(long ptr, InputEvent event);
    private static native VerifiedInputEvent nativeVerifyInputEvent(long ptr, InputEvent event);
    private static native void nativeToggleCapsLock(long ptr, int deviceId);
    private static native void nativeToggleCapsLock(long ptr, int deviceId);
    private static native void nativeDisplayRemoved(long ptr, int displayId);
    private static native void nativeSetInputWindows(long ptr, InputWindowHandle[] windowHandles,
            int displayId);
    private static native void nativeSetInputDispatchMode(long ptr, boolean enabled, boolean frozen);
    private static native void nativeSetInputDispatchMode(long ptr, boolean enabled, boolean frozen);
    private static native void nativeSetSystemUiVisibility(long ptr, int visibility);
    private static native void nativeSetSystemUiVisibility(long ptr, int visibility);
    private static native void nativeSetFocusedApplication(long ptr,
    private static native void nativeSetFocusedApplication(long ptr,
@@ -1534,7 +1536,7 @@ public class InputManagerService extends IInputManager.Stub


    /** Clean up input window handles of the given display. */
    /** Clean up input window handles of the given display. */
    public void onDisplayRemoved(int displayId) {
    public void onDisplayRemoved(int displayId) {
        nativeDisplayRemoved(mPtr, displayId);
        nativeSetInputWindows(mPtr, null /* windowHandles */, displayId);
    }
    }


    @Override
    @Override
+9 −12
Original line number Original line Diff line number Diff line
@@ -62,7 +62,7 @@ final class InputMonitor {
    // When true, need to call updateInputWindowsLw().
    // When true, need to call updateInputWindowsLw().
    private boolean mUpdateInputWindowsNeeded = true;
    private boolean mUpdateInputWindowsNeeded = true;
    private boolean mUpdateInputWindowsPending;
    private boolean mUpdateInputWindowsPending;
    private boolean mUpdateInputWindowsImmediately;
    private boolean mApplyImmediately;


    // Currently focused input window handle.
    // Currently focused input window handle.
    private InputWindowHandle mFocusedInputWindowHandle;
    private InputWindowHandle mFocusedInputWindowHandle;
@@ -347,20 +347,14 @@ final class InputMonitor {
        }
        }
    }
    }


    /**
    void updateInputWindowsImmediately() {
     * Immediately update the input transaction and merge into the passing Transaction that could be
     * collected and applied later.
     */
    void updateInputWindowsImmediately(SurfaceControl.Transaction t) {
        mHandler.removeCallbacks(mUpdateInputWindows);
        mHandler.removeCallbacks(mUpdateInputWindows);
        mUpdateInputWindowsImmediately = true;
        mApplyImmediately = true;
        mUpdateInputWindows.run();
        mUpdateInputWindows.run();
        mUpdateInputWindowsImmediately = false;
        mApplyImmediately = false;
        t.merge(mInputTransaction);
    }
    }


    /**
    /* Called when the current input focus changes.
     * Called when the current input focus changes.
     * Layer assignment is assumed to be complete by the time this is called.
     * Layer assignment is assumed to be complete by the time this is called.
     */
     */
    public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
    public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
@@ -471,7 +465,10 @@ final class InputMonitor {
            if (mAddWallpaperInputConsumerHandle) {
            if (mAddWallpaperInputConsumerHandle) {
                mWallpaperInputConsumer.show(mInputTransaction, 0);
                mWallpaperInputConsumer.show(mInputTransaction, 0);
            }
            }
            if (!mUpdateInputWindowsImmediately) {

            if (mApplyImmediately) {
                mInputTransaction.apply();
            } else {
                mDisplayContent.getPendingTransaction().merge(mInputTransaction);
                mDisplayContent.getPendingTransaction().merge(mInputTransaction);
                mDisplayContent.scheduleAnimation();
                mDisplayContent.scheduleAnimation();
            }
            }
+2 −3
Original line number Original line Diff line number Diff line
@@ -268,9 +268,8 @@ class TaskPositioner implements IBinder.DeathRecipient {
        mDisplayContent.getDisplayRotation().pause();
        mDisplayContent.getDisplayRotation().pause();


        // Notify InputMonitor to take mDragWindowHandle.
        // Notify InputMonitor to take mDragWindowHandle.
        final SurfaceControl.Transaction t = mService.mTransactionFactory.get();
        mDisplayContent.getInputMonitor().updateInputWindowsImmediately();
        mDisplayContent.getInputMonitor().updateInputWindowsImmediately(t);
        new SurfaceControl.Transaction().syncInputWindows().apply(true);
        t.syncInputWindows().apply();


        final DisplayMetrics displayMetrics = displayContent.getDisplayMetrics();
        final DisplayMetrics displayMetrics = displayContent.getDisplayMetrics();
        mMinVisibleWidth = dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
        mMinVisibleWidth = dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
+3 −7
Original line number Original line Diff line number Diff line
@@ -7746,23 +7746,19 @@ public class WindowManagerService extends IWindowManager.Stub
    public void syncInputTransactions() {
    public void syncInputTransactions() {
        waitForAnimationsToComplete();
        waitForAnimationsToComplete();


        // Collect all input transactions from all displays to make sure we could sync all input
        // windows at same time.
        final SurfaceControl.Transaction t = mTransactionFactory.get();
        synchronized (mGlobalLock) {
        synchronized (mGlobalLock) {
            mWindowPlacerLocked.performSurfacePlacementIfScheduled();
            mWindowPlacerLocked.performSurfacePlacementIfScheduled();
            mRoot.forAllDisplays(displayContent ->
            mRoot.forAllDisplays(displayContent ->
                    displayContent.getInputMonitor().updateInputWindowsImmediately(t));
                    displayContent.getInputMonitor().updateInputWindowsImmediately());
        }
        }


        t.syncInputWindows().apply();
        mTransactionFactory.get().syncInputWindows().apply(true);
    }
    }


    private void waitForAnimationsToComplete() {
    private void waitForAnimationsToComplete() {
        synchronized (mGlobalLock) {
        synchronized (mGlobalLock) {
            long timeoutRemaining = ANIMATION_COMPLETED_TIMEOUT_MS;
            long timeoutRemaining = ANIMATION_COMPLETED_TIMEOUT_MS;
            while ((mAnimator.isAnimationScheduled()
            while (mRoot.isAnimating(TRANSITION | CHILDREN) && timeoutRemaining > 0) {
                    || mRoot.isAnimating(TRANSITION | CHILDREN)) && timeoutRemaining > 0) {
                long startTime = System.currentTimeMillis();
                long startTime = System.currentTimeMillis();
                try {
                try {
                    mGlobalLock.wait(timeoutRemaining);
                    mGlobalLock.wait(timeoutRemaining);
+55 −8
Original line number Original line Diff line number Diff line
@@ -206,7 +206,7 @@ public:
    status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
    status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
    status_t pilferPointers(const sp<IBinder>& token);
    status_t pilferPointers(const sp<IBinder>& token);


    void displayRemoved(JNIEnv* env, int32_t displayId);
    void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray, int32_t displayId);
    void setFocusedApplication(JNIEnv* env, int32_t displayId, jobject applicationHandleObj);
    void setFocusedApplication(JNIEnv* env, int32_t displayId, jobject applicationHandleObj);
    void setFocusedDisplay(JNIEnv* env, int32_t displayId);
    void setFocusedDisplay(JNIEnv* env, int32_t displayId);
    void setInputDispatchMode(bool enabled, bool frozen);
    void setInputDispatchMode(bool enabled, bool frozen);
@@ -771,10 +771,55 @@ void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration
    }
    }
}
}


void NativeInputManager::displayRemoved(JNIEnv* env, int32_t displayId) {
void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray,
    // Set an empty list to remove all handles from the specific display.
         int32_t displayId) {
    std::vector<sp<InputWindowHandle> > windowHandles;
    std::vector<sp<InputWindowHandle> > windowHandles;
    mInputManager->getDispatcher()->setInputWindows({{displayId, windowHandles}});

    if (windowHandleObjArray) {
        jsize length = env->GetArrayLength(windowHandleObjArray);
        for (jsize i = 0; i < length; i++) {
            jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
            if (! windowHandleObj) {
                break; // found null element indicating end of used portion of the array
            }

            sp<InputWindowHandle> windowHandle =
                    android_view_InputWindowHandle_getHandle(env, windowHandleObj);
            if (windowHandle != nullptr) {
                windowHandles.push_back(windowHandle);
            }
            env->DeleteLocalRef(windowHandleObj);
        }
    }

    mInputManager->getDispatcher()->setInputWindows(windowHandles, displayId);

    // Do this after the dispatcher has updated the window handle state.
    bool newPointerGesturesEnabled = true;
    size_t numWindows = windowHandles.size();
    for (size_t i = 0; i < numWindows; i++) {
        const sp<InputWindowHandle>& windowHandle = windowHandles[i];
        const InputWindowInfo* windowInfo = windowHandle->getInfo();
        if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
                & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
            newPointerGesturesEnabled = false;
        }
    }

    bool pointerGesturesEnabledChanged = false;
    { // acquire lock
        AutoMutex _l(mLock);

        if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
            mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
            pointerGesturesEnabledChanged = true;
        }
    } // release lock

    if (pointerGesturesEnabledChanged) {
        mInputManager->getReader()->requestRefreshConfiguration(
                InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT);
    }
}
}


void NativeInputManager::setFocusedApplication(JNIEnv* env, int32_t displayId,
void NativeInputManager::setFocusedApplication(JNIEnv* env, int32_t displayId,
@@ -1522,10 +1567,11 @@ static void nativeToggleCapsLock(JNIEnv* env, jclass /* clazz */,
    im->getInputManager()->getReader()->toggleCapsLockState(deviceId);
    im->getInputManager()->getReader()->toggleCapsLockState(deviceId);
}
}


static void nativeDisplayRemoved(JNIEnv* env, jclass /* clazz */, jlong ptr, jint displayId) {
static void nativeSetInputWindows(JNIEnv* env, jclass /* clazz */,
        jlong ptr, jobjectArray windowHandleObjArray, jint displayId) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);


    im->displayRemoved(env, displayId);
    im->setInputWindows(env, windowHandleObjArray, displayId);
}
}


static void nativeSetFocusedApplication(JNIEnv* env, jclass /* clazz */,
static void nativeSetFocusedApplication(JNIEnv* env, jclass /* clazz */,
@@ -1769,7 +1815,8 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"nativeVerifyInputEvent", "(JLandroid/view/InputEvent;)Landroid/view/VerifiedInputEvent;",
        {"nativeVerifyInputEvent", "(JLandroid/view/InputEvent;)Landroid/view/VerifiedInputEvent;",
         (void*)nativeVerifyInputEvent},
         (void*)nativeVerifyInputEvent},
        {"nativeToggleCapsLock", "(JI)V", (void*)nativeToggleCapsLock},
        {"nativeToggleCapsLock", "(JI)V", (void*)nativeToggleCapsLock},
        {"nativeDisplayRemoved", "(JI)V", (void*)nativeDisplayRemoved},
        {"nativeSetInputWindows", "(J[Landroid/view/InputWindowHandle;I)V",
         (void*)nativeSetInputWindows},
        {"nativeSetFocusedApplication", "(JILandroid/view/InputApplicationHandle;)V",
        {"nativeSetFocusedApplication", "(JILandroid/view/InputApplicationHandle;)V",
         (void*)nativeSetFocusedApplication},
         (void*)nativeSetFocusedApplication},
        {"nativeSetFocusedDisplay", "(JI)V", (void*)nativeSetFocusedDisplay},
        {"nativeSetFocusedDisplay", "(JI)V", (void*)nativeSetFocusedDisplay},