Commit Graph

272 Commits

Author SHA1 Message Date
James Mattis
4e2be816f6 PermissionUtils update to validate system feature
Update to PermissionUtils adding method for validating
availability of a system feature.

Bug: 210485380
Test: atest NetworkStaticLibTests:
com.android.net.moduletests.util.PermissionUtilsTest

Change-Id: Ic994af205da2ecf12ce7df4608d6c0ae29382ba7
2022-01-05 13:54:14 -08:00
Junyu Lai
c5f0e2c80a [MS19.2] Add constrain and total into utils
Test: atest FrameworksNetTests NetworkStaticLibTests
Bug: 204830222
Change-Id: Ib98a5d3acdec2988cebd5d184982e8b968b67b17
2021-12-27 10:48:52 +00:00
Taras Antoshchuk
ec4afa74a2 Merge "Revert "Revert "Suppress NewApi warnings for @SystemApi -> public APIs""" 2021-12-23 12:41:22 +00:00
Junyu Lai
7315362738 Merge "[MS10.3] Move multiplySafeByRational to NetworkStatsUtils" 2021-12-21 01:22:14 +00:00
Junyu Lai
0c538d9415 [MS10.3] Move multiplySafeByRational to NetworkStatsUtils
Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.NetworkStatsUtilsTest
Bug: 204830222
Change-Id: I87df4dc754f6fc46ea1a7e8770a3c76c019e097e
2021-12-20 09:14:00 +00:00
Taras Antoshchuk
98905d9ab7 Revert "Revert "Suppress NewApi warnings for @SystemApi -> public APIs""
This reverts commit d654277abfa0abd1268acc6db1753536509e41c8.

Reason for revert: Re-landing changes not related to postsubmit failure

Change-Id: I72fd6b908deeb293f1f3a342f006515029972089
2021-12-19 12:04:26 +00:00
Ayush Sharma
93ac7f6bed Merge "Revert "Suppress NewApi warnings for @SystemApi -> public APIs"" 2021-12-16 15:01:30 +00:00
Ayush Sharma
85bff36a58 Revert "Suppress NewApi warnings for @SystemApi -> public APIs"
Revert "Add VpnServiceBuilderShim for VpnService.Builder"

Revert submission 1551943-vpn-impl

Reason for revert: <DroidMonitor-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?branch=aosp-master&target=mainline_modules_x86_64-userdebug&lkgb=8007224&lkbb=8008168&fkbb=8007902 >, bug b/210979001
Reverted Changes:
I0e7aa077a:Add VpnServiceBuilderShim for VpnService.Builder
Ib12f5ab39:Suppress NewApi warnings for @SystemApi -> public ...
I59b9185cf:Unhide RouteInfo#getType and related fields
Ie5b62b2b2:Unhide IpPrefix(InetAddress, int)
I993a32d40:Add CTS tests for exclude VPN routes APIs
Ib24b2d3fb:Suppress NewApi warnings for @SystemApi -> public ...
Ic3b10464a:Add APIs that allow to exclude routes from VPN

Change-Id: I5b918dbf4293168c2a02cfe1c0f6ca8342b3195c
BUG: 210979001
2021-12-16 14:40:13 +00:00
Taras Antoshchuk
5c4736de42 Merge "Suppress NewApi warnings for @SystemApi -> public APIs" 2021-12-16 11:13:33 +00:00
Nucca Chen
4b4fee639d Merge changes I15757da1,Ie62b95bf
* changes:
  PacketBuilder: add support for UDP
  Add a class to build IPv4 TCP packet
2021-12-15 05:54:24 +00:00
Hungming Chen
de9ac2853b PacketBuilder: add support for UDP
Note that IPv4 and UDP options are not supported.

Test: atest NetworkStaticLibTests
Change-Id: I15757da19311c5bae9b8b56674bef467afa7142a
2021-12-14 23:16:13 +08:00
Hungming Chen
435833f2cd Add a class to build IPv4 TCP packet
Note that IPv4 and TCP options are not supported.

