Commit Graph

195 Commits

Author SHA1 Message Date
markchien
00a0bed534 Add replaceFirewallChain API
To deprecated firewallReplaceUidChain netd binder and move the
functionality to tethering (connectivity) mainline module, expose
replaceFirewallChain to support the caller outside the module.
Currently the API are still call to netd. Will replace with the
implementation inside tethering (connectivity) module.

Bug: 209935649
Test: atest CtsHostsideNetworkTests
Change-Id: If7a87548b0a3acda00a1455da4e4ff24a630ddc7
2022-01-14 10:23:21 +08:00
markchien
98a6f95d0f Add setFirewallChainEnabled API
To deprecated firewallEnableChildChain netd binder and move the
functionality to tethering (connectivity) mainline module, expose
setFirewallChainEnabled to support the caller outside the module.
Currently the API are still call to netd. Will replace with the
implementation inside tethering (connectivity) module.

Bug: 209935649
Test: atest CtsHostsideNetworkTests
Change-Id: I9b64c9d12260521489a87fbeae5afbee2a8ea8f6
2022-01-14 10:23:15 +08:00
markchien
e1561fa800 Add updateFirewallRule API
To deprecated firewallSetUidRule netd binder and move the functionality to
tethering (connectivity) mainline module, expose updateFirewallRule to
support the caller outside the module. Currently the API are still call
to netd. Will replace with the implementation inside tethering
(connectivity) module.

Bug: 209935649
Test: atest CtsHostsideNetworkTests
Change-Id: I0b53c999e06c2378afec0eb491815ec398c91b0b
2022-01-14 10:19:51 +08:00
Mark Chien
136f2d2d91 Merge "Add updateMeteredNetwork{Allow, Deny}List APIs" 2022-01-13 08:21:03 +00:00
Treehugger Robot
296a343528 Merge "Add a method to apply a set of network preferences to a user profile" 2022-01-13 04:08:34 +00:00
Sooraj Sasindran
e7aee2736e Add a method to apply a set of network preferences to a user profile
Add a method to apply a set of network preferences to a user profile

Bug: 194332512
CTS-Coverage-Bug: 211133973
Test: CTS
Change-Id: I97730ea14e7c96922236fd77a591e5acadd875ba
2022-01-11 21:07:23 -08:00
Chiachang Wang
bf6b879b55 Add excludeLocalRoutes in NativeNetworkConfig
Add extra field in NativeNetworkConfig to allow CS to notify
netd whether the local traffic should be excluded from the VPN
network.

Bug: 184750836
Test: atest FrameworksNetworkTests
Change-Id: If230fe7057722c80a09433673ac3cec857f7a7a5
2022-01-11 11:33:44 +08:00
markchien
738ad911c7 Add updateMeteredNetwork{Allow, Deny}List APIs
To deprecated below netd binder interfaces and move the functionality to
tethering(connectivity) mainline module:
  bandwidthAddNaughtyApp
  bandwidthRemoveNaughtyApp
  bandwidthAddNiceApp
  bandwidthRemoveNiceApp
Expose updateMeteredNetwork{Allow, Deny}List APIs to support the caller
outside the module. Currently the two APIs are still call to INetd
binders. Once functionality is moved to mainline module, will switch to
use them.

Bug: 209935649
Test: m
Change-Id: I8df720935748c2587f91a7b760cfd5a93a0fa852
2022-01-07 10:16:13 +08:00
James Mattis
4ab1ffca29 Update to ConnectivityService to use utils
Update to ConnectivityService to use permission utils to validate the
existence of a system feature.

Bug: 210485380
Test: atest FrameworksNetTests:
com.android.server.ConnectivityServiceTest

Change-Id: Ia537cc5b37ef8d80f49f1a83ba572b3b8a9f6874
2022-01-05 09:15:24 -08:00
Chalard Jean
f4802fa4c2 Genericize NC#hasSameUids
This will be used by another set of UIDs in a future patch

Test: FrameworksNetTests
Change-Id: I2c5d18ef93e73b702723814592ef3f3baf5dfbc4
2021-12-16 23:03:42 +09:00
Chiachang Wang
e5c363a3bd Merge "Enable strict_updatability_linting in connectivity src" am: 81bc609550
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1902533

