Commit Graph

740 Commits

Author SHA1 Message Date
Chalard Jean
f4802fa4c2 Genericize NC#hasSameUids
This will be used by another set of UIDs in a future patch

Test: FrameworksNetTests
Change-Id: I2c5d18ef93e73b702723814592ef3f3baf5dfbc4
2021-12-16 23:03:42 +09:00
Jean Chalard
ec3013ddf4 Merge "Mark arg to NC#appliesToUidRange non-null" 2021-12-14 12:17:27 +00:00
Jean Chalard
5469fa6e59 Merge "Remove NetworkCapabilities#combine*" 2021-12-14 10:47:31 +00:00
Chalard Jean
2873428835 Mark arg to NC#appliesToUidRange non-null
This is always non-null, and if it's not it has a good
chance to throw anyway

Test: m
Change-Id: I1020ab9e6eb546390325cf6aa4d30183b2e69785
2021-12-13 21:55:56 +09:00
Chalard Jean
bdf4f2987d Remove NetworkCapabilities#combine*
This is no longer used outside of tests, and can be safely
removed.

Also this family of methods is fairly confusing, as while
it's well defined for some members, many later additions
had to be written so as to dissallow some combinations when
the workings of this family of methods didn't match the
semantics of some members, making them possibly dangerous
to use and at least exhibit difficult to understand semantics.

Test: FrameworksNetTests
      m
Change-Id: Ia69c20afa16c2153839891f6e33331caa9da33ff
2021-12-13 21:15:34 +09:00
Treehugger Robot
0db3016398 Merge changes from topic "DnsException"
* changes:
  CTS DnsResolverTest for DnsException ctor
  DnsResolver: Make DnsException ctor public
2021-12-13 07:48:28 +00:00
Mingguang Xu
0a416b65b1 Merge "Create DhcpOption object and make it a SystemApi" 2021-12-10 19:43:02 +00:00
Aswin Sankar
74cbfd5aab DnsResolver: Make DnsException ctor public
Making the DnsException constructor public is useful for apps
using DnsResolver to write their tests, and for internal packages
that may want to implement the DnsResolver.Callback interface.

Test: for regression; CTS tests in b/208479811
Bug: 208464882
Change-Id: I14641688f53721c96e6df9596a7506912ba3aec0
2021-12-10 19:30:20 +00:00
Mingguang Xu
2d87c6152d Create DhcpOption object and make it a SystemApi
This allows OEM apps to pass their custom DHCP options for establishing
network connection.

Bug: 177278970

Test: atest FrameworksNetTests
Test: atest NetworkStackTests

Signed-off-by: Mingguang Xu <mingguangxu@google.com>
Change-Id: I2b8c38ee9a948ad6edb666312c989d27a8ff904b
2021-12-09 19:37:40 -08:00
Chiachang Wang
81bc609550 Merge "Enable strict_updatability_linting in connectivity src" 2021-12-08 02:36:16 +00:00
Chiachang Wang
0209c36662 Ensure created fd being closed
If exception s thrown while calling bindSocket(fd), the temporary
created ParcelFileDescriptor may not be closed as expected.

Ensure it's closed eventually.

Bug: 206042872
Test: atest FrameworksNetTests
Change-Id: Icde895978ab9281006ffd56335d1247462d9da28
2021-12-01 14:46:29 +08:00
Chiachang Wang
3bc5276568 Enable strict_updatability_linting in connectivity src
Bug: 188851968
Test: m lint-check
Change-Id: I3cd06ea16f05cb37d9369a48dd0285d8239fd764
2021-11-26 10:31:58 +08:00
Chalard Jean
dece0d805f S- not to crash on NetworkInfo(null) or setDetailedState(null)
When NetworkInfo(null) or setDetailedState(null, any, any) are
called, S used to not crash but plant a null bomb for later
which may explode in some calls (notably, parceling) : see the
bug referenced below for details.

To help catching these errors earlier a patch was made to crash
as soon as one of these methods is called with a null argument,
but this will also crash incorrect use on existing code that
may never actually step on the mine, crashing code that used not
to crash. For safety, implement the new behavior only on T.

Bug: 145972387
Test: NetworkInfoTest
Change-Id: Ib710497d83b2d26439c2bd4d2f572310db97d6fd
2021-11-15 21:18:25 +09:00
Anton Hansson
7ea2767864 Merge "Qualify references to WifiNetworkSuggestions" 2021-10-21 11:53:06 +00:00
Lucas Lin
9c9850b944 Merge "Add underlying networks into NetworkAgentInfo if any" 2021-10-21 08:33:29 +00:00
Anton Hansson
df40109271 Qualify references to WifiNetworkSuggestions
Connectivity's metalava invocation does not depend on framework-wifi,
so these references fail to resolve, and as a result metalava currently
removes the import.

