Commit graph android_packages_modules_Co.../Tethering/tests/unit
Message SHA1
Validate packageName with AppOpsManager#checkPackage
Change the permission check for tethering to checkPackage. This avoids
having to create context as another user which is not supported when
running the networkstack from secondary user.

Bug: 375535923
Bug: 216524590
Test: atest TetheringManagerTest TetheringServiceTest
Change-Id: Ibc3abe9ec2eab5ec976c6a9cbc08e1552203ee5d

Oscar Shu   authored and   Quang Luong   commited 2024-11-08 02:31:46 +00:00
5f9339d6a9
Revert^2 "Add UID and package name to TetheringRequest"
This reverts commit c8df03ffd7.

Reason for revert: Will fix issue with CL aosp/3326396

Change-Id: I220025f7c8f8145a232ac2ae7f44e16088c122d7

Oscar Shu   commited 2024-11-05 22:52:36 +00:00
46722ad4c4
Revert "Add UID and package name to TetheringRequest"
This reverts commit 462703c850.

Reason for revert: b/375535923

Change-Id: I7f77959490e8243bb95985bd28b67efcf0f3eb00

Patrick Rohr   authored and   Gerrit Code Review   commited 2024-10-30 16:29:15 +00:00
c8df03ffd7
Add UID and package name to TetheringRequest
Add a uid and package name to TetheringRequest to keep track of which
app the request belongs to, and also convey this information to Wifi
for later use with resource conflicts.

Bug: 216524590
Test: atest TetheringManagerTest TetheringServiceTest
Change-Id: If963694cb1bbd831ba379a76043825c94ef9d67a

Quang Anh Luong   commited 2024-10-23 15:52:03 +09:00
462703c850
Merge changes I24b0bf5f,I950d6787 into main
* changes:
  Introduce dependencies object for EntitlementManager
  Improved Entitlement UI Launch for multiple admin users

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-21 11:42:28 +00:00
0537a07d86
Introduce dependencies object for EntitlementManager
This is a no-op refactoring which only introduce
dependencies object injection to replace the wrapper class.

Test: atest TetheringTests:EntitlementManagerTest
Fix: 363972541
Change-Id: I24b0bf5f8951c453af1e9ae9278285d1a7b86849

Junyu Lai   commited 2024-10-21 10:22:48 +08:00
1193f08d69
Improved Entitlement UI Launch for multiple admin users
This change addresses the launch of entitlement UI activities
in Headless System User Mode (HSUM) on multi-user devices.

HSUM is a configuration where the system user (user 0) does
not represent a human user and primarily runs system services.
In this mode, the first user set up on the device is not user 0.

Modified the EntitlementManager logic to handle the
launch of the entitlement UI in multi-user environments,
specifically addressing scenarios where HSUM is enabled, which
includes:
  1. Always launch the UI to the foreground current user.
  2. Check whether the current user is allowed to show the UI.
This ensures the UI is presented to the appropriate user.

Test: Manual
  1. Mock requires entitlement
  2. adb shell cmd user set-system-user-mode-emulation headless
  3. enable hotspot
Test: atest TetheringTests:EntitlementManagerTest
Fix: 363972541

Change-Id: I950d678741a3f1714f347206fa161bcd7538b402

Junyu Lai   commited 2024-10-21 10:22:42 +08:00
b4a92ff791
Update requestDownstreamAddress calls in PrivateAddressCoordinatorTest
Bug: 369282577
Change-Id: Idccd15a8191e519a19afc71668e4ae2003efb71e

Handa Wang   commited 2024-10-18 01:29:56 +00:00
b1145dc6b1
Split requestDownstreamAddress into two methods
This CL splits requestDownstreamAddress into two methods:  requestStickyDownstreamAddress and requestDownstreamAddress.

- The requestStickyDownstreamAddress is equivalent to the former requestDownstreamAddress when useLastAddress=true.
- The new requestDownstreamAddress method allows allocating an address without providing the interface type and scope, which is Thread NAT64's use case.


Bug: 369282577


Change-Id: Ib839d121c7b46c492f2c4c1c61b52b5d017fa055

