Merge "Rewrite #restartSystemServer"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c8eb2fbe14
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user