Commit Graph

2588 Commits

Author SHA1 Message Date
Chiachang Wang
aa88bca82b Update state in NetworkInfo when network resumes
State override is only handled when state is changed from
CONNECTED to SUSPENDED but not reverse path. Handle both ways
for SUSPENDED state.

Bug: 148678431
Test: FrameworkNetTests
Change-Id: I9333f865d61bbf008fdb8ca162ad17dfdffd1d67
2020-02-14 16:41:33 +08:00
Benedict Wong
0bd4bba07a Enforce restricted user, getConnectionOwnerUid checks
This CL adds checks to ensure restricted users cannot change or
start/stop platform VPNs. In addition, this also adds checks to the
ConnectivityManager#getConnectionOwnerUid() to ensure that only
VpnService based VPNs can identify connections

Bug: 148040659
Test: FrameworksNetTests run
Change-Id: Id47ada5766036bfc84f3ba47f66f2d2683af916d
2020-02-14 00:09:47 -08:00
Roshan Pius
02d8578fc3 Merge "RELAND: NetworkRequest: Embed requestor uid & packageName" 2020-02-14 01:57:49 +00:00
Chiachang Wang
d0f3cb625e Merge "Add permission check for CaptivePortal#reevaluateNetwork" 2020-02-13 06:41:53 +00:00
Roshan Pius
08c94fb8a9 RELAND: NetworkRequest: Embed requestor uid & packageName
Add the requestorUid & requestorPackageName fields to
NetworkCapabilities. This is populated by CS when
a new network request is received.
These 2 requestor fields are also optionally used for network
matching. All of the regular app initiated requests will have the
requestor uid and package name set by connectivity service. Network
agents can optionally set the requestorUid and requestorPackageName
to restrict the network created only to the app that requested the network.

This will help removing the necessity for the various specifiers to embed
the uid & package name info in the specifier for network matching.

Note: NetworkSpecifier.assertValidFromUid() is deprecated & removed in
favor of setting the uid/package name on the agent to restrict the
network to a certain app (useful for wifi peer to peer API & wifi aware).

Bug: 144102365
Test: Verified that wifi network request related CTS verifier tests
pass.
Test: Device boots up and connects to wifi networks
Merged-In: I207c446108afdac7ee2c25e6bbcbc37c4e3f6529

Change-Id: I58775e82aa7725aac5aa27ca9d2b5ee8f0be4242
2020-02-12 16:58:36 -08:00
Roshan Pius
948f0f9878 Merge "Revert "NetworkRequest: Embed requestor uid & packageName"" 2020-02-12 23:36:13 +00:00
Roshan Pius
d85de75bfa Revert "NetworkRequest: Embed requestor uid & packageName"
This reverts commit d499517306.

Reason for revert: b/149425896
Bug: b/149425896

Change-Id: I9fe31509c040cc421ccb00ea60f15e6f199e8bc6
2020-02-12 23:33:43 +00:00
Qingxi Li
7b59ec507c Merge "NetworkRequest: Embed requestor uid & packageName" 2020-02-12 18:43:32 +00:00
Cody Kesting
287c4adbc9 Merge "Include NetworkCapabilities and LinkProperties in DataStallReport." 2020-02-12 16:38:38 +00:00
Chalard Jean
b10ab41350 [NS B10] Cleanup : remove mRematchedNetworks
This is better computed by the code that applies the change
than by the code that computes the reassignment

Test: FrameworksNetTests
Change-Id: I13e2764fd9b29145499085c3bb56de88a97d6c3c
2020-02-12 21:23:45 +09:00
Chalard Jean
96a4f4b8de [NS B09] Create NetworkRanker
Bug: 113554781
Test: FrameworksNetTests
Change-Id: Ia534247144f479fe896e1a6e05b906103cd10005
2020-02-12 20:57:45 +09:00
Chalard Jean
f955f8eb6c [NS B08] More simplification
Only computing the reassignment does not actually change the
default network.