Handa Wang   commited 2024-10-18 01:29:53 +00:00
389bc7f13e
Update unit tests to reflect the changes to RoutingCoordinator and
PrivateAddressCoordinator

Bug: 350699020

Change-Id: Id0ae47dcb03c60b6caafa3feeecaf8b21092a101

Handa Wang   commited 2024-10-16 23:54:29 +00:00
d789d1b8de
Move PrivateAddressCoordinator from Tethering to staticlibs
This CL moves PrivateAddressCoordinator from Tethering to staticlibs
so that RoutingCooridnatorService can create an instance of
PrivateAddressCoordinator.

Bug: 350699020

Change-Id: I13ccd515972243719465c1c9ab844f802bc8884b

Handa Wang   commited 2024-10-16 23:54:29 +00:00
69aee7b055
Merge changes I2e556cf5,I5e42005f,I7b766ef6 into main
* changes:
  Remove unused method TetheringConfiguration#isRandomPrefixBaseEnabled()
  PrivateAddressCoordinator: introduce Dependencies class
  PrivateAddressCoordinator: move the special handling of WiFi P2P dedicated IP to IpServer

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-08 17:07:29 +00:00
a757293484
PrivateAddressCoordinator: introduce Dependencies class
This CL introduces the Dependencies class for PrivateAddressCoordinator
to allow changing the TetheringConfiguration in tests. Although in
production code TetheringConfiguration won't change after passed to
PrivateAddressCoordinator, there are unit test cases relying on changing
the configuration at runtime.

Bug: 369282577

Change-Id: I5e42005f85e784c0ce3ac9192248c9e4ed4e6147

Handa Wang   commited 2024-10-08 14:41:24 +00:00
88312f6451
PrivateAddressCoordinator: move the special handling of WiFi P2P
dedicated IP to IpServer

