Search in sources :

Example 41 with InputMethodInfo

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

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)

Example 42 with InputMethodInfo

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

the class InputMethodUtils method getMostApplicableDefaultIME.

public static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) {
    if (enabledImes == null || enabledImes.isEmpty()) {
        return null;
    }
    // We'd prefer to fall back on a system IME, since that is safer.
    int i = enabledImes.size();
    int firstFoundSystemIme = -1;
    while (i > 0) {
        i--;
        final InputMethodInfo imi = enabledImes.get(i);
        if (imi.isAuxiliaryIme()) {
            continue;
        }
        if (InputMethodUtils.isSystemIme(imi) && containsSubtypeOf(imi, ENGLISH_LOCALE, false, /* checkCountry */
        SUBTYPE_MODE_KEYBOARD)) {
            return imi;
        }
        if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi)) {
            firstFoundSystemIme = i;
        }
    }
    return enabledImes.get(Math.max(firstFoundSystemIme, 0));
}
Also used : InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 43 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndLanguageSettings method onSaveInputMethodPreference.

@Override
public void onSaveInputMethodPreference(final InputMethodPreference pref) {
    final InputMethodInfo imi = pref.getInputMethodInfo();
    if (!pref.isChecked()) {
        // An IME is being disabled. Save enabled subtypes of the IME to shared preference to be
        // able to re-enable these subtypes when the IME gets re-enabled.
        saveEnabledSubtypesOf(imi);
    }
    final boolean hasHardwareKeyboard = getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY;
    InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(this, getContentResolver(), mImm.getInputMethodList(), hasHardwareKeyboard);
    // Update input method settings and preference list.
    mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
    if (pref.isChecked()) {
        // An IME is being enabled. Load the previously enabled subtypes from shared preference
        // and enable these subtypes.
        restorePreviouslyEnabledSubtypesOf(imi);
    }
    for (final InputMethodPreference p : mInputMethodPreferenceList) {
        p.updatePreferenceViews();
    }
}
Also used : InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 44 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InputMethodAndLanguageSettings method updateInputMethodPreferenceViews.

private void updateInputMethodPreferenceViews() {
    if (mKeyboardSettingsCategory == null) {
        return;
    }
    synchronized (mInputMethodPreferenceList) {
        // Clear existing "InputMethodPreference"s
        for (final InputMethodPreference pref : mInputMethodPreferenceList) {
            mKeyboardSettingsCategory.removePreference(pref);
        }
        mInputMethodPreferenceList.clear();
        List<String> permittedList = mDpm.getPermittedInputMethodsForCurrentUser();
        final Context context = getPrefContext();
        final List<InputMethodInfo> imis = mShowsOnlyFullImeAndKeyboardList ? mInputMethodSettingValues.getInputMethodList() : mImm.getEnabledInputMethodList();
        final int N = (imis == null ? 0 : imis.size());
        for (int i = 0; i < N; ++i) {
            final InputMethodInfo imi = imis.get(i);
            final boolean isAllowedByOrganization = permittedList == null || permittedList.contains(imi.getPackageName());
            final InputMethodPreference pref = new InputMethodPreference(context, imi, mShowsOnlyFullImeAndKeyboardList, /* hasSwitch */
            isAllowedByOrganization, this);
            mInputMethodPreferenceList.add(pref);
        }
        final Collator collator = Collator.getInstance();
        Collections.sort(mInputMethodPreferenceList, new Comparator<InputMethodPreference>() {

            @Override
            public int compare(InputMethodPreference lhs, InputMethodPreference rhs) {
                return lhs.compareTo(rhs, collator);
            }
        });
        for (int i = 0; i < N; ++i) {
            final InputMethodPreference pref = mInputMethodPreferenceList.get(i);
            mKeyboardSettingsCategory.addPreference(pref);
            InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
            pref.updatePreferenceViews();
        }
    }
    updateCurrentImeName();
    // TODO: Consolidate the logic with InputMethodSettingsWrapper
    // CAVEAT: The preference class here does not know about the default value - that is
    // managed by the Input Method Manager Service, so in this case it could save the wrong
    // value. Hence we must update the checkboxes here.
    InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(this, getContentResolver(), mInputMethodSettingValues.getInputMethodList(), null);
}
Also used : Context(android.content.Context) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Collator(java.text.Collator)

Example 45 with InputMethodInfo

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

the class DevicePolicyManagerService method getPermittedInputMethodsForCurrentUser.

@Override
public List getPermittedInputMethodsForCurrentUser() {
    UserInfo currentUser;
    try {
        currentUser = mInjector.getIActivityManager().getCurrentUser();
    } catch (RemoteException e) {
        Slog.e(LOG_TAG, "Failed to make remote calls to get current user", e);
        // Activity managed is dead, just allow all IMEs
        return null;
    }
    int userId = currentUser.id;
    synchronized (this) {
        List<String> result = null;
        // If we have multiple profiles we return the intersection of the
        // permitted lists. This can happen in cases where we have a device
        // and profile owner.
        int[] profileIds = mUserManager.getProfileIdsWithDisabled(userId);
        for (int profileId : profileIds) {
            // Just loop though all admins, only device or profiles
            // owners can have permitted lists set.
            DevicePolicyData policy = getUserDataUnchecked(profileId);
            final int N = policy.mAdminList.size();
            for (int j = 0; j < N; j++) {
                ActiveAdmin admin = policy.mAdminList.get(j);
                List<String> fromAdmin = admin.permittedInputMethods;
                if (fromAdmin != null) {
                    if (result == null) {
                        result = new ArrayList<String>(fromAdmin);
                    } else {
                        result.retainAll(fromAdmin);
                    }
                }
            }
        }
        // If we have a permitted list add all system input methods.
        if (result != null) {
            InputMethodManager inputMethodManager = mContext.getSystemService(InputMethodManager.class);
            List<InputMethodInfo> imes = inputMethodManager.getInputMethodList();
            long id = mInjector.binderClearCallingIdentity();
            try {
                if (imes != null) {
                    for (InputMethodInfo ime : imes) {
                        ServiceInfo serviceInfo = ime.getServiceInfo();
                        ApplicationInfo applicationInfo = serviceInfo.applicationInfo;
                        if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                            result.add(serviceInfo.packageName);
                        }
                    }
                }
            } finally {
                mInjector.binderRestoreCallingIdentity(id);
            }
        }
        return result;
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) InputMethodManager(android.view.inputmethod.InputMethodManager) ParcelableString(com.android.internal.util.ParcelableString) InputMethodInfo(android.view.inputmethod.InputMethodInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) RemoteException(android.os.RemoteException)

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