Test: FrameworksNetTests
Change-Id: I21ddf5cc1e3d3817055dbda4246e38ceb0732407
2020-02-12 20:57:44 +09:00
Chalard Jean
a6014db965 [NS B07] More simplification
The new reassignment does not contain these useless lines
any more.

Test: FrameworksNetTests
Change-Id: I1583aebe94e529ce2b36e191a6e1f49c976bf29a
2020-02-12 20:57:44 +09:00
Chalard Jean
46a62378ec [NS B06] Simplification
This check is now unnecessary, seeing how the code adding these
changes is now guaranteed to only add at most one change for
each request.

Test: FrameworksNetTests
Change-Id: Ia0443602d9c89ee413e956df9c7b79f8f74813f7
2020-02-12 20:57:43 +09:00
Chalard Jean
7feb6ed384 [NS B05] Remove old dead code
Test: FrameworksNetTests
Change-Id: I553721b327b76ede0e76b9fb7a0130fcae012175
2020-02-12 20:52:17 +09:00
Chalard Jean
857a1719a1 [NS B04] Make the network selection request-major.
This patch marks the most important turning point of this
refactoring. Cleanups removing unused code will follow.

Replace the old network-major reassignment computation with a
much simpler and faster loop that takes each request and assigns
it the highest-scoring network.

All tests pass, of course.

Bug: 113554781
Test: FrameworksNetTests
Change-Id: Ie143802995155151a38a4eb1d2f26c3f29e556bd
2020-02-12 20:52:17 +09:00
Chalard Jean
4970757c26 [NS B03] Add debug log showing the reassignment
dumpString for a reassignment looks like :

NetworkReassignment :
  Rematched networks : [100 CELLULAR], [101 WIFI]
  6 : 100 → 101
  8 : null → 101

toString looks like :

NetReassign [4 : 100 → 101, 5 : null → 101]

If no changes, then it looks like
NetworkReassignment : no changes

Bug: 113554781
Test: Manual
Change-Id: If9eeadb7ee317dee2d91ca1feca3091ae39e9bae
2020-02-12 20:52:17 +09:00
Chalard Jean
d7f762d7be [NS B02] Split out a function to apply a NetworkReassignment
This makes the rematchAllNetworksAndRequests function, which
is the nexus of the rematching code, very straightforward and
easy to read.

Bug: 113554781
Test: FrameworksNetTests
Change-Id: I5cea4ed7e06439494700d88ab202b696402fa360
2020-02-12 20:52:17 +09:00
Chalard Jean
57cc7cb461 [NS B01] Move the computation loop to a separate function
Bug: 113554781
Test: FrameworksNetTests
Change-Id: I6c28c7af5c600d35aa1e9328b6c988dadb921f51
2020-02-12 20:52:17 +09:00
Chalard Jean
64520dc488 [NS A44 2/2] Apply requests after all networks rematching is computed
This patch finally separates completely computing the rematch
from all the side effects. A collateral effect of this is to
compute correctly the background network state in
rematchNetworkAndRequests, which compensates the breakage
from the previous patch.

Bug: 113554781
Test: ConnectivityServiceTest
Change-Id: I998c729c385940168fcd6ba3f2e01911f1844ce1
2020-02-12 20:52:17 +09:00
Chalard Jean
6a4dfac6b8 [NS A44 1/2] Update linger state before processing listens
To compute accurately whether a network is in the background, the
linger state needs to be updated. Do that before computing whether
a network is in the background and possibly calling
applyBackgroundChangeForRematch.

However ! As of this patch, rematchNetworksAndRequests computes
a wrong value when adding to the list of affected networks, because
it is looking at intermediate global state. Somehow this used to
compensate exactly for the way reading back the state was wrong.
There might have been a few undetected bugs there, but none is
known.

As such, as of this patch, rematchNetworksAndRequests still
computes a wrong value while the computation when applying that
state now computes the right one, so the tests do not pass.
This patch must be checked in together with A44 2/2 which will
fix the computation in rematchNetworksAndRequests, but is kept
separate for ease of review.

