Commit Graph

2258 Commits

Author SHA1 Message Date
Sarah Chin
45fa6bd811 Merge "Add tests for NetCapability#getCapabilityCarrierName" 2021-04-27 17:58:12 +00:00
Chiachang Wang
5d4e9ee83d Merge "Update APIs based on API review feedback" 2021-04-26 00:22:27 +00: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
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
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
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
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
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
Chiachang Wang
7d0e27bd7c Merge "Update tests for onNetworkCreated and onNetworkDestroyed" 2021-04-06 11:04:30 +00:00
Chiachang Wang
674a907cc4 Merge "Ensure SSID is not exposed to apps without correct permission" 2021-04-06 08:58:50 +00:00
Frank Li
320cd17220 Merge "Add session ID to VpnTransportInfo" 2021-04-06 06:50:48 +00:00
lifr
877fd475f5 Add session ID to VpnTransportInfo
- This will be visible only to apps with the NETWORK_SETTINGS
  permissions (signature), and will be redacted for all other callers.
- This string is expected to be the same as set by
  VpnService#setSession, and in general, VpnConfig.session. But it
  will be a general API that Vpn.java can call when setting the
  VpnTransportInfo.
- This string cannot be updated once the VPN NetworkAgent is connected.

Bug: 171872481
Ignore-AOSP-First: needed to prevent automerger race breaking build
Test: atest ConnectivityServiceTest
      atest VpnTransportInfoTest
      atest NetworkAgentTest
Change-Id: I883035262465238c35c5a931d89707f3e84feef8
Merged-In: I883035262465238c35c5a931d89707f3e84feef8
           (cherry-picked from ag/14008230)
2021-04-01 15:51:44 +08:00
Chiachang Wang
9a27925368 Update tests for onNetworkCreated and onNetworkDestroyed
Update test to:
1. verify onNetworkCreated callback called when network is
   created.
2. Verify onNetworkDestroyed callback called when agent
   updates its connection state to disconnect and native
   network is destroyed.

Bug: 178725261
Test: atest android.net.cts.NetworkAgentTest
Change-Id: Icd30440e0f553d0f97b860d0e69b4f3d4f0a2a1d
2021-04-01 11:13:42 +08:00
Sudheer Shanka
b0f50c579b Check and skip certain operations if they are unsupported.
Fixes: 178334463
Test: com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testMeteredNetworkAccess_expeditedJob
Change-Id: Ie68e17063454e7feeffc93b20b1b8fbb276e837f
Merged-In: Ie68e17063454e7feeffc93b20b1b8fbb276e837f
2021-03-30 16:22:43 +00:00
Chiachang Wang
d841868f39 Ensure SSID is not exposed to apps without correct permission
The class NetworkCapabilities has an extra field for SSID that
can be used by apps to obtain the router SSID (a surrogate for
location) without holding permission. This is a circumvention
of the permission system. Thus, add a test to ensure that
visibility of SSID for apps are controlled by NETWORK_SETTING
permission.

Bug: 183911251
Test: atest CtsNetTestCasesLatestSdk:ConnectivityManagerTest
Change-Id: I18d17093e2da37cde88b730c091c6a1deda08a8a
2021-03-29 17:19:47 +08:00
Treehugger Robot
a7542972b1 Merge "Shorten the name for the dump file." 2021-03-22 21:34:02 +00:00
Sudheer Shanka
8bb9eb1912 Try reconnecting to wifi if it doesn't automatically connect.
When meteredness of wifi changes during test, wifi disconnects.
Try reconnecting if it automatically connects after this.
Also, change the way we update metereness so that we can
use callback mechanism to wait for the state change instead of
polling for it regularly.

Bug: 181686645
Test: atest ./tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
Merged-In: I31fb127ef333d39fe4697043876c7cef15d525e3
Change-Id: Icc0b37730201aebeab2713c6527a3195f6dcf97d
2021-03-22 17:26:46 +00:00
Sudheer Shanka
8d92650da9 Shorten the name for the dump file.
The file name is getting truncated by tradefed and
we are missing the information to actually idenity
the test. So, instead shorten the filename to preserve
the test name.

Test: atest ./tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
Ignore-AOSP-First: Submitting internally first to avoid merge conflicts.
Merged-In: Ic0f87b97bb58e115fe81e2d688ce0e633397da42
Change-Id: I6ce3fc662782de82d8cad95414e24204b5f7f130
2021-03-22 17:24:46 +00:00
Lorenzo Colitti
60b26ee453 Mark most VpnServiceTest methods as @AppModeFull.
In S, instant apps can no longer access the system service that
backs the VPN APIs, so these tests started to fail in instant
mode.

