Commit graph android_packages_modules_Co.../Tethering
Message SHA1
Merge "Use MANAGE_USERS permission to check for admin user" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-31 16:33:54 +00:00
12a7e185f2
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
Use MANAGE_USERS permission to check for admin user
The current implementation uses MANAGE_USERS, CREATE_USERS, or
QUERY_USERS to check if the user is an admin. However,
QUERY_USERS is not a privileged permission until Android U.
This can cause issues on devices running older Android versions
(e.g., T) where the tethering module requires this check but
doesn't have the necessary permission, leading to crashes.

This change updates the code to use MANAGE_USERS, a privileged
permission since 2015, to reliably determine if the user is
an admin across different Android versions.

Test: Manual on T device:
      1. Mock entitlement and enable hotspot
      2. Check granted permissions of android.uid.networkstack
Fix: 366816004
Change-Id: Iee060f0225d23c62d836f0211c63b649e539f77b

Junyu Lai   commited 2024-10-28 17:31:22 +08:00
f014ae2f2a
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 "Update requestDownstreamAddress calls in PrivateAddressCoordinatorTest" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-10-18 06:11:19 +00:00
5f6f114c91
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
Update requestDownstreamAddress calls in PrivateAddressCoordinatorTest
Bug: 369282577
Change-Id: Idccd15a8191e519a19afc71668e4ae2003efb71e

Handa Wang   commited 2024-10-18 01:29:56 +00:00
b1145dc6b1
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
Merge changes from topic "refactor-pac" into main
* changes:
  Update unit tests to reflect the changes to RoutingCoordinator and PrivateAddressCoordinator
  Move PrivateAddressCoordinator from Tethering to staticlibs
  Refator IpServer to allocate IPv4 address via RoutingCoordinatorManager API
  Introduce PrivateAddressCoordinator methods at RoutingCoordinatorManager

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-17 01:28:02 +00:00
e2a031b159
Update unit tests to reflect the changes to RoutingCoordinator and
PrivateAddressCoordinator

Bug: 350699020

Change-Id: Id0ae47dcb03c60b6caafa3feeecaf8b21092a101

Handa Wang   commited 2024-10-16 23:54:29 +00:00
d789d1b8de
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
Rename TapPacketReader to PollPacketReader for broader applicability
* Renamed TapPacketReader to PollPacketReader to better reflect its
  functionality beyond TAP interface interaction.
* The class includes general logic for polling and sending packets to
  file descriptors, making it suitable for wider use cases.

Test: TH
Change-Id: Icdf9a9d7ef6f49b589ed9cdbd05159ab95e7e5d9

Yuyang Huang   commited 2024-10-15 13:42:05 +09:00
eb3c631b89
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
Merge "Handle CMD_IPV6_TETHER_UPDATE in UnavailableState" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-05 01:43:58 +00:00
cc53e7feee
Merge "Change TetheringManager#RequestDispatcher as static" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-04 23:13:14 +00:00
edddb5b6f7
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
Merge "Mark packages/modules/Connectivity apps in updatable apexes with updatable: true" into main
Colin Cross   authored and   Gerrit Code Review   commited 2024-10-03 18:02:04 +00:00
7f16a49fa5
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
Mark packages/modules/Connectivity apps in updatable apexes with updatable: true
Set updatable: true for apps that are embedded in updatable apexes.
This replaces the top down propagation that was automatically setting
the flag in order to unblock support for incremental Soong analysis.

Bug: 367784740
Test: builds
Flag: EXEMPT refactor
Change-Id: Icba5fd39077b309750224b3cd4c8c3a65c94de10

Colin Cross   commited 2024-10-01 16:13:41 -07:00
558f56bd10
Merge changes from topic "pac-random-address" into main
* changes:
  Drastically simplify prefix and address selection process
  Simplify getSanitizedSubAddr to 1-liner
  Rename getStartedPrefixIndex to getRandomPrefixIndex
  Remove unused imports

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-09-29 04:25:22 +00:00
76b4a63ec1
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
Merge "Prefer framework-annotations-lib dependency" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-09-27 19:48:21 +00:00
acdd45dd3c
Simplify getSanitizedSubAddr to 1-liner
This assumes that PREFIX_LENGTH is 24. The change also adds a warning to
make sure PREFIX_LENGTH is not updated without updating
chooseDownstreamAddress.

