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

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

Merge "Rewrite #restartSystemServer"

parents 6ec0d5df 749242a2
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.tests.stagedinstallinternal.host;
import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.android.ddmlib.Log;
import com.android.tests.rollback.host.AbandonSessionsRule;
@@ -83,7 +84,7 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {

    private void restartSystemServer() throws Exception {
        // Restart the system server
        long oldStartTime = getDevice().getProcessByName("system_server").getStartTime();
        ProcessInfo oldPs = getDevice().getProcessByName("system_server");

        getDevice().enableAdbRoot(); // Need root to restart system server
        assertThat(getDevice().executeShellCommand("am restart")).contains("Restart the system");
@@ -91,18 +92,16 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {

        // Wait for new system server process to start
        long start = System.currentTimeMillis();
        long newStartTime = oldStartTime;
        while (System.currentTimeMillis() < start + SYSTEM_SERVER_TIMEOUT_MS) {
            ProcessInfo newPs = getDevice().getProcessByName("system_server");
            if (newPs != null) {
                newStartTime = newPs.getStartTime();
                if (newStartTime != oldStartTime) {
                    break;
                if (newPs.getPid() != oldPs.getPid()) {
                    getDevice().waitForDeviceAvailable();
                    return;
                }
            }
            Thread.sleep(500);
        }
        assertThat(newStartTime).isNotEqualTo(oldStartTime);
        getDevice().waitForDeviceAvailable();
        fail("Timed out in restarting system server");
    }
}