Fully qualify the references instead, to avoid both metalava trying
to resolve the dependency, and having to depend on framework-wifi just
for javadoc.

Bug: 186197911
Test: build the sdk (with connectivity module stubs as input)
Change-Id: I7129821b9a0d08d06f8e977a3c17fa5f5f6f9cee
2021-10-20 11:34:48 +01:00
Chalard Jean
4b918ab1a4 Crash bad callers earlier
Instead of crashing when parceling the NetworkInfo object,
crash at the time the bad call is made.

Bug: 145972387
Test: FrameworksNetTests
Change-Id: If8b5fd3d7b800c97211bcd16c9a8c5812708d4ab
2021-10-19 16:43:50 +08:00
lucaslin
6adf5ac19b Add underlying networks into NetworkAgentInfo if any
Now, VPN will set underlying networks into NetworkCapabilities
directly. So the declaredUnderlyingNetworks can also be set
directly when creating a NetworkAgentInfo.

Bug: 191918368
Test: atest FrameworksNetTests:ConnectivityServiceTest
Change-Id: I507072d00ae1eb0c391e5261ab93e359b9c4cb5c
2021-10-19 15:04:56 +08:00
lucaslin
8b2dfa7c02 Add new APIs in NetworkCapabilities to set and get underlying networks
Previously, the caller can only know about the transport type of
the underlying network. The information might not be enough if
the device support WiFi STA+STA.
Thus, provide an API for the caller to get the correct underlying
network.

Bug: 191918368
Test: atest FrameworksNetTests:NetworkCapabilitiesTest
Change-Id: I7752b2356770f4572f6ca4cbaecaa45c09d6d72f
2021-10-15 18:07:12 +08:00
Chalard Jean
7f40360e32 Merge "Add a small usage comment" am: a898f0a039
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1844182

Change-Id: Ibe27d64cd16a2ef44d6a41b94f81a0daa06c523b
2021-10-05 11:14:01 +00:00
Chalard Jean
025f40bc4f Add a small usage comment
Test: comment-only change
Bug: 201972281
Change-Id: Ifbdadbaacfaf364f6770e56ccb816eb3269003d5
2021-10-04 18:33:36 +09:00
Chiachang Wang
e129460c46 Merge "Remove reference when active listener is unregistered" am: a39b107812
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1833145

Change-Id: I7b05b33c2a0c02c298d42ab4891ce543fe5ab9bd
2021-10-01 00:54:16 +00:00
Chiachang Wang
a39b107812 Merge "Remove reference when active listener is unregistered" 2021-10-01 00:37:00 +00:00
Chiachang Wang
2de41686e7 Remove reference when active listener is unregistered
The registered listeners are added into internal ArrayMap as a
reference but are not removed when the listeners are
unregistered. The actions for registration should be done in
pairs.

Test: atest FrameworksNetTests
Change-Id: Id9e674f5104d1471dd81224b6a271a8a92172e34
2021-09-30 10:30:35 +00:00
Chalard Jean
9f61ab08bd Merge "Small doc improvement" am: a997db7f40
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1838427

Change-Id: Id3afa12d046e1666978840fee0918f4f160a21c9
2021-09-30 08:01:44 +00:00
Chalard Jean
a997db7f40 Merge "Small doc improvement" 2021-09-30 07:48:00 +00:00
Chalard Jean
0d05151b5c Small doc improvement
Test: comment-only change
Bug: 191744296
Change-Id: I80447783c9fd89f3b6685a4276cc555a7075a70f
2021-09-28 15:31:15 +09:00
Chalard Jean
d4ec13a400 Merge "Add a mode for cell radios unable to time share" am: c80a5d56db
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1827923

Change-Id: I5ded48c8498c32977adcfe2363599d6cfa246e1b
2021-09-18 12:50:52 +00:00
Chalard Jean
0702f98edc Add a mode for cell radios unable to time share
Upon changing the default SIM card, the radio will create a
new connection to the new subscription. If that subscription
works correctly, the stack will prefer it to the old one as
the new subscription will be marked with a Primary policy
flag it its score.

Normally, at this point the old network lingers to give apps
an opportunity to gracefully migrate their connections. But
with some radios, this may have a dramatic effect on the
performance of the new connection.

This patch introduces a flag so that devices with such radios
can be marked. In this case the stack will move to a degraded
mode and eschew the grace delay for apps and give them a hard
break instead, so that the new network can reach a good
performance immediately. Apps with existing connections will
suffer a worse experience.

If there is a request that can only be served by the old
connection, still keep it, as arguably the user still
expects their MMS be sent on the old connection, even if the
new connection doesn't work well until it's done.

Test: new test in this patch, and add relevant tests in both modes
      also manually change the value of the flag and run
      FrameworksNetTests and CtsNetTestCasesLatestSdk
