Commit graph android_packages_modules_Co.../Tethering/src
Message SHA1
SyncSM04: implement processMessage function
After this change, all synchronous state machine functions are
implemented.
There are some intentional limiations:
1. Allow setup states before machine thread started or inside machine
   thread but states can only be setup once before calling #start.
2. The behavior of transitionTo is defined so that the destination
   state can never change during state transitions. Once a destination
   has been specified, it cannot be changed until the previous state
   transition is complete. In other words, SyncStateMachine does not
   support calling transitionTo in State enter or exit.
3. Support sendSelfMessage in State#processMessage(), #enter() and
   #exit(). This allow automaton to decide the follow up action by
   itself. For example: if something wrong happens during state
   transition, the implementation can enqueue an error message then
   process the error message after finishing the current state
   transition.

Test: atest SynStateMachineTest
Change-Id: I0790df4eeab2dccdb9f407d9131a62c3c12d123b

Mark   commited 2023-09-19 08:20:56 +00:00
21cdb40e59
SyncSM03: implement state transition logic
Implement performTransitions which does state transitions.
1. Determine the common ancestor state of current/destination states
2. Invoke state exit list from current state to common ancestor state.
3. Invoke state enter list from common ancestor state to destState by
going through mEnterStateStack.

The state transition is always defined so that the target can never be
changed mid-way of a state transition. In other words, calling
transitionTo in State enter and exit is not allowed.

Test: atest SyncStateMachineTest
Change-Id: I51e8c5440a8b9ac25715c3d030717421f68c15b3

Mark   commited 2023-09-15 14:38:12 +00:00
9e572d10f3
SyncSM02: implement addState function
Duplicated state is not allowed.

Test: atest SynStateMachineTest
Change-Id: I0d5c73f666f90aebcfbf535cf0f824c5050941a2

Mark   commited 2023-09-15 14:23:52 +00:00
1d460b568e
SyncSM01: define SyncStateMachine user interface
This change adds SyncStateMachine class and provides the user
interface but doesn't have the details implementation.

Test: m
Change-Id: Ic2fa69b9e6424601fc2df2d07a052f48a6a46370

Mark   commited 2023-09-15 08:07:22 +00:00
b48caa22f3
Remove unnecessary arguments from isTetheringFeatureEnabled
This CL also updates not to use isTetheringFeatureEnabled for
TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION which is wrongly configured in
Connectivity namespace.

Test: m
Bug: 279108992
Change-Id: If4f3a57c749bbaeb85454c31248c5bc5feaab936

Motomu Utsumi   commited 2023-09-08 16:11:28 +09:00
3e0be398a2
Remove duplicated bpf offload support check in IpServer
In current code, IpServer will ensure bpf offload is supported before
calling BpfCoordinator's APIs. But those APIs already have the same
checks inside the function. This CL removed duplicated checks in
IpServer.

After this change, the BPF offload support status is only determined
inside BpfCoordinator and it won't change during the life cycle of
Tethering. Tethering initializes mBpfCoordinator just once in the
constructor. After that point, the value of isUsingBpf can never
change, because mIsBpfEnabled is final and
mBpfCoordinatorShim.isInitialized() is either always true (api30) or
can either never change (api31).

Also fixed a bug in IpServerTest upon this change.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I50f231a83bf678b90eae4fd9bfa6035e86978bb3

KH Shi   commited 2023-09-01 07:37:18 +00:00
e4d549ab11
Relief unnecessary dependencies of code order
The original code requires updating mLastIPv6LinkProperties before
calling updateIpv6ForwardingRules because mLastIPv6LinkProperties will
be used inside an internal function later. Remove this unnecessary
dependency by passing the interface name into the function.

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

KH Shi   commited 2023-08-30 09:33:30 +00:00
6877034343
Introduce Ipv6UpstreamRule to bpf tethering offload
Replaced startUpstreamIpv6Forwarding and stopUpstreamIpv6Forwarding
with add/remove Ipv6UpstreamRule. This is a preparation for following
CLs which will pass the upstream's prefixes to the bpf map. We might
have more than one upstream rules.

