diff --git a/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java b/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java index 21c4491fc3716..971c0caced30f 100644 --- a/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java +++ b/apct-tests/perftests/inputmethod/src/android/inputmethod/ImePerfTest.java @@ -24,8 +24,6 @@ import static android.view.WindowInsetsAnimation.Callback.DISPATCH_MODE_STOP; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; -import static org.junit.Assert.assertTrue; - import android.annotation.UiThread; import android.app.Activity; import android.content.ComponentName; @@ -39,6 +37,7 @@ import android.perftests.utils.PerfManualStatusReporter; import android.perftests.utils.TraceMarkParser; import android.perftests.utils.TraceMarkParser.TraceMarkSlice; import android.provider.Settings; +import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -53,6 +52,7 @@ import androidx.annotation.Nullable; import androidx.test.filters.LargeTest; import com.android.compatibility.common.util.PollingCheck; +import com.android.compatibility.common.util.SystemUtil; import junit.framework.Assert; @@ -185,7 +185,6 @@ public class ImePerfTest extends ImePerfTestBase public static class BaselineIme extends InputMethodService { public static final int HEIGHT_DP = 100; - private static int sPid; @Override public View onCreateInputView() { @@ -196,14 +195,10 @@ public class ImePerfTest extends ImePerfTestBase view.setPadding(0, 0, 0, 0); view.addView(inner, new FrameLayout.LayoutParams(MATCH_PARENT, height)); inner.setBackgroundColor(0xff01fe10); // green - sPid = Process.myPid(); + Log.v(TAG, "onCreateInputView"); return view; } - static int getPid() { - return sPid; - } - static ComponentName getName(Context context) { return new ComponentName(context, BaselineIme.class); } @@ -281,9 +276,16 @@ public class ImePerfTest extends ImePerfTestBase } private void killBaselineIme() { - assertTrue("PID of test and IME can't be same", - Process.myPid() != BaselineIme.getPid()); - Process.killProcess(BaselineIme.getPid()); + // pidof returns a space separated list of numeric PIDs. + String result = SystemUtil.runShellCommand( + "pidof com.android.perftests.inputmethod:BaselineIME"); + for (String pid : result.trim().split(" ")) { + // The output may be empty if there is no process with the name. + if (TextUtils.isEmpty(pid)) { + continue; + } + Process.killProcess(Integer.parseInt(pid)); + } } private void testShowOrHideImeWarm(final boolean show) throws Throwable {