History log of /frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
2ead893b182abce54fc4c7f3e63ca17947a94726 10-May-2017 Andrew Sapperstein <asapperstein@google.com> Merge "Update input method menu to use proper context." into oc-dev
8a3b4cbb6f64f9fe43c6f7696c7f5f3b1209e7e3 28-Apr-2017 Andrew Sapperstein <asapperstein@google.com> Update input method menu to use proper context.

Was not using the system ui context so it wasn't getting
themed properly.

Bug: 36059431
Fixes: 37788566
Test: built sailfish-userdebug, opened the keyboard by selecting an
EditText, long-pressed keyboard to switch keyboards, observed
Change-Id: I6ec2381620d1a88c025a0f9228bc58bc11db6bc4
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
83b40f69bef4ba17bb63ac30d52f661a12d5b4f4 26-Apr-2017 Dianne Hackborn <hackbod@google.com> Work on issue #36891897: Need to ensure foreground services can't...

...hide themselves

The activity manager now keeps track of all apps that are running
foreground services and builds a notification showing them to the
user. We ensure they are shown to the user for at least 30 seconds
(configurable). If foreground services are executed while the
screen is off, their apps will be shown to the user for at least
30 seconds after the screen turns back on.

While doing this I am also adding a new process state to distinguish
between "important background" stuff that should bypass bg check vs.
ones that don't. By default, these now no longer bypass bg check,
which is really the expected (and documented) behavior. There is a
new bind flag to allow them to bypass bg check, which is currently
only used by the IME.

Also add some new job scheduler commands that will be used to
write new tests cases for jobs timing out.

Bug: 36891897

Test: manual

Change-Id: Ied3f7b56444254513fd776f06b88bc0e54704958
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d6475a682d9651a651f60856baef9b17b4633b13 17-Apr-2017 Yohei Yukawa <yukawa@google.com> A new power button mode to hide the IME when shown

As discussed in Bug 33038203 on certain platforms there is a demand
that the power button can change the behavior depending on whether an
IME window is shown on the screen or not. The behavior requested here
can be summarized into two parts:

* Hide the IME window if it is shown [1]
* Go to the home screen if no IME window is shown

This CL implements the above request by introducing a new config mode
for config_shortPressOnPowerBehavior. Note the definition of when an
IME is shown is often tricky than people would expect. The way this
CL is implemented is to propagate IME window state from
InputMethodManagerService (IMMS) to PhoneWindowManager via
WindowManagerService regarding when the back button on the NavBar for
phones/tablets should be shown as an IME dismiss key [2].

[1]: Even with this CL the IME still is allowed to ignore the request
to hide the software keyboard. Currently there is no official
protocol to forcefully hide the software keyboard. How to deal
with such a situation is a long standing TODO task.
[2]: Internally this is controlled by the following IMMS fields:
- InputMethodManagerService#mImeWindowVis
- InputMethodManagerService#mBackDisposition
Note that those fields rely on self-report from the IME. To be
precise, the base implementation of InputMethodService is
responsible for report back its internal state to IMMS when
necessary. The important point is that, although this could
allow a malicious IME to confuse the system UI to some extent,
supporting malicious IMEs is not clearly a goal of Android.
Anyway, the definition of when an IME is shown is a kind of
hot topic in several system services recently. Hopefully we
can come up with better definition and reliable mechanism in
a future release.

Fixes: 33824860
Test: Manually verified as follows
1. Change config_shortPressOnPowerBehavior to "5"
2. Rebuilt the OS image and flash it to the device
3. Make sure that the power button works like a home button
if software keyboard is not shown.
4. Open dialer and focus in to the text field shown on top
5. Make sure that the AOSP keyboard is shown.
6. Run 'adb shell dumpsys input_method' to observe the
following line:
mImeWindowVis=Active|Visible
7. Tap the power button to make sure that the AOSP keyboard
gets dismissed.
8. Tap the power button again to make sure that it works
as if a home button.
Test: Manually tested as follows
1. Open dialer and focus in to the text field to show an IME
2. Run 'adb shell dumpsys window policy' to make sure
mDismissImeOnBackKeyPressed=true
3. Tap the back button to dismiss the IME
4. Run 'adb shell dumpsys window policy' to make sure
mDismissImeOnBackKeyPressed=false
Change-Id: I20721547c73360a70b5fc5cbe06824d577d1768a
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
fe9a53bc45fd0124a876dc0a49680aaf86641d3e 31-Mar-2017 Jeff Sharkey <jsharkey@android.com> Consistent dump() permission checking.

This change introduces new methods on DumpUtils that can check if the
caller has DUMP and/or PACKAGE_USAGE_STATS access. It then moves all
existing dump() methods to use these checks so that we emit
consistent error messages.

Test: cts-tradefed run commandAndExit cts-dev -m CtsSecurityTestCases -t android.security.cts.ServicePermissionsTest
Bug: 32806790
Change-Id: Iaff6b9506818ee082b1e169c89ebe1001b3bfeca
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
13df64aa8ea86a423d21c5e4c07e5d41dd811c0b 01-Apr-2017 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Use correct binding flags when reconnecting to IME" into oc-dev
a67a45958fa2763ff9ee51d3baa23d1f9b908bbb 31-Mar-2017 Yohei Yukawa <yukawa@google.com> Use correct binding flags when reconnecting to IME

Since ICS MR-1 [1], InputMethodManagerService (IMMS) establishes two
connections to an IME: one is for general connection and the other to
allow the system to adjust the IME's performance characteristics much
more like a foreground activity. The tricky point is that the former
connection can be re-connected not only IMMS#startInputInnerLocked() in
but also in IMMS#showCurrentInputLocked().

It turns out that some previous attempts to adjust BIND_ flags for the
former connection [2][3] were not applied to
IMMS#showCurrentInputLocked(). This CL addresses that inconsistency by
make it clear that IMMS establishes up to connections to the IME.

[1]: Id1f73de66dc93d63212183958a72119ad174318b
2c84cfc001fb92a71811bf7384b7f865ff31ff9d
[2]: I1724113f42abe7862e8aecb6faae5a7620245e89
c8230519728b14065effd3b7d4eca273ff86160c
[3]: Ie5793fd9b40d980fa18f80246326511ed6ae0597
f0f94d129b6eb3c48624e915898d86d4f2de59ff

Test: Manuall tested as follows.
1. Build and flash an OS image.
2. Complete the setup wizard (if any).
3. tapas LatinIME && make -j
4. adb install -r out/target/product/generic/system/app/LatinIME/LatinIME.apk
5. Run a test program that keeps calling IMM#showSoftInput()
6. adb shell ime enable com.android.inputmethod.latin/.LatinIME
7. adb shell ime set com.android.inputmethod.latin/.LatinIME
8. adb shell dumpsys activity processes android
Make sure that there is a ConnectionRecord to
com.android.inputmethod.latin that has "CR !FG UI !VIS" bits.
9. adb install -r out/target/product/generic/system/app/LatinIME/LatinIME.apk
10. adb shell dumpsys activity processes android
Make sure that there is a ConnectionRecord to
com.android.inputmethod.latin that has "CR !FG UI !VIS" bits.
Fixes: 36727763
Change-Id: Ib7fa34b21e1fb8bb5b19a9b08e36d0565f3dd266
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
282cfefea0fbbd299839e353e6d30affdcd4a55c 27-Mar-2017 Chris Wren <cwren@android.com> standardize system notification IDs

All the trivial cases, plus some fixes to try to
mitigate collisions with the complex ones.

Complex services to follow in another CL,

Bug: 32584866
Test: make framework services
Change-Id: Ie9663600171d8ede11676e9d66f009dbb06def03
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
af759c52ce01fe6b5144957e38da956af01a217b 15-Feb-2017 Geoffrey Pitsch <gpitsch@google.com> Channels for Frameworks notifications

Adapts all notifications used by system services to use channels.
Channels are initialized by SystemServer after the NotificationService
has started.

Test: runtest systemui-notification
Change-Id: I25c45293b786adb57787aeab4c2613c9d7c89dab
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
75af69c9f72d425e837088605902ba48e9355028 23-Feb-2017 Yohei Yukawa <yukawa@google.com> Merge "Optimize IMMS.MyPackageMonitor more"
5e3e8a5205f5ed584ad9466746f6fa397f293476 15-Feb-2017 Yohei Yukawa <yukawa@google.com> Optimize IMMS.MyPackageMonitor more

This CL is a follow up CL to my previous CL [1] that aimed to reduce
false positives in InputMethodManagerService.MyPackageMonitor when
deciding if InputMethodManagerService (IMMS) needs to rebuild the list
of enabled IMEs or not.

Currently IMMS.MyPackageMonitor#onSomePackagesChanged() gets called
back to trigger IMMS#buildInputMethodListLocked() when either the
following rule A or B is fulfiled.

A. Intent with one of the following actions for any package name:
- ACTION_PACKAGE_ADDED
- ACTION_PACKAGE_REMOVED
- ACTION_EXTERNAL_APPLICATIONS_AVAILABLE
- ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE
- ACTION_PACKAGES_SUSPENDED
- ACTION_PACKAGES_UNSUSPENDED
B. ACTION_PACKAGE_CHANGED with a package that is included in the
known IME package list, which can be obtained from PackageManager.

The previous CL [1] addressed Bug 28181208 by introducing the rule B,
but we can actually apply the same optimization for A, except for one
false negative case where an appearing package that is not in the
known IME package list actually contains one or more
InputMethodService.

In short, we can reduce false positives by replacing the above two
rules with the following two rules.

A. Intent with one of the following actions for any package name that
is in the known IME package list:
- ACTION_PACKAGE_ADDED
- ACTION_PACKAGE_CHANGED
- ACTION_PACKAGE_REMOVED
- ACTION_EXTERNAL_APPLICATIONS_AVAILABLE
- ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE
- ACTION_PACKAGES_SUSPENDED
- ACTION_PACKAGES_UNSUSPENDED
B. Intent with one of the following actions for any package that
implements at least one InputMethodServivce.
- ACTION_PACKAGE_ADDED
- ACTION_EXTERNAL_APPLICATIONS_AVAILABLE

Basically in the rule A PackageManager gives us the list of relevant
package names that might contain IMEs regardless enabled/disabled
state, and such a list works well to filter out irrelevant
notifications except for one case where a new package is adding one
or new IMEs that we did not know. This is why we also need the rule B.

Even though the rule B requires a secondary query to PackageManager,
it can be done outside of the state lock of IMMS.

[1]: I7b69c349318ce06a48d03a4468cf2c45bfb73dc2
c4e4491735ad5614ec4592fae98f05c455f5944d

Test: Manually verified as follows.
1. tapas ShortcutDemo && make -j
2. Copy ShortcutDemo.apk to the current directory.
3. adb shell dumpsys input_method | grep mMethodMapUpdateCount=
to check the "mMethodMapUpdateCount".
4. adb install -r ShortcutDemo.apk
5. adb shell dumpsys input_method | grep mMethodMapUpdateCount=
to make sure "mMethodMapUpdateCount" remains unchanged.
6. adb install -r ShortcutDemo.apk
7. adb shell dumpsys input_method | grep mMethodMapUpdateCount=
to make sure "mMethodMapUpdateCount" remains unchanged.
8. adb uninstall com.example.android.pm.shortcutdemo
9. adb shell dumpsys input_method | grep mMethodMapUpdateCount=
to make sure "mMethodMapUpdateCount" remains unchanged.
Test: Manually verified as follows.
1. tapas SoftKeyboard && make -j
2. Copy SoftKeyboard.apk to the current directory.
3. adb root
4. adb install -r SoftKeyboard.apk
5. adb shell dumpsys input_method
Make sure that
com.example.android.softkeyboard/.SoftKeyboard
is recognized by IMMS.
6. adb shell pm disable com.example.android.softkeyboard/.SoftKeyboard
7. adb shell dumpsys input_method
Make sure that
com.example.android.softkeyboard/.SoftKeyboard
is no longer recognized by IMMS.
8. adb shell pm enable com.example.android.softkeyboard/.SoftKeyboard
9. adb shell dumpsys input_method
Make sure that
com.example.android.softkeyboard/.SoftKeyboard
is recognized by IMMS again.
Fixes: 35361128
Change-Id: I063688297156188f68fe0b55a46d72f2e811dc88
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
bbb10e8ec05956c7dc84091e6d9c2a6f44e1480a 18-Feb-2017 Yohei Yukawa <yukawa@google.com> Really fix regressions in IMMS#setImeWindowStatus

My previous CL [1] that aimed to fix Bug 35395372 was imperfect.
It just converted InvalidParameterException into NullPointerException
due to a silly mistake in a new error check.

[1]: Ib9448c551d9a30776a999c27a5ff20f1a095633a
ee2a7ed3d971f83134a2b28258dd2e56f9634f94

Test: Made sure Bug 35395372 and Bug 35479942 are no longer
reproducible, that is,
1. Flash a new image and complete the setup wizard on a
direct-boot unaware device.
2. Set a device password and require it upon each device boot.
3. adb reboot
4. Observe the default IME does not crash because of
NullPointerException/InvalidParameterException thrown by IMMS.
Test: Made sure IMM#showSoftInputFromInputMethod(IBinder, int) does
not throw an NullPointerException even in an extreme case.
1. Rebuild LatinIME with the following code in LatinIME.java
@Override
public AbstractInputMethodImpl onCreateInputMethodInterface() {
return new InputMethodService.InputMethodImpl() {
@Override
public void attachToken(IBinder token) {
super.attachToken(token);

final InputMethodManager imm =
getSystemService(InputMethodManager.class);
final IBinder imeToken =
getWindow().getWindow().getAttributes().token;
imm.showSoftInputFromInputMethod(imeToken, 0);
}
};
}
2. adb install -r LatinIME.apk
3. adb shell ime enable com.android.inputmethod.latin/.LatinIME
4. adb shell ime set com.android.inputmethod.latin/.LatinIME
5. Tap any text field.
4. Observe LatinIME does not crash because of
NullPointerException/InvalidParameterException thrown by IMMS.
Bug: 34628091
Bug: 35079353
Fixes: 35395372
Fixes: 35479942
Change-Id: Id8e34ecb28480755e8141b6e46820b37fe3dc92b
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
ee2a7ed3d971f83134a2b28258dd2e56f9634f94 16-Feb-2017 Yohei Yukawa <yukawa@google.com> Allow setImeWindowStatus with null startInputToken

This is a follow up CL to my previous CL [1], which caused an unexpected
side effect that leads the current IME to crash due to a too strict
requiremnt.

It turns out that it was too early for us to start requiring non-null
StartInputToken in InputMethodManagerService#setImeWindowStatus()
because in many places we have assumed that an IME can show/hide its
software keyboard even before an IME target window is associated with
the IME.

There are two major cases that we missed:

- InputMethodManager#showSoftInputFromInputMethod(IBinder, int):

This method does not require that the calling IME is already bound
to an IME target window.

- InputMethodManager#showSoftInputUnchecked(int ,ResultReceiver):

This @hide method allows the caller application to let current IME
show the software keyboard with bypassing all the normal focus
management tasks in InputMethodManager. We should seriously
consider to deprecate this @hide method, but to do that we have to
clean up some internal components and SearchView in the support
library that still rely on this method.

Bug 35395372 is triggered by the second scenario, but until we sort out
all the possible corner cases, we should allow null startInputToken as a
valid request, like we had have done so before the CL [1] introduced
such a validation.

[1]: I9921b381e02106dbffff5e0b3d13f0a1245ce807
6db3bfe33d92127d203ec872a0b353585a99f256

Test: Made sure Bug 35395372 is no longer reproducible, that is,
1. Flash a new image and complete the setup wizard on a
direct-boot unaware device.
2. Set a device password and require it upon each device boot.
3. adb reboot
4. Observe the default IME does not crash because of
InvalidParameterException thrown by IMMS.
Test: Made sure IMM#showSoftInputFromInputMethod(IBinder, int) does
not throw an InvalidParameterException even in an extreme case.
1. Rebuild LatinIME with the following code in LatinIME.java
@Override
public AbstractInputMethodImpl onCreateInputMethodInterface() {
return new InputMethodService.InputMethodImpl() {
@Override
public void attachToken(IBinder token) {
super.attachToken(token);

final InputMethodManager imm =
getSystemService(InputMethodManager.class);
final IBinder imeToken =
getWindow().getWindow().getAttributes().token;
imm.showSoftInputFromInputMethod(imeToken, 0);
}
};
}
2. adb install -r LatinIME.apk
3. adb shell ime enable com.android.inputmethod.latin/.LatinIME
4. adb shell ime set com.android.inputmethod.latin/.LatinIME
5. Tap any text field.
4. Observe LatinIME does not crash because of
InvalidParameterException thrown by IMMS.
Bug: 34628091
Bug: 35079353
Fixes: 35395372
Change-Id: Ib9448c551d9a30776a999c27a5ff20f1a095633a
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
019b018cf79d59c4fba0c32c0fbadc3a369924c4 16-Feb-2017 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Access IMMS#mSettings only inside the lock"
278f2ab11baefa9c298403f7be70e7dfc22cf601 15-Feb-2017 Yohei Yukawa <yukawa@google.com> Access IMMS#mSettings only inside the lock

