Commit Graph

259 Commits

Author SHA1 Message Date
Mathew Inwood
55418eada5 Limit access to suspected false positives.
Members modified herein are suspected to be false positives: i.e. things
that were added to the greylist in P, but subsequent data analysis
suggests that they are not, in fact, used after all.

Add a maxTargetSdk=P to these APIs. This is lower-risk that simply
removing these things from the greylist, as none of out data sources are
perfect nor complete.

For APIs that are not supported yet by annotations, move them to
hiddenapi-greylist-max-p.txt instead which has the same effect.

Exempted-From-Owner-Approval: Automatic changes to the codebase
affecting only @UnsupportedAppUsage annotations, themselves added
without requiring owners approval earlier.

Bug: 115609023
Test: m
Change-Id: Ia937d8c41512e7f1b6e7f67b9104c1878b5cc3a0
Merged-In: I020a9c09672ebcae64c5357abc4993e07e744687
2018-12-28 14:26:35 +00:00
Mathew Inwood
45d2c252b1 Move some members to the "Q blacklist".
Based on some analysis, these fields/methods are likely false positives.
Set maxTargetSdk=P so that any apps using them are required to migrate off
them in future. See the bug for more details.

Exempted-From-Owner-Approval: Automatic changes to the codebase
affecting only @UnsupportedAppUsage annotations, themselves added
without requiring owners approval earlier.

Bug: 115609023
Test: m
Merged-In: I719b5c94e5b1f4fa562dd5d655953422958ad37e
Change-Id: I719b5c94e5b1f4fa562dd5d655953422958ad37e
(cherry picked from commit 8c854f86a4)
2018-10-22 17:28:24 -07:00
Yohei Yukawa
13a9ffba01 Let SoftInputWindow handle BadTokenException
After several attempts [1][2], this is our latest attempt to
gracefully ignore BadTokenException an IME that is being destroyed is
still handling pending showSoftInput() requests.

The point is that SoftInputWindow is a hidden API. This means that
instead of adding a bunch of try/catch blocks around mWindow.show() in
InputMethodService we can always override SoftInputWindow#show() to
inject our own code around mWindow.show().

With this CL, we can now fully track the internal lifecycle of
SoftInputWindow in SoftInputWindow#mWindowState.  It enables us to
easily sort out cases like double fault cases discussed
in Bug 113159114, where showSoftInput() requests were queued multiple
times and still IMEs crash because what mWindow.show() throws for
the 2nd failure is IllegaStateException not BadTokenException.

 [1] Id1e5f236f48c8ef01b7f157ba3f6e7ab2c26b135
     6fcbb56290
 [2] I2c21573cf972145ab08e66604cdb9344139a3f31
     e4bbb1cc45

Fix: 113159114
Test: Manually verified IME switching scenario as follows.
  1. Build and flush aosp_taimen-userdebug
  2. make -j SoftKeyboard
  3. adb install -r $OUT/system/app/SoftKeyboard/SoftKeyboard.apk
  4. adb shell ime enable com.example.android.softkeyboard/.SoftKeyboard
  5. Open the Dialer app and tap the top edit field.
  6. Make sure that AOSP Keyboard is shown.
  7. Tap the globe button on AOSP Keyboard.
  8. Make sure that AOSP Keyboard is dismissed and SoftKeybaord is
     shown.
  9. Tap the globe button on SoftKeybaord.
 10. Make sure that SoftKeybaord. is dismissed and AOSP Keyboard is
     shown again.
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Change-Id: I1f51ed29df6b22b003ca285698e06b8f3ee5106a
2018-08-29 19:56:02 -07:00
Mathew Inwood
a1c24bf8af resolve merge conflicts of d609a40342 to stage-aosp-master
Bug: None
Test: I solemnly swear I tested this conflict resolution.
Change-Id: I0049d94802b5e6801789e733847be4cfdabb0040
2018-08-06 10:14:20 +01:00
Mathew Inwood
6be794927b Add @UnsupportedAppUsage annotations
For packages:
  android.inputmethodservice

This is an automatically generated CL. See go/UnsupportedAppUsage
for more details.

