Merge "Fix CtsHostsideNetworkTests." into oc-dev

am: 569fdfd845

Change-Id: Ie9c3997824ff4ecbf853078c0714424cd149c361
This commit is contained in:
Sudheer Shanka
2017-05-02 05:18:28 +00:00
committed by android-build-merger

View File

@@ -817,29 +817,37 @@ 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) { if (latch.await(FOREGROUND_PROC_NETWORK_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
mContext.startService(launchIntent); 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()) { } else {
fail("Network is not available for app2 (" + mUid + "): " + errors[0]); fail("Timed out waiting for network availability status from app2 (" + mUid + ")");
} }
} else { } 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) { private Intent getIntentForComponent(int type) {
final Intent intent = new Intent(); final Intent intent = new Intent();
if (type == TYPE_COMPONENT_ACTIVTIY) { if (type == TYPE_COMPONENT_ACTIVTIY) {