This is a preparation CL before addresssing Bug 35361128.

IMMS.MyPackageMonitor#isChangingPackagesOfCurrentUser() needs to be
called after taking a lock for IMMS#mMethodMap because it internally
relies on InputMethodManagerService#mSettings.

Test: Made sure that the device can boot and the IME is available.
Bug: 35361128
Change-Id: I66752a275f20f6ba33bc211ffb8d6fd269250c0d
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
357b2f60e147d18af9c8399b346a9e63de1baaf3 14-Feb-2017 Yohei Yukawa <yukawa@google.com> Take state snapshot in IMMS#attachNewInputLocked()

With this CL, we can finally start taking a state snapshot every time
IMMS#attachNewInputLocked() gets called, which allows us to include
the last N (currently set to 16) history of such snapshots in dumpsys
from InputMethodManagerService:

adb shell dumpsys input_method

This is a huge milestone for us to start relying more on historical
debugging rather than logcat-based debugging.

Test: Run `adb shell dumpsys input_method` to make sure that
"mStartInputHistory" entries are updated.
Bug: 35079353
Change-Id: Icb29c4ef0703553ead8654d3255a554de6d1a9b4
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
b37d8bddc9ace8e3a4d66f206e933350b390c805 14-Feb-2017 Yohei Yukawa <yukawa@google.com> Add missing final and @GuardedBy

This is a follow up CL to my previous CL [1], where I forgot to add
final and @GuardedBy to InputMethodManagerService#mStartInputMap.

[1]: I9921b381e02106dbffff5e0b3d13f0a1245ce807
6db3bfe33d92127d203ec872a0b353585a99f256

Test: Compile
Bug: 35079353
Change-Id: I29897752e16573a27bf700b1d822889789c35292
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
3400795aecc8b1c139dd0726716545118b125f47 14-Feb-2017 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Propagate setImeWindowStatus() to WMS"
ff54b306de12066a7bf67bd494ca8971d8c4135c 13-Feb-2017 Yohei Yukawa <yukawa@google.com> Merge "Track event flow to IMMS#setImeWindowStatus"
69e68024220d3f18b08cbb314c7991f8f76cbe49 13-Feb-2017 Yohei Yukawa <yukawa@google.com> Propagate setImeWindowStatus() to WMS

setImeWindowStatus() introduced in the previous CL [1] can help
WindowManagerService (WMS) address Bug 34628091. As a preparation
this CL has InputMethodManagerService propagate relevant information
to WMS WMS for later use.

[1]: I9921b381e02106dbffff5e0b3d13f0a1245ce807
db2afde0e584904ee4ce115ce176a4dfe1773990

Test: Verified the callback in WindowManagerService as follows:
1. Rebuild the system with DEBUG_INPUT_METHOD=true
2. adb logcat -s WindowManager:*
to make sure the visibility passed to
WindowManagerService#updateInputMethodWindowStatus matches
to the actual IME window visibility
Bug: 34628091
Bug: 35079353
Change-Id: I54fb1faf513883a54293a756e4c9d2ae9453d778
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
6db3bfe33d92127d203ec872a0b353585a99f256 13-Feb-2017 Yohei Yukawa <yukawa@google.com> Track event flow to IMMS#setImeWindowStatus

This is part of work to introduce historical debugging infrastructure
for Android IME.

In this CL, we will focus on the following two event flows.

A1. IMMS#attachNewInputLocked() queues MSG_(RE)START_INPUT to deliver
new InputConnection/EditorInfo to the current IME
A2. The IME triggers IMS#onStartInput()/IMS#onRestartInput() and
updates the following fields:
- InputMethodService#mStartedInputConnection
- InputMethodService#mInputEditorInfo

B1. IME is expected to call back IMM#setImeWindowStatus() to notify
its window visibility change to IMMS.
B2. IMMS updates the following field if the caller is still the
current IME.
- InputMethodManagerService#mImeWindowVis

What this CL aims to do is to enable IMMS to access A1 state when it
was in B2 state, by considering that for given a B1 the last A2
happened before B1 is the cause of B1 and B2.

To do this, IMMS issues a binder token in A1 and each IME keeps it
so that it can be passed in B1. By using this Binder token as a key,
IMMS can keep tracking state snapshot taken from each A1. Note that
those state snapshots keep alive until the Binder token's proxy in the
IME process loses strong reference from its GC root.

Test: Make sure `adb shell dumpsys input_method | grep mImeWindowVis`
matches to the IME window visibility.
Test: Make sure the current IME is not receiving any
InvalidParameterException from IMMS.
Bug: 35079353
Change-Id: I9921b381e02106dbffff5e0b3d13f0a1245ce807
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
639c371e9615a771e4ad85c32e3e5693c25fe76b 13-Feb-2017 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Introduce @SoftInputModeFlags annotation"
618b7a9aec2cda96edbe1d97044f017f605788c6 13-Feb-2017 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Track the last softInputMode in IMMS"
22dac1c8df4ec212e8195a69d2de15d313d724fb 13-Feb-2017 Yohei Yukawa <yukawa@google.com> Introduce @SoftInputModeFlags annotation

Doing this allows us to annotate integer values that should corresponds
to WindowManager.LayoutParams#softInputMode.

Test: There should be no behavior change. RetentionPolicy.SOURCE
annotation should change nothing in production code.
Test: checkbuild
Bug: 32784563
Bug: 35079353
Change-Id: I96300b090edce327d0515c740183abe91ded6bac
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
22a8923368a41cf50adfbc963c02b66302bb2d41 13-Feb-2017 Yohei Yukawa <yukawa@google.com> Track the last softInputMode in IMMS

A field in WindowManager.LayoutParams softInputMode is something that
definitely needs to be kept tracking in historical debugging
infrastructure across IME-related processes (Bug 35079353) [1]. As a
preparation, this CL enables InputMethodManagerService (IMMS) to
include the last softInputMode specified in IMMS#windowGainedFocus()
in the dumpsys in human readable format.

[1]: As explained in b.android.com/224318, softInputMode misspecified
by app developers is a typical root cause of unexpected behavior
in keyboard visibility. Bugs such as Bug 23168250, Bug 27275709,
and Bug 31770400 fall into this category.

Test: `adb shell dumpsys input_method | grep softInputMode=`
Bug: 35079353
Change-Id: I485ced030def179dad78b4b811c6eb52b5e5c951
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
f7526b58960608887b064670bb42f41aa28b8f41 12-Feb-2017 Yohei Yukawa <yukawa@google.com> Merge restartInput into startInput in internal IPC

This is the 2nd attempt to merge restartInput into startInput in
internal IPC after fixing the mistake in new parameter order in
the previous CL [1].

As a preparation to start tracking all the event flows that
cause InputMethodManagerService#setImeWindowStatus(), this CL
merges an internal IPC method IInputMethod#restartInput() into
IInputMethod#startInput() in favor of simplicity.

This is a refactoring CL that should have no behavior change.

[1]: Ifda6f74ac1b1370d9e9a9fe60354b692121fdcb9
1a5838e966eab7a9f0dca71cabbc9922babb995e

Test: Set true to InputMethodService#DEBUG and make sure startInput()
and restartInput() are called in the following scenario.
1. Complete the setup wizard.
2. adb shell am start -a android.app.action.SET_NEW_PASSWORD
3. Proceed to "Choose your password" page
4. Make sure startInput() gets called.
5. Type "aaaa" then hit "CONTINUE" button.
6. Make sure restartInput() gets called.
Bug: 35079353
Change-Id: I476d0cf8cbb0a0134941854f9337d9ad15e66a71
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
9a49f85ae4ae45343838b189cdfd884ffabbd5ff 12-Feb-2017 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Revert "Merge restartInput into startInput in internal IPC""
3eaf8674872824e4d44a1de7ad72529c299634f7 12-Feb-2017 Yohei Yukawa <yukawa@google.com> Revert "Merge restartInput into startInput in internal IPC"

This reverts commit 1a5838e966eab7a9f0dca71cabbc9922babb995e [1].

Reason of revert:
There was a mistake in the parameter order of MSG_START_INPUT.

[1]: Ifda6f74ac1b1370d9e9a9fe60354b692121fdcb9

Test: none. This is a revert.
Bug: 35079353
Change-Id: Ic1487768932febe0f1f1b6e71929464e91f357e0
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
aab4e11c0ac5a73cd5ab7f6e6fb6b9de8c9ffd84 12-Feb-2017 Yohei Yukawa <yukawa@google.com> Merge "Inline IMMS#resetAllInternalStateLocked()"
d5c1d92eb5bd3abf65b7349af195dfc49e0c76bc 12-Feb-2017 Yohei Yukawa <yukawa@google.com> Merge "Merge restartInput into startInput in internal IPC"
1a5838e966eab7a9f0dca71cabbc9922babb995e 10-Feb-2017 Yohei Yukawa <yukawa@google.com> Merge restartInput into startInput in internal IPC

As a preparation to start tracking all the event flows that
cause InputMethodManagerService#setImeWindowStatus(), this CL
merges an internal IPC method IInputMethod#restartInput() into
IInputMethod#startInput() in favor of simplicity.

Test: Done some quick manual testing to make sure that IME is
still working
Bug: 35079353
Change-Id: Ifda6f74ac1b1370d9e9a9fe60354b692121fdcb9
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
0d7aff8ab22b25e4215bee1a1f1da830a4d8fbfe 10-Feb-2017 Yohei Yukawa <yukawa@google.com> Inline IMMS#resetAllInternalStateLocked()

Currently IMMS#resetAllInternalStateLocked(boolean, boolean) has
only two call sites, and the first parameter is the constant for
each call site. We can get much simpler code by inlining the
method in question into those two call sites. It actually revealed
that UNBIND_REASON_RESET_IME should have been called
UNBIND_REASON_SWITCH_USER.

Test: no behavior change
Test: adb shell dumpsys input_method | grep "mMethodMapUpdateCount="
to make sure that switching users can cause the same count
increase.
Test: adb shell dumpsys input_method | grep "mMethodMapUpdateCount="
to make sure that switching the device locale can cause the
same count increase.
Bug: 35079353
Change-Id: I63388402369f58d11fdb21b508eb2051ff39fa5b
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
e073306d7788dd14aa8b6bd24304a18dece7c084 10-Feb-2017 Yohei Yukawa <yukawa@google.com> Track update count of IMMS#mMethodMap

InputMethodManagerService#buildInputMethodListLocked() is known be
one of the biggest contributors to CPU and I/O bandwidth consumed
by InputMethodManagerService (IMMS). To check when it gets called
and to see how a CL would affect its call count, it would be useful
if we can easily get the call count of that method.

With this CL, how many times IMMS#mMethodMap was rebuilt will be
included in the dumpsys.

Test: adb shell dumpsys input_method | grep "mMethodMapUpdateCount="
to make sure the count is increasing.
Bug: 32343335
Change-Id: I05850578cbf2e6adfea6c7e9b1fb9ec4e9d5e2c9
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
c4e4491735ad5614ec4592fae98f05c455f5944d 10-Feb-2017 Yohei Yukawa <yukawa@google.com> Improve ACTION_PACKAGE_CHANGED handling in IMMS

This CL fixes a false negative case when handling
ACTION_PACKAGE_CHANGED in IMMS#MyPackageMonitor with greatly reducing
unnecessary false positives cases as well.

PackageMonitor#onPackageChanged(), which is the default handler of
ACTION_PACKAGE_CHANGED, returns true when and only when the entire
package state is changed to let InputMethodManagerService (IMMS)
rebuild the list of available IMEs when it returns true. Here we have
a false negative case and false positive cases.

Case 1 - false negative (Bug 28181208)

If ACTION_PACKAGE_CHANGED was about some components not the
entire package itself, currently MyPackageMonitor#onPackageChanged()
returns false and IMMS fails to rebuild the list of available IMEs.

Case 2 - false positive (contributing to Bug 32343335)

Even if ACTION_PACKAGE_CHANGED was about a package that implements
no IME service at all, currently MyPackageMonitor#onPackageChanged()
returns true and IMMS ends up with rebuilding the list of avilable
IMEs unnecessarily. Note that package replacement is a different
story that should be dealt with ACTION_PACKAGE_{ADDED, REMOVED}.

For both cases, luckily we can easily ask PackageManager to give the
list of relevant package names that might contain IMEs regardless of
enabled/disabled state, which is exactly what we want to use the watch
list for ACTION_PACKAGE_CHANGED events.

For the case 3, we can just check the current user ID.

Test: Manually verified as follows.
1. adb root
2. adb install -r LatinIME.apk
3. adb shell dumpsys input_method
Make sure that com.android.inputmethod.latin/.LatinIME is
recognized by IMMS.
4. adb shell pm disable com.android.inputmethod.latin/.LatinIME
5. adb shell dumpsys input_method
Make sure that com.android.inputmethod.latin/.LatinIME is
no longer recognized by IMMS.
6. adb shell pm enable com.android.inputmethod.latin/.LatinIME
7. adb shell dumpsys input_method
Make sure that com.android.inputmethod.latin/.LatinIME is
recognized by IMMS again.
Test: Manually verified as follows.
1. Build a custom APK LatinIME_no_ime.apk that has no input
method service.
2. adb install -r LatinIME_no_ime.apk
3. adb shell dumpsys input_method
Make sure that com.android.inputmethod.latin/.LatinIME is
not recognized by IMMS.
4. adb install -r LatinIME.apk
5. adb shell dumpsys input_method
Make sure that com.android.inputmethod.latin/.LatinIME is
recognized by IMMS.
6. adb install -r LatinIME_no_ime.apk
7. adb shell dumpsys input_method
Make sure that com.android.inputmethod.latin/.LatinIME is
no longer recognized by IMMS.
Bug: 32343335
Fixes: 28181208
Change-Id: I7b69c349318ce06a48d03a4468cf2c45bfb73dc2
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
efdb4289597ad1594eb906aeafd2ebdf8854bdc7 09-Feb-2017 Yohei Yukawa <yukawa@google.com> Merge "Eliminate out-of-sync IMM#mFullscreenMode error"
2bc66171cce4d5ae7bee2c3920e82e45a9d245af 08-Feb-2017 Yohei Yukawa <yukawa@google.com> Eliminate out-of-sync IMM#mFullscreenMode error

As explained in the commit message of my previous CL [1], we have
had a design issue in how to notify the full-screen mode change
from the IME to InputMethodManager running in the target application.

Histrically we have done this by using hooking the following IPC
from the IME to the target application.

InputConnection#reportFullscreenMode()

However, since we also want InputConnection to be deactivated in some
situations such as the when the target application is no longer
focused. In other words, InputConnection is not a reliable way to
notify something.

As a result, we have suffered from many stale state issues.
Bug 21455064 and Bug 28157836 are such examples. In Android N, we
introduced yet another hack to work around those issues, but it is
really time to fix the protocol design instead.

The new strategy is to rely on internal IPCs provided by
InputMethodManager to deliver such critical notifications from one
process to the other. This is actually more natural because our goal
is to make sure that InputMethodManager#isFullscreenMode() always
returns the latest value as long as the caller is the focused
application.

For backword compatibility, applications that are monitoring
this callback should continue working, as InputMethodManager emulates
the previous behavior. However, as updated in JavaDoc, IMEs are no
longer allowed to invoke InputConnection#reportFullscreenMode(),
which should be OK because even on previous releases IMEs should rely on
InputMethodService#updateFullscreenMode() instead.

[1]: Iba184245a01a3b340f006bc4e415d304de3c2696
1544def0facda69c210b0ae64b17394ea2860d39

Fixes: 28406127
Test: Make sure Bug 21455064 is still fixed.
1. Input some words in extract mode.
2. Select a word.
3. Perform copy.
4. Select a word.
5. Rotate the device.
6. Try to select a word.
7. Make sure he word is selected and action mode starts.
Test: Make sure Bug 28157836 is still fixed.
1. Rotate device to landscape mode.
2. Tap on EditText and start full screen extracted mode.
3. Rotate device to portrait mode.
4. Long press to start action mode.
5. Make sure Action mode gets started.
Test: `adb shell dumpsys input_method` to make sure that fullscreen
state is synchronized across the app, IMMS, and the IME.
Change-Id: If23e7c7c265ab3dfb48c2fb6fdb361b17d22c594
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
87ca8406d4dc711e9c9dba7a5ffccedc9e212021 07-Feb-2017 Yohei Yukawa <yukawa@google.com> Propagate StartInputReason to attachNewInputLocked

As a preaparation to work on Bug 35079353, this CL makes it clear that
IMS#startInput()/IMS#restartInput() can be also be triggered by
IMMS#onSessionCreated().

By doing this, we can now assume that each
IMS#startInput()/IMS#restartInput() event has always one corresponding
StartInputReason. In a subsequent CL, we will pass this to the IME
process (and to the app process) for further traceability.

