Commit graph android_packages_modules_Co.../Tethering
Message SHA1
Merge "change 'for-system' owner from root to clat" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-03-17 19:47:33 -07:00
1569bc4cbe
Start tethered hotspot with TetheringRequest
Use WifiManager.startTetheredHotspot(TetheringRequest, Executor,
SoftApCallback) to start softap. This allows for passing in the
requested SoftApConfiguration via TetheringRequest.

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

Quang Anh Luong   commited 2025-03-17 21:13:47 +09:00
f7b6434a65
Fix WifiManager.startTetheredHotspot mocking
TetheringTest has several tests that rely on starting Wifi tethering,
but do not mock WifiManager.startTetheredHotspot. This causes the
pending Wifi request to be removed, even though the test continues
thinking that the call succeeded and continues mocking Wifi AP events.

Fix this by making sure the mock returns true in setUp(), and only set
it to false when we expect that the call should fail.

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

Quang Anh Luong   commited 2025-03-17 15:18:29 +09:00
db7fdac6d9
Replace isTetheringWithSoftApConfig flag with B SDK check
isTetheringWithSoftApConfig flag is finalized, replace it with a simple
SdkLevel.isAtLeastB() check. This also fixes any issues with reading the
flag during boot.

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

Quang Anh Luong   commited 2025-03-17 15:18:29 +09:00
a10437f133
[Revert^2] Stop tethering request only if fuzzy-matched to existing request
stopTethering with a TetheringRequest should only stop tethering if
there is an existing request (pending or serving) that fuzzy-matches the
input and whose UID matches the caller (unless the caller is Settings,
which is allowed to remove any request).

If there is no existing fuzzy-matched request, return
TETHER_ERROR_UNKNOWN_REQUEST.

Note: This was originally merged as aosp/3527440 but was reverted due to
a dependency CL being reverted. Remerging this on top of the fix for the
dependency CL.

Reverted changes: /q/submissionid:3541662-revert-3527440-JRJJTQBUFC

Bug: 216524590
Test: atest TetheringTest RequestTrackerTest TetheringManagerTest

Change-Id: I99dd2433efbb82f3721aa708ab50d198f6fbcb10

Quang Luong   authored and   Quang Anh Luong   commited 2025-03-17 15:18:29 +09:00
d093ea69b0
[Revert^2] Reject TetheringRequests that fuzzy-match existing ones
Legacy behavior will return success results to multiple startTethering
calls of the same type, even though the link layer can only support one
of those requests at a time (other than tethered AP + LOHS).

For B+, clean up this behavior by only allowing the amount of requests
that the link layer can concurrently support. To do this, we'll
introduce the concept of "fuzzy-matching" such that if a new request
fuzzy-matches an existing request (either pending or serving), this
indicates that the link layer cannot support the new request
concurrently, and we'll fail the new request with
TETHER_ERROR_DUPLICATE_REQUEST.

To keep track of serving requests, we'll store the request and it's
IpServer in RequestTracker when we call IpServer.enable(), and we'll
remove it (indexed by IpServer) when
1) Calling IpServer.onStop()
2) Calling IpServer.unwanted()
3) We detect an IpServer transition to AvailableState with error code

Note: This was originally merged as aosp/3529632 but was reverted due to
a crash when reading aconfig flags at boot. That issue has been fixed
here.

Reverted changes: /q/submissionid:3541662-revert-3527440-JRJJTQBUFC

Bug: 216524590
Test: atest TetheringTest RequestTrackerTest TetheringManagerTest

Change-Id: I87a1ed31927cda27d3b7fdd7c823b8f828f8d777

Quang Luong   authored and   Quang Anh Luong   commited 2025-03-17 15:18:29 +09:00
8b29d287f5
Merge "no-op: Remove checkAndNotifyCommonError with ResultReceiver" into main
Quang Luong   authored and   Gerrit Code Review   commited 2025-03-14 23:53:01 -07:00
67055ed7a8
Merge "Fix TetheringTest.failureEnablingIpForwarding verification count" into main
Quang Luong   authored and   Gerrit Code Review   commited 2025-03-14 19:51:47 -07:00
856f57a0ce
Fix TetheringTest.failureEnablingIpForwarding verification count
failureEnablingIpForwarding verifies that TetheringMetrics sends one
more error report than it should. This extra verification is caused by
any(class) being passed into the mock WifiManager.startTetheredHotspot,
which does not match null even though the actual code passes in a
null. This results in an extra failure that causes the extra error
report call.

Fix this by replacing any(class) with null, and removing the extra error
verification.

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

Quang Anh Luong   commited 2025-03-15 10:42:22 +09:00
3b6ee54cf6
change 'for-system' owner from root to clat
See https://b.corp.google.com/issues/402962730#comment27
for explanation how clat uid not having access to this
directory causes selinux denials, but basically the dynamic
linker tries to call realpath on /proc/self/exe, which fails
because it's post setuid/gid and thus running as clat/clat,
not as uid=root or gid=system which have access.

