|
18 | 18 | import android.net.NetworkStats; |
19 | 19 | import android.net.TrafficStats; |
20 | 20 | import android.os.Bundle; |
| 21 | +import android.util.Log; |
21 | 22 |
|
22 | 23 | import java.lang.reflect.InvocationTargetException; |
23 | 24 | import java.lang.reflect.Method; |
|
29 | 30 | * as an {@link InstrumentationTestCase} |
30 | 31 | */ |
31 | 32 | public class BandwidthTestCase extends InstrumentationTestCase { |
| 33 | + private static final String TAG = "BandwidthTestCase"; |
32 | 34 | private static final String REPORT_KEY_PACKETS_SENT = "txPackets"; |
33 | 35 | private static final String REPORT_KEY_PACKETS_RECEIVED = "rxPackets"; |
34 | 36 | private static final String REPORT_KEY_BYTES_SENT = "txBytes"; |
@@ -86,11 +88,26 @@ public void run() { |
86 | 88 | } |
87 | 89 | } else if (method.isAnnotationPresent(BandwidthTest.class) || |
88 | 90 | testClass.isAnnotationPresent(BandwidthTest.class)) { |
89 | | - TrafficStats.startDataProfiling(null); |
| 91 | + /** |
| 92 | + * If bandwidth profiling fails for whatever reason the test |
| 93 | + * should be allow to execute to its completion. |
| 94 | + * Typically bandwidth profiling would fail when a lower level |
| 95 | + * component is missing, such as the kernel module, for a newly |
| 96 | + * introduced hardware. |
| 97 | + */ |
| 98 | + try{ |
| 99 | + TrafficStats.startDataProfiling(null); |
| 100 | + } catch(IllegalStateException isx){ |
| 101 | + Log.w(TAG, "Failed to start bandwidth profiling"); |
| 102 | + } |
90 | 103 | runMethod(method, 1, false); |
91 | | - NetworkStats stats = TrafficStats.stopDataProfiling(null); |
92 | | - NetworkStats.Entry entry = stats.getTotal(null); |
93 | | - getInstrumentation().sendStatus(2, getBandwidthStats(entry)); |
| 104 | + try{ |
| 105 | + NetworkStats stats = TrafficStats.stopDataProfiling(null); |
| 106 | + NetworkStats.Entry entry = stats.getTotal(null); |
| 107 | + getInstrumentation().sendStatus(2, getBandwidthStats(entry)); |
| 108 | + } catch (IllegalStateException isx){ |
| 109 | + Log.w(TAG, "Failed to collect bandwidth stats"); |
| 110 | + } |
94 | 111 | } else { |
95 | 112 | runMethod(method, runCount, isRepetitive); |
96 | 113 | } |
|
0 commit comments