Commit Graph

204 Commits

Author SHA1 Message Date
Chalard Jean
d6f4efb1a8 Add hidden constants for communicating about local network agents
Test: FrameworksNetTests
Change-Id: Ic490fee6ee70d74acff0a290199b2946817173d0
2023-10-12 13:30:49 +09:00
Treehugger Robot
760bcac429 Merge "Add some tests back which were removed for fixing kotlin nullable errors" into main 2023-08-24 04:14:28 +00:00
Motomu Utsumi
5324475f6e Add some tests back which were removed for fixing kotlin nullable errors
Followup CL for aosp/2700076

Bug: 296972712
Test: build with aosp/2688146
Change-Id: I617b330c42a99e4c839adac2ea614756b5955ce9
2023-08-24 11:25:21 +09:00
Treehugger Robot
b5208bad3e Merge "Ignore EXCLUDED_ROUTES LinkPropertiesTest up to S_V2" into main 2023-08-22 08:19:25 +00:00
Yuyang Huang
7fe61f4cbd Ignore EXCLUDED_ROUTES LinkPropertiesTest up to S_V2
The platform doesn't allow overwriting compat flags that have target SDK
lower than the platform SDK in release build. Ignoring the test cases
that need compat flag overwrite up to S_V2 makes the MTS pass on S
device.

Bug: 296248982
Test: TH
Change-Id: Iab102725004c39b4dc3c0200c9bc673dd6be1302
2023-08-22 15:17:38 +09:00
Colin Cross
4e5a061f26 Fix kotlin nullable errors in Connectivity tests
Fix kotlin nullable errors that were exposed by setting the retention
of android.annotation.NonNull and android.annotation.Nullable to
class retention.

Bug: 294110802
Test: builds
Change-Id: Id49e4a2ee0b7b463d99bce6eb22919b84c21443a
2023-08-09 10:57:35 -07:00
chiachangwang
65240048ce Create v4 mapped v6 correctly
Tests verifies the behavior with v4 mapped v6. The
taken parameter should be a v6 address. However,
InetAddresses.parseNumericAddress() will translate a v4
mapped v6 address into v4. This does not actually test
the behavior. The constant should be created via
Inet6Address.getByAddress() so that it will be an
expected Inet6Address.

Bug: 291869581
Test: atest NattKeepalivePacketDataTest
      w/ and w/o aosp/2626269
Change-Id: I2f086f0fe7d1dd038f5d850f2281deb807c837cf
2023-07-20 03:14:08 +00:00
Paul Hu
f51a0139a2 Merge "Move NsdServiceInfoTest to common tests" 2023-07-03 06:24:43 +00:00
Remi NGUYEN VAN
64020abf11 Set test component in common OWNERS
Move the test component configuration from subdirectories
to the common OWNERS file. This ensures that all test directories
like unit/ that did not have the component set are covered.

Bug: 288137916
Change-Id: I48fbe846309cace41588c5ff3dfd46e878c38576
Test: TH
2023-06-21 02:54:13 +00:00
chiachangwang
e91f8dc3c4 Fix flaky test in NattKeepalivePacketDataTest
The testConstructor_afterR is a new added test which should be
run with latest connectivity module, but some test combinations
do not contain latest connectivity module which will fail the
test. Add ConnectivityModuleTest annotation to skip combinations
without latest connectivity module.

Bug: 287226038
Bug: 196453719
Test: atest ConnectivityCoverageTests
Change-Id: I16dfa8f86f77bb3561a24684e7823f8d45b7613d
2023-06-15 02:20:44 +00:00
chiachangwang
c18f0bbbb3 Add helper method to generate a v6 NAT-T keepalive packet
This is a part of preliminary work for sending a v6 NAT-T
keepalive packet in a v6 only network. This commit
release the constraint on constructing a v6 NAT-T keepalive
packet.

Bug: 196453719
Test: Manually connect to v6 only network and check if the
      keepalive packets are sent with subsequent commit
