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 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 18 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 22 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 23 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 24 | import com.android.internal.annotations.GuardedBy; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 25 | import com.android.internal.content.PackageMonitor; |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 26 | import com.android.internal.inputmethod.IInputContentUriToken; |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 27 | import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController; |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 28 | import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 29 | import com.android.internal.inputmethod.InputMethodUtils; |
| 30 | import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings; |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 31 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 32 | import com.android.internal.notification.SystemNotificationChannels; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import com.android.internal.os.HandlerCaller; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 34 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 35 | import com.android.internal.os.TransferPipe; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 36 | import com.android.internal.util.DumpUtils; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 37 | import com.android.internal.util.FastXmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import com.android.internal.view.IInputContext; |
| 39 | import com.android.internal.view.IInputMethod; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import com.android.internal.view.IInputMethodClient; |
| 41 | import com.android.internal.view.IInputMethodManager; |
| 42 | import com.android.internal.view.IInputMethodSession; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 43 | import com.android.internal.view.IInputSessionCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import com.android.internal.view.InputBindResult; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 45 | import com.android.internal.view.InputMethodClient; |
Adam Lesinski | ef2ea1f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 46 | import com.android.server.statusbar.StatusBarManagerService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 48 | import org.xmlpull.v1.XmlPullParser; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import org.xmlpull.v1.XmlPullParserException; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 50 | import org.xmlpull.v1.XmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 52 | import android.annotation.BinderThread; |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 53 | import android.annotation.ColorInt; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 54 | import android.annotation.IntDef; |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 55 | import android.annotation.MainThread; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 56 | import android.annotation.NonNull; |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 57 | import android.annotation.Nullable; |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 58 | import android.annotation.UserIdInt; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 59 | import android.app.ActivityManager; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 60 | import android.app.ActivityManagerInternal; |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 61 | import android.app.ActivityThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.app.AlertDialog; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 63 | import android.app.AppGlobals; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 64 | import android.app.AppOpsManager; |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame] | 65 | import android.app.KeyguardManager; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 66 | import android.app.Notification; |
| 67 | import android.app.NotificationManager; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 68 | import android.app.PendingIntent; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 69 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.content.ComponentName; |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 71 | import android.content.ContentProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.content.ContentResolver; |
| 73 | import android.content.Context; |
| 74 | import android.content.DialogInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.content.DialogInterface.OnCancelListener; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 76 | import android.content.DialogInterface.OnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.content.Intent; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 78 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 80 | import android.content.pm.ApplicationInfo; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 81 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.content.pm.PackageManager; |
| 83 | import android.content.pm.ResolveInfo; |
| 84 | import android.content.pm.ServiceInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 85 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.content.res.Resources; |
| 87 | import android.content.res.TypedArray; |
| 88 | import android.database.ContentObserver; |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 89 | import android.graphics.drawable.Drawable; |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 90 | import android.hardware.input.InputManagerInternal; |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 91 | import android.inputmethodservice.InputMethodService; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 92 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import android.os.Binder; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 94 | import android.os.Bundle; |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 95 | import android.os.Debug; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 96 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.os.Handler; |
| 98 | import android.os.IBinder; |
| 99 | import android.os.IInterface; |
| 100 | import android.os.Message; |
Yohei Yukawa | 23cbe85 | 2016-05-17 16:42:58 -0700 | [diff] [blame] | 101 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | import android.os.Parcel; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 103 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 105 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.os.ServiceManager; |
| 107 | import android.os.SystemClock; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 108 | import android.os.UserHandle; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 109 | import android.os.UserManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.provider.Settings; |
| 111 | import android.text.TextUtils; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 112 | import android.text.style.SuggestionSpan; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 113 | import android.util.ArrayMap; |
| 114 | import android.util.ArraySet; |
Dianne Hackborn | 39606a0 | 2012-07-31 17:54:35 -0700 | [diff] [blame] | 115 | import android.util.AtomicFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.util.EventLog; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 117 | import android.util.LruCache; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 118 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | import android.util.PrintWriterPrinter; |
| 120 | import android.util.Printer; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 121 | import android.util.Slog; |
| 122 | import android.util.Xml; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 123 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import android.view.IWindowManager; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 125 | import android.view.InputChannel; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 126 | import android.view.LayoutInflater; |
| 127 | import android.view.View; |
| 128 | import android.view.ViewGroup; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 129 | import android.view.Window; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import android.view.WindowManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 131 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | import android.view.inputmethod.InputBinding; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 133 | import android.view.inputmethod.InputConnection; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 134 | import android.view.inputmethod.InputConnectionInspector; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import android.view.inputmethod.InputMethod; |
| 136 | import android.view.inputmethod.InputMethodInfo; |
| 137 | import android.view.inputmethod.InputMethodManager; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 138 | import android.view.inputmethod.InputMethodManagerInternal; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 139 | import android.view.inputmethod.InputMethodSubtype; |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 140 | import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 141 | import android.widget.ArrayAdapter; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 142 | import android.widget.CompoundButton; |
| 143 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 144 | import android.widget.RadioButton; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 145 | import android.widget.Switch; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 146 | import android.widget.TextView; |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 147 | import android.widget.Toast; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 149 | import com.android.server.wm.WindowManagerInternal; |
| 150 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 151 | import java.io.File; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | import java.io.FileDescriptor; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 153 | import java.io.FileInputStream; |
| 154 | import java.io.FileOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | import java.io.IOException; |
| 156 | import java.io.PrintWriter; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 157 | import java.lang.annotation.Retention; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 158 | import java.nio.charset.StandardCharsets; |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 159 | import java.security.InvalidParameterException; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 160 | import java.text.SimpleDateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | import java.util.ArrayList; |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 162 | import java.util.Collections; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 163 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | import java.util.HashMap; |
| 165 | import java.util.List; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 166 | import java.util.Locale; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 167 | import java.util.WeakHashMap; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 168 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * This class provides a system service that manages input methods. |
| 172 | */ |
| 173 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 174 | implements ServiceConnection, Handler.Callback { |
| 175 | static final boolean DEBUG = false; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 176 | static final boolean DEBUG_RESTORE = DEBUG || false; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 177 | static final String TAG = "InputMethodManagerService"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | |
Seigo Nonaka | d4474cb | 2015-05-04 16:53:24 -0700 | [diff] [blame] | 179 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 1; |
| 180 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 2; |
| 181 | static final int MSG_SHOW_IM_CONFIG = 3; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | static final int MSG_UNBIND_INPUT = 1000; |
| 184 | static final int MSG_BIND_INPUT = 1010; |
| 185 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 186 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 187 | static final int MSG_HIDE_CURRENT_INPUT_METHOD = 1035; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | static final int MSG_ATTACH_TOKEN = 1040; |
| 189 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | static final int MSG_START_INPUT = 2000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 192 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 193 | static final int MSG_UNBIND_CLIENT = 3000; |
| 194 | static final int MSG_BIND_CLIENT = 3010; |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 195 | static final int MSG_SET_ACTIVE = 3020; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 196 | static final int MSG_SET_INTERACTIVE = 3030; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 197 | static final int MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER = 3040; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 198 | static final int MSG_REPORT_FULLSCREEN_MODE = 3045; |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 199 | static final int MSG_SWITCH_IME = 3050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 200 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 201 | static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000; |
| 202 | |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 203 | static final int MSG_SYSTEM_UNLOCK_USER = 5000; |
| 204 | |
Satoshi Kataoka | bcacc32 | 2013-10-21 17:57:27 -0700 | [diff] [blame] | 205 | static final long TIME_TO_RECONNECT = 3 * 1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 206 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 207 | static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20; |
| 208 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 209 | private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID; |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 210 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 211 | |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 212 | /** |
| 213 | * Binding flags for establishing connection to the {@link InputMethodService}. |
| 214 | */ |
| 215 | private static final int IME_CONNECTION_BIND_FLAGS = |
| 216 | Context.BIND_AUTO_CREATE |
| 217 | | Context.BIND_NOT_VISIBLE |
| 218 | | Context.BIND_NOT_FOREGROUND |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 219 | | Context.BIND_IMPORTANT_BACKGROUND; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * Binding flags used only while the {@link InputMethodService} is showing window. |
| 223 | */ |
| 224 | private static final int IME_VISIBLE_BIND_FLAGS = |
| 225 | Context.BIND_AUTO_CREATE |
| 226 | | Context.BIND_TREAT_LIKE_ACTIVITY |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 227 | | Context.BIND_FOREGROUND_SERVICE |
| 228 | | Context.BIND_SHOWING_UI; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 229 | |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 230 | @Retention(SOURCE) |
| 231 | @IntDef({HardKeyboardBehavior.WIRELESS_AFFORDANCE, HardKeyboardBehavior.WIRED_AFFORDANCE}) |
| 232 | private @interface HardKeyboardBehavior { |
| 233 | int WIRELESS_AFFORDANCE = 0; |
| 234 | int WIRED_AFFORDANCE = 1; |
| 235 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 236 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 237 | /** |
| 238 | * A protected broadcast intent action for internal use for {@link PendingIntent} in |
| 239 | * the notification. |
| 240 | */ |
| 241 | private static final String ACTION_SHOW_INPUT_METHOD_PICKER = |
| 242 | "com.android.server.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER"; |
| 243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | final Context mContext; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 245 | final Resources mRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 247 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | final SettingsObserver mSettingsObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | final IWindowManager mIWindowManager; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 250 | final WindowManagerInternal mWindowManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | final HandlerCaller mCaller; |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 252 | final boolean mHasFeature; |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 253 | private InputMethodFileManager mFileManager; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 254 | private final HardKeyboardListener mHardKeyboardListener; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 255 | private final AppOpsManager mAppOpsManager; |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 256 | private final UserManager mUserManager; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 257 | |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 258 | final InputBindResult mNoBinding = new InputBindResult(null, null, null, -1, -1); |
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 | // All known input methods. mMethodMap also serves as the global |
| 261 | // lock for this class. |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 262 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>(); |
| 263 | final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<>(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 264 | private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 265 | new LruCache<>(SECURE_SUGGESTION_SPANS_MAX_SIZE); |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 266 | private final InputMethodSubtypeSwitchingController mSwitchingController; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 267 | |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 268 | /** |
| 269 | * Tracks how many times {@link #mMethodMap} was updated. |
| 270 | */ |
| 271 | @GuardedBy("mMethodMap") |
| 272 | private int mMethodMapUpdateCount = 0; |
| 273 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 274 | // Used to bring IME service up to visible adjustment while it is being shown. |
| 275 | final ServiceConnection mVisibleConnection = new ServiceConnection() { |
| 276 | @Override public void onServiceConnected(ComponentName name, IBinder service) { |
| 277 | } |
| 278 | |
| 279 | @Override public void onServiceDisconnected(ComponentName name) { |
| 280 | } |
| 281 | }; |
| 282 | boolean mVisibleBound = false; |
| 283 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 284 | // Ongoing notification |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 285 | private NotificationManager mNotificationManager; |
| 286 | private KeyguardManager mKeyguardManager; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 287 | private @Nullable StatusBarManagerService mStatusBar; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 288 | private Notification.Builder mImeSwitcherNotification; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 289 | private PendingIntent mImeSwitchPendingIntent; |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 290 | private boolean mShowOngoingImeSwitcherForPhones; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 291 | private boolean mNotificationShown; |
| 292 | |
Tadashi G. Takaoka | 8c6d477 | 2014-08-05 15:29:17 +0900 | [diff] [blame] | 293 | static class SessionState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | final ClientState client; |
| 295 | final IInputMethod method; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 296 | |
| 297 | IInputMethodSession session; |
| 298 | InputChannel channel; |
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 | @Override |
| 301 | public String toString() { |
| 302 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 303 | + " method " + Integer.toHexString( |
| 304 | System.identityHashCode(method)) |
| 305 | + " session " + Integer.toHexString( |
| 306 | System.identityHashCode(session)) |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 307 | + " channel " + channel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | + "}"; |
| 309 | } |
| 310 | |
| 311 | SessionState(ClientState _client, IInputMethod _method, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 312 | IInputMethodSession _session, InputChannel _channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | client = _client; |
| 314 | method = _method; |
| 315 | session = _session; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 316 | channel = _channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | } |
| 318 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 319 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 320 | static final class ClientState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | final IInputMethodClient client; |
| 322 | final IInputContext inputContext; |
| 323 | final int uid; |
| 324 | final int pid; |
| 325 | final InputBinding binding; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | boolean sessionRequested; |
| 328 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | @Override |
| 331 | public String toString() { |
| 332 | return "ClientState{" + Integer.toHexString( |
| 333 | System.identityHashCode(this)) + " uid " + uid |
| 334 | + " pid " + pid + "}"; |
| 335 | } |
| 336 | |
| 337 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
| 338 | int _uid, int _pid) { |
| 339 | client = _client; |
| 340 | inputContext = _inputContext; |
| 341 | uid = _uid; |
| 342 | pid = _pid; |
| 343 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
| 344 | } |
| 345 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 346 | |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 347 | final HashMap<IBinder, ClientState> mClients = new HashMap<>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 350 | * Set once the system is ready to run third party code. |
| 351 | */ |
| 352 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 353 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 354 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 355 | * Id obtained with {@link InputMethodInfo#getId()} for the currently selected input method. |
| 356 | * method. This is to be synchronized with the secure settings keyed with |
| 357 | * {@link Settings.Secure#DEFAULT_INPUT_METHOD}. |
| 358 | * |
| 359 | * <p>This can be transiently {@code null} when the system is re-initializing input method |
| 360 | * settings, e.g., the system locale is just changed.</p> |
| 361 | * |
| 362 | * <p>Note that {@link #mCurId} is used to track which IME is being connected to |
| 363 | * {@link InputMethodManagerService}.</p> |
| 364 | * |
| 365 | * @see #mCurId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 367 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | String mCurMethodId; |
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 | * The current binding sequence number, incremented every time there is |
| 372 | * a new bind performed. |
| 373 | */ |
| 374 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | /** |
| 377 | * The client that is currently bound to an input method. |
| 378 | */ |
| 379 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | /** |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 382 | * The last window token that we confirmed to be focused. This is always updated upon reports |
| 383 | * from the input method client. If the window state is already changed before the report is |
| 384 | * handled, this field just keeps the last value. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 385 | */ |
| 386 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 387 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 388 | /** |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 389 | * {@link WindowManager.LayoutParams#softInputMode} of {@link #mCurFocusedWindow}. |
| 390 | * |
| 391 | * @see #mCurFocusedWindow |
| 392 | */ |
| 393 | int mCurFocusedWindowSoftInputMode; |
| 394 | |
| 395 | /** |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 396 | * The client by which {@link #mCurFocusedWindow} was reported. Used only for debugging. |
| 397 | */ |
| 398 | ClientState mCurFocusedWindowClient; |
| 399 | |
| 400 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | * The input context last provided by the current client. |
| 402 | */ |
| 403 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | /** |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 406 | * The missing method flags for the input context last provided by the current client. |
| 407 | * |
| 408 | * @see android.view.inputmethod.InputConnectionInspector.MissingMethodFlags |
| 409 | */ |
| 410 | int mCurInputContextMissingMethods; |
| 411 | |
| 412 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | * The attributes last provided by the current client. |
| 414 | */ |
| 415 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 418 | * 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] | 419 | * connected to or in the process of connecting to. |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 420 | * |
| 421 | * <p>This can be {@code null} when no input method is connected.</p> |
| 422 | * |
| 423 | * @see #mCurMethodId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 425 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | String mCurId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 429 | * The current subtype of the current input method. |
| 430 | */ |
| 431 | private InputMethodSubtype mCurrentSubtype; |
| 432 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 433 | // This list contains the pairs of InputMethodInfo and InputMethodSubtype. |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 434 | private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>> |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 435 | mShortcutInputMethodsAndSubtypes = new HashMap<>(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 436 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 437 | // Was the keyguard locked when this client became current? |
| 438 | private boolean mCurClientInKeyguard; |
| 439 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 440 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | * Set to true if our ServiceConnection is currently actively bound to |
| 442 | * a service (whether or not we have gotten its IBinder back yet). |
| 443 | */ |
| 444 | boolean mHaveConnection; |
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 | /** |
| 447 | * Set if the client has asked for the input method to be shown. |
| 448 | */ |
| 449 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | /** |
| 452 | * Set if we were explicitly told to show the input method. |
| 453 | */ |
| 454 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | /** |
| 457 | * Set if we were forced to be shown. |
| 458 | */ |
| 459 | boolean mShowForced; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | /** |
| 462 | * Set if we last told the input method to show itself. |
| 463 | */ |
| 464 | boolean mInputShown; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | /** |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 467 | * {@code true} if the current input method is in fullscreen mode. |
| 468 | */ |
| 469 | boolean mInFullscreenMode; |
| 470 | |
| 471 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | * The Intent used to connect to the current input method. |
| 473 | */ |
| 474 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | /** |
| 477 | * The token we have made for the currently active input method, to |
| 478 | * identify it in the future. |
| 479 | */ |
| 480 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | /** |
| 483 | * If non-null, this is the input method service we are currently connected |
| 484 | * to. |
| 485 | */ |
| 486 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | /** |
| 489 | * Time that we last initiated a bind to the input method, to determine |
| 490 | * if we should try to disconnect and reconnect to it. |
| 491 | */ |
| 492 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | /** |
| 495 | * Have we called mCurMethod.bindInput()? |
| 496 | */ |
| 497 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | /** |
| 500 | * Currently enabled session. Only touched by service thread, not |
| 501 | * protected by a lock. |
| 502 | */ |
| 503 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | /** |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 506 | * 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] | 507 | */ |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 508 | boolean mIsInteractive = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 509 | |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 510 | int mCurUserActionNotificationSequenceNumber = 0; |
| 511 | |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 512 | int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 513 | |
| 514 | /** |
| 515 | * A set of status bits regarding the active IME. |
| 516 | * |
| 517 | * <p>This value is a combination of following two bits:</p> |
| 518 | * <dl> |
| 519 | * <dt>{@link InputMethodService#IME_ACTIVE}</dt> |
| 520 | * <dd> |
| 521 | * If this bit is ON, connected IME is ready to accept touch/key events. |
| 522 | * </dd> |
| 523 | * <dt>{@link InputMethodService#IME_VISIBLE}</dt> |
| 524 | * <dd> |
| 525 | * If this bit is ON, some of IME view, e.g. software input, candidate view, is visible. |
| 526 | * </dd> |
| 527 | * </dl> |
| 528 | * <em>Do not update this value outside of setImeWindowStatus.</em> |
| 529 | */ |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 530 | int mImeWindowVis; |
| 531 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 532 | private AlertDialog.Builder mDialogBuilder; |
| 533 | private AlertDialog mSwitchingDialog; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 534 | private IBinder mSwitchingDialogToken = new Binder(); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 535 | private View mSwitchingDialogTitleView; |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 536 | private Toast mSubtypeSwitchedByShortCutToast; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 537 | private InputMethodInfo[] mIms; |
| 538 | private int[] mSubtypeIds; |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 539 | private LocaleList mLastSystemLocales; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 540 | private boolean mShowImeWithHardKeyboard; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 541 | private boolean mAccessibilityRequestingNoSoftKeyboard; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 542 | private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor(); |
| 543 | private final IPackageManager mIPackageManager; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 544 | private final String mSlotIme; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 545 | @HardKeyboardBehavior |
| 546 | private final int mHardKeyboardBehavior; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 547 | |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 548 | /** |
| 549 | * Internal state snapshot when {@link #MSG_START_INPUT} message is about to be posted to the |
| 550 | * internal message queue. Any subsequent state change inside {@link InputMethodManagerService} |
| 551 | * will not affect those tasks that are already posted. |
| 552 | * |
| 553 | * <p>Posting {@link #MSG_START_INPUT} message basically means that |
| 554 | * {@link InputMethodService#doStartInput(InputConnection, EditorInfo, boolean)} will be called |
| 555 | * back in the current IME process shortly, which will also affect what the current IME starts |
| 556 | * receiving from {@link InputMethodService#getCurrentInputConnection()}. In other words, this |
| 557 | * snapshot will be taken every time when {@link InputMethodManagerService} is initiating a new |
| 558 | * logical input session between the client application and the current IME.</p> |
| 559 | * |
| 560 | * <p>Be careful to not keep strong references to this object forever, which can prevent |
| 561 | * {@link StartInputInfo#mImeToken} and {@link StartInputInfo#mTargetWindow} from being GC-ed. |
| 562 | * </p> |
| 563 | */ |
| 564 | private static class StartInputInfo { |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 565 | private static final AtomicInteger sSequenceNumber = new AtomicInteger(0); |
| 566 | |
| 567 | final int mSequenceNumber; |
| 568 | final long mTimestamp; |
| 569 | final long mWallTime; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 570 | @NonNull |
| 571 | final IBinder mImeToken; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 572 | @NonNull |
| 573 | final String mImeId; |
| 574 | // @InputMethodClient.StartInputReason |
| 575 | final int mStartInputReason; |
| 576 | final boolean mRestarting; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 577 | @Nullable |
| 578 | final IBinder mTargetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 579 | @NonNull |
| 580 | final EditorInfo mEditorInfo; |
| 581 | final int mTargetWindowSoftInputMode; |
| 582 | final int mClientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 583 | |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 584 | StartInputInfo(@NonNull IBinder imeToken, @NonNull String imeId, |
| 585 | /* @InputMethodClient.StartInputReason */ int startInputReason, boolean restarting, |
| 586 | @Nullable IBinder targetWindow, @NonNull EditorInfo editorInfo, |
| 587 | int targetWindowSoftInputMode, int clientBindSequenceNumber) { |
| 588 | mSequenceNumber = sSequenceNumber.getAndIncrement(); |
| 589 | mTimestamp = SystemClock.uptimeMillis(); |
| 590 | mWallTime = System.currentTimeMillis(); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 591 | mImeToken = imeToken; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 592 | mImeId = imeId; |
| 593 | mStartInputReason = startInputReason; |
| 594 | mRestarting = restarting; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 595 | mTargetWindow = targetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 596 | mEditorInfo = editorInfo; |
| 597 | mTargetWindowSoftInputMode = targetWindowSoftInputMode; |
| 598 | mClientBindSequenceNumber = clientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Yohei Yukawa | b37d8bd | 2017-02-13 18:29:05 -0800 | [diff] [blame] | 602 | @GuardedBy("mMethodMap") |
| 603 | private final WeakHashMap<IBinder, StartInputInfo> mStartInputMap = new WeakHashMap<>(); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 604 | |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 605 | /** |
| 606 | * A ring buffer to store the history of {@link StartInputInfo}. |
| 607 | */ |
| 608 | private static final class StartInputHistory { |
| 609 | /** |
| 610 | * Entry size for non low-RAM devices. |
| 611 | * |
| 612 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 613 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 614 | */ |
| 615 | private final static int ENTRY_SIZE_FOR_HIGH_RAM_DEVICE = 16; |
| 616 | |
| 617 | /** |
| 618 | * Entry size for non low-RAM devices. |
| 619 | * |
| 620 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 621 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 622 | */ |
| 623 | private final static int ENTRY_SIZE_FOR_LOW_RAM_DEVICE = 5; |
| 624 | |
| 625 | private static int getEntrySize() { |
| 626 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 627 | return ENTRY_SIZE_FOR_LOW_RAM_DEVICE; |
| 628 | } else { |
| 629 | return ENTRY_SIZE_FOR_HIGH_RAM_DEVICE; |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Backing store for the ring bugger. |
| 635 | */ |
| 636 | private final Entry[] mEntries = new Entry[getEntrySize()]; |
| 637 | |
| 638 | /** |
| 639 | * An index of {@link #mEntries}, to which next {@link #addEntry(StartInputInfo)} should |
| 640 | * write. |
| 641 | */ |
| 642 | private int mNextIndex = 0; |
| 643 | |
| 644 | /** |
| 645 | * Recyclable entry to store the information in {@link StartInputInfo}. |
| 646 | */ |
| 647 | private static final class Entry { |
| 648 | int mSequenceNumber; |
| 649 | long mTimestamp; |
| 650 | long mWallTime; |
| 651 | @NonNull |
| 652 | String mImeTokenString; |
| 653 | @NonNull |
| 654 | String mImeId; |
| 655 | /* @InputMethodClient.StartInputReason */ |
| 656 | int mStartInputReason; |
| 657 | boolean mRestarting; |
| 658 | @NonNull |
| 659 | String mTargetWindowString; |
| 660 | @NonNull |
| 661 | EditorInfo mEditorInfo; |
| 662 | int mTargetWindowSoftInputMode; |
| 663 | int mClientBindSequenceNumber; |
| 664 | |
| 665 | Entry(@NonNull StartInputInfo original) { |
| 666 | set(original); |
| 667 | } |
| 668 | |
| 669 | void set(@NonNull StartInputInfo original) { |
| 670 | mSequenceNumber = original.mSequenceNumber; |
| 671 | mTimestamp = original.mTimestamp; |
| 672 | mWallTime = original.mWallTime; |
| 673 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 674 | // object. |
| 675 | mImeTokenString = String.valueOf(original.mImeToken); |
| 676 | mImeId = original.mImeId; |
| 677 | mStartInputReason = original.mStartInputReason; |
| 678 | mRestarting = original.mRestarting; |
| 679 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 680 | // object. |
| 681 | mTargetWindowString = String.valueOf(original.mTargetWindow); |
| 682 | mEditorInfo = original.mEditorInfo; |
| 683 | mTargetWindowSoftInputMode = original.mTargetWindowSoftInputMode; |
| 684 | mClientBindSequenceNumber = original.mClientBindSequenceNumber; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * Add a new entry and discard the oldest entry as needed. |
| 690 | * @param info {@lin StartInputInfo} to be added. |
| 691 | */ |
| 692 | void addEntry(@NonNull StartInputInfo info) { |
| 693 | final int index = mNextIndex; |
| 694 | if (mEntries[index] == null) { |
| 695 | mEntries[index] = new Entry(info); |
| 696 | } else { |
| 697 | mEntries[index].set(info); |
| 698 | } |
| 699 | mNextIndex = (mNextIndex + 1) % mEntries.length; |
| 700 | } |
| 701 | |
| 702 | void dump(@NonNull PrintWriter pw, @NonNull String prefix) { |
| 703 | final SimpleDateFormat dataFormat = |
| 704 | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US); |
| 705 | |
| 706 | for (int i = 0; i < mEntries.length; ++i) { |
| 707 | final Entry entry = mEntries[(i + mNextIndex) % mEntries.length]; |
| 708 | if (entry == null) { |
| 709 | continue; |
| 710 | } |
| 711 | pw.print(prefix); |
| 712 | pw.println("StartInput #" + entry.mSequenceNumber + ":"); |
| 713 | |
| 714 | pw.print(prefix); |
| 715 | pw.println(" time=" + dataFormat.format(new Date(entry.mWallTime)) |
| 716 | + " (timestamp=" + entry.mTimestamp + ")" |
| 717 | + " reason=" |
| 718 | + InputMethodClient.getStartInputReason(entry.mStartInputReason) |
| 719 | + " restarting=" + entry.mRestarting); |
| 720 | |
| 721 | pw.print(prefix); |
| 722 | pw.println(" imeToken=" + entry.mImeTokenString + " [" + entry.mImeId + "]"); |
| 723 | |
| 724 | pw.print(prefix); |
| 725 | pw.println(" targetWin=" + entry.mTargetWindowString |
| 726 | + " [" + entry.mEditorInfo.packageName + "]" |
| 727 | + " clientBindSeq=" + entry.mClientBindSequenceNumber); |
| 728 | |
| 729 | pw.print(prefix); |
| 730 | pw.println(" softInputMode=" + InputMethodClient.softInputModeToString( |
| 731 | entry.mTargetWindowSoftInputMode)); |
| 732 | |
| 733 | pw.print(prefix); |
| 734 | pw.println(" inputType=0x" + Integer.toHexString(entry.mEditorInfo.inputType) |
| 735 | + " imeOptions=0x" + Integer.toHexString(entry.mEditorInfo.imeOptions) |
| 736 | + " fieldId=0x" + Integer.toHexString(entry.mEditorInfo.fieldId) |
| 737 | + " fieldName=" + entry.mEditorInfo.fieldName |
| 738 | + " actionId=" + entry.mEditorInfo.actionId |
| 739 | + " actionLabel=" + entry.mEditorInfo.actionLabel); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | @GuardedBy("mMethodMap") |
| 745 | @NonNull |
| 746 | private final StartInputHistory mStartInputHistory = new StartInputHistory(); |
| 747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | class SettingsObserver extends ContentObserver { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 749 | int mUserId; |
| 750 | boolean mRegistered = false; |
Yohei Yukawa | 7b574cb | 2016-03-16 17:22:22 -0700 | [diff] [blame] | 751 | @NonNull |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 752 | String mLastEnabled = ""; |
| 753 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 754 | /** |
| 755 | * <em>This constructor must be called within the lock.</em> |
| 756 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | SettingsObserver(Handler handler) { |
| 758 | super(handler); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 761 | public void registerContentObserverLocked(@UserIdInt int userId) { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 762 | if (mRegistered && mUserId == userId) { |
| 763 | return; |
| 764 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | ContentResolver resolver = mContext.getContentResolver(); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 766 | if (mRegistered) { |
| 767 | mContext.getContentResolver().unregisterContentObserver(this); |
| 768 | mRegistered = false; |
| 769 | } |
| 770 | if (mUserId != userId) { |
| 771 | mLastEnabled = ""; |
| 772 | mUserId = userId; |
| 773 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 775 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, userId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 776 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 777 | Settings.Secure.ENABLED_INPUT_METHODS), false, this, userId); |
satok | b6109bb | 2011-02-03 22:24:54 +0900 | [diff] [blame] | 778 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 779 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this, userId); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 780 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 781 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this, userId); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 782 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 783 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE), false, this, userId); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 784 | mRegistered = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 786 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 787 | @Override public void onChange(boolean selfChange, Uri uri) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 788 | final Uri showImeUri = Settings.Secure.getUriFor( |
| 789 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
| 790 | final Uri accessibilityRequestingNoImeUri = Settings.Secure.getUriFor( |
| 791 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | synchronized (mMethodMap) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 793 | if (showImeUri.equals(uri)) { |
| 794 | updateKeyboardFromSettingsLocked(); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 795 | } else if (accessibilityRequestingNoImeUri.equals(uri)) { |
| 796 | mAccessibilityRequestingNoSoftKeyboard = Settings.Secure.getIntForUser( |
| 797 | mContext.getContentResolver(), |
| 798 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, |
| 799 | 0, mUserId) == 1; |
| 800 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 801 | final boolean showRequested = mShowRequested; |
| 802 | hideCurrentInputLocked(0, null); |
| 803 | mShowRequested = showRequested; |
| 804 | } else if (mShowRequested) { |
| 805 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 806 | } |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 807 | } else { |
| 808 | boolean enabledChanged = false; |
| 809 | String newEnabled = mSettings.getEnabledInputMethodsStr(); |
| 810 | if (!mLastEnabled.equals(newEnabled)) { |
| 811 | mLastEnabled = newEnabled; |
| 812 | enabledChanged = true; |
| 813 | } |
| 814 | updateInputMethodsFromSettingsLocked(enabledChanged); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 815 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | } |
| 817 | } |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 818 | |
| 819 | @Override |
| 820 | public String toString() { |
| 821 | return "SettingsObserver{mUserId=" + mUserId + " mRegistered=" + mRegistered |
| 822 | + " mLastEnabled=" + mLastEnabled + "}"; |
| 823 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 825 | |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 826 | class ImmsBroadcastReceiver extends BroadcastReceiver { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 827 | @Override |
| 828 | public void onReceive(Context context, Intent intent) { |
| 829 | final String action = intent.getAction(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 830 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 831 | hideInputMethodMenu(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 832 | // No need to update mIsInteractive |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 833 | return; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 834 | } else if (Intent.ACTION_USER_ADDED.equals(action) |
| 835 | || Intent.ACTION_USER_REMOVED.equals(action)) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 836 | updateCurrentProfileIds(); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 837 | return; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 838 | } else if (Intent.ACTION_SETTING_RESTORED.equals(action)) { |
| 839 | final String name = intent.getStringExtra(Intent.EXTRA_SETTING_NAME); |
| 840 | if (Settings.Secure.ENABLED_INPUT_METHODS.equals(name)) { |
| 841 | final String prevValue = intent.getStringExtra( |
| 842 | Intent.EXTRA_SETTING_PREVIOUS_VALUE); |
| 843 | final String newValue = intent.getStringExtra( |
| 844 | Intent.EXTRA_SETTING_NEW_VALUE); |
| 845 | restoreEnabledInputMethods(mContext, prevValue, newValue); |
| 846 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 847 | } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 848 | onActionLocaleChanged(); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 849 | } else if (ACTION_SHOW_INPUT_METHOD_PICKER.equals(action)) { |
| 850 | // ACTION_SHOW_INPUT_METHOD_PICKER action is a protected-broadcast and it is |
| 851 | // guaranteed to be send only from the system, so that there is no need for extra |
| 852 | // security check such as |
| 853 | // {@link #canShowInputMethodPickerLocked(IInputMethodClient)}. |
| 854 | mHandler.obtainMessage( |
| 855 | MSG_SHOW_IM_SUBTYPE_PICKER, |
| 856 | InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES, |
| 857 | 0 /* arg2 */) |
| 858 | .sendToTarget(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 859 | } else { |
| 860 | Slog.w(TAG, "Unexpected intent " + intent); |
| 861 | } |
| 862 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 864 | |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 865 | /** |
| 866 | * Handles {@link Intent#ACTION_LOCALE_CHANGED}. |
| 867 | * |
| 868 | * <p>Note: For historical reasons, {@link Intent#ACTION_LOCALE_CHANGED} has been sent to all |
| 869 | * the users. We should ignore this event if this is about any background user's locale.</p> |
| 870 | * |
| 871 | * <p>Caution: This method must not be called when system is not ready.</p> |
| 872 | */ |
| 873 | void onActionLocaleChanged() { |
| 874 | synchronized (mMethodMap) { |
| 875 | final LocaleList possibleNewLocale = mRes.getConfiguration().getLocales(); |
| 876 | if (possibleNewLocale != null && possibleNewLocale.equals(mLastSystemLocales)) { |
| 877 | return; |
| 878 | } |
| 879 | buildInputMethodListLocked(true); |
| 880 | // If the locale is changed, needs to reset the default ime |
| 881 | resetDefaultImeLocked(mContext); |
| 882 | updateFromSettingsLocked(true); |
| 883 | mLastSystemLocales = possibleNewLocale; |
| 884 | } |
| 885 | } |
| 886 | |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 887 | // Apply the results of a restore operation to the set of enabled IMEs. Note that this |
| 888 | // does not attempt to validate on the fly with any installed device policy, so must only |
| 889 | // be run in the context of initial device setup. |
| 890 | // |
| 891 | // TODO: Move this method to InputMethodUtils with adding unit tests. |
| 892 | static void restoreEnabledInputMethods(Context context, String prevValue, String newValue) { |
| 893 | if (DEBUG_RESTORE) { |
| 894 | Slog.i(TAG, "Restoring enabled input methods:"); |
| 895 | Slog.i(TAG, "prev=" + prevValue); |
| 896 | Slog.i(TAG, " new=" + newValue); |
| 897 | } |
| 898 | // '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] | 899 | ArrayMap<String, ArraySet<String>> prevMap = |
| 900 | InputMethodUtils.parseInputMethodsAndSubtypesString(prevValue); |
| 901 | ArrayMap<String, ArraySet<String>> newMap = |
| 902 | InputMethodUtils.parseInputMethodsAndSubtypesString(newValue); |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 903 | |
| 904 | // Merge the restored ime+subtype enabled states into the live state |
| 905 | for (ArrayMap.Entry<String, ArraySet<String>> entry : newMap.entrySet()) { |
| 906 | final String imeId = entry.getKey(); |
| 907 | ArraySet<String> prevSubtypes = prevMap.get(imeId); |
| 908 | if (prevSubtypes == null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 909 | prevSubtypes = new ArraySet<>(2); |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 910 | prevMap.put(imeId, prevSubtypes); |
| 911 | } |
| 912 | prevSubtypes.addAll(entry.getValue()); |
| 913 | } |
| 914 | |
Seigo Nonaka | 2a099bc | 2015-08-14 19:29:45 -0700 | [diff] [blame] | 915 | final String mergedImesAndSubtypesString = |
| 916 | InputMethodUtils.buildInputMethodsAndSubtypesString(prevMap); |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 917 | if (DEBUG_RESTORE) { |
| 918 | Slog.i(TAG, "Merged IME string:"); |
| 919 | Slog.i(TAG, " " + mergedImesAndSubtypesString); |
| 920 | } |
| 921 | Settings.Secure.putString(context.getContentResolver(), |
| 922 | Settings.Secure.ENABLED_INPUT_METHODS, mergedImesAndSubtypesString); |
| 923 | } |
| 924 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 925 | final class MyPackageMonitor extends PackageMonitor { |
| 926 | /** |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 927 | * Package names that are known to contain {@link InputMethodService}. |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 928 | * |
| 929 | * <p>No need to include packages because of direct-boot unaware IMEs since we always rescan |
| 930 | * all the packages when the user is unlocked, and direct-boot awareness will not be changed |
| 931 | * dynamically unless the entire package is updated, which also always triggers package |
| 932 | * rescanning.</p> |
| 933 | */ |
| 934 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 935 | final private ArraySet<String> mKnownImePackageNames = new ArraySet<>(); |
| 936 | |
| 937 | /** |
| 938 | * Packages that are appeared, disappeared, or modified for whatever reason. |
| 939 | * |
| 940 | * <p>Note: For now we intentionally use {@link ArrayList} instead of {@link ArraySet} |
| 941 | * because 1) the number of elements is almost always 1 or so, and 2) we do not care |
| 942 | * duplicate elements for our use case.</p> |
| 943 | * |
| 944 | * <p>This object must be accessed only from callback methods in {@link PackageMonitor}, |
| 945 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 946 | */ |
| 947 | private final ArrayList<String> mChangedPackages = new ArrayList<>(); |
| 948 | |
| 949 | /** |
| 950 | * {@code true} if one or more packages that contain {@link InputMethodService} appeared. |
| 951 | * |
| 952 | * <p>This field must be accessed only from callback methods in {@link PackageMonitor}, |
| 953 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 954 | */ |
| 955 | private boolean mImePackageAppeared = false; |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 956 | |
| 957 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 958 | void clearKnownImePackageNamesLocked() { |
| 959 | mKnownImePackageNames.clear(); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 963 | final void addKnownImePackageNameLocked(@NonNull String packageName) { |
| 964 | mKnownImePackageNames.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 965 | } |
| 966 | |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 967 | @GuardedBy("mMethodMap") |
| 968 | private boolean isChangingPackagesOfCurrentUserLocked() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 969 | final int userId = getChangingUserId(); |
| 970 | final boolean retval = userId == mSettings.getCurrentUserId(); |
| 971 | if (DEBUG) { |
satok | 81f8b7c | 2012-12-04 20:42:56 +0900 | [diff] [blame] | 972 | if (!retval) { |
| 973 | Slog.d(TAG, "--- ignore this call back from a background user: " + userId); |
| 974 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 975 | } |
| 976 | return retval; |
| 977 | } |
| 978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 980 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 982 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 983 | return false; |
| 984 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 985 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | final int N = mMethodList.size(); |
| 987 | if (curInputMethodId != null) { |
| 988 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 989 | InputMethodInfo imi = mMethodList.get(i); |
| 990 | if (imi.getId().equals(curInputMethodId)) { |
| 991 | for (String pkg : packages) { |
| 992 | if (imi.getPackageName().equals(pkg)) { |
| 993 | if (!doit) { |
| 994 | return true; |
| 995 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 996 | resetSelectedInputMethodAndSubtypeLocked(""); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 997 | chooseNewDefaultIMELocked(); |
| 998 | return true; |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
| 1008 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1009 | public void onBeginPackageChanges() { |
| 1010 | clearPackageChangeState(); |
| 1011 | } |
| 1012 | |
| 1013 | @Override |
| 1014 | public void onPackageAppeared(String packageName, int reason) { |
| 1015 | if (!mImePackageAppeared) { |
| 1016 | final PackageManager pm = mContext.getPackageManager(); |
| 1017 | final List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
| 1018 | new Intent(InputMethod.SERVICE_INTERFACE).setPackage(packageName), |
| 1019 | PackageManager.MATCH_DISABLED_COMPONENTS, getChangingUserId()); |
| 1020 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1021 | if (!services.isEmpty()) { |
| 1022 | mImePackageAppeared = true; |
| 1023 | } |
| 1024 | } |
| 1025 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1026 | mChangedPackages.add(packageName); |
| 1027 | } |
| 1028 | |
| 1029 | @Override |
| 1030 | public void onPackageDisappeared(String packageName, int reason) { |
| 1031 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1032 | mChangedPackages.add(packageName); |
| 1033 | } |
| 1034 | |
| 1035 | @Override |
| 1036 | public void onPackageModified(String packageName) { |
| 1037 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1038 | mChangedPackages.add(packageName); |
| 1039 | } |
| 1040 | |
| 1041 | @Override |
| 1042 | public void onPackagesSuspended(String[] packages) { |
| 1043 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1044 | for (String packageName : packages) { |
| 1045 | mChangedPackages.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1050 | public void onPackagesUnsuspended(String[] packages) { |
| 1051 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1052 | for (String packageName : packages) { |
| 1053 | mChangedPackages.add(packageName); |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | @Override |
| 1058 | public void onFinishPackageChanges() { |
| 1059 | onFinishPackageChangesInternal(); |
| 1060 | clearPackageChangeState(); |
| 1061 | } |
| 1062 | |
| 1063 | private void clearPackageChangeState() { |
| 1064 | // No need to lock them because we access these fields only on getRegisteredHandler(). |
| 1065 | mChangedPackages.clear(); |
| 1066 | mImePackageAppeared = false; |
| 1067 | } |
| 1068 | |
| 1069 | private boolean shouldRebuildInputMethodListLocked() { |
| 1070 | // This method is guaranteed to be called only by getRegisteredHandler(). |
| 1071 | |
| 1072 | // If there is any new package that contains at least one IME, then rebuilt the list |
| 1073 | // of IMEs. |
| 1074 | if (mImePackageAppeared) { |
| 1075 | return true; |
| 1076 | } |
| 1077 | |
| 1078 | // Otherwise, check if mKnownImePackageNames and mChangedPackages have any intersection. |
| 1079 | // TODO: Consider to create a utility method to do the following test. List.retainAll() |
| 1080 | // is an option, but it may still do some extra operations that we do not need here. |
| 1081 | final int N = mChangedPackages.size(); |
| 1082 | for (int i = 0; i < N; ++i) { |
| 1083 | final String packageName = mChangedPackages.get(i); |
| 1084 | if (mKnownImePackageNames.contains(packageName)) { |
| 1085 | return true; |
| 1086 | } |
| 1087 | } |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | private void onFinishPackageChangesInternal() { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1092 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1093 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1094 | return; |
| 1095 | } |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1096 | if (!shouldRebuildInputMethodListLocked()) { |
| 1097 | return; |
| 1098 | } |
| 1099 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1100 | InputMethodInfo curIm = null; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1101 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1102 | final int N = mMethodList.size(); |
| 1103 | if (curInputMethodId != null) { |
| 1104 | for (int i=0; i<N; i++) { |
| 1105 | InputMethodInfo imi = mMethodList.get(i); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1106 | final String imiId = imi.getId(); |
| 1107 | if (imiId.equals(curInputMethodId)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1108 | curIm = imi; |
| 1109 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1110 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1111 | int change = isPackageDisappearing(imi.getPackageName()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1112 | if (isPackageModified(imi.getPackageName())) { |
| 1113 | mFileManager.deleteAllInputMethodSubtypes(imiId); |
| 1114 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1115 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1116 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1117 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1118 | + imi.getComponent()); |
| 1119 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | } |
| 1121 | } |
| 1122 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1123 | |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 1124 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1127 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1128 | if (curIm != null) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1129 | int change = isPackageDisappearing(curIm.getPackageName()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1130 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1131 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1132 | ServiceInfo si = null; |
| 1133 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1134 | si = mIPackageManager.getServiceInfo( |
| 1135 | curIm.getComponent(), 0, mSettings.getCurrentUserId()); |
| 1136 | } catch (RemoteException ex) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1137 | } |
| 1138 | if (si == null) { |
| 1139 | // Uh oh, current input method is no longer around! |
| 1140 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1141 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1142 | updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1143 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1144 | changed = true; |
| 1145 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1146 | Slog.i(TAG, "Unsetting current input method"); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1147 | resetSelectedInputMethodAndSubtypeLocked(""); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1148 | } |
| 1149 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1150 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1151 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1152 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1153 | if (curIm == null) { |
| 1154 | // We currently don't have a default input method... is |
| 1155 | // one now available? |
| 1156 | changed = chooseNewDefaultIMELocked(); |
Yohei Yukawa | 54d512c | 2015-05-19 22:15:02 -0700 | [diff] [blame] | 1157 | } else if (!changed && isPackageModified(curIm.getPackageName())) { |
| 1158 | // Even if the current input method is still available, mCurrentSubtype could |
| 1159 | // be obsolete when the package is modified in practice. |
| 1160 | changed = true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1161 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1162 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1163 | if (changed) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1164 | updateFromSettingsLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | } |
| 1168 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1169 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1170 | private static final class MethodCallback extends IInputSessionCallback.Stub { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1171 | private final InputMethodManagerService mParentIMMS; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1172 | private final IInputMethod mMethod; |
| 1173 | private final InputChannel mChannel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1174 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1175 | MethodCallback(InputMethodManagerService imms, IInputMethod method, |
| 1176 | InputChannel channel) { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1177 | mParentIMMS = imms; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1178 | mMethod = method; |
| 1179 | mChannel = channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1181 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1182 | @Override |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1183 | public void sessionCreated(IInputMethodSession session) { |
Dianne Hackborn | 6b6b3fd | 2014-03-24 11:27:18 -0700 | [diff] [blame] | 1184 | long ident = Binder.clearCallingIdentity(); |
| 1185 | try { |
| 1186 | mParentIMMS.onSessionCreated(mMethod, session, mChannel); |
| 1187 | } finally { |
| 1188 | Binder.restoreCallingIdentity(ident); |
| 1189 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | } |
| 1191 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1192 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1193 | private class HardKeyboardListener |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1194 | implements WindowManagerInternal.OnHardKeyboardStatusChangeListener { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1195 | @Override |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1196 | public void onHardKeyboardStatusChange(boolean available) { |
| 1197 | mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED, |
| 1198 | available ? 1 : 0)); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1199 | } |
| 1200 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1201 | public void handleHardKeyboardStatusChange(boolean available) { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1202 | if (DEBUG) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1203 | Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1204 | } |
| 1205 | synchronized(mMethodMap) { |
| 1206 | if (mSwitchingDialog != null && mSwitchingDialogTitleView != null |
| 1207 | && mSwitchingDialog.isShowing()) { |
| 1208 | mSwitchingDialogTitleView.findViewById( |
| 1209 | com.android.internal.R.id.hard_keyboard_section).setVisibility( |
| 1210 | available ? View.VISIBLE : View.GONE); |
| 1211 | } |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1216 | public static final class Lifecycle extends SystemService { |
| 1217 | private InputMethodManagerService mService; |
| 1218 | |
| 1219 | public Lifecycle(Context context) { |
| 1220 | super(context); |
| 1221 | mService = new InputMethodManagerService(context); |
| 1222 | } |
| 1223 | |
| 1224 | @Override |
| 1225 | public void onStart() { |
| 1226 | LocalServices.addService(InputMethodManagerInternal.class, |
| 1227 | new LocalServiceImpl(mService.mHandler)); |
| 1228 | publishBinderService(Context.INPUT_METHOD_SERVICE, mService); |
| 1229 | } |
| 1230 | |
| 1231 | @Override |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1232 | public void onSwitchUser(@UserIdInt int userHandle) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1233 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1234 | // TODO: Dispatch this to a worker thread as needed. |
| 1235 | mService.onSwitchUser(userHandle); |
| 1236 | } |
| 1237 | |
| 1238 | @Override |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1239 | public void onBootPhase(int phase) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1240 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1241 | // TODO: Dispatch this to a worker thread as needed. |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1242 | if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { |
| 1243 | StatusBarManagerService statusBarService = (StatusBarManagerService) ServiceManager |
| 1244 | .getService(Context.STATUS_BAR_SERVICE); |
| 1245 | mService.systemRunning(statusBarService); |
| 1246 | } |
| 1247 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1248 | |
| 1249 | @Override |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1250 | public void onUnlockUser(final @UserIdInt int userHandle) { |
| 1251 | // Called on ActivityManager thread. |
| 1252 | mService.mHandler.sendMessage(mService.mHandler.obtainMessage(MSG_SYSTEM_UNLOCK_USER, |
Fyodor Kupolov | 0f57cce | 2016-09-09 10:36:30 -0700 | [diff] [blame] | 1253 | userHandle /* arg1 */, 0 /* arg2 */)); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1257 | void onUnlockUser(@UserIdInt int userId) { |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1258 | synchronized(mMethodMap) { |
| 1259 | final int currentUserId = mSettings.getCurrentUserId(); |
| 1260 | if (DEBUG) { |
| 1261 | Slog.d(TAG, "onUnlockUser: userId=" + userId + " curUserId=" + currentUserId); |
| 1262 | } |
| 1263 | if (userId != currentUserId) { |
| 1264 | return; |
| 1265 | } |
| 1266 | mSettings.switchCurrentUser(currentUserId, !mSystemReady); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1267 | if (mSystemReady) { |
| 1268 | // We need to rebuild IMEs. |
| 1269 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
| 1270 | updateInputMethodsFromSettingsLocked(true /* enabledChanged */); |
| 1271 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1272 | } |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1273 | } |
| 1274 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1275 | void onSwitchUser(@UserIdInt int userId) { |
| 1276 | synchronized (mMethodMap) { |
| 1277 | switchUserLocked(userId); |
| 1278 | } |
| 1279 | } |
| 1280 | |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1281 | public InputMethodManagerService(Context context) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1282 | mIPackageManager = AppGlobals.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | mContext = context; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1284 | mRes = context.getResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | mHandler = new Handler(this); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1286 | // Note: SettingsObserver doesn't register observers in its constructor. |
| 1287 | mSettingsObserver = new SettingsObserver(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 1289 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1290 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1291 | mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1292 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | public void executeMessage(Message msg) { |
| 1294 | handleMessage(msg); |
| 1295 | } |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1296 | }, true /*asyncHandler*/); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1297 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1298 | mUserManager = mContext.getSystemService(UserManager.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1299 | mHardKeyboardListener = new HardKeyboardListener(); |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 1300 | mHasFeature = context.getPackageManager().hasSystemFeature( |
| 1301 | PackageManager.FEATURE_INPUT_METHODS); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1302 | mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 1303 | mHardKeyboardBehavior = mContext.getResources().getInteger( |
| 1304 | com.android.internal.R.integer.config_externalHardKeyboardBehavior); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1305 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1306 | Bundle extras = new Bundle(); |
| 1307 | extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1308 | @ColorInt final int accentColor = mContext.getColor( |
| 1309 | com.android.internal.R.color.system_notification_accent_color); |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 1310 | mImeSwitcherNotification = |
| 1311 | new Notification.Builder(mContext, SystemNotificationChannels.VIRTUAL_KEYBOARD) |
| 1312 | .setSmallIcon(com.android.internal.R.drawable.ic_notification_ime_default) |
| 1313 | .setWhen(0) |
| 1314 | .setOngoing(true) |
| 1315 | .addExtras(extras) |
| 1316 | .setCategory(Notification.CATEGORY_SYSTEM) |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1317 | .setColor(accentColor); |
Daniel Sandler | 590d515 | 2012-06-14 16:10:13 -0400 | [diff] [blame] | 1318 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1319 | Intent intent = new Intent(ACTION_SHOW_INPUT_METHOD_PICKER) |
| 1320 | .setPackage(mContext.getPackageName()); |
satok | 683e238 | 2011-07-12 08:28:52 +0900 | [diff] [blame] | 1321 | mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1322 | |
| 1323 | mShowOngoingImeSwitcherForPhones = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1324 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1325 | mNotificationShown = false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1326 | int userId = 0; |
| 1327 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1328 | userId = ActivityManager.getService().getCurrentUser().id; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1329 | } catch (RemoteException e) { |
| 1330 | Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e); |
| 1331 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1332 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1333 | // mSettings should be created before buildInputMethodListLocked |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 1334 | mSettings = new InputMethodSettings( |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1335 | mRes, context.getContentResolver(), mMethodMap, mMethodList, userId, !mSystemReady); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1336 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1337 | updateCurrentProfileIds(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1338 | mFileManager = new InputMethodFileManager(mMethodMap, userId); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1339 | mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked( |
| 1340 | mSettings, context); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1341 | } |
| 1342 | |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1343 | private void resetDefaultImeLocked(Context context) { |
| 1344 | // Do not reset the default (current) IME when it is a 3rd-party IME |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1345 | if (mCurMethodId != null && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) { |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1346 | return; |
| 1347 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1348 | final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes( |
Yohei Yukawa | af5cee8 | 2017-01-23 16:17:11 -0800 | [diff] [blame] | 1349 | context, mSettings.getEnabledInputMethodListLocked()); |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1350 | if (suitableImes.isEmpty()) { |
| 1351 | Slog.i(TAG, "No default found"); |
| 1352 | return; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1353 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1354 | final InputMethodInfo defIm = suitableImes.get(0); |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1355 | if (DEBUG) { |
| 1356 | Slog.i(TAG, "Default found, using " + defIm.getId()); |
| 1357 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1358 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1359 | } |
| 1360 | |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1361 | private void switchUserLocked(int newUserId) { |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1362 | if (DEBUG) Slog.d(TAG, "Switching user stage 1/3. newUserId=" + newUserId |
| 1363 | + " currentUserId=" + mSettings.getCurrentUserId()); |
| 1364 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1365 | // ContentObserver should be registered again when the user is changed |
| 1366 | mSettingsObserver.registerContentObserverLocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1367 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1368 | // If the system is not ready or the device is not yed unlocked by the user, then we use |
| 1369 | // copy-on-write settings. |
| 1370 | final boolean useCopyOnWriteSettings = |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1371 | !mSystemReady || !mUserManager.isUserUnlockingOrUnlocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1372 | mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1373 | updateCurrentProfileIds(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1374 | // InputMethodFileManager should be reset when the user is changed |
| 1375 | mFileManager = new InputMethodFileManager(mMethodMap, newUserId); |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 1376 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1377 | |
| 1378 | if (DEBUG) Slog.d(TAG, "Switching user stage 2/3. newUserId=" + newUserId |
| 1379 | + " defaultImiId=" + defaultImiId); |
| 1380 | |
Satoshi Kataoka | 7c4a2a1 | 2013-02-25 15:25:43 +0900 | [diff] [blame] | 1381 | // For secondary users, the list of enabled IMEs may not have been updated since the |
| 1382 | // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may |
| 1383 | // not be empty even if the IME has been uninstalled by the primary user. |
| 1384 | // Even in such cases, IMMS works fine because it will find the most applicable |
| 1385 | // IME for that user. |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1386 | final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1387 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
| 1388 | |
| 1389 | // TODO: Is it really possible that switchUserLocked() happens before system ready? |
| 1390 | if (mSystemReady) { |
| 1391 | hideCurrentInputLocked(0, null); |
| 1392 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_USER); |
| 1393 | buildInputMethodListLocked(initialUserSwitch); |
| 1394 | if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) { |
| 1395 | // This is the first time of the user switch and |
| 1396 | // set the current ime to the proper one. |
| 1397 | resetDefaultImeLocked(mContext); |
| 1398 | } |
| 1399 | updateFromSettingsLocked(true); |
| 1400 | try { |
| 1401 | startInputInnerLocked(); |
| 1402 | } catch (RuntimeException e) { |
| 1403 | Slog.w(TAG, "Unexpected exception", e); |
| 1404 | } |
| 1405 | } |
| 1406 | |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1407 | if (initialUserSwitch) { |
Yohei Yukawa | 094c71f | 2015-06-20 00:41:31 -0700 | [diff] [blame] | 1408 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1409 | mSettings.getEnabledInputMethodListLocked(), newUserId, |
| 1410 | mContext.getBasePackageName()); |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1411 | } |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1412 | |
| 1413 | if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId |
| 1414 | + " selectedIme=" + mSettings.getSelectedInputMethod()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1415 | } |
| 1416 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1417 | void updateCurrentProfileIds() { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 1418 | mSettings.setCurrentProfileIds( |
| 1419 | mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId())); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1420 | } |
| 1421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1422 | @Override |
| 1423 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1424 | throws RemoteException { |
| 1425 | try { |
| 1426 | return super.onTransact(code, data, reply, flags); |
| 1427 | } catch (RuntimeException e) { |
| 1428 | // The input method manager only throws security exceptions, so let's |
| 1429 | // log all others. |
| 1430 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 164371f | 2013-10-01 19:10:13 -0700 | [diff] [blame] | 1431 | Slog.wtf(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | } |
| 1433 | throw e; |
| 1434 | } |
| 1435 | } |
| 1436 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 1437 | public void systemRunning(StatusBarManagerService statusBar) { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1438 | synchronized (mMethodMap) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1439 | if (DEBUG) { |
| 1440 | Slog.d(TAG, "--- systemReady"); |
| 1441 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1442 | if (!mSystemReady) { |
| 1443 | mSystemReady = true; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1444 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1445 | final int currentUserId = mSettings.getCurrentUserId(); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1446 | mSettings.switchCurrentUser(currentUserId, |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1447 | !mUserManager.isUserUnlockingOrUnlocked(currentUserId)); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1448 | mKeyguardManager = mContext.getSystemService(KeyguardManager.class); |
| 1449 | mNotificationManager = mContext.getSystemService(NotificationManager.class); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1450 | mStatusBar = statusBar; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 1451 | if (mStatusBar != null) { |
| 1452 | mStatusBar.setIconVisibility(mSlotIme, false); |
| 1453 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1454 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1455 | mShowOngoingImeSwitcherForPhones = mRes.getBoolean( |
| 1456 | com.android.internal.R.bool.show_ongoing_ime_switcher); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1457 | if (mShowOngoingImeSwitcherForPhones) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1458 | mWindowManagerInternal.setOnHardKeyboardStatusChangeListener( |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1459 | mHardKeyboardListener); |
| 1460 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1461 | |
| 1462 | mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true); |
| 1463 | mSettingsObserver.registerContentObserverLocked(currentUserId); |
| 1464 | |
| 1465 | final IntentFilter broadcastFilter = new IntentFilter(); |
| 1466 | broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 1467 | broadcastFilter.addAction(Intent.ACTION_USER_ADDED); |
| 1468 | broadcastFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 1469 | broadcastFilter.addAction(Intent.ACTION_SETTING_RESTORED); |
| 1470 | broadcastFilter.addAction(Intent.ACTION_LOCALE_CHANGED); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1471 | broadcastFilter.addAction(ACTION_SHOW_INPUT_METHOD_PICKER); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1472 | mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter); |
| 1473 | |
Yohei Yukawa | 1f9a3cb | 2017-10-26 15:00:59 -0700 | [diff] [blame] | 1474 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
| 1475 | final boolean imeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId); |
| 1476 | buildInputMethodListLocked(!imeSelectedOnBoot /* resetDefaultEnabledIme */); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1477 | resetDefaultImeLocked(mContext); |
| 1478 | updateFromSettingsLocked(true); |
| 1479 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1480 | mSettings.getEnabledInputMethodListLocked(), currentUserId, |
| 1481 | mContext.getBasePackageName()); |
| 1482 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1483 | try { |
| 1484 | startInputInnerLocked(); |
| 1485 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1486 | Slog.w(TAG, "Unexpected exception", e); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1487 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1488 | } |
| 1489 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1490 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1491 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1492 | // --------------------------------------------------------------------------------------- |
| 1493 | // Check whether or not this is a valid IPC. Assumes an IPC is valid when either |
| 1494 | // 1) it comes from the system process |
| 1495 | // 2) the calling process' user id is identical to the current user id IMMS thinks. |
| 1496 | private boolean calledFromValidUser() { |
| 1497 | final int uid = Binder.getCallingUid(); |
| 1498 | final int userId = UserHandle.getUserId(uid); |
| 1499 | if (DEBUG) { |
| 1500 | Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? " |
| 1501 | + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID |
| 1502 | + " calling userId = " + userId + ", foreground user id = " |
Satoshi Kataoka | 87c2914 | 2013-07-31 23:11:54 +0900 | [diff] [blame] | 1503 | + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid() |
| 1504 | + InputMethodUtils.getApiCallStack()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1505 | } |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1506 | if (uid == Process.SYSTEM_UID || mSettings.isCurrentProfile(userId)) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1507 | return true; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1508 | } |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1509 | |
| 1510 | // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the |
| 1511 | // foreground user, not for the user of that process. Accordingly InputMethodManagerService |
| 1512 | // must not manage background users' states in any functions. |
| 1513 | // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded |
| 1514 | // by a token. |
| 1515 | if (mContext.checkCallingOrSelfPermission( |
| 1516 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 1517 | == PackageManager.PERMISSION_GRANTED) { |
| 1518 | if (DEBUG) { |
| 1519 | Slog.d(TAG, "--- Access granted because the calling process has " |
| 1520 | + "the INTERACT_ACROSS_USERS_FULL permission"); |
| 1521 | } |
| 1522 | return true; |
| 1523 | } |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1524 | // TODO(b/34886274): The semantics of this verification is actually not well-defined. |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 1525 | Slog.w(TAG, "--- IPC called from background users. Ignore. callers=" |
| 1526 | + Debug.getCallers(10)); |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1527 | return false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1528 | } |
| 1529 | |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1530 | |
| 1531 | /** |
| 1532 | * Returns true iff the caller is identified to be the current input method with the token. |
| 1533 | * @param token The window token given to the input method when it was started. |
| 1534 | * @return true if and only if non-null valid token is specified. |
| 1535 | */ |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1536 | private boolean calledWithValidToken(@Nullable IBinder token) { |
| 1537 | if (token == null && Binder.getCallingPid() == Process.myPid()) { |
| 1538 | if (DEBUG) { |
| 1539 | // TODO(b/34851776): Basically it's the caller's fault if we reach here. |
| 1540 | Slog.d(TAG, "Bug 34851776 is detected callers=" + Debug.getCallers(10)); |
| 1541 | } |
| 1542 | return false; |
| 1543 | } |
| 1544 | if (token == null || token != mCurToken) { |
| 1545 | // TODO(b/34886274): The semantics of this verification is actually not well-defined. |
| 1546 | Slog.e(TAG, "Ignoring " + Debug.getCaller() + " due to an invalid token." |
| 1547 | + " uid:" + Binder.getCallingUid() + " token:" + token); |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1548 | return false; |
| 1549 | } |
| 1550 | return true; |
| 1551 | } |
| 1552 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1553 | private boolean bindCurrentInputMethodService( |
| 1554 | Intent service, ServiceConnection conn, int flags) { |
| 1555 | if (service == null || conn == null) { |
| 1556 | Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn); |
| 1557 | return false; |
| 1558 | } |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1559 | return mContext.bindServiceAsUser(service, conn, flags, |
| 1560 | new UserHandle(mSettings.getCurrentUserId())); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1561 | } |
| 1562 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1563 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | public List<InputMethodInfo> getInputMethodList() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1565 | // TODO: Make this work even for non-current users? |
| 1566 | if (!calledFromValidUser()) { |
| 1567 | return Collections.emptyList(); |
| 1568 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | synchronized (mMethodMap) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1570 | return new ArrayList<>(mMethodList); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | } |
| 1572 | } |
| 1573 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1574 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | public List<InputMethodInfo> getEnabledInputMethodList() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1576 | // TODO: Make this work even for non-current users? |
| 1577 | if (!calledFromValidUser()) { |
| 1578 | return Collections.emptyList(); |
| 1579 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | synchronized (mMethodMap) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1581 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1585 | /** |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1586 | * @param imiId if null, returns enabled subtypes for the current imi |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1587 | * @return enabled subtypes of the specified imi |
| 1588 | */ |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1589 | @Override |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1590 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId, |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 1591 | boolean allowsImplicitlySelectedSubtypes) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1592 | // TODO: Make this work even for non-current users? |
| 1593 | if (!calledFromValidUser()) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1594 | return Collections.emptyList(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1595 | } |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1596 | synchronized (mMethodMap) { |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1597 | final InputMethodInfo imi; |
| 1598 | if (imiId == null && mCurMethodId != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1599 | imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1600 | } else { |
| 1601 | imi = mMethodMap.get(imiId); |
| 1602 | } |
| 1603 | if (imi == null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1604 | return Collections.emptyList(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1605 | } |
| 1606 | return mSettings.getEnabledInputMethodSubtypeListLocked( |
| 1607 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1611 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1612 | public void addClient(IInputMethodClient client, |
| 1613 | IInputContext inputContext, int uid, int pid) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1614 | if (!calledFromValidUser()) { |
| 1615 | return; |
| 1616 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | synchronized (mMethodMap) { |
| 1618 | mClients.put(client.asBinder(), new ClientState(client, |
| 1619 | inputContext, uid, pid)); |
| 1620 | } |
| 1621 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1622 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1623 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | public void removeClient(IInputMethodClient client) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1625 | if (!calledFromValidUser()) { |
| 1626 | return; |
| 1627 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | synchronized (mMethodMap) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1629 | ClientState cs = mClients.remove(client.asBinder()); |
| 1630 | if (cs != null) { |
| 1631 | clearClientSessionLocked(cs); |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 1632 | if (mCurClient == cs) { |
| 1633 | mCurClient = null; |
| 1634 | } |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 1635 | if (mCurFocusedWindowClient == cs) { |
| 1636 | mCurFocusedWindowClient = null; |
| 1637 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | } |
| 1640 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | void executeOrSendMessage(IInterface target, Message msg) { |
| 1643 | if (target.asBinder() instanceof Binder) { |
| 1644 | mCaller.sendMessage(msg); |
| 1645 | } else { |
| 1646 | handleMessage(msg); |
| 1647 | msg.recycle(); |
| 1648 | } |
| 1649 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1650 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1651 | void unbindCurrentClientLocked( |
| 1652 | /* @InputMethodClient.UnbindReason */ final int unbindClientReason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | if (mCurClient != null) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1654 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | + mCurClient.client.asBinder()); |
| 1656 | if (mBoundToMethod) { |
| 1657 | mBoundToMethod = false; |
| 1658 | if (mCurMethod != null) { |
| 1659 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1660 | MSG_UNBIND_INPUT, mCurMethod)); |
| 1661 | } |
| 1662 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 1663 | |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 1664 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 1665 | MSG_SET_ACTIVE, 0, 0, mCurClient)); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1666 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 1667 | MSG_UNBIND_CLIENT, mCurSeq, unbindClientReason, mCurClient.client)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | mCurClient.sessionRequested = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | mCurClient = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1670 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1671 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | } |
| 1673 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | private int getImeShowFlags() { |
| 1676 | int flags = 0; |
| 1677 | if (mShowForced) { |
| 1678 | flags |= InputMethod.SHOW_FORCED |
| 1679 | | InputMethod.SHOW_EXPLICIT; |
| 1680 | } else if (mShowExplicitlyRequested) { |
| 1681 | flags |= InputMethod.SHOW_EXPLICIT; |
| 1682 | } |
| 1683 | return flags; |
| 1684 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | private int getAppShowFlags() { |
| 1687 | int flags = 0; |
| 1688 | if (mShowForced) { |
| 1689 | flags |= InputMethodManager.SHOW_FORCED; |
| 1690 | } else if (!mShowExplicitlyRequested) { |
| 1691 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 1692 | } |
| 1693 | return flags; |
| 1694 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1695 | |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1696 | InputBindResult attachNewInputLocked( |
| 1697 | /* @InputMethodClient.StartInputReason */ final int startInputReason, boolean initial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | if (!mBoundToMethod) { |
| 1699 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1700 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 1701 | mBoundToMethod = true; |
| 1702 | } |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1703 | |
| 1704 | final Binder startInputToken = new Binder(); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1705 | final StartInputInfo info = new StartInputInfo(mCurToken, mCurId, startInputReason, |
| 1706 | !initial, mCurFocusedWindow, mCurAttribute, mCurFocusedWindowSoftInputMode, |
| 1707 | mCurSeq); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1708 | mStartInputMap.put(startInputToken, info); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1709 | mStartInputHistory.addEntry(info); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | final SessionState session = mCurClient.curSession; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1712 | executeOrSendMessage(session.method, mCaller.obtainMessageIIOOOO( |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 1713 | MSG_START_INPUT, mCurInputContextMissingMethods, initial ? 0 : 1 /* restarting */, |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1714 | startInputToken, session, mCurInputContext, mCurAttribute)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1716 | 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] | 1717 | showCurrentInputLocked(getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | } |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 1719 | return new InputBindResult(session.session, |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1720 | (session.channel != null ? session.channel.dup() : null), |
| 1721 | mCurId, mCurSeq, mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1723 | |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1724 | InputBindResult startInputLocked( |
| 1725 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1726 | IInputMethodClient client, IInputContext inputContext, |
| 1727 | /* @InputConnectionInspector.missingMethods */ final int missingMethods, |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 1728 | @Nullable EditorInfo attribute, int controlFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1729 | // If no method is currently selected, do nothing. |
| 1730 | if (mCurMethodId == null) { |
| 1731 | return mNoBinding; |
| 1732 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1734 | ClientState cs = mClients.get(client.asBinder()); |
| 1735 | if (cs == null) { |
| 1736 | throw new IllegalArgumentException("unknown client " |
| 1737 | + client.asBinder()); |
| 1738 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1739 | |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 1740 | if (attribute == null) { |
| 1741 | Slog.w(TAG, "Ignoring startInput with null EditorInfo." |
| 1742 | + " uid=" + cs.uid + " pid=" + cs.pid); |
| 1743 | return null; |
| 1744 | } |
| 1745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | try { |
| 1747 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 1748 | // Check with the window manager to make sure this client actually |
| 1749 | // has a window with focus. If not, reject. This is thread safe |
| 1750 | // because if the focus changes some time before or after, the |
| 1751 | // next client receiving focus that has any interest in input will |
| 1752 | // be calling through here after that change happens. |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1753 | if (DEBUG) { |
| 1754 | Slog.w(TAG, "Starting input on non-focused client " + cs.client |
| 1755 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 1756 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1757 | return null; |
| 1758 | } |
| 1759 | } catch (RemoteException e) { |
| 1760 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1761 | |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1762 | return startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1763 | controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1764 | } |
| 1765 | |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1766 | InputBindResult startInputUncheckedLocked(@NonNull ClientState cs, IInputContext inputContext, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1767 | /* @InputConnectionInspector.missingMethods */ final int missingMethods, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1768 | @NonNull EditorInfo attribute, int controlFlags, |
| 1769 | /* @InputMethodClient.StartInputReason */ final int startInputReason) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1770 | // If no method is currently selected, do nothing. |
| 1771 | if (mCurMethodId == null) { |
| 1772 | return mNoBinding; |
| 1773 | } |
| 1774 | |
Yohei Yukawa | d57ba67 | 2015-06-08 16:39:46 -0700 | [diff] [blame] | 1775 | if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid, |
| 1776 | attribute.packageName)) { |
| 1777 | Slog.e(TAG, "Rejecting this client as it reported an invalid package name." |
| 1778 | + " uid=" + cs.uid + " package=" + attribute.packageName); |
| 1779 | return mNoBinding; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1782 | if (mCurClient != cs) { |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1783 | // Was the keyguard locked when switching over to the new client? |
| 1784 | mCurClientInKeyguard = isKeyguardLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1785 | // If the client is changing, we need to switch over to the new |
| 1786 | // one. |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1787 | unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_CLIENT); |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1788 | if (DEBUG) Slog.v(TAG, "switching to client: client=" |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1789 | + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | |
| 1791 | // If the screen is on, inform the new client it is active |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 1792 | if (mIsInteractive) { |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 1793 | executeOrSendMessage(cs.client, mCaller.obtainMessageIO( |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 1794 | MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, cs)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1795 | } |
| 1796 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1798 | // Bump up the sequence for this client and attach it. |
| 1799 | mCurSeq++; |
| 1800 | if (mCurSeq <= 0) mCurSeq = 1; |
| 1801 | mCurClient = cs; |
| 1802 | mCurInputContext = inputContext; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1803 | mCurInputContextMissingMethods = missingMethods; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1804 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1806 | // Check if the input method is changing. |
| 1807 | if (mCurId != null && mCurId.equals(mCurMethodId)) { |
| 1808 | if (cs.curSession != null) { |
| 1809 | // Fast case: if we are already connected to the input method, |
| 1810 | // then just return it. |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1811 | return attachNewInputLocked(startInputReason, |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1812 | (controlFlags&InputMethodManager.CONTROL_START_INITIAL) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | } |
| 1814 | if (mHaveConnection) { |
| 1815 | if (mCurMethod != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | // Return to client, and we will get back with it when |
| 1817 | // we have had a session made for it. |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1818 | requestClientSessionLocked(cs); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1819 | return new InputBindResult(null, null, mCurId, mCurSeq, |
| 1820 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | } else if (SystemClock.uptimeMillis() |
| 1822 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 1823 | // In this case we have connected to the service, but |
| 1824 | // don't yet have its interface. If it hasn't been too |
| 1825 | // long since we did the connection, we'll return to |
| 1826 | // the client and wait to get the service interface so |
| 1827 | // we can report back. If it has been too long, we want |
| 1828 | // to fall through so we can try a disconnect/reconnect |
| 1829 | // to see if we can get back in touch with the service. |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1830 | return new InputBindResult(null, null, mCurId, mCurSeq, |
| 1831 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1832 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1833 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 1834 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1835 | } |
| 1836 | } |
| 1837 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1838 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1839 | return startInputInnerLocked(); |
| 1840 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1841 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1842 | InputBindResult startInputInnerLocked() { |
| 1843 | if (mCurMethodId == null) { |
| 1844 | return mNoBinding; |
| 1845 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1846 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1847 | if (!mSystemReady) { |
| 1848 | // If the system is not yet ready, we shouldn't be running third |
| 1849 | // party code. |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1850 | return new InputBindResult(null, null, mCurMethodId, mCurSeq, |
| 1851 | mCurUserActionNotificationSequenceNumber); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1852 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 1855 | if (info == null) { |
| 1856 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 1857 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1858 | |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1859 | unbindCurrentMethodLocked(true); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1860 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1861 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 1862 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1863 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 1864 | com.android.internal.R.string.input_method_binding_label); |
| 1865 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 1866 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 1867 | if (bindCurrentInputMethodService(mCurIntent, this, IME_CONNECTION_BIND_FLAGS)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1868 | mLastBindTime = SystemClock.uptimeMillis(); |
| 1869 | mHaveConnection = true; |
| 1870 | mCurId = info.getId(); |
| 1871 | mCurToken = new Binder(); |
| 1872 | try { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1873 | if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1874 | mIWindowManager.addWindowToken(mCurToken, TYPE_INPUT_METHOD, DEFAULT_DISPLAY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | } catch (RemoteException e) { |
| 1876 | } |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1877 | return new InputBindResult(null, null, mCurId, mCurSeq, |
| 1878 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | } else { |
| 1880 | mCurIntent = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1881 | Slog.w(TAG, "Failure connecting to input method service: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | + mCurIntent); |
| 1883 | } |
| 1884 | return null; |
| 1885 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1886 | |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 1887 | private InputBindResult startInput( |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1888 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1889 | IInputMethodClient client, IInputContext inputContext, |
| 1890 | /* @InputConnectionInspector.missingMethods */ final int missingMethods, |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 1891 | @Nullable EditorInfo attribute, int controlFlags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1892 | if (!calledFromValidUser()) { |
| 1893 | return null; |
| 1894 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1895 | synchronized (mMethodMap) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1896 | if (DEBUG) { |
| 1897 | Slog.v(TAG, "startInput: reason=" |
| 1898 | + InputMethodClient.getStartInputReason(startInputReason) |
| 1899 | + " client = " + client.asBinder() |
| 1900 | + " inputContext=" + inputContext |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1901 | + " missingMethods=" |
| 1902 | + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods) |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1903 | + " attribute=" + attribute |
| 1904 | + " controlFlags=#" + Integer.toHexString(controlFlags)); |
| 1905 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1906 | final long ident = Binder.clearCallingIdentity(); |
| 1907 | try { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1908 | return startInputLocked(startInputReason, client, inputContext, missingMethods, |
| 1909 | attribute, controlFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1910 | } finally { |
| 1911 | Binder.restoreCallingIdentity(ident); |
| 1912 | } |
| 1913 | } |
| 1914 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1915 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1916 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1917 | public void finishInput(IInputMethodClient client) { |
| 1918 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1919 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1920 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 1922 | synchronized (mMethodMap) { |
| 1923 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 1924 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1925 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1926 | Slog.w(TAG, "Service connected without a token!"); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1927 | unbindCurrentMethodLocked(false); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1928 | return; |
| 1929 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 1930 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1931 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1932 | MSG_ATTACH_TOKEN, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1934 | clearClientSessionLocked(mCurClient); |
| 1935 | requestClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | } |
| 1939 | } |
| 1940 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1941 | void onSessionCreated(IInputMethod method, IInputMethodSession session, |
| 1942 | InputChannel channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | synchronized (mMethodMap) { |
| 1944 | if (mCurMethod != null && method != null |
| 1945 | && mCurMethod.asBinder() == method.asBinder()) { |
| 1946 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1947 | clearClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | mCurClient.curSession = new SessionState(mCurClient, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1949 | method, session, channel); |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1950 | InputBindResult res = attachNewInputLocked( |
| 1951 | InputMethodClient.START_INPUT_REASON_SESSION_CREATED_BY_IME, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1952 | if (res.method != null) { |
| 1953 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1954 | MSG_BIND_CLIENT, mCurClient.client, res)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1956 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | } |
| 1958 | } |
| 1959 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1960 | |
| 1961 | // Session abandoned. Close its associated input channel. |
| 1962 | channel.dispose(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1964 | |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1965 | void unbindCurrentMethodLocked(boolean savePosition) { |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 1966 | if (mVisibleBound) { |
| 1967 | mContext.unbindService(mVisibleConnection); |
| 1968 | mVisibleBound = false; |
| 1969 | } |
| 1970 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1971 | if (mHaveConnection) { |
| 1972 | mContext.unbindService(this); |
| 1973 | mHaveConnection = false; |
| 1974 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1975 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1976 | if (mCurToken != null) { |
| 1977 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1978 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 1979 | if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) { |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 1980 | // The current IME is shown. Hence an IME switch (transition) is happening. |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1981 | mWindowManagerInternal.saveLastInputMethodWindowForTransition(); |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 1982 | } |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1983 | mIWindowManager.removeWindowToken(mCurToken, DEFAULT_DISPLAY); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1984 | } catch (RemoteException e) { |
| 1985 | } |
| 1986 | mCurToken = null; |
| 1987 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1988 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1989 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1990 | clearCurMethodLocked(); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1991 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1992 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1993 | void resetCurrentMethodAndClient( |
| 1994 | /* @InputMethodClient.UnbindReason */ final int unbindClientReason) { |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1995 | mCurMethodId = null; |
| 1996 | unbindCurrentMethodLocked(false); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1997 | unbindCurrentClientLocked(unbindClientReason); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1998 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1999 | |
| 2000 | void requestClientSessionLocked(ClientState cs) { |
| 2001 | if (!cs.sessionRequested) { |
| 2002 | if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs); |
| 2003 | InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString()); |
| 2004 | cs.sessionRequested = true; |
| 2005 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO( |
| 2006 | MSG_CREATE_SESSION, mCurMethod, channels[1], |
| 2007 | new MethodCallback(this, mCurMethod, channels[0]))); |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | void clearClientSessionLocked(ClientState cs) { |
| 2012 | finishSessionLocked(cs.curSession); |
| 2013 | cs.curSession = null; |
| 2014 | cs.sessionRequested = false; |
| 2015 | } |
| 2016 | |
| 2017 | private void finishSessionLocked(SessionState sessionState) { |
| 2018 | if (sessionState != null) { |
| 2019 | if (sessionState.session != null) { |
| 2020 | try { |
| 2021 | sessionState.session.finishSession(); |
| 2022 | } catch (RemoteException e) { |
| 2023 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2024 | updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2025 | } |
| 2026 | sessionState.session = null; |
| 2027 | } |
| 2028 | if (sessionState.channel != null) { |
| 2029 | sessionState.channel.dispose(); |
| 2030 | sessionState.channel = null; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2031 | } |
| 2032 | } |
| 2033 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2034 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2035 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | if (mCurMethod != null) { |
| 2037 | for (ClientState cs : mClients.values()) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2038 | clearClientSessionLocked(cs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2039 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2040 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2041 | finishSessionLocked(mEnabledSession); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2042 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | mCurMethod = null; |
| 2044 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2045 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2046 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2047 | } |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 2048 | mInFullscreenMode = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2049 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2050 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2051 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2052 | public void onServiceDisconnected(ComponentName name) { |
Yohei Yukawa | 817d5f7 | 2017-01-04 20:15:02 -0800 | [diff] [blame] | 2053 | // Note that mContext.unbindService(this) does not trigger this. Hence if we are here the |
| 2054 | // disconnection is not intended by IMMS (e.g. triggered because the current IMS crashed), |
| 2055 | // which is irregular but can eventually happen for everyone just by continuing using the |
| 2056 | // device. Thus it is important to make sure that all the internal states are properly |
| 2057 | // refreshed when this method is called back. Running |
| 2058 | // adb install -r <APK that implements the current IME> |
| 2059 | // would be a good way to trigger such a situation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2061 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2062 | + " mCurIntent=" + mCurIntent); |
| 2063 | if (mCurMethod != null && mCurIntent != null |
| 2064 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2065 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | // We consider this to be a new bind attempt, since the system |
| 2067 | // should now try to restart the service for us. |
| 2068 | mLastBindTime = SystemClock.uptimeMillis(); |
| 2069 | mShowRequested = mInputShown; |
| 2070 | mInputShown = false; |
Yohei Yukawa | 817d5f7 | 2017-01-04 20:15:02 -0800 | [diff] [blame] | 2071 | unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_DISCONNECT_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | } |
| 2075 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2076 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | public void updateStatusIcon(IBinder token, String packageName, int iconId) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2078 | synchronized (mMethodMap) { |
| 2079 | if (!calledWithValidToken(token)) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2080 | return; |
| 2081 | } |
| 2082 | final long ident = Binder.clearCallingIdentity(); |
| 2083 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2085 | 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] | 2086 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2087 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2090 | 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] | 2091 | CharSequence contentDescription = null; |
| 2092 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2093 | // Use PackageManager to load label |
| 2094 | final PackageManager packageManager = mContext.getPackageManager(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2095 | contentDescription = packageManager.getApplicationLabel( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2096 | mIPackageManager.getApplicationInfo(packageName, 0, |
| 2097 | mSettings.getCurrentUserId())); |
| 2098 | } catch (RemoteException e) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2099 | /* ignore */ |
| 2100 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2101 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2102 | mStatusBar.setIcon(mSlotIme, packageName, iconId, 0, |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2103 | contentDescription != null |
| 2104 | ? contentDescription.toString() : null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2105 | mStatusBar.setIconVisibility(mSlotIme, true); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2106 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | } |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2108 | } finally { |
| 2109 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2111 | } |
| 2112 | } |
| 2113 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2114 | private boolean shouldShowImeSwitcherLocked(int visibility) { |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2115 | if (!mShowOngoingImeSwitcherForPhones) return false; |
Jason Monk | 807ef76 | 2014-05-08 15:47:46 -0400 | [diff] [blame] | 2116 | if (mSwitchingDialog != null) return false; |
Yohei Yukawa | d2bc309 | 2017-07-31 15:37:14 -0700 | [diff] [blame] | 2117 | if (mWindowManagerInternal.isKeyguardShowingAndNotOccluded() |
| 2118 | && mKeyguardManager != null && mKeyguardManager.isKeyguardSecure()) return false; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2119 | if ((visibility & InputMethodService.IME_ACTIVE) == 0) return false; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2120 | if (mWindowManagerInternal.isHardKeyboardAvailable()) { |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 2121 | if (mHardKeyboardBehavior == HardKeyboardBehavior.WIRELESS_AFFORDANCE) { |
| 2122 | // When physical keyboard is attached, we show the ime switcher (or notification if |
| 2123 | // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently |
| 2124 | // exists in the IME switcher dialog. Might be OK to remove this condition once |
| 2125 | // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live. |
| 2126 | return true; |
| 2127 | } |
Yohei Yukawa | 8939838 | 2016-03-29 11:37:04 -0700 | [diff] [blame] | 2128 | } else if ((visibility & InputMethodService.IME_VISIBLE) == 0) { |
| 2129 | return false; |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2130 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2131 | |
| 2132 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 2133 | final int N = imis.size(); |
| 2134 | if (N > 2) return true; |
| 2135 | if (N < 1) return false; |
| 2136 | int nonAuxCount = 0; |
| 2137 | int auxCount = 0; |
| 2138 | InputMethodSubtype nonAuxSubtype = null; |
| 2139 | InputMethodSubtype auxSubtype = null; |
| 2140 | for(int i = 0; i < N; ++i) { |
| 2141 | final InputMethodInfo imi = imis.get(i); |
| 2142 | final List<InputMethodSubtype> subtypes = |
| 2143 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
| 2144 | final int subtypeCount = subtypes.size(); |
| 2145 | if (subtypeCount == 0) { |
| 2146 | ++nonAuxCount; |
| 2147 | } else { |
| 2148 | for (int j = 0; j < subtypeCount; ++j) { |
| 2149 | final InputMethodSubtype subtype = subtypes.get(j); |
| 2150 | if (!subtype.isAuxiliary()) { |
| 2151 | ++nonAuxCount; |
| 2152 | nonAuxSubtype = subtype; |
| 2153 | } else { |
| 2154 | ++auxCount; |
| 2155 | auxSubtype = subtype; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2156 | } |
| 2157 | } |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2158 | } |
| 2159 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2160 | if (nonAuxCount > 1 || auxCount > 1) { |
| 2161 | return true; |
| 2162 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 2163 | if (nonAuxSubtype != null && auxSubtype != null |
| 2164 | && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 2165 | || auxSubtype.overridesImplicitlyEnabledSubtype() |
| 2166 | || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) |
| 2167 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 2168 | return false; |
| 2169 | } |
| 2170 | return true; |
| 2171 | } |
| 2172 | return false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2173 | } |
| 2174 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2175 | private boolean isKeyguardLocked() { |
| 2176 | return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked(); |
| 2177 | } |
| 2178 | |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2179 | @BinderThread |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 2180 | @SuppressWarnings("deprecation") |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2181 | @Override |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2182 | public void setImeWindowStatus(IBinder token, IBinder startInputToken, int vis, |
| 2183 | int backDisposition) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2184 | if (!calledWithValidToken(token)) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2185 | return; |
| 2186 | } |
| 2187 | |
Yohei Yukawa | 69e6802 | 2017-02-13 12:04:50 -0800 | [diff] [blame] | 2188 | final StartInputInfo info; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2189 | synchronized (mMethodMap) { |
Yohei Yukawa | 69e6802 | 2017-02-13 12:04:50 -0800 | [diff] [blame] | 2190 | info = mStartInputMap.get(startInputToken); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2191 | mImeWindowVis = vis; |
| 2192 | mBackDisposition = backDisposition; |
| 2193 | updateSystemUiLocked(token, vis, backDisposition); |
| 2194 | } |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2195 | |
| 2196 | final boolean dismissImeOnBackKeyPressed; |
| 2197 | switch (backDisposition) { |
| 2198 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 2199 | dismissImeOnBackKeyPressed = true; |
| 2200 | break; |
| 2201 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 2202 | dismissImeOnBackKeyPressed = false; |
| 2203 | break; |
| 2204 | default: |
| 2205 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 2206 | dismissImeOnBackKeyPressed = ((vis & InputMethodService.IME_VISIBLE) != 0); |
| 2207 | break; |
| 2208 | } |
Yohei Yukawa | ee2a7ed | 2017-02-15 21:38:57 -0800 | [diff] [blame] | 2209 | mWindowManagerInternal.updateInputMethodWindowStatus(token, |
| 2210 | (vis & InputMethodService.IME_VISIBLE) != 0, |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2211 | dismissImeOnBackKeyPressed, info != null ? info.mTargetWindow : null); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | private void updateSystemUi(IBinder token, int vis, int backDisposition) { |
| 2215 | synchronized (mMethodMap) { |
| 2216 | updateSystemUiLocked(token, vis, backDisposition); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | // Caution! This method is called in this class. Handle multi-user carefully |
| 2221 | private void updateSystemUiLocked(IBinder token, int vis, int backDisposition) { |
| 2222 | if (!calledWithValidToken(token)) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2223 | return; |
| 2224 | } |
| 2225 | |
| 2226 | // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure |
| 2227 | // all updateSystemUi happens on system previlege. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2228 | final long ident = Binder.clearCallingIdentity(); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2229 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2230 | // apply policy for binder calls |
| 2231 | if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) { |
| 2232 | vis = 0; |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2233 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2234 | // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked(). |
| 2235 | final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis); |
| 2236 | if (mStatusBar != null) { |
| 2237 | mStatusBar.setImeWindowStatus(token, vis, backDisposition, |
| 2238 | needsToShowImeSwitcher); |
| 2239 | } |
| 2240 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2241 | if (imi != null && needsToShowImeSwitcher) { |
| 2242 | // Used to load label |
| 2243 | final CharSequence title = mRes.getText( |
| 2244 | com.android.internal.R.string.select_input_method); |
| 2245 | final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName( |
| 2246 | mContext, imi, mCurrentSubtype); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2247 | mImeSwitcherNotification.setContentTitle(title) |
| 2248 | .setContentText(summary) |
| 2249 | .setContentIntent(mImeSwitchPendingIntent); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2250 | try { |
| 2251 | if ((mNotificationManager != null) |
| 2252 | && !mIWindowManager.hasNavigationBar()) { |
| 2253 | if (DEBUG) { |
| 2254 | Slog.d(TAG, "--- show notification: label = " + summary); |
| 2255 | } |
| 2256 | mNotificationManager.notifyAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2257 | SystemMessage.NOTE_SELECT_INPUT_METHOD, |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2258 | mImeSwitcherNotification.build(), UserHandle.ALL); |
| 2259 | mNotificationShown = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2260 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2261 | } catch (RemoteException e) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2262 | } |
| 2263 | } else { |
| 2264 | if (mNotificationShown && mNotificationManager != null) { |
| 2265 | if (DEBUG) { |
| 2266 | Slog.d(TAG, "--- hide notification"); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2267 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2268 | mNotificationManager.cancelAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2269 | SystemMessage.NOTE_SELECT_INPUT_METHOD, UserHandle.ALL); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2270 | mNotificationShown = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2271 | } |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2272 | } |
| 2273 | } finally { |
| 2274 | Binder.restoreCallingIdentity(ident); |
| 2275 | } |
| 2276 | } |
| 2277 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2278 | @Override |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2279 | public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2280 | if (!calledFromValidUser()) { |
| 2281 | return; |
| 2282 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2283 | synchronized (mMethodMap) { |
| 2284 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
| 2285 | for (int i = 0; i < spans.length; ++i) { |
| 2286 | SuggestionSpan ss = spans[i]; |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2287 | if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) { |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2288 | mSecureSuggestionSpans.put(ss, currentImi); |
| 2289 | } |
| 2290 | } |
| 2291 | } |
| 2292 | } |
| 2293 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2294 | @Override |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2295 | public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2296 | if (!calledFromValidUser()) { |
| 2297 | return false; |
| 2298 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2299 | synchronized (mMethodMap) { |
| 2300 | final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span); |
| 2301 | // TODO: Do not send the intent if the process of the targetImi is already dead. |
| 2302 | if (targetImi != null) { |
| 2303 | final String[] suggestions = span.getSuggestions(); |
| 2304 | if (index < 0 || index >= suggestions.length) return false; |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2305 | final String className = span.getNotificationTargetClassName(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2306 | final Intent intent = new Intent(); |
| 2307 | // Ensures that only a class in the original IME package will receive the |
| 2308 | // notification. |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2309 | intent.setClassName(targetImi.getPackageName(), className); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2310 | intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED); |
| 2311 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString); |
| 2312 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]); |
| 2313 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode()); |
Amith Yamasani | f043de9 | 2012-10-24 06:42:40 -0700 | [diff] [blame] | 2314 | final long ident = Binder.clearCallingIdentity(); |
| 2315 | try { |
| 2316 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
| 2317 | } finally { |
| 2318 | Binder.restoreCallingIdentity(ident); |
| 2319 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2320 | return true; |
| 2321 | } |
| 2322 | } |
| 2323 | return false; |
| 2324 | } |
| 2325 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2326 | void updateFromSettingsLocked(boolean enabledMayChange) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2327 | updateInputMethodsFromSettingsLocked(enabledMayChange); |
| 2328 | updateKeyboardFromSettingsLocked(); |
| 2329 | } |
| 2330 | |
| 2331 | void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2332 | if (enabledMayChange) { |
| 2333 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 2334 | for (int i=0; i<enabled.size(); i++) { |
| 2335 | // We allow the user to select "disabled until used" apps, so if they |
| 2336 | // are enabling one of those here we now need to make it enabled. |
| 2337 | InputMethodInfo imm = enabled.get(i); |
| 2338 | try { |
| 2339 | ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(), |
| 2340 | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 2341 | mSettings.getCurrentUserId()); |
Satoshi Kataoka | 7987a31 | 2013-04-17 18:59:33 +0900 | [diff] [blame] | 2342 | if (ai != null && ai.enabledSetting |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2343 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 2344 | if (DEBUG) { |
| 2345 | Slog.d(TAG, "Update state(" + imm.getId() |
| 2346 | + "): DISABLED_UNTIL_USED -> DEFAULT"); |
| 2347 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2348 | mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(), |
| 2349 | PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 2350 | PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(), |
| 2351 | mContext.getBasePackageName()); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2352 | } |
| 2353 | } catch (RemoteException e) { |
| 2354 | } |
| 2355 | } |
| 2356 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2357 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 2358 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 2359 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 2360 | // enabled. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2361 | String id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2362 | // There is no input method selected, try to choose new applicable input method. |
| 2363 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2364 | id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2365 | } |
| 2366 | if (!TextUtils.isEmpty(id)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2368 | setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2369 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2370 | Slog.w(TAG, "Unknown input method from prefs: " + id, e); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2371 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_IME_FAILED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2372 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2373 | mShortcutInputMethodsAndSubtypes.clear(); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2374 | } else { |
| 2375 | // 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] | 2376 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_NO_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 2378 | // Here is not the perfect place to reset the switching controller. Ideally |
| 2379 | // mSwitchingController and mSettings should be able to share the same state. |
| 2380 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 2381 | // the same enabled IMEs list. |
| 2382 | mSwitchingController.resetCircularListLocked(mContext); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2383 | |
| 2384 | } |
| 2385 | |
| 2386 | public void updateKeyboardFromSettingsLocked() { |
| 2387 | mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled(); |
| 2388 | if (mSwitchingDialog != null |
| 2389 | && mSwitchingDialogTitleView != null |
| 2390 | && mSwitchingDialog.isShowing()) { |
| 2391 | final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById( |
| 2392 | com.android.internal.R.id.hard_keyboard_switch); |
| 2393 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
| 2394 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2396 | |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 2397 | private void notifyInputMethodSubtypeChanged(final int userId, |
| 2398 | @Nullable final InputMethodInfo inputMethodInfo, |
| 2399 | @Nullable final InputMethodSubtype subtype) { |
| 2400 | final InputManagerInternal inputManagerInternal = |
| 2401 | LocalServices.getService(InputManagerInternal.class); |
| 2402 | if (inputManagerInternal != null) { |
| 2403 | inputManagerInternal.onInputMethodSubtypeChanged(userId, inputMethodInfo, subtype); |
| 2404 | } |
| 2405 | } |
| 2406 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2407 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | InputMethodInfo info = mMethodMap.get(id); |
| 2409 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2410 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2412 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2413 | // 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] | 2414 | if (id.equals(mCurMethodId)) { |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2415 | final int subtypeCount = info.getSubtypeCount(); |
| 2416 | if (subtypeCount <= 0) { |
| 2417 | return; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2418 | } |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2419 | final InputMethodSubtype oldSubtype = mCurrentSubtype; |
| 2420 | final InputMethodSubtype newSubtype; |
| 2421 | if (subtypeId >= 0 && subtypeId < subtypeCount) { |
| 2422 | newSubtype = info.getSubtypeAt(subtypeId); |
| 2423 | } else { |
| 2424 | // If subtype is null, try to find the most applicable one from |
| 2425 | // getCurrentInputMethodSubtype. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2426 | newSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2427 | } |
| 2428 | if (newSubtype == null || oldSubtype == null) { |
| 2429 | Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype |
| 2430 | + ", new subtype = " + newSubtype); |
| 2431 | return; |
| 2432 | } |
| 2433 | if (newSubtype != oldSubtype) { |
| 2434 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 2435 | if (mCurMethod != null) { |
| 2436 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2437 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2438 | mCurMethod.changeInputMethodSubtype(newSubtype); |
| 2439 | } catch (RemoteException e) { |
| 2440 | Slog.w(TAG, "Failed to call changeInputMethodSubtype"); |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 2441 | return; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2442 | } |
| 2443 | } |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 2444 | notifyInputMethodSubtypeChanged(mSettings.getCurrentUserId(), info, newSubtype); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2445 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | return; |
| 2447 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2448 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2449 | // Changing to a different IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | final long ident = Binder.clearCallingIdentity(); |
| 2451 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2452 | // Set a subtype to this input method. |
| 2453 | // subtypeId the name of a subtype which will be set. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2454 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 2455 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 2456 | // because mCurMethodId is stored as a history in |
| 2457 | // setSelectedInputMethodAndSubtypeLocked(). |
| 2458 | mCurMethodId = id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 2460 | if (LocalServices.getService(ActivityManagerInternal.class).isSystemReady()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 2462 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | intent.putExtra("input_method_id", id); |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 2464 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2465 | } |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2466 | unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | } finally { |
| 2468 | Binder.restoreCallingIdentity(ident); |
| 2469 | } |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 2470 | |
| 2471 | notifyInputMethodSubtypeChanged(mSettings.getCurrentUserId(), info, |
| 2472 | getCurrentInputMethodSubtypeLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2473 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2474 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2475 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2476 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 2477 | ResultReceiver resultReceiver) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2478 | if (!calledFromValidUser()) { |
| 2479 | return false; |
| 2480 | } |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2481 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2482 | long ident = Binder.clearCallingIdentity(); |
| 2483 | try { |
| 2484 | synchronized (mMethodMap) { |
| 2485 | if (mCurClient == null || client == null |
| 2486 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 2487 | try { |
| 2488 | // We need to check if this is the current client with |
| 2489 | // focus in the window manager, to allow this call to |
| 2490 | // be made before input is started in it. |
| 2491 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2492 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2493 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2494 | } |
| 2495 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2496 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | } |
| 2498 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2499 | |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2500 | 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] | 2501 | return showCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | } |
| 2503 | } finally { |
| 2504 | Binder.restoreCallingIdentity(ident); |
| 2505 | } |
| 2506 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2507 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2508 | boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2509 | mShowRequested = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2510 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 2511 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | } |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 2515 | mShowExplicitlyRequested = true; |
| 2516 | mShowForced = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2517 | } else if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 2518 | mShowExplicitlyRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2519 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2520 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2521 | if (!mSystemReady) { |
| 2522 | return false; |
| 2523 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2524 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2525 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | if (mCurMethod != null) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2527 | if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2528 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 2529 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 2530 | resultReceiver)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2531 | mInputShown = true; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2532 | if (mHaveConnection && !mVisibleBound) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2533 | bindCurrentInputMethodService( |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 2534 | mCurIntent, mVisibleConnection, IME_VISIBLE_BIND_FLAGS); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2535 | mVisibleBound = true; |
| 2536 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2537 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2539 | >= (mLastBindTime+TIME_TO_RECONNECT)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | // The client has asked to have the input method shown, but |
| 2541 | // we have been sitting here too long with a connection to the |
| 2542 | // service and no interface received, so let's disconnect/connect |
| 2543 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2544 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | SystemClock.uptimeMillis()-mLastBindTime,1); |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2546 | 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] | 2547 | mContext.unbindService(this); |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 2548 | bindCurrentInputMethodService(mCurIntent, this, IME_CONNECTION_BIND_FLAGS); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2549 | } else { |
| 2550 | if (DEBUG) { |
| 2551 | Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = " |
| 2552 | + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis())); |
| 2553 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2555 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2556 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2558 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2559 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2560 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 2561 | ResultReceiver resultReceiver) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2562 | if (!calledFromValidUser()) { |
| 2563 | return false; |
| 2564 | } |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2565 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | long ident = Binder.clearCallingIdentity(); |
| 2567 | try { |
| 2568 | synchronized (mMethodMap) { |
| 2569 | if (mCurClient == null || client == null |
| 2570 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 2571 | try { |
| 2572 | // We need to check if this is the current client with |
| 2573 | // focus in the window manager, to allow this call to |
| 2574 | // be made before input is started in it. |
| 2575 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2576 | if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid " |
| 2577 | + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2578 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2579 | } |
| 2580 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2581 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2582 | } |
| 2583 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2584 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2585 | 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] | 2586 | return hideCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | } |
| 2588 | } finally { |
| 2589 | Binder.restoreCallingIdentity(ident); |
| 2590 | } |
| 2591 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2592 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2593 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 2595 | && (mShowExplicitlyRequested || mShowForced)) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2596 | 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] | 2597 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | } |
| 2599 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2600 | 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] | 2601 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2602 | } |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2603 | |
| 2604 | // There is a chance that IMM#hideSoftInput() is called in a transient state where |
| 2605 | // IMMS#InputShown is already updated to be true whereas IMMS#mImeWindowVis is still waiting |
| 2606 | // to be updated with the new value sent from IME process. Even in such a transient state |
| 2607 | // historically we have accepted an incoming call of IMM#hideSoftInput() from the |
| 2608 | // application process as a valid request, and have even promised such a behavior with CTS |
| 2609 | // since Android Eclair. That's why we need to accept IMM#hideSoftInput() even when only |
| 2610 | // IMMS#InputShown indicates that the software keyboard is shown. |
| 2611 | // TODO: Clean up, IMMS#mInputShown, IMMS#mImeWindowVis and mShowRequested. |
| 2612 | final boolean shouldHideSoftInput = (mCurMethod != null) && (mInputShown || |
| 2613 | (mImeWindowVis & InputMethodService.IME_ACTIVE) != 0); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2614 | boolean res; |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2615 | if (shouldHideSoftInput) { |
| 2616 | // The IME will report its visible state again after the following message finally |
| 2617 | // delivered to the IME process as an IPC. Hence the inconsistency between |
| 2618 | // IMMS#mInputShown and IMMS#mImeWindowVis should be resolved spontaneously in |
| 2619 | // the final state. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2620 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 2621 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 2622 | res = true; |
| 2623 | } else { |
| 2624 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | } |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2626 | if (mHaveConnection && mVisibleBound) { |
| 2627 | mContext.unbindService(mVisibleConnection); |
| 2628 | mVisibleBound = false; |
| 2629 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2630 | mInputShown = false; |
| 2631 | mShowRequested = false; |
| 2632 | mShowExplicitlyRequested = false; |
| 2633 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2634 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2636 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2637 | @Override |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2638 | public InputBindResult startInputOrWindowGainedFocus( |
| 2639 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
| 2640 | IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode, |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 2641 | int windowFlags, @Nullable EditorInfo attribute, IInputContext inputContext, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2642 | /* @InputConnectionInspector.missingMethods */ final int missingMethods) { |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2643 | if (windowToken != null) { |
| 2644 | return windowGainedFocus(startInputReason, client, windowToken, controlFlags, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2645 | softInputMode, windowFlags, attribute, inputContext, missingMethods); |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2646 | } else { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2647 | return startInput(startInputReason, client, inputContext, missingMethods, attribute, |
| 2648 | controlFlags); |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | private InputBindResult windowGainedFocus( |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2653 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
Yohei Yukawa | 22dac1c | 2017-02-12 16:54:16 -0800 | [diff] [blame] | 2654 | IInputMethodClient client, IBinder windowToken, int controlFlags, |
| 2655 | /* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2656 | int windowFlags, EditorInfo attribute, IInputContext inputContext, |
| 2657 | /* @InputConnectionInspector.missingMethods */ final int missingMethods) { |
Satoshi Kataoka | 8d03305 | 2012-11-19 17:30:40 +0900 | [diff] [blame] | 2658 | // Needs to check the validity before clearing calling identity |
| 2659 | final boolean calledFromValidUser = calledFromValidUser(); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2660 | InputBindResult res = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | long ident = Binder.clearCallingIdentity(); |
| 2662 | try { |
| 2663 | synchronized (mMethodMap) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2664 | if (DEBUG) Slog.v(TAG, "windowGainedFocus: reason=" |
| 2665 | + InputMethodClient.getStartInputReason(startInputReason) |
| 2666 | + " client=" + client.asBinder() |
| 2667 | + " inputContext=" + inputContext |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2668 | + " missingMethods=" |
| 2669 | + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods) |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2670 | + " attribute=" + attribute |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2671 | + " controlFlags=#" + Integer.toHexString(controlFlags) |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 2672 | + " softInputMode=" + InputMethodClient.softInputModeToString(softInputMode) |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2673 | + " windowFlags=#" + Integer.toHexString(windowFlags)); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2674 | |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2675 | ClientState cs = mClients.get(client.asBinder()); |
| 2676 | if (cs == null) { |
| 2677 | throw new IllegalArgumentException("unknown client " |
| 2678 | + client.asBinder()); |
| 2679 | } |
| 2680 | |
| 2681 | try { |
| 2682 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 2683 | // Check with the window manager to make sure this client actually |
| 2684 | // has a window with focus. If not, reject. This is thread safe |
| 2685 | // because if the focus changes some time before or after, the |
| 2686 | // next client receiving focus that has any interest in input will |
| 2687 | // be calling through here after that change happens. |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 2688 | if (DEBUG) { |
| 2689 | Slog.w(TAG, "Focus gain on non-focused client " + cs.client |
| 2690 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 2691 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2692 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2693 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2694 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2696 | |
Satoshi Kataoka | 8d03305 | 2012-11-19 17:30:40 +0900 | [diff] [blame] | 2697 | if (!calledFromValidUser) { |
| 2698 | Slog.w(TAG, "A background user is requesting window. Hiding IME."); |
| 2699 | Slog.w(TAG, "If you want to interect with IME, you need " |
| 2700 | + "android.permission.INTERACT_ACROSS_USERS_FULL"); |
| 2701 | hideCurrentInputLocked(0, null); |
| 2702 | return null; |
| 2703 | } |
| 2704 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2705 | if (mCurFocusedWindow == windowToken) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 2706 | if (DEBUG) { |
| 2707 | Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client |
| 2708 | + " attribute=" + attribute + ", token = " + windowToken); |
| 2709 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2710 | if (attribute != null) { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2711 | return startInputUncheckedLocked(cs, inputContext, missingMethods, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2712 | attribute, controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2713 | } |
| 2714 | return null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2715 | } |
| 2716 | mCurFocusedWindow = windowToken; |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 2717 | mCurFocusedWindowSoftInputMode = softInputMode; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 2718 | mCurFocusedWindowClient = cs; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2719 | |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2720 | // Should we auto-show the IME even if the caller has not |
| 2721 | // specified what should be done with it? |
| 2722 | // We only do this automatically if the window can resize |
| 2723 | // to accommodate the IME (so what the user sees will give |
| 2724 | // them good context without input information being obscured |
| 2725 | // by the IME) or if running on a large screen where there |
| 2726 | // is more room for the target window + IME. |
| 2727 | final boolean doAutoShow = |
| 2728 | (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 2729 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
| 2730 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 2731 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2732 | final boolean isTextEditor = |
| 2733 | (controlFlags&InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0; |
| 2734 | |
| 2735 | // We want to start input before showing the IME, but after closing |
| 2736 | // it. We want to do this after closing it to help the IME disappear |
| 2737 | // more quickly (not get stuck behind it initializing itself for the |
| 2738 | // new focused input, even if its window wants to hide the IME). |
| 2739 | boolean didStart = false; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 2740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2741 | switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 2742 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2743 | if (!isTextEditor || !doAutoShow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) { |
| 2745 | // There is no focus view, and this window will |
| 2746 | // be behind any soft input window, so hide the |
| 2747 | // soft input window if it is shown. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2748 | 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] | 2749 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | } |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2751 | } else if (isTextEditor && doAutoShow && (softInputMode & |
| 2752 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | // There is a focus view, and we are navigating forward |
| 2754 | // into the window, so show the input window for the user. |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2755 | // We only do this automatically if the window can resize |
| 2756 | // to accommodate the IME (so what the user sees will give |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2757 | // them good context without input information being obscured |
| 2758 | // by the IME) or if running on a large screen where there |
| 2759 | // is more room for the target window + IME. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2760 | if (DEBUG) Slog.v(TAG, "Unspecified window will show input"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2761 | if (attribute != null) { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2762 | res = startInputUncheckedLocked(cs, inputContext, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2763 | missingMethods, attribute, controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2764 | didStart = true; |
| 2765 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2766 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2767 | } |
| 2768 | break; |
| 2769 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
| 2770 | // Do nothing. |
| 2771 | break; |
| 2772 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 2773 | if ((softInputMode & |
| 2774 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2775 | 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] | 2776 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | } |
| 2778 | break; |
| 2779 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2780 | 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] | 2781 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2782 | break; |
| 2783 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 2784 | if ((softInputMode & |
| 2785 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2786 | if (DEBUG) Slog.v(TAG, "Window asks to show input going forward"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2787 | if (attribute != null) { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2788 | res = startInputUncheckedLocked(cs, inputContext, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2789 | missingMethods, attribute, controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2790 | didStart = true; |
| 2791 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2792 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2793 | } |
| 2794 | break; |
| 2795 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2796 | if (DEBUG) Slog.v(TAG, "Window asks to always show input"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2797 | if (attribute != null) { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2798 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2799 | attribute, controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2800 | didStart = true; |
| 2801 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2802 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2803 | break; |
| 2804 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2805 | |
| 2806 | if (!didStart && attribute != null) { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2807 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2808 | controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | } |
| 2811 | } finally { |
| 2812 | Binder.restoreCallingIdentity(ident); |
| 2813 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2814 | |
| 2815 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2817 | |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 2818 | private boolean canShowInputMethodPickerLocked(IInputMethodClient client) { |
| 2819 | final int uid = Binder.getCallingUid(); |
| 2820 | if (UserHandle.getAppId(uid) == Process.SYSTEM_UID) { |
| 2821 | return true; |
| 2822 | } else if (mCurClient != null && client != null |
| 2823 | && mCurClient.client.asBinder() == client.asBinder()) { |
| 2824 | return true; |
| 2825 | } else if (mCurIntent != null && InputMethodUtils.checkIfPackageBelongsToUid( |
| 2826 | mAppOpsManager, |
| 2827 | uid, |
| 2828 | mCurIntent.getComponent().getPackageName())) { |
| 2829 | return true; |
| 2830 | } else if (mContext.checkCallingPermission( |
| 2831 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 2832 | == PackageManager.PERMISSION_GRANTED) { |
| 2833 | return true; |
| 2834 | } |
| 2835 | |
| 2836 | return false; |
| 2837 | } |
| 2838 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2839 | @Override |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2840 | public void showInputMethodPickerFromClient( |
| 2841 | IInputMethodClient client, int auxiliarySubtypeMode) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2842 | if (!calledFromValidUser()) { |
| 2843 | return; |
| 2844 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2845 | synchronized (mMethodMap) { |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 2846 | if(!canShowInputMethodPickerLocked(client)) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 2847 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2848 | + Binder.getCallingUid() + ": " + client); |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 2849 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | } |
| 2851 | |
satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 2852 | // Always call subtype picker, because subtype picker is a superset of input method |
| 2853 | // picker. |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2854 | mHandler.sendMessage(mCaller.obtainMessageI( |
| 2855 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode)); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2856 | } |
| 2857 | } |
| 2858 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2859 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | public void setInputMethod(IBinder token, String id) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2861 | if (!calledFromValidUser()) { |
| 2862 | return; |
| 2863 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2864 | setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID); |
| 2865 | } |
| 2866 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2867 | @Override |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2868 | public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2869 | if (!calledFromValidUser()) { |
| 2870 | return; |
| 2871 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2872 | synchronized (mMethodMap) { |
| 2873 | if (subtype != null) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2874 | setInputMethodWithSubtypeIdLocked(token, id, |
| 2875 | InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id), |
| 2876 | subtype.hashCode())); |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2877 | } else { |
| 2878 | setInputMethod(token, id); |
| 2879 | } |
| 2880 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2881 | } |
| 2882 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2883 | @Override |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 2884 | public void showInputMethodAndSubtypeEnablerFromClient( |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 2885 | IInputMethodClient client, String inputMethodId) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2886 | if (!calledFromValidUser()) { |
| 2887 | return; |
| 2888 | } |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 2889 | synchronized (mMethodMap) { |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 2890 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 2891 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2895 | @Override |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2896 | public boolean switchToLastInputMethod(IBinder token) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2897 | if (!calledFromValidUser()) { |
| 2898 | return false; |
| 2899 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2900 | synchronized (mMethodMap) { |
satok | c445bcd | 2011-01-25 18:57:24 +0900 | [diff] [blame] | 2901 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2902 | final InputMethodInfo lastImi; |
satok | 208d563 | 2011-05-20 22:13:38 +0900 | [diff] [blame] | 2903 | if (lastIme != null) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2904 | lastImi = mMethodMap.get(lastIme.first); |
| 2905 | } else { |
| 2906 | lastImi = null; |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2907 | } |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2908 | String targetLastImiId = null; |
| 2909 | int subtypeId = NOT_A_SUBTYPE_ID; |
| 2910 | if (lastIme != null && lastImi != null) { |
| 2911 | final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId); |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 2912 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2913 | final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID |
| 2914 | : mCurrentSubtype.hashCode(); |
| 2915 | // If the last IME is the same as the current IME and the last subtype is not |
| 2916 | // defined, there is no need to switch to the last IME. |
| 2917 | if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) { |
| 2918 | targetLastImiId = lastIme.first; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2919 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2920 | } |
| 2921 | } |
| 2922 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2923 | if (TextUtils.isEmpty(targetLastImiId) |
| 2924 | && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2925 | // This is a safety net. If the currentSubtype can't be added to the history |
| 2926 | // and the framework couldn't find the last ime, we will make the last ime be |
| 2927 | // the most applicable enabled keyboard subtype of the system imes. |
| 2928 | final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 2929 | if (enabled != null) { |
| 2930 | final int N = enabled.size(); |
| 2931 | final String locale = mCurrentSubtype == null |
| 2932 | ? mRes.getConfiguration().locale.toString() |
| 2933 | : mCurrentSubtype.getLocale(); |
| 2934 | for (int i = 0; i < N; ++i) { |
| 2935 | final InputMethodInfo imi = enabled.get(i); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2936 | if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2937 | InputMethodSubtype keyboardSubtype = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2938 | InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, |
| 2939 | InputMethodUtils.getSubtypes(imi), |
| 2940 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2941 | if (keyboardSubtype != null) { |
| 2942 | targetLastImiId = imi.getId(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2943 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2944 | imi, keyboardSubtype.hashCode()); |
| 2945 | if(keyboardSubtype.getLocale().equals(locale)) { |
| 2946 | break; |
| 2947 | } |
| 2948 | } |
| 2949 | } |
| 2950 | } |
| 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | if (!TextUtils.isEmpty(targetLastImiId)) { |
| 2955 | if (DEBUG) { |
| 2956 | Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second |
| 2957 | + ", from: " + mCurMethodId + ", " + subtypeId); |
| 2958 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2959 | setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2960 | return true; |
| 2961 | } else { |
| 2962 | return false; |
| 2963 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2964 | } |
| 2965 | } |
| 2966 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2967 | @Override |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2968 | public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2969 | if (!calledFromValidUser()) { |
| 2970 | return false; |
| 2971 | } |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2972 | synchronized (mMethodMap) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 2973 | if (!calledWithValidToken(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 2974 | return false; |
| 2975 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 2976 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | d39ae85 | 2016-04-10 20:28:40 -0700 | [diff] [blame] | 2977 | onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype, |
| 2978 | true /* forward */); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2979 | if (nextSubtype == null) { |
| 2980 | return false; |
| 2981 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2982 | setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(), |
| 2983 | nextSubtype.mSubtypeId); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2984 | return true; |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | @Override |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 2989 | public boolean shouldOfferSwitchingToNextInputMethod(IBinder token) { |
| 2990 | if (!calledFromValidUser()) { |
| 2991 | return false; |
| 2992 | } |
| 2993 | synchronized (mMethodMap) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 2994 | if (!calledWithValidToken(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 2995 | return false; |
| 2996 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 2997 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | d39ae85 | 2016-04-10 20:28:40 -0700 | [diff] [blame] | 2998 | false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype, |
| 2999 | true /* forward */); |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3000 | if (nextSubtype == null) { |
| 3001 | return false; |
| 3002 | } |
| 3003 | return true; |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | @Override |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3008 | public InputMethodSubtype getLastInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3009 | if (!calledFromValidUser()) { |
| 3010 | return null; |
| 3011 | } |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3012 | synchronized (mMethodMap) { |
| 3013 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 3014 | // TODO: Handle the case of the last IME with no subtypes |
| 3015 | if (lastIme == null || TextUtils.isEmpty(lastIme.first) |
| 3016 | || TextUtils.isEmpty(lastIme.second)) return null; |
| 3017 | final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); |
| 3018 | if (lastImi == null) return null; |
| 3019 | try { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3020 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3021 | final int lastSubtypeId = |
| 3022 | InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 0e7d7d6 | 2011-07-05 13:28:06 +0900 | [diff] [blame] | 3023 | if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { |
| 3024 | return null; |
| 3025 | } |
| 3026 | return lastImi.getSubtypeAt(lastSubtypeId); |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3027 | } catch (NumberFormatException e) { |
| 3028 | return null; |
| 3029 | } |
| 3030 | } |
| 3031 | } |
| 3032 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3033 | @Override |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3034 | public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3035 | if (!calledFromValidUser()) { |
| 3036 | return; |
| 3037 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3038 | // By this IPC call, only a process which shares the same uid with the IME can add |
| 3039 | // additional input method subtypes to the IME. |
Yohei Yukawa | 70f5c48 | 2016-01-04 19:42:36 -0800 | [diff] [blame] | 3040 | if (TextUtils.isEmpty(imiId) || subtypes == null) return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3041 | synchronized (mMethodMap) { |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 3042 | if (!mSystemReady) { |
| 3043 | return; |
| 3044 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3045 | final InputMethodInfo imi = mMethodMap.get(imiId); |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3046 | if (imi == null) return; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3047 | final String[] packageInfos; |
| 3048 | try { |
| 3049 | packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 3050 | } catch (RemoteException e) { |
| 3051 | Slog.e(TAG, "Failed to get package infos"); |
| 3052 | return; |
| 3053 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3054 | if (packageInfos != null) { |
| 3055 | final int packageNum = packageInfos.length; |
| 3056 | for (int i = 0; i < packageNum; ++i) { |
| 3057 | if (packageInfos[i].equals(imi.getPackageName())) { |
| 3058 | mFileManager.addInputMethodSubtypes(imi, subtypes); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3059 | final long ident = Binder.clearCallingIdentity(); |
| 3060 | try { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3061 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(ident); |
| 3064 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3065 | return; |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3066 | } |
| 3067 | } |
| 3068 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3069 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3070 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3071 | } |
| 3072 | |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3073 | @Override |
| 3074 | public int getInputMethodWindowVisibleHeight() { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 3075 | return mWindowManagerInternal.getInputMethodWindowVisibleHeight(); |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3076 | } |
| 3077 | |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3078 | @Override |
Yohei Yukawa | 833bdce | 2016-05-15 20:05:56 -0700 | [diff] [blame] | 3079 | public void clearLastInputMethodWindowForTransition(IBinder token) { |
| 3080 | if (!calledFromValidUser()) { |
| 3081 | return; |
| 3082 | } |
Yohei Yukawa | fa49c00 | 2017-01-31 19:15:00 -0800 | [diff] [blame] | 3083 | synchronized (mMethodMap) { |
| 3084 | if (!calledWithValidToken(token)) { |
Yohei Yukawa | fa49c00 | 2017-01-31 19:15:00 -0800 | [diff] [blame] | 3085 | return; |
Yohei Yukawa | 833bdce | 2016-05-15 20:05:56 -0700 | [diff] [blame] | 3086 | } |
Yohei Yukawa | 833bdce | 2016-05-15 20:05:56 -0700 | [diff] [blame] | 3087 | } |
Yohei Yukawa | fa49c00 | 2017-01-31 19:15:00 -0800 | [diff] [blame] | 3088 | mWindowManagerInternal.clearLastInputMethodWindowForTransition(); |
Yohei Yukawa | 833bdce | 2016-05-15 20:05:56 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | @Override |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3092 | public void notifyUserAction(int sequenceNumber) { |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3093 | if (DEBUG) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3094 | Slog.d(TAG, "Got the notification of a user action. sequenceNumber:" + sequenceNumber); |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3095 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3096 | synchronized (mMethodMap) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3097 | if (mCurUserActionNotificationSequenceNumber != sequenceNumber) { |
| 3098 | if (DEBUG) { |
| 3099 | Slog.d(TAG, "Ignoring the user action notification due to the sequence number " |
| 3100 | + "mismatch. expected:" + mCurUserActionNotificationSequenceNumber |
| 3101 | + " actual: " + sequenceNumber); |
| 3102 | } |
| 3103 | return; |
| 3104 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3105 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 3106 | if (imi != null) { |
Yohei Yukawa | 0297051 | 2014-06-05 16:16:18 +0900 | [diff] [blame] | 3107 | mSwitchingController.onUserActionLocked(imi, mCurrentSubtype); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3108 | } |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3112 | private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3113 | synchronized (mMethodMap) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3114 | setInputMethodWithSubtypeIdLocked(token, id, subtypeId); |
| 3115 | } |
| 3116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3117 | |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3118 | private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) { |
| 3119 | if (token == null) { |
| 3120 | if (mContext.checkCallingOrSelfPermission( |
| 3121 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3122 | != PackageManager.PERMISSION_GRANTED) { |
| 3123 | throw new SecurityException( |
| 3124 | "Using null token requires permission " |
| 3125 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3127 | } else if (mCurToken != token) { |
| 3128 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 3129 | + " token: " + token); |
| 3130 | return; |
| 3131 | } |
| 3132 | |
| 3133 | final long ident = Binder.clearCallingIdentity(); |
| 3134 | try { |
| 3135 | setInputMethodLocked(id, subtypeId); |
| 3136 | } finally { |
| 3137 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | } |
| 3139 | } |
| 3140 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3141 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | public void hideMySoftInput(IBinder token, int flags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3143 | if (!calledFromValidUser()) { |
| 3144 | return; |
| 3145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3146 | synchronized (mMethodMap) { |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 3147 | if (!calledWithValidToken(token)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | return; |
| 3149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | long ident = Binder.clearCallingIdentity(); |
| 3151 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3152 | hideCurrentInputLocked(flags, null); |
| 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(ident); |
| 3155 | } |
| 3156 | } |
| 3157 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3158 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3159 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3160 | public void showMySoftInput(IBinder token, int flags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3161 | if (!calledFromValidUser()) { |
| 3162 | return; |
| 3163 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3164 | synchronized (mMethodMap) { |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 3165 | if (!calledWithValidToken(token)) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3166 | return; |
| 3167 | } |
| 3168 | long ident = Binder.clearCallingIdentity(); |
| 3169 | try { |
| 3170 | showCurrentInputLocked(flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | } finally { |
| 3172 | Binder.restoreCallingIdentity(ident); |
| 3173 | } |
| 3174 | } |
| 3175 | } |
| 3176 | |
| 3177 | void setEnabledSessionInMainThread(SessionState session) { |
| 3178 | if (mEnabledSession != session) { |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3179 | if (mEnabledSession != null && mEnabledSession.session != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3181 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3182 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3183 | } catch (RemoteException e) { |
| 3184 | } |
| 3185 | } |
| 3186 | mEnabledSession = session; |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3187 | if (mEnabledSession != null && mEnabledSession.session != null) { |
| 3188 | try { |
| 3189 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
| 3190 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true); |
| 3191 | } catch (RemoteException e) { |
| 3192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | } |
| 3194 | } |
| 3195 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3196 | |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 3197 | @MainThread |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3198 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | public boolean handleMessage(Message msg) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3200 | SomeArgs args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | switch (msg.what) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3202 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3203 | final boolean showAuxSubtypes; |
| 3204 | switch (msg.arg1) { |
| 3205 | case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO: |
| 3206 | // This is undocumented so far, but IMM#showInputMethodPicker() has been |
| 3207 | // implemented so that auxiliary subtypes will be excluded when the soft |
| 3208 | // keyboard is invisible. |
| 3209 | showAuxSubtypes = mInputShown; |
| 3210 | break; |
| 3211 | case InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES: |
| 3212 | showAuxSubtypes = true; |
| 3213 | break; |
| 3214 | case InputMethodManager.SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES: |
| 3215 | showAuxSubtypes = false; |
| 3216 | break; |
| 3217 | default: |
| 3218 | Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1); |
| 3219 | return false; |
| 3220 | } |
| 3221 | showInputMethodMenu(showAuxSubtypes); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3222 | return true; |
| 3223 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3224 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 3225 | showInputMethodAndSubtypeEnabler((String)msg.obj); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3226 | return true; |
| 3227 | |
| 3228 | case MSG_SHOW_IM_CONFIG: |
| 3229 | showConfigureInputMethods(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3230 | return true; |
| 3231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | case MSG_UNBIND_INPUT: |
| 3235 | try { |
| 3236 | ((IInputMethod)msg.obj).unbindInput(); |
| 3237 | } catch (RemoteException e) { |
| 3238 | // There is nothing interesting about the method dying. |
| 3239 | } |
| 3240 | return true; |
| 3241 | case MSG_BIND_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3242 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | try { |
| 3244 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 3245 | } catch (RemoteException e) { |
| 3246 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3247 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3248 | return true; |
| 3249 | case MSG_SHOW_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3250 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3252 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput(" |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 3253 | + msg.arg1 + ", " + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 3254 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3255 | } catch (RemoteException e) { |
| 3256 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3257 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | return true; |
| 3259 | case MSG_HIDE_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3260 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3262 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, " |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 3263 | + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 3264 | ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | } catch (RemoteException e) { |
| 3266 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3267 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | return true; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 3269 | case MSG_HIDE_CURRENT_INPUT_METHOD: |
| 3270 | synchronized (mMethodMap) { |
| 3271 | hideCurrentInputLocked(0, null); |
| 3272 | } |
| 3273 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | case MSG_ATTACH_TOKEN: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3275 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3277 | 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] | 3278 | ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2); |
| 3279 | } catch (RemoteException e) { |
| 3280 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3281 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3282 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3283 | case MSG_CREATE_SESSION: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3284 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3285 | IInputMethod method = (IInputMethod)args.arg1; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3286 | InputChannel channel = (InputChannel)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3288 | method.createSession(channel, (IInputSessionCallback)args.arg3); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3289 | } catch (RemoteException e) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3290 | } finally { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3291 | // Dispose the channel if the input method is not local to this process |
| 3292 | // because the remote proxy will get its own copy when unparceled. |
| 3293 | if (channel != null && Binder.isProxy(method)) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3294 | channel.dispose(); |
| 3295 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3297 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3299 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3301 | |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3302 | case MSG_START_INPUT: { |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 3303 | final int missingMethods = msg.arg1; |
| 3304 | final boolean restarting = msg.arg2 != 0; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3305 | args = (SomeArgs) msg.obj; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 3306 | final IBinder startInputToken = (IBinder) args.arg1; |
| 3307 | final SessionState session = (SessionState) args.arg2; |
| 3308 | final IInputContext inputContext = (IInputContext) args.arg3; |
| 3309 | final EditorInfo editorInfo = (EditorInfo) args.arg4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | setEnabledSessionInMainThread(session); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 3312 | session.method.startInput(startInputToken, inputContext, missingMethods, |
| 3313 | editorInfo, restarting); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3314 | } catch (RemoteException e) { |
| 3315 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3316 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3317 | return true; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3318 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3321 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3322 | case MSG_UNBIND_CLIENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3323 | try { |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3324 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1, msg.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | } catch (RemoteException e) { |
| 3326 | // There is nothing interesting about the last client dying. |
| 3327 | } |
| 3328 | return true; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3329 | case MSG_BIND_CLIENT: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3330 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3331 | IInputMethodClient client = (IInputMethodClient)args.arg1; |
| 3332 | InputBindResult res = (InputBindResult)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3334 | client.onBindMethod(res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3336 | Slog.w(TAG, "Client died receiving input method " + args.arg2); |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3337 | } finally { |
| 3338 | // Dispose the channel if the input method is not local to this process |
| 3339 | // because the remote proxy will get its own copy when unparceled. |
| 3340 | if (res.channel != null && Binder.isProxy(client)) { |
| 3341 | res.channel.dispose(); |
| 3342 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3344 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | return true; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3346 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 3347 | case MSG_SET_ACTIVE: |
| 3348 | try { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3349 | ((ClientState)msg.obj).client.setActive(msg.arg1 != 0, msg.arg2 != 0); |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 3350 | } catch (RemoteException e) { |
| 3351 | Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " |
| 3352 | + ((ClientState)msg.obj).pid + " uid " |
| 3353 | + ((ClientState)msg.obj).uid); |
| 3354 | } |
| 3355 | return true; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3356 | case MSG_SET_INTERACTIVE: |
| 3357 | handleSetInteractive(msg.arg1 != 0); |
| 3358 | return true; |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3359 | case MSG_SWITCH_IME: |
| 3360 | handleSwitchInputMethod(msg.arg1 != 0); |
| 3361 | return true; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3362 | case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER: { |
| 3363 | final int sequenceNumber = msg.arg1; |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 3364 | final ClientState clientState = (ClientState)msg.obj; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3365 | try { |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 3366 | clientState.client.setUserActionNotificationSequenceNumber(sequenceNumber); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3367 | } catch (RemoteException e) { |
| 3368 | Slog.w(TAG, "Got RemoteException sending " |
| 3369 | + "setUserActionNotificationSequenceNumber(" |
| 3370 | + sequenceNumber + ") notification to pid " |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 3371 | + clientState.pid + " uid " |
| 3372 | + clientState.uid); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3373 | } |
| 3374 | return true; |
| 3375 | } |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3376 | case MSG_REPORT_FULLSCREEN_MODE: { |
| 3377 | final boolean fullscreen = msg.arg1 != 0; |
| 3378 | final ClientState clientState = (ClientState)msg.obj; |
| 3379 | try { |
| 3380 | clientState.client.reportFullscreenMode(fullscreen); |
| 3381 | } catch (RemoteException e) { |
| 3382 | Slog.w(TAG, "Got RemoteException sending " |
| 3383 | + "reportFullscreen(" + fullscreen + ") notification to pid=" |
| 3384 | + clientState.pid + " uid=" + clientState.uid); |
| 3385 | } |
| 3386 | return true; |
| 3387 | } |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3388 | |
| 3389 | // -------------------------------------------------------------- |
| 3390 | case MSG_HARD_KEYBOARD_SWITCH_CHANGED: |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3391 | mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3392 | return true; |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 3393 | case MSG_SYSTEM_UNLOCK_USER: |
| 3394 | final int userId = msg.arg1; |
| 3395 | onUnlockUser(userId); |
| 3396 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | } |
| 3398 | return false; |
| 3399 | } |
| 3400 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3401 | private void handleSetInteractive(final boolean interactive) { |
| 3402 | synchronized (mMethodMap) { |
| 3403 | mIsInteractive = interactive; |
| 3404 | updateSystemUiLocked(mCurToken, interactive ? mImeWindowVis : 0, mBackDisposition); |
| 3405 | |
| 3406 | // Inform the current client of the change in active status |
| 3407 | if (mCurClient != null && mCurClient.client != null) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3408 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 3409 | MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, mInFullscreenMode ? 1 : 0, |
| 3410 | mCurClient)); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3411 | } |
| 3412 | } |
| 3413 | } |
| 3414 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3415 | private void handleSwitchInputMethod(final boolean forwardDirection) { |
| 3416 | synchronized (mMethodMap) { |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3417 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | d39ae85 | 2016-04-10 20:28:40 -0700 | [diff] [blame] | 3418 | false, mMethodMap.get(mCurMethodId), mCurrentSubtype, forwardDirection); |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3419 | if (nextSubtype == null) { |
| 3420 | return; |
| 3421 | } |
| 3422 | setInputMethodLocked(nextSubtype.mImi.getId(), nextSubtype.mSubtypeId); |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 3423 | final InputMethodInfo newInputMethodInfo = mMethodMap.get(mCurMethodId); |
| 3424 | if (newInputMethodInfo == null) { |
| 3425 | return; |
| 3426 | } |
| 3427 | final CharSequence toastText = InputMethodUtils.getImeAndSubtypeDisplayName(mContext, |
| 3428 | newInputMethodInfo, mCurrentSubtype); |
| 3429 | if (!TextUtils.isEmpty(toastText)) { |
Yohei Yukawa | b2f901a | 2016-04-12 01:19:31 -0700 | [diff] [blame] | 3430 | if (mSubtypeSwitchedByShortCutToast == null) { |
| 3431 | mSubtypeSwitchedByShortCutToast = Toast.makeText(mContext, toastText, |
| 3432 | Toast.LENGTH_SHORT); |
| 3433 | } else { |
| 3434 | mSubtypeSwitchedByShortCutToast.setText(toastText); |
| 3435 | } |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 3436 | mSubtypeSwitchedByShortCutToast.show(); |
| 3437 | } |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3438 | } |
| 3439 | } |
| 3440 | |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 3441 | private boolean chooseNewDefaultIMELocked() { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3442 | final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME( |
| 3443 | mSettings.getEnabledInputMethodListLocked()); |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 3444 | if (imi != null) { |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 3445 | if (DEBUG) { |
| 3446 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 3447 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3448 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3449 | return true; |
| 3450 | } |
| 3451 | |
| 3452 | return false; |
| 3453 | } |
| 3454 | |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3455 | void buildInputMethodListLocked(boolean resetDefaultEnabledIme) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3456 | if (DEBUG) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3457 | Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 3458 | + " \n ------ caller=" + Debug.getCallers(10)); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3459 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 3460 | if (!mSystemReady) { |
| 3461 | Slog.e(TAG, "buildInputMethodListLocked is not allowed until system is ready"); |
| 3462 | return; |
| 3463 | } |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3464 | mMethodList.clear(); |
| 3465 | mMethodMap.clear(); |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 3466 | mMethodMapUpdateCount++; |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 3467 | mMyPackageMonitor.clearKnownImePackageNamesLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3468 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3469 | // Use for queryIntentServicesAsUser |
| 3470 | final PackageManager pm = mContext.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3471 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 3472 | // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default |
| 3473 | // behavior of PackageManager is exactly what we want. It by default picks up appropriate |
| 3474 | // services depending on the unlock state for the specified user. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3475 | final List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | new Intent(InputMethod.SERVICE_INTERFACE), |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 3477 | PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 3478 | mSettings.getCurrentUserId()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3479 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3480 | final HashMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3481 | mFileManager.getAllAdditionalInputMethodSubtypes(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3482 | for (int i = 0; i < services.size(); ++i) { |
| 3483 | ResolveInfo ri = services.get(i); |
| 3484 | ServiceInfo si = ri.serviceInfo; |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3485 | final String imeId = InputMethodInfo.computeId(ri); |
| 3486 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 3487 | Slog.w(TAG, "Skipping input method " + imeId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3488 | + ": it does not require the permission " |
| 3489 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 3490 | continue; |
| 3491 | } |
| 3492 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3493 | if (DEBUG) Slog.d(TAG, "Checking " + imeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3495 | final List<InputMethodSubtype> additionalSubtypes = additionalSubtypeMap.get(imeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | try { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3497 | InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes); |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3498 | mMethodList.add(p); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 3499 | final String id = p.getId(); |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3500 | mMethodMap.put(id, p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | |
| 3502 | if (DEBUG) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3503 | Slog.d(TAG, "Found an input method " + p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3504 | } |
Tadashi G. Takaoka | 3c23d5b | 2016-09-16 11:41:07 +0900 | [diff] [blame] | 3505 | } catch (Exception e) { |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3506 | Slog.wtf(TAG, "Unable to load input method " + imeId, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | } |
| 3508 | } |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3509 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3510 | // Construct the set of possible IME packages for onPackageChanged() to avoid false |
| 3511 | // negatives when the package state remains to be the same but only the component state is |
| 3512 | // changed. |
| 3513 | { |
| 3514 | // Here we intentionally use PackageManager.MATCH_DISABLED_COMPONENTS since the purpose |
| 3515 | // of this query is to avoid false negatives. PackageManager.MATCH_ALL could be more |
| 3516 | // conservative, but it seems we cannot use it for now (Issue 35176630). |
| 3517 | final List<ResolveInfo> allInputMethodServices = pm.queryIntentServicesAsUser( |
| 3518 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 3519 | PackageManager.MATCH_DISABLED_COMPONENTS, mSettings.getCurrentUserId()); |
| 3520 | final int N = allInputMethodServices.size(); |
| 3521 | for (int i = 0; i < N; ++i) { |
| 3522 | final ServiceInfo si = allInputMethodServices.get(i).serviceInfo; |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 3523 | if (android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 3524 | mMyPackageMonitor.addKnownImePackageNameLocked(si.packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3525 | } |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3526 | } |
| 3527 | } |
| 3528 | |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3529 | // TODO: The following code should find better place to live. |
| 3530 | if (!resetDefaultEnabledIme) { |
| 3531 | boolean enabledImeFound = false; |
| 3532 | final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked(); |
| 3533 | final int N = enabledImes.size(); |
| 3534 | for (int i = 0; i < N; ++i) { |
| 3535 | final InputMethodInfo imi = enabledImes.get(i); |
| 3536 | if (mMethodList.contains(imi)) { |
| 3537 | enabledImeFound = true; |
| 3538 | break; |
| 3539 | } |
| 3540 | } |
| 3541 | if (!enabledImeFound) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 3542 | if (DEBUG) { |
| 3543 | Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs."); |
| 3544 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3545 | resetDefaultEnabledIme = true; |
| 3546 | resetSelectedInputMethodAndSubtypeLocked(""); |
| 3547 | } |
| 3548 | } |
| 3549 | |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3550 | if (resetDefaultEnabledIme) { |
| 3551 | final ArrayList<InputMethodInfo> defaultEnabledIme = |
Yohei Yukawa | af5cee8 | 2017-01-23 16:17:11 -0800 | [diff] [blame] | 3552 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 3553 | final int N = defaultEnabledIme.size(); |
| 3554 | for (int i = 0; i < N; ++i) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3555 | final InputMethodInfo imi = defaultEnabledIme.get(i); |
| 3556 | if (DEBUG) { |
| 3557 | Slog.d(TAG, "--- enable ime = " + imi); |
| 3558 | } |
| 3559 | setInputMethodEnabledLocked(imi.getId(), true); |
| 3560 | } |
| 3561 | } |
| 3562 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3563 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3564 | if (!TextUtils.isEmpty(defaultImiId)) { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3565 | if (!mMethodMap.containsKey(defaultImiId)) { |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3566 | Slog.w(TAG, "Default IME is uninstalled. Choose new default IME."); |
| 3567 | if (chooseNewDefaultIMELocked()) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3568 | updateInputMethodsFromSettingsLocked(true); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3569 | } |
| 3570 | } else { |
| 3571 | // Double check that the default IME is certainly enabled. |
| 3572 | setInputMethodEnabledLocked(defaultImiId, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3573 | } |
| 3574 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 3575 | // Here is not the perfect place to reset the switching controller. Ideally |
| 3576 | // mSwitchingController and mSettings should be able to share the same state. |
| 3577 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 3578 | // the same enabled IMEs list. |
Yohei Yukawa | c834a25 | 2014-05-21 22:42:32 +0900 | [diff] [blame] | 3579 | mSwitchingController.resetCircularListLocked(mContext); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3580 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3583 | |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3584 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
Tadashi G. Takaoka | f49688f | 2011-01-20 17:56:13 +0900 | [diff] [blame] | 3585 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3586 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 3587 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 3588 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3589 | if (!TextUtils.isEmpty(inputMethodId)) { |
Tadashi G. Takaoka | 2548020 | 2011-01-20 23:13:02 +0900 | [diff] [blame] | 3590 | intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3591 | } |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 3592 | final int userId; |
| 3593 | synchronized (mMethodMap) { |
| 3594 | userId = mSettings.getCurrentUserId(); |
| 3595 | } |
| 3596 | mContext.startActivityAsUser(intent, null, UserHandle.of(userId)); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | private void showConfigureInputMethods() { |
| 3600 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 3601 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 3602 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 3603 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Satoshi Kataoka | 3ba439d | 2012-10-05 18:30:13 +0900 | [diff] [blame] | 3604 | mContext.startActivityAsUser(intent, null, UserHandle.CURRENT); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3605 | } |
| 3606 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 3607 | private boolean isScreenLocked() { |
| 3608 | return mKeyguardManager != null |
| 3609 | && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure(); |
| 3610 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3611 | |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3612 | private void showInputMethodMenu(boolean showAuxSubtypes) { |
| 3613 | 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] | 3614 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 3615 | final boolean isScreenLocked = isScreenLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3616 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3617 | final String lastInputMethodId = mSettings.getSelectedInputMethod(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3618 | int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3619 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3620 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3621 | synchronized (mMethodMap) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 3622 | final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 3623 | mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked( |
| 3624 | mContext); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 3625 | if (immis == null || immis.size() == 0) { |
| 3626 | return; |
| 3627 | } |
| 3628 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3629 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3631 | final List<ImeSubtypeListItem> imList = |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3632 | mSwitchingController.getSortedInputMethodAndSubtypeListLocked( |
Yohei Yukawa | 5f8e731 | 2015-12-10 00:58:55 -0800 | [diff] [blame] | 3633 | showAuxSubtypes, isScreenLocked); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 3634 | |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3635 | if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3636 | final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3637 | if (currentSubtype != null) { |
| 3638 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3639 | lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
| 3640 | currentImi, currentSubtype.hashCode()); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3641 | } |
| 3642 | } |
| 3643 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 3644 | final int N = imList.size(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3645 | mIms = new InputMethodInfo[N]; |
| 3646 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3647 | int checkedItem = 0; |
| 3648 | for (int i = 0; i < N; ++i) { |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3649 | final ImeSubtypeListItem item = imList.get(i); |
| 3650 | mIms[i] = item.mImi; |
| 3651 | mSubtypeIds[i] = item.mSubtypeId; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3652 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3653 | int subtypeId = mSubtypeIds[i]; |
| 3654 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 3655 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 3656 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 3657 | checkedItem = i; |
| 3658 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3659 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | } |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3661 | |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 3662 | final Context settingsContext = new ContextThemeWrapper( |
| 3663 | ActivityThread.currentActivityThread().getSystemUiContext(), |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3664 | com.android.internal.R.style.Theme_DeviceDefault_Settings); |
| 3665 | |
| 3666 | mDialogBuilder = new AlertDialog.Builder(settingsContext); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3667 | mDialogBuilder.setOnCancelListener(new OnCancelListener() { |
| 3668 | @Override |
| 3669 | public void onCancel(DialogInterface dialog) { |
| 3670 | hideInputMethodMenu(); |
| 3671 | } |
| 3672 | }); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3673 | |
| 3674 | final Context dialogContext = mDialogBuilder.getContext(); |
| 3675 | final TypedArray a = dialogContext.obtainStyledAttributes(null, |
| 3676 | com.android.internal.R.styleable.DialogPreference, |
| 3677 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 3678 | final Drawable dialogIcon = a.getDrawable( |
| 3679 | com.android.internal.R.styleable.DialogPreference_dialogIcon); |
| 3680 | a.recycle(); |
| 3681 | |
| 3682 | mDialogBuilder.setIcon(dialogIcon); |
| 3683 | |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 3684 | final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3685 | final View tv = inflater.inflate( |
| 3686 | com.android.internal.R.layout.input_method_switch_dialog_title, null); |
| 3687 | mDialogBuilder.setCustomTitle(tv); |
| 3688 | |
| 3689 | // Setup layout for a toggle switch of the hardware keyboard |
| 3690 | mSwitchingDialogTitleView = tv; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3691 | mSwitchingDialogTitleView |
| 3692 | .findViewById(com.android.internal.R.id.hard_keyboard_section) |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 3693 | .setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3694 | ? View.VISIBLE : View.GONE); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3695 | final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById( |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3696 | com.android.internal.R.id.hard_keyboard_switch); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3697 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3698 | hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 3699 | @Override |
| 3700 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3701 | mSettings.setShowImeWithHardKeyboard(isChecked); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3702 | // Ensure that the input method dialog is dismissed when changing |
| 3703 | // the hardware keyboard state. |
| 3704 | hideInputMethodMenu(); |
| 3705 | } |
| 3706 | }); |
| 3707 | |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3708 | final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3709 | com.android.internal.R.layout.input_method_switch_item, imList, checkedItem); |
| 3710 | final OnClickListener choiceListener = new OnClickListener() { |
| 3711 | @Override |
| 3712 | public void onClick(final DialogInterface dialog, final int which) { |
| 3713 | synchronized (mMethodMap) { |
| 3714 | if (mIms == null || mIms.length <= which || mSubtypeIds == null |
| 3715 | || mSubtypeIds.length <= which) { |
| 3716 | return; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3717 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3718 | final InputMethodInfo im = mIms[which]; |
| 3719 | int subtypeId = mSubtypeIds[which]; |
| 3720 | adapter.mCheckedItem = which; |
| 3721 | adapter.notifyDataSetChanged(); |
| 3722 | hideInputMethodMenu(); |
| 3723 | if (im != null) { |
| 3724 | if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) { |
| 3725 | subtypeId = NOT_A_SUBTYPE_ID; |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 3726 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3727 | setInputMethodLocked(im.getId(), subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3729 | } |
| 3730 | } |
| 3731 | }; |
| 3732 | mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3734 | mSwitchingDialog = mDialogBuilder.create(); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 3735 | mSwitchingDialog.setCanceledOnTouchOutside(true); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 3736 | final Window w = mSwitchingDialog.getWindow(); |
| 3737 | final WindowManager.LayoutParams attrs = w.getAttributes(); |
| 3738 | w.setType(TYPE_INPUT_METHOD_DIALOG); |
| 3739 | // Use an alternate token for the dialog for that window manager can group the token |
| 3740 | // with other IME windows based on type vs. grouping based on whichever token happens |
| 3741 | // to get selected by the system later on. |
| 3742 | attrs.token = mSwitchingDialogToken; |
| 3743 | attrs.privateFlags |= PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
| 3744 | attrs.setTitle("Select input method"); |
| 3745 | w.setAttributes(attrs); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 3746 | updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3747 | mSwitchingDialog.show(); |
| 3748 | } |
| 3749 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3750 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3751 | private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> { |
| 3752 | private final LayoutInflater mInflater; |
| 3753 | private final int mTextViewResourceId; |
| 3754 | private final List<ImeSubtypeListItem> mItemsList; |
Satoshi Kataoka | d214296 | 2012-11-12 18:43:06 +0900 | [diff] [blame] | 3755 | public int mCheckedItem; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3756 | public ImeSubtypeListAdapter(Context context, int textViewResourceId, |
| 3757 | List<ImeSubtypeListItem> itemsList, int checkedItem) { |
| 3758 | super(context, textViewResourceId, itemsList); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3759 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3760 | mTextViewResourceId = textViewResourceId; |
| 3761 | mItemsList = itemsList; |
| 3762 | mCheckedItem = checkedItem; |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 3763 | mInflater = context.getSystemService(LayoutInflater.class); |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | @Override |
| 3767 | public View getView(int position, View convertView, ViewGroup parent) { |
| 3768 | final View view = convertView != null ? convertView |
| 3769 | : mInflater.inflate(mTextViewResourceId, null); |
| 3770 | if (position < 0 || position >= mItemsList.size()) return view; |
| 3771 | final ImeSubtypeListItem item = mItemsList.get(position); |
| 3772 | final CharSequence imeName = item.mImeName; |
| 3773 | final CharSequence subtypeName = item.mSubtypeName; |
| 3774 | final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1); |
| 3775 | final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2); |
| 3776 | if (TextUtils.isEmpty(subtypeName)) { |
| 3777 | firstTextView.setText(imeName); |
| 3778 | secondTextView.setVisibility(View.GONE); |
| 3779 | } else { |
| 3780 | firstTextView.setText(subtypeName); |
| 3781 | secondTextView.setText(imeName); |
| 3782 | secondTextView.setVisibility(View.VISIBLE); |
| 3783 | } |
| 3784 | final RadioButton radioButton = |
| 3785 | (RadioButton)view.findViewById(com.android.internal.R.id.radio); |
| 3786 | radioButton.setChecked(position == mCheckedItem); |
| 3787 | return view; |
| 3788 | } |
| 3789 | } |
| 3790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3791 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3792 | synchronized (mMethodMap) { |
| 3793 | hideInputMethodMenuLocked(); |
| 3794 | } |
| 3795 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3796 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3797 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3798 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3800 | if (mSwitchingDialog != null) { |
| 3801 | mSwitchingDialog.dismiss(); |
| 3802 | mSwitchingDialog = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3804 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 3805 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3806 | mDialogBuilder = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3807 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3808 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3811 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3812 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3813 | public boolean setInputMethodEnabled(String id, boolean enabled) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3814 | // TODO: Make this work even for non-current users? |
| 3815 | if (!calledFromValidUser()) { |
| 3816 | return false; |
| 3817 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | synchronized (mMethodMap) { |
| 3819 | if (mContext.checkCallingOrSelfPermission( |
| 3820 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3821 | != PackageManager.PERMISSION_GRANTED) { |
| 3822 | throw new SecurityException( |
| 3823 | "Requires permission " |
| 3824 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 3825 | } |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 3826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3827 | long ident = Binder.clearCallingIdentity(); |
| 3828 | try { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3829 | return setInputMethodEnabledLocked(id, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | } finally { |
| 3831 | Binder.restoreCallingIdentity(ident); |
| 3832 | } |
| 3833 | } |
| 3834 | } |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3835 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3836 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 3837 | // Make sure this is a valid input method. |
| 3838 | InputMethodInfo imm = mMethodMap.get(id); |
| 3839 | if (imm == null) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3840 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3841 | } |
| 3842 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3843 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 3844 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3845 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3846 | if (enabled) { |
| 3847 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 3848 | if (pair.first.equals(id)) { |
| 3849 | // We are enabling this input method, but it is already enabled. |
| 3850 | // Nothing to do. The previous state was enabled. |
| 3851 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3852 | } |
| 3853 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3854 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 3855 | // Previous state was disabled. |
| 3856 | return false; |
| 3857 | } else { |
| 3858 | StringBuilder builder = new StringBuilder(); |
| 3859 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 3860 | builder, enabledInputMethodsList, id)) { |
| 3861 | // Disabled input method is currently selected, switch to another one. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3862 | final String selId = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 3863 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 3864 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 3865 | resetSelectedInputMethodAndSubtypeLocked(""); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3866 | } |
| 3867 | // Previous state was enabled. |
| 3868 | return true; |
| 3869 | } else { |
| 3870 | // We are disabling the input method but it is already disabled. |
| 3871 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3872 | return false; |
| 3873 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3874 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3875 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3876 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3877 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 3878 | boolean setSubtypeOnly) { |
| 3879 | // Update the history of InputMethod and Subtype |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3880 | mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3881 | |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3882 | mCurUserActionNotificationSequenceNumber = |
| 3883 | Math.max(mCurUserActionNotificationSequenceNumber + 1, 1); |
| 3884 | if (DEBUG) { |
| 3885 | Slog.d(TAG, "Bump mCurUserActionNotificationSequenceNumber:" |
| 3886 | + mCurUserActionNotificationSequenceNumber); |
| 3887 | } |
| 3888 | |
| 3889 | if (mCurClient != null && mCurClient.client != null) { |
| 3890 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 3891 | MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER, |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 3892 | mCurUserActionNotificationSequenceNumber, mCurClient)); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3893 | } |
| 3894 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3895 | // Set Subtype here |
| 3896 | if (imi == null || subtypeId < 0) { |
| 3897 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 3898 | mCurrentSubtype = null; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3899 | } else { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 3900 | if (subtypeId < imi.getSubtypeCount()) { |
| 3901 | InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId); |
| 3902 | mSettings.putSelectedSubtype(subtype.hashCode()); |
| 3903 | mCurrentSubtype = subtype; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3904 | } else { |
| 3905 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 3906 | // If the subtype is not specified, choose the most applicable one |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3907 | mCurrentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3908 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3909 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3910 | |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 3911 | if (!setSubtypeOnly) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3912 | // Set InputMethod here |
| 3913 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 3918 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 3919 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 3920 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 3921 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 3922 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 3923 | if (subtypeHashCode != null) { |
| 3924 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3925 | lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3926 | imi, Integer.parseInt(subtypeHashCode)); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3927 | } catch (NumberFormatException e) { |
| 3928 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 3929 | } |
| 3930 | } |
| 3931 | } |
| 3932 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3933 | } |
| 3934 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3935 | // If there are no selected shortcuts, tries finding the most applicable ones. |
| 3936 | private Pair<InputMethodInfo, InputMethodSubtype> |
| 3937 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) { |
| 3938 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 3939 | InputMethodInfo mostApplicableIMI = null; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3940 | InputMethodSubtype mostApplicableSubtype = null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3941 | boolean foundInSystemIME = false; |
| 3942 | |
| 3943 | // Search applicable subtype for each InputMethodInfo |
| 3944 | for (InputMethodInfo imi: imis) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3945 | final String imiId = imi.getId(); |
| 3946 | if (foundInSystemIME && !imiId.equals(mCurMethodId)) { |
| 3947 | continue; |
| 3948 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3949 | InputMethodSubtype subtype = null; |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3950 | final List<InputMethodSubtype> enabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3951 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3952 | // 1. Search by the current subtype's locale from enabledSubtypes. |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3953 | if (mCurrentSubtype != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3954 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3955 | mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3956 | } |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3957 | // 2. Search by the system locale from enabledSubtypes. |
| 3958 | // 3. Search the first enabled subtype matched with mode from enabledSubtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3959 | if (subtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3960 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3961 | mRes, enabledSubtypes, mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3962 | } |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3963 | final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3964 | InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode); |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3965 | final ArrayList<InputMethodSubtype> subtypesForSearch = |
| 3966 | overridingImplicitlyEnabledSubtypes.isEmpty() |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3967 | ? InputMethodUtils.getSubtypes(imi) |
| 3968 | : overridingImplicitlyEnabledSubtypes; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3969 | // 4. Search by the current subtype's locale from all subtypes. |
| 3970 | if (subtype == null && mCurrentSubtype != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3971 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3972 | mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3973 | } |
| 3974 | // 5. Search by the system locale from all subtypes. |
| 3975 | // 6. Search the first enabled subtype matched with mode from all subtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3976 | if (subtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3977 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3978 | mRes, subtypesForSearch, mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3979 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3980 | if (subtype != null) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3981 | if (imiId.equals(mCurMethodId)) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3982 | // The current input method is the most applicable IME. |
| 3983 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3984 | mostApplicableSubtype = subtype; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3985 | break; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3986 | } else if (!foundInSystemIME) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3987 | // The system input method is 2nd applicable IME. |
| 3988 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3989 | mostApplicableSubtype = subtype; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3990 | if ((imi.getServiceInfo().applicationInfo.flags |
| 3991 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 3992 | foundInSystemIME = true; |
| 3993 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3994 | } |
| 3995 | } |
| 3996 | } |
| 3997 | if (DEBUG) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3998 | if (mostApplicableIMI != null) { |
| 3999 | Slog.w(TAG, "Most applicable shortcut input method was:" |
| 4000 | + mostApplicableIMI.getId()); |
| 4001 | if (mostApplicableSubtype != null) { |
| 4002 | Slog.w(TAG, "Most applicable shortcut input method subtype was:" |
| 4003 | + "," + mostApplicableSubtype.getMode() + "," |
| 4004 | + mostApplicableSubtype.getLocale()); |
| 4005 | } |
| 4006 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4007 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4008 | if (mostApplicableIMI != null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4009 | return new Pair<> (mostApplicableIMI, mostApplicableSubtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4010 | } else { |
| 4011 | return null; |
| 4012 | } |
| 4013 | } |
| 4014 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4015 | /** |
| 4016 | * @return Return the current subtype of this input method. |
| 4017 | */ |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 4018 | @Override |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4019 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4020 | // TODO: Make this work even for non-current users? |
| 4021 | if (!calledFromValidUser()) { |
| 4022 | return null; |
| 4023 | } |
| 4024 | synchronized (mMethodMap) { |
| 4025 | return getCurrentInputMethodSubtypeLocked(); |
| 4026 | } |
| 4027 | } |
| 4028 | |
| 4029 | private InputMethodSubtype getCurrentInputMethodSubtypeLocked() { |
satok | fdf419e | 2012-05-08 16:52:08 +0900 | [diff] [blame] | 4030 | if (mCurMethodId == null) { |
| 4031 | return null; |
| 4032 | } |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4033 | final boolean subtypeIsSelected = mSettings.isSubtypeSelected(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4034 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 4035 | if (imi == null || imi.getSubtypeCount() == 0) { |
| 4036 | return null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4037 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4038 | if (!subtypeIsSelected || mCurrentSubtype == null |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4039 | || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) { |
| 4040 | int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4041 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
| 4042 | // If there are no selected subtypes, the framework will try to find |
| 4043 | // the most applicable subtype from explicitly or implicitly enabled |
| 4044 | // subtypes. |
| 4045 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4046 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4047 | // If there is only one explicitly or implicitly enabled subtype, |
| 4048 | // just returns it. |
| 4049 | if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { |
| 4050 | mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0); |
| 4051 | } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4052 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4053 | mRes, explicitlyOrImplicitlyEnabledSubtypes, |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4054 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4055 | if (mCurrentSubtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4056 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4057 | mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, |
| 4058 | true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4059 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 4060 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4061 | } else { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4062 | mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId); |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 4063 | } |
| 4064 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4065 | return mCurrentSubtype; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4066 | } |
| 4067 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4068 | // TODO: We should change the return type from List to List<Parcelable> |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 4069 | @SuppressWarnings("rawtypes") |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4070 | @Override |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4071 | public List getShortcutInputMethodsAndSubtypes() { |
| 4072 | synchronized (mMethodMap) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4073 | ArrayList<Object> ret = new ArrayList<>(); |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 4074 | if (mShortcutInputMethodsAndSubtypes.size() == 0) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4075 | // If there are no selected shortcut subtypes, the framework will try to find |
| 4076 | // the most applicable subtype from all subtypes whose mode is |
| 4077 | // 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] | 4078 | Pair<InputMethodInfo, InputMethodSubtype> info = |
| 4079 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked( |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4080 | InputMethodUtils.SUBTYPE_MODE_VOICE); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4081 | if (info != null) { |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 4082 | ret.add(info.first); |
| 4083 | ret.add(info.second); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4084 | } |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 4085 | return ret; |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 4086 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 4087 | for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) { |
| 4088 | ret.add(imi); |
| 4089 | for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) { |
| 4090 | ret.add(subtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4091 | } |
| 4092 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 4093 | return ret; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4094 | } |
| 4095 | } |
| 4096 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 4097 | @Override |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 4098 | public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4099 | // TODO: Make this work even for non-current users? |
| 4100 | if (!calledFromValidUser()) { |
| 4101 | return false; |
| 4102 | } |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 4103 | synchronized (mMethodMap) { |
| 4104 | if (subtype != null && mCurMethodId != null) { |
| 4105 | InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4106 | int subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode()); |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 4107 | if (subtypeId != NOT_A_SUBTYPE_ID) { |
| 4108 | setInputMethodLocked(mCurMethodId, subtypeId); |
| 4109 | return true; |
| 4110 | } |
| 4111 | } |
| 4112 | return false; |
| 4113 | } |
| 4114 | } |
| 4115 | |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 4116 | // 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] | 4117 | private static class InputMethodFileManager { |
| 4118 | private static final String SYSTEM_PATH = "system"; |
| 4119 | private static final String INPUT_METHOD_PATH = "inputmethod"; |
| 4120 | private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml"; |
| 4121 | private static final String NODE_SUBTYPES = "subtypes"; |
| 4122 | private static final String NODE_SUBTYPE = "subtype"; |
| 4123 | private static final String NODE_IMI = "imi"; |
| 4124 | private static final String ATTR_ID = "id"; |
| 4125 | private static final String ATTR_LABEL = "label"; |
| 4126 | private static final String ATTR_ICON = "icon"; |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4127 | private static final String ATTR_IME_SUBTYPE_ID = "subtypeId"; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4128 | private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale"; |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 4129 | private static final String ATTR_IME_SUBTYPE_LANGUAGE_TAG = "languageTag"; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4130 | private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode"; |
| 4131 | private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue"; |
| 4132 | private static final String ATTR_IS_AUXILIARY = "isAuxiliary"; |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 4133 | private static final String ATTR_IS_ASCII_CAPABLE = "isAsciiCapable"; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4134 | private final AtomicFile mAdditionalInputMethodSubtypeFile; |
| 4135 | private final HashMap<String, InputMethodInfo> mMethodMap; |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4136 | private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4137 | new HashMap<>(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 4138 | public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4139 | if (methodMap == null) { |
| 4140 | throw new NullPointerException("methodMap is null"); |
| 4141 | } |
| 4142 | mMethodMap = methodMap; |
Xiaohui Chen | 7c69636 | 2015-09-16 09:56:14 -0700 | [diff] [blame] | 4143 | final File systemDir = userId == UserHandle.USER_SYSTEM |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 4144 | ? new File(Environment.getDataDirectory(), SYSTEM_PATH) |
| 4145 | : Environment.getUserSystemDirectory(userId); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4146 | final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH); |
Yohei Yukawa | df5af48 | 2015-08-04 22:11:11 -0700 | [diff] [blame] | 4147 | if (!inputMethodDir.exists() && !inputMethodDir.mkdirs()) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4148 | Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath()); |
| 4149 | } |
| 4150 | final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME); |
| 4151 | mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile); |
| 4152 | if (!subtypeFile.exists()) { |
| 4153 | // If "subtypes.xml" doesn't exist, create a blank file. |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4154 | writeAdditionalInputMethodSubtypes( |
| 4155 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4156 | } else { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4157 | readAdditionalInputMethodSubtypes( |
| 4158 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | private void deleteAllInputMethodSubtypes(String imiId) { |
| 4163 | synchronized (mMethodMap) { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4164 | mAdditionalSubtypesMap.remove(imiId); |
| 4165 | writeAdditionalInputMethodSubtypes( |
| 4166 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | public void addInputMethodSubtypes( |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 4171 | InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4172 | synchronized (mMethodMap) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4173 | final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4174 | final int N = additionalSubtypes.length; |
| 4175 | for (int i = 0; i < N; ++i) { |
| 4176 | final InputMethodSubtype subtype = additionalSubtypes[i]; |
satok | ed2b24e | 2011-08-31 18:03:21 +0900 | [diff] [blame] | 4177 | if (!subtypes.contains(subtype)) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4178 | subtypes.add(subtype); |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4179 | } else { |
| 4180 | Slog.w(TAG, "Duplicated subtype definition found: " |
| 4181 | + subtype.getLocale() + ", " + subtype.getMode()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4182 | } |
| 4183 | } |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4184 | mAdditionalSubtypesMap.put(imi.getId(), subtypes); |
| 4185 | writeAdditionalInputMethodSubtypes( |
| 4186 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() { |
| 4191 | synchronized (mMethodMap) { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4192 | return mAdditionalSubtypesMap; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | private static void writeAdditionalInputMethodSubtypes( |
| 4197 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile, |
| 4198 | HashMap<String, InputMethodInfo> methodMap) { |
| 4199 | // Safety net for the case that this function is called before methodMap is set. |
| 4200 | final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0; |
| 4201 | FileOutputStream fos = null; |
| 4202 | try { |
| 4203 | fos = subtypesFile.startWrite(); |
| 4204 | final XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 4205 | out.setOutput(fos, StandardCharsets.UTF_8.name()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4206 | out.startDocument(null, true); |
| 4207 | out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 4208 | out.startTag(null, NODE_SUBTYPES); |
| 4209 | for (String imiId : allSubtypes.keySet()) { |
| 4210 | if (isSetMethodMap && !methodMap.containsKey(imiId)) { |
| 4211 | Slog.w(TAG, "IME uninstalled or not valid.: " + imiId); |
| 4212 | continue; |
| 4213 | } |
| 4214 | out.startTag(null, NODE_IMI); |
| 4215 | out.attribute(null, ATTR_ID, imiId); |
| 4216 | final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId); |
| 4217 | final int N = subtypesList.size(); |
| 4218 | for (int i = 0; i < N; ++i) { |
| 4219 | final InputMethodSubtype subtype = subtypesList.get(i); |
| 4220 | out.startTag(null, NODE_SUBTYPE); |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4221 | if (subtype.hasSubtypeId()) { |
| 4222 | out.attribute(null, ATTR_IME_SUBTYPE_ID, |
| 4223 | String.valueOf(subtype.getSubtypeId())); |
| 4224 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4225 | out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId())); |
| 4226 | out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId())); |
| 4227 | out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale()); |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 4228 | out.attribute(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG, |
| 4229 | subtype.getLanguageTag()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4230 | out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode()); |
| 4231 | out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue()); |
| 4232 | out.attribute(null, ATTR_IS_AUXILIARY, |
| 4233 | String.valueOf(subtype.isAuxiliary() ? 1 : 0)); |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 4234 | out.attribute(null, ATTR_IS_ASCII_CAPABLE, |
| 4235 | String.valueOf(subtype.isAsciiCapable() ? 1 : 0)); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4236 | out.endTag(null, NODE_SUBTYPE); |
| 4237 | } |
| 4238 | out.endTag(null, NODE_IMI); |
| 4239 | } |
| 4240 | out.endTag(null, NODE_SUBTYPES); |
| 4241 | out.endDocument(); |
| 4242 | subtypesFile.finishWrite(fos); |
| 4243 | } catch (java.io.IOException e) { |
| 4244 | Slog.w(TAG, "Error writing subtypes", e); |
| 4245 | if (fos != null) { |
| 4246 | subtypesFile.failWrite(fos); |
| 4247 | } |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | private static void readAdditionalInputMethodSubtypes( |
| 4252 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) { |
| 4253 | if (allSubtypes == null || subtypesFile == null) return; |
| 4254 | allSubtypes.clear(); |
Yohei Yukawa | 5894b43 | 2015-08-11 13:29:24 -0700 | [diff] [blame] | 4255 | try (final FileInputStream fis = subtypesFile.openRead()) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4256 | final XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 4257 | parser.setInput(fis, StandardCharsets.UTF_8.name()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4258 | int type = parser.getEventType(); |
| 4259 | // Skip parsing until START_TAG |
| 4260 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 4261 | && type != XmlPullParser.END_DOCUMENT) {} |
| 4262 | String firstNodeName = parser.getName(); |
| 4263 | if (!NODE_SUBTYPES.equals(firstNodeName)) { |
| 4264 | throw new XmlPullParserException("Xml doesn't start with subtypes"); |
| 4265 | } |
| 4266 | final int depth =parser.getDepth(); |
| 4267 | String currentImiId = null; |
| 4268 | ArrayList<InputMethodSubtype> tempSubtypesArray = null; |
| 4269 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 4270 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 4271 | if (type != XmlPullParser.START_TAG) |
| 4272 | continue; |
| 4273 | final String nodeName = parser.getName(); |
| 4274 | if (NODE_IMI.equals(nodeName)) { |
| 4275 | currentImiId = parser.getAttributeValue(null, ATTR_ID); |
| 4276 | if (TextUtils.isEmpty(currentImiId)) { |
| 4277 | Slog.w(TAG, "Invalid imi id found in subtypes.xml"); |
| 4278 | continue; |
| 4279 | } |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4280 | tempSubtypesArray = new ArrayList<>(); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4281 | allSubtypes.put(currentImiId, tempSubtypesArray); |
| 4282 | } else if (NODE_SUBTYPE.equals(nodeName)) { |
| 4283 | if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) { |
| 4284 | Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId); |
| 4285 | continue; |
| 4286 | } |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4287 | final int icon = Integer.parseInt( |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4288 | parser.getAttributeValue(null, ATTR_ICON)); |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4289 | final int label = Integer.parseInt( |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4290 | parser.getAttributeValue(null, ATTR_LABEL)); |
| 4291 | final String imeSubtypeLocale = |
| 4292 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE); |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 4293 | final String languageTag = |
| 4294 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4295 | final String imeSubtypeMode = |
| 4296 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE); |
| 4297 | final String imeSubtypeExtraValue = |
| 4298 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE); |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 4299 | final boolean isAuxiliary = "1".equals(String.valueOf( |
| 4300 | parser.getAttributeValue(null, ATTR_IS_AUXILIARY))); |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 4301 | final boolean isAsciiCapable = "1".equals(String.valueOf( |
| 4302 | parser.getAttributeValue(null, ATTR_IS_ASCII_CAPABLE))); |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4303 | final InputMethodSubtypeBuilder builder = new InputMethodSubtypeBuilder() |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 4304 | .setSubtypeNameResId(label) |
| 4305 | .setSubtypeIconResId(icon) |
| 4306 | .setSubtypeLocale(imeSubtypeLocale) |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 4307 | .setLanguageTag(languageTag) |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 4308 | .setSubtypeMode(imeSubtypeMode) |
| 4309 | .setSubtypeExtraValue(imeSubtypeExtraValue) |
| 4310 | .setIsAuxiliary(isAuxiliary) |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4311 | .setIsAsciiCapable(isAsciiCapable); |
| 4312 | final String subtypeIdString = |
| 4313 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_ID); |
| 4314 | if (subtypeIdString != null) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4315 | builder.setSubtypeId(Integer.parseInt(subtypeIdString)); |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4316 | } |
| 4317 | tempSubtypesArray.add(builder.build()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4318 | } |
| 4319 | } |
Yohei Yukawa | 5894b43 | 2015-08-11 13:29:24 -0700 | [diff] [blame] | 4320 | } catch (XmlPullParserException | IOException | NumberFormatException e) { |
| 4321 | Slog.w(TAG, "Error reading subtypes", e); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4322 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | } |
| 4326 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4327 | private static final class LocalServiceImpl implements InputMethodManagerInternal { |
| 4328 | @NonNull |
| 4329 | private final Handler mHandler; |
| 4330 | |
| 4331 | LocalServiceImpl(@NonNull final Handler handler) { |
| 4332 | mHandler = handler; |
| 4333 | } |
| 4334 | |
| 4335 | @Override |
| 4336 | public void setInteractive(boolean interactive) { |
| 4337 | // Do everything in handler so as not to block the caller. |
| 4338 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_INTERACTIVE, |
| 4339 | interactive ? 1 : 0, 0)); |
| 4340 | } |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 4341 | |
| 4342 | @Override |
| 4343 | public void switchInputMethod(boolean forwardDirection) { |
| 4344 | // Do everything in handler so as not to block the caller. |
| 4345 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SWITCH_IME, |
| 4346 | forwardDirection ? 1 : 0, 0)); |
| 4347 | } |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4348 | |
| 4349 | @Override |
| 4350 | public void hideCurrentInputMethod() { |
| 4351 | mHandler.removeMessages(MSG_HIDE_CURRENT_INPUT_METHOD); |
| 4352 | mHandler.sendEmptyMessage(MSG_HIDE_CURRENT_INPUT_METHOD); |
| 4353 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4354 | } |
| 4355 | |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 4356 | private static String imeWindowStatusToString(final int imeWindowVis) { |
| 4357 | final StringBuilder sb = new StringBuilder(); |
| 4358 | boolean first = true; |
| 4359 | if ((imeWindowVis & InputMethodService.IME_ACTIVE) != 0) { |
| 4360 | sb.append("Active"); |
| 4361 | first = false; |
| 4362 | } |
| 4363 | if ((imeWindowVis & InputMethodService.IME_VISIBLE) != 0) { |
| 4364 | if (!first) { |
| 4365 | sb.append("|"); |
| 4366 | } |
| 4367 | sb.append("Visible"); |
| 4368 | } |
| 4369 | return sb.toString(); |
| 4370 | } |
| 4371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4372 | @Override |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4373 | public IInputContentUriToken createInputContentUriToken(@Nullable IBinder token, |
| 4374 | @Nullable Uri contentUri, @Nullable String packageName) { |
| 4375 | if (!calledFromValidUser()) { |
| 4376 | return null; |
| 4377 | } |
| 4378 | |
| 4379 | if (token == null) { |
| 4380 | throw new NullPointerException("token"); |
| 4381 | } |
| 4382 | if (packageName == null) { |
| 4383 | throw new NullPointerException("packageName"); |
| 4384 | } |
| 4385 | if (contentUri == null) { |
| 4386 | throw new NullPointerException("contentUri"); |
| 4387 | } |
| 4388 | final String contentUriScheme = contentUri.getScheme(); |
| 4389 | if (!"content".equals(contentUriScheme)) { |
| 4390 | throw new InvalidParameterException("contentUri must have content scheme"); |
| 4391 | } |
| 4392 | |
| 4393 | synchronized (mMethodMap) { |
| 4394 | final int uid = Binder.getCallingUid(); |
| 4395 | if (mCurMethodId == null) { |
| 4396 | return null; |
| 4397 | } |
| 4398 | if (mCurToken != token) { |
| 4399 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurToken=" + mCurToken |
| 4400 | + " token=" + token); |
| 4401 | return null; |
| 4402 | } |
| 4403 | // We cannot simply distinguish a bad IME that reports an arbitrary package name from |
| 4404 | // an unfortunate IME whose internal state is already obsolete due to the asynchronous |
| 4405 | // nature of our system. Let's compare it with our internal record. |
| 4406 | if (!TextUtils.equals(mCurAttribute.packageName, packageName)) { |
| 4407 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurAttribute.packageName=" |
| 4408 | + mCurAttribute.packageName + " packageName=" + packageName); |
| 4409 | return null; |
| 4410 | } |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4411 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4412 | final int imeUserId = UserHandle.getUserId(uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4413 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4414 | final int appUserId = UserHandle.getUserId(mCurClient.uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4415 | // This user ID may be invalid if "contentUri" embedded an invalid user ID. |
| 4416 | final int contentUriOwnerUserId = ContentProvider.getUserIdFromUri(contentUri, |
| 4417 | imeUserId); |
| 4418 | final Uri contentUriWithoutUserId = ContentProvider.getUriWithoutUserId(contentUri); |
| 4419 | // Note: InputContentUriTokenHandler.take() checks whether the IME (specified by "uid") |
| 4420 | // actually has the right to grant a read permission for "contentUriWithoutUserId" that |
| 4421 | // is claimed to belong to "contentUriOwnerUserId". For example, specifying random |
| 4422 | // content URI and/or contentUriOwnerUserId just results in a SecurityException thrown |
| 4423 | // from InputContentUriTokenHandler.take() and can never be allowed beyond what is |
| 4424 | // actually allowed to "uid", which is guaranteed to be the IME's one. |
| 4425 | return new InputContentUriTokenHandler(contentUriWithoutUserId, uid, |
| 4426 | packageName, contentUriOwnerUserId, appUserId); |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | @Override |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4431 | public void reportFullscreenMode(IBinder token, boolean fullscreen) { |
| 4432 | if (!calledFromValidUser()) { |
| 4433 | return; |
| 4434 | } |
| 4435 | synchronized (mMethodMap) { |
| 4436 | if (!calledWithValidToken(token)) { |
| 4437 | return; |
| 4438 | } |
| 4439 | if (mCurClient != null && mCurClient.client != null) { |
| 4440 | mInFullscreenMode = fullscreen; |
| 4441 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 4442 | MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, mCurClient)); |
| 4443 | } |
| 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 4449 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4450 | |
| 4451 | IInputMethod method; |
| 4452 | ClientState client; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4453 | ClientState focusedWindowClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4457 | synchronized (mMethodMap) { |
| 4458 | p.println("Current Input Method Manager state:"); |
| 4459 | int N = mMethodList.size(); |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 4460 | p.println(" Input Methods: mMethodMapUpdateCount=" + mMethodMapUpdateCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | for (int i=0; i<N; i++) { |
| 4462 | InputMethodInfo info = mMethodList.get(i); |
| 4463 | p.println(" InputMethod #" + i + ":"); |
| 4464 | info.dump(p, " "); |
| 4465 | } |
| 4466 | p.println(" Clients:"); |
| 4467 | for (ClientState ci : mClients.values()) { |
| 4468 | p.println(" Client " + ci + ":"); |
| 4469 | p.println(" client=" + ci.client); |
| 4470 | p.println(" inputContext=" + ci.inputContext); |
| 4471 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 4472 | p.println(" curSession=" + ci.curSession); |
| 4473 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4474 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 4476 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 4477 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow |
| 4478 | + " softInputMode=" + |
| 4479 | InputMethodClient.softInputModeToString(mCurFocusedWindowSoftInputMode) |
| 4480 | + " client=" + mCurFocusedWindowClient); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4481 | focusedWindowClient = mCurFocusedWindowClient; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4482 | p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection |
| 4483 | + " mBoundToMethod=" + mBoundToMethod); |
| 4484 | p.println(" mCurToken=" + mCurToken); |
| 4485 | p.println(" mCurIntent=" + mCurIntent); |
| 4486 | method = mCurMethod; |
| 4487 | p.println(" mCurMethod=" + mCurMethod); |
| 4488 | p.println(" mEnabledSession=" + mEnabledSession); |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 4489 | p.println(" mImeWindowVis=" + imeWindowStatusToString(mImeWindowVis)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4490 | p.println(" mShowRequested=" + mShowRequested |
| 4491 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 4492 | + " mShowForced=" + mShowForced |
| 4493 | + " mInputShown=" + mInputShown); |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4494 | p.println(" mInFullscreenMode=" + mInFullscreenMode); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 4495 | p.println(" mCurUserActionNotificationSequenceNumber=" |
| 4496 | + mCurUserActionNotificationSequenceNumber); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4497 | p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 4498 | p.println(" mSettingsObserver=" + mSettingsObserver); |
Yohei Yukawa | d724886 | 2015-06-03 23:56:12 -0700 | [diff] [blame] | 4499 | p.println(" mSwitchingController:"); |
| 4500 | mSwitchingController.dump(p); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4501 | p.println(" mSettings:"); |
| 4502 | mSettings.dumpLocked(p, " "); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 4503 | |
| 4504 | p.println(" mStartInputHistory:"); |
| 4505 | mStartInputHistory.dump(pw, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4507 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4508 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4510 | pw.flush(); |
| 4511 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4512 | TransferPipe.dumpAsync(client.client.asBinder(), fd, args); |
| 4513 | } catch (IOException | RemoteException e) { |
| 4514 | p.println("Failed to dump input method client: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4516 | } else { |
| 4517 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4518 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4519 | |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4520 | if (focusedWindowClient != null && client != focusedWindowClient) { |
| 4521 | p.println(" "); |
| 4522 | p.println("Warning: Current input method client doesn't match the last focused. " |
| 4523 | + "window."); |
| 4524 | p.println("Dumping input method client in the last focused window just in case."); |
| 4525 | p.println(" "); |
| 4526 | pw.flush(); |
| 4527 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4528 | TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args); |
| 4529 | } catch (IOException | RemoteException e) { |
| 4530 | p.println("Failed to dump input method client in focused window: " + e); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4531 | } |
| 4532 | } |
| 4533 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4534 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4536 | pw.flush(); |
| 4537 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4538 | TransferPipe.dumpAsync(method.asBinder(), fd, args); |
| 4539 | } catch (IOException | RemoteException e) { |
| 4540 | p.println("Failed to dump input method service: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4541 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4542 | } else { |
| 4543 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4544 | } |
| 4545 | } |
| 4546 | } |