Test: no behavior change.
Bug: 35079353
Change-Id: I604e35b023d27b77126cd70fe068dc6b5edc2611
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
ddad4b93fac5258e29c0f1d2e871b055cae6e6b8 02-Feb-2017 Yohei Yukawa <yukawa@google.com> Simplify the constructor of InputMethodInfo

This is a preparation CL for fixing Bug 32343335, where we aim to
avoid unnecessary reconstruction of InputMethodInfo objects by caching
immutable part of those metadata by APK revisions.

The reason why we have had to pass additional subtypes not just as
List<InputMethodSubtype> but as Map<String, List<InputMethodSubtype>>
to create an instance of InputMethodInfo is that how to compute
so-called IME ID is not exposed from InputMethodInfo even as @hide
method.

In practice it has been calculated as
new ComponentName(packageName, serviceName).flattenToShortString()
and those IDs are already stored here and there including secure
settings. It is almost impossible to change the rule anymore hence
we should consider them to be a kind of public API.

This CL adds a @hide static method InputMethodInfo#computeId() to
make it clear. This also enables us to simplify the constructor
of InputMethodInfo finally, because we have used IME IDs as keys
in subtypes.xml, where additional subtypes are stored.

Test: Manually verified that addtional subtypes still work
Test: checkbuild
Bug: 32343335
Change-Id: I1deaa470e042eac749e7a847933d14448a0d9e03
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d03328350878e48a3b6769f7bb6d6de5951eb5ff 01-Feb-2017 Yohei Yukawa <yukawa@google.com> No warning/info log for expected/normal situations

This CL hides warning and info log messages from
InputMethodManagerService (IMMS) and InputMethodService (IMS) behind
DEBUG flag like other logs unless the state is certainly unusual.

Of course the definition of "unusual" is still an open question, but
basically that we should not see any suspicious message from IMMS/IMS
just by turning on a new phone, launching some applications, typing
something, and turning off the device. IMMS and IMS should expect all
events that can (easily) occur in that scenario, and no log is
necessary for such things.

Note that warnings suppressed with TODO comments will be tracked
under Bug 34851776 (and Bug 34886274).

Test: adb logcat -s InputMethodManagerService:* InputMethodService:*
to monitor log in the following scenario:
1. Boot the device.
2. Complete the setup wizard.
3. Launch Dialer and type something on it.
4. Launch Contacts app and type something on it.
5. Try some special modes:
- Turn on/off display
- Recents screen
- Split-window mode
- Guest user
- Multi user
- Direct-boot (setup a device password and reboot)
except for logs about actual IPC calls from a background user.
Bug: 34838583
Bug: 34851776
Bug: 34886274
Change-Id: I3fcdeb919bb2f2940da9ff45e17ac00baa1253f4
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
59377cab5c4afa9ccca5d5613eef4406e7ef0df6 01-Feb-2017 Yohei Yukawa <yukawa@google.com> Fix a wrong UID can be logged

This is a prepartion for fixing Bug 34838583

Currently Binder.clearCallingIdentity() is called too early, which
ends up always blaming the system UID when calledWithValidToken()
fails in InputMethodManagerService#updateStatusIcon().

Test: Compile
Bug: 34838583
Change-Id: Id69da24de8269c0c7e31ea9ef3c595c3d69fe40e
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
fa49c0008962ec8108036a0c496bb2d475fa3a74 01-Feb-2017 Yohei Yukawa <yukawa@google.com> Remove unnecessary Binder.clearCallingIdentity()

This is a follow up CL to my previous CL [1] for Bug 26663589.

This is also a preparation CL for Bug 34838583, where the warning
shown from the method in question is to be suppressed.

The fix still works, but the Binder.{clear, restore}CallingIdentity()
block introduced by that CL is not actually necessary, because
WindowManagerInternal#clearLastInputMethodWindowForTransition() only
updates some internal variables. No system privilege is involved.

[1]: Ib567daa009c1139858dccadcfc6a04465ebecf36
833bdcedceee60a873694a77587393abfc830eb5

Test: Manually verified that Bug 26663589 is still fixed.
1. Flash a new OS image.
2. Complete the setup wizard.
Make sure a voice IME (subtype mode="voice") is installed.
Make sure you can type with LatinIME.
3. Connect to an external hardware keyboard.
4. Launch an app whose window has "stateAlwaysVisible" bit.
5. Focus in an EditText on the app.
6. Hit the right ALT key on the hardware keyboard.
Make sure that LatinIME shows symbol keyboard.
7. Hit the "ABC" button at the left botton on keyboard.
8. Tap the mic icon on the keyboard.
Make sure that the voice IME is shown.
Bug: 26663589
Bug: 34838583
Change-Id: I88b3abb9fa88b54e4844dabd89126f5dcdda6405
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
af5cee8d2631255d9aa3cc1ebdaef998be307164 24-Jan-2017 Yohei Yukawa <yukawa@google.com> Remove a redundant param in getDefaultEnabledImes

With the previous CL [1], systemReady parameter in
InputMethodUtils.getDefaultEnabledImes() is guaranteed to be true.
Hence this CL removes that parameter. There should be no behavior change
in this CL.

[1]: I5b37c450db4b25b3e635b6d634293a34eec8b9d4
7924782c000733b2d7a180701b74988f0154adee

Test: adb shell am instrument -w -e class com.android.internal.inputmethod.InputMethodUtilsTest com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Bug: 32343335
Change-Id: Ia14d12a4e21d0e2e22bfe0bd8d496f48058c5525
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7924782c000733b2d7a180701b74988f0154adee 24-Jan-2017 Yohei Yukawa <yukawa@google.com> Delay tasks from IMMS constructor to later phase

This is a preparation CL for Bug 32343335.

This CL basically addresses the concern raised in a previous CL [1]
that added several synchnonized blocks in the constructor of
InputMethodManagerService (IMMS).

After hours of code reading and investigation, it is concluded to be
safe IMMS to behave as if there was no IME available until
SystemService.PHASE_ACTIVITY_MANAGER_READY phase. This allows IMMS to
register callbacks not in the constructor but in the later phase to
addresses the concern that object references to IMMS could be leaked
into different threads before IMMS object is properly constructed.

As far as performance is concerned, basically the amount of tasks
to be done in the main thread remains same, or could be reduced a bit
if some unnecessary callback events were skipped. To confirm this, we
can check the total number of the following performance metrics.
- StartInputMethodManagerLifecycle
- StartActivityManagerReadyPhase

[1]: I9d4d3d7232c984432185c10c13fb726a6158cac8
8f202f82fd86a3b40bc5e7d62779eddff21096b1

Bug: 32343335
Test: Manual: pre-installed IME on Direct-Boot disabled device
Test: Manual: pre-installed IME on Direct-Boot enabled device
Test: Manual: user-installed IME on Direct-Boot enabled device
Test: Manual: user-installed IME on Direct-Boot disabled device
Test: Manual: user switching scenario on Direct-Boot enabled device
Test: Manual: user switching scenario on Direct-Boot disabled device
Test: Manual: device unlocking scenario on Direct-Boot enabled device
Change-Id: I5b37c450db4b25b3e635b6d634293a34eec8b9d4
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
817d5f7d3ce051184959f9adfac317f31d39d6fe 05-Jan-2017 Yohei Yukawa <yukawa@google.com> Refresh IMMS#mBoundToMethod when IMS is disconnected

It turns out that InputMethodManagerService#mBoundToMethod is not
correctly reset to false when the current InputMethodService is
killed by the system before IMMS explicitly terminates the connection.

As a result, InputMethodService#onBindInput() is not called when the
same IMS is reconnected to the IMMS. This also means that
IMS#mInputBinding and IMS#mInputConnection remain to be null
unexpectedly. Crashes of IMEs and APK replacement of IMEs can trigger
such a situation.

With this CL, IMMS#onServiceDisconnected() eventually calls
IMMS#unbindCurrentClientLocked(). It not only resets
IMMS#mBoundToMethod but also updates NavBar icons and closes the IME
switcher dialog, but it is probably an acceptable and reasonable
behavior change because we have done so when switching the IME.

Bug: b.android.com/225029
Bug: 32102706
Test: `adb shell dumpsys input_method | grep "mBoundToMethod"` becomes "false" after the current IME crashes
Change-Id: Id87252a1a50029481d08b70afb12f38830bcd1d9
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
a8a82ee297f491fd04d30f1da4570a9e1c85398f 08-Dec-2016 Fyodor Kupolov <fkupolov@google.com> Do not call buildInputMethodListLocked twice

Skip the call in PHASE_ACTIVITY_MANAGER_READY, because the list of input
methods hasn't change since buildInputMethodListLocked was called in the
constructor.

Bug: 32343335
Test: manual
Change-Id: Iabd475a9f825e9b49ae9fd2108009d2c34ee9738
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
dc589ac82b5fe2063f4cfd94c8ae26d43d5420a0 11-Nov-2016 Sudheer Shanka <sudheersai@google.com> Update usage of ActivityManagerNative.

- Remove references to ActivityManagerProxy.
- Add isSystemReady to ActivityManager.

Bug: 30977067
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test android.server.cts
adb shell am instrument -e class com.android.server.am.ActivityManagerTest,com.android.server.am.TaskStackChangedListenerTest \
-w com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I07390b6124fb1515821f5c0b37baf6ae74adc8fa
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
3933a6e0c358238302e07bc8782d65f672b88e7b 10-Nov-2016 Yohei Yukawa <yukawa@google.com> Support content URIs w/ userId in IC#commitContent

With this CL, one can specify a content URI with an embedded user ID to
InputContentInfo, like such a URI is supported in
Context#grantUriPermission().

Note that such a scenario is actually possible when 1) an application
running as User X sets a content URI to the system clipboard then 2) the
IME runing as User Y who share the clipboard with User X obtains the
content URI from the system and tries to create a new instance of
InputContentInfo.

Bug: 32427307
Bug: 32778718
Test: 'adb shell dumpsys activity permissions' with a custom IME that
instantiates InputContentInfo from the content URI obtained from
the clipboard.
Change-Id: I7918c0a379b8f3e7e64b106447b42447876f9057
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
850c83e6da3b34a4eab804133420247fc9dbb8a1 09-Nov-2016 Jeff Sharkey <jsharkey@android.com> Move dump() to dumpAsync(), more oneway calls.

When calling out to dump services hosted by external apps, use
dumpAsync() to avoid hanging if the remote process is wedged.

Test: builds, boots, runs with minimal logs triggered
Bug: 32715088
Change-Id: I70aa2666ae21dae8f09ded2063bed359c0b210c5
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
fc46e9b643881b7b2ab76854f3a0ac077e9def8d 22-Oct-2016 Sudheer Shanka <sudheersai@google.com> Move IActivityManager to aidl.

Bug: 30977067
Test: Existing tests are passing, dump commands still working.
Change-Id: I9cf81c4d381ebce14a6c701e409cbb269f2ff1fb
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
3a9316945432d79eebd08b7122b2222a1983d8a9 03-Nov-2016 Wale Ogunwale <ogunwale@google.com> Order non-app window containers.

- Add non-app window tokens to the display child container based on
their base layer so the highest based layer is z-ordered on-top.
- Separated DisplayContent.mNonAppWindowContainers into
mAboveAppWindowContainer and mBelowAppWindowContainer where the former
contains non-app windows that should be z-ordered on-top of all app
windows and the later contains non-app windows that should be
z-ordered below app windows.
- Change wallpaper base layer to 1 so that it is always below all other
window types.
- Add Ime related windows/tokens to DisplayContent.mImeWindowContainers
so that we can track them together
- Use alternative binder token when adding window TYPE_INPUT_METHOD_DIALOG
so that it can properly be associated as an IME token in WM vs. with
system_server or sys-ui token.

Test: Existing tests pass.
Bug: 30060889
Change-Id: Ib53e09af12545868c3741d83aaccb7311c872b41
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
ac2561e8206ac42921bb6ddbb0a5972fb360e394 01-Nov-2016 Wale Ogunwale <ogunwale@google.com> Make window token add/remove APIs require displayId

Window tokens can now only be on one display, so we now require clients
that want to add/remove window tokens to specify the display they would
like the token to be created on. This simplifies the token handling code
in WM and will be useful moving forward for clients that want to add
windows to external displays.

Test: Existing tests pass
Change-Id: I6b2d8d58a913b3624f1a9a7bebbb99315613f103
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
3c23d5ba6cee5188ccb79d514782a9b6f8c567f2 16-Sep-2016 Tadashi G. Takaoka <takaoka@google.com> Catch all exceptions when parsing IME meta data

Bug: 30568284
Change-Id: I0b613f8ce0f014320c5ac1bf445699ea2702a0a2
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
0f57cce644ae8b5bb87de3e7fba9e9c00f9a0b1a 09-Sep-2016 Fyodor Kupolov <fkupolov@google.com> Fixed a bug with incorrect handling of onUnlockUser

userId should be passed as arg1 instead of obj.

Bug: 31321500
Change-Id: I11e8c146d83773c73ec6bb5f5cfac566759b7bcc
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7877b8add811aafd7f57f731c8e22c9fe6a319c8 29-Jun-2016 Fyodor Kupolov <fkupolov@google.com> Optimized onUnlockUser

Offload work to the handler thread to allow AM to proceed with unlocking
the user.

Also optimized generatePackageInfo by not computing GIDs when GET_GIDS
flag is not set.

Bug: 29619732
Change-Id: Ib9dea53ea0d74038baeed67f21077305da61e46e
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
25e0813e6eb6315b1016db805fa9b791b4ae5cc2 23-Jun-2016 Yohei Yukawa <yukawa@google.com> Add InputMethodService#exposeContent()

This is a follow up CL to my previous CLs [1][2] that introduced
InputConnection#commitContent(InputContentInfo, Bundle) API to enable
IMEs to send a content to the target application.

With this CL, IME developers are able to temporarily expose
InputContentInfo object to the target package without permanently
granting URI permission. Although calling IMS#exposeContent() is
allowed only for the IME that is currently selected, the client is able
to request a temporary read-only access even after the current IME is
switched to any other IME as long as the client keeps InputContentInfo
object.

Here is a sample code snippet about how to use this mechanism.

[IME]
InputContentInfo contentInfo = new InputContentInfo(
contentUri,
new ClipDescription(description, new String[]{mimeType}),
linkUrl);
exposeContent(contentInfo, getCurrentInputEditorInfo());
getCurrentInputConnection().commitContent(inputContentInfo, null);

[App]
try {
contentInfo.requestPermission();
// Load inputContentInfo.getContentUri() here.
} finally {
contentInfo.releasePermission();
}

[1]: Iaadf934a997ffcd6000a516cc3c1873db56e60ad
152944f4909c47917473293b258d266435c6ab35
[2]: Ica1ba3154795c1bf44e140dfe639b299f83cd8af
adebb52588b098a1af678d4e33a234ef1ce783b2

Bug: 29450031
Change-Id: I2772889ca01f2ecb2cdeed4e04a9319bdf7bc5a6
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
3c5d0f104109048ba55308f81ca0ce7fa1afb626 25-May-2016 Jorim Jaggi <jjaggi@google.com> Close IME when attaching dock stack

So we don't end up with animation weirdness.

Bug: 28905720
Change-Id: I04124995dd99fa26d2e9be467c5976d7b20810a7
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
23cbe85610f780134cc77dd4a54732a22ed6e86e 18-May-2016 Yohei Yukawa <yukawa@google.com> Move LocaleList to avoid layering violation.

Since LocaleList needs to depend on android.os.Parcelable, we cannot let
that class belong to "android.util" package, which causes layering
violation.

Bug: 28819696
Change-Id: Ia8de2ee9df3dd0a42b1fe84574439519b680fe18
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
833bdcedceee60a873694a77587393abfc830eb5 16-May-2016 Yohei Yukawa <yukawa@google.com> Make IMS#clearInsetOfPreviousIme() reliable.

This is a follow-up to my previous CL [1] for Bug 15922840 so that we
can clear the following variables in a more reliable way.
- PhoneWindowManager#mLastInputMethodWindow
- PhoneWindowManager#mLastInputMethodTargetWindow

The idea behind CL [2] is that when InputMethodManagerService (IMMS) is
switching from an IME to another IME, IMMS can send a signal to
WindowManagerService (WMS) to remember the current IME's inset so that
the system can continue using it to reduce jank until the new inset is
specified by the next IME. As summarized in Bug 28781358, however, if
the next IME does not show the window after the IME switch, WMS (or
PhoneWindowManager to be precise) keeps using the previous IME's inset
unexpectedly until the new IME shows its window. All we have seen in
Bug 15922840 and Bug 26663589 fall into this category.

The idea of this CL is just adding a hidden API to InputMethodManager so
that InputMethodService#clearInsetOfPreviousIme() can surely terminate
the IME transition state managed in PhoneWindowManager, rather than
relying on a hack of calling SoftInputWindow#show() and
SoftInputWindow#hide(), which actually does not work for Bug 26663589.