Bug: 113554781
Test: ConnectivityServiceTest
Change-Id: Iaeed0d11bfa09f292f232ae020e944e430bc0184
2020-02-12 20:52:17 +09:00
Chiachang Wang
f7a0f125db Add permission check for CaptivePortal#reevaluateNetwork
CaptivePortal#reevaluateNetwork is added as a system API which
requires a proper permission check.

Bug: 148379628
Test: Manually check with captive portal
Test: atest FrameworksNetTests
Test: make test-api-stubs-docs-update-current-api \
      system-api-stubs-docs-update-current-api

Change-Id: I3f974339d5bd53a6f6ecb0842c02a8264dc3a5f9
Merged-In: I559d42089aeb09801d14c251c5165fca793c3cb3
2020-02-12 11:29:24 +00:00
Roshan Pius
d499517306 NetworkRequest: Embed requestor uid & packageName
Add the requestorUid & requestorPackageName fields to
NetworkCapabilities. This is populated by CS when
a new network request is received.
These 2 requestor fields are also optionally used for network
matching. All of the regular app initiated requests will have the
requestor uid and package name set by connectivity service. Network
agents can optionally set the requestorUid and requestorPackageName
to restrict the network created only to the app that requested the network.

This will help removing the necessity for the various specifiers to embed
the uid & package name info in the specifier for network matching.

Note: NetworkSpecifier.assertValidFromUid() is deprecated & removed in
favor of setting the uid/package name on the agent to restrict the
network to a certain app (useful for wifi peer to peer API & wifi aware).

Bug: 144102365
Test: Verified that wifi network request related CTS verifier tests
pass.
Test: Device boots up and connects to wifi networks
Change-Id: I207c446108afdac7ee2c25e6bbcbc37c4e3f6529
Merged-In: I207c446108afdac7ee2c25e6bbcbc37c4e3f6529
2020-02-12 04:42:58 +00:00
Cody Kesting
f2852480a0 Include NetworkCapabilities and LinkProperties in DataStallReport.
DataStallReport is updated to include the NetworkCapabilities and Link
Properties for the Network being reported on. This provides a more
complete picture of the Network conditions when the suspected data stall
was detected.

Bug: 148966398
Test: atest FrameworksNetTests
Change-Id: I913cf18c348b9f688f9d2a3d25a71bc94eb8f000
2020-02-11 08:50:59 -08:00
Chalard Jean
30394e2a2b Merge "[NS A43] Separate updating the linger timer and sending LOSING" 2020-02-09 06:51:06 +00:00
Chalard Jean
358eb47a06 Merge "[NS A42] Move writing to the reassignment to the computation" 2020-02-09 06:50:48 +00:00
Chalard Jean
2d45ce0b69 Merge "[NS A41] Cut out a function to update NAI info" 2020-02-09 04:56:37 +00:00
Cody Kesting
0b3645740c Merge "Fire ConnectivityDiagnostics callbacks on Connectivity reported." 2020-02-06 15:54:06 +00:00
Cody Kesting
daeccbf13e Merge "Implement INetworkMonitorCallbacks#notifyDataStallSuspected." 2020-02-06 15:47:26 +00:00
Chalard Jean
8fd82aea7e [NS A43] Separate updating the linger timer and sending LOSING
This will be necessary because updating the linger timer is
what lets the network agent know whether the network is

Test: ConnectivityServiceTest
Change-Id: I9b5a36f6d5eac5a404eff6740cd8f4dcbb0c2786
2020-02-06 18:04:13 +09:00
Chalard Jean
383f5ef79a [NS A42] Move writing to the reassignment to the computation
...instead of the side effect loop. This is a no-op refactoring.

