use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.
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));
}
use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.
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);
}
}
use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.
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)
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(false);
} finally {
Binder.restoreCallingIdentity(ident);
}
return;
}
}
}
}
return;
}
use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.
the class InputMethodManagerService method updateSystemUiLocked.
// Caution! This method is called in this class. Handle multi-user carefully
private void updateSystemUiLocked(IBinder token, int vis, int backDisposition) {
if (!calledWithValidToken(token)) {
final int uid = Binder.getCallingUid();
Slog.e(TAG, "Ignoring updateSystemUiLocked due to an invalid token. uid:" + uid + " token:" + token);
return;
}
// TODO: Move this clearing calling identity block to setImeWindowStatus after making sure
// all updateSystemUi happens on system previlege.
final long ident = Binder.clearCallingIdentity();
try {
// apply policy for binder calls
if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) {
vis = 0;
}
// mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked().
final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis);
if (mStatusBar != null) {
mStatusBar.setImeWindowStatus(token, vis, backDisposition, needsToShowImeSwitcher);
}
final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
if (imi != null && needsToShowImeSwitcher) {
// Used to load label
final CharSequence title = mRes.getText(com.android.internal.R.string.select_input_method);
final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName(mContext, imi, mCurrentSubtype);
mImeSwitcherNotification.setContentTitle(title).setContentText(summary).setContentIntent(mImeSwitchPendingIntent);
try {
if ((mNotificationManager != null) && !mIWindowManager.hasNavigationBar()) {
if (DEBUG) {
Slog.d(TAG, "--- show notification: label = " + summary);
}
mNotificationManager.notifyAsUser(null, com.android.internal.R.string.select_input_method, mImeSwitcherNotification.build(), UserHandle.ALL);
mNotificationShown = true;
}
} catch (RemoteException e) {
}
} else {
if (mNotificationShown && mNotificationManager != null) {
if (DEBUG) {
Slog.d(TAG, "--- hide notification");
}
mNotificationManager.cancelAsUser(null, com.android.internal.R.string.select_input_method, UserHandle.ALL);
mNotificationShown = false;
}
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
use of android.view.inputmethod.InputMethodInfo in project platform_frameworks_base by android.
the class InputMethodManagerService method showInputMethodMenu.
private void showInputMethodMenu(boolean showAuxSubtypes) {
if (DEBUG)
Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
final Context context = mContext;
final boolean isScreenLocked = isScreenLocked();
final String lastInputMethodId = mSettings.getSelectedInputMethod();
int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
if (DEBUG)
Slog.v(TAG, "Current IME: " + lastInputMethodId);
synchronized (mMethodMap) {
final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(mContext);
if (immis == null || immis.size() == 0) {
return;
}
hideInputMethodMenuLocked();
final List<ImeSubtypeListItem> imList = mSwitchingController.getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, isScreenLocked);
if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
if (currentSubtype != null) {
final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
}
}
final int N = imList.size();
mIms = new InputMethodInfo[N];
mSubtypeIds = new int[N];
int checkedItem = 0;
for (int i = 0; i < N; ++i) {
final ImeSubtypeListItem item = imList.get(i);
mIms[i] = item.mImi;
mSubtypeIds[i] = item.mSubtypeId;
if (mIms[i].getId().equals(lastInputMethodId)) {
int subtypeId = mSubtypeIds[i];
if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
checkedItem = i;
}
}
}
final Context settingsContext = new ContextThemeWrapper(context, com.android.internal.R.style.Theme_DeviceDefault_Settings);
mDialogBuilder = new AlertDialog.Builder(settingsContext);
mDialogBuilder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
hideInputMethodMenu();
}
});
final Context dialogContext = mDialogBuilder.getContext();
final TypedArray a = dialogContext.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
final Drawable dialogIcon = a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogIcon);
a.recycle();
mDialogBuilder.setIcon(dialogIcon);
final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
mDialogBuilder.setCustomTitle(tv);
// Setup layout for a toggle switch of the hardware keyboard
mSwitchingDialogTitleView = tv;
mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mSettings.setShowImeWithHardKeyboard(isChecked);
// Ensure that the input method dialog is dismissed when changing
// the hardware keyboard state.
hideInputMethodMenu();
}
});
final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
final OnClickListener choiceListener = new OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
synchronized (mMethodMap) {
if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
return;
}
final InputMethodInfo im = mIms[which];
int subtypeId = mSubtypeIds[which];
adapter.mCheckedItem = which;
adapter.notifyDataSetChanged();
hideInputMethodMenu();
if (im != null) {
if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
subtypeId = NOT_A_SUBTYPE_ID;
}
setInputMethodLocked(im.getId(), subtypeId);
}
}
}
};
mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
mSwitchingDialog = mDialogBuilder.create();
mSwitchingDialog.setCanceledOnTouchOutside(true);
mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
mSwitchingDialog.show();
}
}
Aggregations