Test: atest NetworkStaticLibTests

Change-Id: Ie62b95bf759b74d72a5e85d312d17978422f633b
2021-12-14 18:12:34 +08:00
Taras Antoshchuk
9ad8a4a6aa Suppress NewApi warnings for @SystemApi -> public APIs
Android Lint doesn't handle API change from @SystemApi to public API
correctly (see b/193460475). We have to manually suppress those
warnings for now.

This CL suppresses warnings related to:
 - IpPrefix(InetAddress, int)
 - RouteInfo#getType

Bug: 186082280
Test: presubmit
Change-Id: Ib24b2d3fb21b86bd9e3555316a5a5bcb94434c00
2021-12-13 11:11:00 +01:00
Treehugger Robot
9a560bfaa2 Merge "Return null RtNetlinkAddressMessage if IFA_FLAGS attr is malformed." 2021-12-11 09:22:29 +00:00
Treehugger Robot
c6afd1c451 Merge "Add unit test to parse UTF-8 IFLA_IFNAME attribute." 2021-12-08 18:47:23 +00:00
Chalard Jean
997300b9d1 Support multiple cleanup blocks in tryTest{}
This is useful for some tests that need to make sure a few
things all happen, but some of them may throw an exception.

In vanilla Java you'd say

try {
  ...
} finally {
  try {
    ...
  } finally {
    try {
      ...
    } finally {
      ...
    }
  }
}

With this patch, you can pass a list of blocks to clean.
Kotlin :

tryTest {
  ...
} cleanupStep {
  ...
} cleanupStep {
  ...
} cleanup {
  ...
}

Java :
tryAndCleanup(() -> {
  ...
  }, () -> {
  ...
  }, () -> {
  ...
  })

This keeps the semantics of tryTest{} of throwing any
exception that was thrown in tryTest{} and adding the
exception in the cleanup steps as suppressed.

Test: new tests for this
Change-Id: Ie26b802cb4893e13a70646aa0b7887701dee1ec6
2021-12-06 17:57:29 +09:00
Xiao Ma
76ce961e1f Add unit test to parse UTF-8 IFLA_IFNAME attribute.
Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: I6e2f8c642fa1612e14b2a6b104164c9b54345053
2021-12-05 08:33:53 +00:00
Xiao Ma
9adc333f21 Return null RtNetlinkAddressMessage if IFA_FLAGS attr is malformed.
Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: I62732634d7cc31c6ca8a3ea63bb76079d8d22c14
2021-11-30 01:37:51 +00:00
Aswin Sankar
37176da85b [DnsPacketUtils] Knob for name compression support
- Allows clients of DnsRecordParser to explicitly mention
whether name compression is supported.

Test: atest NetworkStaticLibTests
Bug: b/207710965
Change-Id: Iac92f062a16f8f28f58cb180ab27e7626a9bd701
2021-11-29 18:58:48 +00:00
Chalard Jean
8f0a33054b Add catch{} to tryTest{}
Usage is
tryTest {
  ...
}.catch<Exception> {
  it
} cleanup {
  ...
}

Test: New tests for this
Change-Id: Idb7d9bd33034921c8f212288179b34a175e866f4
2021-11-25 16:26:42 +09:00
Chalard Jean
b6fdf63095 tryTest to return its last evaluated expression
This is the same thing try{} does, and allows to lift
return out of tryTest.

This allows syntaxes like :
fun foo() = try {
    "Foo";
  } cleanup {
    doSomeCleanup()
  }
}

val network = try {
    registerNetworkCallback
    callback.getNetwork()
  } cleanup {
    unregisterNetworkCallback
  }
}

Note: bypassing ktlint because of b/185077240

Test: FrameworksNetTests
Change-Id: Ib8f6fde7ccfd62fdcb3c1e3b7b03909ed94d4b23
2021-11-25 16:26:42 +09:00
Chalard Jean
bfbcacef6d Make sure no suppressed expression is present when they shouldn't
In fact the test already passes, because addSuppressed contains
an explicit test that if this === argument, then it doesn't add
it. But otherwise that's a bug in tryCleanup