Test: ConnectivityServiceTest
Change-Id: I8308d55eaff080efb22a7a43142492545e626cf5
2020-02-06 18:04:09 +09:00
Chalard Jean
24344d7e72 [NS A41] Cut out a function to update NAI info
Test: ConnectivityServiceTest
Change-Id: I6d92fb1699eb0acb1bcd7baa4a5d9d3e1c0dc728
2020-02-06 18:03:30 +09:00
Chalard Jean
47dad79bf6 Merge "[NS A40] Read current reassignment state instead of global state" 2020-02-06 04:14:43 +00:00
Cody Kesting
5a9a2ae4b4 Fire ConnectivityDiagnostics callbacks on Connectivity reported.
When ConnectivityService#reportNetworkTested is called, the platform
needs to fire ConnectivityDiagnostics callbacks for registered callbacks
that are permissioned for the network being reported on. This adds a new
event to ConnectivityDiagnosticsHandler for invoking these callbacks.

Bug: 143187964
Test: compiles
Test: atest CtsNetTestCases ConnectivityServiceTest
Change-Id: Icc6bcf7a2411133d8ecd7477bc351dad9333f24f
Merged-In: Icc6bcf7a2411133d8ecd7477bc351dad9333f24f
2020-02-05 15:05:29 -08:00
Cody Kesting
b12ad4ca3a Implement INetworkMonitorCallbacks#notifyDataStallSuspected.
INetworkMonitorCallbacks defines notifyDataStallSuspected() for
notifying ConnectivityService of networks encountering a potential data
stall. A new event is introduced for ConnectivityDiagnosticsHandler to
process the notification and invoke the relevant
ConnectivityDiagnosticsCallbacks.

Bug: 143187964
Test: compiles
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: I70320bdda9855dced31e08e6a0b25329fb5cb535
Merged-In: I70320bdda9855dced31e08e6a0b25329fb5cb535
2020-02-05 15:05:28 -08:00
Cody Kesting
e10545c736 Merge "Implement INetworkMonitorCallbacks#notifyNetworkTestedWithExtras." 2020-02-05 19:55:05 +00:00
Cody Kesting
83bb5fa762 Implement INetworkMonitorCallbacks#notifyNetworkTestedWithExtras.
INetworkMonitorCallbacks defines notifyNetworkTestedWithExtras() for
notifying ConnectivityService of networks being tested along with a
PersistableBundle of extras. A new event is introduced for
NetworkStateTrackerHandler to notify the ConnectivityDiagnosticsHandler
before continuing with the normal processing for "network tested"
notifications. The event is also used in the
ConnectivityDiagnosticsHandler.

Bug: 143187964
Bug: 147391402
Test: compiles.
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: Iab29da790c0f5faae68227770bc3a84bbc94f124
Merged-In: Iab29da790c0f5faae68227770bc3a84bbc94f124
2020-02-05 18:48:12 +00:00
Chalard Jean
f1211e9531 Merge changes Ic1a5d032,I271e7f4d,I7af37281
* changes:
  [NS A39] Simplification
  [NS A38] Fill the initial reassignment
  [NS A37] Don't reassign requests multiple times
2020-02-05 00:53:28 +00:00
Benedict Wong
e2684df6ef Merge "Add separate user consent for Platform VPNs" 2020-02-04 23:56:16 +00:00
Benedict Wong
a73199168b Add separate user consent for Platform VPNs
This change adds a new VPN user consent flow (using the same text) for
granting the lesser OP_ACTIVATE_PLATFORM_VPN. A new
PlatformVpnConfirmDialog is created as a subclass to preserve all logic,
but ensure the right appop is granted for the relevant dialog.

Intent extras were considered, but are inherently unsafe, since the
caller may add any extras that they would want.

Bug: 144246835
Test: FrameworksNetTests passing
Change-Id: Ia6f36207d43c3748f938430c2780dcf29e5623f3
Merged-In: Ia6f36207d43c3748f938430c2780dcf29e5623f3
2020-02-04 21:05:36 +00:00
Chalard Jean
7e416aa19e [NS A40] Read current reassignment state instead of global state
The reassignment state has the future value, but is transient
instead of global. With this, the reassignment loop does not
read from global state any more, so it's not affected by the
side effects from the loop.

This means future patches will be able to move the side effects
out of the computation.

