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

Commit 2ae0de31 authored by Taran Singh's avatar Taran Singh Committed by Android (Google) Code Review
Browse files

Merge "Remove inkWindow after stylus idle-timeout"

parents 3afe48e0 cfef0232
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3145,6 +3145,7 @@ package android.view.inputmethod {
    method @NonNull @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public java.util.List<android.view.inputmethod.InputMethodInfo> getInputMethodListAsUser(int);
    method public boolean hasActiveInputConnection(@Nullable android.view.View);
    method public boolean isInputMethodPickerShown();
    method @RequiresPermission("android.permission.TEST_INPUT_METHOD") public void setStylusWindowIdleTimeoutForTest(long);
    field public static final long CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING = 214016041L; // 0xcc1a029L
  }

+17 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.inputmethodservice;

import android.annotation.BinderThread;
import android.annotation.DurationMillisLong;
import android.annotation.MainThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -82,6 +83,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
    private static final int DO_FINISH_STYLUS_HANDWRITING = 130;
    private static final int DO_UPDATE_TOOL_TYPE = 140;
    private static final int DO_REMOVE_STYLUS_HANDWRITING_WINDOW = 150;
    private static final int DO_SET_STYLUS_WINDOW_IDLE_TIMEOUT = 160;

    final WeakReference<InputMethodServiceInternal> mTarget;
    final Context mContext;
@@ -287,6 +289,10 @@ class IInputMethodWrapper extends IInputMethod.Stub
                }
                return;
            }
            case DO_SET_STYLUS_WINDOW_IDLE_TIMEOUT: {
                inputMethod.setStylusWindowIdleTimeoutForTest((long) msg.obj);
                return;
            }
        }
        Log.w(TAG, "Unhandled message code: " + msg.what);
    }
@@ -473,6 +479,13 @@ class IInputMethodWrapper extends IInputMethod.Stub
        mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_REMOVE_STYLUS_HANDWRITING_WINDOW));
    }

    @BinderThread
    @Override
    public void setStylusWindowIdleTimeoutForTest(@DurationMillisLong long timeout) {
        mCaller.executeOrSendMessage(
                mCaller.obtainMessageO(DO_SET_STYLUS_WINDOW_IDLE_TIMEOUT, timeout));
    }

    private static boolean isValid(InputMethod inputMethod, InputMethodServiceInternal target,
            String msg) {
        if (inputMethod != null && target != null && !target.isServiceDestroyed()) {
+57 −5
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.annotation.AnyThread;
import android.annotation.CallSuper;
import android.annotation.DrawableRes;
import android.annotation.DurationMillisLong;
import android.annotation.IntDef;
import android.annotation.MainThread;
import android.annotation.NonNull;
@@ -363,6 +364,11 @@ public class InputMethodService extends AbstractInputMethodService {
    private static final long STYLUS_HANDWRITING_IDLE_TIMEOUT_MAX_MS =
            STYLUS_HANDWRITING_IDLE_TIMEOUT_MS * 3;

    /**
     * Stylus idle-timeout after which stylus {@code InkWindow} will be removed.
     */
    private static final long STYLUS_WINDOW_IDLE_TIMEOUT_MILLIS = 5 * 60 * 1000; // 5 minutes.

    /**
     * A circular buffer of size MAX_EVENTS_BUFFER in case IME is taking too long to add ink view.
     **/
@@ -373,6 +379,8 @@ public class InputMethodService extends AbstractInputMethodService {
    private Runnable mImeSurfaceRemoverRunnable;
    private Runnable mFinishHwRunnable;
    private long mStylusHwSessionsTimeout = STYLUS_HANDWRITING_IDLE_TIMEOUT_MS;
    private Runnable mStylusWindowIdleTimeoutRunnable;
    private long mStylusWindowIdleTimeoutForTest;

    /**
     * Returns whether {@link InputMethodService} is responsible for rendering the back button and
@@ -1050,7 +1058,6 @@ public class InputMethodService extends AbstractInputMethodService {
                mInkWindow = new InkWindow(mWindow.getContext());
                mInkWindow.setToken(mToken);
            }
            // TODO(b/243571274): set an idle-timeout after which InkWindow is removed.
            mInkWindow.initOnly();
        }

@@ -1072,6 +1079,15 @@ public class InputMethodService extends AbstractInputMethodService {
            InputMethodService.this.removeStylusHandwritingWindow();
        }

        /**
         * {@inheritDoc}
         * @hide
         */
        @Override
        public void setStylusWindowIdleTimeoutForTest(@DurationMillisLong long timeout) {
            mStylusWindowIdleTimeoutForTest = timeout;
        }

        /**
         * {@inheritDoc}
         */
@@ -2508,6 +2524,11 @@ public class InputMethodService extends AbstractInputMethodService {
                });
            }
        }

        // Create a stylus window idle-timeout after which InkWindow is removed.
        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
            scheduleStylusWindowIdleTimeout();
        }
    }

    /**
@@ -2568,7 +2589,6 @@ public class InputMethodService extends AbstractInputMethodService {

        mHandwritingEventReceiver.dispose();
        mHandwritingEventReceiver = null;
        // TODO(b/243571274): set an idle-timeout after which InkWindow is removed.
        mInkWindow.hide(false /* remove */);

        mPrivOps.resetStylusHandwriting(requestId);
