blob: 04028aeacd53d8d8469f6bea6d18d839bc67c9b0 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007-2008 The Android Open Source Project
Yohei Yukawa66996da2014-02-24 19:50:40 +09003 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
Yohei Yukawa66996da2014-02-24 19:50:40 +09007 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008 * http://www.apache.org/licenses/LICENSE-2.0
Yohei Yukawa66996da2014-02-24 19:50:40 +09009 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package android.view.inputmethod;
18
Yohei Yukawaddad4b92017-02-02 01:46:13 -080019import android.annotation.NonNull;
Mathew Inwooda570dee2018-08-17 14:56:00 +010020import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.ComponentName;
22import android.content.Context;
23import android.content.pm.ApplicationInfo;
24import android.content.pm.PackageManager;
satoke7c6998e2011-06-03 17:57:59 +090025import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.pm.ResolveInfo;
27import android.content.pm.ServiceInfo;
Dianne Hackborn20cb56e2010-03-04 00:58:29 -080028import android.content.res.Resources;
Yohei Yukawafcedfa02014-09-19 13:22:15 +090029import android.content.res.Resources.NotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.content.res.TypedArray;
31import android.content.res.XmlResourceParser;
32import android.graphics.drawable.Drawable;
33import android.os.Parcel;
34import android.os.Parcelable;
35import android.util.AttributeSet;
36import android.util.Printer;
Satoshi Kataokae62e6d82012-07-02 18:45:43 +090037import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.util.Xml;
Satoshi Kataokadc8abf62013-03-12 14:40:04 +090039import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070041import org.xmlpull.v1.XmlPullParser;
42import org.xmlpull.v1.XmlPullParserException;
43
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import java.io.IOException;
satok7eb84252010-08-04 18:26:42 +090045import java.util.ArrayList;
satoke7c6998e2011-06-03 17:57:59 +090046import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
48/**
49 * This class is used to specify meta information of an input method.
Scott Main5df06312013-10-18 16:07:47 -070050 *
Neil Fuller71fbb812015-11-30 09:51:33 +000051 * <p>It should be defined in an XML resource file with an {@code <input-method>} element.
Scott Main5df06312013-10-18 16:07:47 -070052 * For more information, see the guide to
53 * <a href="{@docRoot}guide/topics/text/creating-input-method.html">
54 * Creating an Input Method</a>.</p>
55 *
56 * @see InputMethodSubtype
57 *
58 * @attr ref android.R.styleable#InputMethod_settingsActivity
59 * @attr ref android.R.styleable#InputMethod_isDefault
60 * @attr ref android.R.styleable#InputMethod_supportsSwitchingToNextInputMethod
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 */
62public final class InputMethodInfo implements Parcelable {
Dianne Hackborneb034652009-09-07 00:49:58 -070063 static final String TAG = "InputMethodInfo";
satokab751aa2010-09-14 19:17:36 +090064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 /**
66 * The Service that implements this input method component.
67 */
68 final ResolveInfo mService;
Yohei Yukawa66996da2014-02-24 19:50:40 +090069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 /**
Tarandeep Singhb360b992017-11-21 14:25:34 -080071 * IME only supports VR mode.
72 */
73 final boolean mIsVrOnly;
74
75 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 * The unique string Id to identify the input method. This is generated
77 * from the input method component.
78 */
79 final String mId;
80
81 /**
82 * The input method setting activity's name, used by the system settings to
83 * launch the setting activity of this input method.
84 */
85 final String mSettingsActivityName;
86
87 /**
88 * The resource in the input method's .apk that holds a boolean indicating
89 * whether it should be considered the default input method for this
90 * system. This is a resource ID instead of the final value so that it
91 * can change based on the configuration (in particular locale).
92 */
93 final int mIsDefaultResId;
satok7eb84252010-08-04 18:26:42 +090094
95 /**
Yohei Yukawaf0656952014-03-03 15:38:18 +090096 * An array-like container of the subtypes.
satok7eb84252010-08-04 18:26:42 +090097 */
Mathew Inwooda570dee2018-08-17 14:56:00 +010098 @UnsupportedAppUsage
Yohei Yukawaf0656952014-03-03 15:38:18 +090099 private final InputMethodSubtypeArray mSubtypes;
satok7eb84252010-08-04 18:26:42 +0900100
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900101 private final boolean mIsAuxIme;
satokdbfba852011-09-05 19:19:12 +0900102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 /**
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900104 * Caveat: mForceDefault must be false for production. This flag is only for test.
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900105 */
106 private final boolean mForceDefault;
107
108 /**
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900109 * The flag whether this IME supports ways to switch to a next input method (e.g. globe key.)
110 */
111 private final boolean mSupportsSwitchingToNextInputMethod;
112
113 /**
Yohei Yukawaddad4b92017-02-02 01:46:13 -0800114 * @param service the {@link ResolveInfo} corresponds in which the IME is implemented.
115 * @return a unique ID to be returned by {@link #getId()}. We have used
116 * {@link ComponentName#flattenToShortString()} for this purpose (and it is already
117 * unrealistic to switch to a different scheme as it is already implicitly assumed in
118 * many places).
119 * @hide
120 */
121 public static String computeId(@NonNull ResolveInfo service) {
122 final ServiceInfo si = service.serviceInfo;
123 return new ComponentName(si.packageName, si.name).flattenToShortString();
124 }
125
126 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 * Constructor.
satoke7c6998e2011-06-03 17:57:59 +0900128 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 * @param context The Context in which we are parsing the input method.
130 * @param service The ResolveInfo returned from the package manager about
131 * this input method's component.
132 */
133 public InputMethodInfo(Context context, ResolveInfo service)
134 throws XmlPullParserException, IOException {
satoke7c6998e2011-06-03 17:57:59 +0900135 this(context, service, null);
136 }
137
138 /**
139 * Constructor.
140 *
141 * @param context The Context in which we are parsing the input method.
142 * @param service The ResolveInfo returned from the package manager about
143 * this input method's component.
Yohei Yukawaddad4b92017-02-02 01:46:13 -0800144 * @param additionalSubtypes additional subtypes being added to this InputMethodInfo
satoke7c6998e2011-06-03 17:57:59 +0900145 * @hide
146 */
147 public InputMethodInfo(Context context, ResolveInfo service,
Yohei Yukawaddad4b92017-02-02 01:46:13 -0800148 List<InputMethodSubtype> additionalSubtypes)
satoke7c6998e2011-06-03 17:57:59 +0900149 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 mService = service;
151 ServiceInfo si = service.serviceInfo;
Yohei Yukawaddad4b92017-02-02 01:46:13 -0800152 mId = computeId(service);
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900153 boolean isAuxIme = true;
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900154 boolean supportsSwitchingToNextInputMethod = false; // false as default
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900155 mForceDefault = false;
satok7eb84252010-08-04 18:26:42 +0900156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 PackageManager pm = context.getPackageManager();
158 String settingsActivityComponent = null;
Tarandeep Singhb360b992017-11-21 14:25:34 -0800159 boolean isVrOnly;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 int isDefaultResId = 0;
satok7eb84252010-08-04 18:26:42 +0900161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 XmlResourceParser parser = null;
Yohei Yukawaf0656952014-03-03 15:38:18 +0900163 final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 try {
165 parser = si.loadXmlMetaData(pm, InputMethod.SERVICE_META_DATA);
166 if (parser == null) {
167 throw new XmlPullParserException("No "
168 + InputMethod.SERVICE_META_DATA + " meta-data");
169 }
Yohei Yukawa66996da2014-02-24 19:50:40 +0900170
Dianne Hackborn20cb56e2010-03-04 00:58:29 -0800171 Resources res = pm.getResourcesForApplication(si.applicationInfo);
Yohei Yukawa66996da2014-02-24 19:50:40 +0900172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 AttributeSet attrs = Xml.asAttributeSet(parser);
Yohei Yukawa66996da2014-02-24 19:50:40 +0900174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 int type;
176 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
177 && type != XmlPullParser.START_TAG) {
178 }
Yohei Yukawa66996da2014-02-24 19:50:40 +0900179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 String nodeName = parser.getName();
181 if (!"input-method".equals(nodeName)) {
182 throw new XmlPullParserException(
183 "Meta-data does not start with input-method tag");
184 }
Yohei Yukawa66996da2014-02-24 19:50:40 +0900185
Dianne Hackborn20cb56e2010-03-04 00:58:29 -0800186 TypedArray sa = res.obtainAttributes(attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 com.android.internal.R.styleable.InputMethod);
188 settingsActivityComponent = sa.getString(
189 com.android.internal.R.styleable.InputMethod_settingsActivity);
Tarandeep Singhb360b992017-11-21 14:25:34 -0800190 isVrOnly = sa.getBoolean(com.android.internal.R.styleable.InputMethod_isVrOnly, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 isDefaultResId = sa.getResourceId(
192 com.android.internal.R.styleable.InputMethod_isDefault, 0);
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900193 supportsSwitchingToNextInputMethod = sa.getBoolean(
194 com.android.internal.R.styleable.InputMethod_supportsSwitchingToNextInputMethod,
195 false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 sa.recycle();
satok7eb84252010-08-04 18:26:42 +0900197
198 final int depth = parser.getDepth();
199 // Parse all subtypes
200 while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
201 && type != XmlPullParser.END_DOCUMENT) {
satokab751aa2010-09-14 19:17:36 +0900202 if (type == XmlPullParser.START_TAG) {
203 nodeName = parser.getName();
204 if (!"subtype".equals(nodeName)) {
205 throw new XmlPullParserException(
206 "Meta-data in input-method does not start with subtype tag");
207 }
208 final TypedArray a = res.obtainAttributes(
209 attrs, com.android.internal.R.styleable.InputMethod_Subtype);
Satoshi Kataokadc8abf62013-03-12 14:40:04 +0900210 final InputMethodSubtype subtype = new InputMethodSubtypeBuilder()
211 .setSubtypeNameResId(a.getResourceId(com.android.internal.R.styleable
212 .InputMethod_Subtype_label, 0))
213 .setSubtypeIconResId(a.getResourceId(com.android.internal.R.styleable
214 .InputMethod_Subtype_icon, 0))
Yohei Yukawab8456a62016-01-21 22:24:44 -0800215 .setLanguageTag(a.getString(com.android.internal.R.styleable
216 .InputMethod_Subtype_languageTag))
Satoshi Kataokadc8abf62013-03-12 14:40:04 +0900217 .setSubtypeLocale(a.getString(com.android.internal.R.styleable
218 .InputMethod_Subtype_imeSubtypeLocale))
219 .setSubtypeMode(a.getString(com.android.internal.R.styleable
220 .InputMethod_Subtype_imeSubtypeMode))
221 .setSubtypeExtraValue(a.getString(com.android.internal.R.styleable
222 .InputMethod_Subtype_imeSubtypeExtraValue))
223 .setIsAuxiliary(a.getBoolean(com.android.internal.R.styleable
224 .InputMethod_Subtype_isAuxiliary, false))
225 .setOverridesImplicitlyEnabledSubtype(a.getBoolean(
226 com.android.internal.R.styleable
227 .InputMethod_Subtype_overridesImplicitlyEnabledSubtype, false))
228 .setSubtypeId(a.getInt(com.android.internal.R.styleable
229 .InputMethod_Subtype_subtypeId, 0 /* use Arrays.hashCode */))
230 .setIsAsciiCapable(a.getBoolean(com.android.internal.R.styleable
231 .InputMethod_Subtype_isAsciiCapable, false)).build();
satokdbfba852011-09-05 19:19:12 +0900232 if (!subtype.isAuxiliary()) {
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900233 isAuxIme = false;
satokdbfba852011-09-05 19:19:12 +0900234 }
Yohei Yukawaf0656952014-03-03 15:38:18 +0900235 subtypes.add(subtype);
satok7eb84252010-08-04 18:26:42 +0900236 }
satok7eb84252010-08-04 18:26:42 +0900237 }
Keisuke Kuroyanagie65e8602016-08-04 13:58:35 +0900238 } catch (NameNotFoundException | IndexOutOfBoundsException | NumberFormatException e) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -0800239 throw new XmlPullParserException(
240 "Unable to create context for: " + si.packageName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 } finally {
242 if (parser != null) parser.close();
243 }
satoke7c6998e2011-06-03 17:57:59 +0900244
Yohei Yukawaf0656952014-03-03 15:38:18 +0900245 if (subtypes.size() == 0) {
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900246 isAuxIme = false;
satokdbfba852011-09-05 19:19:12 +0900247 }
248
Yohei Yukawaddad4b92017-02-02 01:46:13 -0800249 if (additionalSubtypes != null) {
satoke7c6998e2011-06-03 17:57:59 +0900250 final int N = additionalSubtypes.size();
251 for (int i = 0; i < N; ++i) {
252 final InputMethodSubtype subtype = additionalSubtypes.get(i);
Yohei Yukawaf0656952014-03-03 15:38:18 +0900253 if (!subtypes.contains(subtype)) {
254 subtypes.add(subtype);
Satoshi Kataokae62e6d82012-07-02 18:45:43 +0900255 } else {
256 Slog.w(TAG, "Duplicated subtype definition found: "
257 + subtype.getLocale() + ", " + subtype.getMode());
satoke7c6998e2011-06-03 17:57:59 +0900258 }
259 }
260 }
Yohei Yukawaf0656952014-03-03 15:38:18 +0900261 mSubtypes = new InputMethodSubtypeArray(subtypes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 mSettingsActivityName = settingsActivityComponent;
263 mIsDefaultResId = isDefaultResId;
Satoshi Kataoka660e6c92013-08-01 16:50:48 +0900264 mIsAuxIme = isAuxIme;
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900265 mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
Tarandeep Singheda9f312018-03-08 16:11:37 -0800266 mIsVrOnly = isVrOnly;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 }
268
269 InputMethodInfo(Parcel source) {
270 mId = source.readString();
271 mSettingsActivityName = source.readString();
272 mIsDefaultResId = source.readInt();
satokdbfba852011-09-05 19:19:12 +0900273 mIsAuxIme = source.readInt() == 1;
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900274 mSupportsSwitchingToNextInputMethod = source.readInt() == 1;
Tarandeep Singhb360b992017-11-21 14:25:34 -0800275 mIsVrOnly = source.readBoolean();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 mService = ResolveInfo.CREATOR.createFromParcel(source);
Yohei Yukawaf0656952014-03-03 15:38:18 +0900277 mSubtypes = new InputMethodSubtypeArray(source);
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900278 mForceDefault = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 }
satok7eb84252010-08-04 18:26:42 +0900280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 /**
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900282 * Temporary API for creating a built-in input method for test.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 */
284 public InputMethodInfo(String packageName, String className,
285 CharSequence label, String settingsActivity) {
Tadashi G. Takaokae12a6ff2017-01-11 15:51:44 +0900286 this(buildDummyResolveInfo(packageName, className, label), false /* isAuxIme */,
287 settingsActivity, null /* subtypes */, 0 /* isDefaultResId */,
Tarandeep Singhb360b992017-11-21 14:25:34 -0800288 false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */,
289 false /* isVrOnly */);
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900290 }
291
292 /**
293 * Temporary API for creating a built-in input method for test.
294 * @hide
295 */
296 public InputMethodInfo(ResolveInfo ri, boolean isAuxIme,
297 String settingsActivity, List<InputMethodSubtype> subtypes, int isDefaultResId,
298 boolean forceDefault) {
Tadashi G. Takaokae12a6ff2017-01-11 15:51:44 +0900299 this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault,
Tarandeep Singhb360b992017-11-21 14:25:34 -0800300 true /* supportsSwitchingToNextInputMethod */, false /* isVrOnly */);
Yohei Yukawad1da1152014-05-01 17:20:05 +0900301 }
302
303 /**
304 * Temporary API for creating a built-in input method for test.
305 * @hide
306 */
Tadashi G. Takaokae12a6ff2017-01-11 15:51:44 +0900307 public InputMethodInfo(ResolveInfo ri, boolean isAuxIme, String settingsActivity,
308 List<InputMethodSubtype> subtypes, int isDefaultResId, boolean forceDefault,
Tarandeep Singhb360b992017-11-21 14:25:34 -0800309 boolean supportsSwitchingToNextInputMethod, boolean isVrOnly) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900310 final ServiceInfo si = ri.serviceInfo;
311 mService = ri;
312 mId = new ComponentName(si.packageName, si.name).flattenToShortString();
313 mSettingsActivityName = settingsActivity;
314 mIsDefaultResId = isDefaultResId;
315 mIsAuxIme = isAuxIme;
Yohei Yukawaf0656952014-03-03 15:38:18 +0900316 mSubtypes = new InputMethodSubtypeArray(subtypes);
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900317 mForceDefault = forceDefault;
Yohei Yukawad1da1152014-05-01 17:20:05 +0900318 mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod;
Tarandeep Singhb360b992017-11-21 14:25:34 -0800319 mIsVrOnly = isVrOnly;
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900320 }
321
322 private static ResolveInfo buildDummyResolveInfo(String packageName, String className,
323 CharSequence label) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 ResolveInfo ri = new ResolveInfo();
325 ServiceInfo si = new ServiceInfo();
326 ApplicationInfo ai = new ApplicationInfo();
327 ai.packageName = packageName;
328 ai.enabled = true;
329 si.applicationInfo = ai;
330 si.enabled = true;
331 si.packageName = packageName;
332 si.name = className;
333 si.exported = true;
334 si.nonLocalizedLabel = label;
335 ri.serviceInfo = si;
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900336 return ri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 }
satok7eb84252010-08-04 18:26:42 +0900338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 /**
340 * Return a unique ID for this input method. The ID is generated from
341 * the package and class name implementing the method.
342 */
343 public String getId() {
344 return mId;
345 }
satok7eb84252010-08-04 18:26:42 +0900346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 /**
348 * Return the .apk package that implements this input method.
349 */
350 public String getPackageName() {
351 return mService.serviceInfo.packageName;
352 }
satok7eb84252010-08-04 18:26:42 +0900353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 /**
355 * Return the class name of the service component that implements
356 * this input method.
357 */
358 public String getServiceName() {
359 return mService.serviceInfo.name;
360 }
361
362 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700363 * Return the raw information about the Service implementing this
364 * input method. Do not modify the returned object.
365 */
366 public ServiceInfo getServiceInfo() {
367 return mService.serviceInfo;
368 }
369
370 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 * Return the component of the service that implements this input
372 * method.
373 */
374 public ComponentName getComponent() {
375 return new ComponentName(mService.serviceInfo.packageName,
376 mService.serviceInfo.name);
377 }
satok7eb84252010-08-04 18:26:42 +0900378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 /**
380 * Load the user-displayed label for this input method.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900381 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 * @param pm Supply a PackageManager used to load the input method's
383 * resources.
384 */
385 public CharSequence loadLabel(PackageManager pm) {
386 return mService.loadLabel(pm);
387 }
satok7eb84252010-08-04 18:26:42 +0900388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 /**
390 * Load the user-displayed icon for this input method.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900391 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 * @param pm Supply a PackageManager used to load the input method's
393 * resources.
394 */
395 public Drawable loadIcon(PackageManager pm) {
396 return mService.loadIcon(pm);
397 }
satok7eb84252010-08-04 18:26:42 +0900398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 /**
400 * Return the class name of an activity that provides a settings UI for
401 * the input method. You can launch this activity be starting it with
402 * an {@link android.content.Intent} whose action is MAIN and with an
403 * explicit {@link android.content.ComponentName}
404 * composed of {@link #getPackageName} and the class name returned here.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900405 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 * <p>A null will be returned if there is no settings activity associated
Yohei Yukawaf0656952014-03-03 15:38:18 +0900407 * with the input method.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 */
409 public String getSettingsActivity() {
410 return mSettingsActivityName;
411 }
satok7eb84252010-08-04 18:26:42 +0900412
413 /**
Tarandeep Singhb360b992017-11-21 14:25:34 -0800414 * Returns true if IME supports VR mode only.
415 * @hide
416 */
417 public boolean isVrOnly() {
418 return mIsVrOnly;
419 }
420
421 /**
Ken Wakasa586f0512011-01-20 22:31:01 +0900422 * Return the count of the subtypes of Input Method.
satok7eb84252010-08-04 18:26:42 +0900423 */
Ken Wakasa586f0512011-01-20 22:31:01 +0900424 public int getSubtypeCount() {
Yohei Yukawaf0656952014-03-03 15:38:18 +0900425 return mSubtypes.getCount();
Ken Wakasa586f0512011-01-20 22:31:01 +0900426 }
427
428 /**
429 * Return the Input Method's subtype at the specified index.
430 *
431 * @param index the index of the subtype to return.
432 */
433 public InputMethodSubtype getSubtypeAt(int index) {
434 return mSubtypes.get(index);
satok7eb84252010-08-04 18:26:42 +0900435 }
436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 /**
438 * Return the resource identifier of a resource inside of this input
439 * method's .apk that determines whether it should be considered a
440 * default input method for the system.
441 */
442 public int getIsDefaultResourceId() {
443 return mIsDefaultResId;
444 }
satok7eb84252010-08-04 18:26:42 +0900445
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900446 /**
447 * Return whether or not this ime is a default ime or not.
448 * @hide
449 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100450 @UnsupportedAppUsage
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900451 public boolean isDefault(Context context) {
452 if (mForceDefault) {
453 return true;
454 }
455 try {
Yohei Yukawadc489242014-09-14 12:01:59 +0900456 if (getIsDefaultResourceId() == 0) {
457 return false;
458 }
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900459 final Resources res = context.createPackageContext(getPackageName(), 0).getResources();
460 return res.getBoolean(getIsDefaultResourceId());
Yohei Yukawafcedfa02014-09-19 13:22:15 +0900461 } catch (NameNotFoundException | NotFoundException e) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900462 return false;
463 }
464 }
465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 public void dump(Printer pw, String prefix) {
467 pw.println(prefix + "mId=" + mId
Seigo Nonakad742bfd2015-10-14 19:52:32 +0900468 + " mSettingsActivityName=" + mSettingsActivityName
Tarandeep Singhb360b992017-11-21 14:25:34 -0800469 + " mIsVrOnly=" + mIsVrOnly
Tadashi G. Takaoka46699672017-03-31 12:17:20 +0900470 + " mSupportsSwitchingToNextInputMethod=" + mSupportsSwitchingToNextInputMethod);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 pw.println(prefix + "mIsDefaultResId=0x"
472 + Integer.toHexString(mIsDefaultResId));
473 pw.println(prefix + "Service:");
474 mService.dump(pw, prefix + " ");
475 }
Yohei Yukawa66996da2014-02-24 19:50:40 +0900476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 @Override
478 public String toString() {
Dianne Hackborneb034652009-09-07 00:49:58 -0700479 return "InputMethodInfo{" + mId
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 + ", settings: "
481 + mSettingsActivityName + "}";
482 }
483
484 /**
485 * Used to test whether the given parameter object is an
486 * {@link InputMethodInfo} and its Id is the same to this one.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900487 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 * @return true if the given parameter object is an
489 * {@link InputMethodInfo} and its Id is the same to this one.
490 */
491 @Override
492 public boolean equals(Object o) {
493 if (o == this) return true;
494 if (o == null) return false;
495
496 if (!(o instanceof InputMethodInfo)) return false;
497
498 InputMethodInfo obj = (InputMethodInfo) o;
499 return mId.equals(obj.mId);
500 }
satokc50232d2011-03-25 13:52:48 +0900501
502 @Override
503 public int hashCode() {
504 return mId.hashCode();
505 }
506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 /**
satokdbfba852011-09-05 19:19:12 +0900508 * @hide
Yohei Yukawafd70fe82018-04-08 12:19:56 -0700509 * @return {@code true} if the IME is a trusted system component (e.g. pre-installed)
510 */
511 public boolean isSystem() {
512 return (mService.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
513 }
514
515 /**
516 * @hide
satokdbfba852011-09-05 19:19:12 +0900517 */
518 public boolean isAuxiliaryIme() {
519 return mIsAuxIme;
520 }
521
522 /**
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900523 * @return true if this input method supports ways to switch to a next input method.
524 * @hide
525 */
526 public boolean supportsSwitchingToNextInputMethod() {
527 return mSupportsSwitchingToNextInputMethod;
528 }
529
530 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 * Used to package this object into a {@link Parcel}.
Yohei Yukawa66996da2014-02-24 19:50:40 +0900532 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 * @param dest The {@link Parcel} to be written.
534 * @param flags The flags used for parceling.
535 */
satokdbfba852011-09-05 19:19:12 +0900536 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 public void writeToParcel(Parcel dest, int flags) {
538 dest.writeString(mId);
539 dest.writeString(mSettingsActivityName);
540 dest.writeInt(mIsDefaultResId);
satokdbfba852011-09-05 19:19:12 +0900541 dest.writeInt(mIsAuxIme ? 1 : 0);
Satoshi Kataoka69da2692013-08-15 15:36:44 +0900542 dest.writeInt(mSupportsSwitchingToNextInputMethod ? 1 : 0);
Tarandeep Singhb360b992017-11-21 14:25:34 -0800543 dest.writeBoolean(mIsVrOnly);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 mService.writeToParcel(dest, flags);
Yohei Yukawaf0656952014-03-03 15:38:18 +0900545 mSubtypes.writeToParcel(dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 }
547
548 /**
549 * Used to make this class parcelable.
550 */
satok7eb84252010-08-04 18:26:42 +0900551 public static final Parcelable.Creator<InputMethodInfo> CREATOR
552 = new Parcelable.Creator<InputMethodInfo>() {
satokdbfba852011-09-05 19:19:12 +0900553 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 public InputMethodInfo createFromParcel(Parcel source) {
555 return new InputMethodInfo(source);
556 }
557
satokdbfba852011-09-05 19:19:12 +0900558 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 public InputMethodInfo[] newArray(int size) {
560 return new InputMethodInfo[size];
561 }
562 };
563
satokdbfba852011-09-05 19:19:12 +0900564 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 public int describeContents() {
566 return 0;
567 }
568}