IInputMethodWrapperpublic class IInputMethodWrapper extends IInputMethod.Stub implements HandlerCaller.CallbackImplements the internal IInputMethod interface to convert incoming calls
on to it back to calls on the public InputMethod interface, scheduling
them on the main thread of the process. |
Fields Summary |
---|
private static final String | TAG | private static final int | DO_DUMP | private static final int | DO_ATTACH_TOKEN | private static final int | DO_SET_INPUT_CONTEXT | private static final int | DO_UNSET_INPUT_CONTEXT | private static final int | DO_START_INPUT | private static final int | DO_RESTART_INPUT | private static final int | DO_CREATE_SESSION | private static final int | DO_SET_SESSION_ENABLED | private static final int | DO_REVOKE_SESSION | private static final int | DO_SHOW_SOFT_INPUT | private static final int | DO_HIDE_SOFT_INPUT | private static final int | DO_CHANGE_INPUTMETHOD_SUBTYPE | final WeakReference | mTarget | final android.content.Context | mContext | final com.android.internal.os.HandlerCaller | mCaller | final WeakReference | mInputMethod | final int | mTargetSdkVersion |
Constructors Summary |
---|
public IInputMethodWrapper(AbstractInputMethodService context, android.view.inputmethod.InputMethod inputMethod)
mTarget = new WeakReference<AbstractInputMethodService>(context);
mContext = context.getApplicationContext();
mCaller = new HandlerCaller(mContext, null, this, true /*asyncHandler*/);
mInputMethod = new WeakReference<InputMethod>(inputMethod);
mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion;
|
Methods Summary |
---|
public void | attachToken(android.os.IBinder token)
mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_ATTACH_TOKEN, token));
| public void | bindInput(android.view.inputmethod.InputBinding binding)
InputConnection ic = new InputConnectionWrapper(
IInputContext.Stub.asInterface(binding.getConnectionToken()));
InputBinding nu = new InputBinding(ic, binding);
mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_INPUT_CONTEXT, nu));
| public void | changeInputMethodSubtype(android.view.inputmethod.InputMethodSubtype subtype)
mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_CHANGE_INPUTMETHOD_SUBTYPE,
subtype));
| public void | createSession(android.view.InputChannel channel, com.android.internal.view.IInputSessionCallback callback)
mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_CREATE_SESSION,
channel, callback));
| protected void | dump(java.io.FileDescriptor fd, java.io.PrintWriter fout, java.lang.String[] args)
AbstractInputMethodService target = mTarget.get();
if (target == null) {
return;
}
if (target.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
!= PackageManager.PERMISSION_GRANTED) {
fout.println("Permission Denial: can't dump InputMethodManager from from pid="
+ Binder.getCallingPid()
+ ", uid=" + Binder.getCallingUid());
return;
}
CountDownLatch latch = new CountDownLatch(1);
mCaller.executeOrSendMessage(mCaller.obtainMessageOOOO(DO_DUMP,
fd, fout, args, latch));
try {
if (!latch.await(5, TimeUnit.SECONDS)) {
fout.println("Timeout waiting for dump");
}
} catch (InterruptedException e) {
fout.println("Interrupted waiting for dump");
}
| public void | executeMessage(android.os.Message msg)
InputMethod inputMethod = mInputMethod.get();
// Need a valid reference to the inputMethod for everything except a dump.
if (inputMethod == null && msg.what != DO_DUMP) {
Log.w(TAG, "Input method reference was null, ignoring message: " + msg.what);
return;
}
switch (msg.what) {
case DO_DUMP: {
AbstractInputMethodService target = mTarget.get();
if (target == null) {
return;
}
SomeArgs args = (SomeArgs)msg.obj;
try {
target.dump((FileDescriptor)args.arg1,
(PrintWriter)args.arg2, (String[])args.arg3);
} catch (RuntimeException e) {
((PrintWriter)args.arg2).println("Exception: " + e);
}
synchronized (args.arg4) {
((CountDownLatch)args.arg4).countDown();
}
args.recycle();
return;
}
case DO_ATTACH_TOKEN: {
inputMethod.attachToken((IBinder)msg.obj);
return;
}
case DO_SET_INPUT_CONTEXT: {
inputMethod.bindInput((InputBinding)msg.obj);
return;
}
case DO_UNSET_INPUT_CONTEXT:
inputMethod.unbindInput();
return;
case DO_START_INPUT: {
SomeArgs args = (SomeArgs)msg.obj;
IInputContext inputContext = (IInputContext)args.arg1;
InputConnection ic = inputContext != null
? new InputConnectionWrapper(inputContext) : null;
EditorInfo info = (EditorInfo)args.arg2;
info.makeCompatible(mTargetSdkVersion);
inputMethod.startInput(ic, info);
args.recycle();
return;
}
case DO_RESTART_INPUT: {
SomeArgs args = (SomeArgs)msg.obj;
IInputContext inputContext = (IInputContext)args.arg1;
InputConnection ic = inputContext != null
? new InputConnectionWrapper(inputContext) : null;
EditorInfo info = (EditorInfo)args.arg2;
info.makeCompatible(mTargetSdkVersion);
inputMethod.restartInput(ic, info);
args.recycle();
return;
}
case DO_CREATE_SESSION: {
SomeArgs args = (SomeArgs)msg.obj;
inputMethod.createSession(new InputMethodSessionCallbackWrapper(
mContext, (InputChannel)args.arg1,
(IInputSessionCallback)args.arg2));
args.recycle();
return;
}
case DO_SET_SESSION_ENABLED:
inputMethod.setSessionEnabled((InputMethodSession)msg.obj,
msg.arg1 != 0);
return;
case DO_REVOKE_SESSION:
inputMethod.revokeSession((InputMethodSession)msg.obj);
return;
case DO_SHOW_SOFT_INPUT:
inputMethod.showSoftInput(msg.arg1, (ResultReceiver)msg.obj);
return;
case DO_HIDE_SOFT_INPUT:
inputMethod.hideSoftInput(msg.arg1, (ResultReceiver)msg.obj);
return;
case DO_CHANGE_INPUTMETHOD_SUBTYPE:
inputMethod.changeInputMethodSubtype((InputMethodSubtype)msg.obj);
return;
}
Log.w(TAG, "Unhandled message code: " + msg.what);
| public android.view.inputmethod.InputMethod | getInternalInputMethod()
return mInputMethod.get();
| public void | hideSoftInput(int flags, android.os.ResultReceiver resultReceiver)
mCaller.executeOrSendMessage(mCaller.obtainMessageIO(DO_HIDE_SOFT_INPUT,
flags, resultReceiver));
| public void | restartInput(com.android.internal.view.IInputContext inputContext, android.view.inputmethod.EditorInfo attribute)
mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_RESTART_INPUT,
inputContext, attribute));
| public void | revokeSession(com.android.internal.view.IInputMethodSession session)
try {
InputMethodSession ls = ((IInputMethodSessionWrapper)
session).getInternalInputMethodSession();
if (ls == null) {
Log.w(TAG, "Session is already finished: " + session);
return;
}
mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_REVOKE_SESSION, ls));
} catch (ClassCastException e) {
Log.w(TAG, "Incoming session not of correct type: " + session, e);
}
| public void | setSessionEnabled(com.android.internal.view.IInputMethodSession session, boolean enabled)
try {
InputMethodSession ls = ((IInputMethodSessionWrapper)
session).getInternalInputMethodSession();
if (ls == null) {
Log.w(TAG, "Session is already finished: " + session);
return;
}
mCaller.executeOrSendMessage(mCaller.obtainMessageIO(
DO_SET_SESSION_ENABLED, enabled ? 1 : 0, ls));
} catch (ClassCastException e) {
Log.w(TAG, "Incoming session not of correct type: " + session, e);
}
| public void | showSoftInput(int flags, android.os.ResultReceiver resultReceiver)
mCaller.executeOrSendMessage(mCaller.obtainMessageIO(DO_SHOW_SOFT_INPUT,
flags, resultReceiver));
| public void | startInput(com.android.internal.view.IInputContext inputContext, android.view.inputmethod.EditorInfo attribute)
mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_START_INPUT,
inputContext, attribute));
| public void | unbindInput()
mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_UNSET_INPUT_CONTEXT));
|
|