Merge "Fix CtsHostsideNetworkTests." into oc-dev

This commit is contained in:
Sudheer Shanka
2017-05-02 05:12:50 +00:00
committed by Android (Google) Code Review

View File

@@ -817,20 +817,19 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
} }
protected void launchComponentAndAssertNetworkAccess(int type) throws Exception { protected void launchComponentAndAssertNetworkAccess(int type) throws Exception {
if (type == TYPE_COMPONENT_ACTIVTIY) { if (type == TYPE_COMPONENT_FOREGROUND_SERVICE) {
startForegroundService();
assertForegroundServiceNetworkAccess();
return;
} else if (type == TYPE_COMPONENT_ACTIVTIY) {
turnScreenOn(); turnScreenOn();
}
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
final Intent launchIntent = getIntentForComponent(type); final Intent launchIntent = getIntentForComponent(type);
final Bundle extras = new Bundle(); final Bundle extras = new Bundle();
final String[] errors = new String[]{null}; final String[] errors = new String[]{null};
extras.putBinder(KEY_NETWORK_STATE_OBSERVER, getNewNetworkStateObserver(latch, errors)); extras.putBinder(KEY_NETWORK_STATE_OBSERVER, getNewNetworkStateObserver(latch, errors));
launchIntent.putExtras(extras); launchIntent.putExtras(extras);
if (type == TYPE_COMPONENT_ACTIVTIY) {
mContext.startActivity(launchIntent); mContext.startActivity(launchIntent);
} else if (type == TYPE_COMPONENT_FOREGROUND_SERVICE) {
mContext.startService(launchIntent);
}
if (latch.await(FOREGROUND_PROC_NETWORK_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { if (latch.await(FOREGROUND_PROC_NETWORK_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
if (!errors[0].isEmpty()) { if (!errors[0].isEmpty()) {
fail("Network is not available for app2 (" + mUid + "): " + errors[0]); fail("Network is not available for app2 (" + mUid + "): " + errors[0]);
@@ -838,6 +837,15 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
} else { } else {
fail("Timed out waiting for network availability status from app2 (" + mUid + ")"); fail("Timed out waiting for network availability status from app2 (" + mUid + ")");
} }
} else {
throw new IllegalArgumentException("Unknown type: " + type);
}
}
private void startForegroundService() throws Exception {
final Intent launchIntent = getIntentForComponent(TYPE_COMPONENT_FOREGROUND_SERVICE);
mContext.startForegroundService(launchIntent);
assertForegroundServiceState();
} }
private Intent getIntentForComponent(int type) { private Intent getIntentForComponent(int type) {