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