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; |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 38 | import com.android.internal.util.IndentingPrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import com.android.internal.view.IInputContext; |
| 40 | import com.android.internal.view.IInputMethod; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import com.android.internal.view.IInputMethodClient; |
| 42 | import com.android.internal.view.IInputMethodManager; |
| 43 | import com.android.internal.view.IInputMethodSession; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 44 | import com.android.internal.view.IInputSessionCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import com.android.internal.view.InputBindResult; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 46 | import com.android.internal.view.InputMethodClient; |
Adam Lesinski | ef2ea1f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 47 | import com.android.server.statusbar.StatusBarManagerService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 49 | import org.xmlpull.v1.XmlPullParser; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import org.xmlpull.v1.XmlPullParserException; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 51 | import org.xmlpull.v1.XmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 53 | import android.Manifest; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 54 | import android.annotation.AnyThread; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 55 | import android.annotation.BinderThread; |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 56 | import android.annotation.ColorInt; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 57 | import android.annotation.IntDef; |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 58 | import android.annotation.MainThread; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 59 | import android.annotation.NonNull; |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 60 | import android.annotation.Nullable; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 61 | import android.annotation.RequiresPermission; |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 62 | import android.annotation.TestApi; |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 63 | import android.annotation.UserIdInt; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 64 | import android.app.ActivityManager; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 65 | import android.app.ActivityManagerInternal; |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 66 | import android.app.ActivityThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.app.AlertDialog; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 68 | import android.app.AppGlobals; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 69 | import android.app.AppOpsManager; |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame] | 70 | import android.app.KeyguardManager; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 71 | import android.app.Notification; |
| 72 | import android.app.NotificationManager; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 73 | import android.app.PendingIntent; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 74 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.content.ComponentName; |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 76 | import android.content.ContentProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.content.ContentResolver; |
| 78 | import android.content.Context; |
| 79 | import android.content.DialogInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.content.DialogInterface.OnCancelListener; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 81 | import android.content.DialogInterface.OnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.content.Intent; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 83 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 85 | import android.content.pm.ApplicationInfo; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 86 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.content.pm.PackageManager; |
| 88 | import android.content.pm.ResolveInfo; |
| 89 | import android.content.pm.ServiceInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 90 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.content.res.Resources; |
| 92 | import android.content.res.TypedArray; |
| 93 | import android.database.ContentObserver; |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 94 | import android.graphics.drawable.Drawable; |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 95 | import android.inputmethodservice.InputMethodService; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 96 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.os.Binder; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 98 | import android.os.Bundle; |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 99 | import android.os.Debug; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 100 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.os.Handler; |
| 102 | import android.os.IBinder; |
| 103 | import android.os.IInterface; |
| 104 | import android.os.Message; |
Yohei Yukawa | 23cbe85 | 2016-05-17 16:42:58 -0700 | [diff] [blame] | 105 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.os.Parcel; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 107 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 109 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.os.ServiceManager; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 111 | import android.os.ShellCallback; |
| 112 | import android.os.ShellCommand; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.os.SystemClock; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 114 | import android.os.SystemProperties; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 115 | import android.os.UserHandle; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 116 | import android.os.UserManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | import android.provider.Settings; |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 118 | import android.service.vr.IVrManager; |
| 119 | import android.service.vr.IVrStateCallbacks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import android.text.TextUtils; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 121 | import android.text.style.SuggestionSpan; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 122 | import android.util.ArraySet; |
Dianne Hackborn | 39606a0 | 2012-07-31 17:54:35 -0700 | [diff] [blame] | 123 | import android.util.AtomicFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import android.util.EventLog; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 125 | import android.util.LruCache; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 126 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | import android.util.PrintWriterPrinter; |
| 128 | import android.util.Printer; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 129 | import android.util.Slog; |
| 130 | import android.util.Xml; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 131 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | import android.view.IWindowManager; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 133 | import android.view.InputChannel; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 134 | import android.view.LayoutInflater; |
| 135 | import android.view.View; |
| 136 | import android.view.ViewGroup; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 137 | import android.view.Window; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | import android.view.WindowManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 139 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | import android.view.inputmethod.InputBinding; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 141 | import android.view.inputmethod.InputConnection; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 142 | import android.view.inputmethod.InputConnectionInspector; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | import android.view.inputmethod.InputMethod; |
| 144 | import android.view.inputmethod.InputMethodInfo; |
| 145 | import android.view.inputmethod.InputMethodManager; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 146 | import android.view.inputmethod.InputMethodManagerInternal; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 147 | import android.view.inputmethod.InputMethodSubtype; |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 148 | import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 149 | import android.widget.ArrayAdapter; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 150 | import android.widget.CompoundButton; |
| 151 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 152 | import android.widget.RadioButton; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 153 | import android.widget.Switch; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 154 | import android.widget.TextView; |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 155 | import android.widget.Toast; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 157 | import com.android.server.wm.WindowManagerInternal; |
| 158 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 159 | import java.io.File; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | import java.io.FileDescriptor; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 161 | import java.io.FileInputStream; |
| 162 | import java.io.FileOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | import java.io.IOException; |
| 164 | import java.io.PrintWriter; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 165 | import java.lang.annotation.Retention; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 166 | import java.nio.charset.StandardCharsets; |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 167 | import java.security.InvalidParameterException; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 168 | import java.text.SimpleDateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | import java.util.ArrayList; |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 170 | import java.util.Collections; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 171 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | import java.util.HashMap; |
| 173 | import java.util.List; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 174 | import java.util.Locale; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 175 | import java.util.WeakHashMap; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 176 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | |
| 178 | /** |
| 179 | * This class provides a system service that manages input methods. |
| 180 | */ |
| 181 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 182 | implements ServiceConnection, Handler.Callback { |
| 183 | static final boolean DEBUG = false; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 184 | static final String TAG = "InputMethodManagerService"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 186 | @Retention(SOURCE) |
| 187 | @IntDef({ShellCommandResult.SUCCESS, ShellCommandResult.FAILURE}) |
| 188 | private @interface ShellCommandResult { |
| 189 | int SUCCESS = 0; |
| 190 | int FAILURE = -1; |
| 191 | } |
| 192 | |
Seigo Nonaka | d4474cb | 2015-05-04 16:53:24 -0700 | [diff] [blame] | 193 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 1; |
| 194 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 2; |
| 195 | static final int MSG_SHOW_IM_CONFIG = 3; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | static final int MSG_UNBIND_INPUT = 1000; |
| 198 | static final int MSG_BIND_INPUT = 1010; |
| 199 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 200 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 201 | static final int MSG_HIDE_CURRENT_INPUT_METHOD = 1035; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | static final int MSG_ATTACH_TOKEN = 1040; |
| 203 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | static final int MSG_START_INPUT = 2000; |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 206 | static final int MSG_START_VR_INPUT = 2010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 207 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 208 | static final int MSG_UNBIND_CLIENT = 3000; |
| 209 | static final int MSG_BIND_CLIENT = 3010; |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 210 | static final int MSG_SET_ACTIVE = 3020; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 211 | static final int MSG_SET_INTERACTIVE = 3030; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 212 | static final int MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER = 3040; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 213 | static final int MSG_REPORT_FULLSCREEN_MODE = 3045; |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 214 | static final int MSG_SWITCH_IME = 3050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 215 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 216 | static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000; |
| 217 | |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 218 | static final int MSG_SYSTEM_UNLOCK_USER = 5000; |
| 219 | |
Satoshi Kataoka | bcacc32 | 2013-10-21 17:57:27 -0700 | [diff] [blame] | 220 | static final long TIME_TO_RECONNECT = 3 * 1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 221 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 222 | static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20; |
| 223 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 224 | private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID; |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 225 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 226 | |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 227 | /** |
| 228 | * Binding flags for establishing connection to the {@link InputMethodService}. |
| 229 | */ |
| 230 | private static final int IME_CONNECTION_BIND_FLAGS = |
| 231 | Context.BIND_AUTO_CREATE |
| 232 | | Context.BIND_NOT_VISIBLE |
| 233 | | Context.BIND_NOT_FOREGROUND |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 234 | | Context.BIND_IMPORTANT_BACKGROUND; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * Binding flags used only while the {@link InputMethodService} is showing window. |
| 238 | */ |
| 239 | private static final int IME_VISIBLE_BIND_FLAGS = |
| 240 | Context.BIND_AUTO_CREATE |
| 241 | | Context.BIND_TREAT_LIKE_ACTIVITY |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 242 | | Context.BIND_FOREGROUND_SERVICE |
| 243 | | Context.BIND_SHOWING_UI; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 244 | |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 245 | @Retention(SOURCE) |
| 246 | @IntDef({HardKeyboardBehavior.WIRELESS_AFFORDANCE, HardKeyboardBehavior.WIRED_AFFORDANCE}) |
| 247 | private @interface HardKeyboardBehavior { |
| 248 | int WIRELESS_AFFORDANCE = 0; |
| 249 | int WIRED_AFFORDANCE = 1; |
| 250 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 251 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 252 | /** |
| 253 | * A protected broadcast intent action for internal use for {@link PendingIntent} in |
| 254 | * the notification. |
| 255 | */ |
| 256 | private static final String ACTION_SHOW_INPUT_METHOD_PICKER = |
| 257 | "com.android.server.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER"; |
| 258 | |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 259 | /** |
| 260 | * Debug flag for overriding runtime {@link SystemProperties}. |
| 261 | */ |
| 262 | @AnyThread |
| 263 | private static final class DebugFlag { |
| 264 | private static final Object LOCK = new Object(); |
| 265 | private final String mKey; |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 266 | private final boolean mDefaultValue; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 267 | @GuardedBy("LOCK") |
| 268 | private boolean mValue; |
| 269 | |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 270 | public DebugFlag(String key, boolean defaultValue) { |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 271 | mKey = key; |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 272 | mDefaultValue = defaultValue; |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 273 | mValue = SystemProperties.getBoolean(key, defaultValue); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void refresh() { |
| 277 | synchronized (LOCK) { |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 278 | mValue = SystemProperties.getBoolean(mKey, mDefaultValue); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
| 282 | boolean value() { |
| 283 | synchronized (LOCK) { |
| 284 | return mValue; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Debug flags that can be overridden using "adb shell setprop <key>" |
| 291 | * Note: These flags are cached. To refresh, run "adb shell ime refresh_debug_properties". |
| 292 | */ |
| 293 | private static final class DebugFlags { |
| 294 | static final DebugFlag FLAG_OPTIMIZE_START_INPUT = |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 295 | new DebugFlag("debug.optimize_startinput", false); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | final Context mContext; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 300 | final Resources mRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 302 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | final SettingsObserver mSettingsObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | final IWindowManager mIWindowManager; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 305 | final WindowManagerInternal mWindowManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | final HandlerCaller mCaller; |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 307 | final boolean mHasFeature; |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 308 | private InputMethodFileManager mFileManager; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 309 | private final HardKeyboardListener mHardKeyboardListener; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 310 | private final AppOpsManager mAppOpsManager; |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 311 | private final UserManager mUserManager; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | // All known input methods. mMethodMap also serves as the global |
| 314 | // lock for this class. |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 315 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>(); |
| 316 | final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<>(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 317 | private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 318 | new LruCache<>(SECURE_SUGGESTION_SPANS_MAX_SIZE); |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 319 | private final InputMethodSubtypeSwitchingController mSwitchingController; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 320 | |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 321 | /** |
| 322 | * Tracks how many times {@link #mMethodMap} was updated. |
| 323 | */ |
| 324 | @GuardedBy("mMethodMap") |
| 325 | private int mMethodMapUpdateCount = 0; |
| 326 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 327 | // Used to bring IME service up to visible adjustment while it is being shown. |
| 328 | final ServiceConnection mVisibleConnection = new ServiceConnection() { |
| 329 | @Override public void onServiceConnected(ComponentName name, IBinder service) { |
| 330 | } |
| 331 | |
| 332 | @Override public void onServiceDisconnected(ComponentName name) { |
| 333 | } |
| 334 | }; |
| 335 | boolean mVisibleBound = false; |
| 336 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 337 | // Ongoing notification |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 338 | private NotificationManager mNotificationManager; |
| 339 | private KeyguardManager mKeyguardManager; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 340 | private @Nullable StatusBarManagerService mStatusBar; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 341 | private Notification.Builder mImeSwitcherNotification; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 342 | private PendingIntent mImeSwitchPendingIntent; |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 343 | private boolean mShowOngoingImeSwitcherForPhones; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 344 | private boolean mNotificationShown; |
| 345 | |
Tadashi G. Takaoka | 8c6d477 | 2014-08-05 15:29:17 +0900 | [diff] [blame] | 346 | static class SessionState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | final ClientState client; |
| 348 | final IInputMethod method; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 349 | |
| 350 | IInputMethodSession session; |
| 351 | InputChannel channel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | @Override |
| 354 | public String toString() { |
| 355 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 356 | + " method " + Integer.toHexString( |
| 357 | System.identityHashCode(method)) |
| 358 | + " session " + Integer.toHexString( |
| 359 | System.identityHashCode(session)) |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 360 | + " channel " + channel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | + "}"; |
| 362 | } |
| 363 | |
| 364 | SessionState(ClientState _client, IInputMethod _method, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 365 | IInputMethodSession _session, InputChannel _channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | client = _client; |
| 367 | method = _method; |
| 368 | session = _session; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 369 | channel = _channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 372 | |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 373 | /** |
| 374 | * VR state callback. |
| 375 | * Listens for when VR mode finishes. |
| 376 | */ |
| 377 | private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() { |
| 378 | @Override |
| 379 | public void onVrStateChanged(boolean enabled) { |
| 380 | if (!enabled) { |
| 381 | restoreNonVrImeFromSettingsNoCheck(); |
| 382 | } |
| 383 | } |
| 384 | }; |
| 385 | |
| 386 | private void restoreNonVrImeFromSettingsNoCheck() { |
| 387 | // switch back to non-VR InputMethod from settings. |
| 388 | synchronized (mMethodMap) { |
| 389 | final String lastInputId = mSettings.getSelectedInputMethod(); |
| 390 | setInputMethodLocked(lastInputId, |
| 391 | mSettings.getSelectedInputMethodSubtypeId(lastInputId)); |
| 392 | } |
| 393 | } |
| 394 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 395 | static final class ClientState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | final IInputMethodClient client; |
| 397 | final IInputContext inputContext; |
| 398 | final int uid; |
| 399 | final int pid; |
| 400 | final InputBinding binding; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | boolean sessionRequested; |
| 403 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | @Override |
| 406 | public String toString() { |
| 407 | return "ClientState{" + Integer.toHexString( |
| 408 | System.identityHashCode(this)) + " uid " + uid |
| 409 | + " pid " + pid + "}"; |
| 410 | } |
| 411 | |
| 412 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
| 413 | int _uid, int _pid) { |
| 414 | client = _client; |
| 415 | inputContext = _inputContext; |
| 416 | uid = _uid; |
| 417 | pid = _pid; |
| 418 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
| 419 | } |
| 420 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 421 | |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 422 | final HashMap<IBinder, ClientState> mClients = new HashMap<>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 425 | * Set once the system is ready to run third party code. |
| 426 | */ |
| 427 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 428 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 429 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 430 | * Id obtained with {@link InputMethodInfo#getId()} for the currently selected input method. |
| 431 | * method. This is to be synchronized with the secure settings keyed with |
| 432 | * {@link Settings.Secure#DEFAULT_INPUT_METHOD}. |
| 433 | * |
| 434 | * <p>This can be transiently {@code null} when the system is re-initializing input method |
| 435 | * settings, e.g., the system locale is just changed.</p> |
| 436 | * |
| 437 | * <p>Note that {@link #mCurId} is used to track which IME is being connected to |
| 438 | * {@link InputMethodManagerService}.</p> |
| 439 | * |
| 440 | * @see #mCurId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 442 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | String mCurMethodId; |
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 | * The current binding sequence number, incremented every time there is |
| 447 | * a new bind performed. |
| 448 | */ |
| 449 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | /** |
| 452 | * The client that is currently bound to an input method. |
| 453 | */ |
| 454 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | /** |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 457 | * The last window token that we confirmed to be focused. This is always updated upon reports |
| 458 | * from the input method client. If the window state is already changed before the report is |
| 459 | * handled, this field just keeps the last value. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 460 | */ |
| 461 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 462 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 463 | /** |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 464 | * {@link WindowManager.LayoutParams#softInputMode} of {@link #mCurFocusedWindow}. |
| 465 | * |
| 466 | * @see #mCurFocusedWindow |
| 467 | */ |
| 468 | int mCurFocusedWindowSoftInputMode; |
| 469 | |
| 470 | /** |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 471 | * The client by which {@link #mCurFocusedWindow} was reported. |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 472 | */ |
| 473 | ClientState mCurFocusedWindowClient; |
| 474 | |
| 475 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | * The input context last provided by the current client. |
| 477 | */ |
| 478 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | /** |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 481 | * The missing method flags for the input context last provided by the current client. |
| 482 | * |
| 483 | * @see android.view.inputmethod.InputConnectionInspector.MissingMethodFlags |
| 484 | */ |
| 485 | int mCurInputContextMissingMethods; |
| 486 | |
| 487 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | * The attributes last provided by the current client. |
| 489 | */ |
| 490 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 493 | * 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] | 494 | * connected to or in the process of connecting to. |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 495 | * |
| 496 | * <p>This can be {@code null} when no input method is connected.</p> |
| 497 | * |
| 498 | * @see #mCurMethodId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 500 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | String mCurId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 504 | * The current subtype of the current input method. |
| 505 | */ |
| 506 | private InputMethodSubtype mCurrentSubtype; |
| 507 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 508 | // This list contains the pairs of InputMethodInfo and InputMethodSubtype. |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 509 | private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>> |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 510 | mShortcutInputMethodsAndSubtypes = new HashMap<>(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 511 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 512 | // Was the keyguard locked when this client became current? |
| 513 | private boolean mCurClientInKeyguard; |
| 514 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 515 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | * Set to true if our ServiceConnection is currently actively bound to |
| 517 | * a service (whether or not we have gotten its IBinder back yet). |
| 518 | */ |
| 519 | boolean mHaveConnection; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | /** |
| 522 | * Set if the client has asked for the input method to be shown. |
| 523 | */ |
| 524 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | /** |
| 527 | * Set if we were explicitly told to show the input method. |
| 528 | */ |
| 529 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | /** |
| 532 | * Set if we were forced to be shown. |
| 533 | */ |
| 534 | boolean mShowForced; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | /** |
| 537 | * Set if we last told the input method to show itself. |
| 538 | */ |
| 539 | boolean mInputShown; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | /** |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 542 | * {@code true} if the current input method is in fullscreen mode. |
| 543 | */ |
| 544 | boolean mInFullscreenMode; |
| 545 | |
| 546 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | * The Intent used to connect to the current input method. |
| 548 | */ |
| 549 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | /** |
| 552 | * The token we have made for the currently active input method, to |
| 553 | * identify it in the future. |
| 554 | */ |
| 555 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 556 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | /** |
| 558 | * If non-null, this is the input method service we are currently connected |
| 559 | * to. |
| 560 | */ |
| 561 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | /** |
| 564 | * Time that we last initiated a bind to the input method, to determine |
| 565 | * if we should try to disconnect and reconnect to it. |
| 566 | */ |
| 567 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | /** |
| 570 | * Have we called mCurMethod.bindInput()? |
| 571 | */ |
| 572 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | /** |
| 575 | * Currently enabled session. Only touched by service thread, not |
| 576 | * protected by a lock. |
| 577 | */ |
| 578 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | /** |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 581 | * 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] | 582 | */ |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 583 | boolean mIsInteractive = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 584 | |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 585 | int mCurUserActionNotificationSequenceNumber = 0; |
| 586 | |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 587 | int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 588 | |
| 589 | /** |
| 590 | * A set of status bits regarding the active IME. |
| 591 | * |
| 592 | * <p>This value is a combination of following two bits:</p> |
| 593 | * <dl> |
| 594 | * <dt>{@link InputMethodService#IME_ACTIVE}</dt> |
| 595 | * <dd> |
| 596 | * If this bit is ON, connected IME is ready to accept touch/key events. |
| 597 | * </dd> |
| 598 | * <dt>{@link InputMethodService#IME_VISIBLE}</dt> |
| 599 | * <dd> |
| 600 | * If this bit is ON, some of IME view, e.g. software input, candidate view, is visible. |
| 601 | * </dd> |
| 602 | * </dl> |
| 603 | * <em>Do not update this value outside of setImeWindowStatus.</em> |
| 604 | */ |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 605 | int mImeWindowVis; |
| 606 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 607 | private AlertDialog.Builder mDialogBuilder; |
| 608 | private AlertDialog mSwitchingDialog; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 609 | private IBinder mSwitchingDialogToken = new Binder(); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 610 | private View mSwitchingDialogTitleView; |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 611 | private Toast mSubtypeSwitchedByShortCutToast; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 612 | private InputMethodInfo[] mIms; |
| 613 | private int[] mSubtypeIds; |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 614 | private LocaleList mLastSystemLocales; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 615 | private boolean mShowImeWithHardKeyboard; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 616 | private boolean mAccessibilityRequestingNoSoftKeyboard; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 617 | private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor(); |
| 618 | private final IPackageManager mIPackageManager; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 619 | private final String mSlotIme; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 620 | @HardKeyboardBehavior |
| 621 | private final int mHardKeyboardBehavior; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 622 | |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 623 | /** |
| 624 | * Internal state snapshot when {@link #MSG_START_INPUT} message is about to be posted to the |
| 625 | * internal message queue. Any subsequent state change inside {@link InputMethodManagerService} |
| 626 | * will not affect those tasks that are already posted. |
| 627 | * |
| 628 | * <p>Posting {@link #MSG_START_INPUT} message basically means that |
| 629 | * {@link InputMethodService#doStartInput(InputConnection, EditorInfo, boolean)} will be called |
| 630 | * back in the current IME process shortly, which will also affect what the current IME starts |
| 631 | * receiving from {@link InputMethodService#getCurrentInputConnection()}. In other words, this |
| 632 | * snapshot will be taken every time when {@link InputMethodManagerService} is initiating a new |
| 633 | * logical input session between the client application and the current IME.</p> |
| 634 | * |
| 635 | * <p>Be careful to not keep strong references to this object forever, which can prevent |
| 636 | * {@link StartInputInfo#mImeToken} and {@link StartInputInfo#mTargetWindow} from being GC-ed. |
| 637 | * </p> |
| 638 | */ |
| 639 | private static class StartInputInfo { |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 640 | private static final AtomicInteger sSequenceNumber = new AtomicInteger(0); |
| 641 | |
| 642 | final int mSequenceNumber; |
| 643 | final long mTimestamp; |
| 644 | final long mWallTime; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 645 | @NonNull |
| 646 | final IBinder mImeToken; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 647 | @NonNull |
| 648 | final String mImeId; |
| 649 | // @InputMethodClient.StartInputReason |
| 650 | final int mStartInputReason; |
| 651 | final boolean mRestarting; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 652 | @Nullable |
| 653 | final IBinder mTargetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 654 | @NonNull |
| 655 | final EditorInfo mEditorInfo; |
| 656 | final int mTargetWindowSoftInputMode; |
| 657 | final int mClientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 658 | |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 659 | StartInputInfo(@NonNull IBinder imeToken, @NonNull String imeId, |
| 660 | /* @InputMethodClient.StartInputReason */ int startInputReason, boolean restarting, |
| 661 | @Nullable IBinder targetWindow, @NonNull EditorInfo editorInfo, |
| 662 | int targetWindowSoftInputMode, int clientBindSequenceNumber) { |
| 663 | mSequenceNumber = sSequenceNumber.getAndIncrement(); |
| 664 | mTimestamp = SystemClock.uptimeMillis(); |
| 665 | mWallTime = System.currentTimeMillis(); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 666 | mImeToken = imeToken; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 667 | mImeId = imeId; |
| 668 | mStartInputReason = startInputReason; |
| 669 | mRestarting = restarting; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 670 | mTargetWindow = targetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 671 | mEditorInfo = editorInfo; |
| 672 | mTargetWindowSoftInputMode = targetWindowSoftInputMode; |
| 673 | mClientBindSequenceNumber = clientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
Yohei Yukawa | b37d8bd | 2017-02-13 18:29:05 -0800 | [diff] [blame] | 677 | @GuardedBy("mMethodMap") |
| 678 | private final WeakHashMap<IBinder, StartInputInfo> mStartInputMap = new WeakHashMap<>(); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 679 | |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 680 | /** |
| 681 | * A ring buffer to store the history of {@link StartInputInfo}. |
| 682 | */ |
| 683 | private static final class StartInputHistory { |
| 684 | /** |
| 685 | * Entry size for non low-RAM devices. |
| 686 | * |
| 687 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 688 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 689 | */ |
| 690 | private final static int ENTRY_SIZE_FOR_HIGH_RAM_DEVICE = 16; |
| 691 | |
| 692 | /** |
| 693 | * Entry size for non low-RAM devices. |
| 694 | * |
| 695 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 696 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 697 | */ |
| 698 | private final static int ENTRY_SIZE_FOR_LOW_RAM_DEVICE = 5; |
| 699 | |
| 700 | private static int getEntrySize() { |
| 701 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 702 | return ENTRY_SIZE_FOR_LOW_RAM_DEVICE; |
| 703 | } else { |
| 704 | return ENTRY_SIZE_FOR_HIGH_RAM_DEVICE; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Backing store for the ring bugger. |
| 710 | */ |
| 711 | private final Entry[] mEntries = new Entry[getEntrySize()]; |
| 712 | |
| 713 | /** |
| 714 | * An index of {@link #mEntries}, to which next {@link #addEntry(StartInputInfo)} should |
| 715 | * write. |
| 716 | */ |
| 717 | private int mNextIndex = 0; |
| 718 | |
| 719 | /** |
| 720 | * Recyclable entry to store the information in {@link StartInputInfo}. |
| 721 | */ |
| 722 | private static final class Entry { |
| 723 | int mSequenceNumber; |
| 724 | long mTimestamp; |
| 725 | long mWallTime; |
| 726 | @NonNull |
| 727 | String mImeTokenString; |
| 728 | @NonNull |
| 729 | String mImeId; |
| 730 | /* @InputMethodClient.StartInputReason */ |
| 731 | int mStartInputReason; |
| 732 | boolean mRestarting; |
| 733 | @NonNull |
| 734 | String mTargetWindowString; |
| 735 | @NonNull |
| 736 | EditorInfo mEditorInfo; |
| 737 | int mTargetWindowSoftInputMode; |
| 738 | int mClientBindSequenceNumber; |
| 739 | |
| 740 | Entry(@NonNull StartInputInfo original) { |
| 741 | set(original); |
| 742 | } |
| 743 | |
| 744 | void set(@NonNull StartInputInfo original) { |
| 745 | mSequenceNumber = original.mSequenceNumber; |
| 746 | mTimestamp = original.mTimestamp; |
| 747 | mWallTime = original.mWallTime; |
| 748 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 749 | // object. |
| 750 | mImeTokenString = String.valueOf(original.mImeToken); |
| 751 | mImeId = original.mImeId; |
| 752 | mStartInputReason = original.mStartInputReason; |
| 753 | mRestarting = original.mRestarting; |
| 754 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 755 | // object. |
| 756 | mTargetWindowString = String.valueOf(original.mTargetWindow); |
| 757 | mEditorInfo = original.mEditorInfo; |
| 758 | mTargetWindowSoftInputMode = original.mTargetWindowSoftInputMode; |
| 759 | mClientBindSequenceNumber = original.mClientBindSequenceNumber; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * Add a new entry and discard the oldest entry as needed. |
| 765 | * @param info {@lin StartInputInfo} to be added. |
| 766 | */ |
| 767 | void addEntry(@NonNull StartInputInfo info) { |
| 768 | final int index = mNextIndex; |
| 769 | if (mEntries[index] == null) { |
| 770 | mEntries[index] = new Entry(info); |
| 771 | } else { |
| 772 | mEntries[index].set(info); |
| 773 | } |
| 774 | mNextIndex = (mNextIndex + 1) % mEntries.length; |
| 775 | } |
| 776 | |
| 777 | void dump(@NonNull PrintWriter pw, @NonNull String prefix) { |
| 778 | final SimpleDateFormat dataFormat = |
| 779 | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US); |
| 780 | |
| 781 | for (int i = 0; i < mEntries.length; ++i) { |
| 782 | final Entry entry = mEntries[(i + mNextIndex) % mEntries.length]; |
| 783 | if (entry == null) { |
| 784 | continue; |
| 785 | } |
| 786 | pw.print(prefix); |
| 787 | pw.println("StartInput #" + entry.mSequenceNumber + ":"); |
| 788 | |
| 789 | pw.print(prefix); |
| 790 | pw.println(" time=" + dataFormat.format(new Date(entry.mWallTime)) |
| 791 | + " (timestamp=" + entry.mTimestamp + ")" |
| 792 | + " reason=" |
| 793 | + InputMethodClient.getStartInputReason(entry.mStartInputReason) |
| 794 | + " restarting=" + entry.mRestarting); |
| 795 | |
| 796 | pw.print(prefix); |
| 797 | pw.println(" imeToken=" + entry.mImeTokenString + " [" + entry.mImeId + "]"); |
| 798 | |
| 799 | pw.print(prefix); |
| 800 | pw.println(" targetWin=" + entry.mTargetWindowString |
| 801 | + " [" + entry.mEditorInfo.packageName + "]" |
| 802 | + " clientBindSeq=" + entry.mClientBindSequenceNumber); |
| 803 | |
| 804 | pw.print(prefix); |
| 805 | pw.println(" softInputMode=" + InputMethodClient.softInputModeToString( |
| 806 | entry.mTargetWindowSoftInputMode)); |
| 807 | |
| 808 | pw.print(prefix); |
| 809 | pw.println(" inputType=0x" + Integer.toHexString(entry.mEditorInfo.inputType) |
| 810 | + " imeOptions=0x" + Integer.toHexString(entry.mEditorInfo.imeOptions) |
| 811 | + " fieldId=0x" + Integer.toHexString(entry.mEditorInfo.fieldId) |
| 812 | + " fieldName=" + entry.mEditorInfo.fieldName |
| 813 | + " actionId=" + entry.mEditorInfo.actionId |
| 814 | + " actionLabel=" + entry.mEditorInfo.actionLabel); |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | @GuardedBy("mMethodMap") |
| 820 | @NonNull |
| 821 | private final StartInputHistory mStartInputHistory = new StartInputHistory(); |
| 822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | class SettingsObserver extends ContentObserver { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 824 | int mUserId; |
| 825 | boolean mRegistered = false; |
Yohei Yukawa | 7b574cb | 2016-03-16 17:22:22 -0700 | [diff] [blame] | 826 | @NonNull |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 827 | String mLastEnabled = ""; |
| 828 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 829 | /** |
| 830 | * <em>This constructor must be called within the lock.</em> |
| 831 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | SettingsObserver(Handler handler) { |
| 833 | super(handler); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 836 | public void registerContentObserverLocked(@UserIdInt int userId) { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 837 | if (mRegistered && mUserId == userId) { |
| 838 | return; |
| 839 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | ContentResolver resolver = mContext.getContentResolver(); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 841 | if (mRegistered) { |
| 842 | mContext.getContentResolver().unregisterContentObserver(this); |
| 843 | mRegistered = false; |
| 844 | } |
| 845 | if (mUserId != userId) { |
| 846 | mLastEnabled = ""; |
| 847 | mUserId = userId; |
| 848 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 850 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, userId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 851 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 852 | Settings.Secure.ENABLED_INPUT_METHODS), false, this, userId); |
satok | b6109bb | 2011-02-03 22:24:54 +0900 | [diff] [blame] | 853 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 854 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this, userId); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 855 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 856 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this, userId); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 857 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 858 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE), false, this, userId); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 859 | mRegistered = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 861 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 862 | @Override public void onChange(boolean selfChange, Uri uri) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 863 | final Uri showImeUri = Settings.Secure.getUriFor( |
| 864 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
| 865 | final Uri accessibilityRequestingNoImeUri = Settings.Secure.getUriFor( |
| 866 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | synchronized (mMethodMap) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 868 | if (showImeUri.equals(uri)) { |
| 869 | updateKeyboardFromSettingsLocked(); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 870 | } else if (accessibilityRequestingNoImeUri.equals(uri)) { |
| 871 | mAccessibilityRequestingNoSoftKeyboard = Settings.Secure.getIntForUser( |
| 872 | mContext.getContentResolver(), |
| 873 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, |
| 874 | 0, mUserId) == 1; |
| 875 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 876 | final boolean showRequested = mShowRequested; |
| 877 | hideCurrentInputLocked(0, null); |
| 878 | mShowRequested = showRequested; |
| 879 | } else if (mShowRequested) { |
| 880 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 881 | } |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 882 | } else { |
| 883 | boolean enabledChanged = false; |
| 884 | String newEnabled = mSettings.getEnabledInputMethodsStr(); |
| 885 | if (!mLastEnabled.equals(newEnabled)) { |
| 886 | mLastEnabled = newEnabled; |
| 887 | enabledChanged = true; |
| 888 | } |
| 889 | updateInputMethodsFromSettingsLocked(enabledChanged); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 890 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | } |
| 892 | } |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 893 | |
| 894 | @Override |
| 895 | public String toString() { |
| 896 | return "SettingsObserver{mUserId=" + mUserId + " mRegistered=" + mRegistered |
| 897 | + " mLastEnabled=" + mLastEnabled + "}"; |
| 898 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 900 | |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 901 | class ImmsBroadcastReceiver extends BroadcastReceiver { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 902 | @Override |
| 903 | public void onReceive(Context context, Intent intent) { |
| 904 | final String action = intent.getAction(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 905 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 906 | hideInputMethodMenu(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 907 | // No need to update mIsInteractive |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 908 | return; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 909 | } else if (Intent.ACTION_USER_ADDED.equals(action) |
| 910 | || Intent.ACTION_USER_REMOVED.equals(action)) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 911 | updateCurrentProfileIds(); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 912 | return; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 913 | } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 914 | onActionLocaleChanged(); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 915 | } else if (ACTION_SHOW_INPUT_METHOD_PICKER.equals(action)) { |
| 916 | // ACTION_SHOW_INPUT_METHOD_PICKER action is a protected-broadcast and it is |
| 917 | // guaranteed to be send only from the system, so that there is no need for extra |
| 918 | // security check such as |
| 919 | // {@link #canShowInputMethodPickerLocked(IInputMethodClient)}. |
| 920 | mHandler.obtainMessage( |
| 921 | MSG_SHOW_IM_SUBTYPE_PICKER, |
| 922 | InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES, |
| 923 | 0 /* arg2 */) |
| 924 | .sendToTarget(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 925 | } else { |
| 926 | Slog.w(TAG, "Unexpected intent " + intent); |
| 927 | } |
| 928 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 930 | |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 931 | /** |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 932 | * Start a VR InputMethod that matches IME with package name of {@param component}. |
Yohei Yukawa | 7a46c28 | 2017-12-10 18:15:19 -0800 | [diff] [blame] | 933 | * Note: This method is called from {@link android.app.VrManager}. |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 934 | */ |
| 935 | private void startVrInputMethodNoCheck(@Nullable ComponentName component) { |
| 936 | if (component == null) { |
| 937 | // clear the current VR-only IME (if any) and restore normal IME. |
| 938 | restoreNonVrImeFromSettingsNoCheck(); |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | synchronized (mMethodMap) { |
| 943 | String packageName = component.getPackageName(); |
| 944 | for (InputMethodInfo info : mMethodList) { |
| 945 | if (TextUtils.equals(info.getPackageName(), packageName) && info.isVrOnly()) { |
| 946 | // set this is as current inputMethod without updating settings. |
Yohei Yukawa | 7a46c28 | 2017-12-10 18:15:19 -0800 | [diff] [blame] | 947 | setInputMethodEnabledLocked(info.getId(), true); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 948 | setInputMethodLocked(info.getId(), NOT_A_SUBTYPE_ID); |
| 949 | break; |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | /** |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 956 | * Handles {@link Intent#ACTION_LOCALE_CHANGED}. |
| 957 | * |
| 958 | * <p>Note: For historical reasons, {@link Intent#ACTION_LOCALE_CHANGED} has been sent to all |
| 959 | * the users. We should ignore this event if this is about any background user's locale.</p> |
| 960 | * |
| 961 | * <p>Caution: This method must not be called when system is not ready.</p> |
| 962 | */ |
| 963 | void onActionLocaleChanged() { |
| 964 | synchronized (mMethodMap) { |
| 965 | final LocaleList possibleNewLocale = mRes.getConfiguration().getLocales(); |
| 966 | if (possibleNewLocale != null && possibleNewLocale.equals(mLastSystemLocales)) { |
| 967 | return; |
| 968 | } |
| 969 | buildInputMethodListLocked(true); |
| 970 | // If the locale is changed, needs to reset the default ime |
| 971 | resetDefaultImeLocked(mContext); |
| 972 | updateFromSettingsLocked(true); |
| 973 | mLastSystemLocales = possibleNewLocale; |
| 974 | } |
| 975 | } |
| 976 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 977 | final class MyPackageMonitor extends PackageMonitor { |
| 978 | /** |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 979 | * Package names that are known to contain {@link InputMethodService}. |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 980 | * |
| 981 | * <p>No need to include packages because of direct-boot unaware IMEs since we always rescan |
| 982 | * all the packages when the user is unlocked, and direct-boot awareness will not be changed |
| 983 | * dynamically unless the entire package is updated, which also always triggers package |
| 984 | * rescanning.</p> |
| 985 | */ |
| 986 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 987 | final private ArraySet<String> mKnownImePackageNames = new ArraySet<>(); |
| 988 | |
| 989 | /** |
| 990 | * Packages that are appeared, disappeared, or modified for whatever reason. |
| 991 | * |
| 992 | * <p>Note: For now we intentionally use {@link ArrayList} instead of {@link ArraySet} |
| 993 | * because 1) the number of elements is almost always 1 or so, and 2) we do not care |
| 994 | * duplicate elements for our use case.</p> |
| 995 | * |
| 996 | * <p>This object must be accessed only from callback methods in {@link PackageMonitor}, |
| 997 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 998 | */ |
| 999 | private final ArrayList<String> mChangedPackages = new ArrayList<>(); |
| 1000 | |
| 1001 | /** |
| 1002 | * {@code true} if one or more packages that contain {@link InputMethodService} appeared. |
| 1003 | * |
| 1004 | * <p>This field must be accessed only from callback methods in {@link PackageMonitor}, |
| 1005 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 1006 | */ |
| 1007 | private boolean mImePackageAppeared = false; |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1008 | |
| 1009 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1010 | void clearKnownImePackageNamesLocked() { |
| 1011 | mKnownImePackageNames.clear(); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1015 | final void addKnownImePackageNameLocked(@NonNull String packageName) { |
| 1016 | mKnownImePackageNames.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1017 | } |
| 1018 | |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1019 | @GuardedBy("mMethodMap") |
| 1020 | private boolean isChangingPackagesOfCurrentUserLocked() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1021 | final int userId = getChangingUserId(); |
| 1022 | final boolean retval = userId == mSettings.getCurrentUserId(); |
| 1023 | if (DEBUG) { |
satok | 81f8b7c | 2012-12-04 20:42:56 +0900 | [diff] [blame] | 1024 | if (!retval) { |
| 1025 | Slog.d(TAG, "--- ignore this call back from a background user: " + userId); |
| 1026 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1027 | } |
| 1028 | return retval; |
| 1029 | } |
| 1030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1032 | 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] | 1033 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1034 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1035 | return false; |
| 1036 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1037 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | final int N = mMethodList.size(); |
| 1039 | if (curInputMethodId != null) { |
| 1040 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1041 | InputMethodInfo imi = mMethodList.get(i); |
| 1042 | if (imi.getId().equals(curInputMethodId)) { |
| 1043 | for (String pkg : packages) { |
| 1044 | if (imi.getPackageName().equals(pkg)) { |
| 1045 | if (!doit) { |
| 1046 | return true; |
| 1047 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1048 | resetSelectedInputMethodAndSubtypeLocked(""); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1049 | chooseNewDefaultIMELocked(); |
| 1050 | return true; |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | return false; |
| 1058 | } |
| 1059 | |
| 1060 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1061 | public void onBeginPackageChanges() { |
| 1062 | clearPackageChangeState(); |
| 1063 | } |
| 1064 | |
| 1065 | @Override |
| 1066 | public void onPackageAppeared(String packageName, int reason) { |
| 1067 | if (!mImePackageAppeared) { |
| 1068 | final PackageManager pm = mContext.getPackageManager(); |
| 1069 | final List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
| 1070 | new Intent(InputMethod.SERVICE_INTERFACE).setPackage(packageName), |
| 1071 | PackageManager.MATCH_DISABLED_COMPONENTS, getChangingUserId()); |
| 1072 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1073 | if (!services.isEmpty()) { |
| 1074 | mImePackageAppeared = true; |
| 1075 | } |
| 1076 | } |
| 1077 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1078 | mChangedPackages.add(packageName); |
| 1079 | } |
| 1080 | |
| 1081 | @Override |
| 1082 | public void onPackageDisappeared(String packageName, int reason) { |
| 1083 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1084 | mChangedPackages.add(packageName); |
| 1085 | } |
| 1086 | |
| 1087 | @Override |
| 1088 | public void onPackageModified(String packageName) { |
| 1089 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1090 | mChangedPackages.add(packageName); |
| 1091 | } |
| 1092 | |
| 1093 | @Override |
| 1094 | public void onPackagesSuspended(String[] packages) { |
| 1095 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1096 | for (String packageName : packages) { |
| 1097 | mChangedPackages.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1102 | public void onPackagesUnsuspended(String[] packages) { |
| 1103 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1104 | for (String packageName : packages) { |
| 1105 | mChangedPackages.add(packageName); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | @Override |
| 1110 | public void onFinishPackageChanges() { |
| 1111 | onFinishPackageChangesInternal(); |
| 1112 | clearPackageChangeState(); |
| 1113 | } |
| 1114 | |
| 1115 | private void clearPackageChangeState() { |
| 1116 | // No need to lock them because we access these fields only on getRegisteredHandler(). |
| 1117 | mChangedPackages.clear(); |
| 1118 | mImePackageAppeared = false; |
| 1119 | } |
| 1120 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1121 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1122 | private boolean shouldRebuildInputMethodListLocked() { |
| 1123 | // This method is guaranteed to be called only by getRegisteredHandler(). |
| 1124 | |
| 1125 | // If there is any new package that contains at least one IME, then rebuilt the list |
| 1126 | // of IMEs. |
| 1127 | if (mImePackageAppeared) { |
| 1128 | return true; |
| 1129 | } |
| 1130 | |
| 1131 | // Otherwise, check if mKnownImePackageNames and mChangedPackages have any intersection. |
| 1132 | // TODO: Consider to create a utility method to do the following test. List.retainAll() |
| 1133 | // is an option, but it may still do some extra operations that we do not need here. |
| 1134 | final int N = mChangedPackages.size(); |
| 1135 | for (int i = 0; i < N; ++i) { |
| 1136 | final String packageName = mChangedPackages.get(i); |
| 1137 | if (mKnownImePackageNames.contains(packageName)) { |
| 1138 | return true; |
| 1139 | } |
| 1140 | } |
| 1141 | return false; |
| 1142 | } |
| 1143 | |
| 1144 | private void onFinishPackageChangesInternal() { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1145 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1146 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1147 | return; |
| 1148 | } |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1149 | if (!shouldRebuildInputMethodListLocked()) { |
| 1150 | return; |
| 1151 | } |
| 1152 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1153 | InputMethodInfo curIm = null; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1154 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1155 | final int N = mMethodList.size(); |
| 1156 | if (curInputMethodId != null) { |
| 1157 | for (int i=0; i<N; i++) { |
| 1158 | InputMethodInfo imi = mMethodList.get(i); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1159 | final String imiId = imi.getId(); |
| 1160 | if (imiId.equals(curInputMethodId)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1161 | curIm = imi; |
| 1162 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1163 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1164 | int change = isPackageDisappearing(imi.getPackageName()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1165 | if (isPackageModified(imi.getPackageName())) { |
| 1166 | mFileManager.deleteAllInputMethodSubtypes(imiId); |
| 1167 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1168 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1169 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1170 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1171 | + imi.getComponent()); |
| 1172 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1176 | |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 1177 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1180 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1181 | if (curIm != null) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1182 | int change = isPackageDisappearing(curIm.getPackageName()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1183 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1184 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1185 | ServiceInfo si = null; |
| 1186 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1187 | si = mIPackageManager.getServiceInfo( |
| 1188 | curIm.getComponent(), 0, mSettings.getCurrentUserId()); |
| 1189 | } catch (RemoteException ex) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1190 | } |
| 1191 | if (si == null) { |
| 1192 | // Uh oh, current input method is no longer around! |
| 1193 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1194 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1195 | updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1196 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1197 | changed = true; |
| 1198 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1199 | Slog.i(TAG, "Unsetting current input method"); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1200 | resetSelectedInputMethodAndSubtypeLocked(""); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1201 | } |
| 1202 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1203 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1204 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1205 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1206 | if (curIm == null) { |
| 1207 | // We currently don't have a default input method... is |
| 1208 | // one now available? |
| 1209 | changed = chooseNewDefaultIMELocked(); |
Yohei Yukawa | 54d512c | 2015-05-19 22:15:02 -0700 | [diff] [blame] | 1210 | } else if (!changed && isPackageModified(curIm.getPackageName())) { |
| 1211 | // Even if the current input method is still available, mCurrentSubtype could |
| 1212 | // be obsolete when the package is modified in practice. |
| 1213 | changed = true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1214 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1215 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1216 | if (changed) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1217 | updateFromSettingsLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1222 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1223 | private static final class MethodCallback extends IInputSessionCallback.Stub { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1224 | private final InputMethodManagerService mParentIMMS; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1225 | private final IInputMethod mMethod; |
| 1226 | private final InputChannel mChannel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1227 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1228 | MethodCallback(InputMethodManagerService imms, IInputMethod method, |
| 1229 | InputChannel channel) { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1230 | mParentIMMS = imms; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1231 | mMethod = method; |
| 1232 | mChannel = channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1234 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1235 | @Override |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1236 | public void sessionCreated(IInputMethodSession session) { |
Dianne Hackborn | 6b6b3fd | 2014-03-24 11:27:18 -0700 | [diff] [blame] | 1237 | long ident = Binder.clearCallingIdentity(); |
| 1238 | try { |
| 1239 | mParentIMMS.onSessionCreated(mMethod, session, mChannel); |
| 1240 | } finally { |
| 1241 | Binder.restoreCallingIdentity(ident); |
| 1242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | } |
| 1244 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1245 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1246 | private class HardKeyboardListener |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1247 | implements WindowManagerInternal.OnHardKeyboardStatusChangeListener { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1248 | @Override |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1249 | public void onHardKeyboardStatusChange(boolean available) { |
| 1250 | mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED, |
| 1251 | available ? 1 : 0)); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1252 | } |
| 1253 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1254 | public void handleHardKeyboardStatusChange(boolean available) { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1255 | if (DEBUG) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1256 | Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1257 | } |
| 1258 | synchronized(mMethodMap) { |
| 1259 | if (mSwitchingDialog != null && mSwitchingDialogTitleView != null |
| 1260 | && mSwitchingDialog.isShowing()) { |
| 1261 | mSwitchingDialogTitleView.findViewById( |
| 1262 | com.android.internal.R.id.hard_keyboard_section).setVisibility( |
| 1263 | available ? View.VISIBLE : View.GONE); |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | } |
| 1268 | |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1269 | public static final class Lifecycle extends SystemService { |
| 1270 | private InputMethodManagerService mService; |
| 1271 | |
| 1272 | public Lifecycle(Context context) { |
| 1273 | super(context); |
| 1274 | mService = new InputMethodManagerService(context); |
| 1275 | } |
| 1276 | |
| 1277 | @Override |
| 1278 | public void onStart() { |
| 1279 | LocalServices.addService(InputMethodManagerInternal.class, |
| 1280 | new LocalServiceImpl(mService.mHandler)); |
| 1281 | publishBinderService(Context.INPUT_METHOD_SERVICE, mService); |
| 1282 | } |
| 1283 | |
| 1284 | @Override |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1285 | public void onSwitchUser(@UserIdInt int userHandle) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1286 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1287 | // TODO: Dispatch this to a worker thread as needed. |
| 1288 | mService.onSwitchUser(userHandle); |
| 1289 | } |
| 1290 | |
| 1291 | @Override |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1292 | public void onBootPhase(int phase) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1293 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1294 | // TODO: Dispatch this to a worker thread as needed. |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1295 | if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { |
| 1296 | StatusBarManagerService statusBarService = (StatusBarManagerService) ServiceManager |
| 1297 | .getService(Context.STATUS_BAR_SERVICE); |
| 1298 | mService.systemRunning(statusBarService); |
| 1299 | } |
| 1300 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1301 | |
| 1302 | @Override |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1303 | public void onUnlockUser(final @UserIdInt int userHandle) { |
| 1304 | // Called on ActivityManager thread. |
| 1305 | mService.mHandler.sendMessage(mService.mHandler.obtainMessage(MSG_SYSTEM_UNLOCK_USER, |
Fyodor Kupolov | 0f57cce | 2016-09-09 10:36:30 -0700 | [diff] [blame] | 1306 | userHandle /* arg1 */, 0 /* arg2 */)); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1310 | void onUnlockUser(@UserIdInt int userId) { |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1311 | synchronized(mMethodMap) { |
| 1312 | final int currentUserId = mSettings.getCurrentUserId(); |
| 1313 | if (DEBUG) { |
| 1314 | Slog.d(TAG, "onUnlockUser: userId=" + userId + " curUserId=" + currentUserId); |
| 1315 | } |
| 1316 | if (userId != currentUserId) { |
| 1317 | return; |
| 1318 | } |
| 1319 | mSettings.switchCurrentUser(currentUserId, !mSystemReady); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1320 | if (mSystemReady) { |
| 1321 | // We need to rebuild IMEs. |
| 1322 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
| 1323 | updateInputMethodsFromSettingsLocked(true /* enabledChanged */); |
| 1324 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1325 | } |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1328 | void onSwitchUser(@UserIdInt int userId) { |
| 1329 | synchronized (mMethodMap) { |
| 1330 | switchUserLocked(userId); |
| 1331 | } |
| 1332 | } |
| 1333 | |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1334 | public InputMethodManagerService(Context context) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1335 | mIPackageManager = AppGlobals.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | mContext = context; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1337 | mRes = context.getResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | mHandler = new Handler(this); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1339 | // Note: SettingsObserver doesn't register observers in its constructor. |
| 1340 | mSettingsObserver = new SettingsObserver(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 1342 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1343 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1344 | mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1345 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1346 | public void executeMessage(Message msg) { |
| 1347 | handleMessage(msg); |
| 1348 | } |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1349 | }, true /*asyncHandler*/); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1350 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1351 | mUserManager = mContext.getSystemService(UserManager.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1352 | mHardKeyboardListener = new HardKeyboardListener(); |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 1353 | mHasFeature = context.getPackageManager().hasSystemFeature( |
| 1354 | PackageManager.FEATURE_INPUT_METHODS); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1355 | mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 1356 | mHardKeyboardBehavior = mContext.getResources().getInteger( |
| 1357 | com.android.internal.R.integer.config_externalHardKeyboardBehavior); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1358 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1359 | Bundle extras = new Bundle(); |
| 1360 | extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1361 | @ColorInt final int accentColor = mContext.getColor( |
| 1362 | com.android.internal.R.color.system_notification_accent_color); |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 1363 | mImeSwitcherNotification = |
| 1364 | new Notification.Builder(mContext, SystemNotificationChannels.VIRTUAL_KEYBOARD) |
| 1365 | .setSmallIcon(com.android.internal.R.drawable.ic_notification_ime_default) |
| 1366 | .setWhen(0) |
| 1367 | .setOngoing(true) |
| 1368 | .addExtras(extras) |
| 1369 | .setCategory(Notification.CATEGORY_SYSTEM) |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1370 | .setColor(accentColor); |
Daniel Sandler | 590d515 | 2012-06-14 16:10:13 -0400 | [diff] [blame] | 1371 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1372 | Intent intent = new Intent(ACTION_SHOW_INPUT_METHOD_PICKER) |
| 1373 | .setPackage(mContext.getPackageName()); |
satok | 683e238 | 2011-07-12 08:28:52 +0900 | [diff] [blame] | 1374 | mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1375 | |
| 1376 | mShowOngoingImeSwitcherForPhones = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1377 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1378 | mNotificationShown = false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1379 | int userId = 0; |
| 1380 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1381 | userId = ActivityManager.getService().getCurrentUser().id; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1382 | } catch (RemoteException e) { |
| 1383 | Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e); |
| 1384 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1385 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1386 | // mSettings should be created before buildInputMethodListLocked |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 1387 | mSettings = new InputMethodSettings( |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1388 | mRes, context.getContentResolver(), mMethodMap, mMethodList, userId, !mSystemReady); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1389 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1390 | updateCurrentProfileIds(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1391 | mFileManager = new InputMethodFileManager(mMethodMap, userId); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1392 | mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked( |
| 1393 | mSettings, context); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 1394 | // Register VR-state listener. |
| 1395 | IVrManager vrManager = (IVrManager) ServiceManager.getService(Context.VR_SERVICE); |
| 1396 | if (vrManager != null) { |
| 1397 | try { |
| 1398 | vrManager.registerListener(mVrStateCallbacks); |
| 1399 | } catch (RemoteException e) { |
| 1400 | Slog.e(TAG, "Failed to register VR mode state listener."); |
| 1401 | } |
| 1402 | } |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1403 | } |
| 1404 | |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1405 | private void resetDefaultImeLocked(Context context) { |
| 1406 | // 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] | 1407 | if (mCurMethodId != null && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) { |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1408 | return; |
| 1409 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1410 | final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes( |
Yohei Yukawa | af5cee8 | 2017-01-23 16:17:11 -0800 | [diff] [blame] | 1411 | context, mSettings.getEnabledInputMethodListLocked()); |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1412 | if (suitableImes.isEmpty()) { |
| 1413 | Slog.i(TAG, "No default found"); |
| 1414 | return; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1415 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1416 | final InputMethodInfo defIm = suitableImes.get(0); |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1417 | if (DEBUG) { |
| 1418 | Slog.i(TAG, "Default found, using " + defIm.getId()); |
| 1419 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1420 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1421 | } |
| 1422 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1423 | @GuardedBy("mMethodMap") |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1424 | private void switchUserLocked(int newUserId) { |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1425 | if (DEBUG) Slog.d(TAG, "Switching user stage 1/3. newUserId=" + newUserId |
| 1426 | + " currentUserId=" + mSettings.getCurrentUserId()); |
| 1427 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1428 | // ContentObserver should be registered again when the user is changed |
| 1429 | mSettingsObserver.registerContentObserverLocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1430 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1431 | // If the system is not ready or the device is not yed unlocked by the user, then we use |
| 1432 | // copy-on-write settings. |
| 1433 | final boolean useCopyOnWriteSettings = |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1434 | !mSystemReady || !mUserManager.isUserUnlockingOrUnlocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1435 | mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1436 | updateCurrentProfileIds(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1437 | // InputMethodFileManager should be reset when the user is changed |
| 1438 | mFileManager = new InputMethodFileManager(mMethodMap, newUserId); |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 1439 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1440 | |
| 1441 | if (DEBUG) Slog.d(TAG, "Switching user stage 2/3. newUserId=" + newUserId |
| 1442 | + " defaultImiId=" + defaultImiId); |
| 1443 | |
Satoshi Kataoka | 7c4a2a1 | 2013-02-25 15:25:43 +0900 | [diff] [blame] | 1444 | // For secondary users, the list of enabled IMEs may not have been updated since the |
| 1445 | // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may |
| 1446 | // not be empty even if the IME has been uninstalled by the primary user. |
| 1447 | // Even in such cases, IMMS works fine because it will find the most applicable |
| 1448 | // IME for that user. |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1449 | final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1450 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
| 1451 | |
| 1452 | // TODO: Is it really possible that switchUserLocked() happens before system ready? |
| 1453 | if (mSystemReady) { |
| 1454 | hideCurrentInputLocked(0, null); |
| 1455 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_USER); |
| 1456 | buildInputMethodListLocked(initialUserSwitch); |
| 1457 | if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) { |
| 1458 | // This is the first time of the user switch and |
| 1459 | // set the current ime to the proper one. |
| 1460 | resetDefaultImeLocked(mContext); |
| 1461 | } |
| 1462 | updateFromSettingsLocked(true); |
| 1463 | try { |
| 1464 | startInputInnerLocked(); |
| 1465 | } catch (RuntimeException e) { |
| 1466 | Slog.w(TAG, "Unexpected exception", e); |
| 1467 | } |
| 1468 | } |
| 1469 | |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1470 | if (initialUserSwitch) { |
Yohei Yukawa | 094c71f | 2015-06-20 00:41:31 -0700 | [diff] [blame] | 1471 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1472 | mSettings.getEnabledInputMethodListLocked(), newUserId, |
| 1473 | mContext.getBasePackageName()); |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1474 | } |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1475 | |
| 1476 | if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId |
| 1477 | + " selectedIme=" + mSettings.getSelectedInputMethod()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1478 | } |
| 1479 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1480 | void updateCurrentProfileIds() { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 1481 | mSettings.setCurrentProfileIds( |
| 1482 | mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId())); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1483 | } |
| 1484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | @Override |
| 1486 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1487 | throws RemoteException { |
| 1488 | try { |
| 1489 | return super.onTransact(code, data, reply, flags); |
| 1490 | } catch (RuntimeException e) { |
| 1491 | // The input method manager only throws security exceptions, so let's |
| 1492 | // log all others. |
| 1493 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 164371f | 2013-10-01 19:10:13 -0700 | [diff] [blame] | 1494 | Slog.wtf(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | } |
| 1496 | throw e; |
| 1497 | } |
| 1498 | } |
| 1499 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 1500 | public void systemRunning(StatusBarManagerService statusBar) { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1501 | synchronized (mMethodMap) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1502 | if (DEBUG) { |
| 1503 | Slog.d(TAG, "--- systemReady"); |
| 1504 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1505 | if (!mSystemReady) { |
| 1506 | mSystemReady = true; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1507 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1508 | final int currentUserId = mSettings.getCurrentUserId(); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1509 | mSettings.switchCurrentUser(currentUserId, |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1510 | !mUserManager.isUserUnlockingOrUnlocked(currentUserId)); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1511 | mKeyguardManager = mContext.getSystemService(KeyguardManager.class); |
| 1512 | mNotificationManager = mContext.getSystemService(NotificationManager.class); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1513 | mStatusBar = statusBar; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 1514 | if (mStatusBar != null) { |
| 1515 | mStatusBar.setIconVisibility(mSlotIme, false); |
| 1516 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1517 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1518 | mShowOngoingImeSwitcherForPhones = mRes.getBoolean( |
| 1519 | com.android.internal.R.bool.show_ongoing_ime_switcher); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1520 | if (mShowOngoingImeSwitcherForPhones) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1521 | mWindowManagerInternal.setOnHardKeyboardStatusChangeListener( |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1522 | mHardKeyboardListener); |
| 1523 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1524 | |
| 1525 | mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true); |
| 1526 | mSettingsObserver.registerContentObserverLocked(currentUserId); |
| 1527 | |
| 1528 | final IntentFilter broadcastFilter = new IntentFilter(); |
| 1529 | broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 1530 | broadcastFilter.addAction(Intent.ACTION_USER_ADDED); |
| 1531 | broadcastFilter.addAction(Intent.ACTION_USER_REMOVED); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1532 | broadcastFilter.addAction(Intent.ACTION_LOCALE_CHANGED); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1533 | broadcastFilter.addAction(ACTION_SHOW_INPUT_METHOD_PICKER); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1534 | mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter); |
| 1535 | |
Yohei Yukawa | 1f9a3cb | 2017-10-26 15:00:59 -0700 | [diff] [blame] | 1536 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
| 1537 | final boolean imeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId); |
| 1538 | buildInputMethodListLocked(!imeSelectedOnBoot /* resetDefaultEnabledIme */); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1539 | resetDefaultImeLocked(mContext); |
| 1540 | updateFromSettingsLocked(true); |
| 1541 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1542 | mSettings.getEnabledInputMethodListLocked(), currentUserId, |
| 1543 | mContext.getBasePackageName()); |
| 1544 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1545 | try { |
| 1546 | startInputInnerLocked(); |
| 1547 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1548 | Slog.w(TAG, "Unexpected exception", e); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1549 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1550 | } |
| 1551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1553 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1554 | // --------------------------------------------------------------------------------------- |
| 1555 | // Check whether or not this is a valid IPC. Assumes an IPC is valid when either |
| 1556 | // 1) it comes from the system process |
| 1557 | // 2) the calling process' user id is identical to the current user id IMMS thinks. |
| 1558 | private boolean calledFromValidUser() { |
| 1559 | final int uid = Binder.getCallingUid(); |
| 1560 | final int userId = UserHandle.getUserId(uid); |
| 1561 | if (DEBUG) { |
| 1562 | Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? " |
| 1563 | + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID |
| 1564 | + " calling userId = " + userId + ", foreground user id = " |
Satoshi Kataoka | 87c2914 | 2013-07-31 23:11:54 +0900 | [diff] [blame] | 1565 | + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid() |
| 1566 | + InputMethodUtils.getApiCallStack()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1567 | } |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1568 | if (uid == Process.SYSTEM_UID || mSettings.isCurrentProfile(userId)) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1569 | return true; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1570 | } |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1571 | |
| 1572 | // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the |
| 1573 | // foreground user, not for the user of that process. Accordingly InputMethodManagerService |
| 1574 | // must not manage background users' states in any functions. |
| 1575 | // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded |
| 1576 | // by a token. |
| 1577 | if (mContext.checkCallingOrSelfPermission( |
| 1578 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 1579 | == PackageManager.PERMISSION_GRANTED) { |
| 1580 | if (DEBUG) { |
| 1581 | Slog.d(TAG, "--- Access granted because the calling process has " |
| 1582 | + "the INTERACT_ACROSS_USERS_FULL permission"); |
| 1583 | } |
| 1584 | return true; |
| 1585 | } |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1586 | // 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] | 1587 | Slog.w(TAG, "--- IPC called from background users. Ignore. callers=" |
| 1588 | + Debug.getCallers(10)); |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1589 | return false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1590 | } |
| 1591 | |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1592 | |
| 1593 | /** |
| 1594 | * Returns true iff the caller is identified to be the current input method with the token. |
| 1595 | * @param token The window token given to the input method when it was started. |
| 1596 | * @return true if and only if non-null valid token is specified. |
| 1597 | */ |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1598 | private boolean calledWithValidToken(@Nullable IBinder token) { |
| 1599 | if (token == null && Binder.getCallingPid() == Process.myPid()) { |
| 1600 | if (DEBUG) { |
| 1601 | // TODO(b/34851776): Basically it's the caller's fault if we reach here. |
| 1602 | Slog.d(TAG, "Bug 34851776 is detected callers=" + Debug.getCallers(10)); |
| 1603 | } |
| 1604 | return false; |
| 1605 | } |
| 1606 | if (token == null || token != mCurToken) { |
| 1607 | // TODO(b/34886274): The semantics of this verification is actually not well-defined. |
| 1608 | Slog.e(TAG, "Ignoring " + Debug.getCaller() + " due to an invalid token." |
| 1609 | + " uid:" + Binder.getCallingUid() + " token:" + token); |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1610 | return false; |
| 1611 | } |
| 1612 | return true; |
| 1613 | } |
| 1614 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1615 | private boolean bindCurrentInputMethodService( |
| 1616 | Intent service, ServiceConnection conn, int flags) { |
| 1617 | if (service == null || conn == null) { |
| 1618 | Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn); |
| 1619 | return false; |
| 1620 | } |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1621 | return mContext.bindServiceAsUser(service, conn, flags, |
| 1622 | new UserHandle(mSettings.getCurrentUserId())); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1623 | } |
| 1624 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1625 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | public List<InputMethodInfo> getInputMethodList() { |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 1627 | return getInputMethodList(false /* isVrOnly */); |
| 1628 | } |
| 1629 | |
| 1630 | public List<InputMethodInfo> getVrInputMethodList() { |
| 1631 | return getInputMethodList(true /* isVrOnly */); |
| 1632 | } |
| 1633 | |
| 1634 | private List<InputMethodInfo> getInputMethodList(final boolean isVrOnly) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1635 | // TODO: Make this work even for non-current users? |
| 1636 | if (!calledFromValidUser()) { |
| 1637 | return Collections.emptyList(); |
| 1638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | synchronized (mMethodMap) { |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 1640 | ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 1641 | for (InputMethodInfo info : mMethodList) { |
| 1642 | |
| 1643 | if (info.isVrOnly() == isVrOnly) { |
| 1644 | methodList.add(info); |
| 1645 | } |
| 1646 | } |
| 1647 | return methodList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1651 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | public List<InputMethodInfo> getEnabledInputMethodList() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1653 | // TODO: Make this work even for non-current users? |
| 1654 | if (!calledFromValidUser()) { |
| 1655 | return Collections.emptyList(); |
| 1656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | synchronized (mMethodMap) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1658 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | } |
| 1660 | } |
| 1661 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1662 | /** |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1663 | * @param imiId if null, returns enabled subtypes for the current imi |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1664 | * @return enabled subtypes of the specified imi |
| 1665 | */ |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1666 | @Override |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1667 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId, |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 1668 | boolean allowsImplicitlySelectedSubtypes) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1669 | // TODO: Make this work even for non-current users? |
| 1670 | if (!calledFromValidUser()) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1671 | return Collections.emptyList(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1672 | } |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1673 | synchronized (mMethodMap) { |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1674 | final InputMethodInfo imi; |
| 1675 | if (imiId == null && mCurMethodId != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1676 | imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1677 | } else { |
| 1678 | imi = mMethodMap.get(imiId); |
| 1679 | } |
| 1680 | if (imi == null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1681 | return Collections.emptyList(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1682 | } |
| 1683 | return mSettings.getEnabledInputMethodSubtypeListLocked( |
| 1684 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1688 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | public void addClient(IInputMethodClient client, |
| 1690 | IInputContext inputContext, int uid, int pid) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1691 | if (!calledFromValidUser()) { |
| 1692 | return; |
| 1693 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | synchronized (mMethodMap) { |
| 1695 | mClients.put(client.asBinder(), new ClientState(client, |
| 1696 | inputContext, uid, pid)); |
| 1697 | } |
| 1698 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1699 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1700 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | public void removeClient(IInputMethodClient client) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1702 | if (!calledFromValidUser()) { |
| 1703 | return; |
| 1704 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | synchronized (mMethodMap) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1706 | ClientState cs = mClients.remove(client.asBinder()); |
| 1707 | if (cs != null) { |
| 1708 | clearClientSessionLocked(cs); |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 1709 | if (mCurClient == cs) { |
Tarandeep Singh | 93c00cea | 2018-02-16 14:31:17 -0800 | [diff] [blame] | 1710 | if (mBoundToMethod) { |
| 1711 | mBoundToMethod = false; |
| 1712 | if (mCurMethod != null) { |
| 1713 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1714 | MSG_UNBIND_INPUT, mCurMethod)); |
| 1715 | } |
| 1716 | } |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 1717 | mCurClient = null; |
| 1718 | } |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 1719 | if (mCurFocusedWindowClient == cs) { |
| 1720 | mCurFocusedWindowClient = null; |
| 1721 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | } |
| 1724 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1726 | void executeOrSendMessage(IInterface target, Message msg) { |
| 1727 | if (target.asBinder() instanceof Binder) { |
| 1728 | mCaller.sendMessage(msg); |
| 1729 | } else { |
| 1730 | handleMessage(msg); |
| 1731 | msg.recycle(); |
| 1732 | } |
| 1733 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1734 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1735 | void unbindCurrentClientLocked( |
| 1736 | /* @InputMethodClient.UnbindReason */ final int unbindClientReason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1737 | if (mCurClient != null) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1738 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | + mCurClient.client.asBinder()); |
| 1740 | if (mBoundToMethod) { |
| 1741 | mBoundToMethod = false; |
| 1742 | if (mCurMethod != null) { |
| 1743 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1744 | MSG_UNBIND_INPUT, mCurMethod)); |
| 1745 | } |
| 1746 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 1747 | |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 1748 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 1749 | MSG_SET_ACTIVE, 0, 0, mCurClient)); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1750 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 1751 | MSG_UNBIND_CLIENT, mCurSeq, unbindClientReason, mCurClient.client)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1752 | mCurClient.sessionRequested = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | mCurClient = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1754 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1755 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1756 | } |
| 1757 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1758 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | private int getImeShowFlags() { |
| 1760 | int flags = 0; |
| 1761 | if (mShowForced) { |
| 1762 | flags |= InputMethod.SHOW_FORCED |
| 1763 | | InputMethod.SHOW_EXPLICIT; |
| 1764 | } else if (mShowExplicitlyRequested) { |
| 1765 | flags |= InputMethod.SHOW_EXPLICIT; |
| 1766 | } |
| 1767 | return flags; |
| 1768 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | private int getAppShowFlags() { |
| 1771 | int flags = 0; |
| 1772 | if (mShowForced) { |
| 1773 | flags |= InputMethodManager.SHOW_FORCED; |
| 1774 | } else if (!mShowExplicitlyRequested) { |
| 1775 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 1776 | } |
| 1777 | return flags; |
| 1778 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1779 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1780 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1781 | @NonNull |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1782 | InputBindResult attachNewInputLocked( |
| 1783 | /* @InputMethodClient.StartInputReason */ final int startInputReason, boolean initial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | if (!mBoundToMethod) { |
| 1785 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1786 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 1787 | mBoundToMethod = true; |
| 1788 | } |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1789 | |
| 1790 | final Binder startInputToken = new Binder(); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1791 | final StartInputInfo info = new StartInputInfo(mCurToken, mCurId, startInputReason, |
| 1792 | !initial, mCurFocusedWindow, mCurAttribute, mCurFocusedWindowSoftInputMode, |
| 1793 | mCurSeq); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1794 | mStartInputMap.put(startInputToken, info); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1795 | mStartInputHistory.addEntry(info); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | final SessionState session = mCurClient.curSession; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1798 | executeOrSendMessage(session.method, mCaller.obtainMessageIIOOOO( |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 1799 | MSG_START_INPUT, mCurInputContextMissingMethods, initial ? 0 : 1 /* restarting */, |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1800 | startInputToken, session, mCurInputContext, mCurAttribute)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1802 | 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] | 1803 | showCurrentInputLocked(getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1804 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1805 | return new InputBindResult(InputBindResult.ResultCode.SUCCESS_WITH_IME_SESSION, |
| 1806 | session.session, (session.channel != null ? session.channel.dup() : null), |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1807 | mCurId, mCurSeq, mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1809 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1810 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1811 | @NonNull |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1812 | InputBindResult startInputLocked( |
| 1813 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1814 | IInputMethodClient client, IInputContext inputContext, |
| 1815 | /* @InputConnectionInspector.missingMethods */ final int missingMethods, |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 1816 | @Nullable EditorInfo attribute, int controlFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1817 | // If no method is currently selected, do nothing. |
| 1818 | if (mCurMethodId == null) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1819 | return InputBindResult.NO_IME; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1822 | ClientState cs = mClients.get(client.asBinder()); |
| 1823 | if (cs == null) { |
| 1824 | throw new IllegalArgumentException("unknown client " |
| 1825 | + client.asBinder()); |
| 1826 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1827 | |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 1828 | if (attribute == null) { |
| 1829 | Slog.w(TAG, "Ignoring startInput with null EditorInfo." |
| 1830 | + " uid=" + cs.uid + " pid=" + cs.pid); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1831 | return InputBindResult.NULL_EDITOR_INFO; |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | try { |
| 1835 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 1836 | // Check with the window manager to make sure this client actually |
| 1837 | // has a window with focus. If not, reject. This is thread safe |
| 1838 | // because if the focus changes some time before or after, the |
| 1839 | // next client receiving focus that has any interest in input will |
| 1840 | // be calling through here after that change happens. |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1841 | if (DEBUG) { |
| 1842 | Slog.w(TAG, "Starting input on non-focused client " + cs.client |
| 1843 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 1844 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1845 | return InputBindResult.NOT_IME_TARGET_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | } |
| 1847 | } catch (RemoteException e) { |
| 1848 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1849 | |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1850 | return startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1851 | controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1852 | } |
| 1853 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1854 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1855 | @NonNull |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1856 | InputBindResult startInputUncheckedLocked(@NonNull ClientState cs, IInputContext inputContext, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1857 | /* @InputConnectionInspector.missingMethods */ final int missingMethods, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1858 | @NonNull EditorInfo attribute, int controlFlags, |
| 1859 | /* @InputMethodClient.StartInputReason */ final int startInputReason) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1860 | // If no method is currently selected, do nothing. |
| 1861 | if (mCurMethodId == null) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1862 | return InputBindResult.NO_IME; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1863 | } |
| 1864 | |
Yohei Yukawa | d57ba67 | 2015-06-08 16:39:46 -0700 | [diff] [blame] | 1865 | if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid, |
| 1866 | attribute.packageName)) { |
| 1867 | Slog.e(TAG, "Rejecting this client as it reported an invalid package name." |
| 1868 | + " uid=" + cs.uid + " package=" + attribute.packageName); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1869 | return InputBindResult.INVALID_PACKAGE_NAME; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | if (mCurClient != cs) { |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1873 | // Was the keyguard locked when switching over to the new client? |
| 1874 | mCurClientInKeyguard = isKeyguardLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | // If the client is changing, we need to switch over to the new |
| 1876 | // one. |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1877 | unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_CLIENT); |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1878 | if (DEBUG) Slog.v(TAG, "switching to client: client=" |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1879 | + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | |
| 1881 | // If the screen is on, inform the new client it is active |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 1882 | if (mIsInteractive) { |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 1883 | executeOrSendMessage(cs.client, mCaller.obtainMessageIO( |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 1884 | MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, cs)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | } |
| 1886 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | // Bump up the sequence for this client and attach it. |
| 1889 | mCurSeq++; |
| 1890 | if (mCurSeq <= 0) mCurSeq = 1; |
| 1891 | mCurClient = cs; |
| 1892 | mCurInputContext = inputContext; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1893 | mCurInputContextMissingMethods = missingMethods; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | // Check if the input method is changing. |
| 1897 | if (mCurId != null && mCurId.equals(mCurMethodId)) { |
| 1898 | if (cs.curSession != null) { |
| 1899 | // Fast case: if we are already connected to the input method, |
| 1900 | // then just return it. |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 1901 | return attachNewInputLocked(startInputReason, |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1902 | (controlFlags&InputMethodManager.CONTROL_START_INITIAL) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | } |
| 1904 | if (mHaveConnection) { |
| 1905 | if (mCurMethod != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1906 | // Return to client, and we will get back with it when |
| 1907 | // we have had a session made for it. |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1908 | requestClientSessionLocked(cs); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1909 | return new InputBindResult( |
| 1910 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_SESSION, |
| 1911 | null, null, mCurId, mCurSeq, |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1912 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | } else if (SystemClock.uptimeMillis() |
| 1914 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 1915 | // In this case we have connected to the service, but |
| 1916 | // don't yet have its interface. If it hasn't been too |
| 1917 | // long since we did the connection, we'll return to |
| 1918 | // the client and wait to get the service interface so |
| 1919 | // we can report back. If it has been too long, we want |
| 1920 | // to fall through so we can try a disconnect/reconnect |
| 1921 | // to see if we can get back in touch with the service. |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1922 | return new InputBindResult( |
| 1923 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, |
| 1924 | null, null, mCurId, mCurSeq, |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1925 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1927 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 1928 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1932 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1933 | return startInputInnerLocked(); |
| 1934 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1935 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1936 | InputBindResult startInputInnerLocked() { |
| 1937 | if (mCurMethodId == null) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1938 | return InputBindResult.NO_IME; |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1939 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1940 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1941 | if (!mSystemReady) { |
| 1942 | // If the system is not yet ready, we shouldn't be running third |
| 1943 | // party code. |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1944 | return new InputBindResult( |
| 1945 | InputBindResult.ResultCode.ERROR_SYSTEM_NOT_READY, |
| 1946 | null, null, mCurMethodId, mCurSeq, |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1947 | mCurUserActionNotificationSequenceNumber); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1948 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 1951 | if (info == null) { |
| 1952 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 1953 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1954 | |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1955 | unbindCurrentMethodLocked(true); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 1958 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1959 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 1960 | com.android.internal.R.string.input_method_binding_label); |
| 1961 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 1962 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 1963 | if (bindCurrentInputMethodService(mCurIntent, this, IME_CONNECTION_BIND_FLAGS)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1964 | mLastBindTime = SystemClock.uptimeMillis(); |
| 1965 | mHaveConnection = true; |
| 1966 | mCurId = info.getId(); |
| 1967 | mCurToken = new Binder(); |
| 1968 | try { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1969 | if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1970 | mIWindowManager.addWindowToken(mCurToken, TYPE_INPUT_METHOD, DEFAULT_DISPLAY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | } catch (RemoteException e) { |
| 1972 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1973 | return new InputBindResult( |
| 1974 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, |
| 1975 | null, null, mCurId, mCurSeq, |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1976 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1977 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1978 | mCurIntent = null; |
| 1979 | Slog.w(TAG, "Failure connecting to input method service: " + mCurIntent); |
| 1980 | return InputBindResult.IME_NOT_CONNECTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1982 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1983 | @NonNull |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 1984 | private InputBindResult startInput( |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1985 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1986 | IInputMethodClient client, IInputContext inputContext, |
| 1987 | /* @InputConnectionInspector.missingMethods */ final int missingMethods, |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 1988 | @Nullable EditorInfo attribute, int controlFlags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1989 | if (!calledFromValidUser()) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1990 | return InputBindResult.INVALID_USER; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1991 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | synchronized (mMethodMap) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1993 | if (DEBUG) { |
| 1994 | Slog.v(TAG, "startInput: reason=" |
| 1995 | + InputMethodClient.getStartInputReason(startInputReason) |
| 1996 | + " client = " + client.asBinder() |
| 1997 | + " inputContext=" + inputContext |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1998 | + " missingMethods=" |
| 1999 | + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods) |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2000 | + " attribute=" + attribute |
| 2001 | + " controlFlags=#" + Integer.toHexString(controlFlags)); |
| 2002 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2003 | final long ident = Binder.clearCallingIdentity(); |
| 2004 | try { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2005 | return startInputLocked(startInputReason, client, inputContext, missingMethods, |
| 2006 | attribute, controlFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | } finally { |
| 2008 | Binder.restoreCallingIdentity(ident); |
| 2009 | } |
| 2010 | } |
| 2011 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2012 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2013 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | public void finishInput(IInputMethodClient client) { |
| 2015 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2016 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2017 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 2019 | synchronized (mMethodMap) { |
| 2020 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 2021 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2022 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2023 | Slog.w(TAG, "Service connected without a token!"); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2024 | unbindCurrentMethodLocked(false); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2025 | return; |
| 2026 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2027 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2028 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 2029 | MSG_ATTACH_TOKEN, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2031 | clearClientSessionLocked(mCurClient); |
| 2032 | requestClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2033 | } |
| 2034 | } |
| 2035 | } |
| 2036 | } |
| 2037 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2038 | void onSessionCreated(IInputMethod method, IInputMethodSession session, |
| 2039 | InputChannel channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | synchronized (mMethodMap) { |
| 2041 | if (mCurMethod != null && method != null |
| 2042 | && mCurMethod.asBinder() == method.asBinder()) { |
| 2043 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2044 | clearClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2045 | mCurClient.curSession = new SessionState(mCurClient, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2046 | method, session, channel); |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2047 | InputBindResult res = attachNewInputLocked( |
| 2048 | InputMethodClient.START_INPUT_REASON_SESSION_CREATED_BY_IME, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2049 | if (res.method != null) { |
| 2050 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2051 | MSG_BIND_CLIENT, mCurClient.client, res)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2052 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2053 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | } |
| 2055 | } |
| 2056 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2057 | |
| 2058 | // Session abandoned. Close its associated input channel. |
| 2059 | channel.dispose(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2061 | |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2062 | void unbindCurrentMethodLocked(boolean savePosition) { |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2063 | if (mVisibleBound) { |
| 2064 | mContext.unbindService(mVisibleConnection); |
| 2065 | mVisibleBound = false; |
| 2066 | } |
| 2067 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2068 | if (mHaveConnection) { |
| 2069 | mContext.unbindService(this); |
| 2070 | mHaveConnection = false; |
| 2071 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2072 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2073 | if (mCurToken != null) { |
| 2074 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2075 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 2076 | if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) { |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 2077 | // The current IME is shown. Hence an IME switch (transition) is happening. |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2078 | mWindowManagerInternal.saveLastInputMethodWindowForTransition(); |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 2079 | } |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 2080 | mIWindowManager.removeWindowToken(mCurToken, DEFAULT_DISPLAY); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2081 | } catch (RemoteException e) { |
| 2082 | } |
| 2083 | mCurToken = null; |
| 2084 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2085 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2086 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2087 | clearCurMethodLocked(); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2088 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2089 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2090 | void resetCurrentMethodAndClient( |
| 2091 | /* @InputMethodClient.UnbindReason */ final int unbindClientReason) { |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2092 | mCurMethodId = null; |
| 2093 | unbindCurrentMethodLocked(false); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2094 | unbindCurrentClientLocked(unbindClientReason); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2095 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2096 | |
| 2097 | void requestClientSessionLocked(ClientState cs) { |
| 2098 | if (!cs.sessionRequested) { |
| 2099 | if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs); |
| 2100 | InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString()); |
| 2101 | cs.sessionRequested = true; |
| 2102 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO( |
| 2103 | MSG_CREATE_SESSION, mCurMethod, channels[1], |
| 2104 | new MethodCallback(this, mCurMethod, channels[0]))); |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | void clearClientSessionLocked(ClientState cs) { |
| 2109 | finishSessionLocked(cs.curSession); |
| 2110 | cs.curSession = null; |
| 2111 | cs.sessionRequested = false; |
| 2112 | } |
| 2113 | |
| 2114 | private void finishSessionLocked(SessionState sessionState) { |
| 2115 | if (sessionState != null) { |
| 2116 | if (sessionState.session != null) { |
| 2117 | try { |
| 2118 | sessionState.session.finishSession(); |
| 2119 | } catch (RemoteException e) { |
| 2120 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2121 | updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2122 | } |
| 2123 | sessionState.session = null; |
| 2124 | } |
| 2125 | if (sessionState.channel != null) { |
| 2126 | sessionState.channel.dispose(); |
| 2127 | sessionState.channel = null; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2128 | } |
| 2129 | } |
| 2130 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2131 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2132 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | if (mCurMethod != null) { |
| 2134 | for (ClientState cs : mClients.values()) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2135 | clearClientSessionLocked(cs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2137 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2138 | finishSessionLocked(mEnabledSession); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2139 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | mCurMethod = null; |
| 2141 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2142 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2143 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2144 | } |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 2145 | mInFullscreenMode = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2147 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2148 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2149 | public void onServiceDisconnected(ComponentName name) { |
Yohei Yukawa | 817d5f7 | 2017-01-04 20:15:02 -0800 | [diff] [blame] | 2150 | // Note that mContext.unbindService(this) does not trigger this. Hence if we are here the |
| 2151 | // disconnection is not intended by IMMS (e.g. triggered because the current IMS crashed), |
| 2152 | // which is irregular but can eventually happen for everyone just by continuing using the |
| 2153 | // device. Thus it is important to make sure that all the internal states are properly |
| 2154 | // refreshed when this method is called back. Running |
| 2155 | // adb install -r <APK that implements the current IME> |
| 2156 | // 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] | 2157 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2158 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | + " mCurIntent=" + mCurIntent); |
| 2160 | if (mCurMethod != null && mCurIntent != null |
| 2161 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2162 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | // We consider this to be a new bind attempt, since the system |
| 2164 | // should now try to restart the service for us. |
| 2165 | mLastBindTime = SystemClock.uptimeMillis(); |
| 2166 | mShowRequested = mInputShown; |
| 2167 | mInputShown = false; |
Yohei Yukawa | 817d5f7 | 2017-01-04 20:15:02 -0800 | [diff] [blame] | 2168 | unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_DISCONNECT_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2173 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | public void updateStatusIcon(IBinder token, String packageName, int iconId) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2175 | synchronized (mMethodMap) { |
| 2176 | if (!calledWithValidToken(token)) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2177 | return; |
| 2178 | } |
| 2179 | final long ident = Binder.clearCallingIdentity(); |
| 2180 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2181 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2182 | 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] | 2183 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2184 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2186 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2187 | 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] | 2188 | CharSequence contentDescription = null; |
| 2189 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2190 | // Use PackageManager to load label |
| 2191 | final PackageManager packageManager = mContext.getPackageManager(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2192 | contentDescription = packageManager.getApplicationLabel( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2193 | mIPackageManager.getApplicationInfo(packageName, 0, |
| 2194 | mSettings.getCurrentUserId())); |
| 2195 | } catch (RemoteException e) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2196 | /* ignore */ |
| 2197 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2198 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2199 | mStatusBar.setIcon(mSlotIme, packageName, iconId, 0, |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2200 | contentDescription != null |
| 2201 | ? contentDescription.toString() : null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2202 | mStatusBar.setIconVisibility(mSlotIme, true); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2203 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2204 | } |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2205 | } finally { |
| 2206 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2207 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2211 | private boolean shouldShowImeSwitcherLocked(int visibility) { |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2212 | if (!mShowOngoingImeSwitcherForPhones) return false; |
Jason Monk | 807ef76 | 2014-05-08 15:47:46 -0400 | [diff] [blame] | 2213 | if (mSwitchingDialog != null) return false; |
Yohei Yukawa | d2bc309 | 2017-07-31 15:37:14 -0700 | [diff] [blame] | 2214 | if (mWindowManagerInternal.isKeyguardShowingAndNotOccluded() |
| 2215 | && mKeyguardManager != null && mKeyguardManager.isKeyguardSecure()) return false; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2216 | if ((visibility & InputMethodService.IME_ACTIVE) == 0) return false; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2217 | if (mWindowManagerInternal.isHardKeyboardAvailable()) { |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 2218 | if (mHardKeyboardBehavior == HardKeyboardBehavior.WIRELESS_AFFORDANCE) { |
| 2219 | // When physical keyboard is attached, we show the ime switcher (or notification if |
| 2220 | // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently |
| 2221 | // exists in the IME switcher dialog. Might be OK to remove this condition once |
| 2222 | // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live. |
| 2223 | return true; |
| 2224 | } |
Yohei Yukawa | 8939838 | 2016-03-29 11:37:04 -0700 | [diff] [blame] | 2225 | } else if ((visibility & InputMethodService.IME_VISIBLE) == 0) { |
| 2226 | return false; |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2227 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2228 | |
| 2229 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 2230 | final int N = imis.size(); |
| 2231 | if (N > 2) return true; |
| 2232 | if (N < 1) return false; |
| 2233 | int nonAuxCount = 0; |
| 2234 | int auxCount = 0; |
| 2235 | InputMethodSubtype nonAuxSubtype = null; |
| 2236 | InputMethodSubtype auxSubtype = null; |
| 2237 | for(int i = 0; i < N; ++i) { |
| 2238 | final InputMethodInfo imi = imis.get(i); |
| 2239 | final List<InputMethodSubtype> subtypes = |
| 2240 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
| 2241 | final int subtypeCount = subtypes.size(); |
| 2242 | if (subtypeCount == 0) { |
| 2243 | ++nonAuxCount; |
| 2244 | } else { |
| 2245 | for (int j = 0; j < subtypeCount; ++j) { |
| 2246 | final InputMethodSubtype subtype = subtypes.get(j); |
| 2247 | if (!subtype.isAuxiliary()) { |
| 2248 | ++nonAuxCount; |
| 2249 | nonAuxSubtype = subtype; |
| 2250 | } else { |
| 2251 | ++auxCount; |
| 2252 | auxSubtype = subtype; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2253 | } |
| 2254 | } |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2255 | } |
| 2256 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2257 | if (nonAuxCount > 1 || auxCount > 1) { |
| 2258 | return true; |
| 2259 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 2260 | if (nonAuxSubtype != null && auxSubtype != null |
| 2261 | && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 2262 | || auxSubtype.overridesImplicitlyEnabledSubtype() |
| 2263 | || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) |
| 2264 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 2265 | return false; |
| 2266 | } |
| 2267 | return true; |
| 2268 | } |
| 2269 | return false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2270 | } |
| 2271 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2272 | private boolean isKeyguardLocked() { |
| 2273 | return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked(); |
| 2274 | } |
| 2275 | |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2276 | @BinderThread |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 2277 | @SuppressWarnings("deprecation") |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2278 | @Override |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2279 | public void setImeWindowStatus(IBinder token, IBinder startInputToken, int vis, |
| 2280 | int backDisposition) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2281 | if (!calledWithValidToken(token)) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2282 | return; |
| 2283 | } |
| 2284 | |
Yohei Yukawa | 69e6802 | 2017-02-13 12:04:50 -0800 | [diff] [blame] | 2285 | final StartInputInfo info; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2286 | synchronized (mMethodMap) { |
Yohei Yukawa | 69e6802 | 2017-02-13 12:04:50 -0800 | [diff] [blame] | 2287 | info = mStartInputMap.get(startInputToken); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2288 | mImeWindowVis = vis; |
| 2289 | mBackDisposition = backDisposition; |
| 2290 | updateSystemUiLocked(token, vis, backDisposition); |
| 2291 | } |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2292 | |
| 2293 | final boolean dismissImeOnBackKeyPressed; |
| 2294 | switch (backDisposition) { |
| 2295 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 2296 | dismissImeOnBackKeyPressed = true; |
| 2297 | break; |
| 2298 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 2299 | dismissImeOnBackKeyPressed = false; |
| 2300 | break; |
| 2301 | default: |
| 2302 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 2303 | dismissImeOnBackKeyPressed = ((vis & InputMethodService.IME_VISIBLE) != 0); |
| 2304 | break; |
| 2305 | } |
Yohei Yukawa | ee2a7ed | 2017-02-15 21:38:57 -0800 | [diff] [blame] | 2306 | mWindowManagerInternal.updateInputMethodWindowStatus(token, |
| 2307 | (vis & InputMethodService.IME_VISIBLE) != 0, |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2308 | dismissImeOnBackKeyPressed, info != null ? info.mTargetWindow : null); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | private void updateSystemUi(IBinder token, int vis, int backDisposition) { |
| 2312 | synchronized (mMethodMap) { |
| 2313 | updateSystemUiLocked(token, vis, backDisposition); |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | // Caution! This method is called in this class. Handle multi-user carefully |
| 2318 | private void updateSystemUiLocked(IBinder token, int vis, int backDisposition) { |
| 2319 | if (!calledWithValidToken(token)) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2320 | return; |
| 2321 | } |
| 2322 | |
| 2323 | // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure |
| 2324 | // all updateSystemUi happens on system previlege. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2325 | final long ident = Binder.clearCallingIdentity(); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2326 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2327 | // apply policy for binder calls |
| 2328 | if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) { |
| 2329 | vis = 0; |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2330 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2331 | // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked(). |
| 2332 | final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis); |
| 2333 | if (mStatusBar != null) { |
| 2334 | mStatusBar.setImeWindowStatus(token, vis, backDisposition, |
| 2335 | needsToShowImeSwitcher); |
| 2336 | } |
| 2337 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2338 | if (imi != null && needsToShowImeSwitcher) { |
| 2339 | // Used to load label |
| 2340 | final CharSequence title = mRes.getText( |
| 2341 | com.android.internal.R.string.select_input_method); |
| 2342 | final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName( |
| 2343 | mContext, imi, mCurrentSubtype); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2344 | mImeSwitcherNotification.setContentTitle(title) |
| 2345 | .setContentText(summary) |
| 2346 | .setContentIntent(mImeSwitchPendingIntent); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2347 | try { |
| 2348 | if ((mNotificationManager != null) |
| 2349 | && !mIWindowManager.hasNavigationBar()) { |
| 2350 | if (DEBUG) { |
| 2351 | Slog.d(TAG, "--- show notification: label = " + summary); |
| 2352 | } |
| 2353 | mNotificationManager.notifyAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2354 | SystemMessage.NOTE_SELECT_INPUT_METHOD, |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2355 | mImeSwitcherNotification.build(), UserHandle.ALL); |
| 2356 | mNotificationShown = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2357 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2358 | } catch (RemoteException e) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2359 | } |
| 2360 | } else { |
| 2361 | if (mNotificationShown && mNotificationManager != null) { |
| 2362 | if (DEBUG) { |
| 2363 | Slog.d(TAG, "--- hide notification"); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2364 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2365 | mNotificationManager.cancelAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2366 | SystemMessage.NOTE_SELECT_INPUT_METHOD, UserHandle.ALL); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2367 | mNotificationShown = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2368 | } |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2369 | } |
| 2370 | } finally { |
| 2371 | Binder.restoreCallingIdentity(ident); |
| 2372 | } |
| 2373 | } |
| 2374 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2375 | @Override |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2376 | public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2377 | if (!calledFromValidUser()) { |
| 2378 | return; |
| 2379 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2380 | synchronized (mMethodMap) { |
| 2381 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
| 2382 | for (int i = 0; i < spans.length; ++i) { |
| 2383 | SuggestionSpan ss = spans[i]; |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2384 | if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) { |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2385 | mSecureSuggestionSpans.put(ss, currentImi); |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2391 | @Override |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2392 | public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2393 | if (!calledFromValidUser()) { |
| 2394 | return false; |
| 2395 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2396 | synchronized (mMethodMap) { |
| 2397 | final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span); |
| 2398 | // TODO: Do not send the intent if the process of the targetImi is already dead. |
| 2399 | if (targetImi != null) { |
| 2400 | final String[] suggestions = span.getSuggestions(); |
| 2401 | if (index < 0 || index >= suggestions.length) return false; |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2402 | final String className = span.getNotificationTargetClassName(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2403 | final Intent intent = new Intent(); |
| 2404 | // Ensures that only a class in the original IME package will receive the |
| 2405 | // notification. |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2406 | intent.setClassName(targetImi.getPackageName(), className); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2407 | intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED); |
| 2408 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString); |
| 2409 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]); |
| 2410 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode()); |
Amith Yamasani | f043de9 | 2012-10-24 06:42:40 -0700 | [diff] [blame] | 2411 | final long ident = Binder.clearCallingIdentity(); |
| 2412 | try { |
| 2413 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
| 2414 | } finally { |
| 2415 | Binder.restoreCallingIdentity(ident); |
| 2416 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 2417 | return true; |
| 2418 | } |
| 2419 | } |
| 2420 | return false; |
| 2421 | } |
| 2422 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2423 | void updateFromSettingsLocked(boolean enabledMayChange) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2424 | updateInputMethodsFromSettingsLocked(enabledMayChange); |
| 2425 | updateKeyboardFromSettingsLocked(); |
| 2426 | } |
| 2427 | |
| 2428 | void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2429 | if (enabledMayChange) { |
| 2430 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 2431 | for (int i=0; i<enabled.size(); i++) { |
| 2432 | // We allow the user to select "disabled until used" apps, so if they |
| 2433 | // are enabling one of those here we now need to make it enabled. |
| 2434 | InputMethodInfo imm = enabled.get(i); |
| 2435 | try { |
| 2436 | ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(), |
| 2437 | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 2438 | mSettings.getCurrentUserId()); |
Satoshi Kataoka | 7987a31 | 2013-04-17 18:59:33 +0900 | [diff] [blame] | 2439 | if (ai != null && ai.enabledSetting |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2440 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 2441 | if (DEBUG) { |
| 2442 | Slog.d(TAG, "Update state(" + imm.getId() |
| 2443 | + "): DISABLED_UNTIL_USED -> DEFAULT"); |
| 2444 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2445 | mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(), |
| 2446 | PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 2447 | PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(), |
| 2448 | mContext.getBasePackageName()); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2449 | } |
| 2450 | } catch (RemoteException e) { |
| 2451 | } |
| 2452 | } |
| 2453 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2454 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 2455 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 2456 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 2457 | // enabled. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2458 | String id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2459 | // There is no input method selected, try to choose new applicable input method. |
| 2460 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2461 | id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2462 | } |
| 2463 | if (!TextUtils.isEmpty(id)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2464 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2465 | setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2466 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2467 | Slog.w(TAG, "Unknown input method from prefs: " + id, e); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2468 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_IME_FAILED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2470 | mShortcutInputMethodsAndSubtypes.clear(); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2471 | } else { |
| 2472 | // 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] | 2473 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_NO_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2474 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 2475 | // Here is not the perfect place to reset the switching controller. Ideally |
| 2476 | // mSwitchingController and mSettings should be able to share the same state. |
| 2477 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 2478 | // the same enabled IMEs list. |
| 2479 | mSwitchingController.resetCircularListLocked(mContext); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2480 | |
| 2481 | } |
| 2482 | |
| 2483 | public void updateKeyboardFromSettingsLocked() { |
| 2484 | mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled(); |
| 2485 | if (mSwitchingDialog != null |
| 2486 | && mSwitchingDialogTitleView != null |
| 2487 | && mSwitchingDialog.isShowing()) { |
| 2488 | final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById( |
| 2489 | com.android.internal.R.id.hard_keyboard_switch); |
| 2490 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
| 2491 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2493 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2494 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2495 | InputMethodInfo info = mMethodMap.get(id); |
| 2496 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2497 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2498 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2499 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2500 | // 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] | 2501 | if (id.equals(mCurMethodId)) { |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2502 | final int subtypeCount = info.getSubtypeCount(); |
| 2503 | if (subtypeCount <= 0) { |
| 2504 | return; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2505 | } |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2506 | final InputMethodSubtype oldSubtype = mCurrentSubtype; |
| 2507 | final InputMethodSubtype newSubtype; |
| 2508 | if (subtypeId >= 0 && subtypeId < subtypeCount) { |
| 2509 | newSubtype = info.getSubtypeAt(subtypeId); |
| 2510 | } else { |
| 2511 | // If subtype is null, try to find the most applicable one from |
| 2512 | // getCurrentInputMethodSubtype. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2513 | newSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2514 | } |
| 2515 | if (newSubtype == null || oldSubtype == null) { |
| 2516 | Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype |
| 2517 | + ", new subtype = " + newSubtype); |
| 2518 | return; |
| 2519 | } |
| 2520 | if (newSubtype != oldSubtype) { |
| 2521 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 2522 | if (mCurMethod != null) { |
| 2523 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2524 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2525 | mCurMethod.changeInputMethodSubtype(newSubtype); |
| 2526 | } catch (RemoteException e) { |
| 2527 | Slog.w(TAG, "Failed to call changeInputMethodSubtype"); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2528 | } |
| 2529 | } |
| 2530 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2531 | return; |
| 2532 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2533 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2534 | // Changing to a different IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | final long ident = Binder.clearCallingIdentity(); |
| 2536 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2537 | // Set a subtype to this input method. |
| 2538 | // subtypeId the name of a subtype which will be set. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2539 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 2540 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 2541 | // because mCurMethodId is stored as a history in |
| 2542 | // setSelectedInputMethodAndSubtypeLocked(). |
| 2543 | mCurMethodId = id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 2545 | if (LocalServices.getService(ActivityManagerInternal.class).isSystemReady()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 2547 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | intent.putExtra("input_method_id", id); |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 2549 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | } |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2551 | unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | } finally { |
| 2553 | Binder.restoreCallingIdentity(ident); |
| 2554 | } |
| 2555 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2556 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2557 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2558 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 2559 | ResultReceiver resultReceiver) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2560 | if (!calledFromValidUser()) { |
| 2561 | return false; |
| 2562 | } |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2563 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2564 | long ident = Binder.clearCallingIdentity(); |
| 2565 | try { |
| 2566 | synchronized (mMethodMap) { |
| 2567 | if (mCurClient == null || client == null |
| 2568 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 2569 | try { |
| 2570 | // We need to check if this is the current client with |
| 2571 | // focus in the window manager, to allow this call to |
| 2572 | // be made before input is started in it. |
| 2573 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2574 | Slog.w(TAG, "Ignoring showSoftInput of uid " + 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 | |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2582 | 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] | 2583 | return showCurrentInputLocked(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 showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | mShowRequested = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2592 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 2593 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | } |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2596 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 2597 | mShowExplicitlyRequested = true; |
| 2598 | mShowForced = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2599 | } else if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 2600 | mShowExplicitlyRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2602 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2603 | if (!mSystemReady) { |
| 2604 | return false; |
| 2605 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2606 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2607 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | if (mCurMethod != null) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2609 | if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2610 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 2611 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 2612 | resultReceiver)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2613 | mInputShown = true; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2614 | if (mHaveConnection && !mVisibleBound) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2615 | bindCurrentInputMethodService( |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 2616 | mCurIntent, mVisibleConnection, IME_VISIBLE_BIND_FLAGS); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2617 | mVisibleBound = true; |
| 2618 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2619 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2620 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2621 | >= (mLastBindTime+TIME_TO_RECONNECT)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | // The client has asked to have the input method shown, but |
| 2623 | // we have been sitting here too long with a connection to the |
| 2624 | // service and no interface received, so let's disconnect/connect |
| 2625 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2626 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | SystemClock.uptimeMillis()-mLastBindTime,1); |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2628 | 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] | 2629 | mContext.unbindService(this); |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 2630 | bindCurrentInputMethodService(mCurIntent, this, IME_CONNECTION_BIND_FLAGS); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2631 | } else { |
| 2632 | if (DEBUG) { |
| 2633 | Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = " |
| 2634 | + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis())); |
| 2635 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2637 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2638 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2639 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2640 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2641 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2642 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 2643 | ResultReceiver resultReceiver) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2644 | if (!calledFromValidUser()) { |
| 2645 | return false; |
| 2646 | } |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2647 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | long ident = Binder.clearCallingIdentity(); |
| 2649 | try { |
| 2650 | synchronized (mMethodMap) { |
| 2651 | if (mCurClient == null || client == null |
| 2652 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 2653 | try { |
| 2654 | // We need to check if this is the current client with |
| 2655 | // focus in the window manager, to allow this call to |
| 2656 | // be made before input is started in it. |
| 2657 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2658 | if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid " |
| 2659 | + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2660 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | } |
| 2662 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2663 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2664 | } |
| 2665 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2666 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2667 | 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] | 2668 | return hideCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2669 | } |
| 2670 | } finally { |
| 2671 | Binder.restoreCallingIdentity(ident); |
| 2672 | } |
| 2673 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2674 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2675 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2676 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 2677 | && (mShowExplicitlyRequested || mShowForced)) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2678 | 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] | 2679 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2680 | } |
| 2681 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2682 | 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] | 2683 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2684 | } |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2685 | |
| 2686 | // There is a chance that IMM#hideSoftInput() is called in a transient state where |
| 2687 | // IMMS#InputShown is already updated to be true whereas IMMS#mImeWindowVis is still waiting |
| 2688 | // to be updated with the new value sent from IME process. Even in such a transient state |
| 2689 | // historically we have accepted an incoming call of IMM#hideSoftInput() from the |
| 2690 | // application process as a valid request, and have even promised such a behavior with CTS |
| 2691 | // since Android Eclair. That's why we need to accept IMM#hideSoftInput() even when only |
| 2692 | // IMMS#InputShown indicates that the software keyboard is shown. |
| 2693 | // TODO: Clean up, IMMS#mInputShown, IMMS#mImeWindowVis and mShowRequested. |
| 2694 | final boolean shouldHideSoftInput = (mCurMethod != null) && (mInputShown || |
| 2695 | (mImeWindowVis & InputMethodService.IME_ACTIVE) != 0); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2696 | boolean res; |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2697 | if (shouldHideSoftInput) { |
| 2698 | // The IME will report its visible state again after the following message finally |
| 2699 | // delivered to the IME process as an IPC. Hence the inconsistency between |
| 2700 | // IMMS#mInputShown and IMMS#mImeWindowVis should be resolved spontaneously in |
| 2701 | // the final state. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2702 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 2703 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 2704 | res = true; |
| 2705 | } else { |
| 2706 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | } |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2708 | if (mHaveConnection && mVisibleBound) { |
| 2709 | mContext.unbindService(mVisibleConnection); |
| 2710 | mVisibleBound = false; |
| 2711 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2712 | mInputShown = false; |
| 2713 | mShowRequested = false; |
| 2714 | mShowExplicitlyRequested = false; |
| 2715 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2716 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2717 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2718 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2719 | @NonNull |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2720 | @Override |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2721 | public InputBindResult startInputOrWindowGainedFocus( |
| 2722 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
| 2723 | IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode, |
Yohei Yukawa | 74750f2 | 2016-03-22 12:54:22 -0700 | [diff] [blame] | 2724 | int windowFlags, @Nullable EditorInfo attribute, IInputContext inputContext, |
Yohei Yukawa | cf68d52 | 2017-12-12 09:33:26 -0800 | [diff] [blame] | 2725 | /* @InputConnectionInspector.missingMethods */ final int missingMethods, |
| 2726 | int unverifiedTargetSdkVersion) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2727 | final InputBindResult result; |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2728 | if (windowToken != null) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2729 | result = windowGainedFocus(startInputReason, client, windowToken, controlFlags, |
Yohei Yukawa | cf68d52 | 2017-12-12 09:33:26 -0800 | [diff] [blame] | 2730 | softInputMode, windowFlags, attribute, inputContext, missingMethods, |
| 2731 | unverifiedTargetSdkVersion); |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2732 | } else { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2733 | result = startInput(startInputReason, client, inputContext, missingMethods, attribute, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2734 | controlFlags); |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2735 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2736 | if (result == null) { |
| 2737 | // This must never happen, but just in case. |
| 2738 | Slog.wtf(TAG, "InputBindResult is @NonNull. startInputReason=" |
| 2739 | + InputMethodClient.getStartInputReason(startInputReason) |
| 2740 | + " windowFlags=#" + Integer.toHexString(windowFlags) |
| 2741 | + " editorInfo=" + attribute); |
| 2742 | return InputBindResult.NULL; |
| 2743 | } |
| 2744 | return result; |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2745 | } |
| 2746 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2747 | @NonNull |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2748 | private InputBindResult windowGainedFocus( |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2749 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
Yohei Yukawa | 22dac1c | 2017-02-12 16:54:16 -0800 | [diff] [blame] | 2750 | IInputMethodClient client, IBinder windowToken, int controlFlags, |
| 2751 | /* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode, |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2752 | int windowFlags, EditorInfo attribute, IInputContext inputContext, |
Yohei Yukawa | cf68d52 | 2017-12-12 09:33:26 -0800 | [diff] [blame] | 2753 | /* @InputConnectionInspector.missingMethods */ final int missingMethods, |
| 2754 | int unverifiedTargetSdkVersion) { |
Satoshi Kataoka | 8d03305 | 2012-11-19 17:30:40 +0900 | [diff] [blame] | 2755 | // Needs to check the validity before clearing calling identity |
| 2756 | final boolean calledFromValidUser = calledFromValidUser(); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2757 | InputBindResult res = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | long ident = Binder.clearCallingIdentity(); |
| 2759 | try { |
| 2760 | synchronized (mMethodMap) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2761 | if (DEBUG) Slog.v(TAG, "windowGainedFocus: reason=" |
| 2762 | + InputMethodClient.getStartInputReason(startInputReason) |
| 2763 | + " client=" + client.asBinder() |
| 2764 | + " inputContext=" + inputContext |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2765 | + " missingMethods=" |
| 2766 | + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods) |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2767 | + " attribute=" + attribute |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2768 | + " controlFlags=#" + Integer.toHexString(controlFlags) |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 2769 | + " softInputMode=" + InputMethodClient.softInputModeToString(softInputMode) |
Yohei Yukawa | cf68d52 | 2017-12-12 09:33:26 -0800 | [diff] [blame] | 2770 | + " windowFlags=#" + Integer.toHexString(windowFlags) |
| 2771 | + " unverifiedTargetSdkVersion=" + unverifiedTargetSdkVersion); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2772 | |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2773 | ClientState cs = mClients.get(client.asBinder()); |
| 2774 | if (cs == null) { |
| 2775 | throw new IllegalArgumentException("unknown client " |
| 2776 | + client.asBinder()); |
| 2777 | } |
| 2778 | |
| 2779 | try { |
| 2780 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 2781 | // Check with the window manager to make sure this client actually |
| 2782 | // has a window with focus. If not, reject. This is thread safe |
| 2783 | // because if the focus changes some time before or after, the |
| 2784 | // next client receiving focus that has any interest in input will |
| 2785 | // be calling through here after that change happens. |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 2786 | if (DEBUG) { |
| 2787 | Slog.w(TAG, "Focus gain on non-focused client " + cs.client |
| 2788 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 2789 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2790 | return InputBindResult.NOT_IME_TARGET_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2792 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2793 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2794 | |
Satoshi Kataoka | 8d03305 | 2012-11-19 17:30:40 +0900 | [diff] [blame] | 2795 | if (!calledFromValidUser) { |
| 2796 | Slog.w(TAG, "A background user is requesting window. Hiding IME."); |
| 2797 | Slog.w(TAG, "If you want to interect with IME, you need " |
| 2798 | + "android.permission.INTERACT_ACROSS_USERS_FULL"); |
| 2799 | hideCurrentInputLocked(0, null); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2800 | return InputBindResult.INVALID_USER; |
Satoshi Kataoka | 8d03305 | 2012-11-19 17:30:40 +0900 | [diff] [blame] | 2801 | } |
| 2802 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2803 | if (mCurFocusedWindow == windowToken) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 2804 | if (DEBUG) { |
| 2805 | Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client |
| 2806 | + " attribute=" + attribute + ", token = " + windowToken); |
| 2807 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2808 | if (attribute != null) { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2809 | return startInputUncheckedLocked(cs, inputContext, missingMethods, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2810 | attribute, controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2811 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2812 | return new InputBindResult( |
| 2813 | InputBindResult.ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY, |
| 2814 | null, null, null, -1, -1); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2815 | } |
| 2816 | mCurFocusedWindow = windowToken; |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 2817 | mCurFocusedWindowSoftInputMode = softInputMode; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 2818 | mCurFocusedWindowClient = cs; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2819 | |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2820 | // Should we auto-show the IME even if the caller has not |
| 2821 | // specified what should be done with it? |
| 2822 | // We only do this automatically if the window can resize |
| 2823 | // to accommodate the IME (so what the user sees will give |
| 2824 | // them good context without input information being obscured |
| 2825 | // by the IME) or if running on a large screen where there |
| 2826 | // is more room for the target window + IME. |
| 2827 | final boolean doAutoShow = |
| 2828 | (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 2829 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
| 2830 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 2831 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2832 | final boolean isTextEditor = |
| 2833 | (controlFlags&InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0; |
| 2834 | |
| 2835 | // We want to start input before showing the IME, but after closing |
| 2836 | // it. We want to do this after closing it to help the IME disappear |
| 2837 | // more quickly (not get stuck behind it initializing itself for the |
| 2838 | // new focused input, even if its window wants to hide the IME). |
| 2839 | boolean didStart = false; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 2840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2841 | switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 2842 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2843 | if (!isTextEditor || !doAutoShow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2844 | if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) { |
| 2845 | // There is no focus view, and this window will |
| 2846 | // be behind any soft input window, so hide the |
| 2847 | // soft input window if it is shown. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2848 | 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] | 2849 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | } |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2851 | } else if (isTextEditor && doAutoShow && (softInputMode & |
| 2852 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | // There is a focus view, and we are navigating forward |
| 2854 | // into the window, so show the input window for the user. |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2855 | // We only do this automatically if the window can resize |
| 2856 | // to accommodate the IME (so what the user sees will give |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2857 | // them good context without input information being obscured |
| 2858 | // by the IME) or if running on a large screen where there |
| 2859 | // is more room for the target window + IME. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2860 | if (DEBUG) Slog.v(TAG, "Unspecified window will show input"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2861 | if (attribute != null) { |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2862 | res = startInputUncheckedLocked(cs, inputContext, |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2863 | missingMethods, attribute, controlFlags, startInputReason); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2864 | didStart = true; |
| 2865 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2866 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | } |
| 2868 | break; |
| 2869 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
| 2870 | // Do nothing. |
| 2871 | break; |
| 2872 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 2873 | if ((softInputMode & |
| 2874 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2875 | 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] | 2876 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2877 | } |
| 2878 | break; |
| 2879 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2880 | 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] | 2881 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2882 | break; |
| 2883 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 2884 | if ((softInputMode & |
| 2885 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2886 | if (DEBUG) Slog.v(TAG, "Window asks to show input going forward"); |
Yohei Yukawa | cf68d52 | 2017-12-12 09:33:26 -0800 | [diff] [blame] | 2887 | if (InputMethodUtils.isSoftInputModeStateVisibleAllowed( |
| 2888 | unverifiedTargetSdkVersion, controlFlags)) { |
| 2889 | if (attribute != null) { |
| 2890 | res = startInputUncheckedLocked(cs, inputContext, |
| 2891 | missingMethods, attribute, controlFlags, |
| 2892 | startInputReason); |
| 2893 | didStart = true; |
| 2894 | } |
| 2895 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 2896 | } else { |
| 2897 | Slog.e(TAG, "SOFT_INPUT_STATE_VISIBLE is ignored because" |
| 2898 | + " there is no focused view that also returns true from" |
| 2899 | + " View#onCheckIsTextEditor()"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | } |
| 2902 | break; |
| 2903 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2904 | if (DEBUG) Slog.v(TAG, "Window asks to always show input"); |
Yohei Yukawa | cf68d52 | 2017-12-12 09:33:26 -0800 | [diff] [blame] | 2905 | if (InputMethodUtils.isSoftInputModeStateVisibleAllowed( |
| 2906 | unverifiedTargetSdkVersion, controlFlags)) { |
| 2907 | if (attribute != null) { |
| 2908 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 2909 | attribute, controlFlags, startInputReason); |
| 2910 | didStart = true; |
| 2911 | } |
| 2912 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 2913 | } else { |
| 2914 | Slog.e(TAG, "SOFT_INPUT_STATE_ALWAYS_VISIBLE is ignored because" |
| 2915 | + " there is no focused view that also returns true from" |
| 2916 | + " View#onCheckIsTextEditor()"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | break; |
| 2919 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2920 | |
Tarandeep Singh | 2f731c55 | 2018-02-05 13:55:06 -0800 | [diff] [blame] | 2921 | if (!didStart) { |
| 2922 | if (attribute != null) { |
| 2923 | if (!DebugFlags.FLAG_OPTIMIZE_START_INPUT.value() |
| 2924 | || (controlFlags |
| 2925 | & InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0) { |
| 2926 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 2927 | attribute, |
| 2928 | controlFlags, startInputReason); |
| 2929 | } else { |
| 2930 | res = InputBindResult.NO_EDITOR; |
| 2931 | } |
| 2932 | } else { |
| 2933 | res = InputBindResult.NULL_EDITOR_INFO; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 2934 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2935 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | } |
| 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(ident); |
| 2939 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2940 | |
| 2941 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2943 | |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 2944 | private boolean canShowInputMethodPickerLocked(IInputMethodClient client) { |
| 2945 | final int uid = Binder.getCallingUid(); |
| 2946 | if (UserHandle.getAppId(uid) == Process.SYSTEM_UID) { |
| 2947 | return true; |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 2948 | } else if (mCurFocusedWindowClient != null && client != null |
| 2949 | && mCurFocusedWindowClient.client.asBinder() == client.asBinder()) { |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 2950 | return true; |
| 2951 | } else if (mCurIntent != null && InputMethodUtils.checkIfPackageBelongsToUid( |
| 2952 | mAppOpsManager, |
| 2953 | uid, |
| 2954 | mCurIntent.getComponent().getPackageName())) { |
| 2955 | return true; |
| 2956 | } else if (mContext.checkCallingPermission( |
| 2957 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 2958 | == PackageManager.PERMISSION_GRANTED) { |
| 2959 | return true; |
| 2960 | } |
| 2961 | |
| 2962 | return false; |
| 2963 | } |
| 2964 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2965 | @Override |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2966 | public void showInputMethodPickerFromClient( |
| 2967 | IInputMethodClient client, int auxiliarySubtypeMode) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2968 | if (!calledFromValidUser()) { |
| 2969 | return; |
| 2970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | synchronized (mMethodMap) { |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 2972 | if(!canShowInputMethodPickerLocked(client)) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 2973 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2974 | + Binder.getCallingUid() + ": " + client); |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 2975 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | } |
| 2977 | |
satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 2978 | // Always call subtype picker, because subtype picker is a superset of input method |
| 2979 | // picker. |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2980 | mHandler.sendMessage(mCaller.obtainMessageI( |
| 2981 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode)); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2982 | } |
| 2983 | } |
| 2984 | |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 2985 | public boolean isInputMethodPickerShownForTest() { |
| 2986 | synchronized(mMethodMap) { |
| 2987 | if (mSwitchingDialog == null) { |
| 2988 | return false; |
| 2989 | } |
| 2990 | return mSwitchingDialog.isShowing(); |
| 2991 | } |
| 2992 | } |
| 2993 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2994 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | public void setInputMethod(IBinder token, String id) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2996 | if (!calledFromValidUser()) { |
| 2997 | return; |
| 2998 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2999 | setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID); |
| 3000 | } |
| 3001 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3002 | @Override |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3003 | public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3004 | if (!calledFromValidUser()) { |
| 3005 | return; |
| 3006 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3007 | synchronized (mMethodMap) { |
| 3008 | if (subtype != null) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3009 | setInputMethodWithSubtypeIdLocked(token, id, |
| 3010 | InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id), |
| 3011 | subtype.hashCode())); |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3012 | } else { |
| 3013 | setInputMethod(token, id); |
| 3014 | } |
| 3015 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3016 | } |
| 3017 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3018 | @Override |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3019 | public void showInputMethodAndSubtypeEnablerFromClient( |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3020 | IInputMethodClient client, String inputMethodId) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3021 | if (!calledFromValidUser()) { |
| 3022 | return; |
| 3023 | } |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3024 | synchronized (mMethodMap) { |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3025 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 3026 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3027 | } |
| 3028 | } |
| 3029 | |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3030 | @Override |
Tarandeep Singh | 164cfba | 2018-02-28 14:17:43 -0800 | [diff] [blame] | 3031 | public boolean switchToPreviousInputMethod(IBinder token) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3032 | if (!calledFromValidUser()) { |
| 3033 | return false; |
| 3034 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3035 | synchronized (mMethodMap) { |
satok | c445bcd | 2011-01-25 18:57:24 +0900 | [diff] [blame] | 3036 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3037 | final InputMethodInfo lastImi; |
satok | 208d563 | 2011-05-20 22:13:38 +0900 | [diff] [blame] | 3038 | if (lastIme != null) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3039 | lastImi = mMethodMap.get(lastIme.first); |
| 3040 | } else { |
| 3041 | lastImi = null; |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3042 | } |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3043 | String targetLastImiId = null; |
| 3044 | int subtypeId = NOT_A_SUBTYPE_ID; |
| 3045 | if (lastIme != null && lastImi != null) { |
| 3046 | final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId); |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3047 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3048 | final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID |
| 3049 | : mCurrentSubtype.hashCode(); |
| 3050 | // If the last IME is the same as the current IME and the last subtype is not |
| 3051 | // defined, there is no need to switch to the last IME. |
| 3052 | if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) { |
| 3053 | targetLastImiId = lastIme.first; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3054 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3055 | } |
| 3056 | } |
| 3057 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3058 | if (TextUtils.isEmpty(targetLastImiId) |
| 3059 | && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3060 | // This is a safety net. If the currentSubtype can't be added to the history |
| 3061 | // and the framework couldn't find the last ime, we will make the last ime be |
| 3062 | // the most applicable enabled keyboard subtype of the system imes. |
| 3063 | final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 3064 | if (enabled != null) { |
| 3065 | final int N = enabled.size(); |
| 3066 | final String locale = mCurrentSubtype == null |
| 3067 | ? mRes.getConfiguration().locale.toString() |
| 3068 | : mCurrentSubtype.getLocale(); |
| 3069 | for (int i = 0; i < N; ++i) { |
| 3070 | final InputMethodInfo imi = enabled.get(i); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3071 | if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3072 | InputMethodSubtype keyboardSubtype = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3073 | InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, |
| 3074 | InputMethodUtils.getSubtypes(imi), |
| 3075 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3076 | if (keyboardSubtype != null) { |
| 3077 | targetLastImiId = imi.getId(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3078 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3079 | imi, keyboardSubtype.hashCode()); |
| 3080 | if(keyboardSubtype.getLocale().equals(locale)) { |
| 3081 | break; |
| 3082 | } |
| 3083 | } |
| 3084 | } |
| 3085 | } |
| 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | if (!TextUtils.isEmpty(targetLastImiId)) { |
| 3090 | if (DEBUG) { |
| 3091 | Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second |
| 3092 | + ", from: " + mCurMethodId + ", " + subtypeId); |
| 3093 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3094 | setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3095 | return true; |
| 3096 | } else { |
| 3097 | return false; |
| 3098 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3102 | @Override |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3103 | public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3104 | if (!calledFromValidUser()) { |
| 3105 | return false; |
| 3106 | } |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3107 | synchronized (mMethodMap) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3108 | if (!calledWithValidToken(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3109 | return false; |
| 3110 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3111 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | d39ae85 | 2016-04-10 20:28:40 -0700 | [diff] [blame] | 3112 | onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype, |
| 3113 | true /* forward */); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3114 | if (nextSubtype == null) { |
| 3115 | return false; |
| 3116 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3117 | setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(), |
| 3118 | nextSubtype.mSubtypeId); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3119 | return true; |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | @Override |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3124 | public boolean shouldOfferSwitchingToNextInputMethod(IBinder token) { |
| 3125 | if (!calledFromValidUser()) { |
| 3126 | return false; |
| 3127 | } |
| 3128 | synchronized (mMethodMap) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3129 | if (!calledWithValidToken(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3130 | return false; |
| 3131 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3132 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | d39ae85 | 2016-04-10 20:28:40 -0700 | [diff] [blame] | 3133 | false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype, |
| 3134 | true /* forward */); |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3135 | if (nextSubtype == null) { |
| 3136 | return false; |
| 3137 | } |
| 3138 | return true; |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | @Override |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3143 | public InputMethodSubtype getLastInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3144 | if (!calledFromValidUser()) { |
| 3145 | return null; |
| 3146 | } |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3147 | synchronized (mMethodMap) { |
| 3148 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 3149 | // TODO: Handle the case of the last IME with no subtypes |
| 3150 | if (lastIme == null || TextUtils.isEmpty(lastIme.first) |
| 3151 | || TextUtils.isEmpty(lastIme.second)) return null; |
| 3152 | final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); |
| 3153 | if (lastImi == null) return null; |
| 3154 | try { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3155 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3156 | final int lastSubtypeId = |
| 3157 | InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 0e7d7d6 | 2011-07-05 13:28:06 +0900 | [diff] [blame] | 3158 | if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { |
| 3159 | return null; |
| 3160 | } |
| 3161 | return lastImi.getSubtypeAt(lastSubtypeId); |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3162 | } catch (NumberFormatException e) { |
| 3163 | return null; |
| 3164 | } |
| 3165 | } |
| 3166 | } |
| 3167 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3168 | @Override |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3169 | public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3170 | if (!calledFromValidUser()) { |
| 3171 | return; |
| 3172 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3173 | // By this IPC call, only a process which shares the same uid with the IME can add |
| 3174 | // additional input method subtypes to the IME. |
Yohei Yukawa | 70f5c48 | 2016-01-04 19:42:36 -0800 | [diff] [blame] | 3175 | if (TextUtils.isEmpty(imiId) || subtypes == null) return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3176 | synchronized (mMethodMap) { |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 3177 | if (!mSystemReady) { |
| 3178 | return; |
| 3179 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3180 | final InputMethodInfo imi = mMethodMap.get(imiId); |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3181 | if (imi == null) return; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3182 | final String[] packageInfos; |
| 3183 | try { |
| 3184 | packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 3185 | } catch (RemoteException e) { |
| 3186 | Slog.e(TAG, "Failed to get package infos"); |
| 3187 | return; |
| 3188 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3189 | if (packageInfos != null) { |
| 3190 | final int packageNum = packageInfos.length; |
| 3191 | for (int i = 0; i < packageNum; ++i) { |
| 3192 | if (packageInfos[i].equals(imi.getPackageName())) { |
| 3193 | mFileManager.addInputMethodSubtypes(imi, subtypes); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3194 | final long ident = Binder.clearCallingIdentity(); |
| 3195 | try { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3196 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3197 | } finally { |
| 3198 | Binder.restoreCallingIdentity(ident); |
| 3199 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3200 | return; |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3201 | } |
| 3202 | } |
| 3203 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3204 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3205 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3206 | } |
| 3207 | |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3208 | @Override |
| 3209 | public int getInputMethodWindowVisibleHeight() { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 3210 | return mWindowManagerInternal.getInputMethodWindowVisibleHeight(); |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3211 | } |
| 3212 | |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3213 | @Override |
Yohei Yukawa | 833bdce | 2016-05-15 20:05:56 -0700 | [diff] [blame] | 3214 | public void clearLastInputMethodWindowForTransition(IBinder token) { |
| 3215 | if (!calledFromValidUser()) { |
| 3216 | return; |
| 3217 | } |
Yohei Yukawa | fa49c00 | 2017-01-31 19:15:00 -0800 | [diff] [blame] | 3218 | synchronized (mMethodMap) { |
| 3219 | if (!calledWithValidToken(token)) { |
Yohei Yukawa | fa49c00 | 2017-01-31 19:15:00 -0800 | [diff] [blame] | 3220 | return; |
Yohei Yukawa | 833bdce | 2016-05-15 20:05:56 -0700 | [diff] [blame] | 3221 | } |
Yohei Yukawa | 833bdce | 2016-05-15 20:05:56 -0700 | [diff] [blame] | 3222 | } |
Yohei Yukawa | fa49c00 | 2017-01-31 19:15:00 -0800 | [diff] [blame] | 3223 | mWindowManagerInternal.clearLastInputMethodWindowForTransition(); |
Yohei Yukawa | 833bdce | 2016-05-15 20:05:56 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | @Override |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3227 | public void notifyUserAction(int sequenceNumber) { |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3228 | if (DEBUG) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3229 | Slog.d(TAG, "Got the notification of a user action. sequenceNumber:" + sequenceNumber); |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3230 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3231 | synchronized (mMethodMap) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3232 | if (mCurUserActionNotificationSequenceNumber != sequenceNumber) { |
| 3233 | if (DEBUG) { |
| 3234 | Slog.d(TAG, "Ignoring the user action notification due to the sequence number " |
| 3235 | + "mismatch. expected:" + mCurUserActionNotificationSequenceNumber |
| 3236 | + " actual: " + sequenceNumber); |
| 3237 | } |
| 3238 | return; |
| 3239 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3240 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 3241 | if (imi != null) { |
Yohei Yukawa | 0297051 | 2014-06-05 16:16:18 +0900 | [diff] [blame] | 3242 | mSwitchingController.onUserActionLocked(imi, mCurrentSubtype); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3243 | } |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3244 | } |
| 3245 | } |
| 3246 | |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3247 | private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3248 | synchronized (mMethodMap) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3249 | setInputMethodWithSubtypeIdLocked(token, id, subtypeId); |
| 3250 | } |
| 3251 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3253 | private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) { |
| 3254 | if (token == null) { |
| 3255 | if (mContext.checkCallingOrSelfPermission( |
| 3256 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3257 | != PackageManager.PERMISSION_GRANTED) { |
| 3258 | throw new SecurityException( |
| 3259 | "Using null token requires permission " |
| 3260 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3262 | } else if (mCurToken != token) { |
| 3263 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 3264 | + " token: " + token); |
| 3265 | return; |
| 3266 | } |
| 3267 | |
| 3268 | final long ident = Binder.clearCallingIdentity(); |
| 3269 | try { |
| 3270 | setInputMethodLocked(id, subtypeId); |
| 3271 | } finally { |
| 3272 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3273 | } |
| 3274 | } |
| 3275 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3276 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | public void hideMySoftInput(IBinder token, int flags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3278 | if (!calledFromValidUser()) { |
| 3279 | return; |
| 3280 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | synchronized (mMethodMap) { |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 3282 | if (!calledWithValidToken(token)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3283 | return; |
| 3284 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | long ident = Binder.clearCallingIdentity(); |
| 3286 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3287 | hideCurrentInputLocked(flags, null); |
| 3288 | } finally { |
| 3289 | Binder.restoreCallingIdentity(ident); |
| 3290 | } |
| 3291 | } |
| 3292 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3293 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3294 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3295 | public void showMySoftInput(IBinder token, int flags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3296 | if (!calledFromValidUser()) { |
| 3297 | return; |
| 3298 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3299 | synchronized (mMethodMap) { |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 3300 | if (!calledWithValidToken(token)) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3301 | return; |
| 3302 | } |
| 3303 | long ident = Binder.clearCallingIdentity(); |
| 3304 | try { |
| 3305 | showCurrentInputLocked(flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | } finally { |
| 3307 | Binder.restoreCallingIdentity(ident); |
| 3308 | } |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | void setEnabledSessionInMainThread(SessionState session) { |
| 3313 | if (mEnabledSession != session) { |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3314 | if (mEnabledSession != null && mEnabledSession.session != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3316 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3317 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | } catch (RemoteException e) { |
| 3319 | } |
| 3320 | } |
| 3321 | mEnabledSession = session; |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3322 | if (mEnabledSession != null && mEnabledSession.session != null) { |
| 3323 | try { |
| 3324 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
| 3325 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true); |
| 3326 | } catch (RemoteException e) { |
| 3327 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | } |
| 3329 | } |
| 3330 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3331 | |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 3332 | @MainThread |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3333 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3334 | public boolean handleMessage(Message msg) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3335 | SomeArgs args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | switch (msg.what) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3337 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3338 | final boolean showAuxSubtypes; |
| 3339 | switch (msg.arg1) { |
| 3340 | case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO: |
| 3341 | // This is undocumented so far, but IMM#showInputMethodPicker() has been |
| 3342 | // implemented so that auxiliary subtypes will be excluded when the soft |
| 3343 | // keyboard is invisible. |
| 3344 | showAuxSubtypes = mInputShown; |
| 3345 | break; |
| 3346 | case InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES: |
| 3347 | showAuxSubtypes = true; |
| 3348 | break; |
| 3349 | case InputMethodManager.SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES: |
| 3350 | showAuxSubtypes = false; |
| 3351 | break; |
| 3352 | default: |
| 3353 | Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1); |
| 3354 | return false; |
| 3355 | } |
| 3356 | showInputMethodMenu(showAuxSubtypes); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3357 | return true; |
| 3358 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3359 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 3360 | showInputMethodAndSubtypeEnabler((String)msg.obj); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3361 | return true; |
| 3362 | |
| 3363 | case MSG_SHOW_IM_CONFIG: |
| 3364 | showConfigureInputMethods(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3365 | return true; |
| 3366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3367 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | case MSG_UNBIND_INPUT: |
| 3370 | try { |
| 3371 | ((IInputMethod)msg.obj).unbindInput(); |
| 3372 | } catch (RemoteException e) { |
| 3373 | // There is nothing interesting about the method dying. |
| 3374 | } |
| 3375 | return true; |
| 3376 | case MSG_BIND_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3377 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | try { |
| 3379 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 3380 | } catch (RemoteException e) { |
| 3381 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3382 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | return true; |
| 3384 | case MSG_SHOW_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3385 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3387 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput(" |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 3388 | + msg.arg1 + ", " + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 3389 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | } catch (RemoteException e) { |
| 3391 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3392 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3393 | return true; |
| 3394 | case MSG_HIDE_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3395 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3396 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3397 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, " |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 3398 | + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 3399 | ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | } catch (RemoteException e) { |
| 3401 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3402 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3403 | return true; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 3404 | case MSG_HIDE_CURRENT_INPUT_METHOD: |
| 3405 | synchronized (mMethodMap) { |
| 3406 | hideCurrentInputLocked(0, null); |
| 3407 | } |
| 3408 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | case MSG_ATTACH_TOKEN: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3410 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3412 | 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] | 3413 | ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2); |
| 3414 | } catch (RemoteException e) { |
| 3415 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3416 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3417 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3418 | case MSG_CREATE_SESSION: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3419 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3420 | IInputMethod method = (IInputMethod)args.arg1; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3421 | InputChannel channel = (InputChannel)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3423 | method.createSession(channel, (IInputSessionCallback)args.arg3); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3424 | } catch (RemoteException e) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3425 | } finally { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3426 | // Dispose the channel if the input method is not local to this process |
| 3427 | // because the remote proxy will get its own copy when unparceled. |
| 3428 | if (channel != null && Binder.isProxy(method)) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3429 | channel.dispose(); |
| 3430 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3431 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3432 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3434 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3436 | |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3437 | case MSG_START_INPUT: { |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 3438 | final int missingMethods = msg.arg1; |
| 3439 | final boolean restarting = msg.arg2 != 0; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3440 | args = (SomeArgs) msg.obj; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 3441 | final IBinder startInputToken = (IBinder) args.arg1; |
| 3442 | final SessionState session = (SessionState) args.arg2; |
| 3443 | final IInputContext inputContext = (IInputContext) args.arg3; |
| 3444 | final EditorInfo editorInfo = (EditorInfo) args.arg4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3445 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | setEnabledSessionInMainThread(session); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 3447 | session.method.startInput(startInputToken, inputContext, missingMethods, |
| 3448 | editorInfo, restarting); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3449 | } catch (RemoteException e) { |
| 3450 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3451 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3452 | return true; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3453 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3455 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3456 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3457 | case MSG_UNBIND_CLIENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3458 | try { |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3459 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1, msg.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | } catch (RemoteException e) { |
| 3461 | // There is nothing interesting about the last client dying. |
| 3462 | } |
| 3463 | return true; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3464 | case MSG_BIND_CLIENT: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3465 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3466 | IInputMethodClient client = (IInputMethodClient)args.arg1; |
| 3467 | InputBindResult res = (InputBindResult)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3468 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3469 | client.onBindMethod(res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3471 | Slog.w(TAG, "Client died receiving input method " + args.arg2); |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3472 | } finally { |
| 3473 | // Dispose the channel if the input method is not local to this process |
| 3474 | // because the remote proxy will get its own copy when unparceled. |
| 3475 | if (res.channel != null && Binder.isProxy(client)) { |
| 3476 | res.channel.dispose(); |
| 3477 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3479 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3480 | return true; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3481 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 3482 | case MSG_SET_ACTIVE: |
| 3483 | try { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3484 | ((ClientState)msg.obj).client.setActive(msg.arg1 != 0, msg.arg2 != 0); |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 3485 | } catch (RemoteException e) { |
| 3486 | Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " |
| 3487 | + ((ClientState)msg.obj).pid + " uid " |
| 3488 | + ((ClientState)msg.obj).uid); |
| 3489 | } |
| 3490 | return true; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3491 | case MSG_SET_INTERACTIVE: |
| 3492 | handleSetInteractive(msg.arg1 != 0); |
| 3493 | return true; |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 3494 | case MSG_START_VR_INPUT: |
| 3495 | startVrInputMethodNoCheck((ComponentName) msg.obj); |
| 3496 | return true; |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3497 | case MSG_SWITCH_IME: |
| 3498 | handleSwitchInputMethod(msg.arg1 != 0); |
| 3499 | return true; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3500 | case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER: { |
| 3501 | final int sequenceNumber = msg.arg1; |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 3502 | final ClientState clientState = (ClientState)msg.obj; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3503 | try { |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 3504 | clientState.client.setUserActionNotificationSequenceNumber(sequenceNumber); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3505 | } catch (RemoteException e) { |
| 3506 | Slog.w(TAG, "Got RemoteException sending " |
| 3507 | + "setUserActionNotificationSequenceNumber(" |
| 3508 | + sequenceNumber + ") notification to pid " |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 3509 | + clientState.pid + " uid " |
| 3510 | + clientState.uid); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3511 | } |
| 3512 | return true; |
| 3513 | } |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3514 | case MSG_REPORT_FULLSCREEN_MODE: { |
| 3515 | final boolean fullscreen = msg.arg1 != 0; |
| 3516 | final ClientState clientState = (ClientState)msg.obj; |
| 3517 | try { |
| 3518 | clientState.client.reportFullscreenMode(fullscreen); |
| 3519 | } catch (RemoteException e) { |
| 3520 | Slog.w(TAG, "Got RemoteException sending " |
| 3521 | + "reportFullscreen(" + fullscreen + ") notification to pid=" |
| 3522 | + clientState.pid + " uid=" + clientState.uid); |
| 3523 | } |
| 3524 | return true; |
| 3525 | } |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3526 | |
| 3527 | // -------------------------------------------------------------- |
| 3528 | case MSG_HARD_KEYBOARD_SWITCH_CHANGED: |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3529 | mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3530 | return true; |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 3531 | case MSG_SYSTEM_UNLOCK_USER: |
| 3532 | final int userId = msg.arg1; |
| 3533 | onUnlockUser(userId); |
| 3534 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | } |
| 3536 | return false; |
| 3537 | } |
| 3538 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3539 | private void handleSetInteractive(final boolean interactive) { |
| 3540 | synchronized (mMethodMap) { |
| 3541 | mIsInteractive = interactive; |
| 3542 | updateSystemUiLocked(mCurToken, interactive ? mImeWindowVis : 0, mBackDisposition); |
| 3543 | |
| 3544 | // Inform the current client of the change in active status |
| 3545 | if (mCurClient != null && mCurClient.client != null) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3546 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 3547 | MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, mInFullscreenMode ? 1 : 0, |
| 3548 | mCurClient)); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3549 | } |
| 3550 | } |
| 3551 | } |
| 3552 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3553 | private void handleSwitchInputMethod(final boolean forwardDirection) { |
| 3554 | synchronized (mMethodMap) { |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3555 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | d39ae85 | 2016-04-10 20:28:40 -0700 | [diff] [blame] | 3556 | false, mMethodMap.get(mCurMethodId), mCurrentSubtype, forwardDirection); |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3557 | if (nextSubtype == null) { |
| 3558 | return; |
| 3559 | } |
| 3560 | setInputMethodLocked(nextSubtype.mImi.getId(), nextSubtype.mSubtypeId); |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 3561 | final InputMethodInfo newInputMethodInfo = mMethodMap.get(mCurMethodId); |
| 3562 | if (newInputMethodInfo == null) { |
| 3563 | return; |
| 3564 | } |
| 3565 | final CharSequence toastText = InputMethodUtils.getImeAndSubtypeDisplayName(mContext, |
| 3566 | newInputMethodInfo, mCurrentSubtype); |
| 3567 | if (!TextUtils.isEmpty(toastText)) { |
Yohei Yukawa | b2f901a | 2016-04-12 01:19:31 -0700 | [diff] [blame] | 3568 | if (mSubtypeSwitchedByShortCutToast == null) { |
| 3569 | mSubtypeSwitchedByShortCutToast = Toast.makeText(mContext, toastText, |
| 3570 | Toast.LENGTH_SHORT); |
| 3571 | } else { |
| 3572 | mSubtypeSwitchedByShortCutToast.setText(toastText); |
| 3573 | } |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 3574 | mSubtypeSwitchedByShortCutToast.show(); |
| 3575 | } |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3576 | } |
| 3577 | } |
| 3578 | |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 3579 | private boolean chooseNewDefaultIMELocked() { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3580 | final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME( |
| 3581 | mSettings.getEnabledInputMethodListLocked()); |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 3582 | if (imi != null) { |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 3583 | if (DEBUG) { |
| 3584 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 3585 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3586 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3587 | return true; |
| 3588 | } |
| 3589 | |
| 3590 | return false; |
| 3591 | } |
| 3592 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 3593 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3594 | void buildInputMethodListLocked(boolean resetDefaultEnabledIme) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3595 | if (DEBUG) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3596 | Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 3597 | + " \n ------ caller=" + Debug.getCallers(10)); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3598 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 3599 | if (!mSystemReady) { |
| 3600 | Slog.e(TAG, "buildInputMethodListLocked is not allowed until system is ready"); |
| 3601 | return; |
| 3602 | } |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3603 | mMethodList.clear(); |
| 3604 | mMethodMap.clear(); |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 3605 | mMethodMapUpdateCount++; |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 3606 | mMyPackageMonitor.clearKnownImePackageNamesLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3607 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3608 | // Use for queryIntentServicesAsUser |
| 3609 | final PackageManager pm = mContext.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3610 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 3611 | // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default |
| 3612 | // behavior of PackageManager is exactly what we want. It by default picks up appropriate |
| 3613 | // services depending on the unlock state for the specified user. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3614 | final List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3615 | new Intent(InputMethod.SERVICE_INTERFACE), |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 3616 | PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 3617 | mSettings.getCurrentUserId()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3618 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3619 | final HashMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3620 | mFileManager.getAllAdditionalInputMethodSubtypes(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | for (int i = 0; i < services.size(); ++i) { |
| 3622 | ResolveInfo ri = services.get(i); |
| 3623 | ServiceInfo si = ri.serviceInfo; |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3624 | final String imeId = InputMethodInfo.computeId(ri); |
| 3625 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 3626 | Slog.w(TAG, "Skipping input method " + imeId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3627 | + ": it does not require the permission " |
| 3628 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 3629 | continue; |
| 3630 | } |
| 3631 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3632 | if (DEBUG) Slog.d(TAG, "Checking " + imeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3634 | final List<InputMethodSubtype> additionalSubtypes = additionalSubtypeMap.get(imeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3635 | try { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3636 | InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes); |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3637 | mMethodList.add(p); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 3638 | final String id = p.getId(); |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3639 | mMethodMap.put(id, p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3640 | |
| 3641 | if (DEBUG) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3642 | Slog.d(TAG, "Found an input method " + p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3643 | } |
Tadashi G. Takaoka | 3c23d5b | 2016-09-16 11:41:07 +0900 | [diff] [blame] | 3644 | } catch (Exception e) { |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3645 | 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] | 3646 | } |
| 3647 | } |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3648 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3649 | // Construct the set of possible IME packages for onPackageChanged() to avoid false |
| 3650 | // negatives when the package state remains to be the same but only the component state is |
| 3651 | // changed. |
| 3652 | { |
| 3653 | // Here we intentionally use PackageManager.MATCH_DISABLED_COMPONENTS since the purpose |
| 3654 | // of this query is to avoid false negatives. PackageManager.MATCH_ALL could be more |
| 3655 | // conservative, but it seems we cannot use it for now (Issue 35176630). |
| 3656 | final List<ResolveInfo> allInputMethodServices = pm.queryIntentServicesAsUser( |
| 3657 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 3658 | PackageManager.MATCH_DISABLED_COMPONENTS, mSettings.getCurrentUserId()); |
| 3659 | final int N = allInputMethodServices.size(); |
| 3660 | for (int i = 0; i < N; ++i) { |
| 3661 | final ServiceInfo si = allInputMethodServices.get(i).serviceInfo; |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 3662 | if (android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 3663 | mMyPackageMonitor.addKnownImePackageNameLocked(si.packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3664 | } |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3665 | } |
| 3666 | } |
| 3667 | |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3668 | boolean reenableMinimumNonAuxSystemImes = false; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3669 | // TODO: The following code should find better place to live. |
| 3670 | if (!resetDefaultEnabledIme) { |
| 3671 | boolean enabledImeFound = false; |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3672 | boolean enabledNonAuxImeFound = false; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3673 | final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked(); |
| 3674 | final int N = enabledImes.size(); |
| 3675 | for (int i = 0; i < N; ++i) { |
| 3676 | final InputMethodInfo imi = enabledImes.get(i); |
| 3677 | if (mMethodList.contains(imi)) { |
| 3678 | enabledImeFound = true; |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3679 | if (!imi.isAuxiliaryIme()) { |
| 3680 | enabledNonAuxImeFound = true; |
| 3681 | break; |
| 3682 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3683 | } |
| 3684 | } |
| 3685 | if (!enabledImeFound) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 3686 | if (DEBUG) { |
| 3687 | Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs."); |
| 3688 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3689 | resetDefaultEnabledIme = true; |
| 3690 | resetSelectedInputMethodAndSubtypeLocked(""); |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3691 | } else if (!enabledNonAuxImeFound) { |
| 3692 | if (DEBUG) { |
| 3693 | Slog.i(TAG, "All the enabled non-Aux IMEs are gone. Do partial reset."); |
| 3694 | } |
| 3695 | reenableMinimumNonAuxSystemImes = true; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3696 | } |
| 3697 | } |
| 3698 | |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3699 | if (resetDefaultEnabledIme || reenableMinimumNonAuxSystemImes) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3700 | final ArrayList<InputMethodInfo> defaultEnabledIme = |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3701 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList, |
| 3702 | reenableMinimumNonAuxSystemImes); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 3703 | final int N = defaultEnabledIme.size(); |
| 3704 | for (int i = 0; i < N; ++i) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3705 | final InputMethodInfo imi = defaultEnabledIme.get(i); |
| 3706 | if (DEBUG) { |
| 3707 | Slog.d(TAG, "--- enable ime = " + imi); |
| 3708 | } |
| 3709 | setInputMethodEnabledLocked(imi.getId(), true); |
| 3710 | } |
| 3711 | } |
| 3712 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3713 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3714 | if (!TextUtils.isEmpty(defaultImiId)) { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3715 | if (!mMethodMap.containsKey(defaultImiId)) { |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3716 | Slog.w(TAG, "Default IME is uninstalled. Choose new default IME."); |
| 3717 | if (chooseNewDefaultIMELocked()) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3718 | updateInputMethodsFromSettingsLocked(true); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3719 | } |
| 3720 | } else { |
| 3721 | // Double check that the default IME is certainly enabled. |
| 3722 | setInputMethodEnabledLocked(defaultImiId, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3723 | } |
| 3724 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 3725 | // Here is not the perfect place to reset the switching controller. Ideally |
| 3726 | // mSwitchingController and mSettings should be able to share the same state. |
| 3727 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 3728 | // the same enabled IMEs list. |
Yohei Yukawa | c834a25 | 2014-05-21 22:42:32 +0900 | [diff] [blame] | 3729 | mSwitchingController.resetCircularListLocked(mContext); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3731 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3732 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3733 | |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3734 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
Tadashi G. Takaoka | f49688f | 2011-01-20 17:56:13 +0900 | [diff] [blame] | 3735 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3736 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 3737 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 3738 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3739 | if (!TextUtils.isEmpty(inputMethodId)) { |
Tadashi G. Takaoka | 2548020 | 2011-01-20 23:13:02 +0900 | [diff] [blame] | 3740 | intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3741 | } |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 3742 | final int userId; |
| 3743 | synchronized (mMethodMap) { |
| 3744 | userId = mSettings.getCurrentUserId(); |
| 3745 | } |
| 3746 | mContext.startActivityAsUser(intent, null, UserHandle.of(userId)); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | private void showConfigureInputMethods() { |
| 3750 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 3751 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 3752 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 3753 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Satoshi Kataoka | 3ba439d | 2012-10-05 18:30:13 +0900 | [diff] [blame] | 3754 | mContext.startActivityAsUser(intent, null, UserHandle.CURRENT); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3755 | } |
| 3756 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 3757 | private boolean isScreenLocked() { |
| 3758 | return mKeyguardManager != null |
| 3759 | && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure(); |
| 3760 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3761 | |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3762 | private void showInputMethodMenu(boolean showAuxSubtypes) { |
| 3763 | 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] | 3764 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 3765 | final boolean isScreenLocked = isScreenLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3766 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3767 | final String lastInputMethodId = mSettings.getSelectedInputMethod(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3768 | int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3769 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3770 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3771 | synchronized (mMethodMap) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 3772 | final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 3773 | mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked( |
| 3774 | mContext); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 3775 | if (immis == null || immis.size() == 0) { |
| 3776 | return; |
| 3777 | } |
| 3778 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3779 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3781 | final List<ImeSubtypeListItem> imList = |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3782 | mSwitchingController.getSortedInputMethodAndSubtypeListLocked( |
Yohei Yukawa | 5f8e731 | 2015-12-10 00:58:55 -0800 | [diff] [blame] | 3783 | showAuxSubtypes, isScreenLocked); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 3784 | |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3785 | if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3786 | final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3787 | if (currentSubtype != null) { |
| 3788 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3789 | lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
| 3790 | currentImi, currentSubtype.hashCode()); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3791 | } |
| 3792 | } |
| 3793 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 3794 | final int N = imList.size(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3795 | mIms = new InputMethodInfo[N]; |
| 3796 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3797 | int checkedItem = 0; |
| 3798 | for (int i = 0; i < N; ++i) { |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3799 | final ImeSubtypeListItem item = imList.get(i); |
| 3800 | mIms[i] = item.mImi; |
| 3801 | mSubtypeIds[i] = item.mSubtypeId; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3802 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3803 | int subtypeId = mSubtypeIds[i]; |
| 3804 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 3805 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 3806 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 3807 | checkedItem = i; |
| 3808 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | } |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3811 | |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 3812 | final Context settingsContext = new ContextThemeWrapper( |
| 3813 | ActivityThread.currentActivityThread().getSystemUiContext(), |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3814 | com.android.internal.R.style.Theme_DeviceDefault_Settings); |
| 3815 | |
| 3816 | mDialogBuilder = new AlertDialog.Builder(settingsContext); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3817 | mDialogBuilder.setOnCancelListener(new OnCancelListener() { |
| 3818 | @Override |
| 3819 | public void onCancel(DialogInterface dialog) { |
| 3820 | hideInputMethodMenu(); |
| 3821 | } |
| 3822 | }); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3823 | |
| 3824 | final Context dialogContext = mDialogBuilder.getContext(); |
| 3825 | final TypedArray a = dialogContext.obtainStyledAttributes(null, |
| 3826 | com.android.internal.R.styleable.DialogPreference, |
| 3827 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 3828 | final Drawable dialogIcon = a.getDrawable( |
| 3829 | com.android.internal.R.styleable.DialogPreference_dialogIcon); |
| 3830 | a.recycle(); |
| 3831 | |
| 3832 | mDialogBuilder.setIcon(dialogIcon); |
| 3833 | |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 3834 | final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3835 | final View tv = inflater.inflate( |
| 3836 | com.android.internal.R.layout.input_method_switch_dialog_title, null); |
| 3837 | mDialogBuilder.setCustomTitle(tv); |
| 3838 | |
| 3839 | // Setup layout for a toggle switch of the hardware keyboard |
| 3840 | mSwitchingDialogTitleView = tv; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3841 | mSwitchingDialogTitleView |
| 3842 | .findViewById(com.android.internal.R.id.hard_keyboard_section) |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 3843 | .setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3844 | ? View.VISIBLE : View.GONE); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3845 | final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById( |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3846 | com.android.internal.R.id.hard_keyboard_switch); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3847 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3848 | hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 3849 | @Override |
| 3850 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3851 | mSettings.setShowImeWithHardKeyboard(isChecked); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3852 | // Ensure that the input method dialog is dismissed when changing |
| 3853 | // the hardware keyboard state. |
| 3854 | hideInputMethodMenu(); |
| 3855 | } |
| 3856 | }); |
| 3857 | |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3858 | final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3859 | com.android.internal.R.layout.input_method_switch_item, imList, checkedItem); |
| 3860 | final OnClickListener choiceListener = new OnClickListener() { |
| 3861 | @Override |
| 3862 | public void onClick(final DialogInterface dialog, final int which) { |
| 3863 | synchronized (mMethodMap) { |
| 3864 | if (mIms == null || mIms.length <= which || mSubtypeIds == null |
| 3865 | || mSubtypeIds.length <= which) { |
| 3866 | return; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3867 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3868 | final InputMethodInfo im = mIms[which]; |
| 3869 | int subtypeId = mSubtypeIds[which]; |
| 3870 | adapter.mCheckedItem = which; |
| 3871 | adapter.notifyDataSetChanged(); |
| 3872 | hideInputMethodMenu(); |
| 3873 | if (im != null) { |
| 3874 | if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) { |
| 3875 | subtypeId = NOT_A_SUBTYPE_ID; |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 3876 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3877 | setInputMethodLocked(im.getId(), subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3879 | } |
| 3880 | } |
| 3881 | }; |
| 3882 | mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | mSwitchingDialog = mDialogBuilder.create(); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 3885 | mSwitchingDialog.setCanceledOnTouchOutside(true); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 3886 | final Window w = mSwitchingDialog.getWindow(); |
| 3887 | final WindowManager.LayoutParams attrs = w.getAttributes(); |
| 3888 | w.setType(TYPE_INPUT_METHOD_DIALOG); |
| 3889 | // Use an alternate token for the dialog for that window manager can group the token |
| 3890 | // with other IME windows based on type vs. grouping based on whichever token happens |
| 3891 | // to get selected by the system later on. |
| 3892 | attrs.token = mSwitchingDialogToken; |
| 3893 | attrs.privateFlags |= PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
| 3894 | attrs.setTitle("Select input method"); |
| 3895 | w.setAttributes(attrs); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 3896 | updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3897 | mSwitchingDialog.show(); |
| 3898 | } |
| 3899 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3900 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3901 | private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> { |
| 3902 | private final LayoutInflater mInflater; |
| 3903 | private final int mTextViewResourceId; |
| 3904 | private final List<ImeSubtypeListItem> mItemsList; |
Satoshi Kataoka | d214296 | 2012-11-12 18:43:06 +0900 | [diff] [blame] | 3905 | public int mCheckedItem; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3906 | public ImeSubtypeListAdapter(Context context, int textViewResourceId, |
| 3907 | List<ImeSubtypeListItem> itemsList, int checkedItem) { |
| 3908 | super(context, textViewResourceId, itemsList); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3909 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3910 | mTextViewResourceId = textViewResourceId; |
| 3911 | mItemsList = itemsList; |
| 3912 | mCheckedItem = checkedItem; |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 3913 | mInflater = context.getSystemService(LayoutInflater.class); |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | @Override |
| 3917 | public View getView(int position, View convertView, ViewGroup parent) { |
| 3918 | final View view = convertView != null ? convertView |
| 3919 | : mInflater.inflate(mTextViewResourceId, null); |
| 3920 | if (position < 0 || position >= mItemsList.size()) return view; |
| 3921 | final ImeSubtypeListItem item = mItemsList.get(position); |
| 3922 | final CharSequence imeName = item.mImeName; |
| 3923 | final CharSequence subtypeName = item.mSubtypeName; |
| 3924 | final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1); |
| 3925 | final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2); |
| 3926 | if (TextUtils.isEmpty(subtypeName)) { |
| 3927 | firstTextView.setText(imeName); |
| 3928 | secondTextView.setVisibility(View.GONE); |
| 3929 | } else { |
| 3930 | firstTextView.setText(subtypeName); |
| 3931 | secondTextView.setText(imeName); |
| 3932 | secondTextView.setVisibility(View.VISIBLE); |
| 3933 | } |
| 3934 | final RadioButton radioButton = |
| 3935 | (RadioButton)view.findViewById(com.android.internal.R.id.radio); |
| 3936 | radioButton.setChecked(position == mCheckedItem); |
| 3937 | return view; |
| 3938 | } |
| 3939 | } |
| 3940 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3941 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3942 | synchronized (mMethodMap) { |
| 3943 | hideInputMethodMenuLocked(); |
| 3944 | } |
| 3945 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3946 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3947 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3948 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3949 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3950 | if (mSwitchingDialog != null) { |
| 3951 | mSwitchingDialog.dismiss(); |
| 3952 | mSwitchingDialog = null; |
Yohei Yukawa | 1fc7a1d | 2018-04-18 17:31:27 -0700 | [diff] [blame] | 3953 | mSwitchingDialogTitleView = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3955 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 3956 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3957 | mDialogBuilder = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3958 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3959 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3961 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3962 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3963 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 3964 | // Make sure this is a valid input method. |
| 3965 | InputMethodInfo imm = mMethodMap.get(id); |
| 3966 | if (imm == null) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3967 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3968 | } |
| 3969 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3970 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 3971 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3972 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3973 | if (enabled) { |
| 3974 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 3975 | if (pair.first.equals(id)) { |
| 3976 | // We are enabling this input method, but it is already enabled. |
| 3977 | // Nothing to do. The previous state was enabled. |
| 3978 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3979 | } |
| 3980 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3981 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 3982 | // Previous state was disabled. |
| 3983 | return false; |
| 3984 | } else { |
| 3985 | StringBuilder builder = new StringBuilder(); |
| 3986 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 3987 | builder, enabledInputMethodsList, id)) { |
| 3988 | // Disabled input method is currently selected, switch to another one. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3989 | final String selId = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 3990 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 3991 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 3992 | resetSelectedInputMethodAndSubtypeLocked(""); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3993 | } |
| 3994 | // Previous state was enabled. |
| 3995 | return true; |
| 3996 | } else { |
| 3997 | // We are disabling the input method but it is already disabled. |
| 3998 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3999 | return false; |
| 4000 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4001 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4002 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 4003 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4004 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 4005 | boolean setSubtypeOnly) { |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4006 | // Updates to InputMethod are transient in VR mode. Its not included in history. |
| 4007 | final boolean isVrInput = imi != null && imi.isVrOnly(); |
| 4008 | if (!isVrInput) { |
| 4009 | // Update the history of InputMethod and Subtype |
| 4010 | mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype); |
| 4011 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4012 | |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 4013 | mCurUserActionNotificationSequenceNumber = |
| 4014 | Math.max(mCurUserActionNotificationSequenceNumber + 1, 1); |
| 4015 | if (DEBUG) { |
| 4016 | Slog.d(TAG, "Bump mCurUserActionNotificationSequenceNumber:" |
| 4017 | + mCurUserActionNotificationSequenceNumber); |
| 4018 | } |
| 4019 | |
| 4020 | if (mCurClient != null && mCurClient.client != null) { |
| 4021 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 4022 | MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER, |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 4023 | mCurUserActionNotificationSequenceNumber, mCurClient)); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 4024 | } |
| 4025 | |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4026 | if (isVrInput) { |
| 4027 | // Updates to InputMethod are transient in VR mode. Any changes to Settings are skipped. |
| 4028 | return; |
| 4029 | } |
| 4030 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4031 | // Set Subtype here |
| 4032 | if (imi == null || subtypeId < 0) { |
| 4033 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 4034 | mCurrentSubtype = null; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4035 | } else { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 4036 | if (subtypeId < imi.getSubtypeCount()) { |
| 4037 | InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId); |
| 4038 | mSettings.putSelectedSubtype(subtype.hashCode()); |
| 4039 | mCurrentSubtype = subtype; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4040 | } else { |
| 4041 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 4042 | // If the subtype is not specified, choose the most applicable one |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4043 | mCurrentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4044 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4045 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4046 | |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4047 | if (!setSubtypeOnly) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4048 | // Set InputMethod here |
| 4049 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 4050 | } |
| 4051 | } |
| 4052 | |
| 4053 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 4054 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 4055 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 4056 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 4057 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 4058 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 4059 | if (subtypeHashCode != null) { |
| 4060 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4061 | lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4062 | imi, Integer.parseInt(subtypeHashCode)); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4063 | } catch (NumberFormatException e) { |
| 4064 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 4065 | } |
| 4066 | } |
| 4067 | } |
| 4068 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4069 | } |
| 4070 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4071 | // If there are no selected shortcuts, tries finding the most applicable ones. |
| 4072 | private Pair<InputMethodInfo, InputMethodSubtype> |
| 4073 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) { |
| 4074 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 4075 | InputMethodInfo mostApplicableIMI = null; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4076 | InputMethodSubtype mostApplicableSubtype = null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4077 | boolean foundInSystemIME = false; |
| 4078 | |
| 4079 | // Search applicable subtype for each InputMethodInfo |
| 4080 | for (InputMethodInfo imi: imis) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4081 | final String imiId = imi.getId(); |
| 4082 | if (foundInSystemIME && !imiId.equals(mCurMethodId)) { |
| 4083 | continue; |
| 4084 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4085 | InputMethodSubtype subtype = null; |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 4086 | final List<InputMethodSubtype> enabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4087 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 4088 | // 1. Search by the current subtype's locale from enabledSubtypes. |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4089 | if (mCurrentSubtype != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4090 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 4091 | mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4092 | } |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 4093 | // 2. Search by the system locale from enabledSubtypes. |
| 4094 | // 3. Search the first enabled subtype matched with mode from enabledSubtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4095 | if (subtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4096 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 4097 | mRes, enabledSubtypes, mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4098 | } |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 4099 | final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4100 | InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode); |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 4101 | final ArrayList<InputMethodSubtype> subtypesForSearch = |
| 4102 | overridingImplicitlyEnabledSubtypes.isEmpty() |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4103 | ? InputMethodUtils.getSubtypes(imi) |
| 4104 | : overridingImplicitlyEnabledSubtypes; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4105 | // 4. Search by the current subtype's locale from all subtypes. |
| 4106 | if (subtype == null && mCurrentSubtype != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4107 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 4108 | mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4109 | } |
| 4110 | // 5. Search by the system locale from all subtypes. |
| 4111 | // 6. Search the first enabled subtype matched with mode from all subtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4112 | if (subtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4113 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 4114 | mRes, subtypesForSearch, mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4115 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4116 | if (subtype != null) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4117 | if (imiId.equals(mCurMethodId)) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4118 | // The current input method is the most applicable IME. |
| 4119 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4120 | mostApplicableSubtype = subtype; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4121 | break; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4122 | } else if (!foundInSystemIME) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4123 | // The system input method is 2nd applicable IME. |
| 4124 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4125 | mostApplicableSubtype = subtype; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4126 | if ((imi.getServiceInfo().applicationInfo.flags |
| 4127 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4128 | foundInSystemIME = true; |
| 4129 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4130 | } |
| 4131 | } |
| 4132 | } |
| 4133 | if (DEBUG) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4134 | if (mostApplicableIMI != null) { |
| 4135 | Slog.w(TAG, "Most applicable shortcut input method was:" |
| 4136 | + mostApplicableIMI.getId()); |
| 4137 | if (mostApplicableSubtype != null) { |
| 4138 | Slog.w(TAG, "Most applicable shortcut input method subtype was:" |
| 4139 | + "," + mostApplicableSubtype.getMode() + "," |
| 4140 | + mostApplicableSubtype.getLocale()); |
| 4141 | } |
| 4142 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4143 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 4144 | if (mostApplicableIMI != null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4145 | return new Pair<> (mostApplicableIMI, mostApplicableSubtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4146 | } else { |
| 4147 | return null; |
| 4148 | } |
| 4149 | } |
| 4150 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4151 | /** |
| 4152 | * @return Return the current subtype of this input method. |
| 4153 | */ |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 4154 | @Override |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4155 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4156 | // TODO: Make this work even for non-current users? |
| 4157 | if (!calledFromValidUser()) { |
| 4158 | return null; |
| 4159 | } |
| 4160 | synchronized (mMethodMap) { |
| 4161 | return getCurrentInputMethodSubtypeLocked(); |
| 4162 | } |
| 4163 | } |
| 4164 | |
| 4165 | private InputMethodSubtype getCurrentInputMethodSubtypeLocked() { |
satok | fdf419e | 2012-05-08 16:52:08 +0900 | [diff] [blame] | 4166 | if (mCurMethodId == null) { |
| 4167 | return null; |
| 4168 | } |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4169 | final boolean subtypeIsSelected = mSettings.isSubtypeSelected(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4170 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 4171 | if (imi == null || imi.getSubtypeCount() == 0) { |
| 4172 | return null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4173 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4174 | if (!subtypeIsSelected || mCurrentSubtype == null |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4175 | || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) { |
| 4176 | int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4177 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
| 4178 | // If there are no selected subtypes, the framework will try to find |
| 4179 | // the most applicable subtype from explicitly or implicitly enabled |
| 4180 | // subtypes. |
| 4181 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4182 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4183 | // If there is only one explicitly or implicitly enabled subtype, |
| 4184 | // just returns it. |
| 4185 | if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { |
| 4186 | mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0); |
| 4187 | } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4188 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4189 | mRes, explicitlyOrImplicitlyEnabledSubtypes, |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4190 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4191 | if (mCurrentSubtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4192 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4193 | mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, |
| 4194 | true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4195 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 4196 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4197 | } else { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4198 | mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId); |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 4199 | } |
| 4200 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4201 | return mCurrentSubtype; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4202 | } |
| 4203 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4204 | // TODO: We should change the return type from List to List<Parcelable> |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 4205 | @SuppressWarnings("rawtypes") |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4206 | @Override |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4207 | public List getShortcutInputMethodsAndSubtypes() { |
| 4208 | synchronized (mMethodMap) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4209 | ArrayList<Object> ret = new ArrayList<>(); |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 4210 | if (mShortcutInputMethodsAndSubtypes.size() == 0) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4211 | // If there are no selected shortcut subtypes, the framework will try to find |
| 4212 | // the most applicable subtype from all subtypes whose mode is |
| 4213 | // 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] | 4214 | Pair<InputMethodInfo, InputMethodSubtype> info = |
| 4215 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked( |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4216 | InputMethodUtils.SUBTYPE_MODE_VOICE); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4217 | if (info != null) { |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 4218 | ret.add(info.first); |
| 4219 | ret.add(info.second); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 4220 | } |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 4221 | return ret; |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 4222 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 4223 | for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) { |
| 4224 | ret.add(imi); |
| 4225 | for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) { |
| 4226 | ret.add(subtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4227 | } |
| 4228 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 4229 | return ret; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4230 | } |
| 4231 | } |
| 4232 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 4233 | @Override |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 4234 | public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4235 | // TODO: Make this work even for non-current users? |
| 4236 | if (!calledFromValidUser()) { |
| 4237 | return false; |
| 4238 | } |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 4239 | synchronized (mMethodMap) { |
| 4240 | if (subtype != null && mCurMethodId != null) { |
| 4241 | InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4242 | int subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode()); |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 4243 | if (subtypeId != NOT_A_SUBTYPE_ID) { |
| 4244 | setInputMethodLocked(mCurMethodId, subtypeId); |
| 4245 | return true; |
| 4246 | } |
| 4247 | } |
| 4248 | return false; |
| 4249 | } |
| 4250 | } |
| 4251 | |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 4252 | // 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] | 4253 | private static class InputMethodFileManager { |
| 4254 | private static final String SYSTEM_PATH = "system"; |
| 4255 | private static final String INPUT_METHOD_PATH = "inputmethod"; |
| 4256 | private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml"; |
| 4257 | private static final String NODE_SUBTYPES = "subtypes"; |
| 4258 | private static final String NODE_SUBTYPE = "subtype"; |
| 4259 | private static final String NODE_IMI = "imi"; |
| 4260 | private static final String ATTR_ID = "id"; |
| 4261 | private static final String ATTR_LABEL = "label"; |
| 4262 | private static final String ATTR_ICON = "icon"; |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4263 | private static final String ATTR_IME_SUBTYPE_ID = "subtypeId"; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4264 | private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale"; |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 4265 | private static final String ATTR_IME_SUBTYPE_LANGUAGE_TAG = "languageTag"; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4266 | private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode"; |
| 4267 | private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue"; |
| 4268 | private static final String ATTR_IS_AUXILIARY = "isAuxiliary"; |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 4269 | private static final String ATTR_IS_ASCII_CAPABLE = "isAsciiCapable"; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4270 | private final AtomicFile mAdditionalInputMethodSubtypeFile; |
| 4271 | private final HashMap<String, InputMethodInfo> mMethodMap; |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4272 | private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4273 | new HashMap<>(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 4274 | public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4275 | if (methodMap == null) { |
| 4276 | throw new NullPointerException("methodMap is null"); |
| 4277 | } |
| 4278 | mMethodMap = methodMap; |
Xiaohui Chen | 7c69636 | 2015-09-16 09:56:14 -0700 | [diff] [blame] | 4279 | final File systemDir = userId == UserHandle.USER_SYSTEM |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 4280 | ? new File(Environment.getDataDirectory(), SYSTEM_PATH) |
| 4281 | : Environment.getUserSystemDirectory(userId); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4282 | final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH); |
Yohei Yukawa | df5af48 | 2015-08-04 22:11:11 -0700 | [diff] [blame] | 4283 | if (!inputMethodDir.exists() && !inputMethodDir.mkdirs()) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4284 | Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath()); |
| 4285 | } |
| 4286 | final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 4287 | mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile, "input-subtypes"); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4288 | if (!subtypeFile.exists()) { |
| 4289 | // If "subtypes.xml" doesn't exist, create a blank file. |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4290 | writeAdditionalInputMethodSubtypes( |
| 4291 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4292 | } else { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4293 | readAdditionalInputMethodSubtypes( |
| 4294 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | private void deleteAllInputMethodSubtypes(String imiId) { |
| 4299 | synchronized (mMethodMap) { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4300 | mAdditionalSubtypesMap.remove(imiId); |
| 4301 | writeAdditionalInputMethodSubtypes( |
| 4302 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4303 | } |
| 4304 | } |
| 4305 | |
| 4306 | public void addInputMethodSubtypes( |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 4307 | InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4308 | synchronized (mMethodMap) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4309 | final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4310 | final int N = additionalSubtypes.length; |
| 4311 | for (int i = 0; i < N; ++i) { |
| 4312 | final InputMethodSubtype subtype = additionalSubtypes[i]; |
satok | ed2b24e | 2011-08-31 18:03:21 +0900 | [diff] [blame] | 4313 | if (!subtypes.contains(subtype)) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4314 | subtypes.add(subtype); |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4315 | } else { |
| 4316 | Slog.w(TAG, "Duplicated subtype definition found: " |
| 4317 | + subtype.getLocale() + ", " + subtype.getMode()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4318 | } |
| 4319 | } |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4320 | mAdditionalSubtypesMap.put(imi.getId(), subtypes); |
| 4321 | writeAdditionalInputMethodSubtypes( |
| 4322 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() { |
| 4327 | synchronized (mMethodMap) { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 4328 | return mAdditionalSubtypesMap; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4329 | } |
| 4330 | } |
| 4331 | |
| 4332 | private static void writeAdditionalInputMethodSubtypes( |
| 4333 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile, |
| 4334 | HashMap<String, InputMethodInfo> methodMap) { |
| 4335 | // Safety net for the case that this function is called before methodMap is set. |
| 4336 | final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0; |
| 4337 | FileOutputStream fos = null; |
| 4338 | try { |
| 4339 | fos = subtypesFile.startWrite(); |
| 4340 | final XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 4341 | out.setOutput(fos, StandardCharsets.UTF_8.name()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4342 | out.startDocument(null, true); |
| 4343 | out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 4344 | out.startTag(null, NODE_SUBTYPES); |
| 4345 | for (String imiId : allSubtypes.keySet()) { |
| 4346 | if (isSetMethodMap && !methodMap.containsKey(imiId)) { |
| 4347 | Slog.w(TAG, "IME uninstalled or not valid.: " + imiId); |
| 4348 | continue; |
| 4349 | } |
| 4350 | out.startTag(null, NODE_IMI); |
| 4351 | out.attribute(null, ATTR_ID, imiId); |
| 4352 | final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId); |
| 4353 | final int N = subtypesList.size(); |
| 4354 | for (int i = 0; i < N; ++i) { |
| 4355 | final InputMethodSubtype subtype = subtypesList.get(i); |
| 4356 | out.startTag(null, NODE_SUBTYPE); |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4357 | if (subtype.hasSubtypeId()) { |
| 4358 | out.attribute(null, ATTR_IME_SUBTYPE_ID, |
| 4359 | String.valueOf(subtype.getSubtypeId())); |
| 4360 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4361 | out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId())); |
| 4362 | out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId())); |
| 4363 | out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale()); |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 4364 | out.attribute(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG, |
| 4365 | subtype.getLanguageTag()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4366 | out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode()); |
| 4367 | out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue()); |
| 4368 | out.attribute(null, ATTR_IS_AUXILIARY, |
| 4369 | String.valueOf(subtype.isAuxiliary() ? 1 : 0)); |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 4370 | out.attribute(null, ATTR_IS_ASCII_CAPABLE, |
| 4371 | String.valueOf(subtype.isAsciiCapable() ? 1 : 0)); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4372 | out.endTag(null, NODE_SUBTYPE); |
| 4373 | } |
| 4374 | out.endTag(null, NODE_IMI); |
| 4375 | } |
| 4376 | out.endTag(null, NODE_SUBTYPES); |
| 4377 | out.endDocument(); |
| 4378 | subtypesFile.finishWrite(fos); |
| 4379 | } catch (java.io.IOException e) { |
| 4380 | Slog.w(TAG, "Error writing subtypes", e); |
| 4381 | if (fos != null) { |
| 4382 | subtypesFile.failWrite(fos); |
| 4383 | } |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | private static void readAdditionalInputMethodSubtypes( |
| 4388 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) { |
| 4389 | if (allSubtypes == null || subtypesFile == null) return; |
| 4390 | allSubtypes.clear(); |
Yohei Yukawa | 5894b43 | 2015-08-11 13:29:24 -0700 | [diff] [blame] | 4391 | try (final FileInputStream fis = subtypesFile.openRead()) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4392 | final XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 4393 | parser.setInput(fis, StandardCharsets.UTF_8.name()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4394 | int type = parser.getEventType(); |
| 4395 | // Skip parsing until START_TAG |
| 4396 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 4397 | && type != XmlPullParser.END_DOCUMENT) {} |
| 4398 | String firstNodeName = parser.getName(); |
| 4399 | if (!NODE_SUBTYPES.equals(firstNodeName)) { |
| 4400 | throw new XmlPullParserException("Xml doesn't start with subtypes"); |
| 4401 | } |
| 4402 | final int depth =parser.getDepth(); |
| 4403 | String currentImiId = null; |
| 4404 | ArrayList<InputMethodSubtype> tempSubtypesArray = null; |
| 4405 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 4406 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 4407 | if (type != XmlPullParser.START_TAG) |
| 4408 | continue; |
| 4409 | final String nodeName = parser.getName(); |
| 4410 | if (NODE_IMI.equals(nodeName)) { |
| 4411 | currentImiId = parser.getAttributeValue(null, ATTR_ID); |
| 4412 | if (TextUtils.isEmpty(currentImiId)) { |
| 4413 | Slog.w(TAG, "Invalid imi id found in subtypes.xml"); |
| 4414 | continue; |
| 4415 | } |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 4416 | tempSubtypesArray = new ArrayList<>(); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4417 | allSubtypes.put(currentImiId, tempSubtypesArray); |
| 4418 | } else if (NODE_SUBTYPE.equals(nodeName)) { |
| 4419 | if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) { |
| 4420 | Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId); |
| 4421 | continue; |
| 4422 | } |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4423 | final int icon = Integer.parseInt( |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4424 | parser.getAttributeValue(null, ATTR_ICON)); |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4425 | final int label = Integer.parseInt( |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4426 | parser.getAttributeValue(null, ATTR_LABEL)); |
| 4427 | final String imeSubtypeLocale = |
| 4428 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE); |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 4429 | final String languageTag = |
| 4430 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4431 | final String imeSubtypeMode = |
| 4432 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE); |
| 4433 | final String imeSubtypeExtraValue = |
| 4434 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE); |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 4435 | final boolean isAuxiliary = "1".equals(String.valueOf( |
| 4436 | parser.getAttributeValue(null, ATTR_IS_AUXILIARY))); |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 4437 | final boolean isAsciiCapable = "1".equals(String.valueOf( |
| 4438 | parser.getAttributeValue(null, ATTR_IS_ASCII_CAPABLE))); |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4439 | final InputMethodSubtypeBuilder builder = new InputMethodSubtypeBuilder() |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 4440 | .setSubtypeNameResId(label) |
| 4441 | .setSubtypeIconResId(icon) |
| 4442 | .setSubtypeLocale(imeSubtypeLocale) |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 4443 | .setLanguageTag(languageTag) |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 4444 | .setSubtypeMode(imeSubtypeMode) |
| 4445 | .setSubtypeExtraValue(imeSubtypeExtraValue) |
| 4446 | .setIsAuxiliary(isAuxiliary) |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4447 | .setIsAsciiCapable(isAsciiCapable); |
| 4448 | final String subtypeIdString = |
| 4449 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_ID); |
| 4450 | if (subtypeIdString != null) { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4451 | builder.setSubtypeId(Integer.parseInt(subtypeIdString)); |
Yohei Yukawa | 66baf69 | 2016-04-11 02:29:35 -0700 | [diff] [blame] | 4452 | } |
| 4453 | tempSubtypesArray.add(builder.build()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4454 | } |
| 4455 | } |
Yohei Yukawa | 5894b43 | 2015-08-11 13:29:24 -0700 | [diff] [blame] | 4456 | } catch (XmlPullParserException | IOException | NumberFormatException e) { |
| 4457 | Slog.w(TAG, "Error reading subtypes", e); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4458 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 4459 | } |
| 4460 | } |
| 4461 | } |
| 4462 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4463 | private static final class LocalServiceImpl implements InputMethodManagerInternal { |
| 4464 | @NonNull |
| 4465 | private final Handler mHandler; |
| 4466 | |
| 4467 | LocalServiceImpl(@NonNull final Handler handler) { |
| 4468 | mHandler = handler; |
| 4469 | } |
| 4470 | |
| 4471 | @Override |
| 4472 | public void setInteractive(boolean interactive) { |
| 4473 | // Do everything in handler so as not to block the caller. |
| 4474 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_INTERACTIVE, |
| 4475 | interactive ? 1 : 0, 0)); |
| 4476 | } |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 4477 | |
| 4478 | @Override |
| 4479 | public void switchInputMethod(boolean forwardDirection) { |
| 4480 | // Do everything in handler so as not to block the caller. |
| 4481 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SWITCH_IME, |
| 4482 | forwardDirection ? 1 : 0, 0)); |
| 4483 | } |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4484 | |
| 4485 | @Override |
| 4486 | public void hideCurrentInputMethod() { |
| 4487 | mHandler.removeMessages(MSG_HIDE_CURRENT_INPUT_METHOD); |
| 4488 | mHandler.sendEmptyMessage(MSG_HIDE_CURRENT_INPUT_METHOD); |
| 4489 | } |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4490 | |
| 4491 | @Override |
| 4492 | public void startVrInputMethodNoCheck(@Nullable ComponentName componentName) { |
| 4493 | mHandler.sendMessage(mHandler.obtainMessage(MSG_START_VR_INPUT, componentName)); |
| 4494 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 4497 | private static String imeWindowStatusToString(final int imeWindowVis) { |
| 4498 | final StringBuilder sb = new StringBuilder(); |
| 4499 | boolean first = true; |
| 4500 | if ((imeWindowVis & InputMethodService.IME_ACTIVE) != 0) { |
| 4501 | sb.append("Active"); |
| 4502 | first = false; |
| 4503 | } |
| 4504 | if ((imeWindowVis & InputMethodService.IME_VISIBLE) != 0) { |
| 4505 | if (!first) { |
| 4506 | sb.append("|"); |
| 4507 | } |
| 4508 | sb.append("Visible"); |
| 4509 | } |
| 4510 | return sb.toString(); |
| 4511 | } |
| 4512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | @Override |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4514 | public IInputContentUriToken createInputContentUriToken(@Nullable IBinder token, |
| 4515 | @Nullable Uri contentUri, @Nullable String packageName) { |
| 4516 | if (!calledFromValidUser()) { |
| 4517 | return null; |
| 4518 | } |
| 4519 | |
| 4520 | if (token == null) { |
| 4521 | throw new NullPointerException("token"); |
| 4522 | } |
| 4523 | if (packageName == null) { |
| 4524 | throw new NullPointerException("packageName"); |
| 4525 | } |
| 4526 | if (contentUri == null) { |
| 4527 | throw new NullPointerException("contentUri"); |
| 4528 | } |
| 4529 | final String contentUriScheme = contentUri.getScheme(); |
| 4530 | if (!"content".equals(contentUriScheme)) { |
| 4531 | throw new InvalidParameterException("contentUri must have content scheme"); |
| 4532 | } |
| 4533 | |
| 4534 | synchronized (mMethodMap) { |
| 4535 | final int uid = Binder.getCallingUid(); |
| 4536 | if (mCurMethodId == null) { |
| 4537 | return null; |
| 4538 | } |
| 4539 | if (mCurToken != token) { |
| 4540 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurToken=" + mCurToken |
| 4541 | + " token=" + token); |
| 4542 | return null; |
| 4543 | } |
| 4544 | // We cannot simply distinguish a bad IME that reports an arbitrary package name from |
| 4545 | // an unfortunate IME whose internal state is already obsolete due to the asynchronous |
| 4546 | // nature of our system. Let's compare it with our internal record. |
| 4547 | if (!TextUtils.equals(mCurAttribute.packageName, packageName)) { |
| 4548 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurAttribute.packageName=" |
| 4549 | + mCurAttribute.packageName + " packageName=" + packageName); |
| 4550 | return null; |
| 4551 | } |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4552 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4553 | final int imeUserId = UserHandle.getUserId(uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4554 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4555 | final int appUserId = UserHandle.getUserId(mCurClient.uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4556 | // This user ID may be invalid if "contentUri" embedded an invalid user ID. |
| 4557 | final int contentUriOwnerUserId = ContentProvider.getUserIdFromUri(contentUri, |
| 4558 | imeUserId); |
| 4559 | final Uri contentUriWithoutUserId = ContentProvider.getUriWithoutUserId(contentUri); |
| 4560 | // Note: InputContentUriTokenHandler.take() checks whether the IME (specified by "uid") |
| 4561 | // actually has the right to grant a read permission for "contentUriWithoutUserId" that |
| 4562 | // is claimed to belong to "contentUriOwnerUserId". For example, specifying random |
| 4563 | // content URI and/or contentUriOwnerUserId just results in a SecurityException thrown |
| 4564 | // from InputContentUriTokenHandler.take() and can never be allowed beyond what is |
| 4565 | // actually allowed to "uid", which is guaranteed to be the IME's one. |
| 4566 | return new InputContentUriTokenHandler(contentUriWithoutUserId, uid, |
| 4567 | packageName, contentUriOwnerUserId, appUserId); |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4568 | } |
| 4569 | } |
| 4570 | |
| 4571 | @Override |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4572 | public void reportFullscreenMode(IBinder token, boolean fullscreen) { |
| 4573 | if (!calledFromValidUser()) { |
| 4574 | return; |
| 4575 | } |
| 4576 | synchronized (mMethodMap) { |
| 4577 | if (!calledWithValidToken(token)) { |
| 4578 | return; |
| 4579 | } |
| 4580 | if (mCurClient != null && mCurClient.client != null) { |
| 4581 | mInFullscreenMode = fullscreen; |
| 4582 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 4583 | MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, mCurClient)); |
| 4584 | } |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4589 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 4590 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4591 | |
| 4592 | IInputMethod method; |
| 4593 | ClientState client; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4594 | ClientState focusedWindowClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4596 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | synchronized (mMethodMap) { |
| 4599 | p.println("Current Input Method Manager state:"); |
| 4600 | int N = mMethodList.size(); |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 4601 | p.println(" Input Methods: mMethodMapUpdateCount=" + mMethodMapUpdateCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | for (int i=0; i<N; i++) { |
| 4603 | InputMethodInfo info = mMethodList.get(i); |
| 4604 | p.println(" InputMethod #" + i + ":"); |
| 4605 | info.dump(p, " "); |
| 4606 | } |
| 4607 | p.println(" Clients:"); |
| 4608 | for (ClientState ci : mClients.values()) { |
| 4609 | p.println(" Client " + ci + ":"); |
| 4610 | p.println(" client=" + ci.client); |
| 4611 | p.println(" inputContext=" + ci.inputContext); |
| 4612 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 4613 | p.println(" curSession=" + ci.curSession); |
| 4614 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4615 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4616 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 4617 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 4618 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow |
| 4619 | + " softInputMode=" + |
| 4620 | InputMethodClient.softInputModeToString(mCurFocusedWindowSoftInputMode) |
| 4621 | + " client=" + mCurFocusedWindowClient); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4622 | focusedWindowClient = mCurFocusedWindowClient; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4623 | p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection |
| 4624 | + " mBoundToMethod=" + mBoundToMethod); |
| 4625 | p.println(" mCurToken=" + mCurToken); |
| 4626 | p.println(" mCurIntent=" + mCurIntent); |
| 4627 | method = mCurMethod; |
| 4628 | p.println(" mCurMethod=" + mCurMethod); |
| 4629 | p.println(" mEnabledSession=" + mEnabledSession); |
Yohei Yukawa | ebda7d7 | 2016-04-02 17:39:23 -0700 | [diff] [blame] | 4630 | p.println(" mImeWindowVis=" + imeWindowStatusToString(mImeWindowVis)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | p.println(" mShowRequested=" + mShowRequested |
| 4632 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 4633 | + " mShowForced=" + mShowForced |
| 4634 | + " mInputShown=" + mInputShown); |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4635 | p.println(" mInFullscreenMode=" + mInFullscreenMode); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 4636 | p.println(" mCurUserActionNotificationSequenceNumber=" |
| 4637 | + mCurUserActionNotificationSequenceNumber); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4638 | p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 4639 | p.println(" mSettingsObserver=" + mSettingsObserver); |
Yohei Yukawa | d724886 | 2015-06-03 23:56:12 -0700 | [diff] [blame] | 4640 | p.println(" mSwitchingController:"); |
| 4641 | mSwitchingController.dump(p); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4642 | p.println(" mSettings:"); |
| 4643 | mSettings.dumpLocked(p, " "); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 4644 | |
| 4645 | p.println(" mStartInputHistory:"); |
| 4646 | mStartInputHistory.dump(pw, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4647 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4648 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4649 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4650 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4651 | pw.flush(); |
| 4652 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4653 | TransferPipe.dumpAsync(client.client.asBinder(), fd, args); |
| 4654 | } catch (IOException | RemoteException e) { |
| 4655 | p.println("Failed to dump input method client: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4656 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4657 | } else { |
| 4658 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4660 | |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4661 | if (focusedWindowClient != null && client != focusedWindowClient) { |
| 4662 | p.println(" "); |
| 4663 | p.println("Warning: Current input method client doesn't match the last focused. " |
| 4664 | + "window."); |
| 4665 | p.println("Dumping input method client in the last focused window just in case."); |
| 4666 | p.println(" "); |
| 4667 | pw.flush(); |
| 4668 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4669 | TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args); |
| 4670 | } catch (IOException | RemoteException e) { |
| 4671 | p.println("Failed to dump input method client in focused window: " + e); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4672 | } |
| 4673 | } |
| 4674 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4675 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4676 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4677 | pw.flush(); |
| 4678 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4679 | TransferPipe.dumpAsync(method.asBinder(), fd, args); |
| 4680 | } catch (IOException | RemoteException e) { |
| 4681 | p.println("Failed to dump input method service: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4683 | } else { |
| 4684 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | } |
| 4686 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4687 | |
| 4688 | @BinderThread |
| 4689 | @Override |
| 4690 | public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out, |
| 4691 | @Nullable FileDescriptor err, |
| 4692 | @NonNull String[] args, @Nullable ShellCallback callback, |
| 4693 | @NonNull ResultReceiver resultReceiver) throws RemoteException { |
| 4694 | new ShellCommandImpl(this).exec( |
| 4695 | this, in, out, err, args, callback, resultReceiver); |
| 4696 | } |
| 4697 | |
| 4698 | private static final class ShellCommandImpl extends ShellCommand { |
| 4699 | @NonNull |
| 4700 | final InputMethodManagerService mService; |
| 4701 | |
| 4702 | ShellCommandImpl(InputMethodManagerService service) { |
| 4703 | mService = service; |
| 4704 | } |
| 4705 | |
| 4706 | @BinderThread |
| 4707 | @ShellCommandResult |
| 4708 | @Override |
| 4709 | public int onCommand(@Nullable String cmd) { |
Yohei Yukawa | dfdab73 | 2018-02-21 07:16:30 +0900 | [diff] [blame] | 4710 | if ("refresh_debug_properties".equals(cmd)) { |
| 4711 | return refreshDebugProperties(); |
| 4712 | } |
| 4713 | |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4714 | // For existing "adb shell ime <command>". |
| 4715 | if ("ime".equals(cmd)) { |
| 4716 | final String imeCommand = getNextArg(); |
| 4717 | if (imeCommand == null || "help".equals(imeCommand) || "-h".equals(imeCommand)) { |
| 4718 | onImeCommandHelp(); |
| 4719 | return ShellCommandResult.SUCCESS; |
| 4720 | } |
| 4721 | switch (imeCommand) { |
| 4722 | case "list": |
| 4723 | return mService.handleShellCommandListInputMethods(this); |
| 4724 | case "enable": |
| 4725 | return mService.handleShellCommandEnableDisableInputMethod(this, true); |
| 4726 | case "disable": |
| 4727 | return mService.handleShellCommandEnableDisableInputMethod(this, false); |
| 4728 | case "set": |
| 4729 | return mService.handleShellCommandSetInputMethod(this); |
| 4730 | case "reset": |
| 4731 | return mService.handleShellCommandResetInputMethod(this); |
| 4732 | default: |
| 4733 | getOutPrintWriter().println("Unknown command: " + imeCommand); |
| 4734 | return ShellCommandResult.FAILURE; |
| 4735 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4736 | } |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4737 | |
| 4738 | return handleDefaultCommands(cmd); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | @BinderThread |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 4742 | @ShellCommandResult |
| 4743 | private int refreshDebugProperties() { |
| 4744 | DebugFlags.FLAG_OPTIMIZE_START_INPUT.refresh(); |
| 4745 | return ShellCommandResult.SUCCESS; |
| 4746 | } |
| 4747 | |
| 4748 | @BinderThread |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4749 | @Override |
| 4750 | public void onHelp() { |
| 4751 | try (PrintWriter pw = getOutPrintWriter()) { |
| 4752 | pw.println("InputMethodManagerService commands:"); |
| 4753 | pw.println(" help"); |
| 4754 | pw.println(" Prints this help text."); |
| 4755 | pw.println(" dump [options]"); |
| 4756 | pw.println(" Synonym of dumpsys."); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4757 | pw.println(" ime <command> [options]"); |
| 4758 | pw.println(" Manipulate IMEs. Run \"ime help\" for details."); |
| 4759 | } |
| 4760 | } |
| 4761 | |
| 4762 | private void onImeCommandHelp() { |
| 4763 | try (IndentingPrintWriter pw = |
| 4764 | new IndentingPrintWriter(getOutPrintWriter(), " ", 100)) { |
| 4765 | pw.println("ime <command>:"); |
| 4766 | pw.increaseIndent(); |
| 4767 | |
| 4768 | pw.println("list [-a] [-s]"); |
| 4769 | pw.increaseIndent(); |
| 4770 | pw.println("prints all enabled input methods."); |
| 4771 | pw.increaseIndent(); |
| 4772 | pw.println("-a: see all input methods"); |
| 4773 | pw.println("-s: only a single summary line of each"); |
| 4774 | pw.decreaseIndent(); |
| 4775 | pw.decreaseIndent(); |
| 4776 | |
| 4777 | pw.println("enable <ID>"); |
| 4778 | pw.increaseIndent(); |
| 4779 | pw.println("allows the given input method ID to be used."); |
| 4780 | pw.decreaseIndent(); |
| 4781 | |
| 4782 | pw.println("disable <ID>"); |
| 4783 | pw.increaseIndent(); |
| 4784 | pw.println("disallows the given input method ID to be used."); |
| 4785 | pw.decreaseIndent(); |
| 4786 | |
| 4787 | pw.println("set <ID>"); |
| 4788 | pw.increaseIndent(); |
| 4789 | pw.println("switches to the given input method ID."); |
| 4790 | pw.decreaseIndent(); |
| 4791 | |
| 4792 | pw.println("reset"); |
| 4793 | pw.increaseIndent(); |
| 4794 | pw.println("reset currently selected/enabled IMEs to the default ones as if " |
| 4795 | + "the device is initially booted with the current locale."); |
| 4796 | pw.decreaseIndent(); |
| 4797 | |
| 4798 | pw.decreaseIndent(); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4799 | } |
| 4800 | } |
| 4801 | } |
| 4802 | |
| 4803 | // ---------------------------------------------------------------------- |
| 4804 | // Shell command handlers: |
| 4805 | |
| 4806 | /** |
| 4807 | * Handles {@code adb shell ime list}. |
| 4808 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 4809 | * @return Exit code of the command. |
| 4810 | */ |
| 4811 | @BinderThread |
| 4812 | @ShellCommandResult |
| 4813 | private int handleShellCommandListInputMethods(@NonNull ShellCommand shellCommand) { |
| 4814 | boolean all = false; |
| 4815 | boolean brief = false; |
| 4816 | while (true) { |
| 4817 | final String nextOption = shellCommand.getNextOption(); |
| 4818 | if (nextOption == null) { |
| 4819 | break; |
| 4820 | } |
| 4821 | switch (nextOption) { |
| 4822 | case "-a": |
| 4823 | all = true; |
| 4824 | break; |
| 4825 | case "-s": |
| 4826 | brief = true; |
| 4827 | break; |
| 4828 | } |
| 4829 | } |
| 4830 | final List<InputMethodInfo> methods = all ? |
| 4831 | getInputMethodList() : getEnabledInputMethodList(); |
| 4832 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 4833 | final Printer printer = x -> pr.println(x); |
| 4834 | final int N = methods.size(); |
| 4835 | for (int i = 0; i < N; ++i) { |
| 4836 | if (brief) { |
| 4837 | pr.println(methods.get(i).getId()); |
| 4838 | } else { |
| 4839 | pr.print(methods.get(i).getId()); pr.println(":"); |
| 4840 | methods.get(i).dump(printer, " "); |
| 4841 | } |
| 4842 | } |
| 4843 | return ShellCommandResult.SUCCESS; |
| 4844 | } |
| 4845 | |
| 4846 | /** |
| 4847 | * Handles {@code adb shell ime enable} and {@code adb shell ime disable}. |
| 4848 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 4849 | * @param enabled {@code true} if the command was {@code adb shell ime enable}. |
| 4850 | * @return Exit code of the command. |
| 4851 | */ |
| 4852 | @BinderThread |
| 4853 | @ShellCommandResult |
| 4854 | @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS) |
| 4855 | private int handleShellCommandEnableDisableInputMethod( |
| 4856 | @NonNull ShellCommand shellCommand, boolean enabled) { |
| 4857 | if (!calledFromValidUser()) { |
| 4858 | shellCommand.getErrPrintWriter().print( |
| 4859 | "Must be called from the foreground user or with INTERACT_ACROSS_USERS_FULL"); |
| 4860 | return ShellCommandResult.FAILURE; |
| 4861 | } |
| 4862 | final String id = shellCommand.getNextArgRequired(); |
| 4863 | |
| 4864 | final boolean previouslyEnabled; |
| 4865 | synchronized (mMethodMap) { |
| 4866 | if (mContext.checkCallingOrSelfPermission( |
| 4867 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 4868 | != PackageManager.PERMISSION_GRANTED) { |
| 4869 | shellCommand.getErrPrintWriter().print( |
| 4870 | "Caller must have WRITE_SECURE_SETTINGS permission"); |
| 4871 | throw new SecurityException( |
| 4872 | "Requires permission " |
| 4873 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 4874 | } |
| 4875 | |
| 4876 | final long ident = Binder.clearCallingIdentity(); |
| 4877 | try { |
| 4878 | previouslyEnabled = setInputMethodEnabledLocked(id, enabled); |
| 4879 | } finally { |
| 4880 | Binder.restoreCallingIdentity(ident); |
| 4881 | } |
| 4882 | } |
| 4883 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 4884 | pr.print("Input method "); |
| 4885 | pr.print(id); |
| 4886 | pr.print(": "); |
| 4887 | pr.print((enabled == previouslyEnabled) ? "already " : "now "); |
| 4888 | pr.println(enabled ? "enabled" : "disabled"); |
| 4889 | return ShellCommandResult.SUCCESS; |
| 4890 | } |
| 4891 | |
| 4892 | /** |
| 4893 | * Handles {@code adb shell ime set}. |
| 4894 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 4895 | * @return Exit code of the command. |
| 4896 | */ |
| 4897 | @BinderThread |
| 4898 | @ShellCommandResult |
| 4899 | private int handleShellCommandSetInputMethod(@NonNull ShellCommand shellCommand) { |
| 4900 | final String id = shellCommand.getNextArgRequired(); |
| 4901 | setInputMethod(null, id); |
| 4902 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 4903 | pr.print("Input method "); |
| 4904 | pr.print(id); |
| 4905 | pr.println(" selected"); |
| 4906 | return ShellCommandResult.SUCCESS; |
| 4907 | } |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 4908 | |
| 4909 | /** |
| 4910 | * Handles {@code adb shell ime reset-ime}. |
| 4911 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 4912 | * @return Exit code of the command. |
| 4913 | */ |
| 4914 | @BinderThread |
| 4915 | @ShellCommandResult |
| 4916 | @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS) |
| 4917 | private int handleShellCommandResetInputMethod(@NonNull ShellCommand shellCommand) { |
| 4918 | if (!calledFromValidUser()) { |
| 4919 | shellCommand.getErrPrintWriter().print( |
| 4920 | "Must be called from the foreground user or with INTERACT_ACROSS_USERS_FULL"); |
| 4921 | return ShellCommandResult.FAILURE; |
| 4922 | } |
| 4923 | synchronized (mMethodMap) { |
| 4924 | if (mContext.checkCallingOrSelfPermission( |
| 4925 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 4926 | != PackageManager.PERMISSION_GRANTED) { |
| 4927 | shellCommand.getErrPrintWriter().print( |
| 4928 | "Caller must have WRITE_SECURE_SETTINGS permission"); |
| 4929 | throw new SecurityException( |
| 4930 | "Requires permission " |
| 4931 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 4932 | } |
| 4933 | final String nextIme; |
| 4934 | final List<InputMethodInfo> nextEnabledImes; |
| 4935 | final long ident = Binder.clearCallingIdentity(); |
| 4936 | try { |
| 4937 | synchronized (mMethodMap) { |
| 4938 | hideCurrentInputLocked(0, null); |
| 4939 | unbindCurrentMethodLocked(false); |
| 4940 | // Reset the current IME |
| 4941 | resetSelectedInputMethodAndSubtypeLocked(null); |
| 4942 | // Also reset the settings of the current IME |
| 4943 | mSettings.putSelectedInputMethod(null); |
| 4944 | // Disable all enabled IMEs. |
| 4945 | { |
| 4946 | final ArrayList<InputMethodInfo> enabledImes = |
| 4947 | mSettings.getEnabledInputMethodListLocked(); |
| 4948 | final int N = enabledImes.size(); |
| 4949 | for (int i = 0; i < N; ++i) { |
| 4950 | setInputMethodEnabledLocked(enabledImes.get(i).getId(), false); |
| 4951 | } |
| 4952 | } |
| 4953 | // Re-enable with default enabled IMEs. |
| 4954 | { |
| 4955 | final ArrayList<InputMethodInfo> defaultEnabledIme = |
| 4956 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList); |
| 4957 | final int N = defaultEnabledIme.size(); |
| 4958 | for (int i = 0; i < N; ++i) { |
| 4959 | setInputMethodEnabledLocked(defaultEnabledIme.get(i).getId(), true); |
| 4960 | } |
| 4961 | } |
| 4962 | updateInputMethodsFromSettingsLocked(true /* enabledMayChange */); |
| 4963 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 4964 | mSettings.getEnabledInputMethodListLocked(), |
| 4965 | mSettings.getCurrentUserId(), |
| 4966 | mContext.getBasePackageName()); |
| 4967 | nextIme = mSettings.getSelectedInputMethod(); |
| 4968 | nextEnabledImes = getEnabledInputMethodList(); |
| 4969 | } |
| 4970 | } finally { |
| 4971 | Binder.restoreCallingIdentity(ident); |
| 4972 | } |
| 4973 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 4974 | pr.println("Reset current and enabled IMEs"); |
| 4975 | pr.println("Newly selected IME:"); |
| 4976 | pr.print(" "); pr.println(nextIme); |
| 4977 | pr.println("Newly enabled IMEs:"); |
| 4978 | { |
| 4979 | final int N = nextEnabledImes.size(); |
| 4980 | for (int i = 0; i < N; ++i) { |
| 4981 | pr.print(" "); |
| 4982 | pr.println(nextEnabledImes.get(i).getId()); |
| 4983 | } |
| 4984 | } |
| 4985 | return ShellCommandResult.SUCCESS; |
| 4986 | } |
| 4987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4988 | } |