Commit graph android_packages_modules_Co.../Tethering/src
Message SHA1
Log legacy tether() calls that succeeded
Log extra enums to audit usages of Wifi/P2P tether() that successfully
resulted in tethering on an interface.

Bug: 216524590
Test: build
Change-Id: Ia0d2a8fc1e508263c597bfd40fbefe5b49ec15d5

Quang Anh Luong   commited 2025-01-15 16:15:37 +09:00
1e60b9a0ea
Disallow legacy tether() API starting in B
As part of the major tethering refactor to associate every IpServer with
a TetheringRequest, tether()/untether() APIs should be completely
removed in B and all tethering should go through startTethering() (with
the exception of Wifi LOHS and Wifi P2P, which will move to
startTethering() in a future CL).

Bug: 216524590
Test: atest CtsTetheringTests TetheringTests

Change-Id: If7981f1ee7d80ff0a1cc0069ba7a4ebf79144160

Quang Anh Luong   commited 2025-01-15 08:59:42 +09:00
30d8a25db3
Merge "Revert "Send TetheringRequest to restart Tethering from IpServer"" into main
Quang Luong   authored and   Gerrit Code Review   commited 2025-01-06 18:49:59 -08:00
cc579ba0e9
Revert "Send TetheringRequest to restart Tethering from IpServer"
This reverts commit 685b8aa508.

Reason for revert: May break Bluetooth pre-T IPv4 prefix conflict handling if TetheringRequest is not specified. Instead we should add this to AOSP/3389321 when we can guarantee IpServer always has a tethering request here.

Bug: 384812983
Test: presubmit

Change-Id: I9c65e87804855fd293fa75c921de3d256caad1b3

Quang Luong   commited 2025-01-06 18:44:30 -08:00
df9cced512
Log usage of legacy tether API with Wifi
TetheringManager#tether() is deprecated and should not be used anymore,
especially for Wifi and Wifi P2P which already start and enable IpServer
based on WIFI_(AP/P2P)_STATE_CHANGED broadcast.

In order to refactor Tethering to only start IpServer with a final
TetheringRequest, we need to audit usage of tether() with Wifi and Wifi
P2P so that we can safely remove it from
Tethering.processInterfaceStateChanged (which starts an IpServer without
TetheringRequest in anticipation of a tether() call).

Bug: 216524590
Test: build
Change-Id: Ieb4bd14150a8b25257bee8ddc71e30037ec3a122

Quang Anh Luong   commited 2024-12-19 22:48:06 +09:00
31f85c6aea
Merge "Remove WRITE_SETTINGS permission from Tethering APIs" into main
Quang Luong   authored and   Gerrit Code Review   commited 2024-12-18 18:42:49 -08:00
915d138309
Merge "Fix legacy tether behavior for duplicate requests" into main
Quang Luong   authored and   Gerrit Code Review   commited 2024-12-18 00:37:54 -08:00
7f911faf5e
Exclude NET_CAP_LOCAL_NETWORK when listening for upstream network events
In the current design, the upstream monitor collects prefixes
of all upstream networks to prevent prefix conflicts,
which are coordinated by the PrivateAddressCoordinator.

However, the upstream monitor does not exclude the newly
added NET_CAP_LOCAL_NETWORK capability, which could be
held by a downstream network. This could lead to a prefix
conflict detection loop:
 1. In UpstreamNetworkMonitor, a prefix is collected from
    a local network and sent to the PrivateAddressCoordinator.
 2. PrivateAddressCoordinator detects a prefix conflict with
    an existing downstream prefix.
 3. The conflict notification is sent to the local
    network provider, triggering a recovery.

Test: atest TetheringTests:com.android.networkstack.tethering.UpstreamNetworkMonitorTest
Bug: 349487600
Bug: 382397803
Change-Id: I743d569394e190c8620b283689d853cd2f5e3f28

Junyu Lai   commited 2024-12-18 15:18:51 +08:00
6ad7599b5c
Remove WRITE_SETTINGS permission from Tethering APIs
As TetheringManager moves to a Public API, remove the weak
WRITE_SETTINGS permission and use TETHER_PRIVILEGED instead. System
callers can still aquire TETHER_PRIVILEGED, and public callers must be
Device Owner or Carrier App to bypass (to be done in a future CL)

Bug: 374400379
Test: atest TetheringTest TetheringServiceTest CtsTetheringTests
Change-Id: Ia192021ac48f9eb3f27cc8c412f17629ad16a587

