From f68359aad4f3dac5ff8199f02780f552fbeb9e39 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 1 Oct 2020 11:18:41 +0900 Subject: [PATCH] Forcibly show IME even hardware keyboard is conencted If device under test has a hardware keyboard connected, usually IME wouldn't show up and the test fails. Bug: 160930110 Test: atest SystemUITests:GlobalActionsImeTest Change-Id: I741155cf1119de981477aed93e3ef9b437c87147 --- .../globalactions/GlobalActionsImeTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsImeTest.java b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsImeTest.java index 58959c456cd99..bfc793516c8dc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsImeTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsImeTest.java @@ -16,6 +16,7 @@ package com.android.systemui.globalactions; +import static android.provider.Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD; import static android.view.WindowInsets.Type.ime; import static org.junit.Assert.assertEquals; @@ -24,9 +25,11 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.app.Activity; +import android.content.ContentResolver; import android.os.Bundle; import android.os.PowerManager; import android.os.SystemClock; +import android.provider.Settings; import android.view.View; import android.view.WindowInsets; import android.view.WindowInsetsController; @@ -41,6 +44,7 @@ import androidx.test.rule.ActivityTestRule; import com.android.systemui.SysuiTestCase; import org.junit.After; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -54,8 +58,23 @@ public class GlobalActionsImeTest extends SysuiTestCase { public ActivityTestRule mActivityTestRule = new ActivityTestRule<>( TestActivity.class, false, false); + private int mOriginalShowImeWithHardKeyboard; + + @Before + public void setUp() { + final ContentResolver contentResolver = mContext.getContentResolver(); + mOriginalShowImeWithHardKeyboard = Settings.Secure.getInt( + contentResolver, SHOW_IME_WITH_HARD_KEYBOARD, 0); + // Forcibly shows IME even when hardware keyboard is connected. + // To change USER_SYSTEM settings, we have to use settings shell command. + executeShellCommand("settings put secure " + SHOW_IME_WITH_HARD_KEYBOARD + " 1"); + } + @After public void tearDown() { + // To restore USER_SYSTEM settings, we have to use settings shell command. + executeShellCommand("settings put secure " + + SHOW_IME_WITH_HARD_KEYBOARD + " " + mOriginalShowImeWithHardKeyboard); executeShellCommand("input keyevent HOME"); }