Commit Graph

43 Commits

Author SHA1 Message Date
paulhu
e99137226e 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
Merged-In: I0ea71b348492aeb4784d487bed4cfd5d387426ba

Change-Id: I0ea71b348492aeb4784d487bed4cfd5d387426ba
2021-06-14 15:55:55 +00:00
paulhu
01f52e7cce 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
Merged-In: I63f65bffc1b8883ddfd774222e26e629d7ea1f94

Change-Id: I63f65bffc1b8883ddfd774222e26e629d7ea1f94
2021-06-14 15:53:05 +00:00
Lorenzo Colitti
473ddeaebb Merge "Correctly get uids for per-app network preferences" 2021-06-14 06:07:56 +00:00
Remi NGUYEN VAN
499219702b Revert "Use shell permission to query current user"
This reverts commit 95bc8d7067.

Reason for revert: Conflict with revert for b/190622577

Change-Id: I993e8da9737634d0cc815cd75b461699170602cc
2021-06-10 15:05:17 +00:00
Remi NGUYEN VAN
95bc8d7067 Use shell permission to query current user
Use shell permissions to obtain CREATE_USERS to call
ActivityManager.getCurrentUser in ConnectivityServiceTest.

This is necessary to allow the tests to run in coverage tests without
the platform certificate.

Bug: 187935317
Test: atest FrameworksNetTests:ConnectivityServiceTest
Change-Id: I5a56ffab4820d351dcdb132046698cd0d3b8bdb1
2021-06-09 19:28:16 +09:00
Junyu Lai
07f97b249c Merge changes from topic "cts-snapshots"
* changes:
  Add CTS for NetworkAgentConfig#setSubscriberId
  Add CTS for getAllNetworkStateSnapshots
  Check NETWORK_SETTINGS permission for getAllNetworkStateSnapshots
2021-06-09 08:09:41 +00:00
Lorenzo Colitti
a3f12dd52c Merge "Don't send onLinkPropertiesChanged after onLost for 464xlat." 2021-06-09 07:59:25 +00:00
junyulai
eaaacb0d47 Check NETWORK_SETTINGS permission for getAllNetworkStateSnapshots
This is declared in the API surface, but the implementation
does not match.

Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testGetAllNetworkStateSnapshots
Bug: 188140631

Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I97aa69651461ebe5c323ec669372f9a61b84e6a6
Change-Id: I97aa69651461ebe5c323ec669372f9a61b84e6a6
  (cherry-picked from ag/14601670)
2021-06-09 01:34:14 +00:00
Lorenzo Colitti
b4bf015b57 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
Change-Id: I944f4c6ad36206bdccd85a6ea7ef71324a29c685
2021-06-08 15:48:57 +09:00
Chalard Jean
550b5214d3 Allow network providers to set the linger duration.
Test: atest CtsNetTestCases:NetworkAgentTest#testSetLingerDuration
CTS-Coverage-Bug: 184796264
Bug: 184227264
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I7f420faa40863385114705d6971cf00887d03318
Change-Id: I7f420faa40863385114705d6971cf00887d03318
  (cherry-picked from ag/14100410)
2021-06-08 00:17:37 +00:00
junyulai
36c02987c6 Fix nascent timer never get removed
By design, the nascent timer will be removed after a network
satisfied first request. However, this never happens.
Because the mInactive is false when that happens, so isNascent
is never true.

Furthermore, when removing a nascent timer, the inactivity
state can never be updated since no condition in the
updateInactivityState will be met to update the state correctly.

Thus, update inactive state accordingly when adding/removing the
nascent timer.

Test: TH
Bug: 184227264
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I4c1521b6e0ef68ac489771a2ab6b09ef3e381577
Change-Id: I4c1521b6e0ef68ac489771a2ab6b09ef3e381577
  (cherry-picked from ag/14060609)
2021-06-08 00:17:37 +00:00
Chalard Jean
c81d4c3c7e [NS13] Remove the last usage of the legacy int
Note that this requires removing part of a test, because
that part is testing that the a 50 bonus of the legacy
int is stronger than the validation penalty, which is
not a mechanic we want to have. When WiFi is unvalidated
and cell is unvalidated, cell should be kept in case it
validates, like is described in comments in
isNetworkPotentialSatisfier ; however this test is
checking that it *IS* reaped off if the wifi score is
strong enough. This should be incorrect, and should not
be tested, so this patch removes the check.

