Commit Graph

48 Commits

Author SHA1 Message Date
Remi NGUYEN VAN
b5f0819d35 Move ConnectivityDiagnosticsManagerTest to common
The tests are also useful in CTS to ensure that the
ConnectivityDiagnosticsManager class API is implemented properly
(including behavior of the DataStallReport class for example).

Bug: 187935317
Test: atest ConnectivityDiagnosticsManagerTest
Original-Change: https://android-review.googlesource.com/1742075
Merged-In: I86f39238054f43403f9a1e383dd2a935de84f06f
Change-Id: I86f39238054f43403f9a1e383dd2a935de84f06f
2021-06-23 09:16:53 +00:00
Lucas Lin
1b64ae6b87 Merge "Send a proxy broadcast when apps moved from/to a VPN" into sc-dev 2021-06-18 02:47:24 +00:00
Lucas Lin
950a65f8cc Send a proxy broadcast when apps moved from/to a VPN
When the apps moved from/to a VPN, a proxy broadcast is needed to
inform the apps that the proxy might be changed since the default
network satisfied by the apps might also changed.
Since the framework does not track the defautlt network of every
apps, thus, this is done when:
  1. VPN connects/disconnects.
  2. List of uids that apply to the VPN has changed.
While 1 is already covered by the current design, the CL implements
2 in order to fulfill the case that different networks have
different proxies.

Bug: 178727215
Test: atest FrameworksNetTests
Original-Change: https://android-review.googlesource.com/1717735
Merged-In: Ifa103dd66394026d752b407a1bee740c9fcdad2b
Change-Id: Ifa103dd66394026d752b407a1bee740c9fcdad2b
2021-06-17 11:10:46 +00:00
James Mattis
b7ca034306 Update CS so that per-app OEM APIs can be tested
Updates to ConnectivityService so that the set OEM network preference
per app APIs can be tested via CTS.

Bug: 176496580
Bug: 176494815
Test: atest FrameworksNetTests
atest FrameworksNetIntegrationTests
atest CtsNetTestCasesLatestSdk

Original-Change: https://android-review.googlesource.com/1723050
Merged-In: I5a47dcece31749293f080af060218d827082eb67
Change-Id: I5a47dcece31749293f080af060218d827082eb67
2021-06-16 03:54:47 +00:00
Lorenzo Colitti
659a0e145f Correctly get uids for per-app network preferences
Per-app network functionality assumed all apps were installed for user 0
which is not always the case. This fix will address that by checking for
the existance of an app for all users and adding it to the per-app
network preference as was originally intended. Prior, no apps were
included if they were not installed for user 0 even if they were
available for another user such as user 10 in automotive.

Bug: 189838408
Test: atest FrameworksNetTests
atest FrameworksNetIntegrationTests
atest CtsNetTestCases

Original-Change: https://android-review.googlesource.com/1723617
Merged-In: I7d75cdb02041e7a202254be2eaeca6c2b02d7c29
Change-Id: I7d75cdb02041e7a202254be2eaeca6c2b02d7c29
2021-06-15 21:56:13 +00:00
TreeHugger Robot
97e90536a8 Merge "Add unit test when querying TYPE_WIFI + null/empty/non-null subscriberId" into sc-dev 2021-06-15 09:16:57 +00:00
Les Lee
caa6f1793d Add unit test when querying TYPE_WIFI + null/empty/non-null subscriberId
Starting with API level 31, the subscriberId is applicable
for the wifi network. Considering applications may use
null or an empty string as subscriberId (for instance, cts),
frameworks create MATCH_WIFI_WILDCARD NetworkTemplate when querying
wifi network with null or an empty string which is the behavior before
API level 31.