(note that the 'w' bits don't really matter since this is
embedded in an apex, and thus readonly filesystem anyway)

Bug: 402962730
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iaf620e33d9211c9bc0c017543bb1be2f43520a51

Maciej Żenczykowski   commited 2025-03-14 09:23:23 -07:00
a89e4d5a36
no-op: Remove checkAndNotifyCommonError with ResultReceiver
There are currently two variants of checkAndNotifyCommonError that do
the exactly the same thing, except one uses IIntResultListener and
another uses ResultReceiver. Remove the lesser-used ResultReceiver
variant and just use the IIntResultListener instead (with a
IIntResultListener wrapper for the ResultReceiver).

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

Quang Anh Luong   commited 2025-03-14 15:27:49 +09:00
d7c6e3022b
Merge changes from topic "revert-3527440-JRJJTQBUFC" into main
* changes:
  Revert "Reject TetheringRequests that fuzzy-match existing ones"
  Revert "Stop tethering request only if fuzzy-matched to existing..."

Priyanka Advani (xWF)   authored and   Gerrit Code Review   commited 2025-03-13 11:43:21 -07:00
99ef00112e
Revert "Reject TetheringRequests that fuzzy-match existing ones"
Revert submission 3527440

Reason for revert: Droidmonitor created revert due to b/403261952. Will be verifying through ABTD before submission.

Reverted changes: /q/submissionid:3527440

Change-Id: Ife596c639899528778f53fef797749fa88596dd6

Priyanka Advani (xWF)   commited 2025-03-13 10:22:16 -07:00
01b6b070ad
Revert "Stop tethering request only if fuzzy-matched to existing..."
Revert submission 3527440

Reason for revert: Droidmonitor created revert due to b/403261952. Will be verifying through ABTD before submission.

Reverted changes: /q/submissionid:3527440

Change-Id: I31ae861d5151c9db7e559ba19db7f07c9545d422

Priyanka Advani (xWF)   authored and   Gerrit Code Review   commited 2025-03-13 10:22:16 -07:00
e72faa10ed
Merge changes Ia8a8eab7,I1e193f35 into main
* changes:
  Stop tethering request only if fuzzy-matched to existing request
  Reject TetheringRequests that fuzzy-match existing ones

Quang Luong   authored and   Gerrit Code Review   commited 2025-03-12 23:20:13 -07:00
a4b6164304
Stop tethering request only if fuzzy-matched to existing request
stopTethering with a TetheringRequest should only stop tethering if
there is an existing request (pending or serving) that fuzzy-matches the
input and whose UID matches the caller (unless the caller is Settings,
which is allowed to remove any request).

If there is no existing fuzzy-matched request, return
TETHER_ERROR_UNKNOWN_REQUEST.

Bug: 216524590
Test: atest TetheringTest RequestTrackerTest TetheringManagerTest
Change-Id: Ia8a8eab78fbecd38321fd0d48734855cff16febb

Quang Anh Luong   commited 2025-03-13 12:49:08 +09:00
a73b21ac11
Reject TetheringRequests that fuzzy-match existing ones
Legacy behavior will return success results to multiple startTethering
calls of the same type, even though the link layer can only support one
of those requests at a time (other than tethered AP + LOHS).

For B+, clean up this behavior by only allowing the amount of requests
that the link layer can concurrently support. To do this, we'll
introduce the concept of "fuzzy-matching" such that if a new request
fuzzy-matches an existing request (either pending or serving), this
indicates that the link layer cannot support the new request
concurrently, and we'll fail the new request with
TETHER_ERROR_DUPLICATE_REQUEST.

To keep track of serving requests, we'll store the request and it's
IpServer in RequestTracker when we call IpServer.enable(), and we'll
remove it (indexed by IpServer) when
1) Calling IpServer.onStop()
2) Calling IpServer.unwanted()
3) We detect an IpServer transition to AvailableState with error code

Bug: 216524590
Test: atest TetheringTest RequestTrackerTest TetheringManagerTest
Change-Id: I1e193f3595a48f806fb70fd08630a12ce2631a59

Quang Anh Luong   commited 2025-03-13 11:11:17 +09:00
2add9260ef
Move CronetInTetheringApexDefaults to //external/cronet
The JNI libs that this target depends on are going to be shimmed on top
of ToT and Stable Cronet. This reduces the number of cross-repo dependencies, making that change simpler (see http://aosp/3507996).

Test: m
Bug: b:396593141
Change-Id: I5e8ab89ea0ebe6a82f006568f30961dcf2f0603e

Stefano Duo   commited 2025-03-12 10:00:42 -07:00
279ba624bc
Merge "Use non-extended mockito for net-tests-utils" into main
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2025-03-11 19:00:20 -07:00
ec2a5cc5c5
Merge "Use SdkLevel.isAtLeastB() instead of SDK_INT" into main
Quang Luong   authored and   Gerrit Code Review   commited 2025-03-11 14:42:37 -07:00
b453055426
Use SdkLevel.isAtLeastB() instead of SDK_INT
Replace the explicit SDK_INT checks with the helper function
SdkLevel.isAtLeastB().

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

Quang Anh Luong   commited 2025-03-11 17:16:56 +09:00
96f8e1b787
Only allow one pending bluetooth request at a time
Currently there may be multiple identical bluetooth requests waiting for
the PAN service to connect before their listeners are notified. To
simplify future code, we should only allow one pending request/listener
pair at a time, and reject every subsequent request with
TETHER_ERROR_SERVICE_UNAVAILABLE.

This should be OK because
1) Bluetooth tethering is hardly used at all
2) Settings disallows extra startTethering calls between the first call
   and the bluetooth service starting