Exempted-From-Owner-Approval: Mechanical changes to the codebase
which have been approved by Android API council and announced on
android-eng@

Bug: 110868826
Test: m
Change-Id: I4b417b8257486fbdaa3b0f54a02ab70696d199e0
2018-07-31 14:49:38 +01:00
Tarandeep Singh
d59c695a78 Stop using unsupported Canvas operations in IME
KeyboardView relies on deprecated Canvas#clipRect(Rect, Op.REPLACE).
This method is now unsupported and throws runtime exception.
Operations other than Difference and Intersect are unsupported.
This method call can be replaced by saving initial Canvas and calling
intersect operation of Canvas#clipRect(Rect).
Saving initial state can be achieved using Canvas.save() and
Canvas.restore().

Fixes: 79777033
Test: Manually verified with SoftKeyboard (which uses KeyboardView)
1. m SoftKeyboard
2. Set current keyboard to SoftKeyboard
3. SoftKeyboard runs fine
Test: Tested Canvas.getClipBounds() is consistent across save() &
.restore() operations

Change-Id: Id34c289f152b2ec06f37fffa9f940a909153447c
2018-05-22 19:10:20 +00:00
Yohei Yukawa
386f50e04f Add IMS#BACK_DISPOSITION_ADJUST_NOTHING
This is a follow up CL to our previous attempt [1] to make
InputMethodService#setBackDisposition() work and make sense.

Based on the feedback from several IME developers, we learned that
InputMethodService#setBackDisposition() is still confusing.

My conclusion is that trying to reuse existing flags was a mistake.
Here are the rationale for deprecating those two flags.

 * BACK_DISPOSITION_WILL_NOT_DISMISS

   This flag had never been used until we started using it in our
   previous CL [1].  However, it turns out that what this flag means
   is hard to understand because its JavaDoc only says
      "This input method will not consume the back key."
   To address the original goal of Bug 38513361, we can (and should)
   introduce a new flag rather than reusing this confusing flag.
   Deprecating this flag should have no impact because it had never
   been used.

 * BACK_DISPOSITION_WILL_DISMISS

   On pre-P devices IME could abuse this flag to override the back
   button to "dismiss" mode even after IME lost the focus.  On the
   other hand, as far as we know there is no good use case for this
   flag.  Hence rather than trying to fix such an abuse scenario, we
   should just deprecate this flag.

Instead, a newly introduced flag BACK_DISPOSITION_ADJUST_NOTHING
should be sufficient to achieve the original goal of Bug 38513361.
This flag does not rely on the concept "dismiss" and key event
handling hence it would be much easier to maintain.

 [1]: I99e7c413fe1a93f8d8cff897b5c5f0947690d2c0
      3fecef119e

Fix: 74403102
Test: atest CtsInputMethodTestCases
Change-Id: I064209c40da79fffb2627e8f580818a793017b1f
2018-03-14 23:42:21 +00:00
Tarandeep Singh
4513699583 Make few of the new IMS API methods final
d8d03a8e1b added new methods to
InputMethodService.
Allowing IME developers to override some of these methods would introduce
unnecessary complexity. Making these methods final makes sure developers
cannot inject some unexpected behavior when called by system.

Bug: 73701052
Test: atest InputMethodServiceTest
Test: atest CtsInputMethodServiceHostTestCases
Change-Id: I1af4ed05a0b7306d840a21129e921a57b4a5fc33
2018-03-08 19:25:38 +00:00
Tarandeep Singh
164cfba536 IME API: rename IMS methods.
Incorporating API Review feedback:
* Use IMS.switchInputMethod(id) instead of IMS.setInputMethod()
* Use IMS.switchInputMethod(id, subtypeId) instead of
  IMS.setInputMethodAndSubtype()
* Renamed switchToLastInputMethod() to switchToPreviousInputMethod()

Bug: 73954137
Test: atest InputMethodServiceTest
Test: atest CtsInputMethodServiceHostTestCases
Change-Id: I6efd5ca473e33e6faeadb7eea7772b9d2b8ca12b
2018-03-06 02:23:15 +00:00
tiansiming [田思明]
f96309e812 Merge "Modify javadoc for onWindowShown" am: 2d46e07e48 am: d5d1718c4a
am: b95b38ca3a