Bug: 188915450
Test: atest -c NetworkStatsManagerTest
Merged-In: Id4ae06840e1749997e970b8f1ec391060967bd47
Change-Id: Id4ae06840e1749997e970b8f1ec391060967bd47
2021-06-15 14:53:25 +08:00
Luke Huang
fcc69726ed Merge "Modify NsdServiceTest to conform to its new mechanism" into sc-dev 2021-06-15 04:52:43 +00:00
Paul Hu
dcba997adf Merge "Add DEFAULT_NETWORK_PRIORITY constants" into sc-dev 2021-06-14 15:17:23 +00:00
Paul Hu
7d5fa3da7d Merge "Add more unit tests for mobile data preferred uids feature" into sc-dev 2021-06-14 14:29:29 +00:00
Luke Huang
a46c4d2726 Modify NsdServiceTest to conform to its new mechanism
Adapt NsdServiceTest to its new mechanism for starting/stopping daemons.
Also, add a new test for the new self-cleanup mechanism.

Bug: 181810560
Test: atest NsdServiceTest
Original-Change: https://android-review.googlesource.com/1719018
Merged-In: I4c485a5d8fb4d6f52d82633a579bce4feb5c6375
Change-Id: I4c485a5d8fb4d6f52d82633a579bce4feb5c6375
2021-06-14 06:53:51 +00:00
Lorenzo Colitti
beb7d92cbc Don't send onLinkPropertiesChanged after onLost for 464xlat.
Currently, when a network that uses 464xlat is torn down,
NetworkCallbacks will receive onLinkPropertiesChanged after
onLost. This is confusing and incorrect.

The incorrect callback is sent because handleLinkProperties
checks that the netId of the agent still exists, not that the
NetworkAgent is still registered. This is normally correct,
because the NetworkAgent is removed from mNetworkAgentInfos and
the netId are removed from mNetworkForNetId by the same method,
disconnectAndDestroyNetwork.

In this specific case it's not correct, because the call to
handleUpdateLinkProperties is from disconnectAndDestroyNetwork
itself via nai.clatd.update and calls Nat464Xlat#stop.

No other callers of handleUpdateLinkProperties are affected
because:

- EVENT_NETWORK_PROPERTIES_CHANGED is called only by
  maybeHandleNetworkAgentMessage, which first checks that the
  NetworkAgent is registered.
- handlePrivateDnsSettingsChanged only looks at registered
  NetworkAgents (it loops over mNetworkAgentInfos).
- handlePrivateDnsValidationUpdate, handleNat64PrefixEvent and
  handleCapportApiDataUpdate call getNetworkAgentInfoForNetId,
  which will correctly determine that the agent is no longer
  registered, since they run on the handler thread and thus
  cannot run at the same time as disconnectAndDestroyNetwork.

The existing code contains a check for the netId being current.
This is intended to ensure that an update from a NetworkAgent
cannot affect another agent with the same Network. This extra
check is not necessary, because code running on the handler
thread can never observe a NetworkAgent in mNetworkAgentInfos
unless mNetworkForNetId maps that NetworkAgent's Network to that
NetworkAgent. This is because mNetworkForNetId is updated by the
same methods as mNetworkAgentInfos, and those updates occur on
the handler thread. So all code on the handler thread will see
those two as consistent.

Bug: 176496580
Test: atest FrameworksNetTests CtsNetTestCases HostsideVpnTests
Original-Change: https://android-review.googlesource.com/1727829
Merged-In: I944f4c6ad36206bdccd85a6ea7ef71324a29c685
Change-Id: I944f4c6ad36206bdccd85a6ea7ef71324a29c685
2021-06-11 13:46:33 +00:00
Lorenzo Colitti
cfa262d8b8 Improve test coverage for disconnecting networks with clat.
Ensure that NetworkCallbacks and netd operations are accounted
for. Also add a test for the spurious onLinkPropertiesChanged
callback that is currently send out after onLost.

Bug: 176496580
Test: atest ConnectivityServiceTest
Original-Change: https://android-review.googlesource.com/1729093
Merged-In: I69cf58bc87dfe55ea359a2cd76167d03fe2c953d
Change-Id: I69cf58bc87dfe55ea359a2cd76167d03fe2c953d
2021-06-11 13:44:46 +00:00
paulhu
c2198778ab Add DEFAULT_NETWORK_PRIORITY constants
- Add default network priority to NetworkRequestInfo.
- The default network priority value is used when issue uid
  ranges rules to netd. Netd will use the priority value and uid
  ranges to generate corresponding ip rules specific to the given
  network preference.

