Commit graph android_packages_modules_Co.../Tethering/src
Message SHA1
Inline tetherInterface and untetherInterface
This is a no-op refactoring which inline the functionalities
to IpServer, enabling subsequent changes to move
networkAddInterface part to ConnectivityService when the
tethering is enabled.

Test: atest TetheringTests:android.net.ip.IpServerTest
      atest NetdStaticLibTests:com.android.net.module.util.NetdUtilsTest
Bug: 349487600

Change-Id: I6d0e5d349691df7a15bee852d5fd1dd19f5da6f6

Junyu Lai   commited 2025-03-07 10:43:17 +08:00
eff5782b0a
Separate route modification and update linkproperties
This is a no-op, preparatory refactoring to isolate route
modification functionality, enabling subsequent changes to move
routing control to ConnectivityService.

Test: atest TetheringTests:android.net.ip.IpServerTest
      atest NetdStaticLibTests:com.android.net.module.util.NetdUtilsTest
Bug: 349487600
Change-Id: I55af07968567b173dd9f97795600390439f1b927

Junyu Lai   commited 2025-03-07 10:43:17 +08:00
d85d3c5e80
no-op: Use helper class to handle pending requests
Pending requests should be updated via a helper class RequestTracker
and stored in a Request wrapper object. This will help out with future
changes to associate each TetheringRequest with it's own
IIntResultListener and make it easier to gate behavior changes.

Bug: 216524590
Test: atest TetheringTest RequestTrackerTest
Change-Id: Ib867e91863bdf618bb0e955eeb529cd132209d77

Quang Anh Luong   commited 2025-03-06 15:18:28 +09:00
1a27e1f9f7
Merge changes I224c1055,I0aa7b5cc,I3e0638a3 into main
* changes:
  no-op: use stopTetheringInternal when restarting tethering on start
  Use pending request when legacy tethering
  no-op: Add test to verify legacyTether does not use explicit request

Quang Luong   authored and   Gerrit Code Review   commited 2025-03-04 02:25:35 -08:00
f2e2a48682
no-op: use stopTetheringInternal when restarting tethering on start
startTethering will sometimes restart tethering if there is an existing
request of the same type but with different contents. This call is
equivalent to stopTetheringInternal, so use that instead for simplicity.

Bug: 216524590
Test: covered by existing tests
Change-Id: I224c10557c2348e2d2f971e1e3ecb11ae346d2cf

Quang Anh Luong   commited 2025-03-04 16:58:43 +09:00
a09574a1db
Use pending request when legacy tethering
Legacy tethering was changed to use it's own tethering requests
with REQUEST_TYPE_LEGACY in aosp/3465235 instead of using the pending
request as it was thought that pending requests (from startTethering)
and legacy tethering would always be mutually exclusive.

However, pre-T Bluetooth tethering actually relies on
startTethering(request) to add the pending request, and then BT service
directly calls legacyTether(iface) to start tethering. Thus we should
continue to use pending requests even for legacyTether.

Bug: 216524590
Test: atest TetheringTest
Change-Id: I0aa7b5cc6d6d54f516a07b0e89259c61e1d05f69

Quang Anh Luong   commited 2025-03-04 16:58:42 +09:00
e87bf658c4
Merge "Enable TETHER_ENABLE_SYNC_SM by default" into main
Paul Hu   authored and   Gerrit Code Review   commited 2025-03-03 17:59:36 -08:00
53dd6ead10
Merge "Enable TETHER_FORCE_RANDOM_PREFIX_BASE_SELECTION by default on 25Q2+" into main
Patrick Rohr   authored and   Gerrit Code Review   commited 2025-03-03 08:45:58 -08:00
dd9451b465
Enable TETHER_ENABLE_SYNC_SM by default
The tether_enable_sync_sm flag has been successfully rolled out
to public stage on Pixel devices without any observed
regressions. As a result, this flag should be enabled by default
with a kill switch, allowing the feature to be deployed to all
production devices.

Test: atest TetheringTests CtsTetheringTest
Change-Id: I2f0f55c1586e1f4987b28488082c4c1f4cae0f5e

Paul Hu   commited 2025-03-03 16:29:32 +00:00
d13f09d7a3
Enable TETHER_FORCE_RANDOM_PREFIX_BASE_SELECTION by default on 25Q2+
Since the feature was fully rolled out via experiment without
regression, this commit removes the flag and the corresponding
logic in PrivateAddressCoordinator. The flag is no longer
necessary and simplifies the code.

Test: atest ConnectivityCoverageTests:PrivateAddressCoordinatorTest
Fix: 312647670
Change-Id: I8781f98b7e99ed0856e9e04112056df5adca2527

Junyu Lai   commited 2025-03-03 16:55:03 +08:00
44f2eb6e42
no-op: Pipe TetheringRequest through enableTetheringInternal
Add a TetheringRequest argument to enableTetheringInternal and
sendTetherResult so we can pass the request to Wifi in a later CL.
Also pass through for TETHERING_VIRTUAL to use the request and
interface directly.