[1]: Ib04967f39b2529251e4835c42e9f99dba2cf43f2
2977eb7b6ce82309a1bb1ba4ab698f503cb0388a
[2]: I5723f627ce323b0d12bd7b93f5b35fc4d342b50c
792faa2c16d319e874a1d633f964a78266d5f3f2

Note that addressing all the corner cases in [2] still requires lots of
non-trivial change. Hence this CL focuses only on Bug 26663589 (and
the case we handled in Bug 15922840).

Bug: 26663589
Change-Id: Ib567daa009c1139858dccadcfc6a04465ebecf36
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
ce18c8167766f92856f94a8e88e19de4698960e6 28-Apr-2016 Jeff Sharkey <jsharkey@android.com> Introduce "unlocking" vs "unlocked" nuance.

There is a narrow window of time during user unlock where we're
reconciling user storage and dispatching the "unlock" status to
various internal system services. While in this "unlocking" state,
apps need to be told that the user still isn't actually "unlocked"
so they don't try making calls to AccountManager, etc.

The majority of internal services are interested in merging together
both the "unlocking" and "unlocked" state, so update them.

Clarify naming in AccountManagerService to make it clear that a local
list is being used, which mirrors the naming in MountService.

To match UX/PM requested behavior, move PRE_BOOT_COMPLETED dispatch
after the user is unlocked, but block BOOT_COMPLETED dispatch until
after all PRE_BOOT receivers are finished to avoid ANRs.

Bug: 28040947, 28164677
Change-Id: I57af2351633d9159f4483f19657ce0b62118d1ce
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
a09b4d2a611a7606e8fc8c73a24bd941b6fc173f 15-Apr-2016 Narayan Kamath <narayan@google.com> Remove unnecessary allocation+unboxing of objects.

Transforming String->int can be done with 0 allocations
using Integer.parseInt.

bug: 28078871
Change-Id: I8d9f322d7154728849dde61ef282046032858d60
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
b2f901ab222b8a7193f9a17cb06232f73cf20518 12-Apr-2016 Yohei Yukawa <yukawa@google.com> Make sure that Toast is always shown by Meta-Space.

It turns out that my previous CL [1] does not always show Toast when
Meta-Space is hit multiple times in a short period. With this CL, we
attempt to make sure that the Toast is shown every time when Meta-Space
rotates the current IME subtype.

This CL also removes a rule that we do not show Toast when the IME
window has InputMethodService.IME_VISIBLE bit as it turns out to be
confusing. In Android N, we just provide a consistent behavior
no matter the IME window is visible or not.

[1]: If3fe17adbffe4c1125783fc77fed3cfe78fc7933
ebda7d7ae14b09bf15cc5f601ea44f903c782a9a

Bug: 27547054
Bug: 28127795
Change-Id: I551c51cd672dba6e7693d23cb181007f51b0de9d
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
4c74334c4425e43dfb53bc2ef707eebb1bef7d5b 11-Apr-2016 Fyodor Kupolov <fkupolov@google.com> Merge "Added getProfileIds method returning array of userIds" into nyc-dev
063fe652be5ac01f1d4ffe621dc2a5f7e2170198 11-Apr-2016 Yohei Yukawa <yukawa@google.com> Merge "Make additional IME Subtype ID persistent." into nyc-dev
66baf69042720e15c97a125cd034010ac456fc44 11-Apr-2016 Yohei Yukawa <yukawa@google.com> Make additional IME Subtype ID persistent.

It turns out that IME subtypes specified to
InputMethodManager#setAdditionalInputMethodSubtypes() are stored in the
presistent storate without subtype IDs. As a result, when the system is
rebooted, the system would no longer consider those additional subtypes
as enabled due to subtype ID mismatch, until the IME re-adds those
additional subtypes again with the original subtype IDs.

Bug: 28104337
Change-Id: I1445213e0b83d76631a839b974ec1ab9b28ad7d2
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d39ae854820edebe3f1cb8580117c451ffa5c4ec 11-Apr-2016 Yohei Yukawa <yukawa@google.com> Shift+Meta+Space should reverse-rotate subtypes.

This is a follow up CL to my previous CL [1], which added a new key
binding Meta+Space to rotate enabled IME subtypes. With this CL,
Shift+Meta+Space starts reverse-rotating enabled IME subtypes as
originally planed.

[1]: I4005692215edfcf8bed3e86b1e07000148f986f5
ae61f7118a92e097e854c840d5726c0920f5db0e

Bug: 25753404
Bug: 28103839
Change-Id: I3694edd80be6dfe18b90360e24ae4d451b331928
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7f98aa4aa93497692f200c553d2d6fff402e3de2 07-Apr-2016 Fyodor Kupolov <fkupolov@google.com> Added getProfileIds method returning array of userIds

Previously many usages of UserManager.getProfiles and getEnabledProfiles
were only using ids of returned users. Given that the list of users needs
to be parceled and unparceled for Binder calls, returning array of ids
minimizes memory usage and serialization time.

A new method getProfileIds was introduced which returns an array of userIds.
Existing method calls were updated where appropriate.

Bug: 27705805
Change-Id: Ic5d5decd77567ba0f749e48837a2c6fa10e812c0
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
fa0e47e0d439b8ecc28efacca92bb16e115e1e6e 05-Apr-2016 Yohei Yukawa <yukawa@google.com> Add an overlayable config for IME switcher visibility.

Seems that there are two mutually exclusive requests about how IME
switcher visibility should be controlled.
A. Requests like Bug 19496012. We should show the IME switcher
as a quick access to "Show input method" setting when a physical
keyboard is attached via wireless connections that do not have
clear connection/disconnection affordance (e.g. Bluetooth
keyboards).
B. Requests like Bug 25432652. We should not have a rule like A
when a physical keyboard is attached with clear
connection/disconnection affordance (e.g. USB wired keyboards,
2-in-1 convertible tables w/ magnetic contacts).

Currently satisfying both requests at the same time is really difficult
because InputDevice does not have such an attribute. Even with such an
attribute, it's still an open question about how to deal with two or
more keyboards. As a short term solution, this CL add an overlayable
config so that each device can configure which strategy to apply as the
default behavior.

Bug: 26245853
Change-Id: Id2aef6597916422ea63435ae9c31a9a9b5ddf5b8
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
ebda7d7ae14b09bf15cc5f601ea44f903c782a9a 03-Apr-2016 Yohei Yukawa <yukawa@google.com> Show toast when subtype is rotated by Meta-Space.

This follows up to my previous CL [1], with which we changed global
hardware key combinations regarding how multilingual user can manage
multiple keyboard layouts / input methods. Now we offer Meta-Space to
rotate input method (subtype), while we offered Shift-Space to rotate
hardware keyboard layouts previously.

One thing that is lost during above transition is an indication when the
such a key combination takes effect. Actually there was a toast that
shows new keyboard layout name, which is now lost.

With this CL, we bring back a toast so that we can show the new input
method (subtype) name. Note that the toast will be shown if all of the
following conditions are met.
- The input method (subtype) is rotated by a hardware key combination.
- IME window does not have IME_VISIBLE bit. Otherwise, showing a toast
is likely to cause UI overlap with the current IME's window.

[1]: I4005692215edfcf8bed3e86b1e07000148f986f5
ae61f7118a92e097e854c840d5726c0920f5db0e

Bug: 27547054
Change-Id: If3fe17adbffe4c1125783fc77fed3cfe78fc7933
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
a102dbddaa17d824f5941d27804b9b19c754e4af 30-Mar-2016 Yohei Yukawa <yukawa@google.com> Remove "Other keyboards" from IME switcher dialog.

Per comment from UX team, we remove "Other keyboards" button from the
IME switcher dialog because it now points to a stale location, and is
not really needed.

Bug: 27924222
Change-Id: I23b20de3ee0efbb67b7ccac2f9e458b6689dd4ed
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
8939838d5d3ee8324d156ce60af4c7feacbb22a2 29-Mar-2016 Yohei Yukawa <yukawa@google.com> IME switcher should not always require IME_VISIBLE.

When one ore more physical keyboards are attached, we should not require
InputMethodService.IME_VISIBLE to show the IME switcher because some
IMEs such as LatinIME shows no software keyboard w/ physical keyboard.

Bug: 26245853
Change-Id: I8aac9f5989ebaf544ace06a3ba0993b3a834869d
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
6090c265e5703601e197b41c3caa49749b510411 25-Mar-2016 Griff Hazen <griff@google.com> Fix a status bar NPE in InputMethodManagerService

Change-Id: I27f43acd7fd46b7c4f12c6c860b98ebf55335e51
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
74750f209acccdd04e96dda890010245cbbd1c99 22-Mar-2016 Yohei Yukawa <yukawa@google.com> Explicitly handle null rather than relying on NPE.

IInputMethodManager is an actual IPC interface with which application
processes can communicate with InputMethodManagerService (IMMS).
Although this has never been a public API, it is actually exposed to the
application process hence we parameters passed to that interface methods
should be considered untrusted.

In Android L-MR1 and prior, calling IInputMethodManager#startInput()
from the application process via reflection with null EditorInfo can
result in NPE in the IME process, which is not great.

In Android M, doing that causes NPE in the IMMS process but the
exception is just sent back to the application process via Binder call,
which is no longer so harmful.

In Android N, we want to make sure that such an invalid internal API
call is clearly under our control, rather than relying on NPE, by having
an explicit null check.

Bug: 26866030
Change-Id: Ica812177d9ca454dd16e3dd6854f3053c329b344
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
1064d35307cff0601a22c8401cb72f628883489d 19-Mar-2016 Yohei Yukawa <yukawa@google.com> Merge "Tell IMS about missing InputConnection methods." into nyc-dev
7b574cb8a1a3d0943392f2bf7180687eff8448ae 17-Mar-2016 Yohei Yukawa <yukawa@google.com> Add more @NonNull/@Nullable to InputMethodSettings.

This follows up to a previous CL [1] for Bug 26279466.

It turns out that we have not clearly defined how nonexistent key should
be handled in InputMethodSettings#getEnabledInputMethodsStr(), e.g. it
returns "" for when mCopyOnWrite is true but returns null when
mCopyOnWrite is false.

Also, since InputMethodSettings now can revert changes made during
mCopyOnWrite is true, the caller may also start receiving null in the
following scenario.
1. call mSettings.switchCurrentUser(userId, true).
2. call mSettings.putEnabledInputMethodsStr(str) where str is non-null.
3. call mSettings.switchCurrentUser(userId, false).
4. call mSettings.getEnabledInputMethodsStr().
If the caller of getEnabledInputMethodsStr() has assumed that it would
never return null, then it would start crashing due to NPE.

With this CL, getEnabledInputMethodsStr() is marked to be @NonNull we
should no longer see such kind of NPE.

[1]: I9c6f9bb3d51174198e5f73588637f87ea0d90e11
68645a638ad1bfb734b2b0f56b17fe206bb891c5

Bug: 27687531
Change-Id: I169ad4957e68b65c64251b0849056195b8ca4911
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
19a80a1e807acd00bec999eaac7812da6ffce954 15-Mar-2016 Yohei Yukawa <yukawa@google.com> Tell IMS about missing InputConnection methods.

Summary:
This CL introduces a unified mechanism to deal with the situation
where the application directly implements InputConnection but some of
methods are not implemented. Note that there should be zero overhead
when the application extends BaseInputConnection or
InputConnectionWrapper.

Background:
When ever we add a new method to InputConnection, there has been a
risk that existing applications that directly implement
InputConnection can get java.lang.AbstractMethodError exception at
runtime, because older SDKs do not require the application developer
to implement the methods that are newly added in later SDKs. Because
of this we strongly discouraged developers to directly implement
InputConnection interface, and encouraged them to subclass
BaseInputConnection or InputConnectionWrapper instead. That said, as
requested in Bug 26945674, there is a certain demand to be able to
implement InputConnection without depending on BaseInputConnection.
The goal of this CL is to provide a reliable and sustainable solution
to above missing method scenario in InputConnection.

One of the reasons why dealing with missing InputConnection methods is
so difficult is that what InputMethodService receives to communicate
with the target application is actually a proxy class
com.android.internal.view.InputConnectionWrapper
that runs in the IME process and immediately returns true for most of
methods in InputConnection such as #commitText() and
#finishComposingText(). Because of this asynchronous nature, it is
too late to change the actual return value that the IME receives when
the application receives those one-way asynchronous IPC calls.

Solution:
To handle those cases, this CL checks the availability of
InputConnection methods that did not exist in the initial release
before the target application calls startInput(), and let the
application to send its availability bits to IMMS so that
InputConnectionWrapper running in the IME process can be initialized
with such availability bits. Note that we do know that
BaseInputConnection and its subclasses support all the InputConnection
methods, hence for most of applications we can just assume that all
the methods are available without reflection.

With such availability bits, InputConnectionWrapper is now able to
gracefully return failure code to the IME because the availability of
those methods is immutable, except for a tricky case where the
application relies on a proxy object that dynamically changes the
dispatch target.

Here is the list of APIs that we start checking the availability in
this CL.
[API Level 9+]
- InputConnection#getSelectedText(int)
- InputConnection#setComposingRegion(int, int)
[API Level 11+]
- InputConnection#commitCorrection(CorrectionInfo)
[API Level 21+]
- InputConnection#requestCursorUpdates(int)}
[API Level 24+]
- InputConnection#deleteSurroundingTextInCodePoints(int, int)
- InputConnection#getHandler()

Ideas alternatively considered: Default methods in InputConnection
We once considered having default methods in InputConnection but
abandoned this idea because it does not directly solve the problem
about how to tell the that the API does not take effect.
Also having default methods would make it difficult for application
developers to be aware of newly added methods in InputConnection.

Bug: 27407234
Bug: 27642734
Bug: 27650039
Change-Id: I3c58fadd924fad72cb984f0c23d3099fd0295c64
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
1e1a447000263151822b67a4981cd854fa8cb3c5 11-Mar-2016 Yohei Yukawa <yukawa@google.com> Persist isAsciiCapable attribute of additional subtypes.

This was somehow missed in the previous commit [1] that added
isAsciiCapable attribute to InputMethodSubtype.

For devices from API level 14 to 23, IME developers might be able to
work around this issue by specifying "AsciiCapable" [2] in
imeSubtypeExtraValue, which is not coverted by CTS though.

[1]: Ic3ace4b6e0432d56696bcbc0be336aec1dc744a5
dc8abf6cee0bcf44e2cad8155f0c151105d46471
[2]: I0bc9954f163a3ec38d08b9ba842a8a31176eb6a6
8e303cc5dd4860b6050d5725ce60ca7e6fb00c7b

Bug: 27603986
Change-Id: Ifb6bc83e782ac05df180dfe0d689897d07441a0c
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7b18aec947a0b004d019dd95894063070d3b8433 07-Mar-2016 Yohei Yukawa <yukawa@google.com> Rely on SystemService#onSwitchUser() in IMMS.

SystemService class has already provided SystemService#onSwitchUser()
callback event. We do not need to set up SynchronousUserSwitchObserver
separately in InputMethodManagerService.

Bug: 25816558
Bug: 26279466
Change-Id: I8ce2ba1335ae4caa35f9a21d87b751bfb4614033
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
15e931273ee8d163f1250d40234cab7f1474e7a6 04-Mar-2016 Dianne Hackborn <hackbod@google.com> Don't need this "feature" any more.

Change-Id: I3ec4550e508656ae6da3112fd78f111214972a60
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
e985c240e3feb62ea38d5b4e386be083ca0f215b 25-Feb-2016 Yohei Yukawa <yukawa@google.com> Use LocaleList for implicitly enabled subtypes.

There are two major changes in this CL:

1. Now IMMS resets its internal state whenever the system locale list
is changed, rather than just checking the primary system locale.
2. For software keyboard subtypes,
InputMethodUtils#getImplicitlyApplicableSubtypesLocked() now takes
the entire system locale list into account when determining what
subtypes should be enabled by default when the user does not
explicitly enable one or more subtypes.

Bug: 27129703
Change-Id: Iaf179d60c12b9a98b4f097e2449471c4184e049b
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
05c25f8a3a033816ac25aa5cd7db5b1ab495bc3f 22-Feb-2016 Yohei Yukawa <yukawa@google.com> Unify windowGainedFocus() and startInput().

This is a safe refactoring that changes nothing.

In order to improve the keyboard dismissal lags [1][2], we have used
IMMS#windowGainedFocus() as a combined event to do startInput() in
certain situations.

To make the intent of those CLs clear, this CL renames
IMMS#windowGainedFocus() to IMMS#startInputOrWindowGainedFocus(). Note
that these are @hide internal IPC protocols. Hence this change is never
observable to application developers.

[1] I8494cbd6e19e2ab6db03f2463d9906680dda058b
a82ba54b0bbc3ff41f29db3998806cb45b261d58
[2] Icb58bef75ef4bf9979f3e2ba88cea20db2e2c3fb
7663d80f6b6fd6ca7a736c3802013a09c0abdeb9