Bug: 171872461
Test: atest FrameworksNetTests
Ignore-AOSP-First: Needs cherry-picks
Change-Id: I0ea71b348492aeb4784d487bed4cfd5d387426ba
2021-06-11 14:22:33 +08:00
paulhu
7ed70a944c Add more unit tests for mobile data preferred uids feature
- Add more tests for mobile data preferred uids.
- Also address leftover comments on implementation commit.

Bug: 171872461
Test: atest FrameworksNetTests
Ignore-AOSP-First: Needs cherry-picks
Change-Id: I63f65bffc1b8883ddfd774222e26e629d7ea1f94
2021-06-11 00:09:45 +08:00
Treehugger Robot
27b6888364 Require location permission for ConnDiags WiFi only.
This CL updates ConnectivityDiagnostics permission checks in
ConnectivityService to only require location permission for Networks
that have TRANSPORT_WIFI. This change is consistent with the location
restrictions required for the transports themselves. Previously,
location permissions were required for all Network types.

Bug: 187310575
Test: atest ConnectivityServiceTest ConnectivityDiagnosticsManagerTest
Change-Id: I48806533e4e705d2d9be45f3b3d3931d9294b167
Merged-In: I48806533e4e705d2d9be45f3b3d3931d9294b167
(cherry picked from commit 0990af5148)
2021-06-07 22:17:05 +00:00
Paul Hu
48fc715694 Merge "Move UIDS_ALLOWED_ON_RESTRICTED_NETWORKS setting" into sc-dev 2021-06-07 09:29:56 +00:00
Paul Hu
9a8e4497a3 Merge "Address leftover comments" into sc-dev 2021-06-07 08:50:21 +00:00
paulhu
71ad4f1175 Implement mobile data preferred uids feature
- Read MOBILE_DATA_PREFERRED_UIDS setting when system ready
- Register MOBILE_DATA_PREFERRED_UIDS setting observer
- Send uid ranges to netd when update mobile data preferred uids

Bug: 171872461
Test: atest FrameworksNetTests
Ignore-AOSP-First: Needs cherry-picks
Change-Id: I5153c770650594e05dfa8cf230d7381d790f4a55
2021-06-02 15:40:53 +08:00
paulhu
a1ac564748 Move UIDS_ALLOWED_ON_RESTRICTED_NETWORKS setting
Now, PermissionMonitor reigster observer to listen the change
from all users, but "uids allowed on restricted networks" should
affect to all users instead of per each user. Thus, move the
setting from Settings.Secure to Settings.Global.

Bug: 189705071
Test: atest FrameworksNetTests
Ignore-AOSP-First: Need cherry-pick
Change-Id: Ibea354d8dda1f02652a193820f3f9eb573b9a956
2021-06-01 21:28:34 +08:00
paulhu
5d8340f7ae Address leftover comments
- Add comment to highestPermissionForUid()
- Add testAppsAllowedOnRestrictedNetworksChangedMultipleUsers
- Add synchronized to guard mUidsAllowedOnRestrictedNetworks
  access.

Bug: 189705071
Test: atest FrameworksNetTests
Ignore-AOSP-First: Need cherry-pick
Change-Id: I9056758db15e8a21b84ef244d4cacf24c3b79894
2021-06-01 19:04:28 +08:00
paulhu
68aacb407a Update allowed on restricted networks getter/setter
As API review feedback, setting allowed on restricted networks
should be by uid instead of package name for security reason.
Thus, update the getter/setter to return/accept set of uids.

Bug: 188085693
Test: atest FrameworksNetTests
Ignore-AOSP-First: Needs cherry-picks
Change-Id: I979bf98075e6c9c0ed7e891582843fddb62643cb
2021-05-26 16:16:57 +08:00
TreeHugger Robot
958fe9a51d Merge changes I1de322c9,Id0983d4b into sc-dev
* changes:
  Improve IKEv2/IPsec VPN by proposing more IPsec algorithms
  Improve IKEv2/IPsec VPN by proposing more IKE algorithms