The source of
TetheringConfiguration#shouldEnableWifiP2pDedicatedIp is in the
Tethering's resources. As refactoring the code, we noticed that it will
be simpler to handle this at IpServer (constructed using
TetheringConfiguration) instead of at PrivateAddressCoordinator
(will require reflection to read the Tethering's resources).

Bug: 369282577
Change-Id: I7b766ef6a769043c2a4ca11741db5c16c5c57071

Handa Wang   commited 2024-10-08 07:00:32 +00:00
731ae53d71
Add MonitorThreadLeak to TetheringMetricsTest
TetheringMetrics creates a thread to process all metrics work on
a handler. This thread should remain active alongside the
Tethering service but should be closed in test class. Therefore,
add MonitorThreadLeak to ensure the thread is closed correctly.

Test: atest TetheringMetricsTest
Change-Id: Ic57beb3324945ddbb45fec9697056889044e680c

Paul Hu   commited 2024-10-03 12:51:50 +00:00
c714bf6d8b
Merge "Simplify tethering active session counting" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-03 09:01:50 +00:00
c286b551d9
Simplify tethering active session counting
The previous implementation for tracking tethering active sessions
was overly complex. This commit simplifies the logic by:

- Moving the counting to the BpfCoordinatorShimImpl (31 impl)
  where rule addition and deletion are centralized.
- Eliminating the unnecessary Android version check (S+) as
  the 31 shim only runs on S+.
- Relocating the tracking counters from
  ConntrackEventConsumer to the shim class, improving code
  locality and encapsulation.

This change addresses the feedback from the networking mainline
release council and resolves a release blocker.

Test: atest TetheringTests:com.android.networkstack.tethering.BpfCoordinatorTest
Fix: 370652384
Change-Id: I70ca58fc45694c738745d7a872272641a62551fd

Junyu Lai   commited 2024-10-03 16:04:56 +08:00
3e90bc85b3
Merge "Update the usage data when upstream is changed" into main
Paul Hu   authored and   Gerrit Code Review   commited 2024-10-02 13:38:03 +00:00
e7f557952e
Update the usage data when upstream is changed
Need to refresh the usage data. If the network switches back to
Wi-Fi after using cellular data (Wi-Fi -> Cellular -> Wi-Fi), the
old baseline might be inaccurate, leading to incorrect delta
calculations.

Also address some leftover comments.

Fix: 369306449
Fix: 370652336
Test: atest TetheringTests
Change-Id: I1c14aac533cee1d989b7ab354111f071da018058

Paul Hu   commited 2024-10-02 12:02:08 +00:00
7065213fca
Drastically simplify prefix and address selection process
This removes all the complex downstream prefix / address selection
logic and reduces it to generating a random address within the selected
prefix and checking whether it satisfies a set of conditions. If the
conditions are not met, the process is retried (for a total of 10 times)
before eventually moving on to the next prefix.

The conditions that must be satisfied are:
- Address within prefix does not end in .0, .1, .255
- Address is not contained within a range of commonly used prefixes.
- Prefix does not overlap with another prefix on the system.

Test: TH
Change-Id: I4c53bcaa29c11cde4df99d5bcb834fde94961da4

Patrick Rohr   commited 2024-09-27 20:47:13 -07:00
b9cfcce30a
PrivateAddress: Clarify the dependency
The dependency of PrivateAddressCoordinator on Context is too generic.
Actually it just needs the ConnectivityManager#getAllNetworks.

This CL clarifies the dependency and this provides flexibility of
instantiation of the class.

Bug: 369282577

Change-Id: I49043f7f557d83856d54cefc201208b7d9b9dd7f

Handa Wang   commited 2024-09-27 13:56:16 +00:00
1cda02fd4a
PrivateAddressCoordinator: remove the dependency on
TetheringConfiguration

We're removing the dependency on TetheringConfiguration because
TetheringConfiguration is not parcelable so it cannot be used in AIDL
API. Eventually we'll make PrivateAddressCoordinator expose its
functionalities via AIDL API at RoutingCoordinator.

Bug: 369282577
Change-Id: Id839d183b9463baa18a92a629370b4b8374f1ffd

Handa Wang   commited 2024-09-25 09:01:38 +00:00
664e1f4b89
PrivateAddressCoordinator: get rid of UpstreamNetworkState for
updateUpstreamPrefix()

This CL changes the signature of
PrivateAddressCoordinator#updateUpstreamPrefix to replace the
UpstreamNetworkState parameter with its member class. This is because we
want to make updateUpstreamPrefix() an AIDL API soon and
UpstreamNetworkState is not parcelable while its member fields are.

Bug: 369282577

Change-Id: Icf71d02d48c8c0d5dc2b21ee351efba956b6752d

Handa Wang   commited 2024-09-24 12:15:45 +00:00
8df9d34eb3
Merge "Make java_sdk_library dependencies explicit" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-09-10 19:12:45 +00:00
430a8ad33c
Merge changes from topic "tether-active-sessions" into main
* changes:
  Support active session metrics sampling
  Add unit test for get max counter when removing tethering client
  Track tethering active sessions counts

Junyu Lai   authored and   Gerrit Code Review   commited 2024-09-10 02:53:47 +00:00
ff3b206df0
Make java_sdk_library dependencies explicit
modules should specify the submodule of java_sdk_library that the module
actually depends on

Test: CI
Bug: 358613520
Change-Id: I0367068c901df98483f6cf95160d3e7801881b0a

Jihoon Kang   commited 2024-09-10 00:01:31 +00:00
8401b6a9f0
Support active session metrics sampling
This commit introduces a feature to monitor and upload active
tethering connection metrics. This will help us understand
the usage of tethering and improve the user experience.

The feature is disabled by default and will be gradually
rolled out.

Test: atest TetheringTests:com.android.networkstack.tethering.BpfCoordinatorTest
Test: manual test with:
      adb shell device_config put tethering tether_active_sessions_metrics 3
      m statsd_testdrive && statsd_testdrive -e 925
Bug: 354619988
Change-Id: I3b3f5ae068b127192c35541c6d9439b7367d54bd

Junyu Lai   commited 2024-09-09 16:35:03 +08:00
d2581d64fb
Add unit test for get max counter when removing tethering client
Test: atest TetheringTests:com.android.networkstack.tethering.BpfCoordinatorTest
Bug: 354619988
Change-Id: I9b4c4c265ca4e66bff353ea616afd0f1ad4339be

Junyu Lai   commited 2024-09-09 16:05:42 +08:00
0ea1136fcb
Track tethering active sessions counts
This commit implements the necessary counters to bookkeep
max connection count, which will be used in follow-up changes
to monitor and upload active tethering session metrics.

The feature is disabled by default and will be gradually
rolled out.

Test: atest TetheringTests:com.android.networkstack.tethering.BpfCoordinatorTest
Bug: 354619988
Change-Id: Iaf251b0ec08bde95c1b12df022db2e03179309de

Junyu Lai   commited 2024-09-09 15:44:50 +08:00
06b81b6af3
Process all accesses to TetheringMetrics on the handler thread
Since calling NetworkStatsManager.queryDetailsForUidTagState may
be blocked for up to 20 seconds, potentially leading to enable
Tethering failure, a handler thread is added to process this task
and prevent blocking.

Furthermore, thread safety is ensured for all accesses to the class
by the internal handler thread.

Bug: 282861165
Test: atest TetheringTests
Change-Id: I38d055e5c3f8dbb22eac97f858d4f56925e8ab36

Paul Hu   commited 2024-09-04 06:08:38 +00:00
26d4476007
Calculate and populate TX/RX bytes for each upstream in TetheringMetrics
Bug: 282861165
Test: statsd_testdrive 303
Test: atest TetheringMetricsTest
Change-Id: I9a358dfc22640f309ca52378ad826cd7dbcee9b3

Paul Hu   commited 2024-09-04 03:00:21 +00:00
ee9f387269
Initialize upstream data usage after tethering is turned on
Added logic to initialize upstream data usage after tethering is
turned on in TetheringMetrics, which is essential for tracking
data usage accurately.

Bug: 282861165
Test: atest TetheringTests
Change-Id: I0b91f6a5966f234ce9d6c67ad0edfe516645d38b

Paul Hu   commited 2024-09-04 02:00:12 +00:00
f982a1dc70
Merge "Add buildNetworkTemplateForUpstreamType() helper method" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-08-14 07:06:35 +00:00
0fd9d77ce9
Add buildNetworkTemplateForUpstreamType() helper method
The method handles different types of UpstreamType and constructs
the corresponding NetworkTemplate object.

Bug: 282861165
Test: atest TetheringMetricsTest
Change-Id: I1b7091e6da2712df6b6319e545465b409259f743

Wayne Ma   authored and   Paul Hu   commited 2024-08-13 03:57:36 +00:00
96496231c7
Do not block broadcast on handler processing
Instead of blocking the broadcast until onReceive returns on the
handler, only post in onReceive.

This should make no difference for the only user, the
mCarrierConfigChange listener in Tethering.java, as the callback still
runs on the handler.

Bug: 349919195
Test: atest
Change-Id: Ie8ce7afbe905b4c6972b3aabda2d7792c96eda6c

Remi NGUYEN VAN   commited 2024-08-09 10:59:06 +09:00
151be34424
Merge "Add isUsageSupportedForUpstreamType() helper method" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-07-15 10:43:42 +00:00
f4bae99d1d
Add isUsageSupportedForUpstreamType() helper method
This new helper method provides a convenient way to validate and
determine whether tethering metrics' data usage can be collected
for a given upstream type.

Bug: 282861165
Test: atest TetheringMetricsTest
Change-Id: I7527ce56815e1f7e9382be1a54b84c91552e1129

Wayne Ma   authored and   Paul Hu   commited 2024-07-15 09:30:43 +00:00
9651e04bf0
Merge "Let IpServer use RoutingCoordinator in R" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-07-12 04:07:16 +00:00
86219a1244
Let IpServer use RoutingCoordinator in R
On Android R, IpServer uses netd to set up tethering while on S+ it uses
RoutingCoordinator.

This CL lets Tethering own a RoutingCoordinatorService when the SDK
version <= R so IpServer can always use RoutingCoordinator instead of
netd.

Bug: 350699020
Test: CI

Change-Id: I0ed33fb050260c26be87079bed0e189716cd8782

Handa Wang   commited 2024-07-12 02:27:22 +00:00
7e9b330d04
Merge changes Ia8726375,I9d368d8a into main
* changes:
  Use Dependencies to mock static methods
  Add a new TetheringMetrics constructor

Paul Hu   authored and   Gerrit Code Review   commited 2024-07-12 01:14:31 +00:00
7e89d18900
Use Dependencies to mock static methods
This is a no-op change. Use Dependencies to mock static methods
instead of using spy().

Bug: 282861165
Test: atest TetheringTests
Change-Id: Ia8726375a8da17dab745848b046f4c32b84d5d77

Paul Hu   commited 2024-07-05 14:42:22 +00:00
99d585c2e8
Refactor RoutingCoordinator
- This CL puts RoutingCoordinator into staticlibs to make it usable by
both Tethering and ConnectivityService on R.
- This CL also changes the return type of
  ConnectivityInternalApi#getRoutingCoordinatorManager() to IBinder so
  it has fewer dependencies.

Bug: 350699020
Test: CI

Change-Id: Iba096e940795cd33e61c5141721394ad39e5ce6d

Handa Wang   commited 2024-07-05 05:26:54 +00:00
8f2c30664d
Add a new TetheringMetrics constructor
This is a no-op change. Add a new TetheringMetrics constructor
for the subsequent TetheringMetrics TX/RX calculation feature.

Bug: 282861165
Test: atest TetheringTests
Change-Id: I9d368d8ad527d73cc91e02ee72a5731fb4c6c195

Paul Hu   commited 2024-07-05 02:46:40 +00:00
2c743c8e11
Replace TetheringRequestParcel with TetheringRequest
Replace TetheringRequestParcel with TetheringRequest in the service
code. This makes future changes easier since TetheringRequest is a
proper class and not an AIDL object.

Bug: 216524590
Test: atest TetheringTest TetheringManagerTest
Change-Id: I0cdee597d393e53feb9fe9aff4d6c67330c88599

Quang Anh Luong   commited 2024-06-26 16:25:13 +09:00
3e65131ba3
Merge changes I47606693,Ia51bc3ab,Idef1a6d1,Ie6fbc3ee,I55064ee7 into main
* changes:
  Clean up BpfCoordinatorTest after refactors
  Move upstream interface BPF support check to BpfCoordinator
  Refactor BPF map update logic of upstream interface change
  Centralize IP neighbor monitoring in BpfCoordinator
  Get rid of BpfCoordinator#mPollingStarted

KH Shi   authored and   Gerrit Code Review   commited 2024-06-22 12:34:34 +00:00
4c701fbfa0
Move SyncStateMachine to staticlibs
Test: mm
Change-Id: I51685a454a3d0fab578fef1eeb42d600adef06e6

Patrick Rohr   commited 2024-06-21 08:25:25 -07:00
aa06b2bf8e
Clean up BpfCoordinatorTest after refactors
Removed the use of a real IpServer instance in BpfCoordinatorTest,
as it is no longer needed after the refactors in aosp/2716773 and
aosp/3113123.

Test: atest TetheringTests
Bug: 294025403
Change-Id: I4760669372275a0165f4980705e328c80e0649a5

KH Shi   commited 2024-06-21 11:35:39 +00:00
572b784fdc
Move upstream interface BPF support check to BpfCoordinator
Removed upstream interface BPF support check from IpServer and moved
it to BpfCoordinator. The support check can be performed directly in
BpfCoordinator using the interface name.

Test: atest TetheringTests
Bug: 294025403
Change-Id: Ia51bc3ab18dd21afdca9db9199fa060aab68f768

KH Shi   commited 2024-06-21 11:35:37 +00:00
582df23c7b
Refactor BPF map update logic of upstream interface change
Move upstream interface change handling for BPF map updates from
IpServer to BpfCoordinator. BpfCoordinator now manages all BPF map
updates.

Test: atest TetheringTests
Bug: 294025403
Change-Id: Idef1a6d1a16a35603e0b476bfdbe6a234f39f4be

KH Shi   commited 2024-06-21 11:32:39 +00:00
9174207bb6
Centralize IP neighbor monitoring in BpfCoordinator
This CL centralizes IP neighbor monitoring in the BpfCoordinator,
eliminating the need for redundant monitors in each IpServer.

Test: atest TetheringTests
Bug: 294025403
Change-Id: Ie6fbc3eeaa0ed4a34a6680714f44678e2d5b633a

KH Shi   commited 2024-06-17 03:03:18 +00:00
f2ccebf96b