diff options
| author | Satoshi Kataoka <satok@google.com> | 2013-01-30 02:41:46 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-01-30 02:41:47 +0000 |
| commit | da01da176d4798d293c90d6280ddc59c780baaa3 (patch) | |
| tree | f02457ba35c612de390b0c40968c8336a485e592 /core/java/android | |
| parent | f5f8502271b04d63c518e3aecfd5eaf557904e72 (diff) | |
| parent | f1367b7e903a2a69a8f833bb272e91d77abd57c6 (diff) | |
Merge "Do not turn on imes unexpectedly with unit tests"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/inputmethod/InputMethodInfo.java | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/core/java/android/view/inputmethod/InputMethodInfo.java b/core/java/android/view/inputmethod/InputMethodInfo.java index 08e30aa37c40..54c2ba565125 100644 --- a/core/java/android/view/inputmethod/InputMethodInfo.java +++ b/core/java/android/view/inputmethod/InputMethodInfo.java @@ -81,6 +81,11 @@ public final class InputMethodInfo implements Parcelable { private boolean mIsAuxIme; /** + * Cavert: mForceDefault must be false for production. This flag is only for test. + */ + private final boolean mForceDefault; + + /** * Constructor. * * @param context The Context in which we are parsing the input method. @@ -108,6 +113,7 @@ public final class InputMethodInfo implements Parcelable { ServiceInfo si = service.serviceInfo; mId = new ComponentName(si.packageName, si.name).flattenToShortString(); mIsAuxIme = true; + mForceDefault = false; PackageManager pm = context.getPackageManager(); String settingsActivityComponent = null; @@ -215,13 +221,39 @@ public final class InputMethodInfo implements Parcelable { mIsAuxIme = source.readInt() == 1; mService = ResolveInfo.CREATOR.createFromParcel(source); source.readTypedList(mSubtypes, InputMethodSubtype.CREATOR); + mForceDefault = false; } /** - * Temporary API for creating a built-in input method. + * Temporary API for creating a built-in input method for test. */ public InputMethodInfo(String packageName, String className, CharSequence label, String settingsActivity) { + this(buildDummyResolveInfo(packageName, className, label), false, settingsActivity, null, + 0, false); + } + + /** + * Temporary API for creating a built-in input method for test. + * @hide + */ + public InputMethodInfo(ResolveInfo ri, boolean isAuxIme, + String settingsActivity, List<InputMethodSubtype> subtypes, int isDefaultResId, + boolean forceDefault) { + final ServiceInfo si = ri.serviceInfo; + mService = ri; + mId = new ComponentName(si.packageName, si.name).flattenToShortString(); + mSettingsActivityName = settingsActivity; + mIsDefaultResId = isDefaultResId; + mIsAuxIme = isAuxIme; + if (subtypes != null) { + mSubtypes.addAll(subtypes); + } + mForceDefault = forceDefault; + } + + private static ResolveInfo buildDummyResolveInfo(String packageName, String className, + CharSequence label) { ResolveInfo ri = new ResolveInfo(); ServiceInfo si = new ServiceInfo(); ApplicationInfo ai = new ApplicationInfo(); @@ -234,11 +266,7 @@ public final class InputMethodInfo implements Parcelable { si.exported = true; si.nonLocalizedLabel = label; ri.serviceInfo = si; - mService = ri; - mId = new ComponentName(si.packageName, si.name).flattenToShortString(); - mSettingsActivityName = settingsActivity; - mIsDefaultResId = 0; - mIsAuxIme = false; + return ri; } /** @@ -340,6 +368,22 @@ public final class InputMethodInfo implements Parcelable { return mIsDefaultResId; } + /** + * Return whether or not this ime is a default ime or not. + * @hide + */ + public boolean isDefault(Context context) { + if (mForceDefault) { + return true; + } + try { + final Resources res = context.createPackageContext(getPackageName(), 0).getResources(); + return res.getBoolean(getIsDefaultResourceId()); + } catch (NameNotFoundException e) { + return false; + } + } + public void dump(Printer pw, String prefix) { pw.println(prefix + "mId=" + mId + " mSettingsActivityName=" + mSettingsActivityName); |