Test: atest ConnectivityServiceTest
Change-Id: I43499f19730bcd94b691cfea83aa1ca1d3de75db
2020-02-04 21:18:25 +09:00
Chalard Jean
933ebfa503 [NS A39] Simplification
If newNetwork is satisfying this request, it means it is the old
satisfier. Plain and simple.

Test: ConnectivityServiceTest
Change-Id: Ic1a5d032801bac476b1c1f53da6f1c4c6056bff0
2020-02-04 16:49:54 +09:00
Chalard Jean
84292aaa46 [NS A38] Fill the initial reassignment
This is more expensive for now but it will allow subsequent patches
to read relevant state from the reassignment instead of from the
global state, which will stop the computation of the reassignment
from reading state that is mutated by the same loop. Eventually
this lets us completely split the computation from the side effects.
The ugly parts of this patch will be cleaned up later as a result,
namely in patches [NS B04] and [NS B05].

Test: ConnectivityServiceTest
Change-Id: I271e7f4d4bc81493c1ea212025b7130619592a8a
2020-02-04 16:49:54 +09:00
Chalard Jean
bf91f5f182 [NS A37] Don't reassign requests multiple times
This is an optimization that skips doing intermediate assignments
of networks to requests that will undergo multiple changes during
the recomputation.
It happens to fix a bug where some of these intermediate states
used to have a visible, transient side effect.

Bug: 113554781
Test: ConnectivityServiceTest
Change-Id: I7af3728152a1cf7571de67f394088a5970ee3c1e
2020-02-04 16:49:54 +09:00
Chalard Jean
04bc807898 [NS A35] Send updated scores to factories at the end.
Test: ConnectivityServiceTests
Change-Id: I66c4e8f52e11bc7e199dd8c12d43b0b136a21f19
2020-02-04 16:49:53 +09:00
Chalard Jean
adf1aafb53 [NS A34] Still more simplification
Test: ConnectivityServiceTest
Change-Id: I85247411eb8fdfb3eae0e7c309ea9537e41cfb80
2020-02-04 16:49:53 +09:00
Chalard Jean
8e382110b8 [NS A33] Unify changing the default network
makeDefault() will be called in rematchAllNetworksAndRequests
in all cases and its first job is to set mDefaultNetwork.

The old code checks if the currently processing request is
the default request and assigns mDefaultNetwork if it is,
doing it earlier than in the new code iff the new default is
not null. However there is no good reason to assign this
member earlier in the non-null case than in the null case,
it's simpler if the same code path is used in both cases.
mDefaultNetwork is also not used between the old place where
it was set and the new place where it is set, so changing
the timing of the assignment has no observable side effects.

Test: ConnectivityServiceTest
Change-Id: Id47c19b73650ba66bff73b07edb8fd95c707e699
2020-02-04 16:49:52 +09:00
Chalard Jean
00419abe9e [NS A32] More simplification
Test: FrameworksNetTests
Change-Id: Ib713c4ae0100c8c242bbba87b2881311c5761869
2020-02-04 16:29:01 +09:00
Chalard Jean
967190ecd0 [NS A31] Simplification
The condition this is testing for cannot actually be false.

The only place where the code writes a null value into this
map is at the end of computeRequestReassignmentForNetwork :
reassignedRequests.put(nri, null).
This proves the code the if() block, which proves that
newNetwork.isSatisfyingRequest(nri.request.requestId) is true.

By definition newNetwork.isSatisfyingRequest(nri) implies that
nri.mSatifier == newNetwork, which proves that
previousSatisfier == newNetwork whenever newSatisfier is null.

Fixes: 146482072
Test: FrameworksNetTests
Change-Id: Ifd6faedce7d49757b82a5f341076ab208b0ccfcb
2020-02-04 16:28:20 +09:00
Chalard Jean
bf021685ca [NS A30] Note linger out of the rematch loop
This doesn't have to be tested every time.

Test: FrameworksNetTests
Change-Id: Ic5702c8b4bd096860fe55c4d9e4c465703561911
2020-02-04 16:24:23 +09:00