Handle non-initalized InkWindow

With [1] we changed the lifecycle of InkWindow to be short lived and
missed certain cases.

This also fixes CTS testStylusSession_fingerTriggersNavbarGestures

Bug: 243571274
Test: atest StylusHandwritingTest

[1]: Icd3eea91fe144cff7100d3ecf19191c064c0d196

This is a retry for I1593ff10a5520aadb5ed86a4a09f2405ee65c321

Change-Id: Ibf54599f41ac13121215c5344eb92ecca3259db1
This commit is contained in:
Taran Singh
2022-09-23 18:56:32 +00:00
parent 9aaeeb3673
commit b4fa71513c
2 changed files with 21 additions and 13 deletions

View File

@@ -163,6 +163,9 @@ final class InkWindow extends PhoneWindow {
mGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (mInkView == null) {
return;
}
if (mInkView.isVisibleToUser()) {
if (mInkViewVisibilityListener != null) {
mInkViewVisibilityListener.onInkViewVisible();

View File

@@ -962,7 +962,7 @@ public class InputMethodService extends AbstractInputMethodService {
Log.d(TAG, "Input should have started before starting Stylus handwriting.");
return;
}
maybeCreateInkWindow();
maybeCreateAndInitInkWindow();
if (!mOnPreparedStylusHwCalled) {
// prepare hasn't been called by Stylus HOVER.
onPrepareStylusHandwriting();
@@ -1022,21 +1022,21 @@ public class InputMethodService extends AbstractInputMethodService {
*/
@Override
public void initInkWindow() {
maybeCreateInkWindow();
mInkWindow.initOnly();
maybeCreateAndInitInkWindow();
onPrepareStylusHandwriting();
mOnPreparedStylusHwCalled = true;
}
/**
* Create and attach token to Ink window if it wasn't already created.
* Create, attach token and layout Ink window if it wasn't already created.
*/
private void maybeCreateInkWindow() {
private void maybeCreateAndInitInkWindow() {
if (mInkWindow == null) {
mInkWindow = new InkWindow(mWindow.getContext());
mInkWindow.setToken(mToken);
}
// TODO(b/243571274): set an idle-timeout after which InkWindow is removed.
mInkWindow.initOnly();
}
/**
@@ -2464,21 +2464,26 @@ public class InputMethodService extends AbstractInputMethodService {
* @param motionEvent {@link MotionEvent} from stylus.
*/
public void onStylusHandwritingMotionEvent(@NonNull MotionEvent motionEvent) {
if (mInkWindow.isInkViewVisible()) {
if (mInkWindow != null && mInkWindow.isInkViewVisible()) {
mInkWindow.getDecorView().dispatchTouchEvent(motionEvent);
} else {
if (mPendingEvents == null) {
mPendingEvents = new RingBuffer(MotionEvent.class, MAX_EVENTS_BUFFER);
}
mPendingEvents.append(motionEvent);
mInkWindow.setInkViewVisibilityListener(() -> {
if (mPendingEvents != null && !mPendingEvents.isEmpty()) {
for (MotionEvent event : mPendingEvents.toArray()) {
mInkWindow.getDecorView().dispatchTouchEvent(event);
if (mInkWindow != null) {
mInkWindow.setInkViewVisibilityListener(() -> {
if (mPendingEvents != null && !mPendingEvents.isEmpty()) {
for (MotionEvent event : mPendingEvents.toArray()) {
if (mInkWindow == null) {
break;
}
mInkWindow.getDecorView().dispatchTouchEvent(event);
}
mPendingEvents.clear();
}
mPendingEvents.clear();
}
});
});
}
}
}