This is a follow up CL to my previous CL [1], which caused an unexpected
side effect that leads the current IME to crash due to a too strict
requiremnt.
It turns out that it was too early for us to start requiring non-null
StartInputToken in InputMethodManagerService#setImeWindowStatus()
because in many places we have assumed that an IME can show/hide its
software keyboard even before an IME target window is associated with
the IME.
There are two major cases that we missed:
- InputMethodManager#showSoftInputFromInputMethod(IBinder, int):
This method does not require that the calling IME is already bound
to an IME target window.
- InputMethodManager#showSoftInputUnchecked(int ,ResultReceiver):
This @hide method allows the caller application to let current IME
show the software keyboard with bypassing all the normal focus
management tasks in InputMethodManager. We should seriously
consider to deprecate this @hide method, but to do that we have to
clean up some internal components and SearchView in the support
library that still rely on this method.
Bug
35395372 is triggered by the second scenario, but until we sort out
all the possible corner cases, we should allow null startInputToken as a
valid request, like we had have done so before the CL [1] introduced
such a validation.
[1]: I9921b381e02106dbffff5e0b3d13f0a1245ce807
6db3bfe33d92127d203ec872a0b353585a99f256
Test: Made sure Bug
35395372 is no longer reproducible, that is,
1. Flash a new image and complete the setup wizard on a
direct-boot unaware device.
2. Set a device password and require it upon each device boot.
3. adb reboot
4. Observe the default IME does not crash because of
InvalidParameterException thrown by IMMS.
Test: Made sure IMM#showSoftInputFromInputMethod(IBinder, int) does
not throw an InvalidParameterException even in an extreme case.
1. Rebuild LatinIME with the following code in LatinIME.java
@Override
public AbstractInputMethodImpl onCreateInputMethodInterface() {
return new InputMethodService.InputMethodImpl() {
@Override
public void attachToken(IBinder token) {
super.attachToken(token);
final InputMethodManager imm =
getSystemService(InputMethodManager.class);
final IBinder imeToken =
getWindow().getWindow().getAttributes().token;
imm.showSoftInputFromInputMethod(imeToken, 0);
}
};
}
2. adb install -r LatinIME.apk
3. adb shell ime enable com.android.inputmethod.latin/.LatinIME
4. adb shell ime set com.android.inputmethod.latin/.LatinIME
5. Tap any text field.
4. Observe LatinIME does not crash because of
InvalidParameterException thrown by IMMS.
Bug:
34628091
Bug:
35079353
Fixes:
35395372
Change-Id: Ib9448c551d9a30776a999c27a5ff20f1a095633a
* to corresponding API calls. Note that this state is not guaranteed
* to be synchronized with state in WindowManagerService.
* @param targetWindowToken token to identify the target window that the IME is associated with.
+ * {@code null} when application, system, or the IME itself decided to
+ * change its window visibility before being associated with any target
+ * window.
*/
- public abstract void updateInputMethodWindowStatus(IBinder imeToken, boolean imeWindowVisible,
- IBinder targetWindowToken);
+ public abstract void updateInputMethodWindowStatus(@NonNull IBinder imeToken,
+ boolean imeWindowVisible, @Nullable IBinder targetWindowToken);
/**
* Returns true when the hardware keyboard is available.
@Override
public void setImeWindowStatus(IBinder token, IBinder startInputToken, int vis,
int backDisposition) {
- if (startInputToken == null) {
- throw new InvalidParameterException("startInputToken cannot be null");
- }
-
if (!calledWithValidToken(token)) {
return;
}
final StartInputInfo info;
synchronized (mMethodMap) {
info = mStartInputMap.get(startInputToken);
- if (info == null) {
- throw new InvalidParameterException("Unknown startInputToken=" + startInputToken);
- }
mImeWindowVis = vis;
mBackDisposition = backDisposition;
updateSystemUiLocked(token, vis, backDisposition);
}
- mWindowManagerInternal.updateInputMethodWindowStatus(info.mImeToken,
- (vis & InputMethodService.IME_VISIBLE) != 0, info.mTargetWindow);
+ mWindowManagerInternal.updateInputMethodWindowStatus(token,
+ (vis & InputMethodService.IME_VISIBLE) != 0,
+ token != null ? info.mTargetWindow : null);
}
private void updateSystemUi(IBinder token, int vis, int backDisposition) {
}
@Override
- public void updateInputMethodWindowStatus(IBinder imeToken, boolean imeWindowVisible,
- IBinder targetWindowToken) {
+ public void updateInputMethodWindowStatus(@NonNull IBinder imeToken,
+ boolean imeWindowVisible, @Nullable IBinder targetWindowToken) {
// TODO (b/34628091): Use this method to address the window animation issue.
if (DEBUG_INPUT_METHOD) {
Slog.w(TAG_WM, "updateInputMethodWindowStatus: imeToken=" + imeToken