Commit Graph

9984 Commits

Author SHA1 Message Date
Lorenzo Colitti
8f67bdec5a Re-enable check for VpnTransportInfo session ID.
This check was commented out because VpnTransportInfo was not
correctly propagated to ConnectivityService. This is now fixed.

Bug: 183938194
Test: atest CtsNetTestCases:NetworkAgentTest
Change-Id: Iab9987c8b58487ee44d8479b02e030c7e1e4465f
2021-05-14 00:47:55 +09:00
Chiachang Wang
78c1663ba3 Merge "Add test for ConnectivityManager.setGlobalProxy()" 2021-05-13 09:30:25 +00:00
Lucas Lin
d56f4a700b Merge "Define PRIVATE_DNS_MODE_OPPORTUNISTIC locally" 2021-05-12 17:09:50 +00:00
Lorenzo Colitti
2422319cb7 Remove dead code.
Remove a few legacy methods that have no callers.

Test: m
Change-Id: I499e940dc98453194fc528d65a89696471ad8bdd
2021-05-12 17:35:49 +09:00
Lorenzo Colitti
94311aa902 Remove mPublicSync.
This is no longer necessary as all the methods that take it are
running on on the handler thread, either in Tethering itself or
on the state machine thread in IpServer, which runs on the same
thread as Tethering.

Specifically:
- interfaceStatusChanged, interfaceAdded, interfaceRemoved,
  interfaceLinkStateChanged: run from mNetdCallback, which always
  posts them to mHandler.
- setWifiTethering: only called by enableTetheringInternal, which
  is called by the following:
  - startTethering, stopTethering: via lambda posted to mHandler
  - IpServerCallback#requestEnableTethering: called by IpServer
    while processing a command.
- setEthernetTethering: only called by enableTetheringInternal.
- EthernetCallback: runs on mExecutor, which posts to mHandler.
- getLastTetherError: only used by the test. Renamed to
  getLastErrorForTest to ensure no other callers.
- sendTetherStateChangedBroadcast: called only by
  notifyInterfaceStateChange, which is called only by
  - IpServerCallback#updateInterfaceState, which is called only
    by sendInterfaceState, which is called by various IpServer
    state enter methods.
- notifyLinkPropertiesChanged: called only by
  IpServerCallback#updateLinkProperties, which is only called by
  IpServer#sendLinkProperties, which is only called by:
  - Code that processes CMD_IPV6_TETHER_UPDATE
  - IpServer#handleNewPrefixRequest: only called when processing
    CMD_NEW_PREFIX_REQUEST.
  - IpServer#sendInterfaceState (see above)
- handleWifiApAction, handleWifiP2pAction: only called by
  mStateReceiver, which runs on the handler thread
- tether(String, int): called by:
  - tether(String, IIntResultListener): posted to mHandler
  - changeInterfaceState: called by:
    - EthernetCallback (see above)
    - enableWifiIpServingLocked: called by handleWifiApAction and
      handleWifiP2pAction (see above)
    - tetherMatchingInterfaces: only called by handleUsbAction,
      which is run from mStateReceiver on the handler thread.
- untether(String): called by:
  - untether(String, IIntResultListener): posted to mHandler
  - changeInterfaceState (see above)
- setUsbTethering: called by:
  - setUsbTethering(boolean, IIntResultListener): posted to mHandler
  - enableTetheringInternal (see above)
- setNcmTethering: called by enableTetheringInternal (see above)
- getTetheredIfaces: called only by TetheringTest. Renamed to
  getTetheredIfacesForTest to ensure no other callers.
- getErroredIfaces: unused, deleted in this CL
- getTetheredIfaces: called by:
  - isTetheringActive: called by onUserRestrictionsChanged, which
    is only called by mStateReceiver
  - TetheringTest
- dump(): changed to run on handler thread
- upstreamWanted: called by
  - TetherModeAliveState#enter
  - TetherModeAliveState#updateUpstreamWanted, which is called
    only by TetherModeAliveState#processMessage.

