Merge "Fix CtsHostsideNetworkTests." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
569fdfd845
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user