Test: NetworkStaticLibTests
Change-Id: I202790bbe8d82445c5affdd9076561c2c6ea9b59
2021-11-24 17:07:28 +09:00
Chalard Jean
cf858ba920 Replace assert with assertTrue in CleanupTest
Test: NetworkStaticLibTests
Change-Id: I9b403d4d3491a5ee34b69d1fa4767defdaff70c2
2021-11-24 16:34:24 +09:00
Chiachang Wang
a37d20ed00 Merge "Enable strict_updatability_linting in frameworks/libs/net" 2021-11-22 02:48:24 +00:00
Treehugger Robot
1f8da2f79a Merge "Fix libs/net tests package" 2021-11-19 15:38:36 +00:00
Remi NGUYEN VAN
0cf724af27 Fix libs/net tests package
Move test classes that were not in the same com.android.module.util
package as their associated class into the right package, and make
net-utils-service-common visible to tests.

Bug: 207020032
Test: atest ConnectivityCoverageTests
Change-Id: Iabe86a7d4c2437b3d01d68d53fb01d4e3c05a02b
2021-11-19 18:33:12 +09:00
Chiachang Wang
7068c88921 Enable strict_updatability_linting in frameworks/libs/net
Enable the strict_updatability_linting here first as a prior
commit to enable strict_updatability_linting in connectivity
modules.

Bug: 188851968
Test: m lint-check ; atest NetworkStaticLibTests
Change-Id: Idac98a1c85bf5bb86269b1daad2b444cfb58db8a
2021-11-19 15:41:27 +08:00
markchien
f3448f905a Separate bpf and struct util from netlink util library
1. Separate bpf and struct libraries from netlink library.
2. Rename bpfmap jni library to respect its java side library.
3. Add README to explain the rules of adding shared jni library.
4. Also allow packages/modules/Connectivity to use bpf library.

Bug: 205088391
Test: atest TetheringTests
      atest CtsTetheringTest
      atest TetheringPrivilegedTests
      atest ConnectivityCoverageTests
Change-Id: I6e668818bede63b241cd901c0967f401613ddaf6
2021-11-11 18:50:53 +08:00
markchien
a14fb38df4 Add JniUtil to identify jni library by package name
Bug: 205088391
Test: atest NetworkStaticLibTests
Change-Id: I4ace7803f246bb396f53d878064fec1204e7c1ef
2021-11-11 18:33:04 +08:00
Xiao Ma
c9bcec238c Merge "Add data structures to parse netlink route messages." 2021-11-05 09:41:19 +00:00
Xiao Ma
2c0b10cb0a Add data structures to parse netlink route messages.
Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: If8c960849f4840b7c516c0d2579da8a805978e13
2021-11-05 07:21:29 +00:00
Chalard Jean
b61091b30b Move static utils to the static library
These classes used to live as a static utility in the
NetworkStack module, but that's not the right place for
them.

The point of this patch is to *not* require topics, as
any change in this space will very quickly spin out of
control and become unmanageable. As such, this starts
with creating equivalent classes in a single, easier to
manage change. Followup changes will migrate users of
the old classes to use these ones instead. Finally, the
old classes can be removed. This way, work can be
broken down into separate changes and be checked in
little by little, rather than one huge topic with many
changes doing everything in one go, which is unlikely
to be manageable.

There are no code changes from the originals, but a
number of reorganizations, most of them unavoidable.

• Vertical spacing (these classes fix it)
• Package names/imports are adjusted
• Added @hide on NetlinkMonitor
• Move all contents of RouteUtils to NetdUtils, because
  all methods depend on INetd, and some of the targets
  do not/cannot depend on netd-client
• Restrict the files used by the filegroup
  net-utils-framework-wifi-common-srcs, since that
  target does not necessarily provide all dependencies
  to all its users.
