Fix CtsHostsideNetworkTests.

The changes made to ensuring network connectivity on app start
only applies to activities. There is no change in how the services
are handled.

Bug: 27803922
Test: cts-tradefed run singleCommand cts-dev -m CtsHostsideNetworkTests -t \
      com.android.cts.net.HostsideRestrictBackgroundNetworkTests

Change-Id: Ib82b07195e395c89701dd525b850c0935d94dfe7
This commit is contained in:
Sudheer Shanka
2017-05-01 11:55:53 -07:00
parent 6a25ed09f9
commit 7655b694ec

View File

@@ -817,29 +817,37 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
}
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();
}
final CountDownLatch latch = new CountDownLatch(1);
final Intent launchIntent = getIntentForComponent(type);
final Bundle extras = new Bundle();
final String[] errors = new String[] {null};
extras.putBinder(KEY_NETWORK_STATE_OBSERVER, getNewNetworkStateObserver(latch, errors));
launchIntent.putExtras(extras);
if (type == TYPE_COMPONENT_ACTIVTIY) {
final CountDownLatch latch = new CountDownLatch(1);
final Intent launchIntent = getIntentForComponent(type);
final Bundle extras = new Bundle();
final String[] errors = new String[]{null};
extras.putBinder(KEY_NETWORK_STATE_OBSERVER, getNewNetworkStateObserver(latch, errors));
launchIntent.putExtras(extras);
mContext.startActivity(launchIntent);
} else if (type == TYPE_COMPONENT_FOREGROUND_SERVICE) {
mContext.startService(launchIntent);
}
if (latch.await(FOREGROUND_PROC_NETWORK_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
if (!errors[0].isEmpty()) {
fail("Network is not available for app2 (" + mUid + "): " + errors[0]);
if (latch.await(FOREGROUND_PROC_NETWORK_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
if (!errors[0].isEmpty()) {
fail("Network is not available for app2 (" + mUid + "): " + errors[0]);
}
} else {
fail("Timed out waiting for network availability status from app2 (" + mUid + ")");
}
} else {
fail("Timed out waiting for network availability status from app2 (" + mUid + ")");
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) {
final Intent intent = new Intent();
if (type == TYPE_COMPONENT_ACTIVTIY) {