Search in sources :

Example 51 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

the class InputMethodManagerService method startInputInnerLocked.

InputBindResult startInputInnerLocked() {
    if (mCurMethodId == null) {
        return mNoBinding;
    }
    if (!mSystemReady) {
        // party code.
        return new InputBindResult(null, null, mCurMethodId, mCurSeq, mCurUserActionNotificationSequenceNumber);
    }
    InputMethodInfo info = mMethodMap.get(mCurMethodId);
    if (info == null) {
        throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
    }
    unbindCurrentMethodLocked(true);
    mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
    mCurIntent.setComponent(info.getComponent());
    mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, com.android.internal.R.string.input_method_binding_label);
    mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
    if (bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE | Context.BIND_NOT_VISIBLE | Context.BIND_NOT_FOREGROUND | Context.BIND_SHOWING_UI)) {
        mLastBindTime = SystemClock.uptimeMillis();
        mHaveConnection = true;
        mCurId = info.getId();
        mCurToken = new Binder();
        try {
            if (true || DEBUG)
                Slog.v(TAG, "Adding window token: " + mCurToken);
            mIWindowManager.addWindowToken(mCurToken, WindowManager.LayoutParams.TYPE_INPUT_METHOD);
        } catch (RemoteException e) {
        }
        return new InputBindResult(null, null, mCurId, mCurSeq, mCurUserActionNotificationSequenceNumber);
    } else {
        mCurIntent = null;
        Slog.w(TAG, "Failure connecting to input method service: " + mCurIntent);
    }
    return null;
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) InputBindResult(com.android.internal.view.InputBindResult) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 52 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

the class InputMethodManagerService method getCurrentInputMethodSubtypeLocked.

private InputMethodSubtype getCurrentInputMethodSubtypeLocked() {
    if (mCurMethodId == null) {
        return null;
    }
    final boolean subtypeIsSelected = mSettings.isSubtypeSelected();
    final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
    if (imi == null || imi.getSubtypeCount() == 0) {
        return null;
    }
    if (!subtypeIsSelected || mCurrentSubtype == null || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) {
        int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId);
        if (subtypeId == NOT_A_SUBTYPE_ID) {
            // If there are no selected subtypes, the framework will try to find
            // the most applicable subtype from explicitly or implicitly enabled
            // subtypes.
            List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
            // just returns it.
            if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
                mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
            } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
                mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, explicitlyOrImplicitlyEnabledSubtypes, InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true);
                if (mCurrentSubtype == null) {
                    mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, true);
                }
            }
        } else {
            mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId);
        }
    }
    return mCurrentSubtype;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 53 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

the class InputMethodManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump InputMethodManager from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
        return;
    }
    IInputMethod method;
    ClientState client;
    ClientState focusedWindowClient;
    final Printer p = new PrintWriterPrinter(pw);
    synchronized (mMethodMap) {
        p.println("Current Input Method Manager state:");
        int N = mMethodList.size();
        p.println("  Input Methods:");
        for (int i = 0; i < N; i++) {
            InputMethodInfo info = mMethodList.get(i);
            p.println("  InputMethod #" + i + ":");
            info.dump(p, "    ");
        }
        p.println("  Clients:");
        for (ClientState ci : mClients.values()) {
            p.println("  Client " + ci + ":");
            p.println("    client=" + ci.client);
            p.println("    inputContext=" + ci.inputContext);
            p.println("    sessionRequested=" + ci.sessionRequested);
            p.println("    curSession=" + ci.curSession);
        }
        p.println("  mCurMethodId=" + mCurMethodId);
        client = mCurClient;
        p.println("  mCurClient=" + client + " mCurSeq=" + mCurSeq);
        p.println("  mCurFocusedWindow=" + mCurFocusedWindow);
        focusedWindowClient = mCurFocusedWindowClient;
        p.println("  mCurFocusedWindowClient=" + focusedWindowClient);
        p.println("  mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection + " mBoundToMethod=" + mBoundToMethod);
        p.println("  mCurToken=" + mCurToken);
        p.println("  mCurIntent=" + mCurIntent);
        method = mCurMethod;
        p.println("  mCurMethod=" + mCurMethod);
        p.println("  mEnabledSession=" + mEnabledSession);
        p.println("  mImeWindowVis=" + imeWindowStatusToString(mImeWindowVis));
        p.println("  mShowRequested=" + mShowRequested + " mShowExplicitlyRequested=" + mShowExplicitlyRequested + " mShowForced=" + mShowForced + " mInputShown=" + mInputShown);
        p.println("  mCurUserActionNotificationSequenceNumber=" + mCurUserActionNotificationSequenceNumber);
        p.println("  mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive);
        p.println("  mSettingsObserver=" + mSettingsObserver);
        p.println("  mSwitchingController:");
        mSwitchingController.dump(p);
        p.println("  mSettings:");
        mSettings.dumpLocked(p, "    ");
    }
    p.println(" ");
    if (client != null) {
        pw.flush();
        try {
            client.client.asBinder().dump(fd, args);
        } catch (RemoteException e) {
            p.println("Input method client dead: " + e);
        }
    } else {
        p.println("No input method client.");
    }
    if (focusedWindowClient != null && client != focusedWindowClient) {
        p.println(" ");
        p.println("Warning: Current input method client doesn't match the last focused. " + "window.");
        p.println("Dumping input method client in the last focused window just in case.");
        p.println(" ");
        pw.flush();
        try {
            focusedWindowClient.client.asBinder().dump(fd, args);
        } catch (RemoteException e) {
            p.println("Input method client in focused window dead: " + e);
        }
    }
    p.println(" ");
    if (method != null) {
        pw.flush();
        try {
            method.asBinder().dump(fd, args);
        } catch (RemoteException e) {
            p.println("Input method service dead: " + e);
        }
    } else {
        p.println("No input method service.");
    }
}
Also used : PrintWriterPrinter(android.util.PrintWriterPrinter) IInputMethod(com.android.internal.view.IInputMethod) Printer(android.util.Printer) PrintWriterPrinter(android.util.PrintWriterPrinter) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 54 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

the class InputMethodManagerService method getLastInputMethodSubtype.

@Override
public InputMethodSubtype getLastInputMethodSubtype() {
    if (!calledFromValidUser()) {
        return null;
    }
    synchronized (mMethodMap) {
        final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
        // TODO: Handle the case of the last IME with no subtypes
        if (lastIme == null || TextUtils.isEmpty(lastIme.first) || TextUtils.isEmpty(lastIme.second))
            return null;
        final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
        if (lastImi == null)
            return null;
        try {
            final int lastSubtypeHash = Integer.parseInt(lastIme.second);
            final int lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
            if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
                return null;
            }
            return lastImi.getSubtypeAt(lastSubtypeId);
        } catch (NumberFormatException e) {
            return null;
        }
    }
}
Also used : InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 55 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

