FileDocCategorySizeDatePackage
IInputMethodWrapper.javaAPI DocAndroid 1.5 API9497Wed May 06 22:41:54 BST 2009android.inputmethodservice

IInputMethodWrapper

public class IInputMethodWrapper extends IInputMethod.Stub implements HandlerCaller.Callback
Implements 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 boolean
DEBUG
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
final AbstractInputMethodService
mTarget
final com.android.internal.os.HandlerCaller
mCaller
final android.view.inputmethod.InputMethod
mInputMethod
Constructors Summary
public IInputMethodWrapper(AbstractInputMethodService context, android.view.inputmethod.InputMethod inputMethod)

        mTarget = context;
        mCaller = new HandlerCaller(context, this);
        mInputMethod = inputMethod;
    
Methods Summary
public voidattachToken(android.os.IBinder token)

        mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_ATTACH_TOKEN, token));
    
public voidbindInput(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 voidcreateSession(com.android.internal.view.IInputMethodCallback callback)

        mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_CREATE_SESSION, callback));
    
protected voiddump(java.io.FileDescriptor fd, java.io.PrintWriter fout, java.lang.String[] args)

        if (mTarget.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 voidexecuteMessage(android.os.Message msg)

        switch (msg.what) {
            case DO_DUMP: {
                HandlerCaller.SomeArgs args = (HandlerCaller.SomeArgs)msg.obj;
                try {
                    mTarget.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();
                }
                return;
            }
            
            case DO_ATTACH_TOKEN: {
                mInputMethod.attachToken((IBinder)msg.obj);
                return;
            }
            case DO_SET_INPUT_CONTEXT: {
                mInputMethod.bindInput((InputBinding)msg.obj);
                return;
            }
            case DO_UNSET_INPUT_CONTEXT:
                mInputMethod.unbindInput();
                return;
            case DO_START_INPUT: {
                HandlerCaller.SomeArgs args = (HandlerCaller.SomeArgs)msg.obj;
                IInputContext inputContext = (IInputContext)args.arg1;
                InputConnection ic = inputContext != null
                        ? new InputConnectionWrapper(inputContext) : null;
                mInputMethod.startInput(ic, (EditorInfo)args.arg2);
                return;
            }
            case DO_RESTART_INPUT: {
                HandlerCaller.SomeArgs args = (HandlerCaller.SomeArgs)msg.obj;
                IInputContext inputContext = (IInputContext)args.arg1;
                InputConnection ic = inputContext != null
                        ? new InputConnectionWrapper(inputContext) : null;
                mInputMethod.restartInput(ic, (EditorInfo)args.arg2);
                return;
            }
            case DO_CREATE_SESSION: {
                mInputMethod.createSession(new InputMethodSessionCallbackWrapper(
                        mCaller.mContext, (IInputMethodCallback)msg.obj));
                return;
            }
            case DO_SET_SESSION_ENABLED:
                mInputMethod.setSessionEnabled((InputMethodSession)msg.obj,
                        msg.arg1 != 0);
                return;
            case DO_REVOKE_SESSION:
                mInputMethod.revokeSession((InputMethodSession)msg.obj);
                return;
            case DO_SHOW_SOFT_INPUT:
                mInputMethod.showSoftInput(msg.arg1, (ResultReceiver)msg.obj);
                return;
            case DO_HIDE_SOFT_INPUT:
                mInputMethod.hideSoftInput(msg.arg1, (ResultReceiver)msg.obj);
                return;
        }
        Log.w(TAG, "Unhandled message code: " + msg.what);
    
public android.view.inputmethod.InputMethodgetInternalInputMethod()

        return mInputMethod;
    
public voidhideSoftInput(int flags, android.os.ResultReceiver resultReceiver)

        mCaller.executeOrSendMessage(mCaller.obtainMessageIO(DO_HIDE_SOFT_INPUT,
                flags, resultReceiver));
    
public voidrestartInput(com.android.internal.view.IInputContext inputContext, android.view.inputmethod.EditorInfo attribute)

        mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_RESTART_INPUT,
                inputContext, attribute));
    
public voidrevokeSession(com.android.internal.view.IInputMethodSession session)

        try {
            InputMethodSession ls = ((IInputMethodSessionWrapper)
                    session).getInternalInputMethodSession();
            mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_REVOKE_SESSION, ls));
        } catch (ClassCastException e) {
            Log.w(TAG, "Incoming session not of correct type: " + session, e);
        }
    
public voidsetSessionEnabled(com.android.internal.view.IInputMethodSession session, boolean enabled)

        try {
            InputMethodSession ls = ((IInputMethodSessionWrapper)
                    session).getInternalInputMethodSession();
            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 voidshowSoftInput(int flags, android.os.ResultReceiver resultReceiver)

        mCaller.executeOrSendMessage(mCaller.obtainMessageIO(DO_SHOW_SOFT_INPUT,
                flags, resultReceiver));
    
public voidstartInput(com.android.internal.view.IInputContext inputContext, android.view.inputmethod.EditorInfo attribute)

        mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_START_INPUT,
                inputContext, attribute));
    
public voidunbindInput()

        mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_UNSET_INPUT_CONTEXT));