Commit graph android_packages_modules_Co.../Tethering/src
Message SHA1
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
Merge "Add more consistent null checks" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-07-09 21:37:51 +00:00
2a3d34413c
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
Add more consistent null checks
This change moves the null check into the service implementation. Since
exceptions on oneway binder interfaces are ignored (across process), the
code was changed to just return early instead.

This also adds a couple of Objects.requireNonNull() assertions in
TetheringManager to assert the existing @NonNull annotation.

Test: TH
Bug: 337167681
Change-Id: I5301ed084bb26c2f910041e9b25314f8181718d1

Patrick Rohr   commited 2024-07-02 11:53:17 -07:00
0692aff5c5
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
Merge changes I76b0a7ba,If7308f1a,Ica8faced,Ia8f42ed0,I975afb45, ... into main
* changes:
  Add some documentation to EthernetInterfaceStateMachine
  Add support for link state tracking
  Add unit test class for EthernetInterfaceStateMachine
  Add missing call to add states to state machine
  Make class testable
  Log.wtf if block times out
  Wait on IpClient#onQuit in StartedState#exit
  Use TAG instead
  Introduce CMD_ON_NETWORK_NEEDED and CMD_ON_NETWORK_UNNEEDED messages
  Clean up and document state lifecycle
  Add convenience method for processMessage with no arguments
  Implement NetworkOffer in EthernetInterfaceStateMachine
  Add boilerplate to represent interface states in state machine
  Fix typo in SyncStateMachineTest
  Move SyncStateMachine to staticlibs

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-06-21 19:01:38 +00:00
58526e4d96
Move SyncStateMachine to staticlibs
Test: mm
Change-Id: I51685a454a3d0fab578fef1eeb42d600adef06e6

Patrick Rohr   commited 2024-06-21 08:25:25 -07:00
aa06b2bf8e
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
Introduce TETHERING_VIRTUAL type
Bug: 340376953
Test: Presubmit
Change-Id: I0714b62ebfc63fc966d7873ebdd68ae72c015bc4

Seungjae Yoo   commited 2024-06-19 16:18:51 +09:00
07b8fe1f92
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
Get rid of BpfCoordinator#mPollingStarted
Refactor IpServer/BpfCoordinator to remove mPollingStarted, and just
maintain the invariant that "data usage polling and conntrack
monitoring are running iff at least one IpServer is serving".

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

KH Shi   commited 2024-06-17 03:02:49 +00:00
b1fb49a996
Clatd: add dump raw BPF map support
Add dump raw BPF map command to connectivity service. The result will
be encoded as base64 strings. This is a preparation for Clatd's tests.

Usage:
    dumpsys connectivity {clatEgress4RawBpfMap|clatIngress6RawBpfMap}

Bug: 285124667
Test: test with MtsEthernetTetheringTest#testTetherClatBpfOffloadUdp
      which will be uploaded in a separated CL
Change-Id: I02c8efadb1c4b861d9bf6168667816b13412dc75

KH Shi   commited 2024-05-31 06:34:41 +00:00
855712aa55
Move dumpRawMap to BpfDump
This is a no-op refactor to move utility methods from BpfCoordinator
to a common place.

Bug: 285124667
Test: atest MtsTetheringTestLatestSdk
Change-Id: I68f310892a28a9bf4669a2c4a08a3416f54a84af

KH Shi   commited 2024-05-14 06:04:08 +00:00
f325ea2064
Merge "Tethering: Throw exception when register null callback to avoid a crash" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2024-04-02 05:45:07 +00:00
c634eb5726
Merge "Allow enable DBG/VDBG without having to rebuild the module." into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-02 05:44:35 +00:00
5250ebe96e
Allow enable DBG/VDBG without having to rebuild the module.
Check out #isLoggable from frameworks/base/core/java/android/util/Log.java to
learn how to enable the log.

Bug: 329552689
Change-Id: I86ce0dae947cf56da069dfe3145ef074de11217e
Test: TH

Mark Chien   commited 2024-04-02 03:59:35 +00:00
9f69605fa0
Merge "Remove mWifiTetherRequested" into main
Mark Chien   authored and   Gerrit Code Review   commited 2024-04-02 03:20:31 +00:00
4775bb519a
Obtain BluetoothAdapter through BluetoothManager
BluetoothAdapter.getDefaultAdapter is deprecated and should be replaced
with BluetoothManager.