Note that removing getOrCreatePendingTetheringRequest in
setVirtualTethering is also a no-op:
- If setVirtualTethering is called from startTethering, the request
  that is now passed in as a parameter is the exact same one that
  was just inserted into the pending list, and which the old code
  would have obtained from getOrCreatePendingTetheringRequest.
- If setVirtualTethering is called due to an IP conflict, both the
  old and the new code use a placeholder request with no interface.
  This codepath was already broken before this CL (and likely has
  never worked).

Bug: 216524590
Test: covered by existing tests
Change-Id: I3cb9b5ed44e83bb6bbf4ed77c37cbf35e306f08b

Quang Anh Luong   commited 2025-02-13 19:09:01 +09:00
394c889699
no-op: Refactor bluetooth tethering listener
enableTetheringInternal immediately sends the tether result for all
types except for TETHERING_BLUETOOTH, which relies on
setBluetoothTethering to sends the result immediately if the Pan
service is connected, or defer the result until after the Pan service
connects.

To keep better track of the active listeners and simplify the logic for
further listener behavior changes (i.e. notifying the listener after the
link layer event), refactor the bluetooth listener to be called
immediately within enableTetheringInternal if the Pan service is
connected like the other tethering types.

Bug: 216524590
Test: covered by existing tests
Change-Id: I91196e430b44ef2391de662ff0ed6e051b453d98

Quang Anh Luong   commited 2025-02-13 18:50:27 +09:00
48fbdf4a36
Fix LOHS stealing pending tethered SoftAP requests
Currently, WIFI_AP_STATE_CHANGED for LOHS will use any pending Wifi
TetheringRequest to start the IpServer. This is a bug, since pending
Wifi requests are always for tethered SoftAP, not LOHS. This means if
there's already a pending request for tethered SoftAP, we will
mistakenly use the tethered SoftAP request for LOHS. Then, when the
WIFI_AP_STATE_CHANGED event for the tethered SoftAP arrives, the pending
request for it will already be gone.

Fix this by always having LOHS use an implicit LOHS TetheringRequest
instead of taking the request from the pending list.

Bug: 216524590
Test: atest
Change-Id: Ic349e0b0688addf6a41b3de0528d444d716846a2

Quang Anh Luong   commited 2025-02-13 10:25:20 +09:00
860828027a
Pre-emptively fail pending pan requests upon opposite request
If there are pending pan requests for an enable but a disable request
comes (or vice versa), remove all the pending requests and pre-emptively
fail their result listeners. This simplifies the logic and helps us
keep track of which request the future link layer event should be long
to.

Technically this is an app-visible behaviour change. In particular, if
something disables bluetooth tethering while the service is
disconnected and request(s) to enable tethering are queued, then the new
code will immediately send onTetheringFailed to all those requests,
whereas the old code would wait until the service connects, enable
tethering (and send the enabler an onTetheringStarted), and then disable
it. Given that this situation is very rare, and Bluetooth tethering is
itself so uncommon (<1% of total tethering sessions) this is an
acceptable trade-off.

Bug: 216524590
Test: atest TetheringTest
Change-Id: I061733d714894b741e7d686810dd39f054e85476

Quang Anh Luong   commited 2025-02-13 10:24:42 +09:00
9cebb8c3b1
Merge "try-catch when calling createContextAsUser" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-02-09 17:52:28 -08:00
592b489e14
Merge "Fix some comments around stopTetheringRequest" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-31 01:59:17 -08:00
f09acc7281
Merge "Add basic implementation of stopTetheringRequest" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-31 00:59:58 -08:00
6f57c93e30
Fix some comments around stopTetheringRequest
Bug: 216524590
Test: atest TetheringManagerTest
Change-Id: Iae0baa8ad7c199770666e2f78813cf0224ea1a9b

Quang Anh Luong   commited 2025-01-31 17:42:39 +09:00
75ac79db56
Add basic implementation of stopTetheringRequest
Add a basic implementation of stopTetheringRequest that simply stops
tethering for that specific type if it is active, or fail with
TETHER_ERROR_UNKNOWN_REQUEST if not. In the future, we will do fuzzy
matching to ensure the correct request is removed.

Bug: 216524590
Test: atest TetheringManagerTest#testStopTetheringRequest
Change-Id: Ib4a660aacdb83e645e39ceb61b7cda45bb24d89d

Quang Anh Luong   commited 2025-01-31 16:23:04 +09:00
696c164c2d
Remove redundant requestedState from IpServer#enable
IpServer#enable is called with both a non-null TetheringRequest and the
requestedState, but the requestedState is derived from the
TetheringRequest's connectivity scope. Remove this requestedState arg
and simply have IpServer read the connectivity scope itself.

Bug: 216524590
Test: covered by existing tests
Change-Id: I73227f5053da3a2ab35563268fc416b6dd9b1801