Regardless of that change in S, though, instant apps cannot
create VPNs because they cannot access the package manager.

Previously, the tests were only passing because they did not
check that the VPN would actually work, they only checked that
the VPN API calls failed.

Fix: 181575083
Test: atest --instant CtsNetTestCases:VpnServiceTest
Change-Id: Idd35051bd1c908a8b85c02e8d0c54d3dea2dde38
2021-03-22 13:16:02 +00:00
Treehugger Robot
bf0c19e52f Merge "Revert^2 "Replace the usage of UidRange"" 2021-03-21 16:41:13 +00:00
Remi NGUYEN VAN
cc305b2fa5 Move connectivity AIDLs to android.net
java_sdk_libraries and apexes need to contain bootclasspath classes
under predefined packages. Tethering currently uses android.net, so make
sure all the connectivity bootclasspath classes are under android.net.

This avoids maintaining two packages for the tethering APEX, where
com.android.connectivity.aidl is only used by internal AIDL files.

Bug: 182984842
Test: m
Change-Id: I23feb26c5de2fd7a4177797a3bc1d0dcbef4ade7
Merged-In: I23feb26c5de2fd7a4177797a3bc1d0dcbef4ade7
2021-03-20 22:24:08 +09:00
Chiachang Wang
2fb0846d70 Revert^2 "Replace the usage of UidRange"
274c796731

The parameter of NetworkCapabilities.setUids() and
NetworkRequest.Builder.setUids() are updated to take a set of
integer Range instead of a set of UidRange because of refactor
work for the incoming connectivity mainline module.

The parameter change stops NetworkRequestTest to work in the
different API levels. Replace the usage with shims to work in
both current and stable APIs.

Bug: 172183305
Test: atest FrameworksNetTests CtsNetTestCasesLatestSdk

Change-Id: I7d18402f051051371f3054f6897b05b6da072105
Merged-In: I4bc0daf5ad9e4b4043f4a897ddab16aec8f8a536
2021-03-19 02:10:06 +00:00
Anthony Stange
83f77d83fd Merge "Revert "Replace the usage of UidRange"" 2021-03-18 16:40:53 +00:00
Anthony Stange
274c796731 Revert "Replace the usage of UidRange"
Revert "Replace the usage of UidRange"

Revert "Add shims for NetworkRequest"

Revert submission 1626206-replaceUidRange

Reason for revert: Breaking build - b/183106405
Reverted Changes:
I0b79c73e8:Add shims for NetworkRequest
I4bc0daf5a:Replace the usage of UidRange
I4e5aec6ef:Replace the usage of UidRange
I107c329d4:Expose uids related APIs in NetworkRequest and Net...

Change-Id: I5a4addc562d180487e2891fd2081c593126e6ffc
2021-03-18 16:30:59 +00:00
Chiachang Wang
1241156261 Merge "Replace the usage of UidRange" 2021-03-18 13:36:39 +00:00
Chalard Jean
3a1932cd79 Merge "Fix a bug where any() returns null" 2021-03-18 09:59:21 +00:00
Remi NGUYEN VAN
584cfc6b67 Merge "Remove networkAttributes resource usage" 2021-03-17 11:24:28 +00:00
Kimberly Kreider
6f4d35119f Merge "Enable networking tests to be included in partial MTS files as well as full mts." 2021-03-17 02:23:54 +00:00
Chalard Jean
1705798d13 Fix a bug where any() returns null
The type needs to be specified

Test: NetworkAgentTest
Change-Id: I7128ae520cb7175f1fb9467a94edfd1a4bdeb9da
2021-03-16 21:49:29 +09:00
Remi NGUYEN VAN
f1c04fb6b3 Remove networkAttributes resource usage
Supported network types are now deduced from system features, not the
networkAttributes resource.
Update the test to expect network types to be configured as per
resources before S, and to match system features on S+.

Bug: 146206136
Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest
Change-Id: I715924d562f439f7239c1c95d2dc5bca7095a123
2021-03-16 16:54:17 +09:00
Chalard Jean
bc786632cf Merge "[NS01.cn] Adjust calls for NetworkScore" 2021-03-16 06:36:07 +00:00
lucaslin
bfaefe42d1 Fix NullPointerException when running testRequestBackgroundNetwork
aosp/1622675 made handler to be nonnull but
testRequestBackgroundNetwork still pass null as handler when
calling requestBackgroundNetwork, so there is a NullPointerException
when running testRequestBackgroundNetwork.

Bug: 175662146
Test: atest CtsNetTestCases:ConnectivityManagerTest#testRequestBackgroundNetwork
Change-Id: I871992549dfc8cc356221164f1dd49c64f0dae67
2021-03-15 18:49:10 +08:00