Change-Id: I04bbf26857e60a1129c6947cb91fffef2c939edf
2018-02-09 06:51:32 +00:00
tiansiming [田思明]
b95b38ca3a Merge "Modify javadoc for onWindowShown" am: 2d46e07e48
am: d5d1718c4a

Change-Id: I82c1c9a4601e579b34e6f8c40f80258b78a8a7d8
2018-02-09 06:39:54 +00:00
tiansiming [田思明]
b9025932bc Modify javadoc for onWindowShown
onWindowShown is more like it should called after mWindow.show()
in InputMethodService. Considering the compatibility problem, just
make its javadoc clearer to the IME developers rather than
change the calling order.

Bug: 72922821
Test: N/A

Change-Id: Ibfe20f40a65475f39c8e79d10e2c494e212cf054
Signed-off-by: tiansiming [田思明] <tiansiming@xiaomi.com>
2018-02-07 15:40:07 +00:00
Jon Dormody
8ea40cf752 Merge "Docs: Inserting a line to include the documentation for keyPreviewHeight." into oc-mr1-dev am: 7b3c924114
am: afb592c4bf

Change-Id: I2276021c9c2ae453add4e139b677dcfe7e71facd
2018-01-29 19:52:56 +00:00
Tarandeep Singh
3fecef119e Make IMS.setBackDisposition() work.
InputMethodService.setBackDisposition() has been broken from a long
time. This is how setBackDisposition() is supposed to work
1. BACK_DISPOSITION_WILL_DISMISS:
When Keyboard is visible back button will show as down arrow (in
navigation bar) and tapping it will dismiss keyboard.
2. BACK_DISPOSITION_WILL_NOT_DISMISS:
When keyboard is visible, back button will be shown as BACK arrow and
tapping it will send the back event to current activity. If activity
doesn't handle onKeyDown() for back button, activity will finish and
keyboard will hide.

Note: backDisposition flags reset when finishInput() is called.

Bug: 38513361
Test: Manual with apk attached in bug
Test: atest InputMethodServiceTest
Change-Id: I99e7c413fe1a93f8d8cff897b5c5f0947690d2c0
2018-01-23 14:56:06 -08:00
Jonathan Dormody
bfaf862130 Docs: Inserting a line to include the documentation for
keyPreviewHeight.

Test: make ds-docs

Bug: 68838052
Change-Id: I25c58d2cfd2fe3637edcd6962202e5b0d1632e0e
2018-01-22 15:49:04 -07:00
TreeHugger Robot
4ae9eacc84 Merge "Unhide InputMethodService#requestShowSelf()" 2018-01-16 16:10:53 +00:00
Yohei Yukawa
fbc2f7acd5 Unhide InputMethodService#requestShowSelf()
This is a follow up CL to a recent CL [1], which aimed to move several
APIs only for InputMethodService from InputMethodManager to
InputMethodService.

This CL removes InputMethodService#hideSoftInputFromInputMethod(),
which is exactly the same as InputMethodService#requestHideSelf() that
is already available as a public API for IME developers.

This CL also virtually renames
InputMethodService#showSoftInputFromInputMethod() to
InputMethodService#requestShowSelf(), which has existed as a
private method but not been exposed to IME developers yet.

 [1]: I3163f3cbe557c85103ca287bee0874a3b4194032
      d8d03a8e1b

Bug: 70282603
Test: atest CtsInputMethodTestCases
Change-Id: If6a786c5774805d041ea9672ef2721e4a38df7fc
2018-01-16 08:09:11 -08:00
TreeHugger Robot
2bb444136a Merge changes I30b40c48,I7d02c54c,Id68ebd35
* changes:
  Use lambda when appropriate
  Remove redundant type casts
  Fix JavaDoc errors
2018-01-15 02:19:15 +00:00
Yohei Yukawa
623e94b857 Use lambda when appropriate
This is a safe refactoring that should have no behavior change in
terms of semantics and performance characteristics.