Also renamed Ipv6ForwardingRule to Ipv6DownstreamRule since we have
defined the Ipv6UpstreamRule.

No logic changes are being made in this CL.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I022f97c2daf468bbd4a4279a069ccf498013e7e7

KH Shi   commited 2023-08-24 12:02:23 +00:00
59ad35ee19
Rename to isTetheringFeatureEnabled
DeviceConfigUtils has isFeatureEnabled for NetworkStack and Tethering
which were confusing since the difference was only the arguments.
This CL renames isFeatureEnabled for Tethering module to
isTetheringFeatureEnabled to avoid confusion.

Bug: 279108992
Test: m
Change-Id: I05255bb38619afbe621d29524d7910d206a149f1

Motomu Utsumi   commited 2023-08-17 17:47:19 +09:00
624aeb4274
Merge "Import RFC7421_PREFIX_LENGTH from NetworkStackConstants." into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-08-10 13:07:20 +00:00
b8ea09efd7
bpf tethering offload - add src subnet to upstream ipv6 direction
This patch is based on aosp/2535559 from maze@.

Add source prefix into the upstream key such that only packets which
source IPv6 address matches it will be forwarded to the upstream
interface.

In this patch, the source prefix is set to zero so there is no
behavior changes. Next CL in patch series will use the real source
prefixes retrieved from upstream interface.

Test: atest TetheringTests
Bug: 261923493
Change-Id: I43d068a29b937c7dfeb6fab632a8effb47ee2263

KH Shi   commited 2023-08-10 16:01:21 +08:00
c8fb1a2530
Import RFC7421_PREFIX_LENGTH from NetworkStackConstants.
Remove the dependency on services-connectivity-shared-srcs
filegroup gradually.

Bug: 290885904
Test: TH
Change-Id: I6474563a3a0b521945e6467a2832862764ad4770

Xiao Ma   commited 2023-08-09 20:02:15 +09:00
1f993309c6
Fix bug for failing to init Offload AIDL HAL service
When fail to init offload AIDL service, OFFLOAD_HAL_VERSION_NONE is
returned. Not as expected, it go to close the FDs for AIDL service and
causes a NE.

Bug: 277834236
Test: atest com.android.networkstack.tethering
Change-Id: I26a7412cb7d88f0d56b713db18af5cd9583a7942

Zemeng Li   authored and   KH Shi   commited 2023-07-24 21:19:31 +08:00
32ef13d7f3
Tethering: ignore duplicate upstream changed event
Different network objects with the same network ID should be
treated as the same network.

