Search in sources :

Example 71 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.

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 {
            TransferPipe.dumpAsync(client.client.asBinder(), fd, args);
        } catch (IOException | RemoteException e) {
            p.println("Failed to dump input method client: " + 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 {
            TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args);
        } catch (IOException | RemoteException e) {
            p.println("Failed to dump input method client in focused window: " + e);
        }
    }
    p.println(" ");
    if (method != null) {
        pw.flush();
        try {
            TransferPipe.dumpAsync(method.asBinder(), fd, args);
        } catch (IOException | RemoteException e) {
            p.println("Failed to dump input method service: " + e);
        }
    } else {
        p.println("No input method service.");
    }
}
Also used : PrintWriterPrinter(android.util.PrintWriterPrinter) IInputMethod(com.android.internal.view.IInputMethod) IOException(java.io.IOException) Printer(android.util.Printer) PrintWriterPrinter(android.util.PrintWriterPrinter) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 72 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.

the class InputMethodManagerService method notifySuggestionPicked.

@Override
public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) {
    if (!calledFromValidUser()) {
        return false;
    }
    synchronized (mMethodMap) {
        final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span);
        // TODO: Do not send the intent if the process of the targetImi is already dead.
        if (targetImi != null) {
            final String[] suggestions = span.getSuggestions();
            if (index < 0 || index >= suggestions.length)
                return false;
            final String className = span.getNotificationTargetClassName();
            final Intent intent = new Intent();
            // Ensures that only a class in the original IME package will receive the
            // notification.
            intent.setClassName(targetImi.getPackageName(), className);
            intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED);
            intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString);
            intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]);
            intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode());
            final long ident = Binder.clearCallingIdentity();
            try {
                mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
            return true;
        }
    }
    return false;
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 73 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.

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 74 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.

the class InputMethodManagerService method updateInputMethodsFromSettingsLocked.

void updateInputMethodsFromSettingsLocked(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);
            resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_IME_FAILED);
        }
        mShortcutInputMethodsAndSubtypes.clear();
    } else {
        // There is no longer an input method set, so stop any current one.
        resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_NO_IME);
    }
    // Here is not the perfect place to reset the switching controller. Ideally
    // mSwitchingController and mSettings should be able to share the same state.
    // TODO: Make sure that mSwitchingController and mSettings are sharing the
    // the same enabled IMEs list.
    mSwitchingController.resetCircularListLocked(mContext);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 75 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.

the class InputMethodManagerService method findLastResortApplicableShortcutInputMethodAndSubtypeLocked.

// If there are no selected shortcuts, tries finding the most applicable ones.
private Pair<InputMethodInfo, InputMethodSubtype> findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
    List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
    InputMethodInfo mostApplicableIMI = null;
    InputMethodSubtype mostApplicableSubtype = null;
    boolean foundInSystemIME = false;
    // Search applicable subtype for each InputMethodInfo
    for (InputMethodInfo imi : imis) {
        final String imiId = imi.getId();
        if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
            continue;
        }
        InputMethodSubtype subtype = null;
        final List<InputMethodSubtype> enabledSubtypes = mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
        // 1. Search by the current subtype's locale from enabledSubtypes.
        if (mCurrentSubtype != null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
        }
        // 3. Search the first enabled subtype matched with mode from enabledSubtypes.
        if (subtype == null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, enabledSubtypes, mode, null, true);
        }
        final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes = InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
        final ArrayList<InputMethodSubtype> subtypesForSearch = overridingImplicitlyEnabledSubtypes.isEmpty() ? InputMethodUtils.getSubtypes(imi) : overridingImplicitlyEnabledSubtypes;
        // 4. Search by the current subtype's locale from all subtypes.
        if (subtype == null && mCurrentSubtype != null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
        }
        // 6. Search the first enabled subtype matched with mode from all subtypes.
        if (subtype == null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, subtypesForSearch, mode, null, true);
        }
        if (subtype != null) {
            if (imiId.equals(mCurMethodId)) {
                // The current input method is the most applicable IME.
                mostApplicableIMI = imi;
                mostApplicableSubtype = subtype;
                break;
            } else if (!foundInSystemIME) {
                // The system input method is 2nd applicable IME.
                mostApplicableIMI = imi;
                mostApplicableSubtype = subtype;
                if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    foundInSystemIME = true;
                }
            }
        }
    }
    if (DEBUG) {
        if (mostApplicableIMI != null) {
            Slog.w(TAG, "Most applicable shortcut input method was:" + mostApplicableIMI.getId());
            if (mostApplicableSubtype != null) {
                Slog.w(TAG, "Most applicable shortcut input method subtype was:" + "," + mostApplicableSubtype.getMode() + "," + mostApplicableSubtype.getLocale());
            }
        }
    }
    if (mostApplicableIMI != null) {
        return new Pair<>(mostApplicableIMI, mostApplicableSubtype);
    } else {
        return null;
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Pair(android.util.Pair)

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