Commit Graph

11430 Commits

Author SHA1 Message Date
Chalard Jean
746cdc28af Migrate VPN to the public NetworkAgent API.
On top of being a cleanup this is useful for the S Network
Selection project that will need to enrich the Network
Agent API, and as such should not have to support legacy
agents.

Test: FrameworksNetTests NetworkStackTests
Bug: 167544279
Change-Id: Id3e5f6e19829c64074cd6a52c5f950cee56b860b
2020-11-30 16:15:18 +09:00
Aaron Huang
6616df39b9 Migrate Slog to Log used in connectivity service module
Connectivity service module uses Slog which is @hide so
migrate to Log, which is public, to remove hidden API usage.

Bug: 172050541
Test: FrameworksNetTests
      check log is moved from system buffer to main buffer.
Change-Id: I0dcc0e169b892cc872ed4510f699642cb81b633a
2020-11-30 14:35:01 +08:00
Remi NGUYEN VAN
d707e7f5ae Do not query CS in NetworkProvider constructor
ConnectivityService may not be available in a NetworkProvider
constructor, if it is created (but still unused) before
ConnectivityService starts.

As ConnectivityManager is only necessary in
declareNetworkRequestUnfulfillable, which should not be called often,
just query ConnectivityManager at that point.

This is necessary for VcnManagementService, which is started before
ConnectivityService and creates its NetworkProvider in its constructor.
Fortunately VcnManagementService does not call
declareNetworkRequestUnfulfillable at this point.

ConnectivityManager may be migrated to classic service getters that
cache "null" when the service was not available the first time it is
queried, so no system service must query it before it starts.

Bug: 171540887
Test: atest FrameworksNetTests:NetworkProviderTest
Change-Id: I8dadcd0e1360a9464192f330493e13aa69dd9fe2
2020-11-30 12:42:15 +09:00
Treehugger Robot
47ec892104 Merge "Adding @IgnoreUpTo to OemNetworkPreferencesTest" am: e794a09bb7
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1511772

Change-Id: Ie7cf35131d553279ccd3244536107c2a0c53b379
2020-11-30 02:08:29 +00:00
Remi NGUYEN VAN
e07a894bc3 Run OemNetworkPreferencesTest with DevSdkIgnoreRunner
The class-level @IgnoreUpTo annotation only applies with that runner.

Change-Id: I065618f2345c1d91de2fa1f2f558e5ed5b066f3e
Fixes: 174268969
Bug: 171505922
Test: atest FrameworksNetTests:android.net.OemNetworkPreferencesTest
2020-11-30 01:42:24 +00:00
Treehugger Robot
e794a09bb7 Merge "Adding @IgnoreUpTo to OemNetworkPreferencesTest" 2020-11-30 01:38:19 +00:00
Lorenzo Colitti
f295719210 Merge changes from topic "networkagent-set-underlying-networks" am: dccf7eda5e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1501816

Change-Id: I94fd855f9b03d7487b1ebc8288be7f95e12fbe4f
2020-11-28 03:34:26 +00:00
Lorenzo Colitti
054f6c19b5 Clear calling identity in registerNetworkAgent. am: 8000e03ec9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1511317

Change-Id: I0f93630527cfe352f5d8f5c69b5276dadbb8c3e4
2020-11-28 03:27:05 +00:00
Lorenzo Colitti
60dbe043ae Allow tests to create TRANSPORT_TEST|TRANSPORT_VPN networks. am: f3963fa279
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1511312

Change-Id: Id28ea9f3b72e5cae0232ffc7698120512359be49
2020-11-28 03:24:32 +00:00
Lorenzo Colitti
298ce37539 Move applying underlying caps from Vpn to ConnectivityService. am: 129c01eabf
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1501815

Change-Id: I10147f9b86661243e654a16a760e183128493042
2020-11-28 03:20:40 +00:00
Lorenzo Colitti
18b00acd92 Stop calling Vpn#updateCapabilities in CS.
Instead, make Vpn#onUserAdded and Vpn#onUserRemoved notify CS
of UID range changes through the VPN's NetworkAgent.

After this change, ConnectivityService no longer touches the
VPN's NetworkCapabilities directly, which is a much cleaner
design.

