diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java index 20bcc3cbd3..bef84f7bf3 100644 --- a/src/com/android/launcher3/views/ActivityContext.java +++ b/src/com/android/launcher3/views/ActivityContext.java @@ -53,6 +53,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.view.WindowInsetsCompat; import com.android.launcher3.BubbleTextView; import com.android.launcher3.DeviceProfile; @@ -314,6 +315,25 @@ public interface ActivityContext { == ((Context) this).getResources().getConfiguration().keyboard; } + /** + * Returns if the software keyboard is hidden. Hardware keyboards do not display on screen by + * default. + */ + default boolean isSoftwareKeyboardHidden() { + if (isHardwareKeyboard()) { + return true; + } else { + View dragLayer = getDragLayer(); + WindowInsets insets = dragLayer.getRootWindowInsets(); + if (insets == null) { + return false; + } + WindowInsetsCompat insetsCompat = + WindowInsetsCompat.toWindowInsetsCompat(insets, dragLayer); + return !insetsCompat.isVisible(WindowInsetsCompat.Type.ime()); + } + } + /** * Sends a pending intent animating from a view. * diff --git a/tests/src/com/android/launcher3/allapps/TaplKeyboardFocusTest.java b/tests/src/com/android/launcher3/allapps/TaplKeyboardFocusTest.java index d71bf84f11..41e3ea1e59 100644 --- a/tests/src/com/android/launcher3/allapps/TaplKeyboardFocusTest.java +++ b/tests/src/com/android/launcher3/allapps/TaplKeyboardFocusTest.java @@ -23,8 +23,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.view.KeyEvent; -import android.view.View; -import android.view.WindowInsets; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; @@ -33,6 +31,7 @@ import com.android.launcher3.LauncherState; import com.android.launcher3.tapl.HomeAllApps; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.util.rule.TestStabilityRule; +import com.android.launcher3.views.ActivityContext; import org.junit.Before; import org.junit.Test; @@ -102,11 +101,8 @@ public class TaplKeyboardFocusTest extends AbstractLauncherUiTest { executeOnLauncher(launcher -> launcher.getAppsView().getSearchUiManager().getEditText() .hideKeyboard(/* clearFocus= */ false)); - waitForLauncherCondition("Keyboard still visible.", launcher -> { - View root = launcher.getDragLayer(); - WindowInsets insets = root.getRootWindowInsets(); - return insets != null && !insets.isVisible(WindowInsets.Type.ime()); - }); + waitForLauncherCondition("Keyboard still visible.", + ActivityContext::isSoftwareKeyboardHidden); mLauncher.pressAndHoldKeyCode(KeyEvent.KEYCODE_DPAD_DOWN, 0); mLauncher.unpressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN, 0);