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

Commit 425e7cdc authored by Kohsuke Yatoh's avatar Kohsuke Yatoh
Browse files

Use pidof to get pid of :BaselineIME process.

BaseineIme.getPid() always returns 0 in the main process.

Bug: 192696127
Test: atest ImePerfTest#testShowImeCold
Change-Id: I054f09972d54b0d50c62025578e4f6f6e2e93c50
parent c5537211
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -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 {