Commit Graph

810 Commits

Author SHA1 Message Date
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
Chiachang Wang
f1e09ef031 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
Change-Id: Ie0f777d0030b66dd306332496192c74f6c183284
2021-06-30 16:41:59 +08:00
Victor Chang
c3815ee358 Remove dependency on stable.core.platform.api.stubs
Bug: 183097033
Test: m droid
Change-Id: I06cbc7e06e112d61575fad6ad0783348c94e3df2
2021-06-29 22:31:05 +01:00
Paul Hu
a244f13f21 Merge "Add ConnectivitySettingsManagerTest" into sc-dev 2021-06-23 16:29:20 +00:00
paulhu
0903f73e1f Add ConnectivitySettingsManagerTest
- Add tests for ConnectivitySettingsManager.
- Also address leftover javadoc comments.

Bug: 182538166
Test: atest FrameworksNetTests
Test: atest CtsNetTestCases
Original-Change: https://android-review.googlesource.com/1738353
Merged-In: I8161c1bca84b41964578d59ee5d6ab07b2380707
Change-Id: I8161c1bca84b41964578d59ee5d6ab07b2380707
2021-06-23 20:02:27 +08:00
Chiachang Wang
fad30e3d84 Provide a way to override the avoid bad wifi configuration
ConnectivityManager.setAvoidUnvalidated only works if the
config_networkAvoidBadWifi configuration is set to 0 and the
NETWORK_AVOID_BAD_WIFI setting is unset. There is no easy way
for a testing app to temporary set a test value to verify the
behavior of the API. Thus, add a mechanism to allow test app
to set a period of time to temporary unstrict the resource
configuration, i.e. Temporary simulate config_networkAvoidBadWifi
configured to 0.

Bug: 186061922
Test: atest CtsNetTestCases FrameworksNetTests
Original-Change: https://android-review.googlesource.com/1733788
Merged-In: If772078c61a9b12926f104d5dfc9c9071e844732
Change-Id: If772078c61a9b12926f104d5dfc9c9071e844732
2021-06-23 08:42:47 +00:00
Remi NGUYEN VAN
7579035ac9 Merge "Initialize TetheringManager lazily" into sc-dev 2021-06-23 02:17:34 +00:00
Paul Hu
6160d60b2e Merge "Add ConnectivitySettingsManagerTest" 2021-06-23 01:36:16 +00:00
Chiachang Wang
38e8c2c94b Merge "Provide a way to override the avoid bad wifi configuration" 2021-06-23 00:48:17 +00:00
Lucas Lin
611bc021e6 Call ConnectivitySettingsUtils to set/get private DNS related settings
ConnectivitySettingsManager and CtsNetUtils are doing the same
thing to set/get private DNS related settings.
To prevent making the duplication code in two places, move the
body to frameworks/libs/net and call it.

Bug: 185311744
Test: atest CtsNetTestCases CtsNetTestCasesLatestSdk
Original-Change: https://android-review.googlesource.com/1719017
Merged-In: I3272c825b86ec30c3d0bf4097088c653e668461b
Change-Id: I3272c825b86ec30c3d0bf4097088c653e668461b
2021-06-22 09:24:37 +00:00
Chiachang Wang
6eac9fb787 Provide a way to override the avoid bad wifi configuration
ConnectivityManager.setAvoidUnvalidated only works if the
config_networkAvoidBadWifi configuration is set to 0 and the
NETWORK_AVOID_BAD_WIFI setting is unset. There is no easy way
for a testing app to temporary set a test value to verify the
behavior of the API. Thus, add a mechanism to allow test app
to set a period of time to temporary unstrict the resource
configuration, i.e. Temporary simulate config_networkAvoidBadWifi
configured to 0.

Bug: 186061922
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: If772078c61a9b12926f104d5dfc9c9071e844732
2021-06-22 14:54:02 +08:00
paulhu
236a992cd0 Add ConnectivitySettingsManagerTest
- Add tests for ConnectivitySettingsManager.
- Also address leftover javadoc comments.