Bug: 200226979
Change-Id: I4ace82f90e873bf06298cc689bb1d794ed5124bd
2021-09-18 04:03:13 +00:00
Chiachang Wang
7c04a51a95 Merge "Correct the calling method in removeDefaultNetworkActiveListener" am: a6e3069c27
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1827914

Change-Id: I69a199d8253aca744a43b04e89a88da65f6bd8b9
2021-09-16 06:39:32 +00:00
Chiachang Wang
e54c8199aa Correct the calling method in removeDefaultNetworkActiveListener
The removeDefaultNetworkActiveListener should do the
unregisteration but it's incorrectly calling
registerNetworkActivityListener into the ConnectivityService.

Bug: 199753782
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I65a2ddc82989d736316d51f5058e707f5b261a82
2021-09-16 02:25:48 +00:00
Chiachang Wang
33076dddff Merge "Separate test into reasonable multiple tests" am: 26a7e61417
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1793478

Change-Id: I9193477c6744c6f9a1f7e7e14e0c98e4348b262d
2021-09-07 03:01:39 +00:00
Xin Li
e534ce4c55 Merge "Merge sc-dev-plus-aosp-without-vendor@7634622" into stage-aosp-master 2021-08-17 18:15:09 +00:00
Chiachang Wang
d525a64ead Separate test into reasonable multiple tests
The test actually verifies multiple behaviors and mutates the
networkCapabilities. Thus, refactor the method to keep the
tests easier to follow up.

Bug: 191918212
Test: atest android.net.NetworkCapabilitiesTest
Change-Id: Ibad1a0569d26d92f94153bee323cef5a1c30d8d4
2021-08-17 16:02:09 +08:00
Remi NGUYEN VAN
5b8e2e9935 Fix NetworkCapabilities MTS on S, CTS on S+module
restrictCapabilitiesForTestNetwork was renamed after S release to be
included in a mainline release, but this causes the MTS test to fail on
S if the Connectivity module is not updated, and CTS to fail if the
connectivity module is updated.

Mark the test as @ConnectivityModuleTest so it can be skipped on
non-connectivity module MTS tests (such as NetworkStack tests), and add
back the previous method name to keep CTS passing.

Bug: 196755836
Test: atest NetworkCapabilitiesTest
Change-Id: Ibd6c2e62e5949ec6d93e9f6e4fc05129c29b94f8
2021-08-16 18:03:37 +09:00
Xin Li
3ec4468fb7 Merge sc-dev-plus-aosp-without-vendor@7634622
Merged-In: I5a33f959c8ae5a34584f57508f392038e44062e7
Change-Id: Ib4e5e75ee8bbe19806bdc2f69590d164fb75774b
2021-08-14 06:31:05 +00:00
Chiachang Wang
c07315aa08 The net cap value should be bit shifted before &ing
The check intends to do the bit & operation. The net cap value
should be shifted against the original capabilities.

Also fix the typo in the method name.

Bug: 191918212
Test: atest FrameworksNetTests
Change-Id: I98396b2538f36fe8b29d27a544a2dfb3060bc9c5
2021-08-11 14:55:00 +08:00
Treehugger Robot
855d6cdf05 Merge "Correct log" am: 913dba8be3 am: 3f6e40dbd7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1772285

Change-Id: I295f07a5621e20ad4cf1bfeafd8a4f57f00d96dd
2021-07-20 08:45:41 +00:00
Treehugger Robot
913dba8be3 Merge "Correct log" 2021-07-20 08:20:37 +00:00
Chiachang Wang
525b07d28a Correct log
Log should print the taken parameter instead of the value of
current variable

Test: m
Bug: 192149168
Change-Id: Ia3b9e607fe8b661a7faea3b46b9697fa85016440
2021-07-20 13:16:57 +08:00
lifr
538f079d20 Cleanup the public API getActiveNetworkForUid on AOSP
In order to make ConnectivityService the mainline module in ANDROID 12,
The earliest ConnectivityService API getActiveNetworkForUid was exposed.

But after that public api getActiveNetworkForUid and all callers
(Outside the module) has been deleted or replaced in android 12
version. So we should delete the public API in AOSP to keep the APIs
of Android 12 & AOSP consistent and also avoid using it again in AOSP.
The commit is equivalent to ag/14029494, but done in a different repo.

Bug: 183465229
Test: atest ConnectivityControllerTest
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Change-Id: I50a39d6391c88bbb914a63fdb17bae6851591c01
2021-07-14 21:13:45 +08:00
lucaslin
6f77442d76 Add new network capabilities to support automotive head unit via USB
- Add a new transport type for USB and a new network capability
to support automotive head unit.
- In order to pass DnsManagerTest#testTransportTypesEqual, Android.bp
needs to link to dnsresolver_aidl_interface-V8-java. That test checks
whether the TRANSPORT types defined in NetworkCapabilities are the
same as IDnsResolver.aidl.