Test: make -j checkbuild
Change-Id: I30b40c483e490ff42c1c707233ca5cc7b67da28f
2018-01-14 16:30:59 -08:00
Yohei Yukawa
31a260f144 Remove redundant type casts
Test: make -j checkbuild
Change-Id: I7d02c54c09543848711c1f3204719a79593a3cbd
2018-01-14 16:24:26 -08:00
Yohei Yukawa
2b63434b93 Follow method renamings
This is a follow up CL to a recent CL [1], which deprecated several
APIs InputMethodManager class but forgot to update some of existing
call sites in InputMethodService to use new method names.

This CL only addresses deprecated API usage warnings.  There should be
no behavior change.

 [1]: I3163f3cbe557c85103ca287bee0874a3b4194032
      d8d03a8e1b

Bug: 70282603
Test: atest CtsInputMethodTestCases
Change-Id: I709ca997523ac9a9cd2d236f3158bbb18cf2edc3
2018-01-14 16:15:31 -08:00
Yohei Yukawa
b2a0e0509a Fix JavaDoc errors
Test: make -j checkbuild
Change-Id: Id68ebd3588cd286c821da49e3bda4299d311e8b9
2018-01-14 16:06:16 -08:00
Yohei Yukawa
8f162c6e84 DecorView#mNavigationGuard is gone
With this CL, DecorView#mNavigationGuard that handles navigation bar
only for IME windows [1] is finally gone and replaced with the
standard mechanism to handle navigation bar layout padding /
background color.

This CL addresses multiple anomalies regarding how the following APIs
work for IME windows.

 * Window#setNavigationBarColor()
   * Previous behavior:
    - Only works for Color#TRANSPARENT [2].
    - Ignores FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS.
   * New behavior:
    - Works as documented.
    - Requires FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS to work.

 * SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION flag
   * Previous behavior:
    - The system automatically sets
      SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION to the IME windows [3].
    - Does not work as documented. Content area is not extended to the
      navigation bar area.
    - Manually unsetting SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION can cause
      unexpected layout, because the system expects that this flag is
      always set to the IME window.
    - Had a special logic for FLAG_LAYOUT_IN_OVERSCAN [4].
   * New behavior:
    - Works as documented.
    - Can set/unset as necessary.

From the viewpoint of IME developers, this CL enables IME windows to
 * correctly extend the input view to the navigation bar region by
   using SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION as documented, instead of
   relying on a special hack with FLAG_LAYOUT_IN_OVERSCAN hack.
 * use Window#setNavigationBarColor() to easily change the navigation
   bar background color, like other non-floating windows.

Note that SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR is not yet supported for
IME windows, which will be implemented in a subsequent CL.

 [1]: I6a93f30aec83f1cecfb854073046cbc87ab4aa66
      ae3349e1c3
 [2]: Iea77915ecc55eedaf19899e72c44f704ba9d852c
      0a9d1ea015
 [3]: I460912ee7c117480c57b947ed31eca330819f32c
      c68d577f29
 [4]: Ic38f204a892bf34e8dae65990d5aa8c95af555d8
      9b32a35aa7
 [5]: I4b10a19641bd3ce6c43e7629404b6f202d4186e8

Fix: 25706186
Bug: 69002467
Test: ThemedNavBarKeyboard sample [5] works for the following cases
      * Extended Dark Navigation Bar
      * Separate Dark Navigation Bar
      * Floating Mode (if the target app uses dark navigation bar)
Change-Id: I664630099b6eb3fe31675444ba94944cb0eb98b0
2018-01-10 13:18:09 -08:00
Tarandeep Singh
d8d03a8e1b Move IME related API methods from IMM to IMS.
InputMethodManager is public InputMethod API for apps. The methods
that take Window-token as parameter are restricted to system
and/or IME developers. Such methods should really live
in InputMethodService.
This CL deprecates such methods in IMM and moves them to IMS.

This is the first step towards simplifying IME APIs.

Bug: 70282603
Test: atest InputMethodManagerTest
Change-Id: I3163f3cbe557c85103ca287bee0874a3b4194032
2017-12-08 10:40:38 -08:00
Eugene Susla
d4128ec0df Revert "Don't generate irrelevant a11y events - framework"
This reverts commit 8ddfb4794f.