2021-05-22 05:05:51 +00:00
Yan Yan
f1ea9b302c Improve IKEv2/IPsec VPN by proposing more IPsec algorithms
This commit allows IKEv2/IPsec VPN to propose more algorithms that
newly added in IpSecAlgorithm. Those new algorithms have stronger
security guarantees and better performances.

This commit also removes algorithm name validation because all
algorithms are URL encoded to ensure no special characters create
problems due to their use by VpnProfile for list or field delimiting
(e.g. rfc7539esp(chacha20,poly1305))

Bug: 185265778
Test: atest FrameworksNetTests, CtsNetTestCases
Test: All new algorithms are manually verified
Change-Id: I1de322c95aacc8924e95bcdbcfdbd1ec441de99c
Merged-In: I1de322c95aacc8924e95bcdbcfdbd1ec441de99c
2021-05-21 23:33:23 +00:00
Cody Kesting
0b4be0203d Check location permission for ConnDiags last.
This CL updates ConnectivityService to check location permissions for
ConnectivityDiagnostics callbacks last in the permission check process.
This minimizes misattribution of location access for networks that an
app is not administering.

This CL also updates ConnectivityDiagnosticsManager documentation to
clearly state that location permissions are required in order to receive
callbacks.

Bug: 187310575
Test: atest ConnectivityDiagnosticsManagerTest
Test: atest ConnectivityServiceTest
Change-Id: I2dbeddac6273e2392ccaeae51a1c7776d6d3da75
Merged-In: I2dbeddac6273e2392ccaeae51a1c7776d6d3da75
(cherry picked from commit f3d0fc49db)
2021-05-21 16:22:50 +00:00
TreeHugger Robot
f9d1bbb566 Merge "Add more unit tests for ConnectivityManager S APIs" into sc-dev 2021-05-20 16:32:19 +00:00
Les Lee
627c446560 Merge "Support to query TYPE_WIFI usage with subscriberId" into sc-dev 2021-05-20 08:55:59 +00:00
Paul Hu
5acfe4933e Merge "Register APPS_ALLOWED_ON_RESTRICTED_NETWORKS setting observer" into sc-dev 2021-05-20 08:45:35 +00:00
Paul Hu
740da160bc Merge "Read APPS_ALLOWED_ON_RESTRICTED_NETWORKS setting from PermissionMonitor" into sc-dev 2021-05-20 05:57:25 +00:00
Junyu Lai
ffda3053d1 Add more unit tests for ConnectivityManager S APIs
Ignore-AOSP-First: Avoid merge conflict
Test: atest android.net.ConnectivityManagerTest
Bug: 188657173
Change-Id: I33612650eb89486a14fcfc440ba0c357f4bb513c
2021-05-19 15:34:38 +00:00
Les Lee
8a2405cb6d Merge "Add metered filter for API: buildTemplateCarrier" into sc-dev 2021-05-19 14:32:29 +00:00
Junyu Lai
458a60dab5 Merge changes I3ba50cbd,I970ee365 into sc-dev
* changes:
  [FUI29] Migrate ConnectivityService to use getAllNetworkStateSnapshots
  [FUI27] Fix internal naming of notifyNetworkStatus
2021-05-19 12:36:03 +00:00
lesl
f96f02703e Add metered filter for API: buildTemplateCarrier
This CL modifies NetworkTemplate#buildTemplateCarrier to force on
metered carrier network and rename to buildTemplateCarrierMetered.
This method was introduced recently and has no callers.

This method will be used in Settings and NetworkPolicyManagerService
to display and manage data usage on carrier metered networks.

Settings/NetworkPolicyManagerService will use it instead of the existing
method buildTemplateMobileAll method, which only matches metered networks.
That code will change from matching metered mobile networks to matching
metered carrier networks.

Note: The carrier metered network includes metered mobile network and
metered "merged carrier wifi network" that is a specific cerrier wifi network
which provides the same user experience as mobile.