Bug: 173331190
Test: passes existing tests in ConnectivityServiceTest
Change-Id: If2201f392cdb5f00c89a97683ad4ce6bda7b89e5
2020-11-27 15:35:39 +09:00
Lorenzo Colitti
fee5e4e34c Stop accessing VPNs in getAllVpnInfo.
This is only used for NetworkStatsService and only called on the
handler thread, so it can be replaced by a simple scan over
mNetworkAgentInfos without having to take any locks.

Bug: 173331190
Test: passes existing tests in ConnectivityServiceTest
Change-Id: I194e0cc55603a0f59f7138f38329f505b55da132
2020-11-27 15:35:38 +09:00
Lorenzo Colitti
8000e03ec9 Clear calling identity in registerNetworkAgent.
Much of registerNetworkAgent calls internal ConnectivityService
methods which generally assume that they are not processing an
IPC and are running under the system's calling identity.

However, only the call to makeNetworkMonitor is run with caller
identity cleared. Expand the scope of clearing the caller
identity over the creation of the nai.

Bug: 173331190
Test: passes existing tests in ConnectivityServiceTest
Change-Id: Icad28601a612fb5e1ed0451ec9e2066f4e766d0e
2020-11-27 15:35:38 +09:00
Lorenzo Colitti
f3963fa279 Allow tests to create TRANSPORT_TEST|TRANSPORT_VPN networks.
This CL allows an app that has the MANAGE_TEST_NETWORKS
permission to create test VPN networks.

The code enforces that such networks can never apply to any UIDs
and thus will never carry any traffic.

Bug: 173331190
Test: passes existing tests, moved tests pass
Change-Id: I5befea0e3b4b6dce4ca0c6a04471a055186b644c
2020-11-27 15:35:38 +09:00
Lorenzo Colitti
129c01eabf Move applying underlying caps from Vpn to ConnectivityService.
Add support to ConnectivityService to track underlying networks
directly instead of through the Vpn class.

1. Communicate all information necessary to propagate underlying
   network capabilities to ConnectivityService via NetworkAgent.
   This includes:
   a. Underlying networks:
      - Add SystemApi for NetworkAgent to declare its underlying
        networks to ConnectivityService, and use it in Vpn.
      - Add a new declaredUnderlyingNetworks member to
        NetworkAgentInfo and store the underlying networks in it.
	Move propagation of underlying network capabilities to
	mixInCapabilities, which is a natural place for it.
   b. "Always metered" bit:
      - Communicate this to ConnectivityService via the existing
        NOT_METERED capability. Store it in a new declaredMetered
	boolean in NetworkAgentInfo to separate it cleanly from
	the NOT_METERED bit in the capabilities, which depends on
	whether the underlying networks are metered or not. In
	order to ensure that this is only ever changed when a NC
	update is received from a NetworkAgent, define a new
	processCapabilitiesFromAgent similar to the existing
        processLinkPropertiesFromAgent.

2. Ensure that propagating underlying network capabilities does
   not read the VPN's NetworkCapabilities. In order to do this,
   ensure that all relevant information on underlying networks
   and metering is sent to ConnectivityService at NetworkAgent
   registration time. CS still calls Vpn#updateCapabilities when
   a user is added/removed, but that is deleted in a future CL.

3. Slightly generalize propagating underlying network
   capabilities because there may be other network types that
   also have underlying networks that aren't VPNs (e.g., VCN).
   - Introduce a new supportsUnderlyingNetworks() boolean method
     in NetworkAgentInfo.
   - Rename updateAllVpnsCapabilities to
     propagateUnderlyingNetworkCapabilities.

This commit does not move the actual logic of calculating the
underlying capabilities out of Vpn.java. That can be done in a
subsequent change once CS stops calling getUnderlyingNetworks().

This commit also does not modify any of the other code in CS that
directly accesses VPNs' underlying networks.

Bug: 173331190
Test: passes existing tests in ConnectivityServiceTest
Test: CTS test in r.android.com/1511114
Test: atest CtsNetTestCases:Ikev2VpnTest HostsideVpnTests
Change-Id: I5f76cb1aa4866efed3d5c4590e931fdb0e994f8d
2020-11-27 15:35:38 +09:00
Lorenzo Colitti
083b00b5fb Stop accessing VPNs in checkConnectivityDiagnosticsPermissions.
Currently, checkConnectivityDiagnosticsPermissions takes the VPN
lock to examine the VPN's underlying networks. Use the underlying
network data that is available in ConnectivityService instead.

