Merge "Simplify the constructor of InputMethodInfo"

This commit is contained in:
Yohei Yukawa
2017-02-03 01:33:38 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 13 deletions

View File

@@ -16,6 +16,7 @@
package android.view.inputmethod;
import android.annotation.NonNull;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -42,7 +43,6 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* This class is used to specify meta information of an input method.
@@ -109,6 +109,19 @@ public final class InputMethodInfo implements Parcelable {
*/
private final boolean mSupportsDismissingWindow;
/**
* @param service the {@link ResolveInfo} corresponds in which the IME is implemented.
* @return a unique ID to be returned by {@link #getId()}. We have used
* {@link ComponentName#flattenToShortString()} for this purpose (and it is already
* unrealistic to switch to a different scheme as it is already implicitly assumed in
* many places).
* @hide
*/
public static String computeId(@NonNull ResolveInfo service) {
final ServiceInfo si = service.serviceInfo;
return new ComponentName(si.packageName, si.name).flattenToShortString();
}
/**
* Constructor.
*
@@ -127,15 +140,15 @@ public final class InputMethodInfo implements Parcelable {
* @param context The Context in which we are parsing the input method.
* @param service The ResolveInfo returned from the package manager about
* this input method's component.
* @param additionalSubtypesMap additional subtypes being added to this InputMethodInfo
* @param additionalSubtypes additional subtypes being added to this InputMethodInfo
* @hide
*/
public InputMethodInfo(Context context, ResolveInfo service,
Map<String, List<InputMethodSubtype>> additionalSubtypesMap)
List<InputMethodSubtype> additionalSubtypes)
throws XmlPullParserException, IOException {
mService = service;
ServiceInfo si = service.serviceInfo;
mId = new ComponentName(si.packageName, si.name).flattenToShortString();
mId = computeId(service);
boolean isAuxIme = true;
boolean supportsSwitchingToNextInputMethod = false; // false as default
boolean supportsDismissingWindow = false; // false as default
@@ -233,8 +246,7 @@ public final class InputMethodInfo implements Parcelable {
isAuxIme = false;
}
if (additionalSubtypesMap != null && additionalSubtypesMap.containsKey(mId)) {
final List<InputMethodSubtype> additionalSubtypes = additionalSubtypesMap.get(mId);
if (additionalSubtypes != null) {
final int N = additionalSubtypes.size();
for (int i = 0; i < N; ++i) {
final InputMethodSubtype subtype = additionalSubtypes.get(i);

View File

@@ -3028,22 +3028,22 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
mSettings.getCurrentUserId());
final HashMap<String, List<InputMethodSubtype>> additionalSubtypes =
final HashMap<String, List<InputMethodSubtype>> additionalSubtypeMap =
mFileManager.getAllAdditionalInputMethodSubtypes();
for (int i = 0; i < services.size(); ++i) {
ResolveInfo ri = services.get(i);
ServiceInfo si = ri.serviceInfo;
ComponentName compName = new ComponentName(si.packageName, si.name);
if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(
si.permission)) {
Slog.w(TAG, "Skipping input method " + compName
final String imeId = InputMethodInfo.computeId(ri);
if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) {
Slog.w(TAG, "Skipping input method " + imeId
+ ": it does not require the permission "
+ android.Manifest.permission.BIND_INPUT_METHOD);
continue;
}
if (DEBUG) Slog.d(TAG, "Checking " + compName);
if (DEBUG) Slog.d(TAG, "Checking " + imeId);
final List<InputMethodSubtype> additionalSubtypes = additionalSubtypeMap.get(imeId);
try {
InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
mMethodList.add(p);
@@ -3054,7 +3054,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
Slog.d(TAG, "Found an input method " + p);
}
} catch (Exception e) {
Slog.wtf(TAG, "Unable to load input method " + compName, e);
Slog.wtf(TAG, "Unable to load input method " + imeId, e);
}
}