Merge "CtsHostsideNetworkTests: Add more logging when the test fails." into oc-mr1-dev
am: 26e6bf91be
Change-Id: Ibf3ea26a55abdb2a6f5340e74cc11dbef05e31f1
diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
index b38eb0f..535703f 100644
--- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
+++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
@@ -141,6 +141,7 @@
Log.i(TAG, "Apps status on " + getName() + ":\n"
+ "\ttest app: uid=" + mMyUid + ", state=" + getProcessStateByUid(mMyUid) + "\n"
+ "\tapp2: uid=" + mUid + ", state=" + getProcessStateByUid(mUid));
+ executeShellCommand("settings get global app_idle_constants");
}
@Override
@@ -388,6 +389,8 @@
timeoutMs = Math.min(timeoutMs*2, NETWORK_TIMEOUT_MS);
}
dumpAllNetworkRules();
+ Log.d(TAG, "Usagestats dump: " + getUsageStatsDump());
+ executeShellCommand("settings get global app_idle_constants");
fail("Invalid state for expectAvailable=" + expectAvailable + " after " + maxTries
+ " attempts.\nLast error: " + error);
}
@@ -859,16 +862,8 @@
protected void setAppIdle(boolean enabled) throws Exception {
Log.i(TAG, "Setting app idle to " + enabled);
- final String beforeStats = getUsageStatsDump();
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
- try {
- assertAppIdle(enabled); // Sanity check
- } catch (Throwable e) {
- final String afterStats = getUsageStatsDump();
- Log.d(TAG, "UsageStats before:\n" + beforeStats);
- Log.d(TAG, "UsageStats after:\n" + afterStats);
- throw e;
- }
+ assertAppIdle(enabled); // Sanity check
}
private String getUsageStatsDump() throws Exception {
@@ -883,7 +878,7 @@
&& !str.contains(TEST_PKG) && !str.contains(TEST_APP2_PKG)) {
continue;
}
- if (str.contains("config=")) {
+ if (str.trim().startsWith("config=") || str.trim().startsWith("time=")) {
continue;
}
sb.append(str).append('\n');
@@ -892,7 +887,13 @@
}
protected void assertAppIdle(boolean enabled) throws Exception {
- assertDelayedShellCommand("am get-inactive " + TEST_APP2_PKG, 15, 2, "Idle=" + enabled);
+ try {
+ assertDelayedShellCommand("am get-inactive " + TEST_APP2_PKG, 15, 2, "Idle=" + enabled);
+ } catch (Throwable e) {
+ Log.d(TAG, "UsageStats dump:\n" + getUsageStatsDump());
+ executeShellCommand("settings get global app_idle_constants");
+ throw e;
+ }
}
/**