chooseUpstreamType compares the current upstream and new upstream
by object (comparison operator) instead of network id
(Network#equals). This implies that different objects with the
same network id still trigger upstream changed report.

Since this commit, reportUpstreamChanged is only called when upsteam
has really changed (connected, switched or disconnected) in
chooseUpstreamType. In previous code, reportUpstreamChanged is also
called if EVENT_ON_CAPABILITIES is called when the upstream is the
same but its capabilities changed.

The NotificationUpdater#onUpstreamCapabilitiesChanged method only
needs to be called by chooseUpstreamType when it chooses a new
upstream. If the upstream remains the same but its capabilities
change, the EVENT_ON_CAPABILITIES will call
onUpstreamCapabilitiesChanged.

Bug: 243516306
Test: atest TetheringTest
Change-Id: I009383a61a5fabd249ba78fcffd524a5bbe4602e

Hungming Chen   authored and   Mark   commited 2023-06-19 06:51:03 +00:00
fc52868213
Support SAP and LOHS enabled at the same time
Use type + scope as key to build cached address map so that
SAP (key: TETHERING_WIFI + INTERNET) and LOHS
(key: TETHERING_WIFI + LOCAL) can use different address.

Bug: 233175023
Test: atest TetheringTests
Change-Id: I46a4b3ee919628092b7540202a43d79f407b09b6

Mark   commited 2023-05-25 08:31:33 +00:00
49649c9aea
Allow SAP and LOHS wifi clients exist at the same time
This change store localOnly wifi clients in its own field so that
tethered and localOnly hotspot clients can exist at the same time.

Currently, there are no tethered and localOnly hotspot clients at
the same time because PrivateAddressCoordinator does not support
SAP + LOHS. A follow-up change will be made to allow this.

When both SAP and LOHS are enabled, the SAP and LOHS clients from
TetheringEventCallback#onClientsChanged are all TETHERING_WIFI.
Currently, there is no way for the listeners to distinguish between
SAP and LOHS clients.

Bug: 233175023
Test: atest TetheringTests
Change-Id: I01b0a6abb084f7135f7825e0c5303e49c16a4c39

Mark   commited 2023-05-25 08:31:06 +00:00
ae3abdfa4b
Add mDesiredServingState field in BaseServingState
As the suggestion from:
https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/2489359/9/Tethering/src/android/net/ip/IpServer.java#b1176

Make BaseServingState an abstract class to prevent it from being used
directly. Additionally, move the handleNewPrefixRequest method into
BaseServingState because it is the only class that uses it.
To avoid TetheredState and LocalHotspotState from having to implement
their own enter function, add the mDesiredInterfaceState field to
BaseServingState.

Bug: 233175023
Test: atest TetheringTests
Change-Id: I03269c37e666345efb0c61039a2bb213f223a5a2

Mark   authored and   Mark Chien   commited 2023-05-24 17:00:41 +00:00
3ec851ef03
Merge "Fix entitlement recheck fail in U"
Mark Chien   authored and   Gerrit Code Review   commited 2023-05-17 05:54:39 +00:00
65a73dbf78
Fix entitlement recheck fail in U
Starting with U, only explicit intents will be allowed to
launch non-exported internal components. Set package name
to entitlement recheck intent so that the intent could be
delivered to tethering itself successfully.

Bug: 278482046
Test: atest TetheringTests
      manual verify entitlement recheck work in U
Change-Id: Ife30eee13fe39509ccb5786d2a76fbb7baa022a8

Mark   commited 2023-05-16 07:59:32 +00:00
e86fb5ef56
Add a dependency object in TetheringConfiguration
Address a TODO in TetheringConfiguration to use a dependency object
instead of static mocking on DeviceConfig.

This avoids TetheringConfiguration dependencies on internal
implementation of DeviceConfigUtils, unblocking changes in
DeviceConfigUtils.

Bug: 279108992
Test: atest TetheringTests
Change-Id: I252eaadff85fa47b894e989b4f2527b00c5dca56

Remi NGUYEN VAN   authored and   Motomu Utsumi   commited 2023-04-28 19:18:43 +09:00
6d38c01852
Merge "Remove TODO comment that was already done"
KH Shi   authored and   Gerrit Code Review   commited 2023-04-24 09:32:56 +00:00
bcd62d18f4
Add tx_bytes and rx_bytes to UpstreamEvent message
This commit adds two new fields, tx_bytes and rx_bytes, to the
UpstreamEvent message. These fields provide information about the
amount of data transferred during the event, which can be useful for
network performance analysis. The current tx/rx usages are always
zero, but it will be updated in a later change to reflect the actual
usage. No changes were made to the existing fields upstream_type and
duration_millis.

Test: atest TetheringMetricsTest
Change-Id: I9e1043b3fff5aa3f548b8696bac7e5bc4271c77c

Wayne Ma   commited 2023-04-21 11:15:56 +08:00
b5ee365614
Add forwarded stats dump in tethering hardware offload
The information can be useful for issue debugging, it shows the
accumulated traffic offloaded to the hardware for all upstreams.

$ dumpsys tethering
....
    ForwardedStats:
      rmnet_data2: rx:155686981 tx:799922
....

Bug: b/205762647
Test: adb shell dumpsys tethering
Change-Id: I94143329bdc8ad0eff79c32f329fae95ad3acf8a

KH Shi   commited 2023-04-19 09:14:57 +00:00
11dee200f9
No Tethering Offload HAL is not really an error
Bug: 278660842
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I978de7fe33b77b432df183b4c7a1966849f17389

Maciej Å»enczykowski   commited 2023-04-18 10:05:13 +00:00
b68f73cc17
Address comment from aosp/2335004
Bug: 263681262
Test: atest TetheringMetricsTest
Change-Id: I7372b7717a903d43a543f82e31a0439725d02e3a

Wayne Ma   commited 2023-04-13 10:01:36 +08:00
fab745c8ae
Remove TODO comment that was already done
The TODO is used to track to dynamically pass down the TTL from the
upstream interface. Remove it as it was already done in IpServer.

Test: No code changes
Change-Id: Idb12f82023315661f1bf4c767b9b7744a151e821

KH Shi   commited 2023-03-24 11:38:18 +08:00
5655bf52e7
Merge "Implement logging of upstream event type and duration."
Wayne Ma   authored and   Gerrit Code Review   commited 2023-03-20 16:50:37 +00:00
9d6b724887
Merge "Add Tetheroffload AIDL interface support"
KH Shi   authored and   Gerrit Code Review   commited 2023-03-20 03:58:42 +00:00
7b8568927e
Add Tetheroffload AIDL interface support
Add the AIDL HAL service interface support and abstract the HIDL/AIDL
interface implementations to allow OffloadController to talk to both
interfaces.

Bug: b/205762647
Test: atest com.android.networkstack.tethering
      atest ConnectivityCoverageTests
      atest ConntrackSocketTest
Change-Id: If7634a298d03668ed70b328f1ad6ca0ac0fe170b

KH Shi   commited 2023-03-17 16:56:47 +08:00
3d5e65cb48
Implement logging of upstream event type and duration.
Bug: 263681262
Test: atest TetheringMetricsTest
Test: statsd_testdrive 303
Change-Id: I80301ee035a9814920e3ce4b9eca6bcdc59350db

Wayne Ma   commited 2023-03-17 16:40:06 +08:00
c0e9e2901b
BpfCoordinator: refactor updateUpstreamNetworkState to get MTU
This is a preparation for CLAT offload.

Move the getting the MTU into a function for refactoring
updateUpstreamNetworkState() which could be simpler.

Bug: 258637850
Test: atest BpfCoordinatorTest
Change-Id: I8f22b022d4d00597810b56ab6e3e55ed7ab9076d

Hungming Chen   commited 2023-02-21 23:00:51 +08:00
85d98ea79f
Increase RA default lifetime.
Currently we have 300s..600s RA interval, so ~450 seconds,
and a 6 * 600s, ie. 3600s (1h) lifetime.
This means on average about 8 RAs during the lifetime.

APF's FRACTION_OF_LIFETIME_TO_FILTER is 6, so the first
3600s / 6 = 600s of RAs are filtered out by a hotspot client
Android device.  This means we really only get 3600s - 600s = 3000s
worth of RAs (after the initial one).
Hence, the client will get approximately 3000s / 450s = 6.666 RAs.

Thus, assuming a clientside DTIM multiplier of just 2, the client
phone only needs to fail a 50/50 coin toss 6 times in a row to
lose all 6 of those RAs.

That's a 1 in 2**6 = 64 chance, and it gets rerolled every ~450s.

Per https://www.codechef.com/wiki/tutorial-expectation
expected number of coin flips for getting N consecutive heads is:
2**(N+1) - 2

N=6 --> 2**7-2 = 126

126 * ~450s = 56700s = 15.75h

This means failure is expected roughly on the order of 16 hours.

By doubling the lifetime from 1h to 2h, we effectively double
the number of RAs, and lower the failure chance from 1 in 2**6,
to 1 in 2**13, which is 1 in 8K and thus much less failure prone.

N=13 -> 2**14-2 = 16382  --> failure expected after ~85 days

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

Maciej Å»enczykowski   commited 2023-02-16 22:56:25 +00:00
f95fd405d7
Merge changes Ie2ba9805,I8f5b23f9
* changes:
  Move onUpstreamCapabilitiesChanged out of reportUpstreamChange
  TetheringTest: improve onUpstreamCapabilitiesChanged test

Treehugger Robot   authored and   Gerrit Code Review   commited 2023-02-01 06:35:13 +00:00
7acd206160
Merge "UpstreamNetworkMonitor: remove unused mTetheringUpstreamNetwork"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-02-01 05:59:59 +00:00
42d28f1d66
BpfCoordinatorTest: add testUpdateUpstreamNetworkState
Bug: 258637850
Bug: 241106456
Test: atest ConnectivityServiceTest
Change-Id: I156398ef7ffaceb454dc187682238821da77c72b

Hungming Chen   commited 2023-01-31 16:35:09 +08:00
650cc9c0d3
Move onUpstreamCapabilitiesChanged out of reportUpstreamChange
onUpstreamCapabilitiesChanged not only be called inside
reportUpstreamChange. Separate onUpstreamCapabilitiesChanged out
of reportUpstreamChange so that reportUpstreamChange can focus
on upstream network change callback.

Bug: 243516306
Test: atest TetheringTests
Change-Id: Ie2ba9805fc43f921100c0286a9300df02f63e35d

Mark   authored and   Hungming Chen   commited 2023-01-18 15:13:49 +08:00
a1f6362931
UpstreamNetworkMonitor: remove unused mTetheringUpstreamNetwork
The variable mTetheringUpstreamNetwork is unused.
Remove the dead variable and its related setter setCurrentUpstream().

History:
aosp/507635: add mTetheringUpstreamNetwork
aosp/1183410: some functions stop using mTetheringUpstreamNetwork
aosp/1203243: stop using mTetheringUpstreamNetwork completely

Bug: 243516306
Test: atest TetheringTest
Change-Id: I07784c47e49dd9ef034f91bef9089ca48c187f30

Hungming Chen   commited 2023-01-18 15:13:49 +08:00
50b25b1136
Merge changes from topic "deprecate_connectivity_action_in_tethering"
* changes:
  Tethering: deprecate CONNECTIVITY_ACTION on U+ device
  Test: add tests to testChooseDunUpstreamByAutomaticMode_*
  TetheringTest: separate setup func from chooseDunUpstreamTestCommon

Treehugger Robot   authored and   Gerrit Code Review   commited 2023-01-13 08:41:20 +00:00
401f1ff2db
Merge "unregistered null callback will cause a crash later"
Steven Moreland   authored and   Gerrit Code Review   commited 2023-01-07 02:11:16 +00:00
f4e0f096b5
unregistered null callback will cause a crash later
Bug: N/A
Change-Id: I7acbc084d8a401817879d416f0283ca40e060069
Test: N/A

Steven Moreland   commited 2023-01-06 02:29:54 +00:00
cf42d60c53
BpfCoordinator: publish upstream interface mtu to v4 offload rule
Respect the upstream interface mtu instead of always setting
mtu 1500.

Using upstream interface mtu is probably not the best solution
for tether offload pmtu but it at least respects the upstream
interface mtu which may be less than 1500.

Test: manual test
1. Connect to carrier Taiwan Star.
2. Enable tethering and check the mtu 1434 in dumpsys.
IPv4 Upstream: proto [inDstMac] iif(iface) src -> nat ->
dst [outDstMac] pmtu age
  udp [02:10:45:32:ef:35] 54(54) 192.168.72.125:39034
  -> 15(rmnet1) 100.83.189.11:39034
  -> 142.251.43.14:443 [00:00:00:00:00:00] 1434 69657ms
IPv4 Downstream: proto [inDstMac] iif(iface) src -> nat
  -> dst [outDstMac] pmtu age
  udp [00:00:00:00:00:00] 15(rmnet1) 142.251.43.14:443
  -> 54(54) 100.83.189.11:39034
  -> 192.168.72.125:39034 [9a:8a:4d:ec:a4:7c] 1434 69633ms

Bug: 262860312
Test: atest BpfCoordinatorTest
Change-Id: Ic6dcb95ed76d5306053e4645b6baebc67ff082cf

Hungming Chen   commited 2023-01-03 23:36:30 +08:00
5c985e2cdd
Tethering: deprecate CONNECTIVITY_ACTION on U+ device
Both CONNECTIVITY_ACTION and UpstreamNetworkMonitor monitor the
upstream connection status. The upstream status should be monitored
in one place and deprecated the duplicate one since U+ device.

Once CONNECTIVITY_ACTION is removed, CMD_UPSTREAM_CHANGED won't be
triggered anymore. For non-dun upstream netowrk , upstream
re-evaluation is triggered by EVENT_DEFAULT_SWITCHED and
EVENT_ON_LOST. For dun upstream re-evaluation, re-evaluation is
triggered by EVENT_ON_LINKPROPERTIES and EVENT_ON_LOST.

Changes:
1. Deprecate the CONNECTIVITY_ACTION broadcast.
2. Re-evaluate possible upstream selection on the event
   UpstreamNetworkMonitor.EVENT_ON_LOST.

Note that EVENT_DEFAULT_SWITCHED and EVENT_ON_LINKPROPERTIES have
already triggered the upstream re-evaluation and keep as it.

Bug: 257408654
Bug: 257941865
Test: atest ConnectivityCoverageTests
Change-Id: I8b75cfb2fec51fb5bc4e2d13ad6b54daf8efc71e

Hungming Chen   authored and   Nucca Chen   commited 2022-12-28 02:28:16 +00:00
a432d621b0
Add Wearable Tethering flag and configuration
This establishes the main Wear connection manager class,
and enforces T+ requirement.

Bug: 245972418

Change-Id: Ia60925ce4dc2a25ac61c4b9bae1d022dc74f5b05

Igor Chernyshev   commited 2022-12-19 14:40:15 -08:00
a4fc702f7e
Merge "Replace NetlinkSocket with NetlinkUtils"
Chiachang Wang   authored and   Gerrit Code Review   commited 2022-12-19 12:40:41 +00:00
2d7d6e5caf
Replace NetlinkSocket with NetlinkUtils
Those static method and constants are better to fit in
NetlinkUitls. Replace the usage.

Test: m
Test: atest FrameworksNetTests NetworkStackTests
Change-Id: I81e27b8264e39764a44a4ba87344e9ac940d920a

chiachangwang   commited 2022-12-19 06:39:31 +00:00
e97aed4847
Merge "Use SocketUtils from shared lib"
Chiachang Wang   authored and   Gerrit Code Review   commited 2022-12-19 00:54:16 +00:00
393052b61f
Add CDM dependency in Tethering
This change introduces a limited library for dependencies on
framework-connectivity from Tethering,
connectivity-internal-api-util, where all classes are annotated with
@RequiresApi(S) to ensure proper API checks are done before usage.

Bug: 245972418

Change-Id: I82bafd9063341adc71d07f0858e6d68283d081f0

Igor Chernyshev   commited 2022-12-16 17:55:53 +00:00
9dac660bf0
Use SocketUtils from shared lib
Test: m
Change-Id: Ia86183a7e7844309dcbd21140e2785a71d7febab

chiachangwang   commited 2022-12-16 07:34:51 +00:00
18e072c7f5
Merge "SyncSM08: statically import tethering error code constant"
Mark Chien   authored and   Gerrit Code Review   commited 2022-12-14 13:35:12 +00:00
6d8176898e
SyncSM08: statically import tethering error code constant
This can make the code using error code not so easy to over 100
words line limit.

Test: m
Change-Id: I952c51f2e3508ed320744985193802454d07ccfe

Mark   commited 2022-12-14 09:12:15 +00:00
74461fc13d