aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoon Kim <moonk@google.com>2014-08-22 23:44:22 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-08-22 23:44:22 +0000
commit4826adb416a50edc772caff0952ffa566d794006 (patch)
treec3953df6addce652a6149e219319ec34d0444e26
parentaf372f5adb59ca6a5b0380e5ee90c5e2d63d72c5 (diff)
parenta22fe0abe71d302bbb780f1f015f3ae7802205fa (diff)
downloadtradefederation-4826adb416a50edc772caff0952ffa566d794006.tar.gz
Merge "Throw RuntimeException when WifiUtil.apk installation has failed."
-rw-r--r--src/com/android/tradefed/device/TestDevice.java151
-rw-r--r--src/com/android/tradefed/device/WifiHelper.java9
2 files changed, 64 insertions, 96 deletions
diff --git a/src/com/android/tradefed/device/TestDevice.java b/src/com/android/tradefed/device/TestDevice.java
index 008f60748..49d056a7c 100644
--- a/src/com/android/tradefed/device/TestDevice.java
+++ b/src/com/android/tradefed/device/TestDevice.java
@@ -36,7 +36,6 @@ import com.android.tradefed.log.LogUtil.CLog;
import com.android.tradefed.result.ByteArrayInputStreamSource;
import com.android.tradefed.result.InputStreamSource;
import com.android.tradefed.result.StubTestRunListener;
-import com.android.tradefed.targetprep.TargetSetupError;
import com.android.tradefed.util.ArrayUtil;
import com.android.tradefed.util.CommandResult;
import com.android.tradefed.util.CommandStatus;
@@ -1692,33 +1691,29 @@ class TestDevice implements IManagedTestDevice {
public boolean connectToWifiNetwork(String wifiSsid, String wifiPsk)
throws DeviceNotAvailableException {
- try {
- // Clears the last connected wifi network.
- mWifiSsid = null;
- mWifiPsk = null;
-
- IWifiHelper wifi = createWifiHelper();
- for (int i = 1; i <= mOptions.getWifiAttempts(); i++) {
- CLog.i("Connecting to wifi network %s on %s", wifiSsid, getSerialNumber());
- boolean success = wifi.connectToNetwork(wifiSsid, wifiPsk,
- mOptions.getConnCheckUrl());
- final Map<String, String> wifiInfo = wifi.getWifiInfo();
- if (success) {
- CLog.i("Successfully connected to wifi network %s(%s) on %s",
- wifiSsid, wifiInfo.get("bssid"), getSerialNumber());
-
- mWifiSsid = wifiSsid;
- mWifiPsk = wifiPsk;
+ // Clears the last connected wifi network.
+ mWifiSsid = null;
+ mWifiPsk = null;
- return true;
- } else {
- CLog.w("Failed to connect to wifi network %s(%s) on %s on attempt %d of %d",
- wifiSsid, wifiInfo.get("bssid"), getSerialNumber(), i,
- mOptions.getWifiAttempts());
- }
+ IWifiHelper wifi = createWifiHelper();
+ for (int i = 1; i <= mOptions.getWifiAttempts(); i++) {
+ CLog.i("Connecting to wifi network %s on %s", wifiSsid, getSerialNumber());
+ boolean success = wifi.connectToNetwork(wifiSsid, wifiPsk,
+ mOptions.getConnCheckUrl());
+ final Map<String, String> wifiInfo = wifi.getWifiInfo();
+ if (success) {
+ CLog.i("Successfully connected to wifi network %s(%s) on %s",
+ wifiSsid, wifiInfo.get("bssid"), getSerialNumber());
+
+ mWifiSsid = wifiSsid;
+ mWifiPsk = wifiPsk;
+
+ return true;
+ } else {
+ CLog.w("Failed to connect to wifi network %s(%s) on %s on attempt %d of %d",
+ wifiSsid, wifiInfo.get("bssid"), getSerialNumber(), i,
+ mOptions.getWifiAttempts());
}
- } catch (TargetSetupError e) {
- CLog.w("Failed to create WifiHelper: %s", e.getMessage());
}
return false;
}
@@ -1728,13 +1723,8 @@ class TestDevice implements IManagedTestDevice {
*/
@Override
public boolean checkConnectivity() throws DeviceNotAvailableException {
- try {
- final IWifiHelper wifi = createWifiHelper();
- return wifi.checkConnectivity(mOptions.getConnCheckUrl());
- } catch (TargetSetupError e) {
- CLog.w("Failed to create WifiHelper: %s", e.getMessage());
- }
- return false;
+ final IWifiHelper wifi = createWifiHelper();
+ return wifi.checkConnectivity(mOptions.getConnCheckUrl());
}
/**
@@ -1757,7 +1747,7 @@ class TestDevice implements IManagedTestDevice {
try {
final IWifiHelper wifi = createWifiHelper();
return wifi.isWifiEnabled();
- } catch (TargetSetupError e) {
+ } catch (RuntimeException e) {
CLog.w("Failed to create WifiHelper: %s", e.getMessage());
return false;
}
@@ -1769,11 +1759,9 @@ class TestDevice implements IManagedTestDevice {
* @param wifiSSID the wifi ssid
* @return <code>true</code> if device is currently connected to wifiSSID and has network
* connectivity. <code>false</code> otherwise
- * @throws TargetSetupError if error occurred obtaining wifi info
* @throws DeviceNotAvailableException if connection with device was lost
*/
- boolean checkWifiConnection(String wifiSSID) throws TargetSetupError,
- DeviceNotAvailableException {
+ boolean checkWifiConnection(String wifiSSID) throws DeviceNotAvailableException {
CLog.i("Checking connection with wifi network %s on %s", wifiSSID, getSerialNumber());
final IWifiHelper wifi = createWifiHelper();
// getSSID returns SSID as "SSID"
@@ -1805,17 +1793,12 @@ class TestDevice implements IManagedTestDevice {
@Override
public boolean disconnectFromWifi() throws DeviceNotAvailableException {
CLog.i("Disconnecting from wifi on %s", getSerialNumber());
- try {
- // Clears the last connected wifi network.
- mWifiSsid = null;
- mWifiPsk = null;
+ // Clears the last connected wifi network.
+ mWifiSsid = null;
+ mWifiPsk = null;
- IWifiHelper wifi = createWifiHelper();
- return wifi.disconnectFromNetwork();
- } catch (TargetSetupError e) {
- CLog.w("Failed to create WifiHelper: %s", e.getMessage());
- return false;
- }
+ IWifiHelper wifi = createWifiHelper();
+ return wifi.disconnectFromNetwork();
}
/**
@@ -1823,13 +1806,8 @@ class TestDevice implements IManagedTestDevice {
*/
@Override
public String getIpAddress() throws DeviceNotAvailableException {
- try {
- IWifiHelper wifi = createWifiHelper();
- return wifi.getIpAddress();
- } catch (TargetSetupError e) {
- CLog.w("Failed to create WifiHelper: %s", e.getMessage());
- return null;
- }
+ IWifiHelper wifi = createWifiHelper();
+ return wifi.getIpAddress();
}
/**
@@ -1837,17 +1815,13 @@ class TestDevice implements IManagedTestDevice {
*/
@Override
public boolean enableNetworkMonitor() throws DeviceNotAvailableException {
- try {
- mNetworkMonitorEnabled = false;
+ mNetworkMonitorEnabled = false;
- IWifiHelper wifi = createWifiHelper();
- wifi.stopMonitor();
- if (wifi.startMonitor(NETWORK_MONITOR_INTERVAL, mOptions.getConnCheckUrl())) {
- mNetworkMonitorEnabled = true;
- return true;
- }
- } catch (TargetSetupError e) {
- CLog.w("Failed to create WifiHelper: %s", e.getMessage());
+ IWifiHelper wifi = createWifiHelper();
+ wifi.stopMonitor();
+ if (wifi.startMonitor(NETWORK_MONITOR_INTERVAL, mOptions.getConnCheckUrl())) {
+ mNetworkMonitorEnabled = true;
+ return true;
}
return false;
}
@@ -1857,35 +1831,30 @@ class TestDevice implements IManagedTestDevice {
*/
@Override
public boolean disableNetworkMonitor() throws DeviceNotAvailableException {
- try {
- mNetworkMonitorEnabled = false;
-
- IWifiHelper wifi = createWifiHelper();
- List<Long> samples = wifi.stopMonitor();
- if (!samples.isEmpty()) {
- int failures = 0;
- long totalLatency = 0;
- for (Long sample : samples) {
- if (sample < 0) {
- failures += 1;
- } else {
- totalLatency += sample;
- }
- }
- double failureRate = failures * 100.0 / samples.size();
- double avgLatency = 0.0;
- if (failures < samples.size()) {
- avgLatency = totalLatency / (samples.size() - failures);
+ mNetworkMonitorEnabled = false;
+
+ IWifiHelper wifi = createWifiHelper();
+ List<Long> samples = wifi.stopMonitor();
+ if (!samples.isEmpty()) {
+ int failures = 0;
+ long totalLatency = 0;
+ for (Long sample : samples) {
+ if (sample < 0) {
+ failures += 1;
+ } else {
+ totalLatency += sample;
}
- CLog.d("[metric] url=%s, window=%ss, failure_rate=%.2f%%, latency_avg=%.2f",
- mOptions.getConnCheckUrl(), samples.size() * NETWORK_MONITOR_INTERVAL / 1000,
- failureRate, avgLatency);
}
- return true;
- } catch (TargetSetupError e) {
- CLog.w("Failed to create WifiHelper: %s", e.getMessage());
+ double failureRate = failures * 100.0 / samples.size();
+ double avgLatency = 0.0;
+ if (failures < samples.size()) {
+ avgLatency = totalLatency / (samples.size() - failures);
+ }
+ CLog.d("[metric] url=%s, window=%ss, failure_rate=%.2f%%, latency_avg=%.2f",
+ mOptions.getConnCheckUrl(), samples.size() * NETWORK_MONITOR_INTERVAL / 1000,
+ failureRate, avgLatency);
}
- return false;
+ return true;
}
/**
@@ -1893,7 +1862,7 @@ class TestDevice implements IManagedTestDevice {
* <p/>
* Exposed so unit tests can mock
*/
- IWifiHelper createWifiHelper() throws TargetSetupError, DeviceNotAvailableException {
+ IWifiHelper createWifiHelper() throws DeviceNotAvailableException {
return new WifiHelper(this);
}
diff --git a/src/com/android/tradefed/device/WifiHelper.java b/src/com/android/tradefed/device/WifiHelper.java
index 055f714c5..2a9081cd5 100644
--- a/src/com/android/tradefed/device/WifiHelper.java
+++ b/src/com/android/tradefed/device/WifiHelper.java
@@ -17,7 +17,6 @@ package com.android.tradefed.device;
import com.android.ddmlib.MultiLineReceiver;
import com.android.tradefed.log.LogUtil.CLog;
-import com.android.tradefed.targetprep.TargetSetupError;
import com.android.tradefed.util.FileUtil;
import com.android.tradefed.util.IRunUtil;
import com.android.tradefed.util.RunUtil;
@@ -60,7 +59,7 @@ public class WifiHelper implements IWifiHelper {
private final ITestDevice mDevice;
- public WifiHelper(ITestDevice device) throws TargetSetupError, DeviceNotAvailableException {
+ public WifiHelper(ITestDevice device) throws DeviceNotAvailableException {
mDevice = device;
ensureDeviceSetup();
}
@@ -74,7 +73,7 @@ public class WifiHelper implements IWifiHelper {
return RunUtil.getDefault();
}
- void ensureDeviceSetup() throws TargetSetupError, DeviceNotAvailableException {
+ void ensureDeviceSetup() throws DeviceNotAvailableException {
final String inst = mDevice.executeShellCommand(CHECK_PACKAGE_CMD);
if (inst != null) {
Matcher matcher = PACKAGE_VERSION_PAT.matcher(inst);
@@ -99,11 +98,11 @@ public class WifiHelper implements IWifiHelper {
// Installed successfully; good to go.
return;
} else {
- throw new TargetSetupError(String.format(
+ throw new RuntimeException(String.format(
"Unable to install WifiUtil utility: %s", error));
}
} catch (IOException e) {
- throw new TargetSetupError(String.format(
+ throw new RuntimeException(String.format(
"Failed to unpack WifiUtil utility: %s", e.getMessage()));
} finally {
FileUtil.deleteFile(apkTempFile);