Quang Anh Luong   commited 2024-12-18 13:53:04 +09:00
2782b3bddf
Fix legacy tether behavior for duplicate requests
Legacy duplicate tethering requests would restart tethering if a pending
request existed that was different (via equals()) from the new request.

However, this behavior existed before uid/package name was added to
TetheringRequest#equals(), so we should use new method to check
equality while ignoring uid/package name.

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

Quang Anh Luong   commited 2024-12-18 13:53:04 +09:00
2d260e9e35
Merge "Fix missing network id arguments" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-12-17 00:52:12 -08:00
3196da7da2
Fix missing network id arguments
Follow-up from aosp/3383831, some arguments are still missing,
adding them and update tests accordingly.

Test: atest NetdStaticLibTests
Bug: 349487600
Change-Id: I495291f1e57c3a32c015fc7dfa3c2e6e86663da8

Junyu Lai   commited 2024-12-16 11:27:32 +08:00
0969fe6e20
Merge changes I84da9c74,I1f3a68d2 into main
* changes:
  Add SkipNativeNetworkCreation flag in NetworkAgentConfig
  Refactor netd utility methods to support custom netIds

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-12-11 01:55:07 -08:00
0e8c8d9792
Refactor netd utility methods to support custom netIds
This is a no-op refactoring which:
  1. Updates netd utility methods to handle custom netIds.
  2. Rename internal methods to reflect the functionality.
  3. Import constants from TetheringManager to improve
     readability.

This refactoring is a prerequisite for future changes that will
utilize a new netId for routing instead of LOCAL_NETWORK_ID.

Test: atest NetdStaticLibTests TetheringTests CtsTetheringTest
Test: adb shell ip ru && adb shell ip ro show table local_network
Bug: 349487600
Change-Id: I1f3a68d24852b6bd85ce7be2ec58746e49b67636

Junyu Lai   commited 2024-12-11 10:47:13 +08:00
04783040d5
Merge "Disable multi-user check for entitlement provisioning" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2024-12-09 04:22:34 +00:00
642f418c59
Disable multi-user check for entitlement provisioning
This commit updates the logic for launching the entitlement UI
for tethering when there are multiple users. It disables the
check for whether the current user can change tethering settings
for secondary users due to a potential issue with calling
createContextAsUser. This reverts the behavior change introduced
in aosp/3289821.

One expected outcome is this change will break tethering with
entilement check enabled for HSUM-enabled devices. Since there
is no currently HSUM-enabled projects, disable this check is
safe.

Test: Manual
  1. Mock requires entitlement
  2. adb shell cmd user set-system-user-mode-emulation headless
  3. enable hotspot
Test: atest TetheringTests:EntitlementManagerTest
Bug: 382624069
Change-Id: Ife3b721d1374602a8fa760954b372429cda1bf71

Junyu Lai   commited 2024-12-09 10:10:58 +08:00
b14cd877fb
Introduce interfaceName field into TetheringRequestParcel
Bug: 340376953
API-Coverage-Bug: 365678805
Test: Presubmit
Test: atest EthernetTetheringTest
Test: atest TetheringTest
Test: atest NsdManagerDownstreamTetheringTest -b
Test: atest TetheringManagerTest -b

Change-Id: I8025cc2e238b8f9516bf18d8ea0253f1c58a05e6

Seungjae Yoo   authored and   Quang Anh Luong   commited 2024-12-05 08:14:10 +09:00
eab1de47f4
Merge changes I2dd18f9d,I5cc02c8a into main
* changes:
  Stop tethering when the current user is not allowed to do entitlement check
  Use TestableResultReceiver in EntitlementManagerTest

Junyu Lai   authored and   Gerrit Code Review   commited 2024-11-27 04:33:45 +00:00
25e0517124
Stop tethering when the current user is not allowed to do entitlement check
This commit ensures that EntitlementManager sends the appropriate
error code to the receiver when the current user is not allowed
to perform entitlement check. This error code also listened by
the tethering module, where it would stop tethering when receiving
such error code.

Test: atest TetheringTests:EntitlementManagerTest
Bug: 376792293
Change-Id: I2dd18f9df9ad7cab542f8877b9fc86600c248144

Junyu Lai   commited 2024-11-27 10:56:05 +08:00
0adbb0277b
Send TetheringRequest to restart Tethering from IpServer
IpServer currently starts/stops tethering by specifying the tethering
type, but this will be a problem when we start to allow multiple
requests per type. To fix this, specify the TetheringRequest instead.

Note this CL has no functional changes.

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