Bug: 173331190
Test: passes existing tests in ConnectivityServiceTest
Change-Id: Ia1c366c5e9974d4d2c4b38030e66c007d62020ff
2020-11-27 15:35:38 +09:00
Treehugger Robot
cdf25a7bf4 Merge changes Id4632e1b,I31985822,Ibbf96a25 am: 30b0d06a86
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1511309

Change-Id: Iabe10bcb42333e1046add1be5090c19733b7887d
2020-11-26 03:58:57 +00:00
Treehugger Robot
30b0d06a86 Merge changes Id4632e1b,I31985822,Ibbf96a25
* changes:
  Test passing an underlying network array with null network in it.
  Make testVpnNetworkActive more deterministic.
  Add a test for restricted profile added/removed with VPN up.
2020-11-26 03:40:44 +00:00
Lorenzo Colitti
6ae6681892 Test passing an underlying network array with null network in it.
Current code treats these nulls as if they weren't there.

Bug: 173331190
Test: test-only change
Change-Id: Id4632e1b004c09910b4b7613f7233d2c19e2f0ac
2020-11-26 10:33:23 +09:00
Lorenzo Colitti
b7769533c1 Make testVpnNetworkActive more deterministic.
This test is a bit brittle because it sets the underlying
networks while the VPN is undergoing validation by
NetworkMonitor. The test does attempt to disable validation,
but that's not actually possible - the only thing that's possible
is to tell NetworkMonitor to validate immediately without sending
any probes. So the underlying network change races with the
validation. I'm not sure why the test isn't flaky. It might be
because both the network change and the validation result in a
capabilities change, and the test expects "a capabilities change"
without expressing what change that should be.

Make this a bit more predictable by ensuring that the network
validates before the underlying networks are set.

This is useful because an upcoming CL will change the way
underlying network capabilities are propagated. With this test
CL, both the old and the new code pass.

Bug: 173331190
Test: test-only change
Change-Id: I319858228e8d097c0b60a107029f296385f91269
2020-11-26 10:33:23 +09:00
Lorenzo Colitti
99fb6920f6 Add a test for restricted profile added/removed with VPN up.
Bug: 173331190
Test: test-only change
Change-Id: Ibbf96a259a73068d110a159d54059720121117cc
2020-11-26 10:33:23 +09:00
James Mattis
b5cc74279d Adding @IgnoreUpTo to OemNetworkPreferencesTest
Adding @IgnoreUpTo to OemNetworkPreferencesTest so that it can run as
part of MTS.

Bug: 174268969
Bug: 171505922
Test: atest FrameworksNetTests:android.net.OemNetworkPreferencesTest
Change-Id: If7fb039c2cdb061f803c8a59e826e485e1f1c761
2020-11-25 15:34:11 -08:00
Lucas Lin
f69ea04ab1 Merge "Ignore verifying canBeSatisfiedBy() on Android Q" am: 7d013abf65
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1508137

Change-Id: Ia287b39a2f7d9a5b1ef9baf60bcf90048d66af7b
2020-11-24 04:16:28 +00:00
Lucas Lin
7d013abf65 Merge "Ignore verifying canBeSatisfiedBy() on Android Q" 2020-11-24 03:38:34 +00:00
lucaslin
1d8505b456 Ignore verifying canBeSatisfiedBy() on Android Q
The method - satisfiedBy() has changed to canBeSatisfiedBy()
starting from Android R, so the method - canBeSatisfiedBy()
cannot be found when running this test on Android Q.
Ignore verifying canBeSatisfiedBy() on Android Q to fix this
problem.

Bug: 173911834
Test: Run MatchAllNetworkSpecifierTest on Android Q, R, S.
Change-Id: Ibe317b56f82d3ea100b1d78c3907dce4f2fd964d
2020-11-23 23:40:23 +08:00
James Mattis
844c7cf2ed Merge changes Ibed6cdd4,I51e3c00d,Ibf37f94b am: 5cbbbfb144
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1498660

Change-Id: Idb3243ae752270a66b32acd0b8a3cc5161e695b2
2020-11-21 00:54:09 +00:00
James Mattis
5cbbbfb144 Merge changes Ibed6cdd4,I51e3c00d,Ibf37f94b
* changes:
  Update toString() to use the correct request
  Update requestsSortedById() to sort by collection
  Allow a way to track the active request in an NRI
