From abc4b8f035c491f976be736373f50c3cac33a7a6 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 29 Feb 2016 13:35:59 -0800 Subject: [PATCH] Revert "InputConnectionWrapper never supports null target." This reverts commit 90bd36363c5738b3f526aa1f1d44f432236300a0. Seems that the semantics of InputConnectionWrapper#setTarget() is more complicated than I thought. At least the following cases have worked fine. case 1: InputConnectionWrapper wrapper = new InputConnectionWrapper(null, false); wrapper.SetTarget(ic); ... case 2: InputConnectionWrapper wrapper = new InputConnectionWrapper(null, true); wrapper.SetTarget(ic); ... case 3: InputConnectionWrapper wrapper = new InputConnectionWrapper(ic, true); wrapper.SetTarget(null); wrapper.SetTarget(ic2); ... The previous code did not intended to break existing code. Let's revert it we decide how to deal with above cases. Bug: 27407697 Change-Id: I8bc84d484ab0b27a02e74f11110430f70646e69a --- .../inputmethod/InputConnectionWrapper.java | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/core/java/android/view/inputmethod/InputConnectionWrapper.java b/core/java/android/view/inputmethod/InputConnectionWrapper.java index afa72a21eadab..65c7654c671b4 100644 --- a/core/java/android/view/inputmethod/InputConnectionWrapper.java +++ b/core/java/android/view/inputmethod/InputConnectionWrapper.java @@ -16,47 +16,33 @@ package android.view.inputmethod; -import android.annotation.NonNull; import android.os.Bundle; import android.os.Handler; import android.view.KeyEvent; -import static com.android.internal.util.Preconditions.checkNotNull; - /** *

Wrapper class for proxying calls to another InputConnection. Subclass * and have fun! */ public class InputConnectionWrapper implements InputConnection { - @NonNull private InputConnection mTarget; final boolean mMutable; - - /** - * Initializes the wrapper for the given {@link InputConnection}. - * @param target the {@link InputConnection} to be wrapped. - * @param mutable {@code true} if the wrapper is to be mutable. - * @throws NullPointerException if {@code target} is {@code null}. - */ - public InputConnectionWrapper(@NonNull InputConnection target, boolean mutable) { - checkNotNull(target); + + public InputConnectionWrapper(InputConnection target, boolean mutable) { mMutable = mutable; mTarget = target; } /** * Change the target of the input connection. - * @param target the {@link InputConnection} to be wrapped. - * @throws NullPointerException if {@code target} is {@code null}. */ - public void setTarget(@NonNull InputConnection target) { - checkNotNull(target); + public void setTarget(InputConnection target) { if (mTarget != null && !mMutable) { throw new SecurityException("not mutable"); } mTarget = target; } - + public CharSequence getTextBeforeCursor(int n, int flags) { return mTarget.getTextBeforeCursor(n, flags); }