Bug: 25373872
Change-Id: I56934f18e30d90fcdf77bcbb0c35a92a5feb1b82
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
ed4952ad0f76a70549777472cd9cefcbc8705917 17-Feb-2016 Yohei Yukawa <yukawa@google.com> Reset IMMS when the device is unlocked.

With File-Based Encryption (FBE), now we have yet another runteime event
to reset IMMS state in order to keep the list of available IMEs updated
and make sure one IME is enabled. Here is the full list of such runtime
events.

1. Boot phase reaches SystemService.PHASE_ACTIVITY_MANAGER_READY.
2. One or more packages that contain InputMethodService are updated.
3. The current user is switched.
4. The device locale is changed.
5. The device is unlocked by the current user.

Now we are adding the rule 5 in this CL.

We also apply Copy-On-Write (COW) settings mode, which was added in a
recent commit [1], until the deivice is unlocked. This allows us to
temporarily update the settings when the device is locked, without
messing up actual SecureSettings.

[1] I9c6f9bb3d51174198e5f73588637f87ea0d90e11

Here are some examples of what users would see in FBE-enabled devices.
Suppose we have following 5 IMEs installed.

- IME A: Encryption Aware, pre-installed, ASCII-capable
- IME B: Encryption Unaware, pre-installed, ASCII-capable
- IME C: Encryption Unaware, not pre-installed, ASCII-capable
- IME D: Encryption Aware, not pre-installed, ASCII-capable

Case 1)
Before boot:
Enabled: IME A
Selected: IME A
Device Locked:
Available: IME A, IME D
Enabled: IME A
Selected: IME A
Device Unolcked:
Available: IME A, IME B, IME C, IME D
Enabled: IME A
Selected: IME A

Case 2)
Before boot:
Enabled: IME A, IME B
Selected: IME B
Device Locked:
Available: IME A, IME D
Enabled: IME A
Selected: IME A
Device Unolcked:
Available: IME A, IME B, IME C, IME D
Enabled: IME A, IME B
Selected: IME B

Case 3)
Before boot:
Enabled: IME B, IME C
Selected: IME B
Device Locked:
Available: IME A, IME D
Enabled: IME A
Selected: IME A
Device Unolcked:
Available: IME A, IME B, IME C, IME D
Enabled: IME B, IME C
Selected: IME B

Note: in this case, IMMS can rely on an existing rule to support
the situation where enabled/selected IMEs were already uninstalled.

Case 4)
Before boot:
Enabled: IME B, IME C, IME D
Selected: IME B
Device Locked:
Available: IME A, IME D
Enabled: IME D
Selected: IME D
Device Unolcked:
Available: IME A, IME B, IME C, IME D
Enabled: IME B, IME C, IME D
Selected: IME B

Following things should be taken care of subsequent CLs.

- Add CTS to ensure that at least one encryption-aware IME is
pre-installed if the device supports FBE.
- Consider an accidental case where there is no encryption-aware IME.
This includes the case where all the encryption-aware system IMEs are
overwritten by encryption-unaware IMEs that have higher versions.

Bug: 26279466
Change-Id: Ifa2225070bf8223f8964cf063c86889e312c5e9a
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
5eb148bab6ea49c4c646649692ae6769b9c4e54c 19-Feb-2016 Yohei Yukawa <yukawa@google.com> Merge "Stop granting default Contacts permission to IMEs." into nyc-dev
726c45970e35e3fff3eeb4d86c3b772db73adcc7 18-Feb-2016 Yohei Yukawa <yukawa@google.com> Stop granting default Contacts permission to IMEs.

This partially reverts the previous commit [1], which allowed special
components to be granted some pre-configured default permissions.

With this CL, we no longer grant Contacts permissions to pre-installed
IMEs. Rationals are:

1. Even without this CL, not the all pre-installed IMEs are granted
Contacts permission by default, because it was done during the boot
time where InputMethodManagerService is not yet completely
initialized. The current behavior is confusing not only for users
but also for developers.
2. In almost all the cases, IMEs are supposed to be able to work
without Contacts permission. Hence it is not too late to ask users
to grant the permission to the IME after the initial setup is
completed.
3. It is difficult to add new features such as File-Based Encryption
(FBE) with keeping the current implementation, because currently we
dynamically call mSettings.setCurrentUserId(userId) just to
enumerate what IMEs will be enabled for a given user. Adding
another condition (whether the user has already unlocked the device
or not) would make things more complicated.

Note that LatinIME has already support the case where Contacts
permission is not granted by default. It does not ask users for
anything until Setup-Wizard is completed, and requests Contacts
permission only when the user taps a message in the suggestion strip
that suggests users to use contacts name for typing suggestions.

[1] If8b8cadbd1980ffe7a6fc15bbb5f54a425f6e8f9
adc1cf46045ae756d3a9ccbccf6b0f894e4c1edd

Bug: 24756974
Bug: 26743676
Change-Id: Ief2a40b5971b3eb97d765f934d20ce7f2ef25665
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
c2393ac3bf2ec44aa46186408aa4636e8c7c4a4b 18-Feb-2016 Yohei Yukawa <yukawa@google.com> Fix bugs in logic to find a default selectd IME.

With this CL, InputMethodManagerService#resetDefaultImeLocked()
picks up the default selected IME with the same logic to find the
default enabled IMEs [1]. It should make sense because the default
selected IME should be one of the default enabled IMEs. The previous
code is problematic because it does not check whether the IME is enabled
or not. There was a chance that unusable IME could be picked up.

This CL also fixes the same problem to Bug 17347871 that only language
part of the locale is taken into account.

[1] See the following series of CLs.
- part 1: I831502db502f4073c9c2f50ce7705a4e45e2e1e3
ed20f8d750ef0b6347448265a14ef2a2c7e1af5c
- part 2: Ife93d909fb8a24471c425c903e2b7048826e17a3
745e7bca8a622ffdf0d0a8e8e2485eab98182ede
- part 3: I6571d464a46453934f0a8f5e79018a67a9a3c845
d0dbd81fe2cd34c9a83e2f5217374d3e1a79f950
- part 4: I871ccda787eb0f1099ba3574356c1da4b33681f3
b21220efae92a56ff7b4b781fa614a6e3a8a3007

Bug: 27197621
Change-Id: Ia0f52c1fb9f5a68230284a1ec4829a2337b60bdd
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
859df05cc081f9390c3c0f4e816b39a8aadd8fd7 17-Feb-2016 Yohei Yukawa <yukawa@google.com> Make sure at least one IME is enabled.

It turns out that there still exists an edge case where the device can
be fallen into a state where IMMS would pick up no IME at the boot
phase. Suppose the following case:

Selecte IMEs : IME X
Enabled IMEs : IME X, IME Y, IME Z
Available IMEs: IME A, IME B

IMMS has already taken care of the case where the selected IME X is no
longer available at the boot phase for some reasons, which is good, but
what it does in InputMethodManagerService#chooseNewDefaultIMELocked() is
just picking up the best-looking IME only from the "Enabled IMEs"
without considering the case where all the enabled IMEs are unavailable
and we have to enable some IMEs as if it was the first boot.

This issue was found when making IMMS File-Based Encryption (FBE), where
it is relatively easy to see such a situation, e.g. only IME A and IME B
are encryption-aware, but subtle but critical details in storage layer
could cause the same situation. Bug 6685037 is an example.

As a tentative workaround, this CL introduces a recovery logic in
IMMS#buildInputMethodListLocked() as a workaround. In future we really
should sort out those initialization code though.

Full FBE support will be added in the next CL [1].

[1] Ifa2225070bf8223f8964cf063c86889e312c5e9a

Bug: 26279466
Change-Id: Ibd53ef8db7afcfac681b401912876d2a52c743d5
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
68645a638ad1bfb734b2b0f56b17fe206bb891c5 17-Feb-2016 Yohei Yukawa <yukawa@google.com> Add Copy-On-Write mode to InputMethodSettings.

This is a preparation for File-Based Encryption (FBE) support in IMMS.

In order to support File-Based Encryption (FBE), IMMS needs to reset
its internal state exactly when the device is unlocked by user first
time. This is important because IMMS would recognize only
encryption-aware input method services until the the device is unlocked
by the current user.

Even if we reset the internal state when the device is unlocked by the
current user, there are still two tricky points.

1. Except for the initial boot, IMMS uses Secure Settings to determine
what IMEs are enabled and what IME is currently selected. These
persistent state may not be suitable for the situation where the
device is not unlocked yet, because some of IMEs referenced there
may or may not be encryption-aware. Depending on the situations,
we may need to enable at least one encryption-aware IME to ensure
that the user is able to type password to unlock the device, even if
such an IME is not Settings.Secure.ENABLED_INPUT_METHODS. We have
to be careful when doing this because we don't want non
pre-installed IMEs to be enabled until the user approves it.
2. IMMS tends to save its internal state into Secure Settings.
However, because of the point 1, we may need to automatically enable
a certain IME to make sure the user is able to type even when the
device is not unlocked yet. We don't want such a temporary state
to be persistent in Secure Settings.

The basic idea of this CL is to implement Copy-On-Write (COW) mode in
InputMethodSettings so that we can later discard any changes made before
the device is unlocked. As the initial step, we start using this COW
mode until the the ActivityManager becomes ready. With this change we
can revert a previous commit [1] for Bug 6685037, where forward-locked
encrypted apks need to be taken care of an early boot phase.

[1] Ifb311f85154beadd4787ec73669bedfdf1f5172d
4c0e7152e74d091eb78af8baacd38287ba95a1a1

Bug: 26279466
Change-Id: I9c6f9bb3d51174198e5f73588637f87ea0d90e11
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
94e3330e639e1b96f5bd000f4c0f743b3cc174fc 13-Feb-2016 Yohei Yukawa <yukawa@google.com> Remove redundant arguments.

The "list" and "map" arguments of IMMS#buildInputMethodListLocked() are
nothing more than synonyms of IMMS#mMethodList and IMMS#mMethodMap,
respectively. There is no reason to pass them as parameters. We can
access them directly as we have done there for other member fields.

This is kind of a mechanical refactoring. No behavior change is
intended.

Bug: 26279466
Change-Id: Ia27e19f9358ba33abbb1e5a27cebe7c9953c998f
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d34e1486ee70ed433b86fa4815eded105f95887a 11-Feb-2016 Yohei Yukawa <yukawa@google.com> Use Context#getSystemService(Class<T>) in IMMS.

This is a mechanical replacement of
Object Context#getSystemService(String)
with
T Context#getSystemService(Class<T>)
in InputMethodManagerService.java.

No behavior change is intended.

Bug: 26279466
Change-Id: Iec6b89f0367140f98d3ca4caa1dae7375e27f3ad
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
f3e5d1d483231d615f5e77032f787fcd8047488b 29-Jan-2016 Anna Galusza <agalusza@google.com> Merge "Add API for IME control by Accessibility Services."
9b278112467581e2b8d99f29cf48b9fbef9cc53f 04-Jan-2016 Anna Galusza <agalusza@google.com> Add API for IME control by Accessibility Services.

Change-Id: I3bb806cf420e0551a2c9ef97d95613f73e362df9
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
1e33dc8fdf3f722ecd32cc586b2a9515de24a242 21-Jan-2016 Fyodor Kupolov <fkupolov@google.com> Use SystemService lifecycle API in input method service

Change-Id: Ic17667df60b30e5355b61a3601ad27a000cab3a3
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
24bf3279f7f0f4bef8c8dcbbc7185a015a10ce5d 20-Jan-2016 Jason Monk <jmonk@google.com> Merge "SysUI Tuner: Status bar work"
18f3d9a39e17f4d434542f0a22bc11ef827187b1 20-Jan-2016 Yohei Yukawa <yukawa@google.com> Merge "There should be a way to clear additional subtypes."
3e189877aba0285d79ce55349afae60457d95d6f 12-Jan-2016 Jason Monk <jmonk@google.com> SysUI Tuner: Status bar work

Improve general status bar goodness, more exactness, less breakage.

Extra extra icons, disabled by default.

Control all the status bar things!

Probably other stuff (10000).

Change-Id: I5d6282a4dcbcefea9f0880042cdf6293cb693712
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
70f5c48e8e0403abe7e0f489b30890e46aac0d8b 05-Jan-2016 Yohei Yukawa <yukawa@google.com> There should be a way to clear additional subtypes.

InputMethodManager#setAdditionalInputMethodSubtypes() is the only API
that allows IMEs to add and remove additional subtypes. However, due to
a bug, there is no way to clear the last entry of additional subtypes
because the API in question does nothing if the given array is emptry.

With this CL, an empty array is treated as a valid input.

This CL also adds a JavaDoc comment about a possible way to work around
this limitation in Android M and prior devices.

Bug: 26298984
Change-Id: I3731f84531247d071d9d88861e9079afc244a4e8
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
41f3427381d77fa9fcd12ed820716ebff7011c16 15-Dec-2015 Yohei Yukawa <yukawa@google.com> Fix IMM#showInputMethodAndSubtypeEnabler().

At least on AOSP InputMethodManager#showInputMethodAndSubtypeEnabler()
has been broken since its beginning. As of Android M, there are three
separate issues:

1. Type mismatch in message dispatching layer.
2. It does not correctly reject API calls from clients that do not
have IME focus.
3. Context#startActivityAsUser(intent, null, UserHandle.CURRENT) ends
up with java.lang.SecurityException:
Permission Denial: startActivity asks to run as user -2 but is
calling from user 0; this requires
android.permission.INTERACT_ACROSS_USERS_FULL.

Given that we have a good alternative to achieve the same result, it
would make sense to deprecate that method and encourage developers to
use Intent-based solution instead.

Before doing that, this CL fixes the issues just for the record.

Bug: 26189558
Change-Id: Ic7a0df3203fee19542a3143abba9bc31baf9698a
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
c18a05faf15111b6018e2599265853f0b21c66cb 14-Dec-2015 Yohei Yukawa <yukawa@google.com> Merge "Rotate IMEs (subtypes) by Meta+Space."
026688070c8002911dc0a8f1fb487bf5bfed52d4 11-Dec-2015 Yohei Yukawa <yukawa@google.com> Merge changes If80df0bc,I4e91b2d7,If3aef820

* changes:
Apply Java 7 diamond operator.
Remove a redundant method overload.
Remove unnecessary parameter that is always true.
5f8e731f18c5cbfd345236c691db0b09aceb7c5d 10-Dec-2015 Yohei Yukawa <yukawa@google.com> Remove unnecessary parameter that is always true.

This is a mechanical refactoring that removes an unnecessary parameter
that is always specified to 'true'.

No behavior change is intended.

Bug: 22859862
Change-Id: If3aef8209a355af1432ca2600bcc3a0027a6c24c
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
ae61f7118a92e097e854c840d5726c0920f5db0e 09-Dec-2015 Yohei Yukawa <yukawa@google.com> Rotate IMEs (subtypes) by Meta+Space.

With this CL, PhoneWindowManager starts monitoring Meta+Space to trigger
input method rotation.

Note that InputMethodManagerService currently supports only one way
rotation. Currently there is no difference in the behavior between
Meta+Space and Shift+Meta+Space. Reverse rotation will be supported in
a subsequent CL.

Bug: 25753404
Change-Id: I4005692215edfcf8bed3e86b1e07000148f986f5
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
868d19b93b1e20c802a001c7304f8bcac5fe5114 08-Dec-2015 Yohei Yukawa <yukawa@google.com> Use BCP-47 LanguageTag in IME/Spell-Checker.

The primary goal of this CL is to make it clear that BCP-47 is the
expected format to annotate locale information for each
{InputMethod, SpellCkecker}Subtype. In order to avoid possible
compatibility issues, this CL introduce a new "languageTag" attribute
instead of reusing existing "imeSubtypeMode" and "subtypeLocale"
attributes.

For IME developers, this CL changes nothing unless "languageTag"
attribute is specified. To summarize:

A: If only legacy locale-string is specified
(existing IMEs/Spell-Checkers fall into this category):
-> The system uses locale-string.

B: If only LanguageTag is specified:
-> The system uses LanguageTag.

C: If both locale-string and languageTag are specified:
-> The system uses LanguageTag. Legacy locale-string is ignored.

For application developers, there should be some follow-ups CLs because
even with this CL most likely they would still have to take care of
previous versions of Android where:
- Locale#forLanguageTag() (N/A in API Level 20 and prior)
- Locale#toLanguageTag() (N/A in API Level 20 and prior)
- InputMethodSubtype#getLocale() (Deprecated in N)
- SpellCheckerSubtype#getLocale() (Deprecated in N)
- InputMethodSubtype#getLanguageTag() (N/A in M and prior)
- SpellCheckerSubtype#getLanguageTag() (N/A in M and prior)
One idea would be is in the official support library to provide a utility
method that takes care of above tasks and just returns a Locale object.
If we had a utility method in the support library, probably not
returning a Locale object from #getLanguageTag() would make sense.

From performance point of view both existing legacy locale-string
attribute and new LanguageTag attribute are just String objects that
travel from XML manifest to system services to applications via IPCs.
Hence there are no performance implications except for having one more
String objects.

