Merge "InputConnectionWrapper never supports null target." into nyc-dev
am: 82197c33a2
* commit '82197c33a23a130acd93dcf54e70138a7e7ba970':
InputConnectionWrapper never supports null target.
This commit is contained in:
@@ -16,33 +16,47 @@
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>Wrapper class for proxying calls to another InputConnection. Subclass
|
||||
* and have fun!
|
||||
*/
|
||||
public class InputConnectionWrapper implements InputConnection {
|
||||
@NonNull
|
||||
private InputConnection mTarget;
|
||||
final boolean mMutable;
|
||||
|
||||
public InputConnectionWrapper(InputConnection target, boolean mutable) {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
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(InputConnection target) {
|
||||
public void setTarget(@NonNull InputConnection target) {
|
||||
checkNotNull(target);
|
||||
if (mTarget != null && !mMutable) {
|
||||
throw new SecurityException("not mutable");
|
||||
}
|
||||
mTarget = target;
|
||||
}
|
||||
|
||||
|
||||
public CharSequence getTextBeforeCursor(int n, int flags) {
|
||||
return mTarget.getTextBeforeCursor(n, flags);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user