Test: atest TetheringCoverageTests
Test: enabled/disabled hotspot, USB tethering
Change-Id: Id49d33f027b8df4c97fda480ff239c0ba90bb96a
2021-05-12 17:35:49 +09:00
Lorenzo Colitti
5f729e14a3 Make Tethering#dump asynchronous.
This is in preparation for removing mPublicSync.

Test: m
Test: adb shell dumpsys tethering
Test: atest TetheringTests TetheringIntegrationTests
Change-Id: Ib2c9d0bff23614f76c8e075d32cb03412d3d21f7
2021-05-12 17:35:49 +09:00
Lorenzo Colitti
b54bdabe5a Skip presubmit for IPsec transport mode IPv6 TCP tests.
These tests are currently broken due to what appears to be an
upstream regression affecting 5.10 kernels, and are causing
all networking CLs to fail presubmit.

Skip them in presubmit until the regression is fixed. The tests
will still fail when run manually or in postsubmit.

Bug: 186608065
Test: atest CtsNetTestCases:android.net.cts.IpSecManagerTest
Change-Id: Ib78e13ace62a0addddff0a2d17b7f393a4cc4f87
2021-05-12 17:35:49 +09:00
Hungming Chen
3c94994650 Fix attaching program failure on kernel 5.10
Attach BPF program may be failed with the netlink error message
"Invalid argument". Per debug kernel trace, it is failed in
comparing the kind name in tc_new_tfilter.

Log:
05-05 19:44:42.329  1073  2332  2332 W tc_new_tfilter:
Specified filter kind does not match existing one

Test: enable usb tethering and check the follows

$ adb shell tc filter show dev <upstream, downstream> ingress
filter protocol ipv6 pref 1 bpf chain 0
filter protocol ipv6 pref 1 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_upstream6_ether:[*fsobj]
direct-action not_in_hw id 3 tag 94ca9b12972fdea8
filter protocol ip pref 2 bpf chain 0
filter protocol ip pref 2 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_upstream4_ether:[*fsobj]
direct-action not_in_hw id 9 tag 992aa9bfd0503457
filter protocol ipv6 pref 1 bpf chain 0
filter protocol ipv6 pref 1 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_downstream6_rawip:[*fsobj]
direct-action not_in_hw id 4 tag 7fb60e556b8f3be7
filter protocol ip pref 2 bpf chain 0
filter protocol ip pref 2 bpf chain 0 handle 0x1
prog_offload_schedcls_tether_downstream4_rawip:[*fsobj]
direct-action not_in_hw id 6 tag e41426095404fb64

Change-Id: I471a2e34c626a3737cbd2754e4d1b3000bcf6ba6
2021-05-06 02:52:07 +00:00
lucaslin
09f1245d4a Define PRIVATE_DNS_MODE_OPPORTUNISTIC locally
The type of ConnectivityManager#PRIVATE_DNS_MODE_OPPORTUNISTIC
has changed from String to int, but the String definition is still
needed to update to Settings.Global.PRIVATE_DNS_MODE, so the
simplest way is to define one locally.

Bug: 185311744
Test: atest CtsNetTestCases
Change-Id: Iafcd861714d8aca44cede658ed630f9d5afd5e59
Merged-In: Iafcd861714d8aca44cede658ed630f9d5afd5e59
    (Cherry-picked from ag/14232792)
2021-05-05 02:36:44 +00:00
Chiachang Wang
38b7a40643 Add test for ConnectivityManager.setGlobalProxy()
ConnectivityManager.setGlobalProxy() requires NETWORK_STACK
permission. Add test to verify exception thrown if caller has
no permission.

Bug: 186061922
Test: atest CtsNetTestCases CtsNetTestCasesLatestSdk
Change-Id: I87e2e6a878bd538b2e8c6f72f44335746151a9a7
2021-04-28 09:27:49 +00:00
Treehugger Robot
e6bafe29b0 Merge "Add native coverage listener to tethering coverage test" 2021-04-27 18:35:29 +00:00
Sarah Chin
45fa6bd811 Merge "Add tests for NetCapability#getCapabilityCarrierName" 2021-04-27 17:58:12 +00:00
markchien
b23e912805 Add native coverage listener to tethering coverage test
This allows the coverage tests to manually trigger native coverage
collection, as a workaround for collection not being triggered
automatically by the coverage infrastructure.