the class InputMethodManagerService method switchToLastInputMethod.

@Override
public boolean switchToLastInputMethod(IBinder token) {
    if (!calledFromValidUser()) {
        return false;
    }
    synchronized (mMethodMap) {
        final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
        final InputMethodInfo lastImi;
        if (lastIme != null) {
            lastImi = mMethodMap.get(lastIme.first);
        } else {
            lastImi = null;
        }
        String targetLastImiId = null;
        int subtypeId = NOT_A_SUBTYPE_ID;
        if (lastIme != null && lastImi != null) {
            final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId);
            final int lastSubtypeHash = Integer.parseInt(lastIme.second);
            final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID : mCurrentSubtype.hashCode();
            // defined, there is no need to switch to the last IME.
            if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) {
                targetLastImiId = lastIme.first;
                subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
            }
        }
        if (TextUtils.isEmpty(targetLastImiId) && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) {
            // This is a safety net. If the currentSubtype can't be added to the history
            // and the framework couldn't find the last ime, we will make the last ime be
            // the most applicable enabled keyboard subtype of the system imes.
            final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
            if (enabled != null) {
                final int N = enabled.size();
                final String locale = mCurrentSubtype == null ? mRes.getConfiguration().locale.toString() : mCurrentSubtype.getLocale();
                for (int i = 0; i < N; ++i) {
                    final InputMethodInfo imi = enabled.get(i);
                    if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) {
                        InputMethodSubtype keyboardSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, InputMethodUtils.getSubtypes(imi), InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
                        if (keyboardSubtype != null) {
                            targetLastImiId = imi.getId();
                            subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, keyboardSubtype.hashCode());
                            if (keyboardSubtype.getLocale().equals(locale)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (!TextUtils.isEmpty(targetLastImiId)) {
            if (DEBUG) {
                Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second + ", from: " + mCurMethodId + ", " + subtypeId);
            }
            setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId);
            return true;
        } else {
            return false;
        }
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Aggregations

InputMethodInfo (android.view.inputmethod.InputMethodInfo)309 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)113 ArrayList (java.util.ArrayList)80 RemoteException (android.os.RemoteException)53 ServiceInfo (android.content.pm.ServiceInfo)34 ComponentName (android.content.ComponentName)33 Intent (android.content.Intent)33 Context (android.content.Context)32 InputMethodManager (android.view.inputmethod.InputMethodManager)29 ApplicationInfo (android.content.pm.ApplicationInfo)27 PendingIntent (android.app.PendingIntent)24 Test (org.junit.Test)24 ResolveInfo (android.content.pm.ResolveInfo)19 ImeSubtypeListItem (com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)15 InputMethodPreference (com.android.settingslib.inputmethod.InputMethodPreference)14 List (java.util.List)14 PackageManager (android.content.pm.PackageManager)13 Drawable (android.graphics.drawable.Drawable)13 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 Printer (android.util.Printer)12