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