Bug: 22858221
Change-Id: I6db107ad2afc7709167f7c4e5d24bd589ac8bd70
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
6005b3f87b063ee7ab7e8877a6a8c90b480f3341 24-Nov-2015 Fyodor Kupolov <fkupolov@google.com> Added SynchronousUserSwitchObserver

This class provides a synchronous version of onUserSwitching, which does not
require notifying a callback.

Bug: 25816558
Change-Id: Id31bb79bf10b5afd72dfca28cf4bea817e726f6f
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
b097b8262ba22040d46d6e212a31b758b7023307 01-Dec-2015 Yohei Yukawa <yukawa@google.com> Plumb IME subtype change from IMMS to IMS.

This is a plumbing CL from IMMS to IMS to notify when the current input
method subtype is changed. Those events are supposed to be used to
change physical keyboard layout depending on input method subtype, which
is to be implemented in subsequent CLs.

Bug: 25753054
Change-Id: I58e71ffce9ac9131551a00dd35e24235dadfef87
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
35d3f37bd51268cc99d81a3f537ac364d178e851 25-Nov-2015 Yohei Yukawa <yukawa@google.com> Tell the reason why IMM called startInput().

As a preparation to fix Bug 25373872, this CL introduces an additional
int parameter into the following two methods
- IInputMethodManager.startInput()
- IInputMethodManager.windowGainedFocus()
so that IMMS can know why IMM needs to start input. Currently the
"startInputReason" parameter is used only for debug message only when
the OS is rebuilt with flipping IMMS#DEBUG to true. Basically this
should have no impact in production builds except for a tiny overhead
of having one int parameter in some internal IPC calls.

Note that since 7663d80f6b6fd6ca7a736c3802013a09c0abdeb9 [1] basically
IMMS#windowGainedFocus() has been a superset of IMMS#startInput().
Hence we should pass to "startInputReason" parameter to
IMMS#windowGainedFocus() as well as IMMS#startInput().

[1]: Icb58bef75ef4bf9979f3e2ba88cea20db2e2c3fb

Bug: 25373872
Change-Id: Ia1fe120af7d71495c5f3a4fc0ec6390efb8240ca
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
e39d4edca74b810038810221a458fb5abb364d86 19-Nov-2015 Yohei Yukawa <yukawa@google.com> Track by which client the last focused window was reported.

To diagnose race conditions like issue #25373872, we want to track
which input method client corresponds to IMMS#mCurFocusedWindow.

Note that IMMS#mCurClient does not always correspond to
IMMS#mCurFocusedWindow, because input method clients can report the
window focus gain only, without requesting to be bound to IME.

Bug: 25373872
Change-Id: Iad121669c0f3db4461245dc80ff3fdee469abb79
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
072b1b5183bf3e193b20902b967fb3ecbbb175a3 19-Nov-2015 Yohei Yukawa <yukawa@google.com> Clear IMMS#mCurClient when it is dead.

Suppose the following case:
1. Launch an activity.
2. Focus in an EditText on the activity. IME is shown up.
3. Kill the activity process in a not graceful way, e.g.,
'adb shell kill'

After step 3, IMMS#removeClient(client) is immediately called back from
com.android.server.wm.Session, which is good, but we forgot to clear
IMMS#mCurClient to null.

Basically not clearing IMMS#mCurClient there is not so critical, because
1) we already have bunch of RemoteException check for the case where
IPC target is already dead, and in theory we cannot avoid this kind of
runtime error anyway, and 2) in most of cases new input method client
gains focus.

That said, in conjunction with other focus-related issues such
as bug #25373872, not cleaning that can result in the following error
message in 'input_method:' section of bugreport, which might be a bit
confusing.

Input method client dead: android.os.DeadObjectException

The primary goal of this CL is to make bugreport less confusing. Any
user/developer-visible changes beyond that is unintentional.

Bug: 25373872
Change-Id: Iee001ad9cce0c8c6324e3c0984be1e6f0e641d05
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
33e81798fa85947f934e262174184b11f97ca7a3 18-Nov-2015 Yohei Yukawa <yukawa@google.com> Tell the reason why IMMS unbinds IME client.

As a preparation to fix Bug 25373872, this introduce an additional
parameter to IInputMethodClient.unbind() so that the IME client
that is running in the application side can know why IMMS needs
to unbind the connection.

In future the "unbindReason" parameter is supposed to be used to
optimize the behavior of IMM runtime running in the application process,
but for now it is not used unless we build the sytem with debug message
enabled. Hence there should be no user-visible change with this CL.

Bug: 25373872
Change-Id: I74e83c8ca9d1d53e31e9c7b5bda1dec6274e59c8
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
bc7b5260431f0b34998a86a0da3227734b84388f 18-Nov-2015 Yohei Yukawa <yukawa@google.com> Factor out IMMS#resetCurrentMethodAndClient().

As a preparation to fix Bug 25373872, this CL does a mechanical
code clean-ups in InputMethodManagerService.

As a follow up of I6c3186050592526fc95c5b27f18e2155acff5ebc, this CL
introduces IMMS#resetCurrentMethodAndClient() to make it clear when we
are resetting both IMMS->IME and IMMS->Apps connections.

This is literally mechanical. No behavior change is intended.

Bug: 25373872
Change-Id: Ia4161854d9da71783fd028fcb79407e4b9463aee
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
e13a20faccf6f33aa43c9c1fa4c4ec2a79b86cfb 01-Oct-2015 Yohei Yukawa <yukawa@google.com> Unbind IME client when unsetting the current IME.

This follows up Ia70b870723acf647e0c27f24aff91b40d6f85543.

In certain scenarios, only IMMS#mCurMethodId is cleared with null
while IMMS#mCurClient is still pointing to the last application.
This is problematic when IMMS#mCurClient matches
SystemConfig#getFixedImeApps(), because it means that the current
IME is to be fixed to null.

With this CL, IMMS#unbindCurrentClientLocked() is always called
every time when IMMS#mCurMethodId is cleared to null. Note that
clearing IMMS#mCurMethodId to null is a kind of hard-reset, where
unbinding IME client should make much sense in terms of robust
and predictable state management.

Bug: 18056075
Change-Id: I6c3186050592526fc95c5b27f18e2155acff5ebc
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
70125f70dc058f0a79485ef473783e1fc6adbfc9 17-Sep-2015 Seigo Nonaka <nona@google.com> Merge "Move buildInputMethodsAndSubtypesString to InputMethodUtils"
2a099bcd6fe974bad47363c214a7bb327484aff8 15-Aug-2015 Seigo Nonaka <nona@google.com> Move buildInputMethodsAndSubtypesString to InputMethodUtils

This CL is mechanical code moving and does not change any existing
behavior.

buildInputMethodsAndSubtypesString is introduced by
If0104151b3526da6ecc669adde3119a239ecafeb for addressing Bug 19822542.
This code moving is one of the TODOs in above change.

Bug: 22285167
Change-Id: Ie63cf593794c9062919887e04a64208a900b1b8b
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7c69636c9a406265e1da368f3edfd8fb9651132c 16-Sep-2015 Xiaohui Chen <xiaohuic@google.com> Cleanup USER_OWNER in various services

Bug: 19913735
Change-Id: I980370bab18e1b9ccf4043eed2b9fd721a940f72
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
6ab1a8214195069f58692936914f66d8417b89c4 25-Aug-2015 Yohei Yukawa <yukawa@google.com> Organize import lines in InputMethodManagerService.java.

This CL changes nothing except for organizing the import lines
with the following style rule.
development/ide/intellij/codestyles/AndroidStyle.xml

No behavior change is intended.

Bug: 22285167
Change-Id: I029baa5e5609207ecc1023ece25fe803f676c377
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7309b123c423504bb18e3d78dd22a36f7271676a 18-Aug-2015 Seigo Nonaka <nona@google.com> Leverage WindowManagerInternal for private communication.

This CL changes following four methods from direct calling of
WindowManagerService to calling via WindowManagerInternal.
- getInputMethodWindowVisibleHeight
(introduced by I0e920ee79c526c3aea6872b063cf294e2ab081c8)
- saveLastInputMethodWindowForTransition
(introduced by Idf7700271cf882dfbf35c9d16f0f173a791221bc)
- isHardKeyboardAvailable
(introduced by I8a6a4a7efce50bfaec114117e33f97f27b1ef950)
- setOnHardKeyboardStatusChangeListener
(introduced by Ica768083f95c33dc1e494a28ba7d8b6eb989b0ef)

This CL does mechanical code moving and does not change any behaviors.

Bug: 22285167
Change-Id: I08e506050a0e495d62236b46e487848c967d185d
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
e27dc2b09d738e3a51232724724a559eec7e45b7 15-Aug-2015 Seigo Nonaka <nona@google.com> Use android.os.Debug.getCallers instead of self implementation.

This changes debug message format but does not change any other behavior.

Maintaining InputMethodUtils.getStackTrace() doesn't make much sense
because we already have a similar method in android.os.Debug.

since there is already utility function in Android. The length 10 is
sufficient for identifying caller modules.

getStackTrace() is introduced by
Ib23849d352db33f0747aa9d5a178f00ac726c13b just for debugging purpose as a
part of Bug 6931482.

Bug: 22285167
Change-Id: If3a6c0d2f51dc3774eef14b4f496b5b59ddcf5a6
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
2028ddaa5024dfc9844376f2032115aee360155a 06-Jul-2015 Seigo Nonaka <nona@google.com> Move parseInputMethodsAndSubtypesString to InputMethodUtils.

This CL is mechanical code moving and does not change any existing
semantics.

parseInputMethodsAndSubtypesString is introduced by
If0104151b3526da6ecc669adde3119a239ecafeb for addressing Bug 19822542.
This code moving is one of the TODOs in above change.

Bug: 22285167
Change-Id: I01f5fafbbcfe3e3f5313829162ec011eaf2ad991
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
5894b434aaf30933c26eb44689970926d274ed19 11-Aug-2015 Yohei Yukawa <yukawa@google.com> Use try-with-resources and multi-catch exceptions in IMMS.

This CL applies new Java 7 language features try-with-resources
and multi-catch exceptions to InputMethodManagerService.

Basically this is a compile-time replacement hence there should
be neither behavior difference nor performance impact.

Bug: 22285167
Change-Id: I971bd12b63649802859410ee6a91351b1261f055
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
59bc6e03a47044a0f6903787403ae6779024c26d 11-Aug-2015 Yohei Yukawa <yukawa@google.com> Delete unused code from IMMS and its utility library.

This CL changes nothing except for deleting unused code and
methods from InputMethodManagerService and InputMethodUtils.

No behavior change is expected.

Bug: 22285167
Change-Id: I3bd814c8b5892b4ef28d6d5622014463df8f1c2b
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
012d014c43c5fecb8f6e034089c22900c8755846 11-Aug-2015 Yohei Yukawa <yukawa@google.com> Merge "Use Java7 diamond operator in IMMS/IMS."
7c0832cb1cc1920efcc3fd266b3479d728d9b207 11-Aug-2015 Yohei Yukawa <yukawa@google.com> Remove unnecessary import lines from IMM and IMMS.

This CL changes nothing except for deleting unnecessary import
lines from IMM and IMMS.

Bug: 22285167
Change-Id: I86d250299fa1a8dc8f78343d6c141248c047255e
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
b0377bbf4e4e2b9b64a25223cd3b0c6386b3a0b7 11-Aug-2015 Yohei Yukawa <yukawa@google.com> Use Java7 diamond operator in IMMS/IMS.

This CL changes nothing except for deleting redundant type
parameters thanks to diamond operator.

Bug: 22285167
Change-Id: I12807f147bd0ca72c243e6fff87250d8f32d556b
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
df5af484f882ede16931a61a866f2ffefbe491ab 05-Aug-2015 Yohei Yukawa <yukawa@google.com> Reduce log spam for the ease of debugging Bug 22857361.

Now InputMethodManagerService generates the following log
Couldn't create dir.: /data/system/inputmethod
not only when it fails to create the directory but also when
/data/system/inputmethod already exists, which makes it
difficult for us to figure out the root cause of boot failure
on emulator environments (Bug 22857361).

With this CL, IMMS no longer shows the message when the
directory already exists. Basically this is no risk change,
which changes only the condition to show the logging message.

Bug: 22857361
Change-Id: I09aaf501b19845c8309b09b57c23077f1757cd1a
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
fa6e0a80e20a4917b403fd330e01a9edd021aabc 24-Jul-2015 Yohei Yukawa <yukawa@google.com> Don't rely on broadcast intent for waking up input method.

Basically this is a copy of Iabef96921dd554ce3768fb18619cefc
for InputMethodManagerService.

As described in JavaDoc of Intent#ACTION_SCREEN_OFF and
Intent#ACTION_SCREEN_ON, one can use those Intents to be
notified when the device becomes non-interactive and
interactive. IMMS has relied on them to enable and disable
InputConnection between the IME and the application so as not
to allow IMEs to update text when the user does not present.
This is actually our design goal as documented in JavaDoc of
InputMethodManager.

An IME can never interact with an InputConnection while
the screen is off. This is enforced by making all clients
inactive while the screen is off, and prevents bad IMEs from
driving the UI when the user can not be aware of its
behavior.

The goal of this CL is to improve the timeliness of above
mechianism by introducing a direct communication channel from
PowerManagerService to InputMethodManagerService via Notifier.
Actually this is what InputManager has been doing since
Iabef96921dd554ce3768fb18619cefc3230b5fb0.

Reasons behind this change are:

1. There are several bugreports that imply those Intents can
dispatch tens of seconds after it is enqueued. This is
indeed problematic because the user cannot type password
to unlock their devices until queued
Intent#ACTION_SCREEN_ON is dispatched. This CL addresses
such an issue without waiting for figuring out the root
cause of the delay.
2. Intent#ACTION_SCREEN_OFF and Intent#ACTION_SCREEN_ON are
sent as a ordered broadcast, which may not be suitable for
tasks that require a certain level of timeliness, and what
IMMS wants is to enable users to start typing immediately
after the system.

This CL was originally authored by Seigo Nonaka.

Bug: 22423200
Bug: 22555778
Change-Id: I747c37ff6dd8f233faef43f2b5713a4320e848eb
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
648abe156596a5f76e6bd883c4d25d0380bbd469 22-Jun-2015 Yohei Yukawa <yukawa@google.com> Merge "Set DISABLED_UNTIL_USED for the correct user in IMMS." into mnc-dev
094c71fd5c0b6b7ce4cd71d097d226a6a1acfc90 20-Jun-2015 Yohei Yukawa <yukawa@google.com> Set DISABLED_UNTIL_USED for the correct user in IMMS.

This CL makes If8ff1b2b95c36d33148def2ab87bd006aa520cc0
multi-user aware.

It turns out that DISABLED_UNTIL_USED has not been correctly
set to IMEs seen from secondary users because we have used
IMMS#mContext.getPackageManager(),
which always returns the PackageManager with the primary
users' context, when specifying
COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED.

We should use IPackageManager instead as we have already done
in many places of IMMS since Ib23849d352db33f0747aa9d5a178f00.

Bug: 8148605
Bug: 8365223
Bug: 21953608
Change-Id: I4b9d6510bf965204bb1f68c8b527d1a4df23fac4
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
1e575a0f32a00fc6a2f9a71fe1d1eb4426c71787 20-Jun-2015 Svet Ganov <svetoslavganov@google.com> Merge "Only grant runtime permissions to special components." into mnc-dev
adc1cf46045ae756d3a9ccbccf6b0f894e4c1edd 16-Jun-2015 Svet Ganov <svetoslavganov@google.com> Only grant runtime permissions to special components.

Now runtime permissions are granted only to components that are
part of the system or perform special system operations. For
exmple, the shell UID gets its runtime permissions granted by
default and the default phone app gets the phone permissions
granted by default.

bug:21764803

Change-Id: If8b8cadbd1980ffe7a6fc15bbb5f54a425f6e8f9
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
ec928651cc3e72c2e8ff6102a6c037c5119617ee 10-Jun-2015 Seigo Nonaka <nona@google.com> Allow apps to hide the soft keyboard even in a transient state.

Since I69b88989ae4d0fe056e9ab8d67d0a955dd10e6d9, we have
asserted that the following test cases can pass with CTS.

assertTrue(imm.showSoftInput(
view, InputMethodManager.SHOW_IMPLICIT));
assertTrue(imm.hideSoftInputFromWindow(token, 0));

This CL fixes the test failure caused by
I33dc6278fd892f26e56352722bf9449b8b102030 in the above
CTS case.

Note that the test failure occurs only when the application
tries to close the software keyboard during IMMS#mInputShown
and IMMS#mImeWindowVis are in a transiently inconsistent
state.

Bug: 21727232
Change-Id: I195a9f9644583cb1172f48801e87273ad8def850
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
1ce4b6d3c6cb5b2eb9c9d00472be12245db92427 11-Jun-2015 Chris Wren <cwren@android.com> remove usage of deprecated method setLatestEventInfo