Quang Anh Luong   commited 2024-11-19 19:32:22 +09:00
685b8aa508
Include SoftAP config in TetheringEventCallback
Include SoftApConfiguration in TetheringEventCallback via
TetheringInterface, to allow apps to know which interfaces are created
with their SoftApConfigurations.

API-Coverage-Bug: 371133403

Bug: 216524590
Test: atest TetheringTest CtsTetheringTest
Change-Id: I1b4868ba8327bee3b03c0f21e5b4f0845f2f24a8

Quang Anh Luong   commited 2024-11-18 13:37:39 +09:00
a66b78ab87
Refactor tether state change callback/broadcast for redactions
Refactor tether state change callback/broadcast to allow for redactions
based on the callback cookie of the recipient. This CL is a no-op and
will be used in a future CL to redact the SoftApConfiguration in
TetheringInterface.

Bug: 216524590
Test: atest TetheringTest CtsTetheringTests
Change-Id: I3684929e6ba832f4da353d48137967739ca558d6

Quang Anh Luong   authored and   Quang Luong   commited 2024-11-08 05:08:43 +00:00
8a3f2e0460
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
Merge "Split requestDownstreamAddress into two methods" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-10-18 05:06:39 +00:00
f1a422de95
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
Standardize handler thread checks
Use HandlerUtils#ensureRunningOnHandlerThread to perform handler
thread checks instead of individual methods within the class.

Test: TH
Change-Id: I6d893dc9eedc588660797768a03e7ad7ab636479

Paul Hu   commited 2024-10-17 06:14:05 +00:00
c0e709700c
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
Refator IpServer to allocate IPv4 address via RoutingCoordinatorManager
API

This CL refactors IpServer to allocate IPv4 address via RoutingCoordinatorManager
instead of directly talking to PrivateAddressCoordinator class.

Bug: 350699020

Change-Id: I5c68620626a3668c079234da232f0ef2beb46628

Handa Wang   commited 2024-10-16 23:54:29 +00:00
55e005251d
Introduce PrivateAddressCoordinator methods at RoutingCoordinatorManager
This CL exposes PrivateAddressCoordinator methods at
RoutingCoordinatorManager and implements the methods in
RoutingCoordinatorService.

The objective is to allow a system service like Thread to request an
IPv4 address allocation.

Bug: 350699020

Change-Id: I65dc309f0b503d544e0fddc1168131fa6174796c

Handa Wang   commited 2024-10-16 23:54:25 +00:00
e5e06f9f7c
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
Remove unused method TetheringConfiguration#isRandomPrefixBaseEnabled()
This CL removes TetheringConfiguration#isRandomPrefixBaseEnabled(). This
method was used for configuring PrivateAddressCoordinator. Now
PrivateAddressCoordinator doesn't depend on TetheringConfiguration so
we'll remove this unused method.

Bug: 369282577
Change-Id: I2e556cf5dd6c28cd6aba29ee9093a9873a4f4d3f

Handa Wang   commited 2024-10-08 14:41:28 +00:00
87d33bac74
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
Merge "Remove unnecessary byte array allocation:" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-08 10:38:08 +00:00
df90099594
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
Handle CMD_IPV6_TETHER_UPDATE in UnavailableState
Technically, UnavailableState should not handle any messages at all (and
shouldn't exist). As the IpServer has already been removed from
mTetherStates. However, sendInterfaceState() cleans up IPv6 tethering
which eventually triggers a CMD_IPV6_TETHER_UPDATE. Instead of
preventing the CMD_IPV6_TETHER_UPDATE, ignore it for now and remove this
state entirely once we have rolled out SyncStateMachine.

Bug: 368713124
Test: TH
Change-Id: I32ae9583aa01411fa1fc299a0fc91138557b7ae2

Patrick Rohr   commited 2024-10-04 15:38:27 -07:00
ba7d9dddc7
Remove unnecessary byte array allocation:
The `upstreamEvents` byte array may not be used if debugging is
disabled.  Remove the array allocation and retrieve the array
directly when required.

Test: atest TetheringTests
Change-Id: I7e1ddd3ce2e3079f07deebe3dd49aef832b24558

Paul Hu   commited 2024-10-04 07:49:21 +00:00
4110b7dc70
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 "Add missing break in BaseServingState" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-03 12:22:33 +00:00
511faf74e9
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
Add missing break in BaseServingState
The break is missing when processing CMD_SERVICE_FAILED_TO_START
in BaseServingState.

Test: atest TetheringTests
Change-Id: I1699da251f90ec447466266b704df24d081c40b3

Paul Hu   commited 2024-10-03 06:45:28 +00:00
0a4758b592
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