Search in sources :

Example 41 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by AOSPA.

the class TextServicesManagerService method resetInternalState.

private void resetInternalState(@UserIdInt int userId) {
    final boolean useCopyOnWriteSettings = !mSystemReady || !mUserManager.isUserUnlockingOrUnlocked(userId);
    mSettings.switchCurrentUser(userId, useCopyOnWriteSettings);
    updateCurrentProfileIds();
    unbindServiceLocked();
    buildSpellCheckerMapLocked(mContext, mSpellCheckerList, mSpellCheckerMap, mSettings);
    SpellCheckerInfo sci = getCurrentSpellChecker(null);
    if (sci == null) {
        sci = findAvailSpellCheckerLocked(null);
        if (sci != null) {
            // Set the current spell checker if there is one or more spell checkers
            // available. In this case, "sci" is the first one in the available spell
            // checkers.
            setCurrentSpellCheckerLocked(sci.getId());
        }
    }
}
Also used : SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 42 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by AOSPA.

the class TextServicesManagerService method setCurrentSpellCheckerSubtypeLocked.

private void setCurrentSpellCheckerSubtypeLocked(int hashCode) {
    if (DBG) {
        Slog.w(TAG, "setCurrentSpellCheckerSubtype: " + hashCode);
    }
    final SpellCheckerInfo sci = getCurrentSpellChecker(null);
    int tempHashCode = 0;
    for (int i = 0; sci != null && i < sci.getSubtypeCount(); ++i) {
        if (sci.getSubtypeAt(i).hashCode() == hashCode) {
            tempHashCode = hashCode;
            break;
        }
    }
    final long ident = Binder.clearCallingIdentity();
    try {
        mSettings.putSelectedSpellCheckerSubtype(tempHashCode);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 43 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by AOSPA.

the class TextServicesManagerService method getCurrentSpellCheckerSubtype.

// TODO: Respect allowImplicitlySelectedSubtype
// TODO: Save SpellCheckerSubtype by supported languages by looking at "locale".
@Override
public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String locale, boolean allowImplicitlySelectedSubtype) {
    // TODO: Make this work even for non-current users?
    if (!calledFromValidUser()) {
        return null;
    }
    final int subtypeHashCode;
    final SpellCheckerInfo sci;
    final Locale systemLocale;
    synchronized (mSpellCheckerMap) {
        subtypeHashCode = mSettings.getSelectedSpellCheckerSubtype(SpellCheckerSubtype.SUBTYPE_ID_NONE);
        if (DBG) {
            Slog.w(TAG, "getCurrentSpellCheckerSubtype: " + subtypeHashCode);
        }
        sci = getCurrentSpellChecker(null);
        systemLocale = mContext.getResources().getConfiguration().locale;
    }
    if (sci == null || sci.getSubtypeCount() == 0) {
        if (DBG) {
            Slog.w(TAG, "Subtype not found.");
        }
        return null;
    }
    if (subtypeHashCode == SpellCheckerSubtype.SUBTYPE_ID_NONE && !allowImplicitlySelectedSubtype) {
        return null;
    }
    String candidateLocale = null;
    if (subtypeHashCode == 0) {
        // Spell checker language settings == "auto"
        final InputMethodManager imm = mContext.getSystemService(InputMethodManager.class);
        if (imm != null) {
            final InputMethodSubtype currentInputMethodSubtype = imm.getCurrentInputMethodSubtype();
            if (currentInputMethodSubtype != null) {
                final String localeString = currentInputMethodSubtype.getLocale();
                if (!TextUtils.isEmpty(localeString)) {
                    // 1. Use keyboard locale if available in the spell checker
                    candidateLocale = localeString;
                }
            }
        }
        if (candidateLocale == null) {
            // 2. Use System locale if available in the spell checker
            candidateLocale = systemLocale.toString();
        }
    }
    SpellCheckerSubtype candidate = null;
    for (int i = 0; i < sci.getSubtypeCount(); ++i) {
        final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
        if (subtypeHashCode == 0) {
            final String scsLocale = scs.getLocale();
            if (candidateLocale.equals(scsLocale)) {
                return scs;
            } else if (candidate == null) {
                if (candidateLocale.length() >= 2 && scsLocale.length() >= 2 && candidateLocale.startsWith(scsLocale)) {
                    // Fall back to the applicable language
                    candidate = scs;
                }
            }
        } else if (scs.hashCode() == subtypeHashCode) {
            if (DBG) {
                Slog.w(TAG, "Return subtype " + scs.hashCode() + ", input= " + locale + ", " + scs.getLocale());
            }
            // 3. Use the user specified spell check language
            return scs;
        }
    }
    // spell check languages
    return candidate;
}
Also used : Locale(java.util.Locale) SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManager(android.view.inputmethod.InputMethodManager) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 44 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by AOSPA.

the class TextServicesManagerService method getSpellCheckerService.

@Override
public void getSpellCheckerService(String sciId, String locale, ITextServicesSessionListener tsListener, ISpellCheckerSessionListener scListener, Bundle bundle) {
    if (!calledFromValidUser()) {
        return;
    }
    if (!mSystemReady) {
        return;
    }
    if (TextUtils.isEmpty(sciId) || tsListener == null || scListener == null) {
        Slog.e(TAG, "getSpellCheckerService: Invalid input.");
        return;
    }
    synchronized (mSpellCheckerMap) {
        if (!mSpellCheckerMap.containsKey(sciId)) {
            return;
        }
        final SpellCheckerInfo sci = mSpellCheckerMap.get(sciId);
        final int uid = Binder.getCallingUid();
        if (mSpellCheckerBindGroups.containsKey(sciId)) {
            final SpellCheckerBindGroup bindGroup = mSpellCheckerBindGroups.get(sciId);
            if (bindGroup != null) {
                final InternalDeathRecipient recipient = mSpellCheckerBindGroups.get(sciId).addListener(tsListener, locale, scListener, uid, bundle);
                if (recipient == null) {
                    if (DBG) {
                        Slog.w(TAG, "Didn't create a death recipient.");
                    }
                    return;
                }
                if (bindGroup.mSpellChecker == null & bindGroup.mConnected) {
                    Slog.e(TAG, "The state of the spell checker bind group is illegal.");
                    bindGroup.removeAll();
                } else if (bindGroup.mSpellChecker != null) {
                    if (DBG) {
                        Slog.w(TAG, "Existing bind found. Return a spell checker session now. " + "Listeners count = " + bindGroup.mListeners.size());
                    }
                    try {
                        final ISpellCheckerSession session = bindGroup.mSpellChecker.getISpellCheckerSession(recipient.mScLocale, recipient.mScListener, bundle);
                        if (session != null) {
                            tsListener.onServiceConnected(session);
                            return;
                        } else {
                            if (DBG) {
                                Slog.w(TAG, "Existing bind already expired. ");
                            }
                            bindGroup.removeAll();
                        }
                    } catch (RemoteException e) {
                        Slog.e(TAG, "Exception in getting spell checker session: " + e);
                        bindGroup.removeAll();
                    }
                }
            }
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            startSpellCheckerServiceInnerLocked(sci, locale, tsListener, scListener, uid, bundle);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    return;
}
Also used : ISpellCheckerSession(com.android.internal.textservice.ISpellCheckerSession) RemoteException(android.os.RemoteException) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 45 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by DirtyUnicorns.

the class InputMethodUtils method setNonSelectedSystemImesDisabledUntilUsed.

public static void setNonSelectedSystemImesDisabledUntilUsed(IPackageManager packageManager, List<InputMethodInfo> enabledImis, int userId, String callingPackage) {
    if (DEBUG) {
        Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
    }
    final String[] systemImesDisabledUntilUsed = Resources.getSystem().getStringArray(com.android.internal.R.array.config_disabledUntilUsedPreinstalledImes);
    if (systemImesDisabledUntilUsed == null || systemImesDisabledUntilUsed.length == 0) {
        return;
    }
    // Only the current spell checker should be treated as an enabled one.
    final SpellCheckerInfo currentSpellChecker = TextServicesManager.getInstance().getCurrentSpellChecker();
    for (final String packageName : systemImesDisabledUntilUsed) {
        if (DEBUG) {
            Slog.d(TAG, "check " + packageName);
        }
        boolean enabledIme = false;
        for (int j = 0; j < enabledImis.size(); ++j) {
            final InputMethodInfo imi = enabledImis.get(j);
            if (packageName.equals(imi.getPackageName())) {
                enabledIme = true;
                break;
            }
        }
        if (enabledIme) {
            // enabled ime. skip
            continue;
        }
        if (currentSpellChecker != null && packageName.equals(currentSpellChecker.getPackageName())) {
            // enabled spell checker. skip
            if (DEBUG) {
                Slog.d(TAG, packageName + " is the current spell checker. skip");
            }
            continue;
        }
        ApplicationInfo ai = null;
        try {
            ai = packageManager.getApplicationInfo(packageName, PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userId);
        } catch (RemoteException e) {
            Slog.w(TAG, "getApplicationInfo failed. packageName=" + packageName + " userId=" + userId, e);
            continue;
        }
        if (ai == null) {
            // No app found for packageName
            continue;
        }
        final boolean isSystemPackage = (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
        if (!isSystemPackage) {
            continue;
        }
        setDisabledUntilUsed(packageManager, packageName, userId, callingPackage);
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Aggregations

SpellCheckerInfo (android.view.textservice.SpellCheckerInfo)62 RemoteException (android.os.RemoteException)16 SpellCheckerSubtype (android.view.textservice.SpellCheckerSubtype)13 ServiceInfo (android.content.pm.ServiceInfo)11 Locale (java.util.Locale)10 Intent (android.content.Intent)7 ComponentName (android.content.ComponentName)6 ApplicationInfo (android.content.pm.ApplicationInfo)6 PackageManager (android.content.pm.PackageManager)6 ResolveInfo (android.content.pm.ResolveInfo)6 InputMethodInfo (android.view.inputmethod.InputMethodInfo)6 InputMethodManager (android.view.inputmethod.InputMethodManager)6 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)6 ISpellCheckerSession (com.android.internal.textservice.ISpellCheckerSession)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1