Remove ImeFocusController#set{Served, NextServed}View

As ImeFocusController#set{Served, NextServed}View originally exposes to
InputMethodManager is only for clearing the served view in
IMM#finishInputLocked() with a special code logic:

```
  setNextServedView(null);
  if (getServedView() != null) {
      // do finish input
     setServedView(null);
  }
```

which isn't necessary and can be clean-up with a method to notify
ImeFocusController to clear the served / next served view, then doing
the rest of finshing logic when the method has cleared the served view:

```
if (controller.clearServedViewsLocked() != null) {
    // do finish input
}
```

With this change, we can simply remove the set{Served, NextServed}View
to get rid of this dependency with InputMethodManager.

Bug: 244504062
Test: atest CtsInputMethodTestCases

Change-Id: Ibcde35765c0e2e6c372aa64dbc7e774a8d860543
This commit is contained in:
Ming-Shin Lu
2022-09-03 00:52:04 +08:00
parent 31e4678463
commit 6924863b37
2 changed files with 21 additions and 26 deletions

View File

@@ -328,14 +328,23 @@ public final class ImeFocusController {
return mNextServedView;
}
// TODO(b/244504062): Remove this method dependency from InputMethodManager.
public void setServedViewLocked(View view) {
mServedView = view;
}
// TODO(b/244504062): Remove this method dependency from InputMethodManager.
public void setNextServedViewLocked(View view) {
mNextServedView = view;
/**
* Clears the served & the next served view when the controller triggers
* {@link InputMethodManagerDelegate#finishInput()} or
* {@link InputMethodManagerDelegate#finishInputAndReportToIme()}.
* Note that this method requires to be called inside {@code InputMethodManager#mH} lock for
* data consistency.
*
* @return The {@code mServedView} that has cleared, or {@code null} means nothing to clear.
*/
public View clearServedViewsLocked() {
View clearedView = null;
mNextServedView = null;
if (mServedView != null) {
clearedView = mServedView;
mServedView = null;
}
return clearedView;
}
/**

View File

@@ -933,20 +933,6 @@ public final class InputMethodManager {
: null;
}
@GuardedBy("mH")
private void setServedViewLocked(View view) {
if (mCurRootView != null) {
mCurRootView.getImeFocusController().setServedViewLocked(view);
}
}
@GuardedBy("mH")
private void setNextServedViewLocked(View view) {
if (mCurRootView != null) {
mCurRootView.getImeFocusController().setNextServedViewLocked(view);
}
}
private ImeFocusController getFocusController() {
synchronized (mH) {
if (mCurRootView != null) {
@@ -1793,13 +1779,13 @@ public final class InputMethodManager {
@GuardedBy("mH")
void finishInputLocked() {
mVirtualDisplayToScreenMatrix = null;
setNextServedViewLocked(null);
if (getServedViewLocked() != null) {
final ImeFocusController controller = getFocusController();
final View clearedView = controller != null ? controller.clearServedViewsLocked() : null;
if (clearedView != null) {
if (DEBUG) {
Log.v(TAG, "FINISH INPUT: mServedView="
+ InputMethodDebug.dumpViewInfo(getServedViewLocked()));
+ InputMethodDebug.dumpViewInfo(clearedView));
}
setServedViewLocked(null);
mCompletions = null;
mServedConnecting = false;
clearConnectionLocked();