2020-11-21 00:24:11 +00:00
Chiachang Wang
9476e9fcdc Merge changes from topic "move_BSCH" am: 81d8d47876
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1503395

Change-Id: I1e27a7fcde0ba83ffcad525ca091af7fc5ced2db
2020-11-20 07:49:31 +00:00
Chiachang Wang
cf16fe22b9 Move BasicShellCommandHandler to frameworks/lib/modules-utils am: 62740141dc
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1483965

Change-Id: Ib2a99f1aeb31b89e69a5b313ca3774ba145dde33
2020-11-20 07:47:11 +00:00
Chiachang Wang
81d8d47876 Merge changes from topic "move_BSCH"
* changes:
  Remove BasicShellCommandHandler from frameworks/base
  Move BasicShellCommandHandler to frameworks/lib/modules-utils
2020-11-20 07:29:56 +00:00
Benedict Wong
117c387343 Merge "Expose MIN_MTU_V6 as a public, @hide constant" am: 3b0f85c921
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1505072

Change-Id: I9ef7cc8f84d6a9a49d754b39cc2bd66209d6343f
2020-11-20 01:38:30 +00:00
Lucas Lin
8f1d8528c8 Merge "Remove a comment from ConnectivityService" am: f0d6b60b9b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1494040

Change-Id: I20fa62c5dbe2d1e8e9cce19a8fb9a932f21722f7
2020-11-20 01:34:29 +00:00
Benedict Wong
3b0f85c921 Merge "Expose MIN_MTU_V6 as a public, @hide constant" 2020-11-20 01:30:18 +00:00
Lucas Lin
f0d6b60b9b Merge "Remove a comment from ConnectivityService" 2020-11-20 01:10:21 +00:00
James Mattis
e955141cc6 Update toString() to use the correct request
Update ConnectivityService.NetworkReassignment#toString to use either
the current satisfier's request otherwise highest priority request when
executing toString(). This is part of the mulilayered request changes.

Bug: 173336774
Bug: 171991028
Test: atest FrameworksNetTests
Change-Id: Ibed6cdd4522133164b2b919f62ecc9411943f026
2020-11-19 17:04:02 -08:00
James Mattis
258ea3c3c3 Update requestsSortedById() to sort by collection
Update requestsSortedById() to sort NetworkRequestInfo by their
nested collection of NetworkRequest objects vs a single request.
Before the NetworkRequestInfo with the request with the lowest
requestId would be sorted to the top. Now the NetworkRequestInfo
which contains the request with the lowest requestId will be
sorted to the top.

Bug: 173292541
Bug: 171991028
Test: atest FrameworksNetTests
Change-Id: I51e3c00d59443e37ddbf168c423d13df8d14fa64
2020-11-19 17:04:02 -08:00
James Mattis
4fce5d1bc7 Allow a way to track the active request in an NRI
As we are now allowing for multi-layered requests in NetworkRequestInfo
(NRI), we need a way to track which of those requests ended up being
satisfied. This also includes updates to NetworkRequestInfo itself to
support multilayared requests.

Bug: 173146509
Bug: 171991028
Test: atest FrameworksNetTests
atest FrameworksNetIntegrationTests
atest CtsNetTestCasesLatestSdk
Change-Id: I7bb5a564769c90928871fe28de05195c9cfae6b5

Change-Id: Ibf37f94b53eb2e833821553e00d76fe38bfea266
2020-11-19 17:03:51 -08:00
Sarah Chin
05dc875b8e Merge "Clarify documentation on TEMP_NOT_METERED API" am: b4b3693558
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1504954

Change-Id: I36d911d227ed4ac8e7b23f52036ff384977e2248
2020-11-19 18:02:28 +00:00
Sarah Chin
b4b3693558 Merge "Clarify documentation on TEMP_NOT_METERED API" 2020-11-19 17:50:35 +00:00
Lorenzo Colitti
d030251f42 Merge "Make MockVpn more realistic and easier to use." am: 8dd41ee6b3
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1501814

Change-Id: I6584e231913841dc218573dc586429cd720621a3
2020-11-19 10:42:04 +00:00
Lorenzo Colitti
23fa46ae09 Merge changes I3711b362,I49421183,Icc0701cb,I2f5ccc1d am: 63c1a59620
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1501951

