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