Search in sources :

Example 26 with SpellCheckerInfo

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

the class TextServicesManagerService method calledFromValidUser.

// ---------------------------------------------------------------------------------------
// Check whether or not this is a valid IPC. Assumes an IPC is valid when either
// 1) it comes from the system process
// 2) the calling process' user id is identical to the current user id TSMS thinks.
private boolean calledFromValidUser() {
    final int uid = Binder.getCallingUid();
    final int userId = UserHandle.getUserId(uid);
    if (DBG) {
        Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? " + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID + " calling userId = " + userId + ", foreground user id = " + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid());
        try {
            final String[] packageNames = AppGlobals.getPackageManager().getPackagesForUid(uid);
            for (int i = 0; i < packageNames.length; ++i) {
                if (DBG) {
                    Slog.d(TAG, "--- process name for " + uid + " = " + packageNames[i]);
                }
            }
        } catch (RemoteException e) {
        }
    }
    if (uid == Process.SYSTEM_UID || userId == mSettings.getCurrentUserId()) {
        return true;
    }
    // Permits current profile to use TSFM as long as the current text service is the system's
    // one. This is a tentative solution and should be replaced with fully functional multiuser
    // support.
    // TODO: Implement multiuser support in TSMS.
    final boolean isCurrentProfile = mSettings.isCurrentProfile(userId);
    if (DBG) {
        Slog.d(TAG, "--- userId = " + userId + " isCurrentProfile = " + isCurrentProfile);
    }
    if (mSettings.isCurrentProfile(userId)) {
        final SpellCheckerInfo spellCheckerInfo = getCurrentSpellCheckerWithoutVerification();
        if (spellCheckerInfo != null) {
            final ServiceInfo serviceInfo = spellCheckerInfo.getServiceInfo();
            final boolean isSystemSpellChecker = (serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
            if (DBG) {
                Slog.d(TAG, "--- current spell checker = " + spellCheckerInfo.getPackageName() + " isSystem = " + isSystemSpellChecker);
            }
            if (isSystemSpellChecker) {
                return true;
            }
        }
    }
    // support is implemented.
    if (DBG) {
        Slog.d(TAG, "--- IPC from userId:" + userId + " is being ignored. \n" + getStackTrace());
    }
    return false;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) RemoteException(android.os.RemoteException) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 27 with SpellCheckerInfo

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

the class TextServicesManagerService 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 TextServicesManagerService from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
        return;
    }
    synchronized (mSpellCheckerMap) {
        pw.println("Current Text Services Manager state:");
        pw.println("  Spell Checkers:");
        int spellCheckerIndex = 0;
        for (final SpellCheckerInfo info : mSpellCheckerMap.values()) {
            pw.println("  Spell Checker #" + spellCheckerIndex);
            info.dump(pw, "    ");
            ++spellCheckerIndex;
        }
        pw.println("");
        pw.println("  Spell Checker Bind Groups:");
        for (final Map.Entry<String, SpellCheckerBindGroup> ent : mSpellCheckerBindGroups.entrySet()) {
            final SpellCheckerBindGroup grp = ent.getValue();
            pw.println("    " + ent.getKey() + " " + grp + ":");
            pw.println("      " + "mInternalConnection=" + grp.mInternalConnection);
            pw.println("      " + "mSpellChecker=" + grp.mSpellChecker);
            pw.println("      " + "mBound=" + grp.mBound + " mConnected=" + grp.mConnected);
            final int N = grp.mListeners.size();
            for (int i = 0; i < N; i++) {
                final InternalDeathRecipient listener = grp.mListeners.get(i);
                pw.println("      " + "Listener #" + i + ":");
                pw.println("        " + "mTsListener=" + listener.mTsListener);
                pw.println("        " + "mScListener=" + listener.mScListener);
                pw.println("        " + "mGroup=" + listener.mGroup);
                pw.println("        " + "mScLocale=" + listener.mScLocale + " mUid=" + listener.mUid);
            }
        }
        pw.println("");
        pw.println("  mSettings:");
        mSettings.dumpLocked(pw, "    ");
    }
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 28 with SpellCheckerInfo

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

the class TextServicesManagerService method calledFromValidUser.

// ---------------------------------------------------------------------------------------
// Check whether or not this is a valid IPC. Assumes an IPC is valid when either
// 1) it comes from the system process
// 2) the calling process' user id is identical to the current user id TSMS thinks.
private boolean calledFromValidUser() {
    final int uid = Binder.getCallingUid();
    final int userId = UserHandle.getUserId(uid);
    if (DBG) {
        Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? " + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID + " calling userId = " + userId + ", foreground user id = " + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid());
        try {
            final String[] packageNames = AppGlobals.getPackageManager().getPackagesForUid(uid);
            for (int i = 0; i < packageNames.length; ++i) {
                if (DBG) {
                    Slog.d(TAG, "--- process name for " + uid + " = " + packageNames[i]);
                }
            }
        } catch (RemoteException e) {
        }
    }
    if (uid == Process.SYSTEM_UID || userId == mSettings.getCurrentUserId()) {
        return true;
    }
    // Permits current profile to use TSFM as long as the current text service is the system's
    // one. This is a tentative solution and should be replaced with fully functional multiuser
    // support.
    // TODO: Implement multiuser support in TSMS.
    final boolean isCurrentProfile = mSettings.isCurrentProfile(userId);
    if (DBG) {
        Slog.d(TAG, "--- userId = " + userId + " isCurrentProfile = " + isCurrentProfile);
    }
    if (mSettings.isCurrentProfile(userId)) {
        final SpellCheckerInfo spellCheckerInfo = getCurrentSpellCheckerWithoutVerification();
        if (spellCheckerInfo != null) {
            final ServiceInfo serviceInfo = spellCheckerInfo.getServiceInfo();
            final boolean isSystemSpellChecker = (serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
            if (DBG) {
                Slog.d(TAG, "--- current spell checker = " + spellCheckerInfo.getPackageName() + " isSystem = " + isSystemSpellChecker);
            }
            if (isSystemSpellChecker) {
                return true;
            }
        }
    }
    // support is implemented.
    if (DBG) {
        Slog.d(TAG, "--- IPC from userId:" + userId + " is being ignored. \n" + getStackTrace());
    }
    return false;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) RemoteException(android.os.RemoteException) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 29 with SpellCheckerInfo

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

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 30 with SpellCheckerInfo

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

the class TextServicesManagerService method setCurrentSpellCheckerLocked.

private void setCurrentSpellCheckerLocked(String sciId) {
    if (DBG) {
        Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
    }
    if (TextUtils.isEmpty(sciId) || !mSpellCheckerMap.containsKey(sciId))
        return;
    final SpellCheckerInfo currentSci = getCurrentSpellChecker(null);
    if (currentSci != null && currentSci.getId().equals(sciId)) {
        // Do nothing if the current spell checker is same as new spell checker.
        return;
    }
    final long ident = Binder.clearCallingIdentity();
    try {
        mSettings.putSelectedSpellChecker(sciId);
        setCurrentSpellCheckerSubtypeLocked(0);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : 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