3) Apps are expected to handle TETHER_ERROR_SERVICE_UNAVAILABLE
   correctly.

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

Quang Anh Luong   authored and   Quang Luong   commited 2025-03-10 21:02:50 -07:00
d1f8cea4df
testTetherBpfOffloadUdpV4: disable on S/Sv2 with old DnsResolver
This mirrors the bpf_existence_test check:

https://source.corp.google.com/h/android/platform/superproject/main/+/main:packages/modules/Connectivity/bpf/tests/mts/bpf_existence_test.cpp;drc=0b477491fb95c04d908ef83d683c42db9102cf40;l=203


Bug: 401312619
Test: TreeHugger, atest EthernetTetheringTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I95020580655f8ff6b1e8c26bc3f26b4823716dd5

Maciej Żenczykowski   commited 2025-03-10 15:53:48 -07:00
bf2c498642
Use non-extended mockito for net-tests-utils
Mockito extended tends to cause all kinds of issues due to the way it
injects itself into the bytecode of framework classes instead of
creating subclasses.

Use non-extended mockito as it is not actually necessary for current
tests.

Test: atest
Change-Id: Id2874309cce2778c4405b852df9a3ae816c4abcb

Remi NGUYEN VAN   commited 2025-03-10 17:59:19 +09:00
05c376a4c5
Merge changes I6d0e5d34,I55af0796 into main am: 75551afe7a
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3526891

Change-Id: Id2490f4835aac74b056294dfe1325c99e2bac1b8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>

Junyu Lai   authored and   Automerger Merge Worker   commited 2025-03-06 23:15:56 -08:00
05757ef267
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
Merge 25Q1 (ab/BP1A.250305.020) to aosp-main-future
Bug: 385190204
Merged-In: Ibbba520f24e88f3dcbafd925aa8da319824377ad
Change-Id: Ib840c52538deb29ca92245d320d49405f45d2957

Xin Li   commited 2025-03-06 12:22:42 -08:00
e671fc9e06
Merge "no-op: Use helper class to handle pending requests" into main
Quang Luong   authored and   Gerrit Code Review   commited 2025-03-05 23:57:51 -08:00
bab398f08c
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
bpf: switch to mainline netbpfload on Android S/SV2
Test: TreeHugger, manually installing tethering apex
  (with and without dnsresolver apex) on pixel 6 running S
  incl. 'atest bpf_existence_test'
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I63d4b84287e9c98dc0d2a517ac58d3f3ce9d7760

Maciej Żenczykowski   commited 2025-03-05 14:27:59 -08:00
0b477491fb
Revert "bpf: change NetBpfLoad rc file from 33 (T/U) to 31 (S/Sv2/T/U)"
This reverts commit 0e9b0e05c6.

Reason for revert: needs a .31rc specific version instead.
Will merge the required changes into the followup commit.

Change-Id: I01e9dfee4aaabc3ddab39da7519b7d9963b84124

Maciej Żenczykowski   commited 2025-03-04 21:54:09 -08:00
03bf18c028
bpf: change NetBpfLoad rc file from 33 (T/U) to 31 (S/Sv2/T/U)
By itself this change is a no-op, as we don't actually *yet* start mdnsd_netbpfload.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic7665b3dd5716bd3bbdc96450a42e9b0c26441c9

Maciej Żenczykowski   commited 2025-03-04 14:21:46 -08:00
0e9b0e05c6
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
no-op: Add test to verify legacyTether does not use explicit request
Add a test that verifies that legacyTether will not use the
explicit pending TetheringRequest set by startTethering.

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

Quang Anh Luong   commited 2025-03-04 16:58:40 +09:00
c22dc00557
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 TetheringTest when run on B" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-02-04 19:13:10 -08:00
e0be07db1b
Fix TetheringTest when run on B
Tethering will ignore interfaceStatusChanged for enabled interfaces
starting in B, instead only creating the IpServer when the link layer
event comes. Fix the assertions around interfaceStatusChanged for B.

Bug: 393978354
Test: atest TetheringTest
Change-Id: I74d0843785c5d9353e59b73d6d7b30d6d07ac0e0

Quang Anh Luong   commited 2025-02-05 10:43:59 +09:00
60dbc79761
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