Bug: 185202279
Test: atest TetheringCoverageTests
Change-Id: I619fc267cf1743dd2218e3dd42546b0d4e9da193
2021-04-27 16:48:25 +00:00
Chiachang Wang
5d4e9ee83d Merge "Update APIs based on API review feedback" 2021-04-26 00:22:27 +00:00
Mark Chien
07f8a618d2 Merge "Release mobile request when default upstream is not mobile" 2021-04-23 11:48:36 +00:00
markchien
d5096f504d Release mobile request when default upstream is not mobile
Some OEM may have special mobile data icon show up when non-default
(e.g. DUN) mobile connection connected even wifi is also connected.
So always connected DUN may let user hard to distinguish tethering
upstream in those OEM's devices. Also release unused mobile connection
may safe power.

This CL removes unnecessary code from selectPreferredUpstreamType.
In particular:
    - When a DUN or HIPRI upstream is selected, calling
    registerMobileNetworkRequest is unnecessary. A mobile
    NetworkRequest is always registered unless a non-mobile upstream
    is selected.

    - When a non-mobile upstream is found, releasing the mobile
    NetworkRequest is unnecessary in selectPreferredUpstreamType
    because it will be done by chooseUpstreamType immediately after
    selectPreferredUpstreamType returns.

    - When no upstream is found and cellular upstream is not permitted,
    it is not necessary to release the mobile NetworkRequest. When
    cellular is not permitted, no such NetworkRequest will be filed
    because registerMobileNetworkRequest checks with EntitlementManager
    before actually requesting the network. If cellular becomes the
    upstream and then later becomes not permitted because of an
    entitlement failure, all tethering will be stopped by Settings.

Note: currently legacy upstream selection has two known bugs:
1. If mobile has higher priority than non-mobile network, mobile request
should never be released and always prefer use mobile. But in practice,
mobile request would be released when tethering select non-mobile network
as upstream.
2. If mobile has higher priority than wifi network and default network
is wifi but mobile is still connected, tethering would choose mobile as
upstream because it has higher priority. Mobile disconnecting may not
trigger tethering to switch its upstream to wifi because currnetly
tethering rely on CONNECTIVITY_ACTION broadcast to handle upstream
disconnect.

Bug: 173068192
Test: atest TetheringTests
Change-Id: Id5df58af830cc534ecd79041ddf8a04171047e9b
2021-04-23 16:45:29 +08:00
Chiachang Wang
878ad503a9 Update APIs based on API review feedback
Update the usage in callers side for
  - Rename NetworkAgent#setTeardownDelayMs to
    NetworkAgent#setTeardownDelayMillis
  - Use getters instead of fields in VpnTransportInfo
  - Rename registerDefaultNetworkCallbackAsUid to
    registerDefaultNetworkCallbackForUid in ConnectiivityManager

Bug: 183972850
Bug: 185246410
Fix: 184735863
Test: atest FrameworksNetTests
Test: atest CtsNetTestCasesLatestSdk
Change-Id: Ie542e5ad631388d9948dd27de21bc218b5b5b8f2
Merged-In: Ie542e5ad631388d9948dd27de21bc218b5b5b8f2
2021-04-23 02:44:07 +00:00
Chiachang Wang
8027d24eaf Merge "Update doc in TestUtils" 2021-04-23 00:35:27 +00:00
Sarah Chin
bae0fb30f9 Add tests for NetCapability#getCapabilityCarrierName
Test: atest ConnectivityManagerTest
Fix: 183553812
Change-Id: I60801bb86302b57f6d72ea903d98a8249fae4555
2021-04-22 17:00:57 -07:00
Treehugger Robot
3b55c68cc2 Merge "Fix testKeepaliveWifiUnsupported failure" 2021-04-22 14:40:40 +00:00
Remi NGUYEN VAN
285d3a5da7 Fix testKeepaliveWifiUnsupported failure
As a temporary measure to get the test to pass, use the
QUERY_ALL_PACKAGES permission when calling getSupportedKeepalives.
This is helps as getSupportedKeepalives obtains the configuration
from resources in the connectivity resources package, which
recently got its own non-platform certificate and is now not
visible from the test anymore.