Change-Id: I021b2719e8b6d76cbb64d979f1ce5f661a1a25a5
2020-11-19 10:37:25 +00:00
Lorenzo Colitti
8dd41ee6b3 Merge "Make MockVpn more realistic and easier to use." 2020-11-19 10:32:19 +00:00
Lorenzo Colitti
63c1a59620 Merge changes I3711b362,I49421183,Icc0701cb,I2f5ccc1d
* changes:
  Increase test coverage for VPN info sent to NetworkStatsService.
  Simplify MockVpn.
  Test a VPN with an underlying network that does not yet exist.
  Minor fixes to NetworkCapabilities#toString.
2020-11-19 10:20:00 +00:00
Sarah Chin
2cb619acfd Clarify documentation on TEMP_NOT_METERED API
Test: build
Bug: 165337240
Change-Id: Ifc0843b529e7a205b0e1caf98420adfc377c28e7
2020-11-19 01:15:48 -08:00
Benedict Wong
f3215117bc Expose MIN_MTU_V6 as a public, @hide constant
MIN_MTU_V6 is increasingly used, and the LinkProperties version is used
as a source of truth for the constant.

Bug: 163602123
Test: atest FrameworksNetTests
Change-Id: I67134cd4fb7e2cf59c36947b62f681ac9b94ea4a
2020-11-19 00:21:53 -08:00
lucaslin
5d358df3c7 Remove a comment from ConnectivityService
This comment is not true anymore since NetworkMonitor is not only
verifying the default network but also verifying VPN when private
DNS is enabled.

Test: Build pass.
Change-Id: Ib975aa28c84b9974a73d1baca9d5185c01b71217
2020-11-19 16:19:10 +08:00
Lorenzo Colitti
4489abdb15 Make MockVpn more realistic and easier to use.
MockVpn is very difficult to use because it requires the test
caller keeping track of both the MockVpn object and an
accompanying TestNetworkAgentWrapper.

It's also not very realistic: for example, connect() doesn't
actually connect anything, it just makes it so that if
ConnectivityService tries to update the capabilities, the attempt
will not be ignored. Also, unlike the real code in Vpn, it
connects with empty NetworkCapabilities (in particular, with
empty UID ranges).

Make this easier to use and a bit more realistic by:
- Allowing TestNetworkAgentWrapper to take a "NetworkCapabilities
  template" that will form the initial capabilities sent when the
  agent registers with ConnectivityService. This allows the VPN
  to register its agent with its UID ranges already set, like the
  production code does.
- Providing separate methods to register the NetworkAgent and
  mark it connected for cases where the test needs to make
  changes to the NetworkAgent before connecting (e.g., poking
  NetworkMonitor).
- Putting the TestNetworkAgentWrapper inside MockVpn and driving
  it through MockVpn's methods. In order not to have too many
  wrapper functions (and because we can't delegate like in
  Kotlin), there's still an agent() method that returns the
  TestNetworkAgentWrapper.

Bug: 173331190
Test: test-only change
Change-Id: I749ff325bc13ac96f512270b86d1f67686eec378
2020-11-19 16:23:07 +09:00
Lorenzo Colitti
e42d10a803 Increase test coverage for VPN info sent to NetworkStatsService.
Bug: 173331190
Test: test-only change
Change-Id: I3711b362f31cb92b759e9f5c9d244fb88d9bd5e7
2020-11-19 14:56:50 +09:00
Lorenzo Colitti
3581b34f69 Simplify MockVpn.
This CL removes four methods in MockVpn by slightly changing the
test code to leverage the actual methods implemented by the
(production) Vpn superclass.

This works because setting mInterface results in
isRunningLocked() returning true, which makes a number of methods
behave as if the VPN is connected (which is what the test
expects).

The more realistic behaviour exposes a minor bug in the treatment
of underlying networks. Add a TODO to fix it.

Bug: 173331190
Test: test-only change
Change-Id: I49421183538ba61ca790af71e309ece36b653bf9
2020-11-19 14:53:53 +09:00
Lorenzo Colitti
d00e0b8757 Test a VPN with an underlying network that does not yet exist.
This test checks that if a VPN declares an underlying network
that does not exist, the capabilities of that network are applied
to the VPN as soon as the network starts to exist.

Bug: 173331190
Test: test-only change
Change-Id: Icc0701cb4cea7d91f7738c1e426e94cd26686b74
2020-11-19 14:46:32 +09:00