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