Test: atest FrameworksNetTests with the updated test
Change-Id: I9dc96e840265c5dee6b9e3ef2b3901a0aeb4ff9e
2023-06-13 11:50:13 +00:00
chiachangwang
60179ec28e Use assertFailsWith to verify exception cases
Test: atest FrameworksNetTests
Change-Id: If7373a1e6543975bee9c646384f6ca4d643a1711
2023-06-09 06:08:39 +00:00
chiachangwang
8af048721a Correct the order of import and remove unused definition
Test: atest
Change-Id: I60c409db5436a5ba9fffdee9df24158f15751658
2023-06-07 06:46:29 +00:00
Yuyang Huang
79a245e16f Update the SDK version to 34 in ConnectivityTestsLatestSdkDefaults
NsdManagerTest need to be updated because the older check was incorrect,
the new behavior should be observed on T when the compat flag is enabled
as well.

Test: m
Change-Id: I5d2e87b1ab5a114005a223e7ccd865540c0fdb78
2023-05-29 15:31:45 +09:00
Remi NGUYEN VAN
8a78f043ea Merge "Do not crash when passing null into buildTemplateMobileAll" 2023-04-04 01:27:41 +00:00
Yan Yan
966fb798a1 Retain subscription IDs on restricted test networks
Fix the bug where subscription IDs will be cleared
on a restricted test network

Bug: 263415068
Test: NetworkCapabilitiesTest
Change-Id: I977781cd81f9d86858bd264825d66a2a69f6ce53
2023-03-30 07:49:13 +00:00
Junyu Lai
2c12f922de Do not crash when passing null into buildTemplateMobileAll
Test: atest FrameworksNetTests:android.net.connectivity.android.net.NetworkTemplateTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.netstats.NetworkTemplateTest
Bug: 273963543
Change-Id: I0a8f94df124147e92d35cf474b3d69d1dee6902c
2023-03-30 13:59:02 +08:00
Yan Yan
acd71e68a6 Add allowed capabilities on non cellular test networks
This commit expands the allowed capabilities of non cellular test
networks to include another three values, so that CTS can verify
features that do network selection based on those capabilities.

It is relatively safe becuase for apps that request TRANSPORT_CELLULAR
and the affected capabilities, test networks will still not become their
default networks.

Bug: 263415068
Test: atest NetworkCapabilitiesTest(new tests)
Change-Id: I2e348e4722ecdaa6e277fe77968916ffa2f16af9
2023-03-22 18:27:19 -07:00
Patrick Rohr
98021b650b Connectivity Tests: join handler thread after calling quitSafely
Somewhat surprisingly, HandlerThread#quitSafely is *not* a synchronous
method, so the tearDown() method still needs to wait for the thread to
join.

Test: TH
Change-Id: I0433e2100adf9299a67af5c259a518cf44f4be57
2023-03-17 01:01:09 -07:00
Paul Hu
839b81e22f Move NsdServiceInfoTest to common tests
- NsdServiceInfoTest can be the unit and cts test because
  NsdServiceInfo is a Parcelable class. Thus, move
  NsdServiceInfoTest class to common tests directory.
- Also add ConnectivityModuleTest annotation because the tests
  are using some connectivity APIs which need to run with the
  latest module.
- Fix some coding style errors.
- Remove unnecessary ThreadPolicy code which may affect other
  tests.

Bug: 266839012
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: Idc4251ef7a1efa294c8a692eb09129440691a22e
2023-03-08 01:43:11 +00:00
Aaron Huang
7e6e5b425c Delete testUnsupportedAppUsageConstructor from coverage test
This tests @hide API which doesn't really officially supported.
Removed from coverage test.

Test: build, FrameworksNetTests
Change-Id: I6375e7713b8ae67486b3df80d13c19b3adaa3560
2023-03-03 15:16:36 +08:00
Aaron Huang
69086d6cbc Fix backward compatibility issue for removed wildcard match rule
A template with type MATCH_MOBILE could have empty subscriber
IDs but it should not contain one of subscriber IDs is null.

An app might still build a template through the constructor
which is annotated with @UnsupportedAppUsage. NetworkTemplate
will throw an exception when the app trying to construct a
template with type *_WILDCARD. The constructor should be
backward compatible with old version so this change is to add
the backward compatibility to have NetworkTemplate not throw
an exception.