Test: ConnectivityServiceTest
Bug: 184834350
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I8966abee59fea2d9f10f082aba87df6588b72762
Change-Id: I8966abee59fea2d9f10f082aba87df6588b72762
  (cherry-picked from ag/14127306)
2021-06-08 00:17:37 +00:00
Chalard Jean
9f6d447a42 Fix a bug where updates of offers won't find existing offers
.equals() only work on cross-process Binder instances if casted to
a Binder instance first.

Bug: 184281544
Test: ConnectivityServiceTest. CTS test for this specific issue to come
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I7b9e0df21a3cca59659867a75792289ddee2f1d7
Change-Id: I7b9e0df21a3cca59659867a75792289ddee2f1d7
  (cherry-picked from ag/14125149)
2021-06-08 00:17:36 +00:00
Chalard Jean
142f0fe4d4 [NS11] Fix yieldToBadWifi over the policy scoring
This doesn't reactivate the test because it's not yet fixed over int
scoring.

Bug: 184834350
Test: Remove @Ignore and run testAvoidBadWifi
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I32477db52eb50faabc499fa68e24ba07577782aa
Change-Id: I32477db52eb50faabc499fa68e24ba07577782aa
  (cherry-picked from ag/14064906)
2021-06-08 00:17:36 +00:00
Treehugger Robot
5cfbc2e4cc Merge "Require location permission for ConnDiags WiFi only." 2021-06-07 18:44:48 +00:00
Chalard Jean
e4aeac6d75 [NS09] Implement the new ranking code
At this stage, this is turned off. Unit tests will be
in a followup change.

Test: In a followup
Bug: 167544279
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I4448a3546fbc1a3dddf757982c031c5f39ba2889
Change-Id: I4448a3546fbc1a3dddf757982c031c5f39ba2889
  (cherry-picked from ag/14010222 with fixes)
2021-06-07 11:00:46 +00:00
Chalard Jean
f3ff362210 [NS07] Add the rest of the scoring policy
Bug: 167544279
Test: FrameworksNetTests
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I5ea44a94ac6f16486274e9091f15a84734db2341
Change-Id: I5ea44a94ac6f16486274e9091f15a84734db2341
  (cherry-picked from ag/13988828)
2021-06-07 10:57:49 +00:00
Chalard Jean
947acd4275 [NS06] Implement the don't-reap mechanism
This exposes a mechanism for network providers to tell
the network stack that a given network must be kept up
for some specific reason. This is meant to be easier
for them than to have to file a request, in particular
because there is no guaranteed way to make sure the
request will be best matched by any given network.

Test: new test for this
Bug: 167544279
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I238a3ee5ee9262477a23b897e4141769dd1505d1
Change-Id: I238a3ee5ee9262477a23b897e4141769dd1505d1
  (cherry-picked from ag/13929760)
2021-06-07 10:57:49 +00:00
Chalard Jean
0354d8c7e0 [NS05] Feed network offer callbacks
The design is very simply expressed :
An offer is needed for a request if and only if that offer
might beat the satisfier for that request.

The implementation of "might beat" is NetworkRanker#mightBeat.

Test: FrameworksNetTests FrameworksWifiTests NetworkStackTests
Bug: 167544279
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I0fe911eef2483ecbac48c733d56283b81538690a
Change-Id: I0fe911eef2483ecbac48c733d56283b81538690a
  (cherry-picked from 7b6a33bd50)
2021-06-07 10:57:48 +00:00
James Mattis
b6b6a4335a 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

Change-Id: I7d75cdb02041e7a202254be2eaeca6c2b02d7c29
2021-06-06 23:51:05 -07:00
paulhu
51f77dcc49 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
Merged-In: I5153c770650594e05dfa8cf230d7381d790f4a55
(cherry-pick with minor conflicts)

Change-Id: I5153c770650594e05dfa8cf230d7381d790f4a55
2021-06-07 02:55:25 +00:00
Junyu Lai
9756b5d4f9 Merge changes Ia930b3d3,If614da81,I975a9439
* changes:
  [NS04.8] Address comments from NS04 and NS04.5
  [NS04.7] Reinstate a necessary change
  [NS04.5] Have NetworkOffer embark a provider ID