Change-Id: I5cf42aa64a838f711cd1ecc589f86aecb19b358f
2021-12-08 02:53:16 +00:00
Chiachang Wang
3bc5276568 Enable strict_updatability_linting in connectivity src
Bug: 188851968
Test: m lint-check
Change-Id: I3cd06ea16f05cb37d9369a48dd0285d8239fd764
2021-11-26 10:31:58 +08:00
Xin Li
e41bbea995 Merge sc-qpr1-dev-plus-aosp-without-vendor@7810918
Bug: 205056467
Merged-In: I745ef4d42ecaf06bb81d9dbe0b7162267fea65a8
Change-Id: I7b2a1fc519124cfc10806dde5fd543504a51e072
2021-11-10 08:06:18 +00:00
Remi NGUYEN VAN
959d2cb6bd Don't rematch all requests when adding new ones
With the network selection rewrite in S, rematching a single request can
now easily be done; this can be used as an optimization in
handleRegisterNetworkRequests to avoid rematching all requests when
registering a new one.

This can be disabled by a flag that is unset by default,
REMATCH_ALL_REQUESTS_ON_REGISTER.

Test: atest ConnectivityServiceTest
Change-Id: If76f79b41ac88863974f7025624667134bea2570
2021-11-08 19:17:57 +09:00
Chalard Jean
ba551d4dbb Improve logs in checkNrisConsistency
Test: ConnectivityServiceTest
Change-Id: If5235443217ad4abbdd40e89d5721d4f7832d52f
2021-10-28 12:45:12 +09:00
Chalard Jean
524f0b1d7f Apply a workaround, and try to detect a system crash
This will prevent the system crash in b/194394697, and on T try to
detect the issue much earlier and crash the system at that time
together with much more expansive logs.

Bug: 194394697
Test: ConnectivityServiceTest
Change-Id: Ia4be82179160216d41bf4d88b896e4814385063a
2021-10-27 16:00:56 +09:00
Chalard Jean
e88bfbc015 Merge "No-op cleanup" 2021-10-26 02:39:47 +00:00
Chalard Jean
a3578a5465 No-op cleanup
Binders from the system server don't help, because if the process
dies there is nobody to listen to its binder deaths.

Test: ConnectivityServiceTest
Change-Id: I993cb9481edfaeb652b875be7f90166db16d0e1d
2021-10-25 19:24:48 +09:00
lucaslin
6adf5ac19b Add underlying networks into NetworkAgentInfo if any
Now, VPN will set underlying networks into NetworkCapabilities
directly. So the declaredUnderlyingNetworks can also be set
directly when creating a NetworkAgentInfo.

Bug: 191918368
Test: atest FrameworksNetTests:ConnectivityServiceTest
Change-Id: I507072d00ae1eb0c391e5261ab93e359b9c4cb5c
2021-10-19 15:04:56 +08:00
Treehugger Robot
29f0350da3 Merge "Update Permission only if the network is created" 2021-10-14 06:13:54 +00:00
Paul Hu
2541cf6d81 Merge "Stop using PerUidCounter#transact" am: a7db5ddda5 am: fe5e2742b6 am: 707437622a
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1821293

Change-Id: I30d748c01fa05f05a02ee5ef8bbc721fc32eafae
2021-10-04 14:23:49 +00:00
Paul Hu
fe5e2742b6 Merge "Stop using PerUidCounter#transact" am: a7db5ddda5
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1821293

Change-Id: Icd1072ef5b8281fa54f71796e7eaa981b0fd943b
2021-10-04 13:58:26 +00:00
Paul Hu
a7db5ddda5 Merge "Stop using PerUidCounter#transact" 2021-10-04 13:48:07 +00:00
Treehugger Robot
3fcefe8039 Merge "Updating formatting and text for per-app dumpsys" am: 7ece4bb71e am: 3a44ebe9a1 am: 388ae1444f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1723618

Change-Id: Iaac0cb2ec69b2335759f10787a3698c636b11753
2021-10-03 06:32:52 +00:00
Treehugger Robot
3a44ebe9a1 Merge "Updating formatting and text for per-app dumpsys" am: 7ece4bb71e
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1723618

Change-Id: Id13fe82d772d51b935a86076b1b660f57b4f5032
2021-10-03 06:11:23 +00:00
TreeHugger Robot
0a2d680a4d Merge "Ensure calling package name and uid are matched" into sc-qpr1-dev am: e93efb6f96
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/15618365

