Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6b031f8a authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Check hasNavigationBar when showing IME nav bar

Before my CL [1] the IME navigation bar was directly tied to the System
navigation bar, and would follow its visibility.

Now that these two are untied, the IME navigation bar must check whether
the System navigation bar will be drawn, to avoid showing itself when it
shouldn't (e.g. emulator).

Test: run on emulator, check that IME navigation bar is not shown;
  atest InputMethodServiceTest#testNoNavigationBar_thenImeNoCaptionBar
Bug: 296435448
Change-Id: Ide89075836a527d806f28cbeeb8d90334b79428f
parent 354ad871
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.proto.ProtoOutputStream;
import android.view.IWindowManager;
import android.view.InputChannel;
import android.view.InputDevice;
import android.view.MotionEvent;
@@ -123,6 +124,7 @@ import android.view.WindowManager;
import android.view.WindowManager.DisplayImePolicy;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.view.WindowManagerGlobal;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.InputBinding;
@@ -2988,7 +2990,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                    "Waiting for the lazy init of mImeDrawsImeNavBarRes");
        }
        final boolean canImeDrawsImeNavBar =
                mImeDrawsImeNavBarRes != null && mImeDrawsImeNavBarRes.get();
                mImeDrawsImeNavBarRes != null && mImeDrawsImeNavBarRes.get()
                        && hasNavigationBarOnCurrentDisplay();
        final boolean shouldShowImeSwitcherWhenImeIsShown = shouldShowImeSwitcherLocked(
                InputMethodService.IME_ACTIVE | InputMethodService.IME_VISIBLE);
        return (canImeDrawsImeNavBar ? InputMethodNavButtonFlags.IME_DRAWS_IME_NAV_BAR : 0)
@@ -2996,6 +2999,21 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                ? InputMethodNavButtonFlags.SHOW_IME_SWITCHER_WHEN_IME_IS_SHOWN : 0);
    }

    /**
     * Whether the current display has a navigation bar. When this is {@code false} (e.g. emulator),
     * the IME should <em>not</em> draw the IME navigation bar.
     */
    @GuardedBy("ImfLock.class")
    private boolean hasNavigationBarOnCurrentDisplay() {
        final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
        try {
            return wm.hasNavigationBar(mCurTokenDisplayId != INVALID_DISPLAY
                    ? mCurTokenDisplayId : DEFAULT_DISPLAY);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    @GuardedBy("ImfLock.class")
    private boolean shouldShowImeSwitcherLocked(int visibility) {
        if (!mShowOngoingImeSwitcherForPhones) return false;
+20 −0
Original line number Diff line number Diff line
@@ -16,15 +16,20 @@

package com.android.inputmethodservice;

import static android.view.WindowInsets.Type.captionBar;

import static com.android.compatibility.common.util.SystemUtil.eventually;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

import android.app.Instrumentation;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.os.RemoteException;
import android.provider.Settings;
import android.support.test.uiautomator.By;
@@ -32,6 +37,7 @@ import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
import android.util.Log;
import android.view.WindowManagerGlobal;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;

@@ -592,6 +598,20 @@ public class InputMethodServiceTest {
                false /* orientationPortrait */);
    }

    /**
     * This checks that when the system navigation bar is not created (e.g. emulator),
     * then the IME caption bar is also not created.
     */
    @Test
    public void testNoNavigationBar_thenImeNoCaptionBar() throws Exception {
        boolean hasNavigationBar = WindowManagerGlobal.getWindowManagerService()
                .hasNavigationBar(mInputMethodService.getDisplayId());
        assumeFalse("Must not have a navigation bar", hasNavigationBar);

        assertEquals(Insets.NONE, mInputMethodService.getWindow().getWindow().getDecorView()
                .getRootWindowInsets().getInsetsIgnoringVisibility(captionBar()));
    }

    private void verifyInputViewStatus(
            Runnable runnable, boolean expected, boolean inputViewStarted)
            throws InterruptedException {