2021-06-04 20:52:38 +00:00
Chalard Jean
dd35f2dab0 [NS04.7] Reinstate a necessary change
NS04.5 removed a security that it shouldn't have. Reinstate it.

Bug: 167544279
Test: ConnectivityServiceTest
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: If614da813a96d1b50a16fa4be5659e1647d9469d
Change-Id: If614da813a96d1b50a16fa4be5659e1647d9469d
  (cherry-picked from ag/13975118)
2021-06-04 02:37:40 +00:00
Chalard Jean
30689b8fd7 [NS04.5] Have NetworkOffer embark a provider ID
...instead of a Messenger.
This will be useful later to compare whether a given offer is
offered by the same provider satisfying a request.

Bug: 167544279
Test: ConnectivityServiceTest
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I975a9439021c7fa511c50ac982819b6dd146291e
Change-Id: I975a9439021c7fa511c50ac982819b6dd146291e
  (cherry-picked from 148dcce559)
2021-06-04 02:36:58 +00:00
Remi NGUYEN VAN
8ae54f7a3e Remove NetdService, NetworkStackClient dependency
Netd should be obtained via getSystemService, and
ModuleNetworkStackClient must be used instead of NetworkStackClient for
modules.

Original change (project moved):
Ibe703ac56dd70673115cd8b95b44b856a7fc01f3

Bug: 171540887
Test: m
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Change-Id: I6c8593712c0e86da139d425ef6240c5004e392e2
2021-06-01 18:41:33 +09:00
Remi NGUYEN VAN
06830749cc Remove ConnectivityService hidden annotations
BoolRes and VpnType are hidden annotations that should not be used in a
module class.

Original change (project moved):
I84690c868ecc62a546ec97bcae2e017a283dc07e

Test: m
Bug: 171540887
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Change-Id: Ie02cff68cf9adf82fc39bde4d2ba2be3255fb3d5
2021-06-01 18:41:05 +09:00
Cody Kesting
7474f67454 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
2021-05-25 13:43:48 -07:00
Treehugger Robot
8d8404ef8f Merge "Use CS identity to update setting while performing factory reset" 2021-05-21 01:26:05 +00:00
Treehugger Robot
049dbc5697 Merge "Use CS identity to update setting while performing factory reset" 2021-05-21 01:26:05 +00:00
Cody Kesting
7f092f1f90 Merge "Check location permission for ConnDiags last." 2021-05-20 21:27:46 +00:00
Cody Kesting
c5f9939bf3 Merge "Check location permission for ConnDiags last." 2021-05-20 21:27:46 +00:00
Chiachang Wang
fe28d9b0ad Use CS identity to update setting while performing factory reset
When apps try to call factoryReset to do networking reset, it
will result in updating the setting in SettingsProvider.
ContentProvider will verify if the package name of the caller
that initiated the request being processed on the current thread.
The package should belong to the calling UID. The setting update
started from the ConnectivityService context, so the package will
be android but the calling UID will be the calling app. It will
cause a SecurityException. The behavior is fine previously as its
known caller(Settings) shares system UID. But it will be a
problem for other callers, such as CTS. Thus, clear the identity
since the necessary permission check should be examined at the
top of the method. The following actions should be fine to be
proceed from the system itself. Also replace the user restriction
check via hasUserRestrictionForUser with the UserHandle created
from the calling uid to ensure it's verified with correct user.

Bug: 186061922
Test: Factory reset from Settings
Change-Id: If2dd69f702a1eafff331f9e71f6b92aeadfb715d
2021-05-20 10:01:50 +08:00
Chiachang Wang
bc66712394 Use CS identity to update setting while performing factory reset
When apps try to call factoryReset to do networking reset, it
will result in updating the setting in SettingsProvider.
ContentProvider will verify if the package name of the caller
that initiated the request being processed on the current thread.
The package should belong to the calling UID. The setting update
started from the ConnectivityService context, so the package will
be android but the calling UID will be the calling app. It will
cause a SecurityException. The behavior is fine previously as its
known caller(Settings) shares system UID. But it will be a
problem for other callers, such as CTS. Thus, clear the identity
since the necessary permission check should be examined at the
top of the method. The following actions should be fine to be
proceed from the system itself. Also replace the user restriction
check via hasUserRestrictionForUser with the UserHandle created
from the calling uid to ensure it's verified with correct user.