Test: presubmit
Bug: 69975306
Change-Id: I05cb545eb0adc77298dddf2dea2997ef36b58a5f
2017-12-05 13:08:51 -08:00
Svet Ganov
8ddfb4794f Don't generate irrelevant a11y events - framework
Now before we fire an a11y event we check if this event has an
observer. As a bonus we don't push the state to clients if the
dynamic service config did not change.

Test: cts-tradefed run cts-dev -m CtsAccessibilityServiceTestCases

bug:69427760

Change-Id: Ie208e13b8557bb7a120198a43efcb79c2752f5db
2017-11-28 17:58:38 -08:00
Tarandeep Singh
1d113d041f Skip blocking InputConnection APIs after unbind
InputConnectionWrapper has several synchronous methods which have a
timeout. If the application's UI thread hangs, all these synchronous
methods are blocked and IME stays on-screen.

This CL aims to improve the responsiveness of IMEs by rejecting
any blocking calls of InputConnection APIs once
IInputMethod#unbindInput() is issued by InputMethodManagerService
(IMMS).

Currently #unbindInput() is issued only from
IMMS#unbindCurrentClientLocked(), which basically means that the
previous application is losing the IME focus.

Underlying #onUnbindInput() signal is still immediately delivered
to the IME process, but it's just waiting to be consumed on the UI thread.
Hence in theory we can change the behavior of InputConnection seen
from the IME once the signal is delivered to the IME process.

This CL does not interrupt already blocked API calls, which is one of
future work for this scenario. This CL relies on:

 A. IInputMethod is marked as oneway
 B. IMMS guarantees that IInputMethod#bindInput() and
     IInputMethod#unbindInput() are always paired without nesting,
     and IInputMethod#startInput() is called 0 or more times only
     during that pair.

In this case, the system guarantees that IInputMethod methods
will be called back in the IME process in the same order, and only
one IPC thread is handling those IPCs at the same time. See the
JavaDoc of IBinder#FLAG_ONEWAY for details.

Bug: 36897707
Test: Manual: using the apk in the linked bug:
1. Make sure that a valid InputConnection is established between
   the test app and a test IME.
2. Let the test app start blocking the UI thread.
3. Let the test IME call InputConnection#getTextBeforeCursor()
   three times.