(clean cherry-pick of change in downstream branch history, original
change ID before project move:
Iec2df09a776d779108f95098e01b7ffdf6f8867a)

Bug: 181742019
Test: atest FrameworksNetTests

Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Change-Id: Ie438ec68577ebdaaf990795fa27f1169b0105411
2021-07-08 09:44:39 +09:00
paulhu
92f128c51c Force only system uid can set uids allowed on restricted networks
- Check whether calling UID/PID is system_server.
- For CTS test, enforce NETWORK_SETTINGS permission otherwise if
  it's a debug build.

Bug: 175199465
Test: atest FrameworksNetTests
Test: atest ConnectivityManagerTest#testUidsAllowedOnRestrictedNetworks
Merged-In: I175a831671d3e52460d28203b09f6c0dda56b61c

Change-Id: I175a831671d3e52460d28203b09f6c0dda56b61c
2021-07-02 20:04:50 +08:00
Paul Hu
77739d37b3 Merge "Force only system uid can set uids allowed on restricted networks" into sc-dev 2021-07-02 10:46:19 +00:00
Remi NGUYEN VAN
298f6aff93 Remove workarounds to use core platform API
Core platform API stubs are now correctly included in module_current and
system_server_current, so workarounds used to use such APIs can be
removed.

OsCompat and InetAddressCompat were only necessary because manually
adding the stubs did not resolve the problem for classes that had
public API stubs, which shadowed the module API stubs.

The manual stubs dependency was already removed in another change. Also
remove the service jar dependency on android_system_server_stubs_current
as it is already included in sdk_version system_server_current.

Bug: 183097033
Test: atest CtsNetTestCases

Original-Change: https://android-review.googlesource.com/1754889
Merged-In: Id448be03b679f832edb24f1b77f471227faf5268
Change-Id: Id448be03b679f832edb24f1b77f471227faf5268
2021-07-02 04:54:29 +00:00
Remi NGUYEN VAN
b2e919f9da Remove workarounds to use core platform API
Core platform API stubs are now correctly included in module_current and
system_server_current, so workarounds used to use such APIs can be
removed.

OsCompat and InetAddressCompat were only necessary because manually
adding the stubs did not resolve the problem for classes that had
public API stubs, which shadowed the module API stubs.

The manual stubs dependency was already removed in another change. Also
remove the service jar dependency on android_system_server_stubs_current
as it is already included in sdk_version system_server_current.

Bug: 183097033
Test: atest CtsNetTestCases

Change-Id: Id448be03b679f832edb24f1b77f471227faf5268
2021-07-02 10:05:07 +09:00
Orion Hodson
5e5c287d6b Remove dependency on stable.core.platform.api.stubs
Bug: 183097033
Test: m droid
Original-Change: https://android-review.googlesource.com/1751523
Merged-In: I06cbc7e06e112d61575fad6ad0783348c94e3df2
Change-Id: I06cbc7e06e112d61575fad6ad0783348c94e3df2
2021-07-02 00:42:52 +00:00
Orion Hodson
f15f2769b4 Merge "Remove dependency on stable.core.platform.api.stubs" 2021-07-01 18:53:17 +00:00
paulhu
03635b3ad5 Force only system uid can set uids allowed on restricted networks
- Check whether calling UID/PID is system_server.
- For CTS test, enforce NETWORK_SETTINGS permission otherwise if
  it's a debug build.

Bug: 175199465
Test: atest FrameworksNetTests
Test: atest ConnectivityManagerTest#testUidsAllowedOnRestrictedNetworks
Ignore-AOSP-First: Need cherry-pick
Change-Id: I175a831671d3e52460d28203b09f6c0dda56b61c
2021-07-01 23:01:41 +08:00
Chiachang Wang
6339ec22ad Trigger the network score update after setting test allow bad wifi
Avoid bad wifi design has to apply in both wifi and cellular
networks. Cellular network should contain POLICY_YIELD_TO_BAD_WIFI
policy, then system default network could stay in the wifi after
wifi becomes unvalidated.

The testing API only update the value but not trigger the avoid
bad wifi callback to update the score in the existing cellular
network. Thus, if the cellular network is connected before
setting the overridden value, the yield to bad wifi policy will
not updated to cellular network. The system default network will
still switch from unvalidated wifi network to cellular network
even wifi network is connected with the avoid bad wifi policy.

Update to trigger a reevaluation to update the score in each
NetworkAgent in the ConnectivityService.

Bug: 192149168
Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest\
      #testSetAvoidUnvalidated --rerun-until-failure 100
Original-Change: https://android-review.googlesource.com/1751588
Merged-In: Ie0f777d0030b66dd306332496192c74f6c183284
Change-Id: Ie0f777d0030b66dd306332496192c74f6c183284
2021-07-01 00:32:08 +00:00