diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java b/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java index 18d9027..11d7fba 100644 --- a/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java +++ b/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java @@ -16,6 +16,7 @@ package com.android.tradefed.targetprep; import com.android.tradefed.build.IBuildInfo; +import com.android.tradefed.config.Option; import com.android.tradefed.config.OptionClass; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.ITestDevice; @@ -24,7 +25,12 @@ import com.android.tradefed.util.RunUtil; @OptionClass(alias = "restart-system-server") public class RestartSystemServerTargetPreparer implements ITargetPreparer { - private static final long SLEEP_MILLIS = 5000L; + @Option(name = "poll-interval-millis", + description = "Time interval to poll if system server has restarted") + private long mPollIntervalMillis = 3000L; + @Option(name = "max-tries", + description = "Max number of tries to poll") + private int mMaxTries = 10; private IRunUtil mRunUtil; @@ -39,8 +45,20 @@ public class RestartSystemServerTargetPreparer implements ITargetPreparer { @Override public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError, BuildError, DeviceNotAvailableException { + device.executeShellCommand("setprop sys.boot_completed 0"); String pid = device.executeShellCommand("pidof system_server"); device.executeShellCommand("kill " + pid); - mRunUtil.sleep(SLEEP_MILLIS); + boolean success = false; + for (int tries = 0; tries < mMaxTries; ++tries) { + if (device.executeShellCommand("getprop sys.boot_completed").equals("1")) { + success = true; + break; + } + mRunUtil.sleep(mPollIntervalMillis); + } + if (!success) { + throw new TargetSetupError("Gave up on waiting for system server to restart", + device.getDeviceDescriptor()); + } } } |