The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2008 The Android Open Source Project |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4 | * 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 |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | * 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 | |
| 17 | package com.android.server; |
| 18 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 19 | import com.android.internal.content.PackageMonitor; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 20 | import com.android.internal.os.AtomicFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import com.android.internal.os.HandlerCaller; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 22 | import com.android.internal.util.FastXmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import com.android.internal.view.IInputContext; |
| 24 | import com.android.internal.view.IInputMethod; |
| 25 | import com.android.internal.view.IInputMethodCallback; |
| 26 | import com.android.internal.view.IInputMethodClient; |
| 27 | import com.android.internal.view.IInputMethodManager; |
| 28 | import com.android.internal.view.IInputMethodSession; |
| 29 | import com.android.internal.view.InputBindResult; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 30 | import com.android.server.EventLogTags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 32 | import org.xmlpull.v1.XmlPullParser; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import org.xmlpull.v1.XmlPullParserException; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 34 | import org.xmlpull.v1.XmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | import android.app.ActivityManagerNative; |
| 37 | import android.app.AlertDialog; |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame^] | 38 | import android.app.KeyguardManager; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 39 | import android.app.Notification; |
| 40 | import android.app.NotificationManager; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 41 | import android.app.PendingIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.content.ComponentName; |
| 43 | import android.content.ContentResolver; |
| 44 | import android.content.Context; |
| 45 | import android.content.DialogInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.DialogInterface.OnCancelListener; |
| 47 | import android.content.Intent; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 48 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 50 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.content.pm.PackageManager; |
| 52 | import android.content.pm.ResolveInfo; |
| 53 | import android.content.pm.ServiceInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 54 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.res.Resources; |
| 56 | import android.content.res.TypedArray; |
| 57 | import android.database.ContentObserver; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 58 | import android.graphics.BitmapFactory; |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 59 | import android.inputmethodservice.InputMethodService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.os.Binder; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 61 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.os.Handler; |
| 63 | import android.os.IBinder; |
| 64 | import android.os.IInterface; |
| 65 | import android.os.Message; |
| 66 | import android.os.Parcel; |
| 67 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 68 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.os.ServiceManager; |
| 70 | import android.os.SystemClock; |
| 71 | import android.provider.Settings; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 72 | import android.provider.Settings.Secure; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 73 | import android.provider.Settings.SettingNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.text.TextUtils; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 75 | import android.text.style.SuggestionSpan; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.util.EventLog; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 77 | import android.util.LruCache; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 78 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.util.PrintWriterPrinter; |
| 80 | import android.util.Printer; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 81 | import android.util.Slog; |
| 82 | import android.util.Xml; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.view.IWindowManager; |
| 84 | import android.view.WindowManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 85 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.view.inputmethod.InputBinding; |
| 87 | import android.view.inputmethod.InputMethod; |
| 88 | import android.view.inputmethod.InputMethodInfo; |
| 89 | import android.view.inputmethod.InputMethodManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 90 | import android.view.inputmethod.InputMethodSubtype; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 92 | import java.io.File; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import java.io.FileDescriptor; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 94 | import java.io.FileInputStream; |
| 95 | import java.io.FileOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import java.io.IOException; |
| 97 | import java.io.PrintWriter; |
| 98 | import java.util.ArrayList; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 99 | import java.util.Collections; |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 100 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import java.util.HashMap; |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 102 | import java.util.HashSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | import java.util.List; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 104 | import java.util.Set; |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 105 | import java.util.TreeMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * This class provides a system service that manages input methods. |
| 109 | */ |
| 110 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 111 | implements ServiceConnection, Handler.Callback { |
| 112 | static final boolean DEBUG = false; |
| 113 | static final String TAG = "InputManagerService"; |
| 114 | |
| 115 | static final int MSG_SHOW_IM_PICKER = 1; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 116 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2; |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 117 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3; |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 118 | static final int MSG_SHOW_IM_CONFIG = 4; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | static final int MSG_UNBIND_INPUT = 1000; |
| 121 | static final int MSG_BIND_INPUT = 1010; |
| 122 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 123 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
| 124 | static final int MSG_ATTACH_TOKEN = 1040; |
| 125 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | static final int MSG_START_INPUT = 2000; |
| 128 | static final int MSG_RESTART_INPUT = 2010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | static final int MSG_UNBIND_METHOD = 3000; |
| 131 | static final int MSG_BIND_METHOD = 3010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | static final long TIME_TO_RECONNECT = 10*1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 134 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 135 | static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20; |
| 136 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 137 | private static final int NOT_A_SUBTYPE_ID = -1; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 138 | private static final String NOT_A_SUBTYPE_ID_STR = String.valueOf(NOT_A_SUBTYPE_ID); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 139 | private static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; |
| 140 | private static final String SUBTYPE_MODE_VOICE = "voice"; |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 141 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | final Context mContext; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 144 | final Resources mRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 146 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | final SettingsObserver mSettingsObserver; |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 148 | final StatusBarManagerService mStatusBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | final IWindowManager mIWindowManager; |
| 150 | final HandlerCaller mCaller; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 151 | private final InputMethodFileManager mFileManager; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | final InputBindResult mNoBinding = new InputBindResult(null, null, -1); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | // All known input methods. mMethodMap also serves as the global |
| 156 | // lock for this class. |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 157 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>(); |
| 158 | final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 159 | private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = |
| 160 | new LruCache<SuggestionSpan, InputMethodInfo>(SECURE_SUGGESTION_SPANS_MAX_SIZE); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 161 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 162 | // Ongoing notification |
| 163 | private final NotificationManager mNotificationManager; |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame^] | 164 | private final KeyguardManager mKeyguardManager; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 165 | private final Notification mImeSwitcherNotification; |
| 166 | private final PendingIntent mImeSwitchPendingIntent; |
| 167 | private final boolean mShowOngoingImeSwitcherForPhones; |
| 168 | private boolean mNotificationShown; |
| 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | class SessionState { |
| 171 | final ClientState client; |
| 172 | final IInputMethod method; |
| 173 | final IInputMethodSession session; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | @Override |
| 176 | public String toString() { |
| 177 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 178 | + " method " + Integer.toHexString( |
| 179 | System.identityHashCode(method)) |
| 180 | + " session " + Integer.toHexString( |
| 181 | System.identityHashCode(session)) |
| 182 | + "}"; |
| 183 | } |
| 184 | |
| 185 | SessionState(ClientState _client, IInputMethod _method, |
| 186 | IInputMethodSession _session) { |
| 187 | client = _client; |
| 188 | method = _method; |
| 189 | session = _session; |
| 190 | } |
| 191 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | class ClientState { |
| 194 | final IInputMethodClient client; |
| 195 | final IInputContext inputContext; |
| 196 | final int uid; |
| 197 | final int pid; |
| 198 | final InputBinding binding; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | boolean sessionRequested; |
| 201 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | @Override |
| 204 | public String toString() { |
| 205 | return "ClientState{" + Integer.toHexString( |
| 206 | System.identityHashCode(this)) + " uid " + uid |
| 207 | + " pid " + pid + "}"; |
| 208 | } |
| 209 | |
| 210 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
| 211 | int _uid, int _pid) { |
| 212 | client = _client; |
| 213 | inputContext = _inputContext; |
| 214 | uid = _uid; |
| 215 | pid = _pid; |
| 216 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
| 217 | } |
| 218 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | final HashMap<IBinder, ClientState> mClients |
| 221 | = new HashMap<IBinder, ClientState>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 224 | * Set once the system is ready to run third party code. |
| 225 | */ |
| 226 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 227 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 228 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | * Id of the currently selected input method. |
| 230 | */ |
| 231 | String mCurMethodId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | /** |
| 234 | * The current binding sequence number, incremented every time there is |
| 235 | * a new bind performed. |
| 236 | */ |
| 237 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | /** |
| 240 | * The client that is currently bound to an input method. |
| 241 | */ |
| 242 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 245 | * The last window token that gained focus. |
| 246 | */ |
| 247 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 248 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 249 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | * The input context last provided by the current client. |
| 251 | */ |
| 252 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | /** |
| 255 | * The attributes last provided by the current client. |
| 256 | */ |
| 257 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | /** |
| 260 | * The input method ID of the input method service that we are currently |
| 261 | * connected to or in the process of connecting to. |
| 262 | */ |
| 263 | String mCurId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 266 | * The current subtype of the current input method. |
| 267 | */ |
| 268 | private InputMethodSubtype mCurrentSubtype; |
| 269 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 270 | // This list contains the pairs of InputMethodInfo and InputMethodSubtype. |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 271 | private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>> |
| 272 | mShortcutInputMethodsAndSubtypes = |
| 273 | new HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 274 | |
| 275 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | * Set to true if our ServiceConnection is currently actively bound to |
| 277 | * a service (whether or not we have gotten its IBinder back yet). |
| 278 | */ |
| 279 | boolean mHaveConnection; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | /** |
| 282 | * Set if the client has asked for the input method to be shown. |
| 283 | */ |
| 284 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | /** |
| 287 | * Set if we were explicitly told to show the input method. |
| 288 | */ |
| 289 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | /** |
| 292 | * Set if we were forced to be shown. |
| 293 | */ |
| 294 | boolean mShowForced; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | /** |
| 297 | * Set if we last told the input method to show itself. |
| 298 | */ |
| 299 | boolean mInputShown; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | /** |
| 302 | * The Intent used to connect to the current input method. |
| 303 | */ |
| 304 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | /** |
| 307 | * The token we have made for the currently active input method, to |
| 308 | * identify it in the future. |
| 309 | */ |
| 310 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | /** |
| 313 | * If non-null, this is the input method service we are currently connected |
| 314 | * to. |
| 315 | */ |
| 316 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | /** |
| 319 | * Time that we last initiated a bind to the input method, to determine |
| 320 | * if we should try to disconnect and reconnect to it. |
| 321 | */ |
| 322 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | /** |
| 325 | * Have we called mCurMethod.bindInput()? |
| 326 | */ |
| 327 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | /** |
| 330 | * Currently enabled session. Only touched by service thread, not |
| 331 | * protected by a lock. |
| 332 | */ |
| 333 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | /** |
| 336 | * True if the screen is on. The value is true initially. |
| 337 | */ |
| 338 | boolean mScreenOn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 339 | |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 340 | int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
| 341 | int mImeWindowVis; |
| 342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | AlertDialog.Builder mDialogBuilder; |
| 344 | AlertDialog mSwitchingDialog; |
| 345 | InputMethodInfo[] mIms; |
| 346 | CharSequence[] mItems; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 347 | int[] mSubtypeIds; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | class SettingsObserver extends ContentObserver { |
| 350 | SettingsObserver(Handler handler) { |
| 351 | super(handler); |
| 352 | ContentResolver resolver = mContext.getContentResolver(); |
| 353 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 354 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 355 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
satok | b6109bb | 2011-02-03 22:24:54 +0900 | [diff] [blame] | 356 | Settings.Secure.ENABLED_INPUT_METHODS), false, this); |
| 357 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 358 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | @Override public void onChange(boolean selfChange) { |
| 362 | synchronized (mMethodMap) { |
| 363 | updateFromSettingsLocked(); |
| 364 | } |
| 365 | } |
| 366 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | class ScreenOnOffReceiver extends android.content.BroadcastReceiver { |
| 369 | @Override |
| 370 | public void onReceive(Context context, Intent intent) { |
| 371 | if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { |
| 372 | mScreenOn = true; |
| 373 | } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { |
| 374 | mScreenOn = false; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 375 | } else if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { |
| 376 | hideInputMethodMenu(); |
| 377 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 379 | Slog.w(TAG, "Unexpected intent " + intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // Inform the current client of the change in active status |
| 383 | try { |
| 384 | if (mCurClient != null && mCurClient.client != null) { |
| 385 | mCurClient.client.setActive(mScreenOn); |
| 386 | } |
| 387 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 388 | Slog.w(TAG, "Got RemoteException sending 'screen on/off' notification to pid " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 390 | } |
| 391 | } |
| 392 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 393 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 394 | class MyPackageMonitor extends PackageMonitor { |
| 395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 397 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | synchronized (mMethodMap) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 399 | String curInputMethodId = Settings.Secure.getString(mContext |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 401 | final int N = mMethodList.size(); |
| 402 | if (curInputMethodId != null) { |
| 403 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 404 | InputMethodInfo imi = mMethodList.get(i); |
| 405 | if (imi.getId().equals(curInputMethodId)) { |
| 406 | for (String pkg : packages) { |
| 407 | if (imi.getPackageName().equals(pkg)) { |
| 408 | if (!doit) { |
| 409 | return true; |
| 410 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 411 | resetSelectedInputMethodAndSubtypeLocked(""); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 412 | chooseNewDefaultIMELocked(); |
| 413 | return true; |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | return false; |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public void onSomePackagesChanged() { |
| 425 | synchronized (mMethodMap) { |
| 426 | InputMethodInfo curIm = null; |
| 427 | String curInputMethodId = Settings.Secure.getString(mContext |
| 428 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 429 | final int N = mMethodList.size(); |
| 430 | if (curInputMethodId != null) { |
| 431 | for (int i=0; i<N; i++) { |
| 432 | InputMethodInfo imi = mMethodList.get(i); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 433 | final String imiId = imi.getId(); |
| 434 | if (imiId.equals(curInputMethodId)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 435 | curIm = imi; |
| 436 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 437 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 438 | int change = isPackageDisappearing(imi.getPackageName()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 439 | if (isPackageModified(imi.getPackageName())) { |
| 440 | mFileManager.deleteAllInputMethodSubtypes(imiId); |
| 441 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 442 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 443 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 444 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 445 | + imi.getComponent()); |
| 446 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 450 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 451 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| 452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 454 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 455 | if (curIm != null) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 456 | int change = isPackageDisappearing(curIm.getPackageName()); |
| 457 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 458 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 459 | ServiceInfo si = null; |
| 460 | try { |
| 461 | si = mContext.getPackageManager().getServiceInfo( |
| 462 | curIm.getComponent(), 0); |
| 463 | } catch (PackageManager.NameNotFoundException ex) { |
| 464 | } |
| 465 | if (si == null) { |
| 466 | // Uh oh, current input method is no longer around! |
| 467 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 468 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 469 | mImeWindowVis = 0; |
| 470 | mStatusBar.setImeWindowStatus(mCurToken, mImeWindowVis, |
| 471 | mBackDisposition); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 472 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 473 | changed = true; |
| 474 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 475 | Slog.i(TAG, "Unsetting current input method"); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 476 | resetSelectedInputMethodAndSubtypeLocked(""); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 477 | } |
| 478 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 479 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 480 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 481 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 482 | if (curIm == null) { |
| 483 | // We currently don't have a default input method... is |
| 484 | // one now available? |
| 485 | changed = chooseNewDefaultIMELocked(); |
| 486 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 487 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 488 | if (changed) { |
| 489 | updateFromSettingsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | } |
| 493 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | class MethodCallback extends IInputMethodCallback.Stub { |
| 496 | final IInputMethod mMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | MethodCallback(IInputMethod method) { |
| 499 | mMethod = method; |
| 500 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 501 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 502 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | public void finishedEvent(int seq, boolean handled) throws RemoteException { |
| 504 | } |
| 505 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 506 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | public void sessionCreated(IInputMethodSession session) throws RemoteException { |
| 508 | onSessionCreated(mMethod, session); |
| 509 | } |
| 510 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 511 | |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 512 | public InputMethodManagerService(Context context, StatusBarManagerService statusBar) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | mContext = context; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 514 | mRes = context.getResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | mHandler = new Handler(this); |
| 516 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 517 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
| 518 | mCaller = new HandlerCaller(context, new HandlerCaller.Callback() { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 519 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | public void executeMessage(Message msg) { |
| 521 | handleMessage(msg); |
| 522 | } |
| 523 | }); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 524 | |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame^] | 525 | mKeyguardManager = (KeyguardManager) |
| 526 | mContext.getSystemService(Context.KEYGUARD_SERVICE); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 527 | mNotificationManager = (NotificationManager) |
| 528 | mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 529 | mImeSwitcherNotification = new Notification(); |
| 530 | mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default; |
| 531 | mImeSwitcherNotification.when = 0; |
| 532 | mImeSwitcherNotification.flags = Notification.FLAG_ONGOING_EVENT; |
| 533 | mImeSwitcherNotification.tickerText = null; |
| 534 | mImeSwitcherNotification.defaults = 0; // please be quiet |
| 535 | mImeSwitcherNotification.sound = null; |
| 536 | mImeSwitcherNotification.vibrate = null; |
| 537 | Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER); |
satok | 683e238 | 2011-07-12 08:28:52 +0900 | [diff] [blame] | 538 | mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 539 | mShowOngoingImeSwitcherForPhones = mRes.getBoolean( |
| 540 | com.android.internal.R.bool.show_ongoing_ime_switcher); |
| 541 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 542 | synchronized (mMethodMap) { |
| 543 | mFileManager = new InputMethodFileManager(mMethodMap); |
| 544 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 545 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 546 | (new MyPackageMonitor()).register(mContext, true); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | IntentFilter screenOnOffFilt = new IntentFilter(); |
| 549 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_ON); |
| 550 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_OFF); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 551 | screenOnOffFilt.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | mContext.registerReceiver(new ScreenOnOffReceiver(), screenOnOffFilt); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 553 | |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 554 | mStatusBar = statusBar; |
| 555 | statusBar.setIconVisibility("ime", false); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 556 | mNotificationShown = false; |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 557 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 558 | // mSettings should be created before buildInputMethodListLocked |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 559 | mSettings = new InputMethodSettings( |
| 560 | mRes, context.getContentResolver(), mMethodMap, mMethodList); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | buildInputMethodListLocked(mMethodList, mMethodMap); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 562 | mSettings.enableAllIMEsIfThereIsNoEnabledIME(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 564 | if (TextUtils.isEmpty(Settings.Secure.getString( |
| 565 | mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | InputMethodInfo defIm = null; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 567 | for (InputMethodInfo imi: mMethodList) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | if (defIm == null && imi.getIsDefaultResourceId() != 0) { |
| 569 | try { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 570 | Resources res = context.createPackageContext( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | imi.getPackageName(), 0).getResources(); |
| 572 | if (res.getBoolean(imi.getIsDefaultResourceId())) { |
| 573 | defIm = imi; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 574 | Slog.i(TAG, "Selected default: " + imi.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | } |
| 576 | } catch (PackageManager.NameNotFoundException ex) { |
| 577 | } catch (Resources.NotFoundException ex) { |
| 578 | } |
| 579 | } |
| 580 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 581 | if (defIm == null && mMethodList.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | defIm = mMethodList.get(0); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 583 | Slog.i(TAG, "No default found, using " + defIm.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | if (defIm != null) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 586 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | } |
| 588 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | mSettingsObserver = new SettingsObserver(mHandler); |
| 591 | updateFromSettingsLocked(); |
| 592 | } |
| 593 | |
| 594 | @Override |
| 595 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 596 | throws RemoteException { |
| 597 | try { |
| 598 | return super.onTransact(code, data, reply, flags); |
| 599 | } catch (RuntimeException e) { |
| 600 | // The input method manager only throws security exceptions, so let's |
| 601 | // log all others. |
| 602 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 603 | Slog.e(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | } |
| 605 | throw e; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | public void systemReady() { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 610 | synchronized (mMethodMap) { |
| 611 | if (!mSystemReady) { |
| 612 | mSystemReady = true; |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 613 | try { |
| 614 | startInputInnerLocked(); |
| 615 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 616 | Slog.w(TAG, "Unexpected exception", e); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 617 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 618 | } |
| 619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 621 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 622 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | public List<InputMethodInfo> getInputMethodList() { |
| 624 | synchronized (mMethodMap) { |
| 625 | return new ArrayList<InputMethodInfo>(mMethodList); |
| 626 | } |
| 627 | } |
| 628 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 629 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | public List<InputMethodInfo> getEnabledInputMethodList() { |
| 631 | synchronized (mMethodMap) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 632 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 636 | private HashMap<InputMethodInfo, List<InputMethodSubtype>> |
| 637 | getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked() { |
| 638 | HashMap<InputMethodInfo, List<InputMethodSubtype>> enabledInputMethodAndSubtypes = |
| 639 | new HashMap<InputMethodInfo, List<InputMethodSubtype>>(); |
| 640 | for (InputMethodInfo imi: getEnabledInputMethodList()) { |
| 641 | enabledInputMethodAndSubtypes.put( |
| 642 | imi, getEnabledInputMethodSubtypeListLocked(imi, true)); |
| 643 | } |
| 644 | return enabledInputMethodAndSubtypes; |
| 645 | } |
| 646 | |
| 647 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(InputMethodInfo imi, |
| 648 | boolean allowsImplicitlySelectedSubtypes) { |
| 649 | if (imi == null && mCurMethodId != null) { |
| 650 | imi = mMethodMap.get(mCurMethodId); |
| 651 | } |
satok | 7265d9b | 2011-02-14 15:47:30 +0900 | [diff] [blame] | 652 | List<InputMethodSubtype> enabledSubtypes = |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 653 | mSettings.getEnabledInputMethodSubtypeListLocked(imi); |
satok | 7265d9b | 2011-02-14 15:47:30 +0900 | [diff] [blame] | 654 | if (allowsImplicitlySelectedSubtypes && enabledSubtypes.isEmpty()) { |
| 655 | enabledSubtypes = getApplicableSubtypesLocked(mRes, getSubtypes(imi)); |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 656 | } |
satok | 7265d9b | 2011-02-14 15:47:30 +0900 | [diff] [blame] | 657 | return InputMethodSubtype.sort(mContext, 0, imi, enabledSubtypes); |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 658 | } |
| 659 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 660 | @Override |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 661 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi, |
| 662 | boolean allowsImplicitlySelectedSubtypes) { |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 663 | synchronized (mMethodMap) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 664 | return getEnabledInputMethodSubtypeListLocked(imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 668 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | public void addClient(IInputMethodClient client, |
| 670 | IInputContext inputContext, int uid, int pid) { |
| 671 | synchronized (mMethodMap) { |
| 672 | mClients.put(client.asBinder(), new ClientState(client, |
| 673 | inputContext, uid, pid)); |
| 674 | } |
| 675 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 676 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 677 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | public void removeClient(IInputMethodClient client) { |
| 679 | synchronized (mMethodMap) { |
| 680 | mClients.remove(client.asBinder()); |
| 681 | } |
| 682 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | void executeOrSendMessage(IInterface target, Message msg) { |
| 685 | if (target.asBinder() instanceof Binder) { |
| 686 | mCaller.sendMessage(msg); |
| 687 | } else { |
| 688 | handleMessage(msg); |
| 689 | msg.recycle(); |
| 690 | } |
| 691 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 692 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 693 | void unbindCurrentClientLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | if (mCurClient != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 695 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 696 | + mCurClient.client.asBinder()); |
| 697 | if (mBoundToMethod) { |
| 698 | mBoundToMethod = false; |
| 699 | if (mCurMethod != null) { |
| 700 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 701 | MSG_UNBIND_INPUT, mCurMethod)); |
| 702 | } |
| 703 | } |
| 704 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 705 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 706 | mCurClient.sessionRequested = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | // Call setActive(false) on the old client |
| 709 | try { |
| 710 | mCurClient.client.setActive(false); |
| 711 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 712 | Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 714 | } |
| 715 | mCurClient = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 716 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 717 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | } |
| 719 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | private int getImeShowFlags() { |
| 722 | int flags = 0; |
| 723 | if (mShowForced) { |
| 724 | flags |= InputMethod.SHOW_FORCED |
| 725 | | InputMethod.SHOW_EXPLICIT; |
| 726 | } else if (mShowExplicitlyRequested) { |
| 727 | flags |= InputMethod.SHOW_EXPLICIT; |
| 728 | } |
| 729 | return flags; |
| 730 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 731 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | private int getAppShowFlags() { |
| 733 | int flags = 0; |
| 734 | if (mShowForced) { |
| 735 | flags |= InputMethodManager.SHOW_FORCED; |
| 736 | } else if (!mShowExplicitlyRequested) { |
| 737 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 738 | } |
| 739 | return flags; |
| 740 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | InputBindResult attachNewInputLocked(boolean initial, boolean needResult) { |
| 743 | if (!mBoundToMethod) { |
| 744 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 745 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 746 | mBoundToMethod = true; |
| 747 | } |
| 748 | final SessionState session = mCurClient.curSession; |
| 749 | if (initial) { |
| 750 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 751 | MSG_START_INPUT, session, mCurInputContext, mCurAttribute)); |
| 752 | } else { |
| 753 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 754 | MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute)); |
| 755 | } |
| 756 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 757 | if (DEBUG) Slog.v(TAG, "Attach new input asks to show input"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 758 | showCurrentInputLocked(getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | } |
| 760 | return needResult |
| 761 | ? new InputBindResult(session.session, mCurId, mCurSeq) |
| 762 | : null; |
| 763 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | InputBindResult startInputLocked(IInputMethodClient client, |
| 766 | IInputContext inputContext, EditorInfo attribute, |
| 767 | boolean initial, boolean needResult) { |
| 768 | // If no method is currently selected, do nothing. |
| 769 | if (mCurMethodId == null) { |
| 770 | return mNoBinding; |
| 771 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | ClientState cs = mClients.get(client.asBinder()); |
| 774 | if (cs == null) { |
| 775 | throw new IllegalArgumentException("unknown client " |
| 776 | + client.asBinder()); |
| 777 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 778 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 779 | try { |
| 780 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 781 | // Check with the window manager to make sure this client actually |
| 782 | // has a window with focus. If not, reject. This is thread safe |
| 783 | // because if the focus changes some time before or after, the |
| 784 | // next client receiving focus that has any interest in input will |
| 785 | // be calling through here after that change happens. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 786 | Slog.w(TAG, "Starting input on non-focused client " + cs.client |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 788 | return null; |
| 789 | } |
| 790 | } catch (RemoteException e) { |
| 791 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | if (mCurClient != cs) { |
| 794 | // If the client is changing, we need to switch over to the new |
| 795 | // one. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 796 | unbindCurrentClientLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 797 | if (DEBUG) Slog.v(TAG, "switching to client: client = " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | + cs.client.asBinder()); |
| 799 | |
| 800 | // If the screen is on, inform the new client it is active |
| 801 | if (mScreenOn) { |
| 802 | try { |
| 803 | cs.client.setActive(mScreenOn); |
| 804 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 805 | Slog.w(TAG, "Got RemoteException sending setActive notification to pid " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | + cs.pid + " uid " + cs.uid); |
| 807 | } |
| 808 | } |
| 809 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 810 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | // Bump up the sequence for this client and attach it. |
| 812 | mCurSeq++; |
| 813 | if (mCurSeq <= 0) mCurSeq = 1; |
| 814 | mCurClient = cs; |
| 815 | mCurInputContext = inputContext; |
| 816 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | // Check if the input method is changing. |
| 819 | if (mCurId != null && mCurId.equals(mCurMethodId)) { |
| 820 | if (cs.curSession != null) { |
| 821 | // Fast case: if we are already connected to the input method, |
| 822 | // then just return it. |
| 823 | return attachNewInputLocked(initial, needResult); |
| 824 | } |
| 825 | if (mHaveConnection) { |
| 826 | if (mCurMethod != null) { |
| 827 | if (!cs.sessionRequested) { |
| 828 | cs.sessionRequested = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 829 | if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 831 | MSG_CREATE_SESSION, mCurMethod, |
| 832 | new MethodCallback(mCurMethod))); |
| 833 | } |
| 834 | // Return to client, and we will get back with it when |
| 835 | // we have had a session made for it. |
| 836 | return new InputBindResult(null, mCurId, mCurSeq); |
| 837 | } else if (SystemClock.uptimeMillis() |
| 838 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 839 | // In this case we have connected to the service, but |
| 840 | // don't yet have its interface. If it hasn't been too |
| 841 | // long since we did the connection, we'll return to |
| 842 | // the client and wait to get the service interface so |
| 843 | // we can report back. If it has been too long, we want |
| 844 | // to fall through so we can try a disconnect/reconnect |
| 845 | // to see if we can get back in touch with the service. |
| 846 | return new InputBindResult(null, mCurId, mCurSeq); |
| 847 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 848 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 849 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 853 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 854 | return startInputInnerLocked(); |
| 855 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 856 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 857 | InputBindResult startInputInnerLocked() { |
| 858 | if (mCurMethodId == null) { |
| 859 | return mNoBinding; |
| 860 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 861 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 862 | if (!mSystemReady) { |
| 863 | // If the system is not yet ready, we shouldn't be running third |
| 864 | // party code. |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 865 | return new InputBindResult(null, mCurMethodId, mCurSeq); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 866 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 869 | if (info == null) { |
| 870 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 871 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 872 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 873 | unbindCurrentMethodLocked(false); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 876 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 877 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 878 | com.android.internal.R.string.input_method_binding_label); |
| 879 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 880 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | if (mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE)) { |
| 882 | mLastBindTime = SystemClock.uptimeMillis(); |
| 883 | mHaveConnection = true; |
| 884 | mCurId = info.getId(); |
| 885 | mCurToken = new Binder(); |
| 886 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 887 | if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | mIWindowManager.addWindowToken(mCurToken, |
| 889 | WindowManager.LayoutParams.TYPE_INPUT_METHOD); |
| 890 | } catch (RemoteException e) { |
| 891 | } |
| 892 | return new InputBindResult(null, mCurId, mCurSeq); |
| 893 | } else { |
| 894 | mCurIntent = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 895 | Slog.w(TAG, "Failure connecting to input method service: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | + mCurIntent); |
| 897 | } |
| 898 | return null; |
| 899 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 900 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 901 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | public InputBindResult startInput(IInputMethodClient client, |
| 903 | IInputContext inputContext, EditorInfo attribute, |
| 904 | boolean initial, boolean needResult) { |
| 905 | synchronized (mMethodMap) { |
| 906 | final long ident = Binder.clearCallingIdentity(); |
| 907 | try { |
| 908 | return startInputLocked(client, inputContext, attribute, |
| 909 | initial, needResult); |
| 910 | } finally { |
| 911 | Binder.restoreCallingIdentity(ident); |
| 912 | } |
| 913 | } |
| 914 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 915 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 916 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | public void finishInput(IInputMethodClient client) { |
| 918 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 919 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 920 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 922 | synchronized (mMethodMap) { |
| 923 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 924 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 925 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 926 | Slog.w(TAG, "Service connected without a token!"); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 927 | unbindCurrentMethodLocked(false); |
| 928 | return; |
| 929 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 930 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 931 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 932 | MSG_ATTACH_TOKEN, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | if (mCurClient != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 934 | if (DEBUG) Slog.v(TAG, "Creating first session while with client " |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 935 | + mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 937 | MSG_CREATE_SESSION, mCurMethod, |
| 938 | new MethodCallback(mCurMethod))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | void onSessionCreated(IInputMethod method, IInputMethodSession session) { |
| 945 | synchronized (mMethodMap) { |
| 946 | if (mCurMethod != null && method != null |
| 947 | && mCurMethod.asBinder() == method.asBinder()) { |
| 948 | if (mCurClient != null) { |
| 949 | mCurClient.curSession = new SessionState(mCurClient, |
| 950 | method, session); |
| 951 | mCurClient.sessionRequested = false; |
| 952 | InputBindResult res = attachNewInputLocked(true, true); |
| 953 | if (res.method != null) { |
| 954 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
| 955 | MSG_BIND_METHOD, mCurClient.client, res)); |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 961 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 962 | void unbindCurrentMethodLocked(boolean reportToClient) { |
| 963 | if (mHaveConnection) { |
| 964 | mContext.unbindService(this); |
| 965 | mHaveConnection = false; |
| 966 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 967 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 968 | if (mCurToken != null) { |
| 969 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 970 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 971 | mIWindowManager.removeWindowToken(mCurToken); |
| 972 | } catch (RemoteException e) { |
| 973 | } |
| 974 | mCurToken = null; |
| 975 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 976 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 977 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 978 | clearCurMethodLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 979 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 980 | if (reportToClient && mCurClient != null) { |
| 981 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 982 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 983 | } |
| 984 | } |
| 985 | |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 986 | private void finishSession(SessionState sessionState) { |
| 987 | if (sessionState != null && sessionState.session != null) { |
| 988 | try { |
| 989 | sessionState.session.finishSession(); |
| 990 | } catch (RemoteException e) { |
Jean-Baptiste Queru | 9d0f6df | 2010-03-29 12:55:09 -0700 | [diff] [blame] | 991 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 995 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 996 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | if (mCurMethod != null) { |
| 998 | for (ClientState cs : mClients.values()) { |
| 999 | cs.sessionRequested = false; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1000 | finishSession(cs.curSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | cs.curSession = null; |
| 1002 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1003 | |
| 1004 | finishSession(mEnabledSession); |
| 1005 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | mCurMethod = null; |
| 1007 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 1008 | mStatusBar.setIconVisibility("ime", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1010 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1011 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | public void onServiceDisconnected(ComponentName name) { |
| 1013 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1014 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | + " mCurIntent=" + mCurIntent); |
| 1016 | if (mCurMethod != null && mCurIntent != null |
| 1017 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1018 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | // We consider this to be a new bind attempt, since the system |
| 1020 | // should now try to restart the service for us. |
| 1021 | mLastBindTime = SystemClock.uptimeMillis(); |
| 1022 | mShowRequested = mInputShown; |
| 1023 | mInputShown = false; |
| 1024 | if (mCurClient != null) { |
| 1025 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 1026 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1032 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | public void updateStatusIcon(IBinder token, String packageName, int iconId) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1034 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | long ident = Binder.clearCallingIdentity(); |
| 1036 | try { |
| 1037 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1038 | Slog.w(TAG, "Ignoring setInputMethod of uid " + uid + " token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | return; |
| 1040 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | synchronized (mMethodMap) { |
| 1043 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1044 | if (DEBUG) Slog.d(TAG, "hide the small icon for the input method"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 1045 | mStatusBar.setIconVisibility("ime", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1047 | if (DEBUG) Slog.d(TAG, "show a small icon for the input method"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 1048 | mStatusBar.setIcon("ime", packageName, iconId, 0); |
| 1049 | mStatusBar.setIconVisibility("ime", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | } finally { |
| 1053 | Binder.restoreCallingIdentity(ident); |
| 1054 | } |
| 1055 | } |
| 1056 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1057 | private boolean needsToShowImeSwitchOngoingNotification() { |
| 1058 | if (!mShowOngoingImeSwitcherForPhones) return false; |
| 1059 | synchronized (mMethodMap) { |
| 1060 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 1061 | final int N = imis.size(); |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1062 | if (N > 2) return true; |
| 1063 | if (N < 1) return false; |
| 1064 | int nonAuxCount = 0; |
| 1065 | int auxCount = 0; |
| 1066 | InputMethodSubtype nonAuxSubtype = null; |
| 1067 | InputMethodSubtype auxSubtype = null; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1068 | for(int i = 0; i < N; ++i) { |
| 1069 | final InputMethodInfo imi = imis.get(i); |
| 1070 | final List<InputMethodSubtype> subtypes = getEnabledInputMethodSubtypeListLocked( |
| 1071 | imi, true); |
| 1072 | final int subtypeCount = subtypes.size(); |
| 1073 | if (subtypeCount == 0) { |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1074 | ++nonAuxCount; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1075 | } else { |
| 1076 | for (int j = 0; j < subtypeCount; ++j) { |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1077 | final InputMethodSubtype subtype = subtypes.get(j); |
| 1078 | if (!subtype.isAuxiliary()) { |
| 1079 | ++nonAuxCount; |
| 1080 | nonAuxSubtype = subtype; |
| 1081 | } else { |
| 1082 | ++auxCount; |
| 1083 | auxSubtype = subtype; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | } |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1087 | } |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1088 | if (nonAuxCount > 1 || auxCount > 1) { |
| 1089 | return true; |
| 1090 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 1091 | if (nonAuxSubtype != null && auxSubtype != null |
| 1092 | && nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 1093 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 1094 | return false; |
| 1095 | } |
| 1096 | return true; |
| 1097 | } |
| 1098 | return false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1099 | } |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1100 | } |
| 1101 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1102 | @Override |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1103 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1104 | int uid = Binder.getCallingUid(); |
| 1105 | long ident = Binder.clearCallingIdentity(); |
| 1106 | try { |
| 1107 | if (token == null || mCurToken != token) { |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1108 | Slog.w(TAG, "Ignoring setImeWindowStatus of uid " + uid + " token: " + token); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1109 | return; |
| 1110 | } |
| 1111 | |
| 1112 | synchronized (mMethodMap) { |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1113 | mImeWindowVis = vis; |
| 1114 | mBackDisposition = backDisposition; |
| 1115 | mStatusBar.setImeWindowStatus(token, vis, backDisposition); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1116 | final boolean iconVisibility = (vis & InputMethodService.IME_ACTIVE) != 0; |
| 1117 | if (iconVisibility && needsToShowImeSwitchOngoingNotification()) { |
| 1118 | final PackageManager pm = mContext.getPackageManager(); |
| 1119 | final CharSequence label = mMethodMap.get(mCurMethodId).loadLabel(pm); |
| 1120 | final CharSequence title = mRes.getText( |
| 1121 | com.android.internal.R.string.select_input_method); |
| 1122 | mImeSwitcherNotification.setLatestEventInfo( |
| 1123 | mContext, title, label, mImeSwitchPendingIntent); |
| 1124 | mNotificationManager.notify( |
| 1125 | com.android.internal.R.string.select_input_method, |
| 1126 | mImeSwitcherNotification); |
| 1127 | mNotificationShown = true; |
| 1128 | } else { |
| 1129 | if (mNotificationShown) { |
| 1130 | mNotificationManager.cancel( |
| 1131 | com.android.internal.R.string.select_input_method); |
| 1132 | mNotificationShown = false; |
| 1133 | } |
| 1134 | } |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1135 | } |
| 1136 | } finally { |
| 1137 | Binder.restoreCallingIdentity(ident); |
| 1138 | } |
| 1139 | } |
| 1140 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1141 | @Override |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1142 | public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) { |
| 1143 | synchronized (mMethodMap) { |
| 1144 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
| 1145 | for (int i = 0; i < spans.length; ++i) { |
| 1146 | SuggestionSpan ss = spans[i]; |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1147 | if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) { |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1148 | mSecureSuggestionSpans.put(ss, currentImi); |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1149 | final InputMethodInfo targetImi = mSecureSuggestionSpans.get(ss); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | } |
| 1154 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1155 | @Override |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1156 | public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) { |
| 1157 | synchronized (mMethodMap) { |
| 1158 | final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span); |
| 1159 | // TODO: Do not send the intent if the process of the targetImi is already dead. |
| 1160 | if (targetImi != null) { |
| 1161 | final String[] suggestions = span.getSuggestions(); |
| 1162 | if (index < 0 || index >= suggestions.length) return false; |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1163 | final String className = span.getNotificationTargetClassName(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1164 | final Intent intent = new Intent(); |
| 1165 | // Ensures that only a class in the original IME package will receive the |
| 1166 | // notification. |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1167 | intent.setClassName(targetImi.getPackageName(), className); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1168 | intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED); |
| 1169 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString); |
| 1170 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]); |
| 1171 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode()); |
| 1172 | mContext.sendBroadcast(intent); |
| 1173 | return true; |
| 1174 | } |
| 1175 | } |
| 1176 | return false; |
| 1177 | } |
| 1178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | void updateFromSettingsLocked() { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1180 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 1181 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 1182 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 1183 | // enabled. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | String id = Settings.Secure.getString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1185 | Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 1186 | // There is no input method selected, try to choose new applicable input method. |
| 1187 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
| 1188 | id = Settings.Secure.getString(mContext.getContentResolver(), |
| 1189 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 1190 | } |
| 1191 | if (!TextUtils.isEmpty(id)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1193 | setInputMethodLocked(id, getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1195 | Slog.w(TAG, "Unknown input method from prefs: " + id, e); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1196 | mCurMethodId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1197 | unbindCurrentMethodLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 1199 | mShortcutInputMethodsAndSubtypes.clear(); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1200 | } else { |
| 1201 | // There is no longer an input method set, so stop any current one. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1202 | mCurMethodId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1203 | unbindCurrentMethodLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1204 | } |
| 1205 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1206 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1207 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | InputMethodInfo info = mMethodMap.get(id); |
| 1209 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1210 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | if (id.equals(mCurMethodId)) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1214 | InputMethodSubtype subtype = null; |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 1215 | if (subtypeId >= 0 && subtypeId < info.getSubtypeCount()) { |
| 1216 | subtype = info.getSubtypeAt(subtypeId); |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1217 | } |
| 1218 | if (subtype != mCurrentSubtype) { |
| 1219 | synchronized (mMethodMap) { |
satok | ca83021 | 2011-01-13 21:15:04 +0900 | [diff] [blame] | 1220 | if (subtype != null) { |
| 1221 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 1222 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1223 | if (mCurMethod != null) { |
| 1224 | try { |
satok | e40dea0 | 2011-01-30 01:14:02 +0900 | [diff] [blame] | 1225 | final Configuration conf = mRes.getConfiguration(); |
| 1226 | final boolean haveHardKeyboard = conf.keyboard |
| 1227 | != Configuration.KEYBOARD_NOKEYS; |
| 1228 | final boolean hardKeyShown = haveHardKeyboard |
Ken Wakasa | 8710e76 | 2011-01-30 11:02:09 +0900 | [diff] [blame] | 1229 | && conf.hardKeyboardHidden |
| 1230 | != Configuration.HARDKEYBOARDHIDDEN_YES; |
satok | e40dea0 | 2011-01-30 01:14:02 +0900 | [diff] [blame] | 1231 | mImeWindowVis = (mInputShown || hardKeyShown) ? ( |
| 1232 | InputMethodService.IME_ACTIVE | InputMethodService.IME_VISIBLE) |
| 1233 | : 0; |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1234 | mStatusBar.setImeWindowStatus(mCurToken, mImeWindowVis, |
| 1235 | mBackDisposition); |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1236 | // If subtype is null, try to find the most applicable one from |
| 1237 | // getCurrentInputMethodSubtype. |
| 1238 | if (subtype == null) { |
| 1239 | subtype = getCurrentInputMethodSubtype(); |
| 1240 | } |
| 1241 | mCurMethod.changeInputMethodSubtype(subtype); |
| 1242 | } catch (RemoteException e) { |
| 1243 | return; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | return; |
| 1249 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | final long ident = Binder.clearCallingIdentity(); |
| 1252 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1253 | // Set a subtype to this input method. |
| 1254 | // subtypeId the name of a subtype which will be set. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1255 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 1256 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 1257 | // because mCurMethodId is stored as a history in |
| 1258 | // setSelectedInputMethodAndSubtypeLocked(). |
| 1259 | mCurMethodId = id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1260 | |
| 1261 | if (ActivityManagerNative.isSystemReady()) { |
| 1262 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 1263 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | intent.putExtra("input_method_id", id); |
| 1265 | mContext.sendBroadcast(intent); |
| 1266 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1267 | unbindCurrentClientLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | } finally { |
| 1269 | Binder.restoreCallingIdentity(ident); |
| 1270 | } |
| 1271 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1272 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1273 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1274 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 1275 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1276 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | long ident = Binder.clearCallingIdentity(); |
| 1278 | try { |
| 1279 | synchronized (mMethodMap) { |
| 1280 | if (mCurClient == null || client == null |
| 1281 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1282 | try { |
| 1283 | // We need to check if this is the current client with |
| 1284 | // focus in the window manager, to allow this call to |
| 1285 | // be made before input is started in it. |
| 1286 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1287 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1288 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1289 | } |
| 1290 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1291 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | } |
| 1293 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1294 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1295 | if (DEBUG) Slog.v(TAG, "Client requesting input be shown"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1296 | return showCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | } |
| 1298 | } finally { |
| 1299 | Binder.restoreCallingIdentity(ident); |
| 1300 | } |
| 1301 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1302 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1303 | boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | mShowRequested = true; |
| 1305 | if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 1306 | mShowExplicitlyRequested = true; |
| 1307 | } |
| 1308 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 1309 | mShowExplicitlyRequested = true; |
| 1310 | mShowForced = true; |
| 1311 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1312 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1313 | if (!mSystemReady) { |
| 1314 | return false; |
| 1315 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1316 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1317 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | if (mCurMethod != null) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1319 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 1320 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 1321 | resultReceiver)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | mInputShown = true; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1323 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
| 1325 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 1326 | // The client has asked to have the input method shown, but |
| 1327 | // we have been sitting here too long with a connection to the |
| 1328 | // service and no interface received, so let's disconnect/connect |
| 1329 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1330 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | SystemClock.uptimeMillis()-mLastBindTime,1); |
| 1332 | mContext.unbindService(this); |
| 1333 | mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE); |
| 1334 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1335 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1336 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1337 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1338 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1339 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1340 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 1341 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1342 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | long ident = Binder.clearCallingIdentity(); |
| 1344 | try { |
| 1345 | synchronized (mMethodMap) { |
| 1346 | if (mCurClient == null || client == null |
| 1347 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1348 | try { |
| 1349 | // We need to check if this is the current client with |
| 1350 | // focus in the window manager, to allow this call to |
| 1351 | // be made before input is started in it. |
| 1352 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1353 | if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid " |
| 1354 | + uid + ": " + client); |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1355 | mImeWindowVis = 0; |
| 1356 | mStatusBar.setImeWindowStatus(mCurToken, mImeWindowVis, |
| 1357 | mBackDisposition); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1358 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1359 | } |
| 1360 | } catch (RemoteException e) { |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1361 | mImeWindowVis = 0; |
| 1362 | mStatusBar.setImeWindowStatus(mCurToken, mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1363 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1364 | } |
| 1365 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1366 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1367 | if (DEBUG) Slog.v(TAG, "Client requesting input be hidden"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1368 | return hideCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | } |
| 1370 | } finally { |
| 1371 | Binder.restoreCallingIdentity(ident); |
| 1372 | } |
| 1373 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1374 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1375 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 1377 | && (mShowExplicitlyRequested || mShowForced)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1378 | if (DEBUG) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | "Not hiding: explicit show not cancelled by non-explicit hide"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1380 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1381 | } |
| 1382 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1383 | if (DEBUG) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | "Not hiding: forced show not cancelled by not-always hide"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1385 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1387 | boolean res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | if (mInputShown && mCurMethod != null) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1389 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1390 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 1391 | res = true; |
| 1392 | } else { |
| 1393 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | } |
| 1395 | mInputShown = false; |
| 1396 | mShowRequested = false; |
| 1397 | mShowExplicitlyRequested = false; |
| 1398 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1399 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1401 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1402 | @Override |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1403 | public void windowGainedFocus(IInputMethodClient client, IBinder windowToken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | boolean viewHasFocus, boolean isTextEditor, int softInputMode, |
| 1405 | boolean first, int windowFlags) { |
| 1406 | long ident = Binder.clearCallingIdentity(); |
| 1407 | try { |
| 1408 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1409 | if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | + " viewHasFocus=" + viewHasFocus |
| 1411 | + " isTextEditor=" + isTextEditor |
| 1412 | + " softInputMode=#" + Integer.toHexString(softInputMode) |
| 1413 | + " first=" + first + " flags=#" |
| 1414 | + Integer.toHexString(windowFlags)); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1416 | if (mCurClient == null || client == null |
| 1417 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1418 | try { |
| 1419 | // We need to check if this is the current client with |
| 1420 | // focus in the window manager, to allow this call to |
| 1421 | // be made before input is started in it. |
| 1422 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1423 | Slog.w(TAG, "Client not active, ignoring focus gain of: " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | return; |
| 1425 | } |
| 1426 | } catch (RemoteException e) { |
| 1427 | } |
| 1428 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1429 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1430 | if (mCurFocusedWindow == windowToken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1431 | Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1432 | return; |
| 1433 | } |
| 1434 | mCurFocusedWindow = windowToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1435 | |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1436 | // Should we auto-show the IME even if the caller has not |
| 1437 | // specified what should be done with it? |
| 1438 | // We only do this automatically if the window can resize |
| 1439 | // to accommodate the IME (so what the user sees will give |
| 1440 | // them good context without input information being obscured |
| 1441 | // by the IME) or if running on a large screen where there |
| 1442 | // is more room for the target window + IME. |
| 1443 | final boolean doAutoShow = |
| 1444 | (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 1445 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
| 1446 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 1447 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
| 1448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 1450 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1451 | if (!isTextEditor || !doAutoShow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) { |
| 1453 | // There is no focus view, and this window will |
| 1454 | // be behind any soft input window, so hide the |
| 1455 | // soft input window if it is shown. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1456 | if (DEBUG) Slog.v(TAG, "Unspecified window will hide input"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1457 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | } |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1459 | } else if (isTextEditor && doAutoShow && (softInputMode & |
| 1460 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | // There is a focus view, and we are navigating forward |
| 1462 | // into the window, so show the input window for the user. |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1463 | // We only do this automatically if the window an resize |
| 1464 | // to accomodate the IME (so what the user sees will give |
| 1465 | // them good context without input information being obscured |
| 1466 | // by the IME) or if running on a large screen where there |
| 1467 | // is more room for the target window + IME. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1468 | if (DEBUG) Slog.v(TAG, "Unspecified window will show input"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1469 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | } |
| 1471 | break; |
| 1472 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
| 1473 | // Do nothing. |
| 1474 | break; |
| 1475 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 1476 | if ((softInputMode & |
| 1477 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1478 | if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1479 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | } |
| 1481 | break; |
| 1482 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1483 | if (DEBUG) Slog.v(TAG, "Window asks to hide input"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1484 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | break; |
| 1486 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 1487 | if ((softInputMode & |
| 1488 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1489 | if (DEBUG) Slog.v(TAG, "Window asks to show input going forward"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1490 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | } |
| 1492 | break; |
| 1493 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1494 | if (DEBUG) Slog.v(TAG, "Window asks to always show input"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1495 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | break; |
| 1497 | } |
| 1498 | } |
| 1499 | } finally { |
| 1500 | Binder.restoreCallingIdentity(ident); |
| 1501 | } |
| 1502 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1503 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1504 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | public void showInputMethodPickerFromClient(IInputMethodClient client) { |
| 1506 | synchronized (mMethodMap) { |
| 1507 | if (mCurClient == null || client == null |
| 1508 | || mCurClient.client.asBinder() != client.asBinder()) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1509 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1510 | + Binder.getCallingUid() + ": " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | } |
| 1512 | |
satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 1513 | // Always call subtype picker, because subtype picker is a superset of input method |
| 1514 | // picker. |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1515 | mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER); |
| 1516 | } |
| 1517 | } |
| 1518 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1519 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | public void setInputMethod(IBinder token, String id) { |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1521 | setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID); |
| 1522 | } |
| 1523 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1524 | @Override |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1525 | public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) { |
| 1526 | synchronized (mMethodMap) { |
| 1527 | if (subtype != null) { |
| 1528 | setInputMethodWithSubtypeId(token, id, getSubtypeIdFromHashCode( |
| 1529 | mMethodMap.get(id), subtype.hashCode())); |
| 1530 | } else { |
| 1531 | setInputMethod(token, id); |
| 1532 | } |
| 1533 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1534 | } |
| 1535 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1536 | @Override |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1537 | public void showInputMethodAndSubtypeEnablerFromClient( |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1538 | IInputMethodClient client, String inputMethodId) { |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1539 | synchronized (mMethodMap) { |
| 1540 | if (mCurClient == null || client == null |
| 1541 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1542 | Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client); |
| 1543 | } |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1544 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1545 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1546 | } |
| 1547 | } |
| 1548 | |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 1549 | @Override |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 1550 | public boolean switchToLastInputMethod(IBinder token) { |
| 1551 | synchronized (mMethodMap) { |
satok | c445bcd | 2011-01-25 18:57:24 +0900 | [diff] [blame] | 1552 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 1553 | final InputMethodInfo lastImi; |
satok | 208d563 | 2011-05-20 22:13:38 +0900 | [diff] [blame] | 1554 | if (lastIme != null) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 1555 | lastImi = mMethodMap.get(lastIme.first); |
| 1556 | } else { |
| 1557 | lastImi = null; |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 1558 | } |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 1559 | String targetLastImiId = null; |
| 1560 | int subtypeId = NOT_A_SUBTYPE_ID; |
| 1561 | if (lastIme != null && lastImi != null) { |
| 1562 | final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId); |
| 1563 | final int lastSubtypeHash = Integer.valueOf(lastIme.second); |
| 1564 | final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID |
| 1565 | : mCurrentSubtype.hashCode(); |
| 1566 | // If the last IME is the same as the current IME and the last subtype is not |
| 1567 | // defined, there is no need to switch to the last IME. |
| 1568 | if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) { |
| 1569 | targetLastImiId = lastIme.first; |
| 1570 | subtypeId = getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | if (TextUtils.isEmpty(targetLastImiId) && !canAddToLastInputMethod(mCurrentSubtype)) { |
| 1575 | // This is a safety net. If the currentSubtype can't be added to the history |
| 1576 | // and the framework couldn't find the last ime, we will make the last ime be |
| 1577 | // the most applicable enabled keyboard subtype of the system imes. |
| 1578 | final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 1579 | if (enabled != null) { |
| 1580 | final int N = enabled.size(); |
| 1581 | final String locale = mCurrentSubtype == null |
| 1582 | ? mRes.getConfiguration().locale.toString() |
| 1583 | : mCurrentSubtype.getLocale(); |
| 1584 | for (int i = 0; i < N; ++i) { |
| 1585 | final InputMethodInfo imi = enabled.get(i); |
| 1586 | if (imi.getSubtypeCount() > 0 && isSystemIme(imi)) { |
| 1587 | InputMethodSubtype keyboardSubtype = |
| 1588 | findLastResortApplicableSubtypeLocked(mRes, getSubtypes(imi), |
| 1589 | SUBTYPE_MODE_KEYBOARD, locale, true); |
| 1590 | if (keyboardSubtype != null) { |
| 1591 | targetLastImiId = imi.getId(); |
| 1592 | subtypeId = getSubtypeIdFromHashCode( |
| 1593 | imi, keyboardSubtype.hashCode()); |
| 1594 | if(keyboardSubtype.getLocale().equals(locale)) { |
| 1595 | break; |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | if (!TextUtils.isEmpty(targetLastImiId)) { |
| 1604 | if (DEBUG) { |
| 1605 | Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second |
| 1606 | + ", from: " + mCurMethodId + ", " + subtypeId); |
| 1607 | } |
| 1608 | setInputMethodWithSubtypeId(token, targetLastImiId, subtypeId); |
| 1609 | return true; |
| 1610 | } else { |
| 1611 | return false; |
| 1612 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1616 | @Override |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 1617 | public InputMethodSubtype getLastInputMethodSubtype() { |
| 1618 | synchronized (mMethodMap) { |
| 1619 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 1620 | // TODO: Handle the case of the last IME with no subtypes |
| 1621 | if (lastIme == null || TextUtils.isEmpty(lastIme.first) |
| 1622 | || TextUtils.isEmpty(lastIme.second)) return null; |
| 1623 | final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); |
| 1624 | if (lastImi == null) return null; |
| 1625 | try { |
| 1626 | final int lastSubtypeHash = Integer.valueOf(lastIme.second); |
satok | 0e7d7d6 | 2011-07-05 13:28:06 +0900 | [diff] [blame] | 1627 | final int lastSubtypeId = getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
| 1628 | if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { |
| 1629 | return null; |
| 1630 | } |
| 1631 | return lastImi.getSubtypeAt(lastSubtypeId); |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 1632 | } catch (NumberFormatException e) { |
| 1633 | return null; |
| 1634 | } |
| 1635 | } |
| 1636 | } |
| 1637 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1638 | @Override |
| 1639 | public boolean setAdditionalInputMethodSubtypes(IBinder token, InputMethodSubtype[] subtypes) { |
| 1640 | if (token == null || mCurToken != token) { |
| 1641 | return false; |
| 1642 | } |
| 1643 | if (subtypes == null || subtypes.length == 0) return false; |
| 1644 | synchronized (mMethodMap) { |
| 1645 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 1646 | if (imi == null) return false; |
| 1647 | final int N = subtypes.length; |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 1648 | mFileManager.addInputMethodSubtypes(imi, subtypes); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1649 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| 1650 | return true; |
| 1651 | } |
| 1652 | } |
| 1653 | |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1654 | private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | synchronized (mMethodMap) { |
| 1656 | if (token == null) { |
| 1657 | if (mContext.checkCallingOrSelfPermission( |
| 1658 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1659 | != PackageManager.PERMISSION_GRANTED) { |
| 1660 | throw new SecurityException( |
| 1661 | "Using null token requires permission " |
| 1662 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1663 | } |
| 1664 | } else if (mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1665 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 1666 | + " token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | return; |
| 1668 | } |
| 1669 | |
| 1670 | long ident = Binder.clearCallingIdentity(); |
| 1671 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1672 | setInputMethodLocked(id, subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | } finally { |
| 1674 | Binder.restoreCallingIdentity(ident); |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1679 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1680 | public void hideMySoftInput(IBinder token, int flags) { |
| 1681 | synchronized (mMethodMap) { |
| 1682 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1683 | if (DEBUG) Slog.w(TAG, "Ignoring hideInputMethod of uid " |
| 1684 | + Binder.getCallingUid() + " token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1685 | return; |
| 1686 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | long ident = Binder.clearCallingIdentity(); |
| 1688 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1689 | hideCurrentInputLocked(flags, null); |
| 1690 | } finally { |
| 1691 | Binder.restoreCallingIdentity(ident); |
| 1692 | } |
| 1693 | } |
| 1694 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1695 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1696 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1697 | public void showMySoftInput(IBinder token, int flags) { |
| 1698 | synchronized (mMethodMap) { |
| 1699 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1700 | Slog.w(TAG, "Ignoring showMySoftInput of uid " |
| 1701 | + Binder.getCallingUid() + " token: " + token); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1702 | return; |
| 1703 | } |
| 1704 | long ident = Binder.clearCallingIdentity(); |
| 1705 | try { |
| 1706 | showCurrentInputLocked(flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1707 | } finally { |
| 1708 | Binder.restoreCallingIdentity(ident); |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | void setEnabledSessionInMainThread(SessionState session) { |
| 1714 | if (mEnabledSession != session) { |
| 1715 | if (mEnabledSession != null) { |
| 1716 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1717 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | mEnabledSession.method.setSessionEnabled( |
| 1719 | mEnabledSession.session, false); |
| 1720 | } catch (RemoteException e) { |
| 1721 | } |
| 1722 | } |
| 1723 | mEnabledSession = session; |
| 1724 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1725 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1726 | session.method.setSessionEnabled( |
| 1727 | session.session, true); |
| 1728 | } catch (RemoteException e) { |
| 1729 | } |
| 1730 | } |
| 1731 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1732 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1733 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1734 | public boolean handleMessage(Message msg) { |
| 1735 | HandlerCaller.SomeArgs args; |
| 1736 | switch (msg.what) { |
| 1737 | case MSG_SHOW_IM_PICKER: |
| 1738 | showInputMethodMenu(); |
| 1739 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1740 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1741 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
| 1742 | showInputMethodSubtypeMenu(); |
| 1743 | return true; |
| 1744 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1745 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1746 | args = (HandlerCaller.SomeArgs)msg.obj; |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1747 | showInputMethodAndSubtypeEnabler((String)args.arg1); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1748 | return true; |
| 1749 | |
| 1750 | case MSG_SHOW_IM_CONFIG: |
| 1751 | showConfigureInputMethods(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1752 | return true; |
| 1753 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1754 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1756 | case MSG_UNBIND_INPUT: |
| 1757 | try { |
| 1758 | ((IInputMethod)msg.obj).unbindInput(); |
| 1759 | } catch (RemoteException e) { |
| 1760 | // There is nothing interesting about the method dying. |
| 1761 | } |
| 1762 | return true; |
| 1763 | case MSG_BIND_INPUT: |
| 1764 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1765 | try { |
| 1766 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 1767 | } catch (RemoteException e) { |
| 1768 | } |
| 1769 | return true; |
| 1770 | case MSG_SHOW_SOFT_INPUT: |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1771 | args = (HandlerCaller.SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1772 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1773 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, |
| 1774 | (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1775 | } catch (RemoteException e) { |
| 1776 | } |
| 1777 | return true; |
| 1778 | case MSG_HIDE_SOFT_INPUT: |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1779 | args = (HandlerCaller.SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1780 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1781 | ((IInputMethod)args.arg1).hideSoftInput(0, |
| 1782 | (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1783 | } catch (RemoteException e) { |
| 1784 | } |
| 1785 | return true; |
| 1786 | case MSG_ATTACH_TOKEN: |
| 1787 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1788 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1789 | if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2); |
| 1791 | } catch (RemoteException e) { |
| 1792 | } |
| 1793 | return true; |
| 1794 | case MSG_CREATE_SESSION: |
| 1795 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1796 | try { |
| 1797 | ((IInputMethod)args.arg1).createSession( |
| 1798 | (IInputMethodCallback)args.arg2); |
| 1799 | } catch (RemoteException e) { |
| 1800 | } |
| 1801 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1802 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1803 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1804 | case MSG_START_INPUT: |
| 1805 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1806 | try { |
| 1807 | SessionState session = (SessionState)args.arg1; |
| 1808 | setEnabledSessionInMainThread(session); |
| 1809 | session.method.startInput((IInputContext)args.arg2, |
| 1810 | (EditorInfo)args.arg3); |
| 1811 | } catch (RemoteException e) { |
| 1812 | } |
| 1813 | return true; |
| 1814 | case MSG_RESTART_INPUT: |
| 1815 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1816 | try { |
| 1817 | SessionState session = (SessionState)args.arg1; |
| 1818 | setEnabledSessionInMainThread(session); |
| 1819 | session.method.restartInput((IInputContext)args.arg2, |
| 1820 | (EditorInfo)args.arg3); |
| 1821 | } catch (RemoteException e) { |
| 1822 | } |
| 1823 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1825 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | case MSG_UNBIND_METHOD: |
| 1828 | try { |
| 1829 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1); |
| 1830 | } catch (RemoteException e) { |
| 1831 | // There is nothing interesting about the last client dying. |
| 1832 | } |
| 1833 | return true; |
| 1834 | case MSG_BIND_METHOD: |
| 1835 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1836 | try { |
| 1837 | ((IInputMethodClient)args.arg1).onBindMethod( |
| 1838 | (InputBindResult)args.arg2); |
| 1839 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1840 | Slog.w(TAG, "Client died receiving input method " + args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | } |
| 1842 | return true; |
| 1843 | } |
| 1844 | return false; |
| 1845 | } |
| 1846 | |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1847 | private boolean isSystemIme(InputMethodInfo inputMethod) { |
| 1848 | return (inputMethod.getServiceInfo().applicationInfo.flags |
| 1849 | & ApplicationInfo.FLAG_SYSTEM) != 0; |
| 1850 | } |
| 1851 | |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 1852 | private static ArrayList<InputMethodSubtype> getSubtypes(InputMethodInfo imi) { |
| 1853 | ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); |
| 1854 | final int subtypeCount = imi.getSubtypeCount(); |
| 1855 | for (int i = 0; i < subtypeCount; ++i) { |
| 1856 | subtypes.add(imi.getSubtypeAt(i)); |
| 1857 | } |
| 1858 | return subtypes; |
| 1859 | } |
| 1860 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1861 | private boolean chooseNewDefaultIMELocked() { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1862 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1863 | if (enabled != null && enabled.size() > 0) { |
Dianne Hackborn | 83e48f5 | 2010-03-23 23:03:25 -0700 | [diff] [blame] | 1864 | // We'd prefer to fall back on a system IME, since that is safer. |
| 1865 | int i=enabled.size(); |
| 1866 | while (i > 0) { |
| 1867 | i--; |
| 1868 | if ((enabled.get(i).getServiceInfo().applicationInfo.flags |
| 1869 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 1870 | break; |
| 1871 | } |
| 1872 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1873 | InputMethodInfo imi = enabled.get(i); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 1874 | if (DEBUG) { |
| 1875 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 1876 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1877 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1878 | return true; |
| 1879 | } |
| 1880 | |
| 1881 | return false; |
| 1882 | } |
| 1883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, |
| 1885 | HashMap<String, InputMethodInfo> map) { |
| 1886 | list.clear(); |
| 1887 | map.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1889 | PackageManager pm = mContext.getPackageManager(); |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1890 | final Configuration config = mRes.getConfiguration(); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1891 | final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY; |
| 1892 | String disabledSysImes = Settings.Secure.getString(mContext.getContentResolver(), |
| 1893 | Secure.DISABLED_SYSTEM_INPUT_METHODS); |
| 1894 | if (disabledSysImes == null) disabledSysImes = ""; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1895 | |
| 1896 | List<ResolveInfo> services = pm.queryIntentServices( |
| 1897 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 1898 | PackageManager.GET_META_DATA); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1899 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1900 | final HashMap<String, List<InputMethodSubtype>> additionalSubtypes = |
| 1901 | mFileManager.getAllAdditionalInputMethodSubtypes(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1902 | for (int i = 0; i < services.size(); ++i) { |
| 1903 | ResolveInfo ri = services.get(i); |
| 1904 | ServiceInfo si = ri.serviceInfo; |
| 1905 | ComponentName compName = new ComponentName(si.packageName, si.name); |
| 1906 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals( |
| 1907 | si.permission)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1908 | Slog.w(TAG, "Skipping input method " + compName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | + ": it does not require the permission " |
| 1910 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 1911 | continue; |
| 1912 | } |
| 1913 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1914 | if (DEBUG) Slog.d(TAG, "Checking " + compName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1915 | |
| 1916 | try { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1917 | InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | list.add(p); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1919 | final String id = p.getId(); |
| 1920 | map.put(id, p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1922 | // System IMEs are enabled by default, unless there's a hard keyboard |
| 1923 | // and the system IME was explicitly disabled |
| 1924 | if (isSystemIme(p) && (!haveHardKeyboard || disabledSysImes.indexOf(id) < 0)) { |
| 1925 | setInputMethodEnabledLocked(id, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1928 | if (DEBUG) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1929 | Slog.d(TAG, "Found a third-party input method " + p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | } catch (XmlPullParserException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1933 | Slog.w(TAG, "Unable to load input method " + compName, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1934 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1935 | Slog.w(TAG, "Unable to load input method " + compName, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | } |
| 1937 | } |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1938 | |
| 1939 | String defaultIme = Settings.Secure.getString(mContext |
| 1940 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1941 | if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1942 | if (chooseNewDefaultIMELocked()) { |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1943 | updateFromSettingsLocked(); |
| 1944 | } |
| 1945 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1946 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1949 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1950 | private void showInputMethodMenu() { |
| 1951 | showInputMethodMenuInternal(false); |
| 1952 | } |
| 1953 | |
| 1954 | private void showInputMethodSubtypeMenu() { |
| 1955 | showInputMethodMenuInternal(true); |
| 1956 | } |
| 1957 | |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1958 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
Tadashi G. Takaoka | f49688f | 2011-01-20 17:56:13 +0900 | [diff] [blame] | 1959 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1960 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 1961 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 1962 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1963 | if (!TextUtils.isEmpty(inputMethodId)) { |
Tadashi G. Takaoka | 2548020 | 2011-01-20 23:13:02 +0900 | [diff] [blame] | 1964 | intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1965 | } |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1966 | mContext.startActivity(intent); |
| 1967 | } |
| 1968 | |
| 1969 | private void showConfigureInputMethods() { |
| 1970 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 1971 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1972 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 1973 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1974 | mContext.startActivity(intent); |
| 1975 | } |
| 1976 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1977 | private void showInputMethodMenuInternal(boolean showSubtypes) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1978 | if (DEBUG) Slog.v(TAG, "Show switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | final Context context = mContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | final PackageManager pm = context.getPackageManager(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1983 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | String lastInputMethodId = Settings.Secure.getString(context |
| 1985 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1986 | int lastInputMethodSubtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1987 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1988 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1989 | synchronized (mMethodMap) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 1990 | final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = |
| 1991 | getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1992 | if (immis == null || immis.size() == 0) { |
| 1993 | return; |
| 1994 | } |
| 1995 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1996 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 1998 | final TreeMap<InputMethodInfo, List<InputMethodSubtype>> sortedImmis = |
| 1999 | new TreeMap<InputMethodInfo, List<InputMethodSubtype>>( |
| 2000 | new Comparator<InputMethodInfo>() { |
| 2001 | @Override |
| 2002 | public int compare(InputMethodInfo imi1, InputMethodInfo imi2) { |
| 2003 | if (imi2 == null) return 0; |
| 2004 | if (imi1 == null) return 1; |
| 2005 | if (pm == null) { |
| 2006 | return imi1.getId().compareTo(imi2.getId()); |
| 2007 | } |
| 2008 | CharSequence imiId1 = imi1.loadLabel(pm) + "/" + imi1.getId(); |
| 2009 | CharSequence imiId2 = imi2.loadLabel(pm) + "/" + imi2.getId(); |
| 2010 | return imiId1.toString().compareTo(imiId2.toString()); |
| 2011 | } |
| 2012 | }); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2013 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2014 | sortedImmis.putAll(immis); |
| 2015 | |
| 2016 | final ArrayList<Pair<CharSequence, Pair<InputMethodInfo, Integer>>> imList = |
| 2017 | new ArrayList<Pair<CharSequence, Pair<InputMethodInfo, Integer>>>(); |
| 2018 | |
| 2019 | for (InputMethodInfo imi : sortedImmis.keySet()) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2020 | if (imi == null) continue; |
| 2021 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypeList = immis.get(imi); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2022 | HashSet<String> enabledSubtypeSet = new HashSet<String>(); |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2023 | for (InputMethodSubtype subtype: explicitlyOrImplicitlyEnabledSubtypeList) { |
| 2024 | enabledSubtypeSet.add(String.valueOf(subtype.hashCode())); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2025 | } |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2026 | ArrayList<InputMethodSubtype> subtypes = getSubtypes(imi); |
Ken Wakasa | 81f6e3d | 2011-03-04 09:59:52 +0900 | [diff] [blame] | 2027 | final CharSequence label = imi.loadLabel(pm); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2028 | if (showSubtypes && enabledSubtypeSet.size() > 0) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2029 | final int subtypeCount = imi.getSubtypeCount(); |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2030 | if (DEBUG) { |
| 2031 | Slog.v(TAG, "Add subtypes: " + subtypeCount + ", " + imi.getId()); |
| 2032 | } |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2033 | for (int j = 0; j < subtypeCount; ++j) { |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2034 | final InputMethodSubtype subtype = imi.getSubtypeAt(j); |
| 2035 | final String subtypeHashCode = String.valueOf(subtype.hashCode()); |
| 2036 | // We show all enabled IMEs and subtypes when an IME is shown. |
| 2037 | if (enabledSubtypeSet.contains(subtypeHashCode) |
satok | 7dca6cd | 2011-06-29 18:06:25 +0900 | [diff] [blame] | 2038 | && (mInputShown || !subtype.isAuxiliary())) { |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2039 | final CharSequence title; |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2040 | final String mode = subtype.getMode(); |
| 2041 | title = TextUtils.concat(subtype.getDisplayName(context, |
| 2042 | imi.getPackageName(), imi.getServiceInfo().applicationInfo), |
| 2043 | (TextUtils.isEmpty(label) ? "" : " (" + label + ")")); |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2044 | imList.add(new Pair<CharSequence, Pair<InputMethodInfo, Integer>>( |
| 2045 | title, new Pair<InputMethodInfo, Integer>(imi, j))); |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2046 | // Removing this subtype from enabledSubtypeSet because we no longer |
| 2047 | // need to add an entry of this subtype to imList to avoid duplicated |
| 2048 | // entries. |
| 2049 | enabledSubtypeSet.remove(subtypeHashCode); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2050 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2051 | } |
| 2052 | } else { |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2053 | imList.add(new Pair<CharSequence, Pair<InputMethodInfo, Integer>>( |
| 2054 | label, new Pair<InputMethodInfo, Integer>(imi, NOT_A_SUBTYPE_ID))); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2055 | } |
Dianne Hackborn | 97106ab | 2010-03-03 00:08:31 -0800 | [diff] [blame] | 2056 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2057 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2058 | final int N = imList.size(); |
| 2059 | mItems = new CharSequence[N]; |
| 2060 | for (int i = 0; i < N; ++i) { |
| 2061 | mItems[i] = imList.get(i).first; |
| 2062 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2063 | mIms = new InputMethodInfo[N]; |
| 2064 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2065 | int checkedItem = 0; |
| 2066 | for (int i = 0; i < N; ++i) { |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2067 | Pair<InputMethodInfo, Integer> value = imList.get(i).second; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2068 | mIms[i] = value.first; |
| 2069 | mSubtypeIds[i] = value.second; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2070 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2071 | int subtypeId = mSubtypeIds[i]; |
| 2072 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 2073 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 2074 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 2075 | checkedItem = i; |
| 2076 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2077 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2079 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2080 | AlertDialog.OnClickListener adocl = new AlertDialog.OnClickListener() { |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2081 | @Override |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2082 | public void onClick(DialogInterface dialog, int which) { |
| 2083 | hideInputMethodMenu(); |
| 2084 | } |
| 2085 | }; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2086 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2087 | TypedArray a = context.obtainStyledAttributes(null, |
| 2088 | com.android.internal.R.styleable.DialogPreference, |
| 2089 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 2090 | mDialogBuilder = new AlertDialog.Builder(context) |
| 2091 | .setTitle(com.android.internal.R.string.select_input_method) |
| 2092 | .setOnCancelListener(new OnCancelListener() { |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2093 | @Override |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2094 | public void onCancel(DialogInterface dialog) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | hideInputMethodMenu(); |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2096 | } |
| 2097 | }) |
| 2098 | .setIcon(a.getDrawable( |
| 2099 | com.android.internal.R.styleable.DialogPreference_dialogTitle)); |
| 2100 | a.recycle(); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2101 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2102 | mDialogBuilder.setSingleChoiceItems(mItems, checkedItem, |
| 2103 | new AlertDialog.OnClickListener() { |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2104 | @Override |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2105 | public void onClick(DialogInterface dialog, int which) { |
| 2106 | synchronized (mMethodMap) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2107 | if (mIms == null || mIms.length <= which |
| 2108 | || mSubtypeIds == null || mSubtypeIds.length <= which) { |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2109 | return; |
| 2110 | } |
| 2111 | InputMethodInfo im = mIms[which]; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2112 | int subtypeId = mSubtypeIds[which]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2113 | hideInputMethodMenu(); |
| 2114 | if (im != null) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2115 | if ((subtypeId < 0) |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2116 | || (subtypeId >= im.getSubtypeCount())) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2117 | subtypeId = NOT_A_SUBTYPE_ID; |
| 2118 | } |
| 2119 | setInputMethodLocked(im.getId(), subtypeId); |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2120 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 2121 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2123 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame^] | 2125 | if (showSubtypes && !(mKeyguardManager.isKeyguardLocked() |
| 2126 | && mKeyguardManager.isKeyguardSecure())) { |
satok | 82beadf | 2010-12-27 19:03:06 +0900 | [diff] [blame] | 2127 | mDialogBuilder.setPositiveButton( |
| 2128 | com.android.internal.R.string.configure_input_methods, |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2129 | new DialogInterface.OnClickListener() { |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2130 | @Override |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2131 | public void onClick(DialogInterface dialog, int whichButton) { |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 2132 | showConfigureInputMethods(); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2133 | } |
| 2134 | }); |
| 2135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | mSwitchingDialog = mDialogBuilder.create(); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 2137 | mSwitchingDialog.setCanceledOnTouchOutside(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | mSwitchingDialog.getWindow().setType( |
| 2139 | WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 2140 | mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | mSwitchingDialog.show(); |
| 2142 | } |
| 2143 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2145 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2146 | synchronized (mMethodMap) { |
| 2147 | hideInputMethodMenuLocked(); |
| 2148 | } |
| 2149 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2150 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2151 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2152 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2154 | if (mSwitchingDialog != null) { |
| 2155 | mSwitchingDialog.dismiss(); |
| 2156 | mSwitchingDialog = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2158 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2159 | mDialogBuilder = null; |
| 2160 | mItems = null; |
| 2161 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2164 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2165 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2166 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2167 | public boolean setInputMethodEnabled(String id, boolean enabled) { |
| 2168 | synchronized (mMethodMap) { |
| 2169 | if (mContext.checkCallingOrSelfPermission( |
| 2170 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 2171 | != PackageManager.PERMISSION_GRANTED) { |
| 2172 | throw new SecurityException( |
| 2173 | "Requires permission " |
| 2174 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 2175 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | long ident = Binder.clearCallingIdentity(); |
| 2178 | try { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2179 | return setInputMethodEnabledLocked(id, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2180 | } finally { |
| 2181 | Binder.restoreCallingIdentity(ident); |
| 2182 | } |
| 2183 | } |
| 2184 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2185 | |
| 2186 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 2187 | // Make sure this is a valid input method. |
| 2188 | InputMethodInfo imm = mMethodMap.get(id); |
| 2189 | if (imm == null) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2190 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2191 | } |
| 2192 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2193 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 2194 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2195 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2196 | if (enabled) { |
| 2197 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 2198 | if (pair.first.equals(id)) { |
| 2199 | // We are enabling this input method, but it is already enabled. |
| 2200 | // Nothing to do. The previous state was enabled. |
| 2201 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2202 | } |
| 2203 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2204 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 2205 | // Previous state was disabled. |
| 2206 | return false; |
| 2207 | } else { |
| 2208 | StringBuilder builder = new StringBuilder(); |
| 2209 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 2210 | builder, enabledInputMethodsList, id)) { |
| 2211 | // Disabled input method is currently selected, switch to another one. |
| 2212 | String selId = Settings.Secure.getString(mContext.getContentResolver(), |
| 2213 | Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2214 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 2215 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 2216 | resetSelectedInputMethodAndSubtypeLocked(""); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2217 | } |
| 2218 | // Previous state was enabled. |
| 2219 | return true; |
| 2220 | } else { |
| 2221 | // We are disabling the input method but it is already disabled. |
| 2222 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2223 | return false; |
| 2224 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2225 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2226 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2227 | |
satok | 57ffc00 | 2011-01-25 00:11:47 +0900 | [diff] [blame] | 2228 | private boolean canAddToLastInputMethod(InputMethodSubtype subtype) { |
| 2229 | if (subtype == null) return true; |
satok | 9b41579 | 2011-05-30 12:37:52 +0900 | [diff] [blame] | 2230 | return !subtype.isAuxiliary(); |
satok | 57ffc00 | 2011-01-25 00:11:47 +0900 | [diff] [blame] | 2231 | } |
| 2232 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2233 | private void saveCurrentInputMethodAndSubtypeToHistory() { |
| 2234 | String subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 2235 | if (mCurrentSubtype != null) { |
| 2236 | subtypeId = String.valueOf(mCurrentSubtype.hashCode()); |
| 2237 | } |
satok | 57ffc00 | 2011-01-25 00:11:47 +0900 | [diff] [blame] | 2238 | if (canAddToLastInputMethod(mCurrentSubtype)) { |
| 2239 | mSettings.addSubtypeToHistory(mCurMethodId, subtypeId); |
| 2240 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2241 | } |
| 2242 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2243 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 2244 | boolean setSubtypeOnly) { |
| 2245 | // Update the history of InputMethod and Subtype |
| 2246 | saveCurrentInputMethodAndSubtypeToHistory(); |
| 2247 | |
| 2248 | // Set Subtype here |
| 2249 | if (imi == null || subtypeId < 0) { |
| 2250 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 2251 | mCurrentSubtype = null; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2252 | } else { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2253 | if (subtypeId < imi.getSubtypeCount()) { |
| 2254 | InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId); |
| 2255 | mSettings.putSelectedSubtype(subtype.hashCode()); |
| 2256 | mCurrentSubtype = subtype; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2257 | } else { |
| 2258 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
| 2259 | mCurrentSubtype = null; |
| 2260 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2261 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2262 | |
| 2263 | if (!setSubtypeOnly) { |
| 2264 | // Set InputMethod here |
| 2265 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 2270 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 2271 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 2272 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 2273 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 2274 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 2275 | if (subtypeHashCode != null) { |
| 2276 | try { |
| 2277 | lastSubtypeId = getSubtypeIdFromHashCode( |
| 2278 | imi, Integer.valueOf(subtypeHashCode)); |
| 2279 | } catch (NumberFormatException e) { |
| 2280 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 2281 | } |
| 2282 | } |
| 2283 | } |
| 2284 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | private int getSelectedInputMethodSubtypeId(String id) { |
| 2288 | InputMethodInfo imi = mMethodMap.get(id); |
| 2289 | if (imi == null) { |
| 2290 | return NOT_A_SUBTYPE_ID; |
| 2291 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2292 | int subtypeId; |
| 2293 | try { |
| 2294 | subtypeId = Settings.Secure.getInt(mContext.getContentResolver(), |
| 2295 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE); |
| 2296 | } catch (SettingNotFoundException e) { |
| 2297 | return NOT_A_SUBTYPE_ID; |
| 2298 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2299 | return getSubtypeIdFromHashCode(imi, subtypeId); |
| 2300 | } |
| 2301 | |
| 2302 | private int getSubtypeIdFromHashCode(InputMethodInfo imi, int subtypeHashCode) { |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2303 | if (imi != null) { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2304 | final int subtypeCount = imi.getSubtypeCount(); |
| 2305 | for (int i = 0; i < subtypeCount; ++i) { |
| 2306 | InputMethodSubtype ims = imi.getSubtypeAt(i); |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2307 | if (subtypeHashCode == ims.hashCode()) { |
| 2308 | return i; |
| 2309 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2310 | } |
| 2311 | } |
| 2312 | return NOT_A_SUBTYPE_ID; |
| 2313 | } |
| 2314 | |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2315 | private static ArrayList<InputMethodSubtype> getApplicableSubtypesLocked( |
| 2316 | Resources res, List<InputMethodSubtype> subtypes) { |
| 2317 | final String systemLocale = res.getConfiguration().locale.toString(); |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2318 | if (TextUtils.isEmpty(systemLocale)) return new ArrayList<InputMethodSubtype>(); |
| 2319 | HashMap<String, InputMethodSubtype> applicableModeAndSubtypesMap = |
| 2320 | new HashMap<String, InputMethodSubtype>(); |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2321 | final int N = subtypes.size(); |
| 2322 | boolean containsKeyboardSubtype = false; |
| 2323 | for (int i = 0; i < N; ++i) { |
| 2324 | InputMethodSubtype subtype = subtypes.get(i); |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2325 | final String locale = subtype.getLocale(); |
| 2326 | final String mode = subtype.getMode(); |
| 2327 | // When system locale starts with subtype's locale, that subtype will be applicable |
| 2328 | // for system locale |
| 2329 | // For instance, it's clearly applicable for cases like system locale = en_US and |
| 2330 | // subtype = en, but it is not necessarily considered applicable for cases like system |
| 2331 | // locale = en and subtype = en_US. |
| 2332 | // We just call systemLocale.startsWith(locale) in this function because there is no |
| 2333 | // need to find applicable subtypes aggressively unlike |
| 2334 | // findLastResortApplicableSubtypeLocked. |
| 2335 | if (systemLocale.startsWith(locale)) { |
| 2336 | InputMethodSubtype applicableSubtype = applicableModeAndSubtypesMap.get(mode); |
| 2337 | // If more applicable subtypes are contained, skip. |
| 2338 | if (applicableSubtype != null |
| 2339 | && systemLocale.equals(applicableSubtype.getLocale())) continue; |
| 2340 | applicableModeAndSubtypesMap.put(mode, subtype); |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2341 | if (!containsKeyboardSubtype |
| 2342 | && SUBTYPE_MODE_KEYBOARD.equalsIgnoreCase(subtype.getMode())) { |
| 2343 | containsKeyboardSubtype = true; |
| 2344 | } |
| 2345 | } |
| 2346 | } |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2347 | final ArrayList<InputMethodSubtype> applicableSubtypes = new ArrayList<InputMethodSubtype>( |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2348 | applicableModeAndSubtypesMap.values()); |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2349 | if (!containsKeyboardSubtype) { |
| 2350 | InputMethodSubtype lastResortKeyboardSubtype = findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2351 | res, subtypes, SUBTYPE_MODE_KEYBOARD, systemLocale, true); |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2352 | if (lastResortKeyboardSubtype != null) { |
| 2353 | applicableSubtypes.add(lastResortKeyboardSubtype); |
| 2354 | } |
| 2355 | } |
| 2356 | return applicableSubtypes; |
| 2357 | } |
| 2358 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2359 | /** |
| 2360 | * If there are no selected subtypes, tries finding the most applicable one according to the |
| 2361 | * given locale. |
| 2362 | * @param subtypes this function will search the most applicable subtype in subtypes |
| 2363 | * @param mode subtypes will be filtered by mode |
| 2364 | * @param locale subtypes will be filtered by locale |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2365 | * @param canIgnoreLocaleAsLastResort if this function can't find the most applicable subtype, |
| 2366 | * it will return the first subtype matched with mode |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2367 | * @return the most applicable subtypeId |
| 2368 | */ |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2369 | private static InputMethodSubtype findLastResortApplicableSubtypeLocked( |
| 2370 | Resources res, List<InputMethodSubtype> subtypes, String mode, String locale, |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2371 | boolean canIgnoreLocaleAsLastResort) { |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2372 | if (subtypes == null || subtypes.size() == 0) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2373 | return null; |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2374 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2375 | if (TextUtils.isEmpty(locale)) { |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2376 | locale = res.getConfiguration().locale.toString(); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2377 | } |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2378 | final String language = locale.substring(0, 2); |
| 2379 | boolean partialMatchFound = false; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2380 | InputMethodSubtype applicableSubtype = null; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2381 | InputMethodSubtype firstMatchedModeSubtype = null; |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2382 | final int N = subtypes.size(); |
| 2383 | for (int i = 0; i < N; ++i) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2384 | InputMethodSubtype subtype = subtypes.get(i); |
| 2385 | final String subtypeLocale = subtype.getLocale(); |
satok | d871343 | 2011-01-18 00:55:13 +0900 | [diff] [blame] | 2386 | // An applicable subtype should match "mode". If mode is null, mode will be ignored, |
| 2387 | // and all subtypes with all modes can be candidates. |
| 2388 | if (mode == null || subtypes.get(i).getMode().equalsIgnoreCase(mode)) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2389 | if (firstMatchedModeSubtype == null) { |
| 2390 | firstMatchedModeSubtype = subtype; |
| 2391 | } |
satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2392 | if (locale.equals(subtypeLocale)) { |
| 2393 | // Exact match (e.g. system locale is "en_US" and subtype locale is "en_US") |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2394 | applicableSubtype = subtype; |
satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2395 | break; |
| 2396 | } else if (!partialMatchFound && subtypeLocale.startsWith(language)) { |
| 2397 | // Partial match (e.g. system locale is "en_US" and subtype locale is "en") |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2398 | applicableSubtype = subtype; |
satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2399 | partialMatchFound = true; |
| 2400 | } |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2404 | if (applicableSubtype == null && canIgnoreLocaleAsLastResort) { |
| 2405 | return firstMatchedModeSubtype; |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2406 | } |
| 2407 | |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2408 | // The first subtype applicable to the system locale will be defined as the most applicable |
| 2409 | // subtype. |
| 2410 | if (DEBUG) { |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2411 | if (applicableSubtype != null) { |
| 2412 | Slog.d(TAG, "Applicable InputMethodSubtype was found: " |
| 2413 | + applicableSubtype.getMode() + "," + applicableSubtype.getLocale()); |
| 2414 | } |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2415 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2416 | return applicableSubtype; |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2417 | } |
| 2418 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2419 | // If there are no selected shortcuts, tries finding the most applicable ones. |
| 2420 | private Pair<InputMethodInfo, InputMethodSubtype> |
| 2421 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) { |
| 2422 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 2423 | InputMethodInfo mostApplicableIMI = null; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2424 | InputMethodSubtype mostApplicableSubtype = null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2425 | boolean foundInSystemIME = false; |
| 2426 | |
| 2427 | // Search applicable subtype for each InputMethodInfo |
| 2428 | for (InputMethodInfo imi: imis) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2429 | final String imiId = imi.getId(); |
| 2430 | if (foundInSystemIME && !imiId.equals(mCurMethodId)) { |
| 2431 | continue; |
| 2432 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2433 | InputMethodSubtype subtype = null; |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2434 | final List<InputMethodSubtype> enabledSubtypes = |
| 2435 | getEnabledInputMethodSubtypeList(imi, true); |
| 2436 | // 1. Search by the current subtype's locale from enabledSubtypes. |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2437 | if (mCurrentSubtype != null) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2438 | subtype = findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2439 | mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2440 | } |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2441 | // 2. Search by the system locale from enabledSubtypes. |
| 2442 | // 3. Search the first enabled subtype matched with mode from enabledSubtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2443 | if (subtype == null) { |
| 2444 | subtype = findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2445 | mRes, enabledSubtypes, mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2446 | } |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2447 | // 4. Search by the current subtype's locale from all subtypes. |
| 2448 | if (subtype == null && mCurrentSubtype != null) { |
| 2449 | subtype = findLastResortApplicableSubtypeLocked( |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2450 | mRes, getSubtypes(imi), mode, mCurrentSubtype.getLocale(), false); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2451 | } |
| 2452 | // 5. Search by the system locale from all subtypes. |
| 2453 | // 6. Search the first enabled subtype matched with mode from all subtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2454 | if (subtype == null) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2455 | subtype = findLastResortApplicableSubtypeLocked( |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2456 | mRes, getSubtypes(imi), mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2457 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2458 | if (subtype != null) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2459 | if (imiId.equals(mCurMethodId)) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2460 | // The current input method is the most applicable IME. |
| 2461 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2462 | mostApplicableSubtype = subtype; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2463 | break; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2464 | } else if (!foundInSystemIME) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2465 | // The system input method is 2nd applicable IME. |
| 2466 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2467 | mostApplicableSubtype = subtype; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2468 | if ((imi.getServiceInfo().applicationInfo.flags |
| 2469 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 2470 | foundInSystemIME = true; |
| 2471 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2472 | } |
| 2473 | } |
| 2474 | } |
| 2475 | if (DEBUG) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2476 | if (mostApplicableIMI != null) { |
| 2477 | Slog.w(TAG, "Most applicable shortcut input method was:" |
| 2478 | + mostApplicableIMI.getId()); |
| 2479 | if (mostApplicableSubtype != null) { |
| 2480 | Slog.w(TAG, "Most applicable shortcut input method subtype was:" |
| 2481 | + "," + mostApplicableSubtype.getMode() + "," |
| 2482 | + mostApplicableSubtype.getLocale()); |
| 2483 | } |
| 2484 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2485 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2486 | if (mostApplicableIMI != null) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2487 | return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI, |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2488 | mostApplicableSubtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2489 | } else { |
| 2490 | return null; |
| 2491 | } |
| 2492 | } |
| 2493 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2494 | /** |
| 2495 | * @return Return the current subtype of this input method. |
| 2496 | */ |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2497 | @Override |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2498 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2499 | boolean subtypeIsSelected = false; |
| 2500 | try { |
| 2501 | subtypeIsSelected = Settings.Secure.getInt(mContext.getContentResolver(), |
| 2502 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE) != NOT_A_SUBTYPE_ID; |
| 2503 | } catch (SettingNotFoundException e) { |
| 2504 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2505 | synchronized (mMethodMap) { |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2506 | if (!subtypeIsSelected || mCurrentSubtype == null) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2507 | String lastInputMethodId = Settings.Secure.getString( |
| 2508 | mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2509 | int subtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId); |
| 2510 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2511 | InputMethodInfo imi = mMethodMap.get(lastInputMethodId); |
| 2512 | if (imi != null) { |
| 2513 | // If there are no selected subtypes, the framework will try to find |
satok | d871343 | 2011-01-18 00:55:13 +0900 | [diff] [blame] | 2514 | // the most applicable subtype from explicitly or implicitly enabled |
| 2515 | // subtypes. |
| 2516 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = |
| 2517 | getEnabledInputMethodSubtypeList(imi, true); |
| 2518 | // If there is only one explicitly or implicitly enabled subtype, |
| 2519 | // just returns it. |
| 2520 | if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { |
| 2521 | mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0); |
| 2522 | } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) { |
| 2523 | mCurrentSubtype = findLastResortApplicableSubtypeLocked( |
| 2524 | mRes, explicitlyOrImplicitlyEnabledSubtypes, |
| 2525 | SUBTYPE_MODE_KEYBOARD, null, true); |
| 2526 | if (mCurrentSubtype == null) { |
| 2527 | mCurrentSubtype = findLastResortApplicableSubtypeLocked( |
| 2528 | mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, |
| 2529 | true); |
| 2530 | } |
| 2531 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2532 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2533 | } else { |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2534 | mCurrentSubtype = |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2535 | getSubtypes(mMethodMap.get(lastInputMethodId)).get(subtypeId); |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2536 | } |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2537 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2538 | return mCurrentSubtype; |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2539 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2540 | } |
| 2541 | |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2542 | private void addShortcutInputMethodAndSubtypes(InputMethodInfo imi, |
| 2543 | InputMethodSubtype subtype) { |
| 2544 | if (mShortcutInputMethodsAndSubtypes.containsKey(imi)) { |
| 2545 | mShortcutInputMethodsAndSubtypes.get(imi).add(subtype); |
| 2546 | } else { |
| 2547 | ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); |
| 2548 | subtypes.add(subtype); |
| 2549 | mShortcutInputMethodsAndSubtypes.put(imi, subtypes); |
| 2550 | } |
| 2551 | } |
| 2552 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2553 | // TODO: We should change the return type from List to List<Parcelable> |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2554 | @Override |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2555 | public List getShortcutInputMethodsAndSubtypes() { |
| 2556 | synchronized (mMethodMap) { |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2557 | ArrayList<Object> ret = new ArrayList<Object>(); |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2558 | if (mShortcutInputMethodsAndSubtypes.size() == 0) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2559 | // If there are no selected shortcut subtypes, the framework will try to find |
| 2560 | // the most applicable subtype from all subtypes whose mode is |
| 2561 | // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode. |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2562 | Pair<InputMethodInfo, InputMethodSubtype> info = |
| 2563 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked( |
| 2564 | SUBTYPE_MODE_VOICE); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2565 | if (info != null) { |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2566 | ret.add(info.first); |
| 2567 | ret.add(info.second); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2568 | } |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2569 | return ret; |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2570 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2571 | for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) { |
| 2572 | ret.add(imi); |
| 2573 | for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) { |
| 2574 | ret.add(subtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2575 | } |
| 2576 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2577 | return ret; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2581 | @Override |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 2582 | public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) { |
| 2583 | synchronized (mMethodMap) { |
| 2584 | if (subtype != null && mCurMethodId != null) { |
| 2585 | InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2586 | int subtypeId = getSubtypeIdFromHashCode(imi, subtype.hashCode()); |
| 2587 | if (subtypeId != NOT_A_SUBTYPE_ID) { |
| 2588 | setInputMethodLocked(mCurMethodId, subtypeId); |
| 2589 | return true; |
| 2590 | } |
| 2591 | } |
| 2592 | return false; |
| 2593 | } |
| 2594 | } |
| 2595 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2596 | /** |
| 2597 | * Utility class for putting and getting settings for InputMethod |
| 2598 | * TODO: Move all putters and getters of settings to this class. |
| 2599 | */ |
| 2600 | private static class InputMethodSettings { |
| 2601 | // The string for enabled input method is saved as follows: |
| 2602 | // example: ("ime0;subtype0;subtype1;subtype2:ime1:ime2;subtype0") |
| 2603 | private static final char INPUT_METHOD_SEPARATER = ':'; |
| 2604 | private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';'; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2605 | private final TextUtils.SimpleStringSplitter mInputMethodSplitter = |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2606 | new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER); |
| 2607 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2608 | private final TextUtils.SimpleStringSplitter mSubtypeSplitter = |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2609 | new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATER); |
| 2610 | |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2611 | private final Resources mRes; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2612 | private final ContentResolver mResolver; |
| 2613 | private final HashMap<String, InputMethodInfo> mMethodMap; |
| 2614 | private final ArrayList<InputMethodInfo> mMethodList; |
| 2615 | |
| 2616 | private String mEnabledInputMethodsStrCache; |
| 2617 | |
| 2618 | private static void buildEnabledInputMethodsSettingString( |
| 2619 | StringBuilder builder, Pair<String, ArrayList<String>> pair) { |
| 2620 | String id = pair.first; |
| 2621 | ArrayList<String> subtypes = pair.second; |
| 2622 | builder.append(id); |
satok | 57c767c | 2010-11-01 22:34:08 +0900 | [diff] [blame] | 2623 | // Inputmethod and subtypes are saved in the settings as follows: |
| 2624 | // ime0;subtype0;subtype1:ime1;subtype0:ime2:ime3;subtype0;subtype1 |
| 2625 | for (String subtypeId: subtypes) { |
| 2626 | builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtypeId); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | public InputMethodSettings( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2631 | Resources res, ContentResolver resolver, |
| 2632 | HashMap<String, InputMethodInfo> methodMap, ArrayList<InputMethodInfo> methodList) { |
| 2633 | mRes = res; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2634 | mResolver = resolver; |
| 2635 | mMethodMap = methodMap; |
| 2636 | mMethodList = methodList; |
| 2637 | } |
| 2638 | |
| 2639 | public List<InputMethodInfo> getEnabledInputMethodListLocked() { |
| 2640 | return createEnabledInputMethodListLocked( |
| 2641 | getEnabledInputMethodsAndSubtypeListLocked()); |
| 2642 | } |
| 2643 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2644 | public List<Pair<InputMethodInfo, ArrayList<String>>> |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2645 | getEnabledInputMethodAndSubtypeHashCodeListLocked() { |
| 2646 | return createEnabledInputMethodAndSubtypeHashCodeListLocked( |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2647 | getEnabledInputMethodsAndSubtypeListLocked()); |
| 2648 | } |
| 2649 | |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2650 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked( |
| 2651 | InputMethodInfo imi) { |
| 2652 | List<Pair<String, ArrayList<String>>> imsList = |
| 2653 | getEnabledInputMethodsAndSubtypeListLocked(); |
| 2654 | ArrayList<InputMethodSubtype> enabledSubtypes = |
| 2655 | new ArrayList<InputMethodSubtype>(); |
satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 2656 | if (imi != null) { |
| 2657 | for (Pair<String, ArrayList<String>> imsPair : imsList) { |
| 2658 | InputMethodInfo info = mMethodMap.get(imsPair.first); |
| 2659 | if (info != null && info.getId().equals(imi.getId())) { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2660 | final int subtypeCount = info.getSubtypeCount(); |
| 2661 | for (int i = 0; i < subtypeCount; ++i) { |
| 2662 | InputMethodSubtype ims = info.getSubtypeAt(i); |
satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 2663 | for (String s: imsPair.second) { |
| 2664 | if (String.valueOf(ims.hashCode()).equals(s)) { |
| 2665 | enabledSubtypes.add(ims); |
| 2666 | } |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2667 | } |
| 2668 | } |
satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 2669 | break; |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2670 | } |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | return enabledSubtypes; |
| 2674 | } |
| 2675 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2676 | // At the initial boot, the settings for input methods are not set, |
| 2677 | // so we need to enable IME in that case. |
| 2678 | public void enableAllIMEsIfThereIsNoEnabledIME() { |
| 2679 | if (TextUtils.isEmpty(getEnabledInputMethodsStr())) { |
| 2680 | StringBuilder sb = new StringBuilder(); |
| 2681 | final int N = mMethodList.size(); |
| 2682 | for (int i = 0; i < N; i++) { |
| 2683 | InputMethodInfo imi = mMethodList.get(i); |
| 2684 | Slog.i(TAG, "Adding: " + imi.getId()); |
| 2685 | if (i > 0) sb.append(':'); |
| 2686 | sb.append(imi.getId()); |
| 2687 | } |
| 2688 | putEnabledInputMethodsStr(sb.toString()); |
| 2689 | } |
| 2690 | } |
| 2691 | |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2692 | private List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2693 | ArrayList<Pair<String, ArrayList<String>>> imsList |
| 2694 | = new ArrayList<Pair<String, ArrayList<String>>>(); |
| 2695 | final String enabledInputMethodsStr = getEnabledInputMethodsStr(); |
| 2696 | if (TextUtils.isEmpty(enabledInputMethodsStr)) { |
| 2697 | return imsList; |
| 2698 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2699 | mInputMethodSplitter.setString(enabledInputMethodsStr); |
| 2700 | while (mInputMethodSplitter.hasNext()) { |
| 2701 | String nextImsStr = mInputMethodSplitter.next(); |
| 2702 | mSubtypeSplitter.setString(nextImsStr); |
| 2703 | if (mSubtypeSplitter.hasNext()) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2704 | ArrayList<String> subtypeHashes = new ArrayList<String>(); |
| 2705 | // The first element is ime id. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2706 | String imeId = mSubtypeSplitter.next(); |
| 2707 | while (mSubtypeSplitter.hasNext()) { |
| 2708 | subtypeHashes.add(mSubtypeSplitter.next()); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2709 | } |
| 2710 | imsList.add(new Pair<String, ArrayList<String>>(imeId, subtypeHashes)); |
| 2711 | } |
| 2712 | } |
| 2713 | return imsList; |
| 2714 | } |
| 2715 | |
| 2716 | public void appendAndPutEnabledInputMethodLocked(String id, boolean reloadInputMethodStr) { |
| 2717 | if (reloadInputMethodStr) { |
| 2718 | getEnabledInputMethodsStr(); |
| 2719 | } |
| 2720 | if (TextUtils.isEmpty(mEnabledInputMethodsStrCache)) { |
| 2721 | // Add in the newly enabled input method. |
| 2722 | putEnabledInputMethodsStr(id); |
| 2723 | } else { |
| 2724 | putEnabledInputMethodsStr( |
| 2725 | mEnabledInputMethodsStrCache + INPUT_METHOD_SEPARATER + id); |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | /** |
| 2730 | * Build and put a string of EnabledInputMethods with removing specified Id. |
| 2731 | * @return the specified id was removed or not. |
| 2732 | */ |
| 2733 | public boolean buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 2734 | StringBuilder builder, List<Pair<String, ArrayList<String>>> imsList, String id) { |
| 2735 | boolean isRemoved = false; |
| 2736 | boolean needsAppendSeparator = false; |
| 2737 | for (Pair<String, ArrayList<String>> ims: imsList) { |
| 2738 | String curId = ims.first; |
| 2739 | if (curId.equals(id)) { |
| 2740 | // We are disabling this input method, and it is |
| 2741 | // currently enabled. Skip it to remove from the |
| 2742 | // new list. |
| 2743 | isRemoved = true; |
| 2744 | } else { |
| 2745 | if (needsAppendSeparator) { |
| 2746 | builder.append(INPUT_METHOD_SEPARATER); |
| 2747 | } else { |
| 2748 | needsAppendSeparator = true; |
| 2749 | } |
| 2750 | buildEnabledInputMethodsSettingString(builder, ims); |
| 2751 | } |
| 2752 | } |
| 2753 | if (isRemoved) { |
| 2754 | // Update the setting with the new list of input methods. |
| 2755 | putEnabledInputMethodsStr(builder.toString()); |
| 2756 | } |
| 2757 | return isRemoved; |
| 2758 | } |
| 2759 | |
| 2760 | private List<InputMethodInfo> createEnabledInputMethodListLocked( |
| 2761 | List<Pair<String, ArrayList<String>>> imsList) { |
| 2762 | final ArrayList<InputMethodInfo> res = new ArrayList<InputMethodInfo>(); |
| 2763 | for (Pair<String, ArrayList<String>> ims: imsList) { |
| 2764 | InputMethodInfo info = mMethodMap.get(ims.first); |
| 2765 | if (info != null) { |
| 2766 | res.add(info); |
| 2767 | } |
| 2768 | } |
| 2769 | return res; |
| 2770 | } |
| 2771 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2772 | private List<Pair<InputMethodInfo, ArrayList<String>>> |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2773 | createEnabledInputMethodAndSubtypeHashCodeListLocked( |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2774 | List<Pair<String, ArrayList<String>>> imsList) { |
| 2775 | final ArrayList<Pair<InputMethodInfo, ArrayList<String>>> res |
| 2776 | = new ArrayList<Pair<InputMethodInfo, ArrayList<String>>>(); |
| 2777 | for (Pair<String, ArrayList<String>> ims : imsList) { |
| 2778 | InputMethodInfo info = mMethodMap.get(ims.first); |
| 2779 | if (info != null) { |
| 2780 | res.add(new Pair<InputMethodInfo, ArrayList<String>>(info, ims.second)); |
| 2781 | } |
| 2782 | } |
| 2783 | return res; |
| 2784 | } |
| 2785 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2786 | private void putEnabledInputMethodsStr(String str) { |
| 2787 | Settings.Secure.putString(mResolver, Settings.Secure.ENABLED_INPUT_METHODS, str); |
| 2788 | mEnabledInputMethodsStrCache = str; |
| 2789 | } |
| 2790 | |
| 2791 | private String getEnabledInputMethodsStr() { |
| 2792 | mEnabledInputMethodsStrCache = Settings.Secure.getString( |
| 2793 | mResolver, Settings.Secure.ENABLED_INPUT_METHODS); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2794 | if (DEBUG) { |
| 2795 | Slog.d(TAG, "getEnabledInputMethodsStr: " + mEnabledInputMethodsStrCache); |
| 2796 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2797 | return mEnabledInputMethodsStrCache; |
| 2798 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2799 | |
| 2800 | private void saveSubtypeHistory( |
| 2801 | List<Pair<String, String>> savedImes, String newImeId, String newSubtypeId) { |
| 2802 | StringBuilder builder = new StringBuilder(); |
| 2803 | boolean isImeAdded = false; |
| 2804 | if (!TextUtils.isEmpty(newImeId) && !TextUtils.isEmpty(newSubtypeId)) { |
| 2805 | builder.append(newImeId).append(INPUT_METHOD_SUBTYPE_SEPARATER).append( |
| 2806 | newSubtypeId); |
| 2807 | isImeAdded = true; |
| 2808 | } |
| 2809 | for (Pair<String, String> ime: savedImes) { |
| 2810 | String imeId = ime.first; |
| 2811 | String subtypeId = ime.second; |
| 2812 | if (TextUtils.isEmpty(subtypeId)) { |
| 2813 | subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 2814 | } |
| 2815 | if (isImeAdded) { |
| 2816 | builder.append(INPUT_METHOD_SEPARATER); |
| 2817 | } else { |
| 2818 | isImeAdded = true; |
| 2819 | } |
| 2820 | builder.append(imeId).append(INPUT_METHOD_SUBTYPE_SEPARATER).append( |
| 2821 | subtypeId); |
| 2822 | } |
| 2823 | // Remove the last INPUT_METHOD_SEPARATER |
| 2824 | putSubtypeHistoryStr(builder.toString()); |
| 2825 | } |
| 2826 | |
| 2827 | public void addSubtypeToHistory(String imeId, String subtypeId) { |
| 2828 | List<Pair<String, String>> subtypeHistory = loadInputMethodAndSubtypeHistoryLocked(); |
| 2829 | for (Pair<String, String> ime: subtypeHistory) { |
| 2830 | if (ime.first.equals(imeId)) { |
| 2831 | if (DEBUG) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2832 | Slog.v(TAG, "Subtype found in the history: " + imeId + ", " |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2833 | + ime.second); |
| 2834 | } |
| 2835 | // We should break here |
| 2836 | subtypeHistory.remove(ime); |
| 2837 | break; |
| 2838 | } |
| 2839 | } |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2840 | if (DEBUG) { |
| 2841 | Slog.v(TAG, "Add subtype to the history: " + imeId + ", " + subtypeId); |
| 2842 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2843 | saveSubtypeHistory(subtypeHistory, imeId, subtypeId); |
| 2844 | } |
| 2845 | |
| 2846 | private void putSubtypeHistoryStr(String str) { |
| 2847 | if (DEBUG) { |
| 2848 | Slog.d(TAG, "putSubtypeHistoryStr: " + str); |
| 2849 | } |
| 2850 | Settings.Secure.putString( |
| 2851 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, str); |
| 2852 | } |
| 2853 | |
| 2854 | public Pair<String, String> getLastInputMethodAndSubtypeLocked() { |
| 2855 | // Gets the first one from the history |
| 2856 | return getLastSubtypeForInputMethodLockedInternal(null); |
| 2857 | } |
| 2858 | |
| 2859 | public String getLastSubtypeForInputMethodLocked(String imeId) { |
| 2860 | Pair<String, String> ime = getLastSubtypeForInputMethodLockedInternal(imeId); |
| 2861 | if (ime != null) { |
| 2862 | return ime.second; |
| 2863 | } else { |
| 2864 | return null; |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | private Pair<String, String> getLastSubtypeForInputMethodLockedInternal(String imeId) { |
| 2869 | List<Pair<String, ArrayList<String>>> enabledImes = |
| 2870 | getEnabledInputMethodsAndSubtypeListLocked(); |
| 2871 | List<Pair<String, String>> subtypeHistory = loadInputMethodAndSubtypeHistoryLocked(); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2872 | for (Pair<String, String> imeAndSubtype : subtypeHistory) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2873 | final String imeInTheHistory = imeAndSubtype.first; |
| 2874 | // If imeId is empty, returns the first IME and subtype in the history |
| 2875 | if (TextUtils.isEmpty(imeId) || imeInTheHistory.equals(imeId)) { |
| 2876 | final String subtypeInTheHistory = imeAndSubtype.second; |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2877 | final String subtypeHashCode = |
| 2878 | getEnabledSubtypeHashCodeForInputMethodAndSubtypeLocked( |
| 2879 | enabledImes, imeInTheHistory, subtypeInTheHistory); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2880 | if (!TextUtils.isEmpty(subtypeHashCode)) { |
| 2881 | if (DEBUG) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2882 | Slog.d(TAG, "Enabled subtype found in the history: " + subtypeHashCode); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2883 | } |
| 2884 | return new Pair<String, String>(imeInTheHistory, subtypeHashCode); |
| 2885 | } |
| 2886 | } |
| 2887 | } |
| 2888 | if (DEBUG) { |
| 2889 | Slog.d(TAG, "No enabled IME found in the history"); |
| 2890 | } |
| 2891 | return null; |
| 2892 | } |
| 2893 | |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2894 | private String getEnabledSubtypeHashCodeForInputMethodAndSubtypeLocked(List<Pair<String, |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2895 | ArrayList<String>>> enabledImes, String imeId, String subtypeHashCode) { |
| 2896 | for (Pair<String, ArrayList<String>> enabledIme: enabledImes) { |
| 2897 | if (enabledIme.first.equals(imeId)) { |
satok | f6cafb6 | 2011-01-17 16:29:02 +0900 | [diff] [blame] | 2898 | final ArrayList<String> explicitlyEnabledSubtypes = enabledIme.second; |
| 2899 | if (explicitlyEnabledSubtypes.size() == 0) { |
| 2900 | // If there are no explicitly enabled subtypes, applicable subtypes are |
| 2901 | // enabled implicitly. |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2902 | InputMethodInfo ime = mMethodMap.get(imeId); |
| 2903 | // If IME is enabled and no subtypes are enabled, applicable subtypes |
| 2904 | // are enabled implicitly, so needs to treat them to be enabled. |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2905 | if (ime != null && ime.getSubtypeCount() > 0) { |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2906 | List<InputMethodSubtype> implicitlySelectedSubtypes = |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2907 | getApplicableSubtypesLocked(mRes, getSubtypes(ime)); |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2908 | if (implicitlySelectedSubtypes != null) { |
| 2909 | final int N = implicitlySelectedSubtypes.size(); |
| 2910 | for (int i = 0; i < N; ++i) { |
| 2911 | final InputMethodSubtype st = implicitlySelectedSubtypes.get(i); |
| 2912 | if (String.valueOf(st.hashCode()).equals(subtypeHashCode)) { |
| 2913 | return subtypeHashCode; |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | } |
| 2918 | } else { |
satok | f6cafb6 | 2011-01-17 16:29:02 +0900 | [diff] [blame] | 2919 | for (String s: explicitlyEnabledSubtypes) { |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2920 | if (s.equals(subtypeHashCode)) { |
| 2921 | // If both imeId and subtypeId are enabled, return subtypeId. |
| 2922 | return s; |
| 2923 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2924 | } |
| 2925 | } |
| 2926 | // If imeId was enabled but subtypeId was disabled. |
| 2927 | return NOT_A_SUBTYPE_ID_STR; |
| 2928 | } |
| 2929 | } |
| 2930 | // If both imeId and subtypeId are disabled, return null |
| 2931 | return null; |
| 2932 | } |
| 2933 | |
| 2934 | private List<Pair<String, String>> loadInputMethodAndSubtypeHistoryLocked() { |
| 2935 | ArrayList<Pair<String, String>> imsList = new ArrayList<Pair<String, String>>(); |
| 2936 | final String subtypeHistoryStr = getSubtypeHistoryStr(); |
| 2937 | if (TextUtils.isEmpty(subtypeHistoryStr)) { |
| 2938 | return imsList; |
| 2939 | } |
| 2940 | mInputMethodSplitter.setString(subtypeHistoryStr); |
| 2941 | while (mInputMethodSplitter.hasNext()) { |
| 2942 | String nextImsStr = mInputMethodSplitter.next(); |
| 2943 | mSubtypeSplitter.setString(nextImsStr); |
| 2944 | if (mSubtypeSplitter.hasNext()) { |
| 2945 | String subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 2946 | // The first element is ime id. |
| 2947 | String imeId = mSubtypeSplitter.next(); |
| 2948 | while (mSubtypeSplitter.hasNext()) { |
| 2949 | subtypeId = mSubtypeSplitter.next(); |
| 2950 | break; |
| 2951 | } |
| 2952 | imsList.add(new Pair<String, String>(imeId, subtypeId)); |
| 2953 | } |
| 2954 | } |
| 2955 | return imsList; |
| 2956 | } |
| 2957 | |
| 2958 | private String getSubtypeHistoryStr() { |
| 2959 | if (DEBUG) { |
| 2960 | Slog.d(TAG, "getSubtypeHistoryStr: " + Settings.Secure.getString( |
| 2961 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY)); |
| 2962 | } |
| 2963 | return Settings.Secure.getString( |
| 2964 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY); |
| 2965 | } |
| 2966 | |
| 2967 | public void putSelectedInputMethod(String imeId) { |
| 2968 | Settings.Secure.putString(mResolver, Settings.Secure.DEFAULT_INPUT_METHOD, imeId); |
| 2969 | } |
| 2970 | |
| 2971 | public void putSelectedSubtype(int subtypeId) { |
| 2972 | Settings.Secure.putInt( |
| 2973 | mResolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, subtypeId); |
| 2974 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2975 | } |
| 2976 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2977 | private static class InputMethodFileManager { |
| 2978 | private static final String SYSTEM_PATH = "system"; |
| 2979 | private static final String INPUT_METHOD_PATH = "inputmethod"; |
| 2980 | private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml"; |
| 2981 | private static final String NODE_SUBTYPES = "subtypes"; |
| 2982 | private static final String NODE_SUBTYPE = "subtype"; |
| 2983 | private static final String NODE_IMI = "imi"; |
| 2984 | private static final String ATTR_ID = "id"; |
| 2985 | private static final String ATTR_LABEL = "label"; |
| 2986 | private static final String ATTR_ICON = "icon"; |
| 2987 | private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale"; |
| 2988 | private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode"; |
| 2989 | private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue"; |
| 2990 | private static final String ATTR_IS_AUXILIARY = "isAuxiliary"; |
| 2991 | private final AtomicFile mAdditionalInputMethodSubtypeFile; |
| 2992 | private final HashMap<String, InputMethodInfo> mMethodMap; |
| 2993 | private final HashMap<String, List<InputMethodSubtype>> mSubtypesMap = |
| 2994 | new HashMap<String, List<InputMethodSubtype>>(); |
| 2995 | public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap) { |
| 2996 | if (methodMap == null) { |
| 2997 | throw new NullPointerException("methodMap is null"); |
| 2998 | } |
| 2999 | mMethodMap = methodMap; |
| 3000 | final File systemDir = new File(Environment.getDataDirectory(), SYSTEM_PATH); |
| 3001 | final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH); |
| 3002 | if (!inputMethodDir.mkdirs()) { |
| 3003 | Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath()); |
| 3004 | } |
| 3005 | final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME); |
| 3006 | mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile); |
| 3007 | if (!subtypeFile.exists()) { |
| 3008 | // If "subtypes.xml" doesn't exist, create a blank file. |
| 3009 | writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile, |
| 3010 | methodMap); |
| 3011 | } else { |
| 3012 | readAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile); |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | private void deleteAllInputMethodSubtypes(String imiId) { |
| 3017 | synchronized (mMethodMap) { |
| 3018 | mSubtypesMap.remove(imiId); |
| 3019 | writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile, |
| 3020 | mMethodMap); |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | public void addInputMethodSubtypes( |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3025 | InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3026 | synchronized (mMethodMap) { |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3027 | final HashSet<InputMethodSubtype> existingSubtypes = |
| 3028 | new HashSet<InputMethodSubtype>(); |
| 3029 | for (int i = 0; i < imi.getSubtypeCount(); ++i) { |
| 3030 | existingSubtypes.add(imi.getSubtypeAt(i)); |
| 3031 | } |
| 3032 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3033 | final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); |
| 3034 | final int N = additionalSubtypes.length; |
| 3035 | for (int i = 0; i < N; ++i) { |
| 3036 | final InputMethodSubtype subtype = additionalSubtypes[i]; |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3037 | if (!subtypes.contains(subtype) && !existingSubtypes.contains(subtype)) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3038 | subtypes.add(subtype); |
| 3039 | } |
| 3040 | } |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3041 | mSubtypesMap.put(imi.getId(), subtypes); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3042 | writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile, |
| 3043 | mMethodMap); |
| 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() { |
| 3048 | synchronized (mMethodMap) { |
| 3049 | return mSubtypesMap; |
| 3050 | } |
| 3051 | } |
| 3052 | |
| 3053 | private static void writeAdditionalInputMethodSubtypes( |
| 3054 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile, |
| 3055 | HashMap<String, InputMethodInfo> methodMap) { |
| 3056 | // Safety net for the case that this function is called before methodMap is set. |
| 3057 | final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0; |
| 3058 | FileOutputStream fos = null; |
| 3059 | try { |
| 3060 | fos = subtypesFile.startWrite(); |
| 3061 | final XmlSerializer out = new FastXmlSerializer(); |
| 3062 | out.setOutput(fos, "utf-8"); |
| 3063 | out.startDocument(null, true); |
| 3064 | out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 3065 | out.startTag(null, NODE_SUBTYPES); |
| 3066 | for (String imiId : allSubtypes.keySet()) { |
| 3067 | if (isSetMethodMap && !methodMap.containsKey(imiId)) { |
| 3068 | Slog.w(TAG, "IME uninstalled or not valid.: " + imiId); |
| 3069 | continue; |
| 3070 | } |
| 3071 | out.startTag(null, NODE_IMI); |
| 3072 | out.attribute(null, ATTR_ID, imiId); |
| 3073 | final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId); |
| 3074 | final int N = subtypesList.size(); |
| 3075 | for (int i = 0; i < N; ++i) { |
| 3076 | final InputMethodSubtype subtype = subtypesList.get(i); |
| 3077 | out.startTag(null, NODE_SUBTYPE); |
| 3078 | out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId())); |
| 3079 | out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId())); |
| 3080 | out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale()); |
| 3081 | out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode()); |
| 3082 | out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue()); |
| 3083 | out.attribute(null, ATTR_IS_AUXILIARY, |
| 3084 | String.valueOf(subtype.isAuxiliary() ? 1 : 0)); |
| 3085 | out.endTag(null, NODE_SUBTYPE); |
| 3086 | } |
| 3087 | out.endTag(null, NODE_IMI); |
| 3088 | } |
| 3089 | out.endTag(null, NODE_SUBTYPES); |
| 3090 | out.endDocument(); |
| 3091 | subtypesFile.finishWrite(fos); |
| 3092 | } catch (java.io.IOException e) { |
| 3093 | Slog.w(TAG, "Error writing subtypes", e); |
| 3094 | if (fos != null) { |
| 3095 | subtypesFile.failWrite(fos); |
| 3096 | } |
| 3097 | } |
| 3098 | } |
| 3099 | |
| 3100 | private static void readAdditionalInputMethodSubtypes( |
| 3101 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) { |
| 3102 | if (allSubtypes == null || subtypesFile == null) return; |
| 3103 | allSubtypes.clear(); |
| 3104 | FileInputStream fis = null; |
| 3105 | try { |
| 3106 | fis = subtypesFile.openRead(); |
| 3107 | final XmlPullParser parser = Xml.newPullParser(); |
| 3108 | parser.setInput(fis, null); |
| 3109 | int type = parser.getEventType(); |
| 3110 | // Skip parsing until START_TAG |
| 3111 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 3112 | && type != XmlPullParser.END_DOCUMENT) {} |
| 3113 | String firstNodeName = parser.getName(); |
| 3114 | if (!NODE_SUBTYPES.equals(firstNodeName)) { |
| 3115 | throw new XmlPullParserException("Xml doesn't start with subtypes"); |
| 3116 | } |
| 3117 | final int depth =parser.getDepth(); |
| 3118 | String currentImiId = null; |
| 3119 | ArrayList<InputMethodSubtype> tempSubtypesArray = null; |
| 3120 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 3121 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 3122 | if (type != XmlPullParser.START_TAG) |
| 3123 | continue; |
| 3124 | final String nodeName = parser.getName(); |
| 3125 | if (NODE_IMI.equals(nodeName)) { |
| 3126 | currentImiId = parser.getAttributeValue(null, ATTR_ID); |
| 3127 | if (TextUtils.isEmpty(currentImiId)) { |
| 3128 | Slog.w(TAG, "Invalid imi id found in subtypes.xml"); |
| 3129 | continue; |
| 3130 | } |
| 3131 | tempSubtypesArray = new ArrayList<InputMethodSubtype>(); |
| 3132 | allSubtypes.put(currentImiId, tempSubtypesArray); |
| 3133 | } else if (NODE_SUBTYPE.equals(nodeName)) { |
| 3134 | if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) { |
| 3135 | Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId); |
| 3136 | continue; |
| 3137 | } |
| 3138 | final int icon = Integer.valueOf( |
| 3139 | parser.getAttributeValue(null, ATTR_ICON)); |
| 3140 | final int label = Integer.valueOf( |
| 3141 | parser.getAttributeValue(null, ATTR_LABEL)); |
| 3142 | final String imeSubtypeLocale = |
| 3143 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE); |
| 3144 | final String imeSubtypeMode = |
| 3145 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE); |
| 3146 | final String imeSubtypeExtraValue = |
| 3147 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE); |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3148 | final boolean isAuxiliary = "1".equals(String.valueOf( |
| 3149 | parser.getAttributeValue(null, ATTR_IS_AUXILIARY))); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3150 | final InputMethodSubtype subtype = |
| 3151 | new InputMethodSubtype(label, icon, imeSubtypeLocale, |
| 3152 | imeSubtypeMode, imeSubtypeExtraValue, isAuxiliary); |
| 3153 | tempSubtypesArray.add(subtype); |
| 3154 | } |
| 3155 | } |
| 3156 | } catch (XmlPullParserException e) { |
| 3157 | Slog.w(TAG, "Error reading subtypes: " + e); |
| 3158 | return; |
| 3159 | } catch (java.io.IOException e) { |
| 3160 | Slog.w(TAG, "Error reading subtypes: " + e); |
| 3161 | return; |
| 3162 | } catch (NumberFormatException e) { |
| 3163 | Slog.w(TAG, "Error reading subtypes: " + e); |
| 3164 | return; |
| 3165 | } finally { |
| 3166 | if (fis != null) { |
| 3167 | try { |
| 3168 | fis.close(); |
| 3169 | } catch (java.io.IOException e1) { |
| 3170 | Slog.w(TAG, "Failed to close."); |
| 3171 | } |
| 3172 | } |
| 3173 | } |
| 3174 | } |
| 3175 | } |
| 3176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3177 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3179 | @Override |
| 3180 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 3181 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 3182 | != PackageManager.PERMISSION_GRANTED) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | pw.println("Permission Denial: can't dump InputMethodManager from from pid=" |
| 3185 | + Binder.getCallingPid() |
| 3186 | + ", uid=" + Binder.getCallingUid()); |
| 3187 | return; |
| 3188 | } |
| 3189 | |
| 3190 | IInputMethod method; |
| 3191 | ClientState client; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3195 | synchronized (mMethodMap) { |
| 3196 | p.println("Current Input Method Manager state:"); |
| 3197 | int N = mMethodList.size(); |
| 3198 | p.println(" Input Methods:"); |
| 3199 | for (int i=0; i<N; i++) { |
| 3200 | InputMethodInfo info = mMethodList.get(i); |
| 3201 | p.println(" InputMethod #" + i + ":"); |
| 3202 | info.dump(p, " "); |
| 3203 | } |
| 3204 | p.println(" Clients:"); |
| 3205 | for (ClientState ci : mClients.values()) { |
| 3206 | p.println(" Client " + ci + ":"); |
| 3207 | p.println(" client=" + ci.client); |
| 3208 | p.println(" inputContext=" + ci.inputContext); |
| 3209 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 3210 | p.println(" curSession=" + ci.curSession); |
| 3211 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3212 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 3214 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
| 3215 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3216 | p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection |
| 3217 | + " mBoundToMethod=" + mBoundToMethod); |
| 3218 | p.println(" mCurToken=" + mCurToken); |
| 3219 | p.println(" mCurIntent=" + mCurIntent); |
| 3220 | method = mCurMethod; |
| 3221 | p.println(" mCurMethod=" + mCurMethod); |
| 3222 | p.println(" mEnabledSession=" + mEnabledSession); |
| 3223 | p.println(" mShowRequested=" + mShowRequested |
| 3224 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 3225 | + " mShowForced=" + mShowForced |
| 3226 | + " mInputShown=" + mInputShown); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 3227 | p.println(" mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3228 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3229 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3230 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3231 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | pw.flush(); |
| 3233 | try { |
| 3234 | client.client.asBinder().dump(fd, args); |
| 3235 | } catch (RemoteException e) { |
| 3236 | p.println("Input method client dead: " + e); |
| 3237 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3238 | } else { |
| 3239 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3241 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3242 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | pw.flush(); |
| 3245 | try { |
| 3246 | method.asBinder().dump(fd, args); |
| 3247 | } catch (RemoteException e) { |
| 3248 | p.println("Input method service dead: " + e); |
| 3249 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3250 | } else { |
| 3251 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | } |
| 3253 | } |
| 3254 | } |