@@ -2592,10 +2612,42 @@ public class InputMethodService extends AbstractInputMethodService {
    }

    private void removeHandwritingInkWindow() {
        cancelStylusWindowIdleTimeout();
        mOnPreparedStylusHwCalled = false;
        mStylusWindowIdleTimeoutRunnable = null;
        if (mInkWindow != null) {
            mInkWindow.hide(true /* remove */);
            mInkWindow.destroy();
            mInkWindow = null;
        }
    }

    private void cancelStylusWindowIdleTimeout() {
        if (mStylusWindowIdleTimeoutRunnable != null && mHandler != null) {
            mHandler.removeCallbacks(mStylusWindowIdleTimeoutRunnable);
        }
    }

    private void scheduleStylusWindowIdleTimeout() {
        if (mHandler == null) {
            return;
        }
        cancelStylusWindowIdleTimeout();
        long timeout = (mStylusWindowIdleTimeoutForTest > 0)
                ? mStylusWindowIdleTimeoutForTest : STYLUS_WINDOW_IDLE_TIMEOUT_MILLIS;
        mHandler.postDelayed(getStylusWindowIdleTimeoutRunnable(), timeout);
    }

    private Runnable getStylusWindowIdleTimeoutRunnable() {
        if (mStylusWindowIdleTimeoutRunnable == null) {
            mStylusWindowIdleTimeoutRunnable = () -> {
                removeHandwritingInkWindow();
                mStylusWindowIdleTimeoutRunnable = null;
            };
        }

        return mStylusWindowIdleTimeoutRunnable;
    }

    /**
     * Sets the duration after which an ongoing stylus handwriting session that hasn't received new
+11 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view.inputmethod;

import android.annotation.AnyThread;
import android.annotation.DurationMillisLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -274,4 +275,14 @@ final class IInputMethodManagerInvoker {
            throw e.rethrowFromSystemServer();
        }
    }

    @AnyThread
    void setStylusWindowIdleTimeoutForTest(
            IInputMethodClient client, @DurationMillisLong long timeout) {
        try {
            mTarget.setStylusWindowIdleTimeoutForTest(client, timeout);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view.inputmethod;

import android.annotation.DurationMillisLong;
import android.annotation.MainThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -417,4 +418,12 @@ public interface InputMethod {
    default void removeStylusHandwritingWindow() {
        // intentionally empty
    }

    /**
     * Set a stylus idle-timeout after which handwriting {@code InkWindow} will be removed.
     * @hide
     */
    default void setStylusWindowIdleTimeoutForTest(@DurationMillisLong long timeout) {
        // intentionally empty
    }
}
Loading