Bug: 267701889
Test: FrameworksNetTests
Change-Id: I23a607dae508e0c53520e2edf187cb611ed36b68
2023-02-21 14:07:15 +08:00
Mark Chien
7c3e8e62af Merge "Allow jarjar com.android.server*" 2023-02-15 02:07:03 +00:00
Mark
53e71c3f3f Allow jarjar com.android.server*
Jarjar com.android.server* and adjust the test by jarjar
FrameworksNetTestsLib to make sure the test cases still can access
package sope fields. Don't auto-jarjar non-connectivity module tests
in FrameworksNetTests because some non-connectivity module test cases
rely on service.core and service.net. The reason why not auto-jarjar
whole ConnectivityCoverageTests because tethering doesn't adopt
auto-jarjar-gen yet. The coverage test must jarjar the same as module so
that test coverage can calculate correctly.

Remove com.android.server* from proguard becasue it already be covered
by android.net* after jarjar'ed.

Move MetricsTestUtil to non connectivity module test group because it
only be used for IpConnectivityEventBuilderTest which is non connectivity
module test. Only jarjar the util without jarjar the caller make the test
failure.

Bug: 248001529
Test: atest ConnectivityCoverageTests FrameworksNetTests

Change-Id: I8439341ef4c03f29697fdf34557ea8ef2825d691
2023-02-14 15:43:43 +00:00
Yuyang Huang
90a2cbdd8d Moves all compatibility flags to ConnectivityCompatChanges.java
ConnectivityCompatChanges.java becomes the centralized place for all the
CompatChanges used in the Connectivity module. By putting all the
CompatChanges here, we are able to manage them under a single
platform_compat_config.

Bug: 268440216
Test: atest FrameworksNetTests
Change-Id: I3e17af545718073d7d1c96e27298e7790563fd33
2023-02-09 19:51:37 +09:00
jahinimtiaz
16d8454e2c Update preparers to align across everything
Carry the exact same options.

Bug: 261855411
Test: presubmit
Change-Id: Ie76fd2a4591bbb9e8ce06fa2f68d0d9109162a98
2023-01-25 18:50:04 +00:00
Aaron Huang
ece181997c Remove *_WILDCARD constants from NetworkTemplate
NetworkTemplate was moved into mainline module and
provide Builder for external users to build template.
MATCH_MOBILE_WILDCARD and MATCH_WIFI_WILDCARD are not
exposed so currently the usage of these two constants
only in module. This change is to remove the constants.

After removing the constants, two methods matchesWifi
and matchesMobile are changed to adapt the original
matches[Wifi|Mobile]Wildcard behavior.

Bug: 238843364
Test: FrameworksNetTests
Change-Id: I9e156b504ce4eb903b39279e443fad27bc921186
2022-12-28 18:49:37 +08:00
Aaron Huang
ee23c03121 Remove mSubscriberId from NetworkTemplate
Currently NetworkTemplate provides Builder for users to build a
template and it supports multiple subscriber ids. The mSubscriberId
is a local variable in current design so it can be removed from
NetworkTemplate and also can be removed from the parameter of a
constructor as long as the constructor is not annotated with
@UnsupportedAppUsage.

Bug: 238843364
Test: build, FrameworksNetTests
      CtsNetTestCases
Change-Id: Ic6a695e1c1719111bf26ba905a38673952a24736
2022-12-28 12:09:21 +08:00
Aaron Huang
4854d055bb Remove mSubscriberIdMatchRule from NetworkTemplate
Currently, mSubscriberIdMatchRule is only used in NetworkTemplate
and it depends on if mMatchSubscriberIds is empty or not. Thus,
remove it since is not really necessary and replace it with
checking matchSubscriberIds if needed.

Bug: 238843364
Test: build, FrameworksNetTests
      CtsNetTestCases
