Merge "Refactor InkWindow lifetime" into udc-qpr-dev am: 1139a889d5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24138936

Change-Id: I23b3d071ecd1cf5ecbbea64474486206ffec3993
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Taran Singh
2023-07-26 05:33:41 +00:00
committed by Automerger Merge Worker

View File

@@ -807,9 +807,11 @@ public class InputMethodService extends AbstractInputMethodService {
onUnbindInput(); onUnbindInput();
mInputBinding = null; mInputBinding = null;
mInputConnection = null; mInputConnection = null;
// free-up cached InkWindow surface on detaching from current client.
if (mInkWindow != null) { if (mInkWindow != null) {
removeHandwritingInkWindow(); finishStylusHandwriting();
// free-up InkWindow surface after timeout.
scheduleStylusWindowIdleTimeout();
} }
} }
@@ -1020,6 +1022,7 @@ public class InputMethodService extends AbstractInputMethodService {
mOnPreparedStylusHwCalled = true; mOnPreparedStylusHwCalled = true;
} }
if (onStartStylusHandwriting()) { if (onStartStylusHandwriting()) {
cancelStylusWindowIdleTimeout();
mPrivOps.onStylusHandwritingReady(requestId, Process.myPid()); mPrivOps.onStylusHandwritingReady(requestId, Process.myPid());
} else { } else {
Log.i(TAG, "IME is not ready. Can't start Stylus Handwriting"); Log.i(TAG, "IME is not ready. Can't start Stylus Handwriting");
@@ -1109,7 +1112,7 @@ public class InputMethodService extends AbstractInputMethodService {
*/ */
@Override @Override
public void removeStylusHandwritingWindow() { public void removeStylusHandwritingWindow() {
InputMethodService.this.removeStylusHandwritingWindow(); InputMethodService.this.finishAndRemoveStylusHandwritingWindow();
} }
/** /**
@@ -2667,21 +2670,15 @@ public class InputMethodService extends AbstractInputMethodService {
* Typically, this is called when {@link InkWindow} should no longer be holding a surface in * Typically, this is called when {@link InkWindow} should no longer be holding a surface in
* memory. * memory.
*/ */
private void removeStylusHandwritingWindow() { private void finishAndRemoveStylusHandwritingWindow() {
cancelStylusWindowIdleTimeout();
mOnPreparedStylusHwCalled = false;
mStylusWindowIdleTimeoutRunnable = null;
if (mInkWindow != null) { if (mInkWindow != null) {
if (mHandwritingRequestId.isPresent()) { if (mHandwritingRequestId.isPresent()) {
// if handwriting session is still ongoing. This shouldn't happen. // if handwriting session is still ongoing. This shouldn't happen.
finishStylusHandwriting(); finishStylusHandwriting();
} }
removeHandwritingInkWindow();
}
}
private void removeHandwritingInkWindow() {
cancelStylusWindowIdleTimeout();
mOnPreparedStylusHwCalled = false;
mStylusWindowIdleTimeoutRunnable = null;
if (mInkWindow != null) {
mInkWindow.hide(true /* remove */); mInkWindow.hide(true /* remove */);
mInkWindow.destroy(); mInkWindow.destroy();
mInkWindow = null; mInkWindow = null;
@@ -2707,7 +2704,7 @@ public class InputMethodService extends AbstractInputMethodService {
private Runnable getStylusWindowIdleTimeoutRunnable() { private Runnable getStylusWindowIdleTimeoutRunnable() {
if (mStylusWindowIdleTimeoutRunnable == null) { if (mStylusWindowIdleTimeoutRunnable == null) {
mStylusWindowIdleTimeoutRunnable = () -> { mStylusWindowIdleTimeoutRunnable = () -> {
removeHandwritingInkWindow(); finishAndRemoveStylusHandwritingWindow();
mStylusWindowIdleTimeoutRunnable = null; mStylusWindowIdleTimeoutRunnable = null;
}; };
} }