4. Tap the Home button on the NavBar.
5. Make sure that the test app is immediately dismissed.
6. Make sure that InputConnection#getTextBeforeCursor() starts
   returning immediately, once after the initial call was timed-
   out after 2 sec (InputConnectionWrapper#MAX_WAIT_TIME_MILLIS)

Change-Id: I0f816c6ca4c5c0664962432b913f074605fedd27
2017-10-19 17:55:41 -07:00
Yohei Yukawa
930328ca97 Annotate threads for some IME handling methods
This is a preparation to work on Bug 36897707.

For instance, the reason why most of IME-related callbacks in
InputMethodService get called on the main thread is because
IInputMethodWrapper keeps forwarding incoming IPCs into the
main looper of the IME process as follows:

  InputMethodManagerService (IMMS)
        ------
    -> one-way binder IPCs over	IInputMethod
        ------
      -> IInputMethodWrapper (on the binder thread(s))
       -> Handler (to dispatch tasks to main thread)
        -> InputMethodImpl.* (on the main thread)
         -> InputMethodService.* (on the main thread)

By adding explicit annotations such as @BinderThread and @MainThread
in relevant methods, this CL makes that kind of investigation much
easier than before.

Bug: 36897707
Test: compile
Change-Id: I8f9afe9a1986a9fa41fb66fdc64e8f0f67e45c2e
2017-10-18 20:19:53 -07:00
Yohei Yukawa
16f0407708 Add missing JavaDoc for IMS.InputMethodImpl
Bug: 36897707
Test: checkbuild
Change-Id: If1f7cfbfe333f30468d551e8a92bba9f987e8a06
2017-10-18 20:19:43 -07:00
Yohei Yukawa
6f0bf747eb No-op code cleanup for IInputMethodWrapper
This CL is a safe and no-op code clean-up, including dead code removal.
There should be no behavior change.

Test: continuous tests
Bug: 36897707
Change-Id: I4a1ad9cb764c7ba82b32e325c4a4b1c8e7296bbf
2017-10-18 20:19:33 -07:00
Tarandeep Singh
e1cfcf4c4d Fix keyboard focus in VR
Consider this VirtualDisplay (VD) scenario:
HostActivity creates a VD which holds SettingsActivity. When EditText
on SettingsActivity is tapped, it gains focus.
On eventual taps, it loses focus i.e. the Window in VD loses focus and
the host activity in primary display gets the focus instead. This
happens because WM's TaskTapPointerEventListener.onPointerEvent()
is called on the default display only.

Root cause:
1. Tap detector isn't registered for non-default display.
2. Tap detector has no info on which displayId touch was received.
3. InputFlinger doesn't deliver InputMonitor events for
non-default displays (fixed in a separate CL)

Fixing above results in onPointerEvent(MotionEvent) to deliver the
Touch events successfully to VD. We restrict these changes to physical
multi-displays and VR VirtualDisplays (which uses virtual touch device).
[VrManagerService calls WMInternal.setVr2dDisplayId(int)]

In future, displayId should be part of InputEvent. Bug: 64258305

Bug: 62033391
Test: bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests
Change-Id: I3626f4de5aa9bcf905da9abd39f3ab1baefc4c48
2017-08-02 10:46:22 -07:00
Alan Viverette
51efddbd3b Remove unnecessary casts on calls to findViewById
Just frameworks/ this time. More paths to come.

Bug: 24137209
Test: make -j32
Change-Id: Iff27abd26fa43296ac2fff8f534fc6742d2ae80c
2017-04-14 11:15:50 -04:00
Mark Renouf
270e4953d2 Corrects CompactExtractEditLayout to account for systemWindowInsetBottom am: d1a0d19794
am: 8f9a6c3e89

Change-Id: I10087b9982b3eceb200b447d4faecad4eb8d19fe
2017-03-31 15:20:24 +00:00
Mark Renouf
d1a0d19794 Corrects CompactExtractEditLayout to account for systemWindowInsetBottom
Percentage-base sizes involving screen height are incorrect for watch
devices with non 1:1 display metrics. These are round screens with an
inactive bottom portion. To maintain the correct proportions the
bottom inset must be added to the height.

BUG: 36728475
Change-Id: Ibe351d1db7964b4b89ce9a588c171cd8407e2a50
2017-03-30 15:01:55 -04:00
Phil Weaver
385912ee2d Deprecate "speak passwords" setting.
This will now be controlled by individual accessibility services.
We'll provide the password information to them, and they can
present or hide the information as it makes sense for their users.

Password information was anyway provided when a headset was
connected.

Bug: 28139568
Test: Manually verified that TalkBack now speaks passwords on the
lock screen and in text views. Since I'm removing functionality
that didn't have tests, it's tricky to have specific tests.
Change-Id: Ic3c724ccce5762ee9dcd9e7dcbd4eae6734dd05e
2017-02-21 15:24:54 -08:00
Yohei Yukawa
4e28668a15 Fix duplicate calls of IMS#doStartInput()
This is another follow up CL to my previous CL [1], which had a bug
that InputMethodService#doStartInput() is now always called back twice.

There was a careless mistake when rebasing the CL [1] onto the previous
CL [2], which ended up with dispatching startInput() twice in
IInputMethodWrapper.

In short, InputMethod#dispatchStartInputWithToken() is the new way to
dispatch startInput()/restartInput(). We do not need to call both of
them.

 [1]: I9921b381e02106dbffff5e0b3d13f0a1245ce807
      6db3bfe33d
 [2]: I476d0cf8cbb0a0134941854f9337d9ad15e66a71
      f7526b5896

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 only once.
      5. Type "aaaa" then hit "CONTINUE" button.
      6. Make sure restartInput() gets called only once.
Bug: 35079353
Fixes: 35442939
Change-Id: Ifde16c3fad5b787d4c9a11bd886943dfe96f9eb9
2017-02-16 17:19:00 -08:00
Yohei Yukawa
6db3bfe33d 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
2017-02-13 12:04:41 -08:00
Yohei Yukawa
f7526b5896 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
      1a5838e966

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
2017-02-11 20:57:10 -08:00
Yohei Yukawa
3eaf867487 Revert "Merge restartInput into startInput in internal IPC"
This reverts commit 1a5838e966 [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
2017-02-11 23:42:15 +00:00
Yohei Yukawa
1a5838e966 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
2017-02-11 02:56:48 +00:00
Yohei Yukawa
2bc66171cc 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
      1544def0fa

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
2017-02-09 00:51:18 +00:00
Yohei Yukawa
d033283508 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
2017-02-01 13:59:43 -08:00
Elliot Waite
0ce4b0e4c3 Fix @links in reference docs. am: 54de77470d am: ab978c035e am: 28ba4722a9
am: 9b21265b2c

Change-Id: If246ebdb36cf2832d5a6c42cbe752e290b6fb6e8
2017-01-26 04:49:33 +00:00
Elliot Waite
54de77470d Fix @links in reference docs.
Change-Id: I40cea46efd80c448640ff69753698fe8404da40b
2017-01-25 17:00:55 -08:00
Yohei Yukawa
ac0211a478 Update JavaDoc for IMS#enableHardwareAcceleration
This makes it clear that on Android L+ devices IME developers basically
no longer need to call InputMethodService#enableHardwareAcceleration(),
because it is deprecated in Android L[1][2].  On L+ devices what IME
developers need to do is to make sure that their IMEs are compatible
with both hardware and software rendering so that the system can choose
the best rendering method.

This is basically a code clean-up that should not change any actual
behavior.

 [1]: I906d48cb07af50fa02dae4f4ecdb5e65211fc6ef
      5e1565ead6
 [2]: I126ea823eb2eeabb29d30999dec9c9411b33b315
      e07b595519

Bug: 31202732
Change-Id: I416669b172737e3eb3d77165dcea50289d207514
2016-09-01 12:41:58 -07:00
Yohei Yukawa
a3fd8bfdfe Merge \"Merge \\"Use a flag to grant a temporary URI permission.\\" into nyc-mr1-dev am: cb56978912\" into nyc-mr1-dev-plus-aosp
am: c58ffb3f9c

Change-Id: Iddc693412d20b86c3a916dd09764d14d23c4fcf4
2016-06-27 20:34:58 +00:00
Yohei Yukawa
45700fa135 Use a flag to grant a temporary URI permission.
It turns out that we can let the system to call
InputMethodService#exposeContent(InputContentInfo, EditorInfo), which
added in my previous CL [1], during the IME is calling
InputConnection#commitContent() as follows.

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

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

This gives us flexibility to let InputConnection#commitContent() do all
the magic for IME developers like other APIs such as
Context#startActivity(), rather than asking them to call one more API to
grant a temporary URI permission like a scenario where
Context#grantUriPermission() is used.

 [1]: I2772889ca01f2ecb2cdeed4e04a9319bdf7bc5a6
      25e0813e6e

Bug: 29450031
Change-Id: I99536cd58c9984af30b0bafb4a1dd25a26634a2d
2016-06-23 17:12:59 -07:00
Yohei Yukawa
bf055ba658 Merge \\"Add InputMethodService#exposeContent()\\" into nyc-mr1-dev am: dc42d7dd13
am: d02470f5a8

Change-Id: Id551d53ae3d7c34157ddf166aa44bdef67d46853
2016-06-23 01:37:10 +00:00
Yohei Yukawa
25e0813e6e 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
      152944f490
 [2]: Ica1ba3154795c1bf44e140dfe639b299f83cd8af
      adebb52588

Bug: 29450031
Change-Id: I2772889ca01f2ecb2cdeed4e04a9319bdf7bc5a6
2016-06-22 16:31:41 -07:00
Aurimas Liutikas
514c5ef8d5 Add missing @Deprecated annotations.
Add missing @Deprecated annotations for methods with @deprecated tag
in javadoc.

Change-Id: I35b78ccb97832d86b914c21a300444ba29e33844
2016-05-24 15:22:55 -07:00