• Don't move NetworkMonitorUtils, since it depends on
  SdkLevel, and net-utils-framework-common-srcs is
  using **/*.java. It would have been possible to list
  explicitly all files actually necessary in this
  filegroup, but NetworkMonitorUtils is actually only
  used by the networking modules and not the framework.
  Eventually it should move but it doesn't have to
  be in this patch, which is complicated enough as
  it is.
• RouteUtils is now empty, because some new methods
  will be added to it soon and it is less expensive
  to keep it empty than to remove it now and add it
  again later.
• Merge NetdUtils, and unify the constants.
Some changes to satisfy checkstyle :
• Remove unused imports
• Reorder modifiers in InterfaceController
• Remove {} in IpNetworkMonitor
• Remove redundant public modifier in IpNetworkMonitor
• Add javadoc to a few methods
• Add whitespace around | in InterfaceParams
However, don't rename members in IpNeighborMonitor
like checkstyle would prefer because this would make
migration to this more involved.

Test: NetworkStaticLibsTests NetdStaticLibTests
Change-Id: I439121cba5d7ea95aa4d6c80ea25207c316880a0
2021-10-27 20:08:05 +09:00
Xiao Ma
c81f6db429 Add data structures to parse netlink IP address messages.
Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: I85f1b80925fa4a9397df931902d6de189902da72
2021-10-21 02:06:36 +00:00
Xiao Ma
d99cf6fe74 Add data structures to parse netlink link messages.
Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: Ida8c22a782eeaca738487d0dc041a459ef6bb936
2021-10-15 05:19:16 +00:00
Taras Antoshchuk
a888a013bf Merge "Zero out the non-prefix bits in NetUtilsTest" am: 5619ef3387
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1556262

Change-Id: I35fa4f887d941ec11922329855796f4d18dd5630
2021-10-06 08:52:18 +00:00
Taras Antoshchuk
de6f90ddbd Zero out the non-prefix bits in NetUtilsTest
Bug: 186082280
Test: atest NetworkStaticLibTests:NetUtilsTest
Change-Id: Ia6e1546b579fccc4fdf969031b389e64b8bb88c5
2021-09-21 11:33:05 +02:00
Chalard Jean
63e8809f5b Add a new utility to improve stack traces from automatic testing am: 6b56526bec
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1821095

Change-Id: I587f022c0a53dc56e654738686e222d384039500
2021-09-17 07:59:31 +00:00
Chalard Jean
5872cb8dbd Add a new utility to improve stack traces from automatic testing
A common pattern in tests is to use try-finally to make sure
cleanup is executed. This is necessary in CTS in particular to
make sure the test does not leave the device in a bad state.

The problem with using try-finally in this manner is that any
exception thrown in the finally{} block will override any thrown
in the try{} block. If the exception in finally{} is caused by
the one from try{}, then the stack trace reported by the tools
is the consequence and not the cause, making it difficult to
interpret the stack trace of automated tests.

So today, code has to make sure that either the code in
finally{} can't throw, or can't be affected by any code in
try{}, and both of these are really difficult to ensure in
presence in finally{} of code the tester does not control.

What we'd want ideally is a structure like try-finally, that
guaratees the code in finally{} is executed in all cases,
but that bubbles up the exception from try{} if any, and
will still bubble up any exception from finally{} if the
try{} block hasn't thrown.

That's what this new tool does.

Usage from Kotlin is like try-finally :
tryTest {
  testing code
} cleanup {
  cleanup code
}

Usage from Java can't be made as nice, but it's relatively okay :
testAndCleanup(() -> {
  testing code
}, () -> {
  cleanup code
});

Bugs listed below are some tests that have been affected by
this issue and have unhelpful traces.

Test: new test for this code
Bug: 198586720
Bug: 198998862
Change-Id: I54b30a7d53772feeade99274b6120a79707ad1c9
2021-09-17 12:21:09 +09:00
Aaron Huang
fe1d4a5a40 Fix type confusion in createRandomUnicastAddress am: 4d59f6cbe4
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1774705

Change-Id: Ia7e01a9fd83353e65bdae8175b097294ec0288c6
2021-09-16 09:38:57 +00:00
Aaron Huang
190f81d8d3 Fix type confusion in createRandomUnicastAddress
In createRandomUnicastAddress, it compare the mac with the
DEFAULT_MAC_ADDRESS. However, the DEFAULT_MAC_ADDRESS is
defined as a string, so the MacAddress equals check always
return false. This patch corrects the wrong String definition
to MacAddress.

Bug: 182165856
Test: NetworkStaticLibTests
Change-Id: Ia0905bfa7a4dd723f42903f77f9d925349ce193e
2021-09-15 18:09:56 +08:00
Xiao Ma
c2d34f33d1 Merge "Parse ND options in netlink message as an ByteBuffer slice." am: 04bc8227d6
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1777768

Change-Id: I1b924bac98d99372b133d8fca5b42e63f911eb7c
2021-09-07 08:27:35 +00:00
Xiao Ma
f9d8bb6b8e Merge "Parse ND options in netlink message as an ByteBuffer slice." 2021-09-07 08:14:14 +00:00
Xiao Ma
d7d65f4659 Merge "Add StructNdOptRdnss class to parse RDNSS option from netlink message." am: 3a8939f97b
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1777767

Change-Id: Ib05f875e7c9962a31cb621b0b4cfe27256ae8fce
2021-09-07 03:41:32 +00:00
Xiao Ma
4f4036d085 Merge "Add StructNdOptRdnss class to parse RDNSS option from netlink message." 2021-09-07 03:28:25 +00:00
Xiao Ma
4d6cafb5ca Parse ND options in netlink message as an ByteBuffer slice.
Parsing ND options as an ByteBuffer slice provides more reliable way to
read raw data from buffer no matter of the option might be malformed,
truncated or options with correct length and value, which doesn't affect
the buffer pointer advances to deal with the remaining data such as
attribute fields even if parsing ND options return null.

Bug: 163492391
Test: atest NetworkStaticLibsTest
Change-Id: Ic348abe6b5d1ceddfde47f19dcaec324927798d1
2021-08-31 02:06:13 +00:00
Xiao Ma
3fe08ae626 Add StructNdOptRdnss class to parse RDNSS option from netlink message.
Bug: 163492391
Test: atest NetworkStaticlibTests
Change-Id: I64059ce3576a3ce9467bd89a9dfcfc7b0498726d
2021-08-31 02:04:20 +00:00
Hungming Chen
f425e08a9e Test CollectionUtils.contains am: 536d685650
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1809998

Change-Id: I87edc84b13db381c364e63c9251fa4a5700876a4
2021-08-30 01:21:42 +00:00
Hungming Chen
8ce72e2518 Test CollectionUtils.contains
Test: atest NetworkStaticLibTests
Change-Id: I5a4426001a4ff7c4ca65be92085e9af3a21267e5
2021-08-27 17:38:18 +08:00
Xiao Ma
049b884c90 Migrate netlink-client to net-utils-device-common-netlink. am: a5abbe6529 am: 3818589c93
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1755889

Change-Id: Ia1a45efa17b46d2787e7385d6fb3e1e4648060fa
2021-08-04 07:56:23 +00:00
Xiao Ma
57b3442c65 Migrate netlink-client to net-utils-device-common-netlink.
Move netlink stuff to frameworks/libs/net/common/device, and build the
source files as an individual libraray. NetworkStack module just depends
on the net-utils-device-common-netlink.

Besides, also fix the incorrect format detected by checkstyle_hook script
such as missing java doc and make some public function as private, rename
the variable and etc.

Bug: 192535368
Test: atest NetworkStaticlibTests
Change-Id: I00e7f30be1bc9ebc2e24d7cd53efc403d6ba3daa
2021-07-29 03:52:09 +00:00