The AttributionSource is not necessarily set properly with
BluetoothAdapter.getDefaultAdapter, and may depend on which package is
returned first by PackageManager.getPackagesForUid. This has been
causing some flaky failures in presubmit.

Fixes: 332225348
Test: atest
Change-Id: I2f066f1a90a3c6fed7885f4bbee870abf96f664d

Remi NGUYEN VAN   commited 2024-04-01 16:35:24 +09:00
9b7fea5eee
Remove mWifiTetherRequested
Removing "mWifiTetherRequested" because it might cause Wi-Fi tethering
to not have an upstream if P2P is turned on. The issue could be
recovered when the upstream's capabilities or link properties change,
tethering calls "chooseUpstreamType" to select an upstream. If none of
the above situations happen, Wi-Fi tethering won't have an upstream.

1. When Wifi P2P is enabled and tethering enters TetherModeAliveState.
2. Turning on wifi tethering, TetherModeAliveState would first receive
   EVENT_IFACE_SERVING_STATE_INACTIVE when wifi tethering's IpServer
   is created and enters IpServer's InitialState. Then it will call
   updateUpstreamWanted and change mUpstreamWanted from false to true
   before wifi tethering's IpServer actually enters TetheredState.
3. When TetherModeAliveState receives EVENT_IFACE_SERVING_STATE_ACTIVE,
   which is triggered by wifi tethering's IpServer entering
   TetheredState, it won't call chooseUpstreamType() because
   mUpstreamWanted is already true.
   case EVENT_IFACE_SERVING_STATE_ACTIVE: {
       IpServer who = (IpServer) message.obj;
       if (VDBG) Log.d(TAG, "Tether Mode requested by " + who);
       handleInterfaceServingStateActive(message.arg1, who);
       who.sendMessage(IpServer.CMD_TETHER_CONNECTION_CHANGED,
               mCurrentUpstreamIfaceSet);
       // If there has been a change and an upstream is now
       // desired, kick off the selection process.
       final boolean previousUpstreamWanted = updateUpstreamWanted();
       if (!previousUpstreamWanted && mUpstreamWanted) {
           chooseUpstreamType(true);
       }

mWifiTetherRequested is only used to check upstreamWanted() and only be
used in TetherModeAliveState so that it is
safe to remove mWifiTetherRequested and always use mForwardedDownstreams
to check whether upstream is needed for TetherModeAliveState because all
the Tethered IpServer is added to mForwardedDownstreams when it enter
Tethered State and be removed from mForwardedDownstreams when it exit
Tethered State.

This change also move the upstreamWanted() function inside TetherMainSM
to prevent it from being used incorrectly outside of TetherMainSM.

Bug: 329552689
Test: atest TetheringTests

Change-Id: I6842170f455b280dd79aae039a1117d5e6d677f3

Mark Chien   commited 2024-03-26 08:08:01 +00:00
27d9121ef3
Tethering: Throw exception when register null callback to avoid a crash
Register null callback will cause a crash so throw an exception

Test: m, CtsTetheringTest
Change-Id: Id4337328f6793f1436c9d3561960fa69d17d030e

Ding Zhang   commited 2024-03-01 11:42:22 -08:00
52776a3c8c
Merge "Pass buffer size to NetlinkUtils.netlinkSocketForProto" into main
Maciej Å»enczykowski   authored and   Gerrit Code Review   commited 2024-01-31 01:42:49 +00:00
2cb28ea360
Pass buffer size to NetlinkUtils.netlinkSocketForProto
Pass buffer size to netlinkSocketForProto to allow callers to specify
buffer size. The buffer size is not set if 0 is passed in.

Following callers of netlinkSocketForProto passes SOCKET_RECV_BUFFERSIZE
to keep same behavior as before:
 * OffloadHardwareInterface.createConntrackSocket()
 * NetlinkUtils.sendOneShotKernelMessage()
 * IpSecXfrmController.Dependencies.newNetlinkSocket()
 * InetDiagMessage.getConnectionOwnerUid()
Following callers pass 0 to not update the buffer size:
 * TunInterfaceController - it uses the socket only for writing
 * NetlinkUtils.createNetLinkInetDiagSocket() same behavior as before
Added a SOCKET_DUMP_RECV_BUFFERSIZE of 128k to be used by socket
requesting dump information from kernel:
 * NetlinkUtils.getAndProcessNetlinkDumpMessages() - sends dump request
   and expecting multiple reply messages.

Bug: 320420453

Test: atest NetworkStaticLibTests
atest FrameworksNetTests

Change-Id: I3dcb76963cf2646eb311602b50ab4e44b8ad3e8f

Yang Sun   commited 2024-01-30 21:54:48 +08:00
7934241c8f
Merge "Add experiment flag for enabling sync sm" into main
Mark Chien   authored and   Gerrit Code Review   commited 2024-01-30 02:18:24 +00:00
c1647a0efc
Merge "Revert "Add experiment flag for tethering refactor"" into main
Mark Chien   authored and   Gerrit Code Review   commited 2024-01-24 07:41:19 +00:00
e48d106863
BpfMap - add R/W constructor alias
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7cef2b19f55e6e056b46bb1b28f85c7f7376f6f4

Maciej Å»enczykowski   commited 2024-01-23 16:16:44 -08:00
06155c8040
Add experiment flag for enabling sync sm
The logic is currently disabled by default, adding a flag so
that we can compare result with A/B rollout. Tethering only read
this flag once when it is created.

Bug: 319212113
Test: atest TetheringTests

Change-Id: I656b0389e56d29dd691738ee3abfa6418746846f

Mark   commited 2024-01-23 09:55:33 +00:00
c512ab7e23
Revert "Add experiment flag for tethering refactor"
This reverts commit cf11be9eb2.

Reason for revert: avoid some IpServer(s) running the new sync state machine while others use the async state machine.

Bug: 319212113
Change-Id: Ib086a7ccd102f38e579c79f94aceae9971f1853a

Mark Chien   authored and   Mark   commited 2024-01-22 11:34:14 +00:00
6e368d1bdd
Merge "Replace HashSet with ArraySet in RaParams" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2024-01-20 19:06:38 +00:00
86b8bf03d2
Migrate Tethering#dump to use runWithScissorsForDump
This change includes:
  1. Refactor the logic in Tethering#dump into utils class.
  2. Move the utils class to a common place which could be referenced
     from other sub-modules.
  3. Add @MonitorThreadLeak annotation to enforce
     there is no thread leak problem.

Test: atest FrameworksNetTests NetworkStaticLibTests
Test: atest ConnectivityCoverageTests:com.android.networkstack.tethering.TetheringTest#testDumpTetheringLog
Test: adb shell dumpsys tethering (with hardcoded exception)
Fix: 312669345

Change-Id: Ia6fdfeeec2110afa0ec9e056e9db3843748845c3

Junyu Lai   commited 2024-01-10 13:56:55 +08:00
2ff42d264b
Merge changes I4888f8f2,Iba829ec0 into main
* changes:
  Revert "Refactor RouterAdvertisementDaemon with FdEventsReader"
  Revert "Refactor RouterAdvertisementDaemon to build new RA in HandlerThread"

Yuyang Huang   authored and   Gerrit Code Review   commited 2023-12-20 08:14:12 +00:00
71c24f190d
Revert "Refactor RouterAdvertisementDaemon with FdEventsReader"
This reverts commit bdcd7db9d8.

Reason for revert: Design changes, don't use extra Handler in RouterAdvertisementDaemon.

Change-Id: I4888f8f22aea2cadbb6064e63f872c605025930f

KH Shi   commited 2023-12-20 06:46:42 +00:00
ec801b887f
Revert "Refactor RouterAdvertisementDaemon to build new RA in HandlerThread"
This reverts commit 23a2158c38.

Reason for revert: Design changes, don't use extra Handler in RouterAdvertisementDaemon.

Change-Id: Iba829ec028e887b6625f4f972e936ca5757a7614

KH Shi   authored and   Gerrit Code Review   commited 2023-12-20 06:25:54 +00:00
f8ab26379e
Add experiment flag for tethering refactor
The logic is currently disabled by default, adding a flag so
that we can compare result with A/B rollout.

Test: atest TetheringTests
Change-Id: If640b9a172b97aa67c49b2976cdef118218f1e0f

Mark   commited 2023-12-12 02:31:54 +00:00
cf11be9eb2
Merge "Rename getXXX to makeXXX in TetheringDependencies" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-12-05 06:42:25 +00:00
ef41398c1f
Merge "Random select started prefix range" into main
Mark Chien   authored and   Gerrit Code Review   commited 2023-12-05 05:25:18 +00:00
78c0d088d7
Rename getXXX to makeXXX in TetheringDependencies
This fix the code review comment from aosp/2319853 that getXXX functions
should be renamed to makeXXX because it's actually creating the object.

Test: TH
Change-Id: Ife8e1cc3a90b835764a2dd9731388b05d8a5c964

Mark   authored and   Mark Chien   commited 2023-12-04 09:02:55 +00:00
b720d6d726
Random select started prefix range
Currently, PrivateAddressCoordinator always selects the /24 prefix
from the 192.168.x.x/16 range first. If the upstream is also a /24
prefix in the 192.168.x.x/16 range, there's a 1/256 chance of a
conflict (192.168.0.x/24 ~ 192.168.255.x/24). Since 192.168.x.x/16
is a popular range for home and small business networks, we should
randomize the starting prefix range to reduce the chance of a
conflict. The /8, /12, and /16 range selection rates are 0.39%,
5.86%, and 93.7%, respectively (see the inline comments for how
the rates are calculated).

The chance of selecting a /24 prefix is:
- 10.0.0.0/8: 1/(256*256) * 93.7% = 0.001429%
- 172.16.0.0/12: 1/(16*256) * 5.86% = 0.00143%
- 192.168.0.0/16: 1/256 * 0.39% = 0.001523%

Note: This change is currently turned off by the
tether_force_random_prefix_base_selection flag. We'll run experiments
to make sure tethering stays reliable with this change enabled.

Bug: 312647670
Test: atest TetheringTests
Change-Id: Iea03fdcf0fccad95410e79ae87fcb046d75da457

Mark   commited 2023-11-28 06:56:06 +00:00
c0b0f616d0
Avoid random twice to generate an address
The code currently calls RandomInt twice to generate an address.
For example, if you want to generate the address 192.168.A.B,
RandomInt will be called twice to generate the values for A and B.
To save resources, we can avoid calling RandomInt twice by reusing
the same random value with different masks for A and B.
Before:
  -  RandomInt() & 0xff00 -> A
  -  RandomInt() & 0x00ff -> B
After:
  -  RandomInt() & 0xffff -> A.B

Bug: 312647670
Test: atest TetheringTests
Change-Id: Iee49af3d82781309f78fe66ab07937b8137fa259

Mark   authored and   Mark Chien   commited 2023-11-24 03:10:11 +00:00
f25af65b28
Refactor RouterAdvertisementDaemon to build new RA in HandlerThread
HandlerThread was introduced in aosp/2493357. This patch moves the
code originally located in buildNewRa() into the HandlerThread.

Bug: 246928127
Test: atest TetheringPrivilegedTests TetheringIntegrationTests \
      TetheringTests
Change-Id: I5f6df0a3a79d7f4a865cfec7f88bc28816b1db95

KH Shi   commited 2023-11-22 07:25:16 +00:00
23a2158c38
Refactor RouterAdvertisementDaemon with FdEventsReader
This patch changes the implementation of UnicastResponder in the
RouterAdvertisementDaemon with FdEventsReader. The change includes
replacing Thread with HandlerThread, create socket in non-blocking
mode (required by FdEventsReader) and use FdEventsReader to listen
to the solicited RS packets. Two commands (CMD_START & CMD_STOP)
were added to control the lifecycle of the FdEventsReader.

Bug: 246928127
Test: atest TetheringPrivilegedTests TetheringIntegrationTests \
      TetheringTests
Test: Enable WiFi hotspot and connected with another Pixel client:
      1. Tcpdump on the Pixel client, checking the RA packets
      2. Verify IPv6 addresses were configured
      3. ping6 2001:4860:4860::64
Change-Id: I6e89903df90864e3bb34d498e353d6f87193e9d6

KH Shi   commited 2023-11-22 06:37:17 +00:00
bdcd7db9d8
Merge "SyncSM11.1 make some functions inline" into main
Mark Chien   authored and   Gerrit Code Review   commited 2023-11-22 03:03:22 +00:00
f1c04ca91f
Merge "SyncSM09: Add Callback to UpstreamNetworkMonitor" into main
Mark Chien   authored and   Gerrit Code Review   commited 2023-11-21 17:29:10 +00:00
309365558c