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