Commit Graph

259 Commits

Author SHA1 Message Date
lucaslin
a19b59d8fc Add common CollectionUtils.{any,all} methods.
Test: new tests for this
Change-Id: I482c958af499bf8cdc8824c9586e9da619cd1f39
2021-02-01 15:22:56 +08:00
Xiao Ma
d2eaad9e81 Merge "Support IPv4/6 address type in Struct." 2021-01-28 06:06:30 +00:00
Xiao Ma
229b17ac0c Support IPv4/6 address type in Struct.
Bug: 163492391
Test: atest NetworkStaticLibTests
Change-Id: I17a753ea495f24d186b69083923a71a7ebccdc7b
2021-01-21 02:46:29 +00:00
Maciej Żenczykowski
0d05d57b89 add maze to OWNERS for common/native
(there's bpf related stuff in here)

Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7fcc19cdf48e468dfcbe5ee34f7bc07e261756b8
2021-01-19 18:34:13 -08:00
Xiao Ma
79c8682381 Merge changes I485e0bbc,I640f343d
* changes:
  Implement generic toString/equals/hashCode in Struct.
  Make a copy of HexDump in the frameworks/libs/net.
2021-01-19 04:03:16 +00:00
Xiao Ma
01c0fe5453 Implement generic toString/equals/hashCode in Struct.
Bug: 163492391
Test: atest NetworkStaticLibTests
Change-Id: I485e0bbc6949c1eb239d52401ff0403dd447619b
2021-01-19 04:02:37 +00:00
Xiao Ma
ef9fd0ae59 Make a copy of HexDump in the frameworks/libs/net.
Make HexDump as a part of module-shared library, being able to share
among of modules. As the first step, moving it to frameworks/libs/net
and be able to use inside net-utils-device-common.

Bug: 177622619
Test: m
Change-Id: I640f343dc6c334b7b4d44960cd043e32a989898d
2021-01-18 16:52:41 +00:00
Chalard Jean
312b5519a2 Fix an embarrassing bug... again.
For the same reason as aosp/1549479, the old method
needs to call the new one. It's not enough that they have
the same implementation ; when NF calls the old one, it
needs to indeed call the overridden new version.

Test: TH
Change-Id: I5e8700fc7455317da382f2328e3f548b3392ca41
2021-01-15 14:36:44 +09:00
Maciej Żenczykowski
02f9e5a413 Merge "Wrap BPF system calls into a versioned module" 2021-01-14 07:36:50 +00:00
Maciej Żenczykowski
a728a70497 Wrap BPF system calls into a versioned module
This isn't new code, this is basically copied verbatim from
  //system/bpf/libbpf_android/include/bpf/BpfUtils.h

Test: atest BpfMapTest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I80523c9ee0c1e4431f3192eb409ad68c737390a6
2021-01-13 18:29:56 -08:00
Paul Hu
8ad6b63d32 Merge "Add PermissionUtils" 2021-01-14 01:15:38 +00:00
Chalard Jean
54e2e4ca63 Merge "[NS01.5] Fix an embarrassing bug" 2021-01-13 13:53:39 +00:00
Chalard Jean
5b76d8d7dc [NS01.5] Fix an embarrassing bug
The existing implementations override the function with the
int, so the default impl of the function with the int has
to call the new one, not the other way around. Otherwise,
when implementations are migrated to overriding the new one
the old code continues to call the function with the int
and that wouldn't work as expected if it didn't call the
newly overridden method.

Test: TH
Change-Id: Ic31cec6481781e0185a0ba150be52390597737e7
2021-01-13 08:04:26 +00:00
Treehugger Robot
297c490647 Merge "[NS01] Add scoreless methods for non-score users" 2021-01-12 10:21:36 +00:00
Nucca Chen
88b345aa42 Merge "Default write to byte array with native order" 2021-01-12 08:06:03 +00:00
Chalard Jean
6f99e869ef [NS01] Add scoreless methods for non-score users
Test: FrameworksNetTests NetworkStackTests
Change-Id: I9ebd5cf17ec96b3e7c09ff041d65ee88d0b37cbf
2021-01-12 16:31:12 +09:00
paulhu
caf7014b2f Add PermissionUtils
Lots of methods are needed to check if the caller has any of
permission. So add PermissionUtils to support
enforceAnyPermissionOf() and checkAnyPermissionOf() usage.

Bug: 177187957
Test: buid, flash, boot to home.
Change-Id: Ie282989f1e73b614093feff28c497af6573a9ef8
2021-01-12 07:17:58 +00:00
Remi NGUYEN VAN
df3191ada8 Move NetworkCapabilitiesUtils to framework-common
Also move CollectionUtils which is a dependency.

NetworkCapabilitiesUtils is needed in BatteryStatsImpl, which is in
frameworks/base/core, so it uses the framework-common library.

The current framework-common target cannot use androidx annotations due
to users of this filegroup. This is being addressed in another change;
use android.annotation annotations in the meantime.

Bug: 174436414
Test: m
Change-Id: Ie188572a6db7c1bea37550a3410d7d828409a902
2021-01-07 12:05:30 +09:00
markchien
22bfada06e Default write to byte array with native order
Bug: 173167302
Test: atest BpfMapTest
      atest StructTest

Change-Id: I60a22ea4cd44697773d98d1720c02cc771643a9e
2021-01-05 00:38:54 +08:00
Baligh Uddin
ffe8f93ce4 Merge "Adjust visibility rules for migration" 2020-12-28 14:03:37 +00:00
Xiao Ma
ed82179342 Merge "Support common MacAddress Type in Struct." 2020-12-28 02:03:56 +00:00
Remi NGUYEN VAN
d5a89c61fd Merge changes from topic "netutils_split"
* changes:
  Add DeviceConfigUtils version caching and tests
  Add getDisplayTransport
  Split NetworkStackUtils to frameworks/libs/net
2020-12-28 01:17:41 +00:00
Baligh Uddin
fcbda3ac66 Adjust visibility rules for migration
Adjusting visibility to accomodate migration of
frameworks/opt/net/wifi to packages/modules/Wifi.

BUG: 137323948
Test: TH
Change-Id: Iee3f2dc6fc5f3262fa9e81626a3e15a3226e4ab7
2020-12-27 15:10:36 +00:00
Serik Beketayev
a3c54cb19b Merge "[Mainline] ProxyInfo migration" 2020-12-25 08:32:04 +00:00
Remi NGUYEN VAN
31c6d82be0 Add DeviceConfigUtils version caching and tests
Querying the APK version can be relatively expensive, so cache it with a
static. Package version cannot change without restarting the process.

Also add some testing for flags being equal to the min/max values.

Bug: 17454103
Test: atest NetworkStaticLibTests
Change-Id: I18c298beb843e0a9f76162d353623bb15ab155f1
2020-12-25 16:48:33 +09:00
Remi NGUYEN VAN
a744975b3e Add getDisplayTransport
While networks can have multiple transports, users generally think of
them as "wifi", "mobile data", "vpn" and expect them to be classified
as such in UI such as settings.
Add a getDisplayTransport utility that returns which transport should
be used for UI display, from a list of transports of a network.

Bug: 174436414
Test: atest NetworkStaticLibTests
Change-Id: Iaefb47bcaa2f6ce2e7a2ae5011c340154009ac3c
2020-12-25 16:23:34 +09:00
Remi NGUYEN VAN
b86b34da48 Split NetworkStackUtils to frameworks/libs/net
Split DeviceConfig and collections-related utilities to CollectionUtils
and DeviceConfigUtils in frameworks/libs/net.

Also add implementations for contains(array, value), to avoid usage of
internal non-API utils.

The original tests are based on mockito-extended, so also add to
NetworkStackTests as a dependency. This also requires setting the test
app as debuggable in its manifest.

Bug: 17454103
Test: atest NetworkStaticLibTests
Change-Id: Ie9bed66a08b7370ebe50d0a7240b788f8b31aa77
2020-12-25 16:23:25 +09:00
Xiao Ma
cd6104ff70 Merge "Add ETHER_BROADCAST and DEFAULT_LINK_MTU constants." 2020-12-25 01:38:03 +00:00
Serik Beketayev
57969d0ec9 [Mainline] ProxyInfo migration
Bug: 173455434
Test: mma

Change-Id: I49f7f491acc657051d9c79fc24605d4896cbc315
2020-12-23 22:15:42 -08:00
Xiao Ma
81a17c3fc6 Support common MacAddress Type in Struct.
MacAddress class is helpful to represent a 48-bits long MAC Address,
we have to use 6-bytes array to interpret a MAC Address without a
specific annotation type. To better parse the MAC Address appeared
in the ether header, link-layer address option or Bpf class, it's
worth supporting this specific type.

Bug: 163492391
Test: atest NetworkStaticLibTests
Change-Id: I1f716e5d4f38372fc5b7ee32e208d55a072c1e51
2020-12-24 04:59:21 +00:00
Baligh Uddin
fe99df5a25 Add visibility rule for migration.
Add paths to visibility needed for tests.
Soong allows specifying paths w/o validation.  Once the
migration is complete, we can remove the old path in
visibility rules.

BUG: 137323948
Test: TH
Merged-In: Id19c650246a8f3d55d7b6a874840a6eebcd9eb17
Change-Id: I68de6a67b978ed5a2e721adf41329af349076696
Exempt-From-Owner-Approval: Cleanup CL
2020-12-24 03:28:41 +00:00
Remi NGUYEN VAN
6c67e2723d Merge "Add visibility rules for Connectivity project" 2020-12-24 01:46:30 +00:00
Xiao Ma
acc47e60da Add ETHER_BROADCAST and DEFAULT_LINK_MTU constants.
ETHER_BROADCAST is used to fill the destination mac address of ether
header, it was defined in the DhcpPacket.java, move it to a common
place for other usecases.

Also have a link mtu constant(default value is 1500 bytes), irrelevant
to specific link-layer type.

Bug: 175830307
Test: m
Change-Id: I422d284cd8fa943bd745ad29229a54515135a3c4
2020-12-23 08:01:45 +00:00
Chalard Jean
359a533e56 Merge "Make Readhead more usable in multithread." 2020-12-23 00:33:32 +00:00
Remi NGUYEN VAN
128c31f0b8 Add kotlin-reflect to net-tests-utils
This fixes failures in CtsNetTestCases, where
TestableNetworkCallback.TAG cannot be used because
it uses kotlin-reflect.

Change-Id: I7e76fe224b1098c967665275eac24fcac08fca23
Fixes: 176047509
Test: atest CtsNetTestCasesLatestSdk
2020-12-21 07:16:52 +00:00
Chalard Jean
460e78931a Make Readhead more usable in multithread.
There doesn't seem to be a way to get any code at all
to run in a generic way on the thread that will execute
a test in android JUnit. JUnit can do it, but the android
harness imposes a thread hop.

This is inconvenent with ReadHead, because ReadHead can't
be used in multithread for semantic reasons : it would
make no sense at all. ReadHead enforces this today in a
relatively strong fashion.

But technically, the only guarantee that is needed is that
poll() is executed only on one thread in slabs of time
defined between a read barrier and a write barrier, where
the write barrier of the previous slab happen-before the
read barrier of the next slab. This in generally speaking
a bit difficult to achieve, but the tests run satisfy this
condition by starting the thread after executing the
@Before methods and joining it before executing the @After
methods. So in fact, it's safe to use ReadHead during
the befores and afters, if a bit uncomfortable, as long
as only one thread uses it during the before, one thread
during the test, and one thread during the afters.

This patch relaxes the enforcement on ReadHead to accept
the usage above. If any slab of time contains usage of
poll() on multiple threads, this will instead crash with
ConcurrentModificationException in almost all cases. It's
no longer possible to detect every possible misuse of
poll() under these conditions, but with this code it's
going to be very unlikely at each test run that the code
is incorrect and still doesn't crash, so incorrect use
should still cause at least very severe flakiness.

The main drawback, aside from the very slight performance
penalty, is that some use can be accidentally correct and
this code will now accept it. So it's possible that code
that is only accidentally correct is accepted, and a
seemingly unrelated change later breaks that correctness,
causing seemingly unrelated tests to fail.

Still, this is going to be an improvement in usability
of ReadHead. We'll no longer need to have lazy creation
of it, and it will be possible to check remaining events
after a tests runs.

Test: FrameworksNetTests NetworkStackTests
Change-Id: If87eef1686b235e53cb444a32f9985b4c2a0a901
2020-12-21 15:47:09 +09:00
Chalard Jean
1aadbb0afd Merge "Move util classes to their destination package" 2020-12-21 05:35:09 +00:00
Xiao Ma
ce033d4824 Move Struct.java to com.android.net.module.util package.
Bug: 163492391
Test: atest NetworkStaticLibTests
Change-Id: If7d54f0356ce4d6426011914df0a2e85784daebd
2020-12-17 15:36:23 +00:00
Xiao Ma
127532321c Merge "Add new APIs writeToByteBuffer/writeToBytes for generic Struct class." 2020-12-17 02:11:50 +00:00
Chalard Jean
ceaf7d0edc Move util classes to their destination package
Test: FrameworksWifiTests FrameworksNetTests
Change-Id: I93e9cfd968e08f983e3fd9f7196c455c79a0f32d
Merged-In: Id19c650246a8f3d55d7b6a874840a6eebcd9eb17
2020-12-16 08:50:20 +09:00
Orion Hodson
72472e4202 Merge "Share JNI file descriptor helper code" 2020-12-15 06:25:37 +00:00
Lorenzo Colitti
a726723ffb Add logging to TestableNetworkCallback.
This is not super useful because it cannot identify different
NetworkCallback objects from each other, but I've found it to be
better than nothing.

Test: manual
Change-Id: Ib402161f361c0f9fb68701bf171cbc99f598dafd
2020-12-14 14:43:42 +09:00
Orion Hodson
4ec55ea007 Share JNI file descriptor helper code
Move JNI File descriptor code from NetworkStack into a common native
static library.

Bug: 158749603
Test: atest NetworkStaticLibTests / treehugger
Change-Id: I3d14587ee8e8590b727736d7d2e29cba687e5514
2020-12-11 23:15:44 +00:00
Xiao Ma
f4cb6d6789 Add new APIs writeToByteBuffer/writeToBytes for generic Struct class.
Split the original U64/UBE64 into two groups: U63/UBE63 which could be
represented by long primitive directly and U64/UBE64 which should be
represented by BigInteger class.

Also fix the endianness-related issue to support both of big-endian or
little-endian input ByteBuffer, and writeToBytes API outputs the bytes
array in appropriate order then.

Bug: 163492391
Test: atest android.net.util.StructTest --rerun-until-failure
Change-Id: Ie9c07fac6dcfceb8efdf1d6b56ce6ff1e845f477
2020-12-07 17:35:03 +09:00
Remi NGUYEN VAN
b1d2c89862 Add NetworkStackConstants to framework/ am: ef5de53830
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1512756

Change-Id: I294d9dd8a4b451dd0de5f1d6e211e4ab61fc7d80
2020-12-04 03:18:27 +00:00
Remi NGUYEN VAN
1ba696dbf7 Add NetworkStackConstants to framework/
The constants are also useful for bootclasspath code, for example in
Ikev2VpnProfile.

Bug: 174436414
Test: atest FrameworksNetTests NetworkStackTests NetworkStaticLibTests
Change-Id: I34458fe6568a73533f956f86ed7bb50d45aa7d7e
2020-11-30 17:19:18 +09:00
Remi NGUYEN VAN
38afb0cd07 Add visibility rules for Connectivity project
The packages/modules/Connectivity project contains module code that can
depend on net-utils-device-common or net-utils-framework-common.

Bug: 171540887
Test: m
Change-Id: Ie754e3f55d78aabff4cef2da3a2a94a1204bd5e5
2020-11-27 13:59:48 +09:00
TreeHugger Robot
517e51d755 Merge "Mark ab/6881855 as merged" into stage-aosp-master 2020-11-25 02:31:19 +00:00
Xiao Ma
fb21a2d0c3 Merge "Introduce cache schema for generic Struct class." 2020-11-25 00:47:18 +00:00
Xiao Ma
a76690a3b7 Introduce cache schema for generic Struct class.
Bug: 163492391
Test: atest android.net.util.StructTest --rerun-until-failure
Change-Id: Idffad7d3b907d8853ed7d296808a2e0e2736cbbe
2020-11-24 18:03:07 +09:00