Test: TH
Change-Id: I96a7f8bf273d69ed27320f9c6f5af4fd41f7097d

Patrick Rohr   commited 2024-09-27 12:19:02 -07:00
b1280c0467
Prefer framework-annotations-lib dependency
Rather than bundling a copy of the framework annotations, reference them
via framework-annotations-lib as a libs reference. This ensures the
target inherits any necessary keep rule configurations, and is the same
pattern used by other mainline modules.

Bug: 275175207
Test: m
Flag: EXEMPT refactor
Change-Id: I014aa79f4fec69aef062a2fb855a50f658380ac5

Jared Duke   commited 2024-09-27 18:41:54 +00:00
dff99282e8
Rename getStartedPrefixIndex to getRandomPrefixIndex
Test: builds
Change-Id: I38bba24dd0a1053e3795495cfdc14c9960056ffc

Patrick Rohr   commited 2024-09-27 10:05:31 -07:00
65bf46db67
Remove unused imports
Test: TH
Change-Id: Ifd3881133e11f303da03b85d845361f00a0fe198

Patrick Rohr   commited 2024-09-27 10:05:31 -07:00
f77127509e
PrivateAddress: Clarify the dependency
The dependency of PrivateAddressCoordinator on Context is too generic.
Actually it just needs the ConnectivityManager#getAllNetworks.

This CL clarifies the dependency and this provides flexibility of
instantiation of the class.

Bug: 369282577

Change-Id: I49043f7f557d83856d54cefc201208b7d9b9dd7f

Handa Wang   commited 2024-09-27 13:56:16 +00:00
1cda02fd4a
Change TetheringManager#RequestDispatcher as static
If the system GC does not recycle the RequestDispatcher
objects in time, they will hold more contexts, which may
lead to OutOfMemoryError.

So change TetheringManager#RequestDispatcher as static.

Bug:369730368

Change-Id: Ia67d8547bd2d239b5f939bd870761f2946afd43b
Signed-off-by: dingfeisong <dingfeisong@xiaomi.corp-partner.google.com>

dingfeisong   authored and   Feisong Ding   commited 2024-09-26 06:03:18 +00:00
8675fc0c5d
PrivateAddressCoordinator: remove the dependency on
TetheringConfiguration

We're removing the dependency on TetheringConfiguration because
TetheringConfiguration is not parcelable so it cannot be used in AIDL
API. Eventually we'll make PrivateAddressCoordinator expose its
functionalities via AIDL API at RoutingCoordinator.

Bug: 369282577
Change-Id: Id839d183b9463baa18a92a629370b4b8374f1ffd

Handa Wang   commited 2024-09-25 09:01:38 +00:00
664e1f4b89
PrivateAddressCoordinator: get rid of UpstreamNetworkState for
updateUpstreamPrefix()

This CL changes the signature of
PrivateAddressCoordinator#updateUpstreamPrefix to replace the
UpstreamNetworkState parameter with its member class. This is because we
want to make updateUpstreamPrefix() an AIDL API soon and
UpstreamNetworkState is not parcelable while its member fields are.

Bug: 369282577

Change-Id: Icf71d02d48c8c0d5dc2b21ee351efba956b6752d

Handa Wang   commited 2024-09-24 12:15:45 +00:00
8df9d34eb3
bpf: merge block.c into netd.c
Since this is just a special case of a bpf cgroup hook,
it really should be in netd.o with all other such hooks.

Besides moving/renaming the map & programs this should be a no-op.

Test: TreeHugger, atest bpf_existence_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4a2aedaf77f89a9c0a96fa1c369d80659535eabe

Maciej Żenczykowski   commited 2024-09-19 00:40:53 +00:00
3ad3794efa
Merge "Make java_sdk_library dependencies explicit" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-09-10 19:12:45 +00:00
430a8ad33c
Merge changes from topic "tether-active-sessions" into main
* changes:
  Support active session metrics sampling
  Add unit test for get max counter when removing tethering client
  Track tethering active sessions counts

Junyu Lai   authored and   Gerrit Code Review   commited 2024-09-10 02:53:47 +00:00
ff3b206df0