Bug: 176396812
Test: atest -c NetworkTemplateTest
Change-Id: I7196d62bb60844458a6c4b1d94e2baccb71e15cd
Merged-In: I7196d62bb60844458a6c4b1d94e2baccb71e15cd
2021-05-19 02:53:39 +00:00
lesl
cf4a1b59ea Support to query TYPE_WIFI usage with subscriberId
Previous the API ignores subscriberId when network type is WIFI.
Allow caller to call querySummaryXXXX with TYPE: WIFI
+ subscriberId: IMSI to get carrier merged wifi usage which matches the wifi
network with the given IMSI.

Bug: 176396812
Test: atest -c NetworkStatsServiceTest
Change-Id: Ia033521a24e2bb56182d74a41bb2b39710571782
Merged-In: Ia033521a24e2bb56182d74a41bb2b39710571782
2021-05-19 02:53:16 +00:00
Paul Hu
206157788c Register APPS_ALLOWED_ON_RESTRICTED_NETWORKS setting observer
PermissionMonitor register APPS_ALLOWED_ON_RESTRICTED_NETWORKS
setting observer to listen setting changed callback. Then update
or revoke permission for those apps.

Bug: 185149952
Test: atest FrameworksNetTests
Merged-In: I4b6a21bd3f47b7bcaac36fcabf1202a5a84a4520
(clean cherry-pick)

Change-Id: I4b6a21bd3f47b7bcaac36fcabf1202a5a84a4520
2021-05-18 14:19:56 +00:00
Paul Hu
deb3f2e7a7 Read APPS_ALLOWED_ON_RESTRICTED_NETWORKS setting from PermissionMonitor
Let PermissionMonitor read APPS_ALLOWED_ON_RESTRICTED_NETWORKS
setting and grant netd system permission to uids whose package
name is listed in setting.

Bug: 185149952
Test: atest FrameworksNetTests
Merged-In: I856b545c0339a262abbe9d432cfda125bc82dc12
(clean cherry-pick)

Change-Id: I856b545c0339a262abbe9d432cfda125bc82dc12
2021-05-18 14:16:57 +00:00
Lorenzo Colitti
86714b1fd2 Allow unprivileged NetworkCallbacks to see other UIDs' networks.
Currently, unprivileged apps can call getAllNetworks() to see
all networks on the system, even networks that do not apply to
them. Allow them to do this via NetworkCallbacks as well.

This is the last piece of information that was only available
through getAllNetworks, so this CL deprecates that API.

Bug: 187921303
Test: new unit tests
Test: CTS test in other CL in topic
Change-Id: I30f1021927d3c8eae6525116c61ff4a4acecff6d
2021-05-18 12:24:07 +09:00
junyulai
6322aeb7f0 [FUI27] Fix internal naming of notifyNetworkStatus
Test: TH
Bug: 174123988
Merged-In: I970ee365ca221956ee85788005d331374b5fa71a
Change-Id: I970ee365ca221956ee85788005d331374b5fa71a
  (cherry-picked from aosp/1620539)
2021-05-17 14:07:00 +08:00
Jayachandran Chinnakkannu
65a0e0d0e5 Merge "QOS filter matching support based on remote address and port number for connected sockets" am: 6c5553aaaa am: f84276bde1 am: 9896622bd3
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1687813

Change-Id: I04ada71bdea2c3851fd6925126f6ff2bfdecad2c
2021-05-14 21:19:17 +00:00
Jayachandran Chinnakkannu
6c5553aaaa Merge "QOS filter matching support based on remote address and port number for connected sockets" 2021-05-14 20:02:30 +00:00
Junyu Lai
3239a62913 Merge "[FUI26] Address comments on aosp/1560408" am: 8f03f1e788 am: e5929c073c am: 13bcaf5446
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1618845

Change-Id: I8c62d218953027ee2fb5426ddacae5a6f8bb6c73
2021-05-14 12:20:10 +00:00
junyulai
c6422b78ea [FUI26] Address comments on aosp/1560408
Test: TH
Bug: 174123988
Change-Id: I949eeb8903e903d8ede90521442b1f917d5cdfeb
2021-05-14 15:57:44 +08:00
Chalard Jean
6948544a4d Make yield-to-bad-wifi behavior backward compatible with R
Yielding cell wins to exiting wifi (whether good or bad).
It loses to bad wifi that's not exiting.

