Skip to content

Commit 6b2c843

Browse files
TreeHugger Robotandroid-build-merge-worker-robot
authored andcommitted
Merge "Revert new logic around FLAG_ALT_FOCUSABLE_IM" into rvc-dev am: 0ef33bc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12059199 Change-Id: I84000632fef10ddf0ec14e82fbcc55eb5e47845e
2 parents 4640bfb + 0ef33bc commit 6b2c843

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

core/java/android/view/WindowManager.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,11 +1454,22 @@ public static boolean isSystemAlertWindowType(@WindowType int type) {
14541454
@Deprecated
14551455
public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000;
14561456

1457-
/** Window flag: When set, input method can't interact with the focusable window
1458-
* and can be placed to use more space and cover the input method.
1459-
* Note: When combined with {@link #FLAG_NOT_FOCUSABLE}, this flag has no
1460-
* effect since input method cannot interact with windows having {@link #FLAG_NOT_FOCUSABLE}
1461-
* flag set.
1457+
/** Window flag: when set, inverts the input method focusability of the window.
1458+
*
1459+
* The effect of setting this flag depends on whether {@link #FLAG_NOT_FOCUSABLE} is set:
1460+
* <p>
1461+
* If {@link #FLAG_NOT_FOCUSABLE} is <em>not</em> set, i.e. when the window is focusable,
1462+
* setting this flag prevents this window from becoming the target of the input method.
1463+
* Consequently, it will <em>not</em> be able to interact with the input method,
1464+
* and will be layered above the input method (unless there is another input method
1465+
* target above it).
1466+
*
1467+
* <p>
1468+
* If {@link #FLAG_NOT_FOCUSABLE} <em>is</em> set, setting this flag requests for the window
1469+
* to be the input method target even though the window is <em>not</em> focusable.
1470+
* Consequently, it will be layered below the input method.
1471+
* Note: Windows that set {@link #FLAG_NOT_FOCUSABLE} cannot interact with the input method,
1472+
* regardless of this flag.
14621473
*/
14631474
public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
14641475

@@ -2142,13 +2153,12 @@ public static boolean isSystemAlertWindowType(@WindowType int type) {
21422153
* focus. In particular, this checks the
21432154
* {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
21442155
* flags and returns true if the combination of the two corresponds
2145-
* to a window that needs to be behind the input method so that the
2146-
* user can type into it.
2156+
* to a window that can use the input method.
21472157
*
21482158
* @param flags The current window manager flags.
21492159
*
2150-
* @return Returns {@code true} if such a window should be behind/interact
2151-
* with an input method, {@code false} if not.
2160+
* @return Returns {@code true} if a window with the given flags would be able to
2161+
* use the input method, {@code false} if not.
21522162
*/
21532163
public static boolean mayUseInputMethod(int flags) {
21542164
return (flags & FLAG_NOT_FOCUSABLE) != FLAG_NOT_FOCUSABLE

services/core/java/com/android/server/wm/WindowState.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,25 +2394,22 @@ boolean canBeImeTarget() {
23942394
if (mAttrs.type == TYPE_APPLICATION_STARTING) {
23952395
// Ignore mayUseInputMethod for starting window for now.
23962396
// TODO(b/159911356): Remove this special casing (originally added in commit e75d872).
2397-
} else if (PixelFormat.formatHasAlpha(mAttrs.format)) {
2398-
// Support legacy use cases where transparent windows can still be ime target with
2399-
// FLAG_NOT_FOCUSABLE and ALT_FOCUSABLE_IM set.
2400-
// Certain apps listen for IME insets using transparent windows and ADJUST_NOTHING to
2401-
// manually synchronize app content to IME animation b/144619551.
2402-
// TODO(b/145812508): remove this once new focus management is complete b/141738570
2397+
} else {
2398+
// TODO(b/145812508): Clean this up in S, may depend on b/141738570
2399+
// The current logic lets windows become the "ime target" even though they are
2400+
// not-focusable and can thus never actually start input.
2401+
// Ideally, this would reject windows where mayUseInputMethod() == false, but this
2402+
// also impacts Z-ordering of and delivery of IME insets to child windows, which means
2403+
// that simply disallowing non-focusable windows would break apps.
2404+
// See b/159438771, b/144619551.
2405+
24032406
final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
24042407

24052408
// Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are
24062409
// set or both are cleared...and not a starting window.
24072410
if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)) {
24082411
return false;
24092412
}
2410-
} else if (!WindowManager.LayoutParams.mayUseInputMethod(mAttrs.flags)) {
2411-
// Can be an IME target only if:
2412-
// 1. FLAG_NOT_FOCUSABLE is not set
2413-
// 2. FLAG_ALT_FOCUSABLE_IM is not set
2414-
// 3. not a starting window.
2415-
return false;
24162413
}
24172414

24182415
if (DEBUG_INPUT_METHOD) {

services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767

6868
import android.graphics.Insets;
6969
import android.graphics.Matrix;
70-
import android.graphics.PixelFormat;
7170
import android.graphics.Rect;
7271
import android.os.RemoteException;
7372
import android.platform.test.annotations.Presubmit;
@@ -229,21 +228,10 @@ public void testCanBeImeTarget() {
229228
appWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
230229
imeWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
231230

232-
// Visible app window with flags FLAG_NOT_FOCUSABLE or FLAG_ALT_FOCUSABLE_IM can't be IME
233-
// target while an IME window can never be an IME target regardless of its visibility
234-
// or flags.
235-
assertFalse(appWindow.canBeImeTarget());
236-
assertFalse(imeWindow.canBeImeTarget());
237-
238-
// b/145812508: special legacy use-case for transparent/translucent windows.
239-
appWindow.mAttrs.format = PixelFormat.TRANSPARENT;
240-
assertTrue(appWindow.canBeImeTarget());
241-
242-
appWindow.mAttrs.format = PixelFormat.OPAQUE;
243-
appWindow.mAttrs.flags &= ~FLAG_ALT_FOCUSABLE_IM;
244-
assertFalse(appWindow.canBeImeTarget());
245-
appWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE;
231+
// Visible app window with flags can be IME target while an IME window can never be an IME
232+
// target regardless of its visibility or flags.
246233
assertTrue(appWindow.canBeImeTarget());
234+
assertFalse(imeWindow.canBeImeTarget());
247235

248236
// Verify PINNED windows can't be IME target.
249237
int initialMode = appWindow.mActivityRecord.getWindowingMode();

0 commit comments

Comments
 (0)