Snap for 6370344 from 6a16c364976206793a0aef016fca914e277fa7c7 to rvc-release
Change-Id: I28c97074f5b81115d9a33253c2b71501e93e64e0
This commit is contained in:
@@ -62,13 +62,10 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
/**
|
||||
* Superclass for tests related to background network restrictions.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(NetworkPolicyTestRunner.class)
|
||||
public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
||||
public static final String TAG = "RestrictBackgroundNetworkTests";
|
||||
|
||||
@@ -137,8 +134,7 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
||||
private boolean mIsLocationOn;
|
||||
|
||||
@Rule
|
||||
public final RuleChain mRuleChain = RuleChain.outerRule(new DumpOnFailureRule())
|
||||
.around(new RequiredPropertiesRule())
|
||||
public final RuleChain mRuleChain = RuleChain.outerRule(new RequiredPropertiesRule())
|
||||
.around(new MeterednessConfigurationRule());
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.cts.net.hostside;
|
||||
|
||||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
|
||||
|
||||
import org.junit.rules.RunRules;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Custom runner to allow dumping logs after a test failure before the @After methods get to run.
|
||||
*/
|
||||
public class NetworkPolicyTestRunner extends AndroidJUnit4ClassRunner {
|
||||
private TestRule mDumpOnFailureRule = new DumpOnFailureRule();
|
||||
|
||||
public NetworkPolicyTestRunner(Class<?> klass) throws InitializationError {
|
||||
super(klass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement methodInvoker(FrameworkMethod method, Object test) {
|
||||
return new RunRules(super.methodInvoker(method, test), List.of(mDumpOnFailureRule),
|
||||
describeChild(method));
|
||||
}
|
||||
}
|
||||
@@ -15,17 +15,22 @@
|
||||
*/
|
||||
package android.tethering.test;
|
||||
|
||||
import static android.net.TetheringManager.TETHERING_USB;
|
||||
import static android.net.TetheringManager.TETHERING_WIFI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.TetheringManager;
|
||||
import android.net.TetheringManager.TetheringRequest;
|
||||
import android.os.ConditionVariable;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
@@ -37,8 +42,6 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -225,4 +228,27 @@ public class TetheringManagerTest {
|
||||
mTM.stopTethering(TETHERING_WIFI);
|
||||
mTetherChangeReceiver.expectNoActiveTethering(DEFAULT_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTetheringRequest() {
|
||||
final TetheringRequest tr = new TetheringRequest.Builder(TETHERING_WIFI).build();
|
||||
assertEquals(TETHERING_WIFI, tr.getTetheringType());
|
||||
assertNull(tr.getLocalIpv4Address());
|
||||
assertNull(tr.getClientStaticIpv4Address());
|
||||
assertFalse(tr.isExemptFromEntitlementCheck());
|
||||
assertTrue(tr.getShouldShowEntitlementUi());
|
||||
|
||||
final LinkAddress localAddr = new LinkAddress("192.168.24.5/24");
|
||||
final LinkAddress clientAddr = new LinkAddress("192.168.24.100/24");
|
||||
final TetheringRequest tr2 = new TetheringRequest.Builder(TETHERING_USB)
|
||||
.setStaticIpv4Addresses(localAddr, clientAddr)
|
||||
.setExemptFromEntitlementCheck(true)
|
||||
.setShouldShowEntitlementUi(false).build();
|
||||
|
||||
assertEquals(localAddr, tr2.getLocalIpv4Address());
|
||||
assertEquals(clientAddr, tr2.getClientStaticIpv4Address());
|
||||
assertEquals(TETHERING_USB, tr2.getTetheringType());
|
||||
assertTrue(tr2.isExemptFromEntitlementCheck());
|
||||
assertFalse(tr2.getShouldShowEntitlementUi());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user