In R, yielding to bad wifi only affects wifis that are
unvalidated, but a wifi that is exiting should still be
dropped in favor of a cell that yields to bad wifi.

I had misunderstood the policy and implemented it wrong.
Now it's implemented right, and has careful tests.

Test: new tests for this
Bug: 186458024
Change-Id: Ib8637100d491e72a2edb837584ce55b7dda58524
2021-05-14 15:27:12 +09:00
Aaron Huang
9ff12842da Rename *Iface* APIs to *Interface*
Address API review feedback, other APIs have been refering to
these as "interface" instead of "iface" so migrate the APIs named
*Iface* to *Interface*.

(cherry-picked from ag/14326779)
Bug: 183972554
Test: atest android.net.UnderlyingNetworkInfoTest
Merged-In: I38b476e762fb57fa88c4a789092d0af6f5330d80
Change-Id: I38b476e762fb57fa88c4a789092d0af6f5330d80
2021-05-14 11:05:22 +08:00
Jayachandran C
735e1ce55b QOS filter matching support based on remote address and port number for connected sockets
This CL adds APIs for telephony to perform filter matching based on
remote address if the socket is connected. Additional checks will be
performed on the state of socket to avoid the future callbacks in a
separate CL.

Bug: 181916576
Test: Manually verified in live T-Mobile network
      atest ConnectivityServiceTest
      atest com.android.internal.telephony.dataconnection.QosCallbackTrackerTest

Change-Id: I6fbd4e84c76bc4acbf4e59f06f8e86e0237bae29
2021-05-13 09:50:13 -07:00
Lorenzo Colitti
a869887d4f Do not automatically redact TransportInfo objects.
Currently, NetworkCapabilities always redacts the TransportInfo
objects it contains whenever a defensive copy is made. This makes
it impossible to make a defensive copy on a TransportInfo
parcelled from another process without redacting it.

Stop redacting by default; instead rely on ConnectivityService
explicitly calling NetworkCapabilities' redacting constructor
when it returns a NetworkCapabilities object to an app via a
callback or synchronous call. This is currently done by
- createWithLocationInfoSanitizedIfNecessaryWhenParceled, which
  is called from callCallbackForRequest, getNetworkCapabilities,
  and getDefaultNetworkCapabilitiesForUser.
- getNetworkCapabilitiesWithoutUids, which is used when sending
  ConnectivityDiagnosticsManager callbacks. In this method,
  unconditionally redact all information, which is what the code
  did previously due to the default redaction setting for empty
  NetworkCapabilities objects being REDACT_ALL.

Bug: 183938194
Test: atest NetworkCapabilitiesTest
Test: atest FrameworksNetTests CtsNetTestCases HostsideVpnTests
Change-Id: I3108ee94cb0930958e071ba678c3554525b0db82
2021-05-13 20:24:19 +09:00
Remi NGUYEN VAN
31022d6cda Move net unit tests to packages/Connectivity
Move the tests together with packages/Connectivity code, so both can be
moved to packages/modules/Connectivity together.

Also reorganize unit tests in a unit/ directory, as other tests
(integration/, common/ etc.) have been added in tests/net since they
were created. This makes the directory structure consistent.

Test: atest FrameworksNetTests
Bug: 187814163
Merged-In: I254ffd1c08ec058d594b4ea55cbae5505f8497cc

Change-Id: I254ffd1c08ec058d594b4ea55cbae5505f8497cc
2021-05-13 08:30:33 +00:00
Remi NGUYEN VAN
678277cc03 Move net unit tests to packages/Connectivity
Move the tests together with packages/Connectivity code, so both can be
moved to packages/modules/Connectivity together.

Also reorganize unit tests in a unit/ directory, as other tests
(integration/, common/ etc.) have been added in tests/net since they
were created. This makes the directory structure consistent.

Test: atest FrameworksNetTests
Bug: 187814163
Ignore-AOSP-First: needs per-branch move for merge conflicts
Change-Id: I254ffd1c08ec058d594b4ea55cbae5505f8497cc
2021-05-13 05:55:44 +00:00