Change-Id: Ic66d2ff2826846778b004bb15a4718a62fa1f470
2022-12-28 12:09:09 +08:00
chiachangwang
2ed983512c Rename getBypassable to isBypassable
Bug: 262336021
Bug: 256775913
Test: atest FrameworksNetTests
Change-Id: I5ac8f4f9a2a64189fc66d3c14af6da201a35e3e2
2022-12-15 04:22:43 +00:00
chiachangwang
a07cef1059 Add areLongLivedTcpConnectionsExpensive in VpnTransportInfo
Add VpnTransportInfo.areLongLivedTcpConnectionsExpensive() in API
surface to allow privileged apps to know whether the long-lived
TCP connections should be expensive in the VPN network.

This is expected to be used combined with getBypassable()
because connections should always go through a VPN that is not
bypassable.

Bug: 259000745
Test: atest FrameworksNetTests
Change-Id: Ic9bcdf43f252f22d12a1136902cc8bbf9cc731f5
2022-12-13 10:15:49 +00:00
Aaron Huang
859884a48f Make mMatchSubscriberIds as a NonNull variable
In current design, mMatchSubscriberIds can be null which has the
same meaning with empty set, and is not easy to maintain since it
need more checks for this variable when mSubscriberId is null.
Thus make mMatchSubscriberIds NonNull for the maintenance.

Bug: 238843364
Test: build, FrameworksNetTests
Change-Id: I6cfc529b5f4a39ded8598283ff968f2f4d1bc89f
2022-11-30 16:38:24 +00:00
chiachangwang
91bac1953c Move VpnTransportInfoTest to common test
Move VpnTransportInfoTest to common test to add the cts
coverage.

Annotate @ConnectivityModuleTest so that the test will
not fail with module that is not up-to-date, and use
assertParcelingIsLossless to prevent similar order module
in device case.

Bug: 256775913
Test: atest CtsNetTestCases:android.net.VpnTransportInfoTest
Change-Id: I1c40a4fc42468748d71c3df5c18b2ceb5b3769e1
2022-11-18 02:17:33 +00:00
Maciej Żenczykowski
44089f5080 trivialize apf property accessor dead code
(these are never called, but must exist for API reasons)

Bug: 257393783
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2f1cb29c5176539abe25bf767997ab4ed5eca6de
2022-11-04 11:43:22 +00:00
Chalard Jean
86317d8bb4 Add logs for changes in capabilities and score
This will be useful for diagnosing default network changes.

Logs may look like, for example :
Update capabilities for net 100 : -NET_CAPABILITY_OEM_PAID+NET_CAPABILITY_TRUSTED
Or :
Update score for net 100 : -POLICY_EVER_EVALUATED+POLICY_IS_VPN+POLICY_IS_DESTROYED

Test: FrameworksNetTests
      manual
Change-Id: Ic4788c599573aae9daeca995b8853800aaaba0b8
2022-10-14 14:32:38 +09:00
Chalard Jean
1d420b3b76 Move bit utilities to BitUtils.
Test: BitUtilsTest
Change-Id: I3e100c6087f61c2a13aa8558ee8f9a9ad480c681
2022-10-12 16:39:37 +09:00
Paul Hu
0655d1b89a Fix test flake on IpConnectivityLogTest
The test does not wait for sending all log events done, just
check the total received event number after 200ms. If one of
thread is running slowly, the test would be flaky. Thus, use
the Thread#join() to ensure the log events sending out
completely.

Bug: 245005401
Test: atest CtsNetTestCases
Change-Id: I90ad6960453c4639b6429a2e36e35d2d53148131
2022-09-16 18:27:53 +08:00
Lorenzo Colitti
9f74712d49 Merge "Simplify per-target-SDK LinkProperties tests." 2022-07-26 05:53:05 +00:00
Treehugger Robot
6ca83bcd7e Merge "Remove usage of isDevSdkInRange" 2022-07-22 11:01:02 +00:00
Lorenzo Colitti
ccd3020a91 Simplify per-target-SDK LinkProperties tests.
Currently these tests run as hostside tests and require a lot of
boilerplate, including their own CtsHostsideNetworkTestsApp3
build target.

Move the coverage to LinkPropertiesTest using the new-ish
@CtsNetTestCasesMaxTargetSdk31 annotation, and remove the
hostside tests.

The only test that is not being moved is one that checks the
behaviour of disabling the compat change on T. This test is not
very useful because it can only run on userdebug builds and not
on production builds, because CtsHostsideNetworkTestsApp3 targets
SDK 33. We do have test coverage for disabling the compat change
on an app targeting SDK 31, where it is allowed.

