Move deduceRestrictedCapability to libs/net and rename it
NetworkCapabilities is included in framework-connectivity, so external module cannot have dependencies on its hidden API. Move the method to libs/net so that external modules can use it by including the library. Bug: 178777253 Test: FrameworksNetTests (cherry-picked from ag/13921626) Merged-In: I77970b3a5e5e0e9d263639694b1f06519169bf64 Change-Id: I77970b3a5e5e0e9d263639694b1f06519169bf64
This commit is contained in:
committed by
Chiachang Wang
parent
33f5f36c68
commit
522918f4ba
@@ -38,14 +38,12 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_WIFI_P2P;
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_ACCESS_FINE_LOCATION;
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_LOCAL_MAC_ADDRESS;
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS;
|
||||
import static android.net.NetworkCapabilities.RESTRICTED_CAPABILITIES;
|
||||
import static android.net.NetworkCapabilities.SIGNAL_STRENGTH_UNSPECIFIED;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_TEST;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_VPN;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI_AWARE;
|
||||
import static android.net.NetworkCapabilities.UNRESTRICTED_CAPABILITIES;
|
||||
import static android.os.Process.INVALID_UID;
|
||||
|
||||
import static com.android.modules.utils.build.SdkLevel.isAtLeastR;
|
||||
@@ -103,20 +101,6 @@ public class NetworkCapabilitiesTest {
|
||||
|
||||
@Test
|
||||
public void testMaybeMarkCapabilitiesRestricted() {
|
||||
// verify EIMS is restricted
|
||||
assertEquals((1 << NET_CAPABILITY_EIMS) & RESTRICTED_CAPABILITIES,
|
||||
(1 << NET_CAPABILITY_EIMS));
|
||||
|
||||
// verify CBS is also restricted
|
||||
assertEquals((1 << NET_CAPABILITY_CBS) & RESTRICTED_CAPABILITIES,
|
||||
(1 << NET_CAPABILITY_CBS));
|
||||
|
||||
// verify default is not restricted
|
||||
assertEquals((1 << NET_CAPABILITY_INTERNET) & RESTRICTED_CAPABILITIES, 0);
|
||||
|
||||
// just to see
|
||||
assertEquals(RESTRICTED_CAPABILITIES & UNRESTRICTED_CAPABILITIES, 0);
|
||||
|
||||
// check that internet does not get restricted
|
||||
NetworkCapabilities netCap = new NetworkCapabilities();
|
||||
netCap.addCapability(NET_CAPABILITY_INTERNET);
|
||||
@@ -985,26 +969,6 @@ public class NetworkCapabilitiesTest {
|
||||
assertNotEquals(-50, nc.getSignalStrength());
|
||||
}
|
||||
|
||||
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
|
||||
public void testDeduceRestrictedCapability() {
|
||||
final NetworkCapabilities nc = new NetworkCapabilities();
|
||||
// Default capabilities don't have restricted capability.
|
||||
assertFalse(nc.deduceRestrictedCapability());
|
||||
// If there is a force restricted capability, then the network capabilities is restricted.
|
||||
nc.addCapability(NET_CAPABILITY_OEM_PAID);
|
||||
nc.addCapability(NET_CAPABILITY_INTERNET);
|
||||
assertTrue(nc.deduceRestrictedCapability());
|
||||
// Except for the force restricted capability, if there is any unrestricted capability in
|
||||
// capabilities, then the network capabilities is not restricted.
|
||||
nc.removeCapability(NET_CAPABILITY_OEM_PAID);
|
||||
nc.addCapability(NET_CAPABILITY_CBS);
|
||||
assertFalse(nc.deduceRestrictedCapability());
|
||||
// Except for the force restricted capability, the network capabilities will only be treated
|
||||
// as restricted when there is no any unrestricted capability.
|
||||
nc.removeCapability(NET_CAPABILITY_INTERNET);
|
||||
assertTrue(nc.deduceRestrictedCapability());
|
||||
}
|
||||
|
||||
private void assertNoTransport(NetworkCapabilities nc) {
|
||||
for (int i = MIN_TRANSPORT; i <= MAX_TRANSPORT; i++) {
|
||||
assertFalse(nc.hasTransport(i));
|
||||
|
||||
Reference in New Issue
Block a user