Change-Id: I80aa5da33f8c4c5154a721ceec58852b6c2d42f1
2021-10-01 14:21:16 +00:00
James Mattis
8b298a00b2 Updating formatting and text for per-app dumpsys
Fixing the indentation for dumpsys CONNECTIVITY for per app network
info. Also updated to more clearly show when the active network is
currently tagged to the "no service network" for configured apps so as
to more clearly show intent to dumpsys consumers. Finally, correctly
showing profile network preferences which weren't being shown
previously.

Prior formatting with no per-app networks:
Current per-app default networks: Per-App Network Preference:
    none

Updated formatting with no per-app networks:
Current network preferences:
  Default requests:

Prior formatting with active per-app networks ("none" is shown in this
case since profile network preferences weren't correctly displayed):
Current per-app default networks: Per-App Network Preference:
    none
  Is per-app network active:
    true
    Active network: 100
    Tracked UIDs:
      {1100000-1199999}

Updated formatting with active per-app networks:
Current network preferences:
  Profile preferences:
    [[ProfileNetworkPreference user=UserHandle{11} caps=[ Capabilities:
    INTERNET&TRUSTED&NOT_VCN_MANAGED&ENTERPRISE Uids:
    <{1100000-1199999}>]]]
  OEM preferences:
    OemNetworkPreferences{mNetworkMappings={android.net.cts=-1}}
  Mobile data preferred UIDs:
    mMobileDataPreferredUids: {1, 2, 3}
  Default requests:
    Request: [uid/pid:1000/1423] - Satisfier: [100] Preference order: 10
    Tracked UIDs:{1100000-1199999}

Bug: 189860802
Test: adb shell dumpsys connectivity
Change-Id: I5ed4bb83e9e5a4497f5019ab4e4c0f238989a246
2021-09-30 11:47:36 -07:00
paulhu
74128521ad Stop using PerUidCounter#transact
PerUidCounter#transact is used to adjust the request counter for
the per-app API flows. Directly adjusting the counter is not
ideal however in the per-app flows, the nris can't be removed
until they are used to create the new nris upon set.

In fact, satisfiers are the info that new nris need reference.
Without satisfiers in new nris, the avaiable callbacks would be
sent to listeners agin when assign new satisfiers. Even the new
best networks are same as previous satisfiers, but the new nris
have lost those info if calling handleRemoveNetworkRequests()
before createPerAppCallbackRequestsToRegister().

However, removing satisfiers from nris is not necessary actually
because the CS will update the best network to nri when compute
network reassignment. It doesn't need to be cleared when
calling handleRemoveNetworkRequest(). Thus, keep that info and
adjust the sequence to remove nri first. The counter is still
correct and doesn't hit limit artificially.

Bug: 201648050
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I4cbc953def7866b23c2b8ebc8deaadf0ffc3b75d
2021-09-30 15:35:53 +00:00
Pavan Kumar M
be994246f4 Update Permission only if the network is created
Reproduction steps:

- Register a NetworkAgent but don't mark it as connected.
- Set teardownDelayMs for the NetworkAgent to 100
- Unregister the NetworkAgent then see system crashed.

Tests:

- Builds, Boots
- ConnectivityServiceTest

Change-Id: Ib8e517acb0193a2454d672612fe61fc199de46a4
Bug: 200023207
2021-09-29 12:37:42 +00:00
Chalard Jean
8c06f9991b Merge "Check NetworkAgentInfo Map Before Destroying Network" am: 9d31c63e03
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1802528

Change-Id: Ibcf989ffd494108faeeb4419041fb32389208c4d
2021-09-29 06:20:06 +00:00
Chalard Jean
9d31c63e03 Merge "Check NetworkAgentInfo Map Before Destroying Network" 2021-09-29 06:03:56 +00:00
Tyler Wear
f405adead7 Fix NetworkOffer Death link does not exist am: 3ec7e6d9fb
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1799528

Change-Id: Ic1b0cb9e06d05d334cedd4b50bc7e8cf91dcc59a
2021-09-29 00:55:19 +00:00
Tyler Wear
614b27badd Check NetworkAgentInfo Map Before Destroying Network
updateNetworkInfo is called with the argument in a message,
which is initialized with `this` in NetworkAgentRegistry.
That means it's technically possible that CS calls
tearDownUnneededNetwork, calling nai.disconnect() and
queuing up a message to call this, but before it's done
the NA calls sendNetworkInfo with DISCONNECTED, which
never looks up the agent from the map. Throwing a
ServiceSpecificException and resulting in a System crash.

Bug: 196423147
Change-Id: Ia52f2b794f32c263200c14b8dc2eb6b184bff5ff
2021-09-28 17:41:23 -07:00
Tyler Wear
3ec7e6d9fb Fix NetworkOffer Death link does not exist
unregisterNetworkProvider is being called from binderDied()
and handleUnregisterNetworkProvider() at the same time. This results
in NoSuchElementException being thrown.

Check than noi can be removed from network offers before unregistering
death link.

Bug: 196423150
Change-Id: If5bd5f2894fa0509a89340efdc85180c54e72e0e
2021-09-20 10:40:19 -07:00
Chalard Jean
d4ec13a400 Merge "Add a mode for cell radios unable to time share" am: c80a5d56db
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1827923

Change-Id: I5ded48c8498c32977adcfe2363599d6cfa246e1b
2021-09-18 12:50:52 +00:00
Chalard Jean
0702f98edc Add a mode for cell radios unable to time share
Upon changing the default SIM card, the radio will create a
new connection to the new subscription. If that subscription
works correctly, the stack will prefer it to the old one as
the new subscription will be marked with a Primary policy
flag it its score.

Normally, at this point the old network lingers to give apps
an opportunity to gracefully migrate their connections. But
with some radios, this may have a dramatic effect on the
performance of the new connection.

This patch introduces a flag so that devices with such radios
can be marked. In this case the stack will move to a degraded
mode and eschew the grace delay for apps and give them a hard
break instead, so that the new network can reach a good
performance immediately. Apps with existing connections will
suffer a worse experience.

If there is a request that can only be served by the old
connection, still keep it, as arguably the user still
expects their MMS be sent on the old connection, even if the
new connection doesn't work well until it's done.

Test: new test in this patch, and add relevant tests in both modes
      also manually change the value of the flag and run
      FrameworksNetTests and CtsNetTestCasesLatestSdk
Bug: 200226979
Change-Id: I4ace82f90e873bf06298cc689bb1d794ed5124bd
2021-09-18 04:03:13 +00:00
Junyu Lai
6f988d4042 Merge "Include suspended network when getAllNetworkStateSnapshots" am: 48426bb2a4
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1797867

Change-Id: I700e16334e0f8aeea862555e8ecf784cf36fd315
2021-09-09 09:40:15 +00:00
Junyu Lai
48426bb2a4 Merge "Include suspended network when getAllNetworkStateSnapshots" 2021-09-09 09:24:04 +00:00
Junyu Lai
ddecb66246 Include suspended network when getAllNetworkStateSnapshots
Suspended network should be considered as temporary shortage of
connectivity of a connected network. Thus, it should not be
excluded from network state snapshots and causes data usage to
stop accounting or iptables rules to be removed on the interface
of the suspended network.

This change also address the naming confusion of default networks
parameter of expectNotifyNetworkStatus.

Test: atest ConnectivityServiceTest#testGetAllNetworkStateSnapshots
Bug: 196079981
Change-Id: I8096356f9a472fb1c1246fbdf3fd5f981387fb1c
2021-09-08 06:02:28 +00:00
paulhu
b2c286816d Ensure calling package name and uid are matched
CS#requestRouteToHostAddress enforcing change permission doesn't
check whether the calling package belongs to calling uid. This
can be used to check whether package name exists or not without
permission. Thus, add a check to ensure calling package name and
uid are matched.

Bug: 193801134
Test: atest FrameworksNetTests CtsNetTestCases
Ignore-AOSP-First: Security fix
Change-Id: I980f1c68b5321601aa40da29e283fb4dd717d5de
2021-08-26 13:23:03 +00:00
Chalard Jean
72ed43d6dc Merge "Fix an infinite loop with network offers" am: 77992bbfbb
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1800007

Change-Id: I1fe463232308fbc73753dc8d19f269142f6f8776
2021-08-20 06:39:30 +00:00
Chalard Jean
bb902a5fee Fix an infinite loop with network offers
When the avoidBadWifi configuration is false and not overridden,
a WiFi network that was validated in the past but becomes
unvalidated needs to outscore a cell network that is validated.
This is happening correctly when the stack compares two networks.
However, when the stack compares an existing network to an offer
for a cellular network, the offer was automatically considered
not to yield. This would mean the stack would be requesting cell
out of the telephony factory, only for that network to lose to
WiFi and be discarded immediately, then recreated again etc.

When there is some other reason cell should be up (such as the
"mobile always on" setting being active), this would not be
visible because the cell network would have another reason not
to be torn down.

Have offers correctly account for the current value of the
configuration and setting. This has the ranking of the offer
lose against WiFi like the actual network loses, meaning the
offer is not needed.

This also requires updating the offers whenever the value of
the setting changes.

Test: new test for this, also ConnectivityServiceTest
Bug: 195441367
Change-Id: I4fe5de98bc15bcf9bbbe25c6c7c8a7ba382f8db7
2021-08-19 22:53:41 +09:00
Xin Li
3ec4468fb7 Merge sc-dev-plus-aosp-without-vendor@7634622
Merged-In: I5a33f959c8ae5a34584f57508f392038e44062e7
Change-Id: Ib4e5e75ee8bbe19806bdc2f69590d164fb75774b
2021-08-14 06:31:05 +00:00
Benedict Wong
5805d3cfd2 Merge "Prevent NPEs when registering/unregistering ConnDiags CBs." 2021-08-12 20:35:39 +00:00
Chiachang Wang
c07315aa08 The net cap value should be bit shifted before &ing
The check intends to do the bit & operation. The net cap value
should be shifted against the original capabilities.

Also fix the typo in the method name.

Bug: 191918212
Test: atest FrameworksNetTests
Change-Id: I98396b2538f36fe8b29d27a544a2dfb3060bc9c5
2021-08-11 14:55:00 +08:00
Chalard Jean
5234f3acc6 Fix a crash when changing preferences
The crash occurs when some app has more than half its limit
in requests that will need to be moved to some other default
network upon changing the preferences.
This will send the requests for this app over the limit
temporarily when creating new requests for the reevaluated
ones.

While ConnectivityService has a provision for making a
transaction-like addition/removal of requests that is meant
to avoid exactly this kind of crash with the transact()
method on PerUidCounter, the code only transacts on
mSystemNetworkRequestCounter. But these requests are counted
in the mNetworkRequestCounters, which is not part of the
transaction, causing the crash anyway.

To avoid the problem, this patch allows the request counters
to go over the max if and only if the system server is
updating the request counts for a UID other than its own.
This should allow only the case where ConnectivityService is
moving the requests over to the new per-uid default, while
keeping the exception when registering from an app (then the
calling UID is not the system server), or when the system
server registers its own requests (then the UID inside the
request is that of the system server).

A much better solution than this patch would be to completely
eliminate the transact() method by somehow unregistering the
old ones before creating the new ones.
However this would be a much bigger and difficult patch than
this, and much more dangerous, because callers depend on the
list of requests to find out the old requests to remove, so
they have to be created first.

Another possible clean solution would be to count the
requests not in the NRI constructor, but later. This would be
more error-prone though because it would be very easy to
create an NRI without counting it.

Bug: 192470012
Test: ConnectivityServiceTest. Improve tests so they catch
      this case.

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1781202

Merged-In: Ia482e6fbf2bf300ce6cbaca72810d394ed201b98
Change-Id: I6744d2f60d6bd664f048b532a58461c110a5b7fe
(cherry picked from commit 916aeb7b0d)
2021-08-05 10:33:12 +09:00
Chalard Jean
faa5bad6c3 Merge "Fix a crash when changing preferences" am: aeb051b962 am: 916aeb7b0d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1781202

Change-Id: I39a8e756c73c675fc0eb74f3d570d128f6ecf390
2021-08-04 12:48:02 +00:00
Chalard Jean
aeb051b962 Merge "Fix a crash when changing preferences" 2021-08-04 12:23:52 +00:00
Xiao Ma
f29e0435a9 Merge "Import net-utils-device-common-netlink instead of netlink-client." am: 609e71a46c am: dd7e9e8800
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1753303

Change-Id: I4fb162f20f5816de1ee1b784cb39533362b34677
2021-08-04 07:56:23 +00:00
Xiao Ma
609e71a46c Merge "Import net-utils-device-common-netlink instead of netlink-client." 2021-08-04 07:27:18 +00:00