Commit Graph

229 Commits

Author SHA1 Message Date
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
Yohei Yukawa
833bdcedce 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
      2977eb7b6c
 [2]: I5723f627ce323b0d12bd7b93f5b35fc4d342b50c
      792faa2c16

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
2016-05-15 20:05:56 -07:00
Yohei Yukawa
d0d0797474 Fix a behavior change in "Show software keyboard".
This bug was a corner case of stopping lying about
Configuration#keyboard when "Show software keyboard" is turned on, which
was done by my CL [1] in Android N development cycle.

Previous implementation

  if (config.keyboard != Configuration.KEYBOARD_NOKEYS) {

had relied on the fact that the system was lying about config.keyboard,
which is no longer valid.  We need to change the behavior of
InputMethodService#onShowInputRequested() depending on
Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD like we did for
InputMethodService#onEvaluateInputViewShown() in [1] to minimize the
impact on stopping lying about Configuration#keyboard.

 [1]: Id4d332e3909590c68345e10e1f2e18650efb2eb7
      7b739a802c

Bug: 28423439
Change-Id: I8a774cbf61ac706d8446be91b17bceee57a13656
2016-05-04 11:56:35 -07:00
Mark Renouf
91eb2651a0 Customizes input extract edit view for Wear
Provides an alternate presentation of the extract edit area
of an input method window, designed for sub 250dp width screens.

An icon is used on a round material style button in place of a text
action, providing more horizontal space for the editing area.

BUG: 28098677
(cherry picked from commit fd71a6a5d99bad5d3ab32edc328fb5b026b66215)

Change-Id: I0e559d17f78d1a48b37979a49e11ae1aad7503f4
2016-04-12 15:05:13 +00:00
Yohei Yukawa
757224008e Revert "Customizes input extract edit view for Wear"
This reverts commit 880602eb64 [1],
which was committed with a wrong author email address and lacked license
notice in some files.  To avoid confusion, this we decided to
temporarily revert that CL so that we can commit it with proper license
notice and author address again.

 [1]: I16226ce393f2d15065d08e66a36d008eb1a0c8a1

Bug: 22512982
Bug: 28098677
Change-Id: I3dd3c7bf0ee9634fc4f3bf433bf5023675873e46
2016-04-09 15:24:02 -07:00
Mark Renouf
880602eb64 Customizes input extract edit view for Wear
Provides an alternate presentation of the extract edit area
of an input method window, designed for sub 250dp width screens.

An icon is used on a round material style button in place of a text
action, providing more horizontal space for the editing area.

BUG: 22512982
Change-Id: I16226ce393f2d15065d08e66a36d008eb1a0c8a1
(cherry picked from commit fd71a6a5d99bad5d3ab32edc328fb5b026b66215)
2016-04-08 16:56:25 -04:00
Yohei Yukawa
2dbc532429 Fix a regression in SHOW_IME_WITH_HARD_KEYBOARD handling.
This is a follow up CL to my previous CL [1], which caused a regression
that LatinIME does not correctly initialize its UI when:
  1. Make sure SHOW_IME_WITH_HARD_KEYBOARD is off.
  2. Pair a hardware keyboard.
  3. Reboot.
  4. Make sure the hardware keyboard is paird.
  5. Focus in a text box.
  6. Make sure that LatinIME does not show software keyboard.
  7. Tap the IME switcher and turn of "Show Input Method" toggle.

Previously IMS had called many methods from
IMS#onConfigurationChanged(), which was just replaced with
IMS#restartInput() by my CL [1] then broke some assumptions in LatinIME.
This could also break other IMEs' assumptions as well.

To avoid unexpected regressions between M and N like this, this CL
ensures that those methods are called as we have done until [1].

 [1]: Id4d332e3909590c68345e10e1f2e18650efb2eb7
      7b739a802c

Bug: 26985193
Change-Id: Iebd98f26d388b64cb318ac202b3bcdd956bd3a27
2016-04-06 05:47:14 +00:00
Yohei Yukawa
ef5b4657a8 Fix a bug that IMS#mShowInputFlags is never updated.
As a preparation to fix bug 26985193, this CL fixes a bug that
IMS#ShowInputFlags is never updated.  As a result,
IMS#onConfigurationChanged() has always called
IMS#onShowInputRequested() with specifying 0 to flags parameter, which
is wrong.

With this CL, we can assume that IMS#mShowInputFlags keeps tracking the
last value when it should do.  Also, we can remove IMS#mShowInputForced
since it is now determined by IMS#mShowInputFlags.

Bug: 26985193
Change-Id: Ieff634b69ce941d78ffe208547f7edd19ea28643
2016-04-03 22:50:11 -07:00
Yohei Yukawa
1064d35307 Merge "Tell IMS about missing InputConnection methods." into nyc-dev 2016-03-19 00:36:22 +00:00
Yohei Yukawa
19a80a1e80 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
2016-03-15 06:43:39 +00:00
Keisuke Kuroyanagi
755c0095a1 Fix: onExtractedDeleteText deletes unintended region.
InputMethodService#onExtractedDeleteText doesn't reset composing
region and InputConnection#deleteSurroundingText deletes text around
the composing region. As a result, #onExtractedDeleteText can delete
unintended region of the text.
This happens when a user perform Drag&Drop or tap "Delete" in
SuggestionsPopup in full screen extracted mode.

Bug: 22440907
Bug: 27536702
Change-Id: I875f2919896f8ff453a77fb4a1b642ad78079b78
2016-03-14 19:09:20 +09:00
Yohei Yukawa
cf8403bc36 Suppress NPE in IMS#onEvaluateInputViewShown().
This is a follow up CL for the previous commit [1], which may have
triggered an unknown bug in either Android Framework or LatinIME.

  [1]: Id4d332e3909590c68345e10e1f2e18650efb2eb7
       7b739a802c

InputMethodService#mSettingsObserver is initialized in #onCreate() and
cleard with null in #onDestroy().  Hence hitting NPE against it implies
that InputMethodService#onEvaluateInputViewShown() can be called before
InputMethodService#onCreate() or after InputMethodService#onDestroy().
Both possibilities are equaly problematic.  Note that this might be a
long-standing issue that just became obvious because of [1].

This CL does not attempt to fix the root cause but just tries to
suppresses the NPE to unblock QA tasks.  A proper fix should be made in
subsequent CLs.

Bug: 22517687
Bug: 26511607
Change-Id: I6bc87c3d18b560fe2253fb9f05557b95b04d0cf0
2016-01-12 12:17:42 -08:00
Yohei Yukawa
7b739a802c Stop lying about hardware keyboard presence.
Here is a brief history of "Use Physical Keyboard", or "Show input
method", or SHOW_IME_WITH_HARD_KEYBOARD.

In Honeycomb, we introduced a mechanism which allows users to temporary
disconnect the physical keyboard connection from a UI [1].  That state
was temporary and non-persistent, but it was implemented to have
system-wide effect.  Whenever the user turned on that temporarily
disconnected state, not only IMEs but also other processes would be
notified that Configuration#keyboard was changed to KEYBOARD_NOKEYS.
The UI to do that was available only in tablet UI at that point and
nothing changed in phones.

In JellyBean, we decided to port that UI to phone, and the "Use Physical
Keyboard" toggle switch found its new home on the IME switcher
dialog [2].

In Lollipop, we revised the wording for the toggle switch on the IME
switcher dialog.  Now it's labeled as "Show input method" [3].

In Lollipop, we also decided to make the settings of "Show input method"
to be persistent as @hide entry in the secure settings [4].

  [1] 2992ea782f
      I136087ca4f726d0068d5983d7d3686787ba60c55
  [2] cb598b11ea
      (Ica768083f95c33dc1e494a28ba7d8b6eb989b0ef)
  [3] be11f3a5cea67c68a08c8da9ce85b3418501060a
      (I9c8a7eb98b5277f1d09cc19fa7402e9b4cf51d92)
  [4] b64e56aad3ffb267aec44308f57641a4c91caa83
      (I2237ded850a0d4ab43ca441d0b7df13e0958e630)

Now, we have hard time making everyone happy.  Having an easy way to
bring software keyboard back is probably still a valid use case, but
after several wording changes it is no longer obvious why
onConfigurationChanged() event is sent to all the processes as a
consequence of tapping that toggle.

In order to address above confusions, this CL removes the concept of
"temporarily disconnected physical keyboard" but tries to implement
"Show input method" functionality in InputMethodManagerService and
InputMethodService to keep the affordance that has been offered in the
IME switcher dialog.  As long as the IME overrides
InputMethodService#onEvaluateInputViewShown() as follows, the behavior
of "Show input method" toggle remains the same except for processes
including IMEs no longer receive onConfigurationChanged() event with
faked Configuration#keyboard value.

  @Override
  public boolean onEvaluateInputViewShown() {
      // If the default implementation returns true, recommend honoring
      // it.
      if (super.onEvaluateInputViewShown()) {
          return true;
      }

      // Implement the logic that is specific to your IME here.
      return myOnEvaluateInputViewShown();
  }

Bug: 22517687
Change-Id: Id4d332e3909590c68345e10e1f2e18650efb2eb7
2015-12-21 13:30:44 -08:00
Clara Bayarri
5ba31aa77d Fix crash in KeyboardView with null Handler
A recent change in how the handler is created in KeyboardView
caused the password change flow to crash in ChooseLockPassword.

Change-Id: Id5fcb256f9a09b75bf91c5c79614d8abfc29747f
2015-10-23 14:27:40 +01:00
John Reck
d0374c6b25 Fix a few view ctors to not call Looper.myLooper
Bug: 25116730
Change-Id: I4e394c281feef6f7987433298d66f2df11352416
2015-10-20 14:20:33 -07:00
Yohei Yukawa
6fcbb56290 Handle BadTokenException exception more reliably.
This is a follow up for I2c21573cf972145ab08e66604cdb9344139a3f31, which
added BadTokenException handler so that we can deal with unavoidable
runtime exceptions. However, it turns out that CL does not work well
in a certain case.

One problem in I2c21573cf972145ab08e66604cdb9344139a3f31 that it added
the exception handler in the call site of
InputMethodService#showWindow(boolean) rather than callee side as
follows.

    try {
        showWindow(true);
    } catch (BadTokenException e) {
        if (DEBUG) Log.v(TAG, "BadTokenException: IME is done.");
        mWindowVisible = false;
    }

However, the above code fails to update #mWindowVisible if an IME
overrides InputMethodService#showWindow(boolean) but catch-and-ignore
BadTokenException as follows.

    @Override
    public void showWindow(boolean showInput) {
        try {
            super.showWindow(showInput);
            // Do something if super.showWindow() succeeds.
        } catch (BadTokenException ex) {
            // Do something if super.showWindow() fails.
        }
    }

With this CL, InputMethodService#mWindowVisible is always updated in
the callee side whenever it should be.

Note that this CL does not change anything about which method can
throw BadTokenException and which method catch-and-ignores it so as
not to break existing IMEs unexpectedly.

Bug: 23798142
Change-Id: Id1e5f236f48c8ef01b7f157ba3f6e7ab2c26b135
2015-09-14 16:48:15 -07:00
Yohei Yukawa
686e03454b Merge "Mechanical merge of nested if statements." 2015-09-14 03:50:22 +00:00
Yohei Yukawa
24182f3dac Remove redundant casts.
This Cl is just a mechanical removal of redundant casts.
Nothing is changed logically.

Bug: 22285167
Change-Id: I460b781753553c002b6cd232ae5918b7acd616d9
2015-09-11 18:33:33 -07:00
Yohei Yukawa
ac8bdd203c Mechanical merge of nested if statements.
This is just a mechanical merge of nested if statements with a dead code
removal.  Nothing is changed logically.

Bug: 22285167
Change-Id: I28c1de84635b68108b25ec32ec58de2128758512
2015-09-11 18:17:11 -07:00
Keisuke Kuroyanagi
2305f99d01 am abe22377: am 7423ca03: am d49c3b65: am 00eb5767: am 437eb6ce: Merge "Fix: Wrong suggestion popup position in extract mode." into mnc-dev
* commit 'abe22377262a2aadbeb3b64d8bc10916b0256d6d':
  Fix: Wrong suggestion popup position in extract mode.
2015-07-21 00:14:50 +00:00
Keisuke Kuroyanagi
fd3eff27bd Fix: Wrong suggestion popup position in extract mode.
Replace text was handled by the original EditText; thus, we
couldn't correctly decide popup window position.
Also, changing selection range replaces entire text of the
extracted EditText. As a result, text cannot be replaced
with the selected item when there is a selection.

This change is a workaround for this issue. This quits
offering "Replace" for selection in extract mode.

Bug: 22038802
Change-Id: I052b027cfd10eeb289f77f4c6b228acf58fea636
2015-07-17 16:36:57 -07:00
Andrei Stingaceanu
e937abe222 am 943b001c: am b9384d5d: am 31ccc9f0: am a7e2ab6e: am 8af7432c: Merge "Fix "Select All" in extracted mode" into mnc-dev
* commit '943b001c80e43d1b36d3f6b8b21673df40942daf':
  Fix "Select All" in extracted mode
2015-07-14 18:47:11 +00:00
Andrei Stingaceanu
a2c1d7841a am 464f4006: am dfa116e2: am 2e59771e: am 0e6360f4: am a9b9907f: Merge "Fix insertion handle disappearing in extract mode" into mnc-dev
* commit '464f40065f0ccd41214733d2a158a035a8b644b6':
  Fix insertion handle disappearing in extract mode
2015-07-14 18:46:57 +00:00
Andrei Stingaceanu
5396c131c0 Fix "Select All" in extracted mode
Stop calling onExtractTextContextMenuItem if "Select All"
is selected (the action does not modify text thus does
not need batch editing). Editor#finishBatchEdit reports
that text changed which in turn can stop the action mode
and the selection after it was started by onPreDraw.

Bug: 22059417
Change-Id: I5354cbe4bae374e0d5f3de39616336170ee33b92
2015-07-14 11:37:28 +01:00
Seigo Nonaka
93c47eab2b Update fullscreen state on hiding window.
Need to update fullscreen state on hiding window as well as showing
window, otherwise IMM#isFullscreenWindow reports obsolete state after
hiding window by back key or device rotation.

Bug: 22238567
Change-Id: Ic8de161cd5d2ee161f32b9942cdc2c331ea4d48e
2015-07-14 15:08:52 +09:00
Andrei Stingaceanu
cfa13a77ed Fix insertion handle disappearing in extract mode
In extract mode, on every screen touch
TextView#setExtractedText gets called which calls
SpannableStringBuilder#sendTextChanged which in turn stops
the action mode. As a fix, if the text is the same only
copy the spans without replacing everything.

Bug: 22315095
Change-Id: I28da760b3dc11e1cfbaf720e547bd817c5b89d7e
2015-07-13 11:14:43 +01:00
Yohei Yukawa
e9311579da am 6a402ca6: am d408d293: am ab142f7f: Merge "Handle back key to cancel text action mode in full-screen IME." into mnc-dev
* commit '6a402ca629185576cf774587da8079977833d25e':
  Handle back key to cancel text action mode in full-screen IME.
2015-06-25 20:16:27 +00:00
Yohei Yukawa
38940aab69 Handle back key to cancel text action mode in full-screen IME.
This CL is a follow up to I7998c8ee2162a0e01525a0cd66ec14fa505,
which completely removed ExtractActionMode including back key
handling in InputMethodService when full-screen mode is enabled.

It turns out that back key events still need to be handled in
InputMethodService when full-screen mode is enabled so that
users can still cancel floating text action mode with back key.

Bug: 22034992
Change-Id: I5f8db34f7425eef343d40d9820925ea6aaf9fccc
2015-06-24 00:20:24 -07:00
Andrei Stingaceanu
ec9e10b74d am 4ca5725f: am 76d2204d: am b1891b3f: Fix selection by double tap in Extracted mode
* commit '4ca5725f95e613a9550f77e4ec155432141a8095':
  Fix selection by double tap in Extracted mode
2015-06-22 13:36:36 +00:00
Andrei Stingaceanu
b1891b3fc9 Fix selection by double tap in Extracted mode
Select with double tap in extracted mode has suffered
a regression recently: flickers and it does not correctly
select. Found this fix after a lot of trials.

Bug: 20128047
Change-Id: I1bbe8c11982d37e5409bac2b648a31b0ca1f0bbc
2015-06-22 12:42:06 +01:00
Yohei Yukawa
5b2a0987fa Fix JavaDoc error in I392166c77cd9dd2c432dc4f1274312f8355de02b.
Fix confirmed with 'make doc-comment-check-docs'

Bug: 21446448
Change-Id: Ica4359b13ddbc790740cc22c95b9e002f7c8e4b8
(cherry picked from commit fd65287cfd)
2015-06-12 04:57:29 +00:00