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