Quang Anh Luong   commited 2025-01-30 14:30:51 +09:00
ffb503e86e
Log tethering started with placeholder request
Bug: 216524590
Test: build
Change-Id: I152505f83745f4d1f8148c72f15dcde990b8d7b9

Quang Anh Luong   commited 2025-01-30 14:30:51 +09:00
e1fd3c2daa
no-op: Make TetheringRequest @NonNull in enableIpServing
Currently the enableIpServing->tetherInternal call stack may have a
tethering request alongside a redundant tethering type and requested
state. The redundant arguments were necessary since there may be cases
where the active request is null (e.g. back-to-back start/stop, which
removes the active request before the link layer event enables ip
serving).

This change gets rid of the redundant arguments and makes the call stack
take a non-null TetheringRequest. In case the active request is not
found, we will create a placeholder request with just the type and
connectivity scope (i.e. requested state). This should be equivalent to
the old code of sending a null request (since none of the other fields
in TetheringRequest are used), making this a no-op change.

Bug: 216524590
Test: covered by existing tests
Change-Id: I5ac83c74f5bc4aec2fe85daa9477740749d95c63

Quang Anh Luong   commited 2025-01-30 14:30:49 +09:00
2b8a42d666
Make it clear that legacyTether always uses IpServer.STATE_TETHERED.
This is a no-op refactor

Bug: 216524590
Test: covered by existing tests
Change-Id: I2a3eb4a64cc9527793136b7ae6fb83d32923debd

Lorenzo Colitti   commited 2025-01-29 17:38:18 +09:00
dca881697c
Rename mActiveTetheringRequests to mPendingTetheringRequests
mActiveTetheringRequests is a misnomer because the requests aren't
actually active yet. Rename this to mPendingTetheringRequests since
they're pending a link layer event that the iface is ready to start IP
serving.

Bug: 216524590
Test: covered by existing tests
Change-Id: Ib0c4a52e0aa72fc27b67bce25187124b20082c05

Quang Anh Luong   authored and   Lorenzo Colitti   commited 2025-01-29 17:15:53 +09:00
caae4e7916
Give the two variants of ensureIpServerStarted different names.
The fact that the two overloads have the same name is confusing
because one of them fetches the type and one of them has it
passed in. This means it's not obvious whether they behave
identically or not.

This is a no-op refactor.

Bug: 216524590
Test: covered by existing tests
Change-Id: Iff7d2981cb5835831f00117166035d48b44a61a4

Lorenzo Colitti   commited 2025-01-29 17:11:37 +09:00
ac046ba684
Move the TetheringRequest further up the stack.
Currently, the active TetheringRequest (if any) is fetched at the
very bottom of the stack, just before enabling the IpServer.
Have the callers pass it in instead.

This CL is a no-op refactor. In particular, it ignores the fact
that the TetheringRequest can be null, and that the connectivity
scope in the request might not match the requested state, etc. -
it just documents the current behaviour (bugs included) and
leaves it unchanged. It exists only to make future changes
easier.

Bug: 216524590
Test: covered by existing tests
Change-Id: Ie8af8b718a9de1f1d5adde0ac589060dce112a27

Lorenzo Colitti   commited 2025-01-29 17:11:37 +09:00
7e43a1adfa
Un-nest legacyTether by moving lambda contents to new method.
This is a no-op refactor.

Bug: 216524590
Test: covered by existing tests
Change-Id: I7884faf8e0f187bb840ec80b8d6d86e3e4323553

Lorenzo Colitti   commited 2025-01-29 17:11:32 +09:00
6887c8d925
try-catch when calling createContextAsUser
There is no safe way to invoke this method correctly since the
package might not be installed for certain user type by OEM.

Thus, improve error handling and logging into WTF counter metrics.

Test: Manual:
  1. Use internal main branch
  2. Modify xml under vendor/google/data/etc/sysconfig to
     configure tethering only installs on the SYSTEM user
  3. Mock the device as entitlement required (ag/29664886)
  4. Create a secondary user which has the permission to
     enable tethering (go/hsum)
  5. adb shell pm list packages --user 10 | grep tether
  6. m statsd_testdrive && statsd_testdrive -e 979
  7. Enable tethering
Test: atest TetheringTests:EntitlementManagerTest
Bug: 382628161
Change-Id: I233cad672e41d2b4687e53e61b93dcea9eb07817

Junyu Lai   commited 2025-01-22 11:22:59 +08:00
a80fd3deba
Add methods to distinguish TetheringRequest types
Add TetheringRequest#RequestType to distinguish the type of
TetheringRequest (i.e. from startTethering, from implicit broadcasts, or
from the legacy tether API) as well as helper methods to create these
requests. These will be used in a future CL.

Bug: 216524590
Test: build

Change-Id: Ibfda48f59e80d423c9b6ee0d244cbdab14be1bd2

Quang Anh Luong   commited 2025-01-21 17:48:38 +09:00
01b9e966d8
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