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