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

Commit f05cb16a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add the first test for multi-session IME" into main

parents 8c989693 a14e26b3
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -20,9 +20,12 @@ package {
android_test {
    name: "ConcurrentMultiSessionImeTest",
    srcs: ["src/**/*.java"],
    resource_dirs: ["res"],
    libs: ["android.test.runner"],
    static_libs: [
        "androidx.test.ext.junit",
        "androidx.test.rules",
        "compatibility-device-util-axt",
        "platform-test-annotations",
        "platform-test-rules",
        "truth",
@@ -35,7 +38,11 @@ android_test {
    test_suites: [
        "general-tests",
    ],
    sdk_version: "current",
    sdk_version: "test_current",

    data: [
        ":CtsMockInputMethod",
    ],

    // Store test artifacts in separated directories for easier debugging.
    per_testcase_directory: true,
+11 −0
Original line number Diff line number Diff line
@@ -17,6 +17,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.server.inputmethod.multisessiontest">

    <application>
        <uses-library android:name="android.test.runner" />
        <activity android:name=".MainActivity"
                  android:theme="@android:style/Theme.Material.NoActionBar"
                  android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
    </application>

    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="com.android.server.inputmethod.multisessiontest"></instrumentation>
+16 −7
Original line number Diff line number Diff line
@@ -17,13 +17,28 @@
<configuration description="Config for Concurrent Multi-Session IME tests">
    <object class="com.android.tradefed.testtype.suite.module.DeviceFeatureModuleController"
        type="module_controller">
        <option name="required-feature" value="android.software.input_methods" />
        <!-- TODO(b/323372972): require this feature once the bug is fixed. -->
        <!-- option name="required-feature" value="android.software.input_methods" -->

        <!-- Currently enabled to automotive only -->
        <option name="required-feature" value="android.hardware.type.automotive" />
    </object>
    <option name="test-suite-tag" value="apct" />

    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="force-install-mode" value="FULL" />
        <option name="test-file-name" value="ConcurrentMultiSessionImeTest.apk" />
        <option name="test-file-name" value="CtsMockInputMethod.apk" />
    </target_preparer>

    <!-- RunOnSecondaryUserTargetPreparer must run after SuiteApkInstaller. -->
    <target_preparer class="com.android.tradefed.targetprep.RunOnSecondaryUserTargetPreparer">
        <option name="start-background-user" value="true" />
        <option name="test-package-name" value="com.android.server.inputmethod.multisessiontest" />
        <option name="test-package-name" value="com.android.cts.mockime" />
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
        <option name="run-command" value="setprop debug.wm.disable_deprecated_abi_dialog 1" />
        <option name="run-command" value="settings put secure show_ime_with_hard_keyboard 1" />
@@ -31,12 +46,6 @@
            value="settings delete secure show_ime_with_hard_keyboard" />
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="force-install-mode" value="FULL" />
        <option name="test-file-name" value="ConcurrentMultiSessionImeTest.apk" />
    </target_preparer>

    <test class="com.android.tradefed.testtype.AndroidJUnitTest">
        <option name="package" value="com.android.server.inputmethod.multisessiontest" />
    </test>
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright 2024 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <EditText
        android:id="@+id/edit_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Input text here"/>
</FrameLayout>
+62 −14
Original line number Diff line number Diff line
@@ -16,16 +16,27 @@

package com.android.server.inputmethod.multisessiontest;

import static com.google.common.truth.Truth.assertThat;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import android.content.Context;
import android.content.pm.PackageManager;
import static com.android.compatibility.common.util.concurrentuser.ConcurrentUserActivityUtils.getResponderUserId;
import static com.android.compatibility.common.util.concurrentuser.ConcurrentUserActivityUtils.launchActivityAsUserSync;
import static com.android.compatibility.common.util.concurrentuser.ConcurrentUserActivityUtils.sendBundleAndWaitForReply;
import static com.android.server.inputmethod.multisessiontest.TestRequestConstants.KEY_REQUEST_CODE;
import static com.android.server.inputmethod.multisessiontest.TestRequestConstants.KEY_RESULT_CODE;
import static com.android.server.inputmethod.multisessiontest.TestRequestConstants.REPLY_IME_HIDDEN;
import static com.android.server.inputmethod.multisessiontest.TestRequestConstants.REQUEST_IME_STATUS;

import androidx.test.platform.app.InstrumentationRegistry;
import static com.google.common.truth.Truth.assertWithMessage;

import android.content.ComponentName;
import android.os.Bundle;

import androidx.test.core.app.ActivityScenario;

import com.android.bedstead.harrier.BedsteadJUnit4;
import com.android.bedstead.harrier.DeviceState;

import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -39,19 +50,56 @@ public final class ConcurrentMultiUserTest {
    @Rule
    public static final DeviceState sDeviceState = new DeviceState();

    private static final ComponentName TEST_ACTIVITY = new ComponentName(
            getInstrumentation().getTargetContext().getPackageName(),
            MainActivity.class.getName());

    private ActivityScenario<MainActivity> mActivityScenario;
    private MainActivity mActivity;
    private int mPeerUserId;

    @Before
    public void doBeforeEachTest() {
        // No op
    public void setUp() {
        // Launch passenger activity.
        mPeerUserId = getResponderUserId();
        launchActivityAsUserSync(TEST_ACTIVITY, mPeerUserId);

        // Launch driver activity.
        mActivityScenario = ActivityScenario.launch(MainActivity.class);
        mActivityScenario.onActivity(activity -> mActivity = activity);
    }

    @After
    public void tearDown() {
        if (mActivityScenario != null) {
            mActivityScenario.close();
        }
    }

    @Test
    public void behaviorBeingTested_expectedResult() {
        // Sample test
        Context context =
                InstrumentationRegistry.getInstrumentation().getTargetContext();
        assertThat(context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_AUTOMOTIVE)).isTrue();
        assertThat(context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_INPUT_METHODS)).isTrue();
    public void driverShowImeNotAffectPassenger() {
        assertDriverImeHidden();
        assertPassengerImeHidden();

        showDriverImeAndAssert();
        assertPassengerImeHidden();
    }

    private void assertDriverImeHidden() {
        assertWithMessage("Driver IME should be hidden")
                .that(mActivity.isMyImeVisible()).isFalse();
    }

    private void assertPassengerImeHidden() {
        final Bundle bundleToSend = new Bundle();
        bundleToSend.putInt(KEY_REQUEST_CODE, REQUEST_IME_STATUS);
        Bundle receivedBundle = sendBundleAndWaitForReply(TEST_ACTIVITY.getPackageName(),
                mPeerUserId, bundleToSend);
        assertWithMessage("Passenger IME should be hidden")
                .that(receivedBundle.getInt(KEY_RESULT_CODE)).isEqualTo(REPLY_IME_HIDDEN);
    }

    private void showDriverImeAndAssert() {
        mActivity.showMyImeAndWait();
    }
}
Loading