Bug: 182538166
Test: atest FrameworksNetTests
Test: atest CtsNetTestCases
Change-Id: I8161c1bca84b41964578d59ee5d6ab07b2380707
2021-06-22 03:00:51 +00:00
Lucas Lin
c12550b9f4 Merge "Call ConnectivitySettingsUtils to set/get private DNS related settings" 2021-06-21 19:12:33 +00:00
Remi NGUYEN VAN
77ea93bbfb Initialize TetheringManager lazily
Many applications use ConnectivityManager without needing
TetheringManager (or without calling legacy ConnectivityManager methods
that delegate to TetheringManager), so initializing TetheringManager
when ConnectivityManager is created wastes resources.

This is especially true considering that TetheringManager is not trivial
to initialize (worst case scenario it starts a thread and does multiple
Binder requests), and ConnectivityManager is created in ActivityThread
when setting up the app proxy on startup.

Bug: 190556328
Test: atest FrameworksNetTests CtsNetTestCases TetheringTests
Original-Change: https://android-review.googlesource.com/1736505
Merged-In: I2ba7b8f2b9e1c934cfb082776b8d643f2f2c17e5
Change-Id: I2ba7b8f2b9e1c934cfb082776b8d643f2f2c17e5
2021-06-21 10:23:52 +00:00
lucaslin
8962128a0b Call ConnectivitySettingsUtils to set/get private DNS related settings
ConnectivitySettingsManager and CtsNetUtils are doing the same
thing to set/get private DNS related settings.
To prevent making the duplication code in two places, move the
body to frameworks/libs/net and call it.

Bug: 185311744
Test: atest CtsNetTestCases CtsNetTestCasesLatestSdk
Change-Id: I3272c825b86ec30c3d0bf4097088c653e668461b
2021-06-21 16:39:08 +08:00
Remi NGUYEN VAN
e4d1cd970e Initialize TetheringManager lazily
Many applications use ConnectivityManager without needing
TetheringManager (or without calling legacy ConnectivityManager methods
that delegate to TetheringManager), so initializing TetheringManager
when ConnectivityManager is created wastes resources.

This is especially true considering that TetheringManager is not trivial
to initialize (worst case scenario it starts a thread and does multiple
Binder requests), and ConnectivityManager is created in ActivityThread
when setting up the app proxy on startup.

Bug: 190556328
Test: atest FrameworksNetTests CtsNetTestCases TetheringTests
Change-Id: I2ba7b8f2b9e1c934cfb082776b8d643f2f2c17e5
2021-06-21 10:59:14 +09: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
Lucas Lin
cfc86ef0f6 Merge "Send a proxy broadcast when apps moved from/to a VPN" 2021-06-15 09:26:21 +00:00
Cody Kesting
f5a4fb124b Keep subIds for Test NetworkCapabilities.
This CL updates NetworkCapabilities to retain configured subscription
IDs for Test NetworkCapabilities. Previously, they were cleared in
restrictCapabilitiesForTestNetwork().

Bug: 182291467
Bug: 189125789
Test: atest Ikev2VpnTest IpSecManagerTunnelTest
Test: atest CtsVcnTestCases
Change-Id: I0e1bc617910c9e8ac7b431572f276b1611acc1cb
Merged-In: I0e1bc617910c9e8ac7b431572f276b1611acc1cb
(cherry picked from commit a262a9d3d5)
2021-06-14 20:51:28 +00:00
Cody Kesting
dd346918b4 Keep subIds for Test NetworkCapabilities.
This CL updates NetworkCapabilities to retain configured subscription
IDs for Test NetworkCapabilities. Previously, they were cleared in
restrictCapabilitiesForTestNetwork().

