Search in sources :

Example 11 with InputMethodInfo

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

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;
    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);
        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("  mShowRequested=" + mShowRequested + " mShowExplicitlyRequested=" + mShowExplicitlyRequested + " mShowForced=" + mShowForced + " mInputShown=" + mInputShown);
        p.println("  mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn);
    }
    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.");
    }
    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 12 with InputMethodInfo

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

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.valueOf(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);
            }
            setInputMethodWithSubtypeId(token, targetLastImiId, subtypeId);
            return true;
        } else {
            return false;
        }
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 13 with InputMethodInfo

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

the class InputMethodManagerService method updateFromSettingsLocked.

void updateFromSettingsLocked(boolean enabledMayChange) {
    if (enabledMayChange) {
        List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
        for (int i = 0; i < enabled.size(); i++) {
            // We allow the user to select "disabled until used" apps, so if they
            // are enabling one of those here we now need to make it enabled.
            InputMethodInfo imm = enabled.get(i);
            try {
                ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(), PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, mSettings.getCurrentUserId());
                if (ai != null && ai.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
                    if (DEBUG) {
                        Slog.d(TAG, "Update state(" + imm.getId() + "): DISABLED_UNTIL_USED -> DEFAULT");
                    }
                    mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(), PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(), mContext.getBasePackageName());
                }
            } catch (RemoteException e) {
            }
        }
    }
    // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
    // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
    // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
    // enabled.
    String id = mSettings.getSelectedInputMethod();
    // There is no input method selected, try to choose new applicable input method.
    if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) {
        id = mSettings.getSelectedInputMethod();
    }
    if (!TextUtils.isEmpty(id)) {
        try {
            setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id));
        } catch (IllegalArgumentException e) {
            Slog.w(TAG, "Unknown input method from prefs: " + id, e);
            mCurMethodId = null;
            unbindCurrentMethodLocked(true, false);
        }
        mShortcutInputMethodsAndSubtypes.clear();
    } else {
        // There is no longer an input method set, so stop any current one.
        mCurMethodId = null;
        unbindCurrentMethodLocked(true, false);
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 14 with InputMethodInfo

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

the class InputMethodManagerService method setAdditionalInputMethodSubtypes.

@Override
public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
    if (!calledFromValidUser()) {
        return;
    }
    // additional input method subtypes to the IME.
    if (TextUtils.isEmpty(imiId) || subtypes == null || subtypes.length == 0)
        return;
    synchronized (mMethodMap) {
        final InputMethodInfo imi = mMethodMap.get(imiId);
        if (imi == null)
            return;
        final String[] packageInfos;
        try {
            packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid());
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to get package infos");
            return;
        }
        if (packageInfos != null) {
            final int packageNum = packageInfos.length;
            for (int i = 0; i < packageNum; ++i) {
                if (packageInfos[i].equals(imi.getPackageName())) {
                    mFileManager.addInputMethodSubtypes(imi, subtypes);
                    final long ident = Binder.clearCallingIdentity();
                    try {
                        buildInputMethodListLocked(mMethodList, mMethodMap, false);
                    } finally {
                        Binder.restoreCallingIdentity(ident);
                    }
                    return;
                }
            }
        }
    }
    return;
}
Also used : RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 15 with InputMethodInfo

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

the class Ime method runList.

/**
     * Execute the list sub-command.
     */
private void runList() {
    String opt;
    boolean all = false;
    boolean brief = false;
    while ((opt = nextOption()) != null) {
        if (opt.equals("-a")) {
            all = true;
        } else if (opt.equals("-s")) {
            brief = true;
        } else {
            System.err.println("Error: Unknown option: " + opt);
            showUsage();
            return;
        }
    }
    List<InputMethodInfo> methods;
    if (!all) {
        try {
            methods = mImm.getEnabledInputMethodList();
        } catch (RemoteException e) {
            System.err.println(e.toString());
            System.err.println(IMM_NOT_RUNNING_ERR);
            return;
        }
    } else {
        try {
            methods = mImm.getInputMethodList();
        } catch (RemoteException e) {
            System.err.println(e.toString());
            System.err.println(IMM_NOT_RUNNING_ERR);
            return;
        }
    }
    if (methods != null) {
        Printer pr = new PrintStreamPrinter(System.out);
        for (int i = 0; i < methods.size(); i++) {
            InputMethodInfo imi = methods.get(i);
            if (brief) {
                System.out.println(imi.getId());
            } else {
                System.out.println(imi.getId() + ":");
                imi.dump(pr, "  ");
            }
        }
    }
}
Also used : PrintStreamPrinter(android.util.PrintStreamPrinter) RemoteException(android.os.RemoteException) PrintStreamPrinter(android.util.PrintStreamPrinter) Printer(android.util.Printer) 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