Fix: 236087258
Test: atest CtsNetTestCasesMaxTargetSdk31
Test: atest CtsNetTestCasesLatestSdk:android.net.LinkPropertiesTest
Change-Id: I6d4b1ba40f6cb63b30a600c227e9628858c03d73
2022-07-22 17:53:55 +09:00
Lorenzo Colitti
cc5054bfe3 Use the same target SDK in ConnectivityCoverageTests and CTS.
Currently, ConnectivityCoverageTests is manually set to target
SDK 31. This is different from CtsNetTestCasesLatestSdk, and
CtsTetheringTestLatestSdk, which are set to 33 and 31
respectively. Set all of them to 33 via a defaults clause.

ConnectivityCoverageTests must have the same target SDK as CTS
because it includes many of the CTS tests (e.g., everything in
common/).

Bug: 236087258
Test: atest ConnectivityCoverageTests
Test: atest CtsNetTestCasesLatestSdk
Test: atest CtsTetheringTestLatestSdk
Change-Id: I88c16dc28d9b73557def25d7f669ed14ae9d360a
2022-07-22 13:08:39 +09:00
Remi NGUYEN VAN
be077c1498 Remove usage of isDevSdkInRange
SdkLevel utilities should be used instead.

Test: atest
Change-Id: I81bf2807be30e3e4d2d7102cf03f267b28c65a08
2022-07-22 11:14:31 +09:00
Remi NGUYEN VAN
e55a88d30f Use jarjar rule generator for connectivity rules
(This rolls forward part of a previous change, now that jarjar was fixed
to not get very slow when the number of rules increases).

Autogenerate connectivity jarjar rules at build time, to avoid issues
with forgotten jarjar rules or hard-to-diagnose errors introduced by
incorrect rules.

This change causes all classes in framework-connectivity(-t) and
service-connectivity to be jarjared into android.net.connectivity, but
still avoids jarjaring classes in com.android.server as before, to keep
it small.
For many classes this differs from the original jarjar rule.

Notes on implementation:

 - connectivity-jarjar-rules now has a subset
   framework-connectivity-jarjar-rules containing only the rules
   necessary for framework-connectivity. This is necessary because
   framework-connectivity cannot depend on rules generated based on
   service-connectivity, as there would be a dependency cycle
   (service-connectivity depends on framework-connectivity); Soong even
   crashes with a stack overflow.

 - framework-wifi.stubs.module_lib is added to
   framework-connectivity-pre-jarjar as it is necessary to build it (it
   is already in impl_only_libs in the defaults).
   It is unclear why framework-connectivity-pre-jarjar could build
   before that (possibly because it was only used as "lib" ?)

 - Fix package-private visibility; for example NattSocketKeepalive,
   TcpSocketKeepalive are not API so should be jarjared, but are used
   by ConnectivityManager which is not jarjared, so they are not in the
   same package after the change. Package-private members in the
   former 2 need to be public to be accessible. Changes in this commit
   are all that is needed, as demonstrated by followup commits that move
   the classes to a different package without further changes, and that
   enforce that no class in an API package gets jarjared.

 - framework-connectivity-internal-test-defaults is separated from
   framework-connectivity-test-defaults, for unit tests that need to
   access internal jarjared classes. Such tests need to use the jarjar
   rules themselves too, so this is only appropriate for connectivity
   internal unit tests.

Test: atest ConnectivityCoverageTests CtsNetTestCases
Bug: 217129444
Change-Id: Ib1bd939b71c0171d945fc01b96195d2f620ff13b
2022-07-20 19:57:11 +09:00
Remi NGUYEN VAN
48380e4132 Revert EXCLUDED_ROUTES to only keep RTN_UNICAST
Revert the previous change to filter out all non-RTN_THROW routes when
EXCLUDED_ROUTES is disabled, as that behavior is CTS tested for T, and
has been used by T for a while. The previous change already ensured that
there is no behavior change on S, so this is the safest approach.

This fixes HostsideLinkPropertiesGatingTests.

