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

Commit 33b8d436 authored by Anushree Ganjam's avatar Anushree Ganjam Committed by Android (Google) Code Review
Browse files

Merge "Add InputDispatcherRule to print the key events dispatched from system_server." into main

parents ed92a14e be6fff5e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.launcher3.ui.widget;

import static com.android.launcher3.util.rule.ShellCommandRule.createEnableInputTransportPublisherRule;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -30,7 +32,9 @@ import com.android.launcher3.util.rule.ScreenRecordRule.ScreenRecord;
import com.android.launcher3.widget.picker.WidgetsFullSheet;
import com.android.launcher3.widget.picker.WidgetsRecyclerView;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;

/**
@@ -40,6 +44,9 @@ import org.junit.runner.RunWith;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class TaplWidgetPickerTest extends AbstractLauncherUiTest {
    // b/325377690 : To get the log printed where DOWN key event is getting lost from TAPL.
    @Rule public final TestRule mEnableInputTransportPublisherRule =
            createEnableInputTransportPublisherRule();

    private WidgetsRecyclerView getWidgetsView(Launcher launcher) {
        return WidgetsFullSheet.getWidgetsView(launcher);
+32 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.launcher3.tapl.TestHelpers.getLauncherInMyProcess;

import android.content.ComponentName;
import android.content.pm.ActivityInfo;
import android.text.TextUtils;

import androidx.annotation.Nullable;
import androidx.test.InstrumentationRegistry;
@@ -40,6 +41,9 @@ import java.util.ArrayList;
 */
public class ShellCommandRule implements TestRule {

    private static final String SETPROP_PREFIX = "setprop";
    private static final String GETPROP_PREFIX = "getprop";
    private static final String UNKNOWN = "UNKNOWN";
    private final String mCmd;
    private final String mRevertCommand;
    private final boolean mCheckSuccess;
@@ -62,6 +66,19 @@ public class ShellCommandRule implements TestRule {
        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                String revertSetPropCmd = null;
                if (mCmd.startsWith(SETPROP_PREFIX) && mRevertCommand == null) {
                    // setprop command always follows format : setprop <TAG> <value>
                    // We are stripping out only the TAG here
                    String tag = mCmd.split("\\s")[1];
                    String getpropCmd = GETPROP_PREFIX + " " + tag;
                    String initialValue = UiDevice.getInstance(
                            getInstrumentation()).executeShellCommand(getpropCmd);
                    if (TextUtils.isEmpty(initialValue.trim())) {
                        initialValue = UNKNOWN;
                    }
                    revertSetPropCmd = SETPROP_PREFIX + " " + tag + " " + initialValue;
                }
                final String result =
                        UiDevice.getInstance(getInstrumentation()).executeShellCommand(mCmd);
                if (mCheckSuccess) {
@@ -73,13 +90,15 @@ public class ShellCommandRule implements TestRule {
                try {
                    base.evaluate();
                } finally {
                    if (mRevertCommand != null) {
                    if (mRevertCommand != null || revertSetPropCmd != null) {
                        String revertCmd =
                                mRevertCommand != null ? mRevertCommand : revertSetPropCmd;
                        final String revertResult = UiDevice.getInstance(
                                getInstrumentation()).executeShellCommand(
                                mRevertCommand);
                                revertCmd);
                        if (mCheckSuccess) {
                            Assert.assertTrue(
                                    "Failed command: " + mRevertCommand
                                    "Failed command: " + revertCmd
                                            + ", result: " + revertResult,
                                    "Success".equals(result.replaceAll("\\s", "")));
                        }
@@ -122,4 +141,14 @@ public class ShellCommandRule implements TestRule {
        return new ShellCommandRule("settings put global heads_up_notifications_enabled 0",
                "settings put global heads_up_notifications_enabled 1");
    }

    /**
     * Enables "InputTransportPublisher" debug flag. This prints the key input events dispatched by
     * the system server.
     * adb shell setprop log.tag.InputTransportPublisher DEBUG
     * See {@link com.android.cts.input.DebugInputRule} for more details.
     */
    public static ShellCommandRule createEnableInputTransportPublisherRule() {
        return new ShellCommandRule("setprop log.tag.InputTransportPublisher DEBUG", null);
    }
}