Bug: 18510449
Change-Id: I56a77991c729990e501f402e007dfa79ee57621e
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d57ba675b1f767885e6d3ccd4d0f7037e634648b 09-Jun-2015 Yohei Yukawa <yukawa@google.com> Do not accept an empty string in EditorInfo#packageName anymore.

In the previous CL Ib871141e3381e45c2623c5f4d692da7a7e78fcc5,
a null or empty EditorInfo#packageName was still allowed in case
there might be applications that simply forgot to set it.

However, after checking the code again, it would be safe to say
that having a null or an empty string in EditorInfo#packageName
would never happen unless the application intentionally clears it
in View#onCreateInputConnection. If there were such applications,
probably we could ask developers to stop doing that.

With this CL the system no longer accepts such an empty package
name. IME developers do not need to handle such an exceptional
case in their side.

Bug: 18931038
Change-Id: I10d579b48b59fa8ada796e92d58517c6cc5f2230
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
81482971431c91bbf63e8ad70c9f720e6bdf10b3 04-Jun-2015 Yohei Yukawa <yukawa@google.com> Make IMMS#mSettingsObserver multiuser-aware.

It turns out that IMMS#SettingsObserver has monitored
only main user's the secure settings. As a result, when the
secondary user changes enabled IMEs in the settigs app,
IMMS only updates internal enabled IME lists only when
the user is switched for secondary users. If a secondary
user enables or disables IMEs at the settings app, such
changes are not correctly notified to IMMS.

This CL addresses above inconsistency by explicitly
specifying the user ID when calling
ContentResolver#registerContentObserver().

This CL also allows dumpsys to contain internal state of
IMMS#mSettingsObserver in case we need to diagnose
problems only with bugreports.

Bug: 19340792
Bug: 19587437
Bug: 21612582
Change-Id: I34b437928c147e9fdbe935f725624cc97c816cb3
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d724886cc13990ebcf55134455ef0fa223054ae8 04-Jun-2015 Yohei Yukawa <yukawa@google.com> Include InputMethodSubtypeSwitchingController in state dump.

In order to diagnose IME issues in multi-user / multi-profile
environment, internal state of
InputMethodSubtypeSwitchingController needs to be included in
the bugreport.

Bug: 19340792
Bug: 19587437
Bug: 21612582
Change-Id: I34aca2c1a4330ec08b5e40441e631809a8bb844e
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
90bf7084bf4f681383bf3329b0935de55330e782 04-Jun-2015 Yohei Yukawa <yukawa@google.com> Show more logs when switching users and IMMS#DEBUG==true.

This CL changes nothing but adds more logging points in IMMS when
switching users and IMMS#DEBUG==true.

No impact in production code.

Bug: 19340792
Bug: 19587437
Bug: 21612582
Change-Id: Ibaeb77ae50d246fc322cb023da7750d7415a58ab
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d9eb911bb99df4d092dea00e52bcb9a1feac39a7 26-May-2015 Seigo Nonaka <nona@google.com> Hide the software input based on its state.

This is a 2nd trial of I20ae2749a which is reverted due to a regression.
The goals of this CL are two:
- Split setImeWindowStatus method into two: keeping IMS status and
updating system UI e.g. NavBar icon state.
- Hide software keyboard based on a realistic IMS status.

IMMS#mImeWindowVis has been used for two purpose, keeping IMS status and
updating the NavBar icons, e.g. keyboard icon.
However, to update NavBar icon, sometimes IMMS#mImeWindowVis value is
updated without any notification from IMS. As the result, the status
value becomes incosistent with the real IMS state.
This patch extracts NavBar update logic into separate method and keeps
IMMS#mImeWindowVis as notified status. Then, use it for hiding software
input correctly in IMMS#hideCurrentInputLocked.

This CL also removes refreshImeWindowVisibilityLocked method including
workaround for fixing Bug 11186297. That issue is no longer
reproducible with latest lock screen and almost no effect for existing
users and developers. So simply remove them in this CL.

BUG: 21446788
BUG: 20764441
BUG: 18722991
Change-Id: I33dc6278fd892f26e56352722bf9449b8b102030
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
54d512c9acc44484b7baa8d8cf02067d175dde11 20-May-2015 Yohei Yukawa <yukawa@google.com> Invalidate IMMS#mCurrentSubtype when upgrading the current IME.

Whenever the package to which the current IME belongs is
modified, IMMS#mCurrentSubtype needs to be invalidated.
Otherwize, InputMethodManager#getCurrentInputMethodSubtype()
continues to return the previously selected subtype.

One example scenario would be to update metadata of a subtype
in a new version of an IME with keeping the same subtypeId.
Suppose imeSubtypeExtraValue was updated from "ABC" to "XYZ".
In this scenario, the subtype in question retrieved with
IMM#getInputMethodList() then InputMethodInfo#getSubtypeAt()
has imeSubtypeExtraValue "XYZ", while the subtype returned
from InputMethodManager#getCurrentInputMethodSubtype() still
has imeSubtypeExtraValue "ABC".

With this CL, IMMS#mCurrentSubtype will be invalidate when
the active IME package is modified.

Bug: 21310194
Bug: 20708002
Change-Id: Ifbb35034d9c8e477ebb5353d2a470dfc1627bbd5
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
6640d21b2e8d16190fdf79cb3ec4b7694a1ea90b 15-May-2015 Yohei Yukawa <yukawa@google.com> Revert "Fix IMMS#mInputShown state inconsistency."

This reverts commit 8d4a9117fbd0aaf03b8486ef920c73894a12cfcd.

Because of a regression Bug 21161785.

Bug: 21161785
Bug: 18722991
Bug: 20763994
Bug: 20764441
Bug: 20926844
Change-Id: If58612eda08764be0226832c0a73f03683889cdb
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
9e9e2e73c6ec7bece20268196dc89ad0c8bafad4 08-May-2015 Wojciech Staszkiewicz <staszkiewicz@google.com> Pass charset to XmlPullParser.setInput instead of null

Passing null to XmlPullParser.setInput forces it to do additional
work, which can be easily avoided if we know the charset beforehand.

bug: b/20849543

Change-Id: Iaff97be9df2d0f99d7af8f19f65934439c9658e2
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
c6c7cd2736fc3b6511e329a969409622750f2a58 13-May-2015 Yohei Yukawa <yukawa@google.com> Show IME switcher also when hardware keyboard is connected.

As per discussion with UX team, we start showing IME switcher UI
not only when there are multiple IMEs are enabled but also when
a hardware keyboard is connected.

This CL also simplifies needsToShowImeSwitchOngoingNotification()
by renaming it with shouldShowImeSwitcherLocked() and unifying
related condition checking into that method.

Bug: 19496012
Change-Id: Id44724a2a46190382c283a52ece8edffb740807d
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
8d4a9117fbd0aaf03b8486ef920c73894a12cfcd 15-Apr-2015 Seigo Nonaka <nona@google.com> Fix IMMS#mInputShown state inconsistency.

The goal of this CL is to keep IMMS#mInputShown consistent with the
actual visibility of the software keyboard. Doing it indeed fixes many
user-visible inconsistency, especially when a physical keyboards is
attached.

It turned out that there are much more cases where IMMS#mInputShown
should have been updated. Basically every time when the software
keyboard is shown or hiden by non-user actions, IMMS#mInputShown was not
updated to the new state. Typical cases are:
- the IME shows its Emoji keyboard when the ALT key is pressed.
- the system hides software keyboard when physical keyboard is
connected.

With this CL, all known issues will disapper by updating
IMMS#mInputShown in IMMS#setImeWindowStatus().

Note that this CL depends on following preparation CLs directly or
indirectly.
- I7002ff063e490928309e9a9a0f6557ce3d12e6aa
- I1e50ee42838a1bf64a612da4904aa93458d44ea4
- I3decaf37198e5864a1763a059df4a36ebc70c5a7
- Id156c85535a221235737ea6dcc15a67f1c4b9f71
- I9f797d07ba02363fab58ceb9aecb3cc11fbc407e
- I60963f1474457ff37cca85e262460dca8105acff

Simply cherry-picking this CL into L branch is supposed to be
insufficient to fix all the issues and would result in different
regressions indeed.

BUG: 18722991
BUG: 20763994
BUG: 20764441
BUG: 20926844
Change-Id: I20ae2749a93bc33840df560aa71d4635e9ec849a
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
14e139179be7daab6ed452105387a3922752c219 07-May-2015 Seigo Nonaka <nona@gogole.com> Retry "Always show auxiliary subtypes from NavBar keyboard icon."

This CL relands I1e50ee42838a1bf64a612da4904aa93458d44ea4, which was
reverted by I3decaf37198e5864a1763a059df4a36ebc70c5a7 due to the build
breakage in 'layoutlib' target, with a proper fix.

Hereafter the original CL description is repeated.

The auxiliary subtypes should be listed if the input method picker is
opened from NavBar keyboard icon. However there is only
IMM#showInputMethodPicker() API to open input method picker and this is
also used from LockScreen or Settings UI. Auxiliary subtypes should not
be listed there(Id7cf5d122). Thus framework shows auxiliary subtypes
based on IMMS#mInputShown and LockScreen state, but it is not a perfect
solution. If a physical keyboard is connected, the soft input may be
gone. As the result, auxiliary subtypes won't be listed even if it is
opened from NavBar keyboard icon.

To fix this issue, this CL introduces IMM#showInputMethodPicker(boolean)
to be able to decide showing auxiliary subtypes by caller.
Note that IMM#showInputMethodPicker(boolean) is still hidden with @hide.
There is no public API change in this CL.

Bug: 20763994
Change-Id: Id156c85535a221235737ea6dcc15a67f1c4b9f71
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
1b0888fe8e70ddb92090edbaea545f2766ee404e 07-May-2015 Bart Sears <bsears@google.com> Merge "Revert "Always show auxiliary subtypes from NavBar keyboard icon."" into mnc-dev
d130bdc462b163f9afcaf144b477be80959e04d6 07-May-2015 Bart Sears <bsears@google.com> Revert "Always show auxiliary subtypes from NavBar keyboard icon."

CL is breaking the build. Discussed with Seigo and verting until he can take a look at it.

This reverts commit 80ff4ed6bb8dbdad7192d679a01096aa888e090b.

Change-Id: I3decaf37198e5864a1763a059df4a36ebc70c5a7
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7afd01e2f1c0235f5d5a95744200d6739d6fcaa4 07-May-2015 Seigo Nonaka <nona@google.com> Merge "Do nothing if hideSoftInput is called from not focused client." into mnc-dev
ccee75966ae00e9a2426df09c0aa8610e145ad72 06-May-2015 Seigo Nonaka <nona@google.com> Do nothing if hideSoftInput is called from not focused client.

IMMS#hideSoftInput calls IMMS#setImeWindowVisibilityStatusHiddenLocked
if it is called from not focused client. However this function changes
IMS visibility state and also changes the back key indicator wrongly.
IMMS should just ignore IMMS#hideSoftInput from not-focused client.

As a preparation to fix b/20764441, this CL partially reverts
Ife3a8733b1a1bf43b195ecf4b8c5082b6538d0a0 but shouldn't have any
user-visible UX regressions.

Bug: 20764441

Change-Id: I60963f1474457ff37cca85e262460dca8105acff
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
80ff4ed6bb8dbdad7192d679a01096aa888e090b 04-May-2015 Seigo Nonaka <nona@google.com> Always show auxiliary subtypes from NavBar keyboard icon.

The auxiliary subtypes should be listed if the input method picker is
opened from NavBar keyboard icon. However there is only
IMM#showInputMethodPicker() API to open input method picker and this is
also used from LockScreen or Settings UI. Auxiliary subtypes should not
be listed there(Id7cf5d122). Thus framework shows auxiliary subtypes
based on IMMS#mInputShown and LockScreen state, but it is not a perfect
solution. If a physical keyboard is connected, the soft input may be
gone. As the result, auxiliary subtypes won't be listed even if it is
opened from NavBar keyboard icon.

To fix this issue, this CL introduces IMM#showInputMethodPicker(boolean)
to be able to decide showing auxiliary subtypes by caller.
Note that IMM#showInputMethodPicker(boolean) is still hidden with @hide.
There is no public API change in this CL.

Bug: 20763994

Change-Id: I1e50ee42838a1bf64a612da4904aa93458d44ea4
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d4474cb9454c7a8b907c0be07236ffed4ecf3fd8 05-May-2015 Seigo Nonaka <nona@google.com> Remove dead code from IMMS.

MSG_SHOW_IM_PICKER is no longer used. Also by removing that message, we
can simplify showInputMethodMenu/showINputMethodSubtypeMenu.

Change-Id: I7002ff063e490928309e9a9a0f6557ce3d12e6aa
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d69e4c1460017062e7c36be55801cb434ad19d97 24-Apr-2015 Dianne Hackborn <hackbod@google.com> Update use of procstate for services.

Now that we have a separate foreground service proc state
(above a sleeping top app), update various system services
to put their bindings into this state when appropriate.

There are two new bind flags for this -- one that just always
makes it a foreground service, another that only does it when
the device is awake (useful for things like the wallpaper).

And with all of that, tweak network policy manager to only
include apps that are at least foreground service state when
in power save and device idle modes. This will allow us to
further reduce the set of apps that have network access
(in particular not giving access to the current top app when
the screen is off), hopefully leading to even better battery
life.

Change-Id: I91d85a5c5ed64e856149e9a5d94a634a7925ec7f
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
e13b15c8101471c2aae1fbdcd55da9b2d7bbf7b1 13-Apr-2015 Kenny Guy <kennyguy@google.com> Merge "Add foreground profile changed to user switch observer."
429796226a8831af63a6303a58329f6b68f7b100 13-Apr-2015 Kenny Guy <kennyguy@google.com> Add foreground profile changed to user switch observer.

Called when the focused activity changes from one profile
to another to allow sys ui to vary display based on the
current profile.
This reverts commit 735a3f90598be31bca5d551d781280a205a5f27f.
Resubmitting with fix for build break in another package.

Bug: 19531782
Change-Id: I98cd2968ade3b1d23feb90d98057f306695d569e
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
48a09a0678752eca242a5379b024da78eb36144f 13-Apr-2015 Kenny Guy <kennyguy@google.com> Merge "Revert "Add foreground profile changed to user switch observer.""
735a3f90598be31bca5d551d781280a205a5f27f 13-Apr-2015 Kenny Guy <kennyguy@google.com> Revert "Add foreground profile changed to user switch observer."

This reverts commit 99b9030a3ececd9b88e5011c98be0a5b9499c776.

Change-Id: If152904f298ecd9e6fd5d038797d061a5c85eec8
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d10bd4852291f1c99d2fc011606a695d631504fe 13-Apr-2015 Kenny Guy <kennyguy@google.com> Merge "Add foreground profile changed to user switch observer."
99b9030a3ececd9b88e5011c98be0a5b9499c776 01-Apr-2015 Kenny Guy <kennyguy@google.com> Add foreground profile changed to user switch observer.

Called when the focused activity changes from one profile
to another to allow sys ui to vary display based on the
current profile.

Bug: 19531782
Change-Id: I1f98398f4b37ce77077394546906ef4dff06cd47
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
a0f3ad1b5aabe04d9eb1df8bad34124b826ab641 07-Apr-2015 Yohei Yukaw <yukawa@google.com> Verify that EditorInfo.packageName and uid are consistent

Currently EditorInfo.packageName is filled in the application
process and passed to the IME without any verification.

With this CL, the system makes sure that the provided package
name and application's uid are consistent before establishing
the input connection. In other words, the risk of spoofed
EditorInfo.packageName will be mitigated with this change.

This should be beneficial especially when an IME wants to have
per-application settings and/or dictionaries.

Bug: 18931038

Change-Id: Ib871141e3381e45c2623c5f4d692da7a7e78fcc5
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7b9a28c7f0a7b88ed1ea777edc05002d2d2b38b7 18-Mar-2015 Christopher Tate <ctate@google.com> Back up and restore the set of enabled IMEs

The restored set of enabled IMEs/subtypes is merged into the
current state of the system, rather than simply replacing it.
This is because we do not want to accidentally disable or
reconfigure something that the user is currently relying on.

There's a certain amount of repetitive activity here, rebuilding
the enabled-state data structures in a different format, but it's
important for maintainability that the restore code be able to
rely on the core InputMethodUtils implementation of reading/writing
the settings element.

Bug 19822542

Change-Id: If0104151b3526da6ecc669adde3119a239ecafeb
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
4a357cd2e55293402d7172766f7f9419815fc1e8 19-Mar-2015 Alan Viverette <alanv@google.com> Replace usages of deprecated Resources.getColor() and getColorStateList()

Change-Id: I8f64fe6c4c44a92ff6d07250223ba590a1d691b0
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
6aa037887800e34bd057585106609236c950ca22 20-Feb-2015 Yohei Yukawa <yukawa@google.com> Remove deprecated hidden public methods from InputMethodUtils.

