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
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 58959c4..bfc7935 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.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 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 ActivityTestRule<TestActivity> 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");
}