Bug: 186061922
Test: Factory reset from Settings
Change-Id: If2dd69f702a1eafff331f9e71f6b92aeadfb715d
2021-05-20 10:01:50 +08:00
Cody Kesting
160ef3936a 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
2021-05-17 19:36:47 -07:00
Cody Kesting
8533f883c2 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
2021-05-17 19:36:47 -07:00
Chiachang Wang
05fbb45936 Dump only NORMAL priority information if no priority assigned
The legacy design of "dumpsys connectivity" will only dump
information with NORMAL priority. It was updated to provide
both NORMAL and HIGH priority information in order to support
dump in bugreport. However, it will also affect the result
using dumpsys connectivity.

Update design to dump NORMAL priority only to align with legacy
design.

Bug: 188387185
Test: adb shell dumpsys connectivity
Test: adb bugreport and check the result in bugreport
Change-Id: I6825c5038e48e3060c0c3ad1512bd584ef6d10a7
2021-05-17 17:31:07 +08:00
Chiachang Wang
c13a0a066c Dump only NORMAL priority information if no priority assigned
The legacy design of "dumpsys connectivity" will only dump
information with NORMAL priority. It was updated to provide
both NORMAL and HIGH priority information in order to support
dump in bugreport. However, it will also affect the result
using dumpsys connectivity.

Update design to dump NORMAL priority only to align with legacy
design.

Bug: 188387185
Test: adb shell dumpsys connectivity
Test: adb bugreport and check the result in bugreport
Change-Id: I6825c5038e48e3060c0c3ad1512bd584ef6d10a7
2021-05-17 17:31:07 +08:00
junyulai
69114dacb2 [FUI29] Migrate ConnectivityService to use getAllNetworkStateSnapshots
Test: atest FrameworksNetTests
Bug: 174123988
Change-Id: I3ba50cbd8a7f60779c69ba85e10dc3cc8a52f8b1
2021-05-14 19:48:17 +08:00
junyulai
5744432f28 [FUI29] Migrate ConnectivityService to use getAllNetworkStateSnapshots
Test: atest FrameworksNetTests
Bug: 174123988
Change-Id: I3ba50cbd8a7f60779c69ba85e10dc3cc8a52f8b1
2021-05-14 19:48:17 +08:00
Ken Chen
75c6d334c1 Reference unreachable netId from INetd
Bug: 181579204
Test: m; atest FrameworksNetTests
Change-Id: Id0d30363abe583459a8022e7400aab1dd4f72939
2021-05-14 14:30:43 +08:00
Ken Chen
4f612fae1f Reference unreachable netId from INetd
Bug: 181579204
Test: m; atest FrameworksNetTests
Change-Id: Id0d30363abe583459a8022e7400aab1dd4f72939
2021-05-14 14:30:43 +08:00
Remi NGUYEN VAN
4febb21cb6 Move connectivity sources to packages/Connectivity
The service-connectivity sources should be in
packages/modules/Connectivity. Move them to
frameworks/base/packages/Connectivity, so that the whole directory can
be moved to the dedicated packages/modules/Connectivity git project.

Bug: 186628461
Test: m
Merged-In: I26d1a274058fa38763ad4f605549d880865b4d76
Change-Id: Ie0562db92ebee269b901926d763ae907bde61b98
2021-05-13 18:18:42 +00:00
Remi NGUYEN VAN
cdb45f8e37 Move connectivity sources to packages/Connectivity
The service-connectivity sources should be in
packages/modules/Connectivity. Move them to
frameworks/base/packages/Connectivity, so that the whole directory can
be moved to the dedicated packages/modules/Connectivity git project.

Bug: 186628461
Test: m
Merged-In: I26d1a274058fa38763ad4f605549d880865b4d76
Change-Id: Ie0562db92ebee269b901926d763ae907bde61b98
2021-05-13 18:18:42 +00:00