This is a follow up CL for a recent attempt to minimize
the number of default enabled IMEs.
- part1: I831502db502f4073c9c2f50ce7705a4e45e2e1e3
- part2: Ife93d909fb8a24471c425c903e2b7048826e17a3
- part3: I6571d464a46453934f0a8f5e79018a67a9a3c845
- part4: I871ccda787eb0f1099ba3574356c1da4b33681f3

This CL removes following deprecated hidden public methods
from InputMethodUtils as planned.
- isSystemImeThatHasEnglishKeyboardSubtype(InputMethodInfo)
- isValidSystemDefaultIme(boolean, InputMethodInfo, Context)
- containsSubtypeOf(InputMethodInfo, String, String)

This is a pure code refactoring with preserving the current
logic. Hence no behavior change is intended.

Change-Id: I1ff994cbbdef83e1e907a0d88aa9ae09d45263b4
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
505e3abb8dd0d8f594280b9510adef74623630d7 25-Nov-2014 Alan Viverette <alanv@google.com> Update IME selection dialog layout for Material

Also cleans up simple_list_item_2.xml formatting.

BUG: 18314215
Change-Id: I12b6ff19fca891524da7137b85dd576f85ee266a
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
5baaaac7c75dbcbd1de8e4f24820f231d2077231 27-Oct-2014 Hyejin Kim <hyejin.kim@lge.com> Fix not to show a log with empty default ime

It'll make reboot to show a log with empty defualt ime.

Bug: 18165757
Change-Id: I7a0d55bc0da0566a60abb24123c1dbcdd03be9ed
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
e63b5fae8d099d2f5d4d5a5cf7a8d5a86266c0fe 19-Sep-2014 Yohei Yukawa <yukawa@google.com> Work on issue #17506095: Plumb a new configuration to IMMS

This CL makes a plumbing from SystemConfig to IMMS.

Change-Id: Ia70b870723acf647e0c27f24aff91b40d6f85543
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
443c2bafd824779a75cd4b922b6839a8df9795e9 10-Sep-2014 Yohei Yukawa <yukawa@google.com> Use public APIs to instantiate InputMethodSubtype

This is a groundwork for subsequent CLs that are
supposed to improve default input method selection
logics.

Historically we have had a @hide constructor of
InputMethodSubtype. However, this contructor is
a bit obsolete because we can not specify some
parameters that were added in recent platform
releases. We should use InputMethodSubtypeBuilder
instead.

BUG: 17347871
Change-Id: I72ad79682a58344e14380eb20e26edf98aee37cd
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
080fa34577ea4d461c91631986ede4a25877b305 01-Sep-2014 Yohei Yukawa <yukawa@google.com> Fix illegal cast in a logging code

This is a follow up CL for I19ad8542659bc092b92ee13eb9,
which introduced a ClassCastException error in the logging code
of MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER handler.

With this CL, the protocol in question looks like:
- what: MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER
- arg1: sequence number to be passed to
#setUserActionNotificationSequenceNumber(int)
- arg2: not used
- obj: ClientState

BUG: 16238154
BUG: 7043015
Change-Id: I08d52d4564bae9e042a2eff359e92549a66e837b
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
255dd04271088590fedc46c8e22b2fd4ab142d39 19-Aug-2014 Selim Cinek <cinek@google.com> Added notification color to all system notifications

Bug: 17128331
Change-Id: I81a94510ef51b99916f314c0dd65852426a1fbeb
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
7b5a96ba8364d5c180780b2f878f5a2b949cfdac 10-Aug-2014 Michael Wright <michaelwr@google.com> Persist Show IME option.

Add a new setting to persist whether to show the IME when a hard
keyboard is connected.

Bug: 14066881
Change-Id: I2237ded850a0d4ab43ca441d0b7df13e0958e630
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
665366a3055c7baa36242b8c92c5ff85b1c3394b 08-Aug-2014 Michael Wright <michaelwr@google.com> Change 'disable hardware keyboard' to 'show input method'

Previously it implied that the hardware keyboard would be disabled,
but really the toggle would just enable showing the IME even if a
hardware keyboard was present. Changed the string and swapped the
semantics to be more clear about the behavior.

Bug: 14066881
Change-Id: I9c8a7eb98b5277f1d09cc19fa7402e9b4cf51d92
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
8c6d477d30e64f3dfae20250b8274ffb37ef7bfa 05-Aug-2014 Tadashi G. Takaoka <takaoka@google.com> Fix unnecessarily non-static inner class to static inner

Change-Id: I0c8efda6ef0bede6b5871cd651f42db82dbfbd39
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d130b803b0787131208bea99926dc655b124f006 01-Aug-2014 Tadashi G. Takaoka <takaoka@google.com> Fix input method picker using Material design language

Note that the button text color will be fixed in the future change.

Bug: 14860252
Change-Id: I8a6a4a7efce50bfaec114117e33f97f27b1ef950
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
0023d0e0c4f5339b299d1eacbd4e7181c2fd271f 10-Jul-2014 Yohei Yukawa <yukawa@google.com> Polish new IME API for L part 2: CursorAnchorInfo

This CL addresses feedbacks from internal customers for new
input method APIs that are mainly used for physical keyboard
support in L.

For performance reasons, #onUpdateCursorAnchorInfo is not called
back by default and each input method has to enable this
event notification explicitly whenever fine-grained character
locations are needed.

In L-preview, InputMethodSession#setCursorAnchorMonitorMode was
introduced for this purpose. However, we got several feedbacks
to be addressed.
- The effect of #setCursorAnchorMonitorMode is not preserved
during focus change. IMEs need to call
#setCursorAnchorMonitorMode every time when #onStartInput is
called. This is tricky and hard to understand.
- As #onUpdateCursorAnchorInfo is a new API, not all
applications/text editors have supported it. Therefore IMEs
can't always rely on it. However, there is no way to query
if the attached target is supporting this new API or not.
It would helpful for IME authors if we can provide a
reliable way to query if the attached input target is
supporting the new API or not.

In order to address these issues, the triggering method has
moved from InputMethodSession to InputConnection in this CL,
as an analogy of existing InputConnection#getExtractedText API,
which has provided similar functionality including optional
reactive event callbacks from the application to the IME.

BUG: 15812658
BUG: 16118603
Change-Id: I3c6b69bd9d79b199afe68d838f25effa6048e5cc
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
3d1e8129ebd69db49d80e5d598f608c59b884cdf 06-Jun-2014 Yohei Yukawa <yukawa@google.com> Introduce a sequence number to avoid redundant IPCs

This CL introduces a sequence number to avoid redundant IPCs
between IMM and IMMS. The basic concept is that:
1. IMMS maintains a sequence number for #notifyUserAction.
2. IMMS increases the sequence number whenever the current
IME/subtype is changed.
3. IMMS notifies the new sequence number to IMM.
4. IMM maintains the last sent sequence number and the next
sequence number. IMM should call #notifyUserAction only
once per particular sequence number.
5. IMMS ignores #notifyUserAction if the specified sequence
number is not the expected one.

BUG: 7043015
Change-Id: I19ad8542659bc092b92ee13eb9f1d68ddd4b815a
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
0297051162193ef2b7d906409868e404f77e4c31 05-Jun-2014 Yohei Yukawa <yukawa@google.com> Trivial method renaming for notifyTextCommitted

This CL does not change existing behavior but only renames
notifyTextCommitted with notifyUserAction so that we can use
not only text commit but also other actions such as just typing
a character will be used as a trigger to update the IME
rotation order for better IME switching experience.

BUG: 7043015
Change-Id: I7f3e13a7226ef0dceee82b67e8a0d8536f7e9807
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
a07557471e43226fd23f6447c1e61177726524c9 04-Jun-2014 Yohei Yukawa <yukawa@google.com> Hardening token validation in InputMethodManagerService

This CL adds missing token validations in
InputMethodManagerService#switchToNextInputMethod and
InputMethodManagerService#shouldOfferSwitchingToNextInputMethod.

This CL also fixes a possible race condition when validating
the token in InputMethodManagerService#updateStatusIcon.

BUG: 15420379
Change-Id: I043aa30a19c821f33effd57dfd6590b0e3ed817b
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
22c97be73b2686a4a06cf31d0b211f47e7b92595 04-Jun-2014 Yohei Yukawa <yukawa@google.com> Remove code duplication in InputMethodManagerService

This is a groundwork for the subsequent fix. It should not change
existing behavior.

BUG: 15420379
Change-Id: I106b3f50731c799e06b26d1eab9c6a406c06d78c
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
4e02bc6f8fa64d8a8398371836e2e9abf3be3070 04-Jun-2014 Yohei Yukawa <yukawa@google.com> Remove redundant synchronization blocks from IMMS

This is a groundwork for the subsequent fix. It should not change
existing behavior.

BUG: 15420379
Change-Id: I6f81ec77e748a8c7c26ffa1f5faf39684b210ae4
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
3d46bab02978df14354379c4b10d7f68c3b80771 30-May-2014 Yohei Yukawa <yukawa@google.com> Rebuild the enabled IMEs list when changed in Settings page

With this CL, the input method switching controller is notified
even when the list of enabled IMEs is changed by System
Settings.

Ideally we should hook every setter method in
InputMethodSettings to ensure that InputMethodSettings and
InputMethodSubtypeSwitchingController can share the same list.
Until then, most of user visible weirdness should disappear
with this CL.

BUG: 15299968
Change-Id: Ie41da226d71b58d2e12057f85e4793b35e8b9f23
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
5a647b69be8ac8d40c33ed9abe63e41514699e5b 21-May-2014 Yohei Yukawa <yukawa@google.com> Remove unnecessary internal lock

Previously, InputMethodSubtypeSwitchingController has relied on
its own internal lock for #getNextInputMethod and
class has to be invalidated whenever
InputMethodManagerService#mMethodMap is updated, any method of
InputMethodSubtypeSwitchingController should be called under
the global lock of InputMethodManagerService#mMethodMap.

As a consequence, we can conclude that
InputMethodSubtypeSwitchingController does not need its own
internal lock.

This CL also adds additional synchronization blocks into
the constructor of InputMethodManagerService to address the
existing inconsistency that methods with *Locked suffix are
called without the lock actually.

BUG: 7043015
Change-Id: I9d4d3d7232c984432185c10c13fb726a6158cac8
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
c834a2590cc7ac478ba2ef5a6d8eb7ce471df132 21-May-2014 Yohei Yukawa <yukawa@google.com> Update InputMethodSubtypeSwitchingController correctly

User visible behavior is supposed to be identical with and
without this CL.

Previously, there is some corner cases where
InputMethodSubtypeSwitchingController#resetCircularListLocked is
not called but the list of enabled input method is updated.

Fortunately, this corner cases are not observable for a user
because we have not updated the the rotation order dynamically.

However we should fix this before implementing smarter rotation
algorithm that changes the rotation order dynamically.

BUG: 7043015
Change-Id: I145a514dc4cde369ba50431c408c916046ab0c6e
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
d4e6d467cd61d6bec1ae25744a415a96f0a0f760 17-May-2014 Dianne Hackborn <hackbod@google.com> Delay the dispatching of non-wakeup alarms.

When the screen is off, there are no guarantees about when
non-wakeup alarms will be dispatched. Historically they are
dispatched any time the device wakes up. With this change,
we will delay the dispatch until sometime later.

The amount of delay is determined by how long the screen has
been off. Currently there are three possible delays: up to
2 minutes if the screen has been off for less than 5 minutes;
up to 15 minutes if it has been off for less than 30 minutes;
and otherwise up to an hour.

When the screen is turned on or a wakeup alarm is dispatched,
all delayed alarms will also be dispatched.

Note that one of the things this delays is TIME_TICK, which
means the in many cases we won't deliver TIME_TICK until the
screen is in the process of waking up. The current
implementation causes this to be delayed until the SCREEN_ON
broadcast is sent; we probably want to improve this to have
the power manager tell the alarm manager about the screen
turning on before it sends that broadcast, to help make sure
things like the lock screen can update their current time
before the screen is actually turned on.

In addition, switch all of the alarm stats to use the new
PendingIntent "tag" identifier for its operations, instead
of the old code to try to construct a pseudo-identifier
by retrieving the raw Intent.

Also add a new package manager command to immediately write
packages.xml.

Change-Id: Id4b14757cccff9cb2c6b36de994de38163abf615
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
9d91b43c8d0fa233905ecf132c6e6ee664904694 19-May-2014 Yohei Yukawa <yukawa@google.com> Do not pass null to IInputMethod#setSessionEnabled

It doen't make sense to pass null as IInputMethodSession
for IInputMethod#setSessionEnabled. If we do this, it
causes NPE.

BUG: 14980068
Change-Id: Ide48d098d5e7640890257e31f8872e79b9821eb2
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
807ef76e23e08405532a0e7e2d71e7433bf7ae9a 08-May-2014 Jason Monk <jmonk@google.com> Don't show switcher button when IME switcher shown

This keeps track of when the switcher is being shown and disables
the IME switcher button/notification when it is up.

Bug: 14631536
Change-Id: I4adf24bc5fa6377645915419583d60596b3bdde0
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
b605fecd9e4282823af754b3968b21205d64554a 02-May-2014 Jason Monk <jmonk@google.com> Only show IME in navigation bar when it should

Add a flag to indicate that the IME should be shown. This follows
the continuous ime notification boolean, and if there are multiple
input methods to choose from enabled. This way the notification
and navigation button show up under the same circumstances (but
not on the same devices).

Change-Id: Ia6a2253061f1876f4bcc511de48c1078e9d96be5
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
e463c745ef6901121837e88ca8597d062843b9dd 02-May-2014 Jason Monk <jmonk@google.com> Don't show IME Switcher not. if nav bar exists

Since the navigation bar now has IME switcher icon no need for a
notification about it when it is present.

Bug: 14257632
Change-Id: I5511fee0dee45475d5b7949f63696b1d29acf9cc
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
b7b7907fb5e4b2252b3c594a6bc4402217fe662a 25-Mar-2014 Yohei Yukawa <yukawa@google.com> Allow IMEs to start/stop receiving onUpdateCursor callback

This CL introduces an API which allows IMEs to start/stop
receiving onUpdateCursor callback upon their request.

BUG: 13388665
Change-Id: I987326872def181dda5d9d701b762f088e0d9c39
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
2a764949c943681a4d25a17a0b203a0127a4a486 02-Apr-2014 Kenny Guy <kennyguy@google.com> Rename related users to profiles.

Rename the related user concept as profiles.
When returning profiles of a user include the
user as a profile of itself.

Change-Id: Id5d4f29017b7ca6844632ce643f10331ad733e1d
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
6b6b3fdbf5547417fde3ce56d9eb883963a54b58 24-Mar-2014 Dianne Hackborn <hackbod@google.com> Fix issue #13564072: Back button no longer dismisses IME after voice usage

Calling identity wasn't being cleared in an incoming code path.

Change-Id: Ib32060a91bf81531de049fafde69835b5382a25f
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
fd7f1e00399e53a392941928ed5a55ca77b1b721 18-Mar-2014 John Spurlock <jspurlock@google.com> Unhide notification category.

Rename @hidden Notification.kind -> category, and flesh out
shared values. Now a single value.

Update framework references, remove unused SystemUpdateService
magic value unused since 2012.

Change-Id: If06d19ff3a8c3125fca1457f5d3c665e2939c66c
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
f0f94d129b6eb3c48624e915898d86d4f2de59ff 18-Mar-2014 Dianne Hackborn <hackbod@google.com> Treat IME processes as hosting activities

When we stop using an IME process, we still treat that
process as if it is hosting activities (in the activity part
of the LRU list), to try to keep it around. This is intended
to help the experience of switching between IMEs, reducing
the chance of your previous IME process being killed and thus
requiring much more time to switch.

Change-Id: Ie5793fd9b40d980fa18f80246326511ed6ae0597
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
734983fff35d9ed2b7a9848bdfbca401887d0dd8 05-Mar-2014 Amith Yamasani <yamasani@google.com> Allow related users to show activities on primary user

Make ActivityManager and WindowManager understand related users.

Task stack will now contain interleaved tasks for related users,
but still group regular users separately from groups of related users.

InputMethodManagerService permits related users to invoke IME and receive
key events.

Change-Id: I3bd87b32aec69c3f8d470c8b29b144f4e849c808
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
49782e46c0eb85a25ae2abcf80880c48dbab5aea 20-Dec-2013 Amith Yamasani <yamasani@google.com> am 9158825f: Move some system services to separate directories

* commit '9158825f9c41869689d6b1786d7c7aa8bdd524ce':
Move some system services to separate directories
9158825f9c41869689d6b1786d7c7aa8bdd524ce 22-Nov-2013 Amith Yamasani <yamasani@google.com> Move some system services to separate directories

Refactored the directory structure so that services can be optionally
excluded. This is step 1. Will be followed by another change that makes
it possible to remove services from the build.

Change-Id: Ideacedfd34b5e213217ad3ff4ebb21c4a8e73f85
/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java