getSupportedKeepalives is only used by tests and ConnectivityService
which has all permissions.

The actual fix should make sure getSupportedKeepalives does not require
such a permission (although getSupportedKeepalives is not a formal API),
but this will take more time and the test needs to stay green in the
meantime.

Bug: 186093901
Test: atest CtsNetTestCases
Change-Id: I288ec13a6f0840b184f1c919785724733ca56adf
2021-04-22 21:35:34 +09:00
Chiachang Wang
d514b53eca Update doc in TestUtils
Follow up commit from aosp/1650232 to update the doc

Bug: 186061922
Test: m
Change-Id: Icb622516bc41de5cbe3112d7abd3df9d83448b32
2021-04-22 18:19:58 +08:00
Chiachang Wang
28f3e69a25 Merge "Add test for NetworkRequest.Builder(NetworkRequest)" 2021-04-22 09:58:54 +00:00
Chiachang Wang
93b807718b Add test for NetworkRequest.Builder(NetworkRequest)
Build NetworkRequest using builder from an existing
NetworkRequest is exposed to API surface, so add a test to
verify its behavior works as expectation.

Also, create a TestUtils in the cts to put the multiple
reference methods(shouldTestSApis) to prevent duplication.

Bug: 186061922
Test: atest CtsNetTestCases:android.net.cts.NetworkRequestTest
      in current sdk
Test: atest CtsNetTestCasesLatestSdk:android.net.cts.NetworkRequestTest
      in R and current sdk
Test: atest android.net.cts.ConnectivityManagerTest#\
      testRegisterNetworkCallback
Change-Id: I46318e212d51e4e13efa86e8b9c3ca7326d62b77
2021-04-22 02:30:26 +00:00
Lorenzo Colitti
ac9ce08d45 Merge "Allow callers of startTethering to choose local-only mode." 2021-04-19 14:10:32 +00:00
Lorenzo Colitti
8a36c297bc Allow callers of startTethering to choose local-only mode.
This is useful for OEMs that want to use RNDIS or NCM as a
local-only link that is directly connected to some other host.
This can be used to implement USB tethering using NCM, which
currently only supports local-only mode.

Bug: 175090447
Test: TetheringIntegrationTests:EthernetTetheringTest#testLocalOnlyTethering
Change-Id: I0ffaa46e4640e5b235340a15d25909106ceb0c07
2021-04-19 20:25:58 +09:00
Treehugger Robot
c3bac64a94 Merge "Move CtsHostsideNetworkTests to group presubmit-large" 2021-04-19 03:05:59 +00:00
Junyu Lai
afd18ddd57 Merge "[VCN20.2] Change requestBackgroundNetwork argument order" 2021-04-16 16:04:31 +00:00
junyulai
989cf46ba0 [VCN20.2] Change requestBackgroundNetwork argument order
Test: atest FrameworksNetTests FrameworksVcnTests
Fix: 185215095
Merged-In: I09ff7461b655cbfc6ed5a7db07e02a388cd3d079
Change-Id: I09ff7461b655cbfc6ed5a7db07e02a388cd3d079
  (cherry-picked from ag/14185520)
2021-04-16 00:29:20 +08:00
Treehugger Robot
f7d188c8c9 Merge "Fix CTS fail to register network callback since lack of permission" 2021-04-15 15:03:15 +00:00
Treehugger Robot
2576c457de Merge "Put tether/untether calls into handler queue" 2021-04-15 14:46:25 +00:00
Treehugger Robot
bea56fbe11 Merge changes from topic "connectivitymanager-blockedreason-shim"
* changes:
  Fix CtsNetTestCasesLatestSdk in AOSP.
  Use the non-API static UserHandle.getUid method in tests.
  Import ConnectivityManager.BLOCKED_REASON_* from ConstantsShim.
2021-04-15 07:30:24 +00:00
Lorenzo Colitti
ddeb269ca0 Fix CtsNetTestCasesLatestSdk in AOSP.
This test suite is broken in AOSP due to a number of tests that
depend on S APIs. We attempted to prevent those tests running on
R builds with:

@IgnoreUpTo(Build.VERSION_CODES.R)

but this is not sufficient for them to pass when the test is
compiled against the R SDK (e.g., in CtsNetTestCasesLatestSdk).
This is because when compiling against the R SDK, the test uses
the API 30 shims, which throw UnsupportedApiLevelException even
though the method actually exists on device.

Fix this using:

    assumeTrue(shouldTestSApis());

This is not great, but at least it unbreaks the tests for now.

Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest
Test: atest CtsNetTestCasesLatestSdk:android.net.cts.ConnectivityManagerTest
Change-Id: Ifee0aea5afef6bd4bc762a4b1f25fc05e562d49a
2021-04-15 13:30:02 +09:00
Lorenzo Colitti
7ba366de0b Use the non-API static UserHandle.getUid method in tests.
The code was updated in AOSP to use the new non-static
UserHandle#getUid(int), which is only available in S or above.
This fails to build in mainline-prod. Instead of defining a shim
for this, simply use an older method that takes a userId.

Bug: 165835257
Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest
Test: CtsNetTestCasesLatestSdk:android.net.cts.ConnectivityManagerTest
Change-Id: Id529f8b201cc871aa3155aef0f44574d88040c2d
2021-04-15 13:20:02 +09:00
Lorenzo Colitti
aa9db67edc Import ConnectivityManager.BLOCKED_REASON_* from ConstantsShim.
This is needed for the tests to compile in mainline-prod.

Bug: 165835257
Test: atest CtsNetTestCases:android.net.ConnectivityManagerTest
Change-Id: I32924824e9968996f379e31f1b28eb6a8f29bc5d
2021-04-15 10:25:46 +09:00
Lorenzo Colitti
f6875cc583 Merge "Test ConnectivityManager module-lib APIs for VPNs and blocking." 2021-04-14 14:46:29 +00:00
junyulai
3a7d92513f Fix CTS fail to register network callback since lack of permission
Currently, NetworkCallbackTest gets the capabilities of current
active network to track the network used for the tests. And
construct the request with the capabilities gets from the
network. This causes test fails if the capabilities contain
signal strength, since it requires NETWORK_SIGNAL_STRENGTH_WAKEUP
to be declared.

Thus, this patch null out several fields from capabilities
of the current active network to construct the new request
in order to prevent over-specifying the requirement.

Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideNetworkCallbackTests
Bug: 182516128
Change-Id: Ib79b38e63ad2083c29fd71a24b8686b3f6f4e12f
2021-04-14 22:18:39 +08:00
Remi NGUYEN VAN
9a82bbf368 Fix proguard rules for Struct in NetworkStack
All members of the Struct class need to be kept, not just the constructor.

Change-Id: I8705234eb2608c0dfe324c517b8885a93271b6c2
Test: m
2021-04-14 01:30:59 +00:00
easoncylee
942a988249 Move CtsHostsideNetworkTests to group presubmit-large
The test config takes longer than 15mins to run. Move it to a dedicated
group for running slow presubmit Test Mapping test.

Some more context is in the referenced bug, e.g, b/174495337
The group will work exactly the same as presubmit for now.

Bug: 174654670
Bug: 174495337
Test: none
Change-Id: I7fe1286ed952a6058c56c36f28b4832947edb69f
2021-04-13 22:26:06 +08:00
Lorenzo Colitti
b84176e9f9 Test ConnectivityManager module-lib APIs for VPNs and blocking.
This CL adds tests for:
- ConnectivityManager#setsetLegacyLockdownVpnEnabled
- ConnectivityManager#setRequireVpnForUids
- NetworkCallback#onBlockedStatusChanged(Network, int)

Bug: 165835257
Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest
Change-Id: Ie9b73ec2a1634f3b3a3eb4d21acbe0803b77c70d
2021-04-13 17:30:49 +09:00
Chiachang Wang
0a5d964242 Merge "Update the method based on API feedback" 2021-04-13 08:15:47 +00:00
Lorenzo Colitti
a329e8c984 Fix a tethering crash when a 464xlat upstream disconnects.
When a 464xlat upstream disconnects, onLinkPropertiesChanged is
called after onLost. This breaks an UpstreamNetworkMonitor
assumption that no callback will ever arrive after onLost.