Bug: 182291467
Bug: 189125789
Test: atest Ikev2VpnTest IpSecManagerTunnelTest
Test: atest CtsVcnTestCases
Change-Id: I0e1bc617910c9e8ac7b431572f276b1611acc1cb
2021-06-09 11:50:53 -07:00
Remi NGUYEN VAN
de3c20ecb5 Merge changes from topic "conn_test_defaults_cp"
* changes:
  Move connectivity test defaults to tests/common
  Add framework-connectivity-test-defaults
2021-06-09 00:59:17 +00:00
Junyu Lai
5b15e700bb Merge changes from topics "enable-policy-ranking", "sendNetworkScore"
* changes:
  Adjust a test for policy scoring
  Enable policy ranking
  Add CTS to verify NetworkAgent#setLingerDuration
  Allow network providers to set the linger duration.
  Fix nascent timer never get removed
  [NS13] Remove the last usage of the legacy int
  Add documentation
  Use filter from CollectionUtils.
  Fix a bug where updates of offers won't find existing offers
  [NS12] Address comments on NS09
  [NS11] Fix yieldToBadWifi over the policy scoring
  Add doc for NetworkScore#getLegacyInt
  Expose sendNetworkScore that takes a NetworkScore
2021-06-08 22:34:44 +00:00
Remi NGUYEN VAN
3912c80e99 Add framework-connectivity-test-defaults
The defaults follow the same pattern as framework-wifi-test-defaults to
allow unit tests to build against hidden API in Connectivity.

(clean cherry-pick of history in downstream branch)

Bug: 171540887
Test: m
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Change-Id: Ia8531f672820fcc8968f98494903e486c4e42652
2021-06-08 19:54:27 +09:00
Remi NGUYEN VAN
674ce27fee Merge changes from topic "framework-conn-stub-cp"
* changes:
  Reference framework-connectivity stubs explicitly
  Merge framework-connectivity impl and stub targets
2021-06-08 09:15:15 +00:00
Remi NGUYEN VAN
12474fdab5 Merge "Add min_sdk_version to connectivity targets" 2021-06-08 08:44:21 +00:00
Paul Hu
7cba5f4163 Merge "Move UIDS_ALLOWED_ON_RESTRICTED_NETWORKS setting" 2021-06-08 07:23:39 +00:00
Remi NGUYEN VAN
e70cd84601 Merge framework-connectivity impl and stub targets
Instead of using api_only: true, use a single java_sdk_library to
generate both framework-connectivity stubs and
framework-connectivity.impl.

Original change (project moved):
I76d7cf1ba31a3f38ae6b9facbf1b668860c8c165

Bug: 183600168
Test: m
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Change-Id: I07d8c4c92c91939b8e8890fdb5db517b75faee2c
2021-06-08 15:24:05 +09:00
Remi NGUYEN VAN
da43ef0b68 Add min_sdk_version to connectivity targets
All targets need min_sdk_version 30 to be included in the tethering
APEX. They will actually never be used on SDK 30 and are only loaded on
31, but this is necessary to be included in com.android.tethering.

Original change (project moved):
I190fd1f3c9fabff057d0a2bd7f45b63a4fe447b3

This also includes changes to the lint baseline to make it match actual
filenames.

Bug: 171540887
Test: m
Test: m lint-check
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Change-Id: I24198565bc98d85d0c036be02e3a6c311b5bb2a3
2021-06-08 15:23:40 +09:00
Remi NGUYEN VAN
8665528151 Merge "Revert "Add min_sdk_version to connectivity targets"" 2021-06-08 04:52:03 +00:00
Remi NGUYEN VAN
ccd2a6aeb4 Revert "Add min_sdk_version to connectivity targets"
This reverts commit 0b900c91f6.

Reason for revert: Broke errorprone: b/190454846

Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Change-Id: I21de7e7e06daa5f4a688b4246986f8d44da97c91
Fixes: 190454846
2021-06-08 04:50:01 +00:00
Remi NGUYEN VAN
bf7cffa7a0 Merge "Add min_sdk_version to connectivity targets" 2021-06-08 04:38:30 +00:00