Bug: 239046959
Test: atest LinkPropertiesTest CtsHostsideNetworkTests
Change-Id: I55e078cdc06341f4957fe7bc743c0022b2c7d3da
2022-07-15 16:46:14 +09:00
Remi NGUYEN VAN
66c27c18a2 Let LinkProperties#getRoutes() keeps returning all routes before T
Starting from T, VpnService supports exclude routes, which will
make the caller to get both of include routes and exclude routes
from LinkProperties#getRoutes(), and it's not expected to get the
exclude routes before T in production code even though the code
returns all routes.

But there is a CTS - LinkPropertiesTest#testRouteAddWithSameKey()
will try to add an exclude route and check if the result of
LinkProperties#getRoutes() contains that exclude route or not.
And the test is failed now since LinkProperties#getRoutes() will
only return include route if compat feature - EXCLUDED_ROUTES is
disabled. (EXCLUDED_ROUTES is enabled starting from target SDK T)

To fix this test failure, let LinkProperties#getRoutes() keeps
returning all routes if SDK is before T. This avoids changing
behavior on S, and even though there is still a behavior change
when upgrading to T, apps are unlikely to be relying on such
behavior, especially outside of tests.

Bug: 238061814
Test: Run "atest CtsNetTestCases:LinkPropertiesTest" on S build
      with mainline module which contains this patch.
Change-Id: Iac4362c4fe347ee3f06d5b21b0325fa69a7f27b6
2022-07-14 18:54:05 +09:00
Lorenzo Colitti
b64aeade58 Merge "Fix LinkProperties exclude routes tests on user builds." 2022-06-13 02:01:43 +00:00
Lorenzo Colitti
1bb94a3490 Fix LinkProperties exclude routes tests on user builds.
The tests fail on user builds because they target T and attempt
to override the compat change, which is not allowed on user
builds because the change defaults to on for apps targeting T+.
Fix this by marking the tests max target SDK 31.

Also improve the tests a bit:

- Use a RuleChain to make it explicit that
  CtsNetTestCasesMaxTargetSdk31 should be evaluated before
  EnableCompatChanges (otherwise the compat change rule would
  crash on user builds even if the max target SDK rule was going
  to skip the test anyway).

- Fix the IgnoreUpTo for all exclude route tests to say S+.
  Currently:
  - One says R+, which is incorrect because the updated
    LinkProperties code is in the connectivity module, which only
    goes back to S, not R.
  - The others say T+, which is incorrect because the update code
    is present on S.

Fix: 233553525
Test: LinkProperties test in CtsNetTestCasesLatestSdk passes on T user build
Test: LinkProperties test in CtsNetTestCasesMaxTargetSdk31 passes on T user build
Change-Id: Ie0e2f6761b90a65813ed3610c7b5e930a9fdc982
2022-06-13 02:01:35 +00:00
Junyu Lai
bfdd4407eb Return sorted NetworkStatsHistory
NetworkStatsHistory internally assumes that bucketStart is
sorted at all times. However, in the fields, we've found there
are some buckets of NetworkStatsHistory do not preserve the
order of timestamp, which is caught by the IAE when addEntry
is called.

In order to provide backward compatibility, return sorted items
instead of throwing IAE when adding entry into
NetworkStatsHistory instance.

Test: atest android.net.netstats.NetworkStatsHistoryTest#testBuilder
Bug: 233825704
Change-Id: If3187384bd1e90770ca5873b8ec73e852fff543d
Merged-In: If3187384bd1e90770ca5873b8ec73e852fff543d
  (pure cherry-picked from ag/18581718)
2022-06-07 10:51:52 +08:00
Remi NGUYEN VAN
5eaefa21bf Merge "Fix service resolve on tethering downstreams" 2022-06-01 05:31:14 +00:00
Natasha Lee
bcdb3c12ee Merge changes from topic "stats-migration"
* changes:
  Skip PersistentIntTest on S- device
  Don't clobber existing history entries.
  Ensure NetworkStats migrated snapshot is identical
  [MS82.1] Support network stats data migration process
  Add a PersistentInt class.
2022-06-01 03:03:02 +00:00