Bug: 173068192
Fix: 185117377
Test: new unit test
Change-Id: I4ff1eca6d5ed1680ff716c71b683891c8a0e5a77
2021-04-12 15:00:24 +00:00
Chiachang Wang
a31a9b6218 Update the method based on API feedback
UserHandle.getUid() is updated to a non-static API based on API
review feedback. Update the usage accordingly.

Bug: 184735865
Test: atest VpnTest
Change-Id: I884f427fae85b2b26973a0315b1ccf3d6f0824c6
2021-04-12 19:35:56 +08:00
Lorenzo Colitti
65bba3f6bc Merge changes from topic "peruidcallback-cts"
* changes:
  Cleanups to VPN hostside tests.
  Ensure the HostsideVpnTests passes with keyguard locked.
  Add CTS tests for registerDefaultNetworkCallbackAsUid.
2021-04-09 15:16:47 +00:00
junyulai
2e74377464 Fix NetworkCallback expecting wrong network
By current wifi design, wifi will report disconnected and
re-connected when changing from non-metered to metered.
However, the cts test app listens for all network, which
will get mobile network as active network when wifi is
changing meteredness. This is not expected. And causes
test failures when DUT has both wifi and mobile connections.

Thus, this change pass request to track currently active
network to the test app and register only for transport
types of currently active network to prevent from getting
unexpected network.

Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideNetworkCallbackTests
Bug: 182516128
Merged-In: I2dce6035b13472bbdc2609009d690aac96280033
Change-Id: I2dce6035b13472bbdc2609009d690aac96280033
  (cherry-picked from ag/14029457)
2021-04-09 10:16:18 +08:00
Lorenzo Colitti
08b33ff7fb Cleanups to VPN hostside tests.
Use TestableNetworkCallback instead of a hand-rolled class.
Remove unnecessary runWithShellPermissionIdentity around
unregisterNetworkCallback calls.

Bug: 165835257
Test: test-only change
Change-Id: I4557dfc64136f9c0b4bdaa1248c33b13e96ba3ed
2021-04-08 22:09:10 +09:00
Lorenzo Colitti
fd3b95c1f7 Ensure the HostsideVpnTests passes with keyguard locked.
The test app used in CtsHostsideNetworkTests already dismisses
the keyguard for its own activity, but that doesn't work for the
VPN tests. This is because as soon as the VPN dialog appears, the
test activity is no longer in the foreground and the keyguard
comes back. As a result, the test cannot click on the VPN dialog.

Test: test-only change
Change-Id: I7be1d7fb46a2f9547bc5325d75b5bd5546e6dc18
2021-04-08 21:50:15 +09:00
Lorenzo Colitti
ed26ffe92d Add CTS tests for registerDefaultNetworkCallbackAsUid.
Bug: 165835257
Test: test-only change
Change-Id: Ib3266665735ee587f3f8ae82dadd1e4ca7ce4353
2021-04-08 21:44:30 +09:00
Nucca Chen
68f6f5fe79 Merge "[NFCT.TETHER.11] Test TetherOffloadRule{Add, Remove} and set limit for IPv4" 2021-04-08 12:02:15 +00:00
Xiao Ma
3e557d777a Apply IPv6 utils struct stuff to build RA packet in the Daemon.
Traffic log of testSolicitRouterAdvertisement:
fe80::4473:4aff:fecb:7799 > ff02::1: ICMP6, router advertisement, length 88
fe80::1122:3344:5566:7788 > ff02::1: ICMP6, router solicitation, length 16
fe80::4473:4aff:fecb:7799 > fe80::1122:3344:5566:7788: ICMP6, router advertisement, length 88

Bug: 154669942
Test: atest TetheringPrivilegedTests --iterations
Change-Id: I7defb80ef9dd1832c9e04d154e1d06aed9e733dc
2021-04-08 04:50:49 +00:00