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

Commit 9f9afe52 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Add IC#closeConnection().

It turns out that BaseInputConnection has still depended on a private
API named BaseInputConnection#reportFinish(), which was introduced
4 years ago to work around a UI freeze due to an unbalanced batch edit
count [1].  Note that such an unbalanced batch edit count cannot always
be avoidable.  It can easily occur in the following situations.
 - The current IME crashed during batch edit.
 - The user changed the View focus during batch edit.
 - The current IME called IMM#switchToNextInputMethod() during batch
   edit.

The remaining problem is that #reportFinish() is still an internal API
and only subclasses of BaseInputConnection can implement it, and IMM
calls it when and only when the current InputConnection is
BaseInputConnection or its subclass.  InputConnectionWrapper and any
other InputConnection implementations will never receive such a callback
to clean up InputConnection#{begin, end}BatchEdit(), which is considered
to be a major contributor to UI freeze.

To address the above issue, we unhide BaseInputConnection#reportFinish()
as InputConnection#closeConnection() so that application developers can
receive an appropriate callback to clean up internal state including
unfinished batch edit.

  [1] I5525d776916f0c42d5e6d4a4282aed590d7f0e9a
      9d69ecbf

Bug: 24688781
Bug: 25332806
Change-Id: I234309c5880c9fe0b299b8bd0f8862796d4dda0d
parent 0caf007b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -44641,6 +44641,7 @@ package android.view.inputmethod {
    ctor public BaseInputConnection(android.view.View, boolean);
    method public boolean beginBatchEdit();
    method public boolean clearMetaKeyStates(int);
    method public void closeConnection();
    method public boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public boolean commitText(java.lang.CharSequence, int);
@@ -44808,6 +44809,7 @@ package android.view.inputmethod {
  public abstract interface InputConnection {
    method public abstract boolean beginBatchEdit();
    method public abstract boolean clearMetaKeyStates(int);
    method public abstract void closeConnection();
    method public abstract boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public abstract boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public abstract boolean commitText(java.lang.CharSequence, int);
@@ -44840,6 +44842,7 @@ package android.view.inputmethod {
    ctor public InputConnectionWrapper(android.view.inputmethod.InputConnection, boolean);
    method public boolean beginBatchEdit();
    method public boolean clearMetaKeyStates(int);
    method public void closeConnection();
    method public boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public boolean commitText(java.lang.CharSequence, int);
@@ -66433,3 +66436,4 @@ package org.xmlpull.v1.sax2 {
  }
}
+4 −0
Original line number Diff line number Diff line
@@ -47370,6 +47370,7 @@ package android.view.inputmethod {
    ctor public BaseInputConnection(android.view.View, boolean);
    method public boolean beginBatchEdit();
    method public boolean clearMetaKeyStates(int);
    method public void closeConnection();
    method public boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public boolean commitText(java.lang.CharSequence, int);
@@ -47537,6 +47538,7 @@ package android.view.inputmethod {
  public abstract interface InputConnection {
    method public abstract boolean beginBatchEdit();
    method public abstract boolean clearMetaKeyStates(int);
    method public abstract void closeConnection();
    method public abstract boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public abstract boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public abstract boolean commitText(java.lang.CharSequence, int);
@@ -47569,6 +47571,7 @@ package android.view.inputmethod {
    ctor public InputConnectionWrapper(android.view.inputmethod.InputConnection, boolean);
    method public boolean beginBatchEdit();
    method public boolean clearMetaKeyStates(int);
    method public void closeConnection();
    method public boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public boolean commitText(java.lang.CharSequence, int);
@@ -69498,3 +69501,4 @@ package org.xmlpull.v1.sax2 {
  }
}
+4 −0
Original line number Diff line number Diff line
@@ -44715,6 +44715,7 @@ package android.view.inputmethod {
    ctor public BaseInputConnection(android.view.View, boolean);
    method public boolean beginBatchEdit();
    method public boolean clearMetaKeyStates(int);
    method public void closeConnection();
    method public boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public boolean commitText(java.lang.CharSequence, int);
@@ -44882,6 +44883,7 @@ package android.view.inputmethod {
  public abstract interface InputConnection {
    method public abstract boolean beginBatchEdit();
    method public abstract boolean clearMetaKeyStates(int);
    method public abstract void closeConnection();
    method public abstract boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public abstract boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public abstract boolean commitText(java.lang.CharSequence, int);
@@ -44914,6 +44916,7 @@ package android.view.inputmethod {
    ctor public InputConnectionWrapper(android.view.inputmethod.InputConnection, boolean);
    method public boolean beginBatchEdit();
    method public boolean clearMetaKeyStates(int);
    method public void closeConnection();
    method public boolean commitCompletion(android.view.inputmethod.CompletionInfo);
    method public boolean commitCorrection(android.view.inputmethod.CorrectionInfo);
    method public boolean commitText(java.lang.CharSequence, int);
@@ -66507,3 +66510,4 @@ package org.xmlpull.v1.sax2 {
  }
}
+5 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view.inputmethod;

import android.annotation.CallSuper;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
@@ -154,12 +155,11 @@ public class BaseInputConnection implements InputConnection {
    }

    /**
     * Called when this InputConnection is no longer used by the InputMethodManager.
     *
     * @hide
     * Default implementation calls {@link #finishComposingText()}.
     */
    public void reportFinish() {
        // Intentionally empty
    @CallSuper
    public void closeConnection() {
        finishComposingText();
    }

    /**
+16 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ import android.view.KeyEvent;
 *     was introduced in {@link android.os.Build.VERSION_CODES#N}.</li>
 *     <li>{@link #getHandler()}}, which was introduced in
 *     {@link android.os.Build.VERSION_CODES#N}.</li>
 *     <li>{@link #closeConnection()}}, which was introduced in
 *     {@link android.os.Build.VERSION_CODES#N}.</li>
 * </ul>
 *
 * <h3>Implementing an IME or an editor</h3>
@@ -820,4 +822,18 @@ public interface InputConnection {
     * @return {@code null} to use the default {@link Handler}.
     */
    public Handler getHandler();

    /**
     * Called by the system up to only once to notify that the system is about to invalidate
     * connection between the input method and the application.
     *
     * <p><strong>Editor authors</strong>: You can clear all the nested batch edit right now and
     * you no longer need to handle subsequent callbacks on this connection, including
     * {@link #beginBatchEdit()}}.  Note that although the system tries to call this method whenever
     * possible, there may be a chance that this method is not called in some exceptional
     * situations.</p>
     *
     * <p>Note: This does nothing when called from input methods.</p>
     */
    public void closeConnection();
}
Loading