Commit Graph

396 Commits

Author SHA1 Message Date
Chalard Jean
43aae65caf Move MultinetworkPolicyTracker to services, where it belongs.
This is necessary so that MultinetworkPolicyTracker can see
DeviceConfig. It will also allow removing reflection from
this file to address a long-standing TODO.

Test: build
Change-Id: I968bf67e0e0189b01515242371599c02bc9e2ca2
2022-09-27 14:10:41 +09:00
Chalard Jean
e9332c4bdf Add the notification for actively prefer bad wifi
With this patch and "config_activelyPreferBadWifi=1"
(or SDK level >= U) and bad wifi avoidance turned off,
when the device connects to a bad wifi, after 20
seconds of the wifi not validating the device will
pop up a head-up notification with text
"<SSID> has no internet access".

When tapped, the notification will bring up the existing
Settings dialog :
*Wifi not connected to the internet*
You can switch to mobile whenever Wi-Fi is bad
 □ Never show again
 <Stay on Wi-Fi> <Switch to Mobile>

If the wifi validates and loses access again, the same
notification/dialog are shown if Settings.Global.
NETWORK_AVOID_BAD_WIFI=PROMPT ; if IGNORE, the device
stays stuck on wifi.
If AVOID, then bad wifi avoidance is turned on in the
first place, so none of this happens.

Behavior in other cases :
- If config_activelyPreferBadWifi=0, then upon connecting
  to a wifi without internet, the behavior is unchanged :
  the device stays on mobile and after 8 seconds a
  notification pops up asking whether to stay connected.
  If the network validates, then loses access, the behavior
  depends on a few things :
  - If config_networkAvoidBadWifi is 0 and Settings.Global.
    NETWORK_AVOID_BAD_WIFI = IGNORE, then the device stays
    on wifi and says nothing.
  - If config_networkAvoidBadWifi is 0 and Settings.Global.
    NETWORK_AVOID_BAD_WIFI = PROMPT, then
    notification pops up asking whether to switch to mobile.
  - If config_networkAvoidBadWifi is 1 (regardless of the
    value of Settings.Global.NETWORK_AVOID_BAD_WIFI), or if
    Settings.Global.NETWORK_AVOID_BAD_WIFI = AVOID, then
    the device switches back to mobile.

- If Mobile is not connected, all the above applies. This
  is not great for the messages including "switch to mobile"
  but this patch doesn't change it.

Test: manual
Change-Id: Idb05b6a6e5c085f5ef72435d462e14bfd1341f87
2022-09-24 11:11:51 +09:00
Chalard Jean
1325a631cc Clear notif upon bad wifi off + tests for bad wifi notif
If a notification is up and the avoid bad wifi setting
is turned off, the notification should disappear.

This patch also adds some general tests for the bad wifi
notifications.

Test: new tests in this patch
Change-Id: I5bc42afbe0efd93cfb59a759bf0aaba49a4bfc9f
2022-09-24 11:11:51 +09:00
Chalard Jean
8a9061f0b5 Detect captive portals as they are tested, not upon notifying
In the previous code, ConnectivityService would mark a network
a captive portal when NetworkMonitor sends it a message to notify
the user for it. Theoretically, this is incorrect ; instead, the
marking should be done upon receiving the message that the network
was tested to be a captive portal.

In practice this hasn't been a problem so far. The captive portal
capability is observable in the app-received callbacks, but for
these purposes the old code and the new code behave the same, in
that in the callbacks, the network used to not have the portal
capability, then later it acquires it.

However, this is only not a problem as long as the captive portal
bit isn't used by network selection, which an upcoming change has
to implement for the "prefer bad wifi" feature. When that is the
case, network selection prefers the wrong result between the time
the network is marked as having been evaluated and the time the
network has been marked a captive portal. It should be marked as
both at the same time to avoid this discrepancy. This is what
this patch is accomplishing.

To do this correctly, this patch also has to disconnect the network
immediately upon it being tested as a captive portal if the old
CAPTIVE_PORTAL_MODE setting is set to CAPTIVE_PORTAL_MODE_AVOID,
instead of keeping it until NM sends the message to notify about
it.

Unfortunately because of the relative timing of the events this
patch has observable impact on what callbacks are sent because of
b/245893397 (the DoubleValidated bug). Before this patch, there
would be an extra useless callback when a captive portal validates
where the capabilities contain both VALIDATED and CAPTIVE_PORTAL,
then a second callback removing CAPTIVE_PORTAL. This patch fixes
this, but unfortunately introduces a symmetrical extra useless
callback when a captive portal network starts matching a callback,
where onCapabilitiesChanged is fired a second time after the
onAvailable sequence with the same capabilities. Fixing this is
very complex ; the best (and simplest) solution is really to
address b/245893397 decisively.

In the mean time, the behavior implemented by this patch is better
than the old one, because there no longer is an observable state
where the network is supposed to be a closed captive portal AND
validated, but instead there is a useless, but correct, caps
callback that mirrors exactly the one from b/245893397. When
b/245893397 is addressed this behavior goes away at the same time,
so this is probably the better behavior.

Test: FrameworksNetTests CtsNetTestCases
Change-Id: I6694db498507860e1d711e2aa0c591dfbfa90be2
2022-09-24 11:11:49 +09:00
Chalard Jean
e63c42f543 Only wait for 8 seconds when T && !activelyPreferBadWifi
Also addressing a cleanup comment from aosp/2210758

Test: FrameworksNetTests
Change-Id: I7414c27840ec84e5ad0aef6d76a7aa7bc39c51fc
2022-09-22 16:59:17 +09:00
Chalard Jean
020b93ac63 Introduce an overlay for actively preferring bad wifi.
This correctly updates when the mcc/mnc change.

Test: MultinetworkPolicyTrackerTest
Change-Id: I11c7ea7074a15975fb68d39eb3c728778d84a516
2022-09-22 16:58:49 +09:00
Jean Chalard
0172361ad4 Merge "Add a reevaluate command to ConnectivityService" 2022-09-20 05:38:47 +00:00
Treehugger Robot
afebcc8608 Merge "Revert "Log BPF programs & maps in bugreport"" 2022-09-18 19:17:32 +00:00
Chalard Jean
5fb43c7d38 Rework unvalidated prompt into first eval timeout
This patch removes the 8-second unvalidated prompt timer
and replaces it with a 20-second timer that does the
same thing in addition to signalling the stack that the
concerned network has now undergone evaluation once.

Test: FrameworksNetTests
Change-Id: I806f2bdfbf35243fa7cdb1cd1f0a5d549cfcd9c8
2022-09-16 16:53:32 +09:00
Chalard Jean
7a1d7a8120 Add a reevaluate command to ConnectivityService
This is useful for debugging occasionally.

Test: manual
Change-Id: Ic29f81cb993d7e75916d3bacfaed7d0d6d07af07
2022-09-15 19:11:33 +09:00
Chalard Jean
4c46308265 Test no Internet and partial connectivity notifications.
Test: new unit tests pass
Change-Id: I363fa3ef15476a30e7b8708a80867dd456e5e520
2022-09-13 19:33:26 +09:00
Motomu Utsumi
3dc2fb5378 Merge "register callback to pull NetworkBpfMapInfo atom" 2022-09-09 08:11:37 +00:00
Motomu Utsumi
166f966209 register callback to pull NetworkBpfMapInfo atom
Test: statsd_testdrive 10161, atest BpfNetMaps
Bug: 217624062
Bug: 245228691

Change-Id: I630a86cb5a34aaa1810eb75b374588dba570f0ff
2022-09-09 11:23:10 +09:00
Chalard Jean
2a96cf2e3e Improve a comment about network scores
Test: comment-only
Change-Id: I02546b207e07133536bcae10f8eb4ad76b944881
2022-09-06 13:44:10 +09:00
Chalard Jean
254bd168a3 Convert booleans in NAI to timestamps
These timestamps will be useful for debugging issues where
debuggers need to know what happened to long-lived networks,
where logcat doesn't span long enough.

These timestamps are also likely to be useful in the future,
in particular for metrics.

Test: FrameworksNetTests
Change-Id: I8f46ce92e2ab301fa32e18e714a43a4130719199
2022-09-01 18:37:01 +09:00
Treehugger Robot
b091693d36 Merge "NullPointerException due to command:adb shell service call connectivity 79 -> void unofferNetwork(in INetworkOfferCallback callback)" 2022-08-29 13:59:18 +00:00
Treehugger Robot
05021aa886 Merge "Never satisfy requests with networks that aren't connected." 2022-08-29 08:30:31 +00:00
Lorenzo Colitti
275ee60963 Never satisfy requests with networks that aren't connected.
Currently, NetworkAgentInfo#satisfies determines whether a
network exists (and should satisfy requests) based on
|created|, not |everConnected|. This is theoretically incorrect
because networks in CONNECTING state or similar must never
satisfy requests or call callbacks.

This cannot happen for requests. New requests are only added to
networks by NetworkAgentInfo#addRequest, which is only called by
computeNetworkReassignment via updateSatisfiersForRematchRequest,
which skips any network with everConnected = false. It can
potentially happen to listens though.

Also, this cannot ever happen for physical networks, because for
physical networks, created is set at the same time as
everConnected, the first time they enter CONNECTED state.

In theory, this can happen for VPNs since ag/988402 , which
changed the code to create VPN networks as soon as they enter
CONNECTING state. That CL added the everConnected boolean to
NetworkAgentInfo but did not update the satisfies and
satisfiesImmutableCapabilitiesOf checks to use everConnected.
In practice, even for VPNs this is very unlikely, since VPNs
advance from CONNECTING to CONNECTED essentially immediately.
Even if they didn't, sending callbacks before they enter
CONNECTED state would be incorrect because the app receiving
the callback would have no way of knowing that the network is
actually not yet connected.

With this change, some checks for everConnected become spurious,
because a network with everConnected=false cannot satisfy either
requests or listens. Remove these checks.

Test: extensively tested by existing ConnectivityServiceTest
Change-Id: I024bb2b85bc57228d53e69a7707c7ce7ac756259
2022-08-24 15:34:44 +09:00
Treehugger Robot
6a8166cf5e Merge "Use PerUidCounter in the connectivity static library" 2022-08-23 18:25:03 +00:00
Ken Chen
e4f45ab956 Revert "Log BPF programs & maps in bugreport"
This reverts commit daf5cb64cc.

Reason for revert: dumpstate has the same information

Bug: 243313712
Change-Id: Ie8283cd942bff6ef9dbb66e5926bf650bd56997f
2022-08-22 08:02:32 +00:00
Junyu Lai
00d92df645 Use PerUidCounter in the connectivity static library
This is a no-op refactoring which uses common PerUidCounter
from the static library and delete the private implementation
inside ConnectivityService. This refactoring includes:
  1. Make a private implementation that inherite PerUidCounter
     to convert and rethrow exception to maintain backward
     compatibility.
  2. Adjust per-uid max limit argument in the counter constructor
     since the private implementation is already buggy.
  3. Use the getter in PerUidCounter for the existing tests.

Test: testNetworkCallbackMaximum
      testProfileNetworkPrefCountsRequestsCorrectlyOnSet
      testRequestCountLimits
Bug: 235771502
Change-Id: I5c49edab18774acf819828201041c9931fabccc4
2022-08-17 15:50:39 +08:00
Xiao Ma
ace5b3635b Merge "Remove filegroup connectivity-module-utils-srcs in connectivity." am: 7f15ce1d9c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2153736

Change-Id: Idd2df16857eab2f7b7e7a971f876c36531fcb736
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-12 09:24:40 +00:00
Xiao Ma
7f15ce1d9c Merge "Remove filegroup connectivity-module-utils-srcs in connectivity." 2022-08-12 09:06:58 +00:00
Junyu Lai
9d5c46947f Merge "Remove ConnectivityService#PerUidCounter hack" am: 1125946264
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2144641

Change-Id: I4ae16a6f232bc3b977bfceea99d6767cebaae83d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-11 10:13:26 +00:00
Junyu Lai
31d38bffdf Remove ConnectivityService#PerUidCounter hack
Follow up from aosp/1781202 and aosp/1821293, creating nris
before removing old nris had been proven not necessary for
per-app API flow. Hence, the per-uid counter hack for system
uid that allows counter temporary go over limit does not
actually be used in the production code.

In other words, this CL is a no-op refactoring.

Test: testRequestCountLimits
Bug: 235771502
Change-Id: I8f71c6e4506fbec60cb503731aee64ab022b4634
2022-08-11 11:06:07 +08:00
Paul Hu
36b1e1eefc Merge changes I1cf472bd,Ibdaf2b23,I6967ad6f,I65f522c2,I0f220d1f, ... am: a3340c1355
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2001790

Change-Id: I1ab803bf751ef4dcb76c07d71ff6acd7873a2b60
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-10 02:17:26 +00:00
Paul Hu
69213fd19c Merge "Force specifying sanitized/not sanitized in caps from agent" am: 1896d713cc
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2001256

Change-Id: Idb21a047bbf6566dcdbb603828e5460aaaab983c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-09 09:35:31 +00:00
Chalard Jean
713e38cd31 Make the temporary NC sanitized instead of inlining
This is a no-op refactoring. This will be useful to
mutate a member of the NC before sending it to the app.

Test: ConnectivityServiceTest
Change-Id: I1cf472bd7626d5ee2b163078a695c4a52ac39085
2022-08-04 06:45:39 +00:00
Chalard Jean
39b12d4b8f Force specifying sanitized/not sanitized in caps from agent
To make sure anyone using the capabilities originally from
the agent have to know what they're dealing with, make the
member private and make accessors that spell out explicitly
the important parts.

This is the last step towards addressing the leftover
comment from aosp/1958906.

Bug: 238139913
Test: FrameworksNetTests CtsNetTestCases
Change-Id: I9fc1986c59726212acfc2ad921745c8bbc424035
2022-08-04 06:45:39 +00:00
Chalard Jean
aa5bc624f6 Remove accessors for legacy int score from NAI
These are no longer useful. Also, NAI no longer needs to
be comparable, and it should no longer be – comparing 2
NAIs only make sense in the context of a specific request.

Bug: 238139913
Test: ConnectivityServiceTest IpConnectivityMetricsTest
Change-Id: I6967ad6f08380213c29f3d47d6422f8bbea1946c
2022-08-04 06:45:39 +00:00
Chalard Jean
ee3fa20a5a Show time taken by the rematch
Example log (short version) :

02-26 12:52:49.624  1751  2116 D ConnectivityService: NetReassign [22 :
  101 → 100, 25 : 101 → 100, 38 : 101 → 100, 27 : 101 → 100, 32 : 101 →
  100, 19 : 101 → 100, 17 : 101 → 100, 34 : 101 → 100, 36 : 101 → 100,
  15 : 101 → 100, 1 : 101 → 100, 7 : 101 → 100] [c 0] [a 37] [i 2]

Example log (long version) :

02-26 14:10:32.433  3876  3979 D ConnectivityService: Rematched networks [computed 0ms] [applied 33ms] [issued 2]
02-26 14:10:32.433  3876  3979 D ConnectivityService: NetworkReassignment :
02-26 14:10:32.433  3876  3979 D ConnectivityService:   15 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   17 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   40 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   1 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   34 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   19 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   38 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   22 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   7 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   32 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   36 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   2 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   25 : null → 100
02-26 14:10:32.433  3876  3979 D ConnectivityService:   27 : null → 100

Bug: 238139913
Test: manual
Change-Id: I0f220d1f73cb9b0ddab82842e918ce8101ef1038
2022-08-04 06:45:39 +00:00
Chalard Jean
46bfbf0367 Address some IDE warnings in ConnectivityService
Unused arguments, non-final members, unannotated members, typos.
This doesn't try to remove all warnings, but just opportunistically
fixes some.

Bug: 238139913
Test: ConnectivityServiceTest
Change-Id: Ia5e905a0244cfb5f72c06d0c0be3458c42b27a52
2022-08-04 06:45:39 +00:00
Chalard Jean
dbc46950f7 Copy arguments from NetworkAgent registration early
These objects have a non-trivial lifetime, as they will be
stored while the NetworkMonitor (which lives in another
process) starts. Agents that live in the system server will
still have a reference to the passed arguments and might
want to keep and mutate them for their own purposes. To
avoid bad surprises, ConnectivityService should copy these
objects before the function returns.

This patch should not cause any additional copies, because
the copies that used to happen after the monitor has started
are now not necessary and are removed.

Bug: 238139913
Test: FrameworksNetTests
Change-Id: I1cdd14e7a247dc01a3d73f528c3f3d77bd103be5
2022-08-04 06:45:39 +00:00
Xiao Ma
6014237340 Remove filegroup connectivity-module-utils-srcs in connectivity.
Once moving NetworkMonitorUtils to frameworks/libs/net is done, we can
remove the connectivity-module-utils-srcs filegroup from connectivity
module, instead import it from net-utils-device-common lib.

Bug: 238960524
Test: atest ConnectivityCoverageTests
Change-Id: Ic1464a4c32d7c22ca7916e8f298ff1a09b71ce46
2022-08-03 18:16:48 +09:00
wangshengrjxtjcb
3f6c0b9949 NullPointerException due to command:adb shell service call connectivity 79 -> void unofferNetwork(in INetworkOfferCallback callback)
BUG:238033349

Change-Id: Ic26e48a8a263e9da3f5b12617e454c5072261253
2022-08-01 07:09:37 +00:00
Paul Hu
4794260989 Merge changes Ife5e91de,I46c5dfeb am: 5760d14c08
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2001255

Change-Id: Ie32913a684ebab39be61109aa40a966b18db5953
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-28 12:58:30 +00:00
Motomu Utsumi
76e3be3f4f Merge "Add flag to test BpfNetMaps refactoring" am: 64f706fe2c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2162998

Change-Id: I131efe444d25c532967fd8ea651ae0b713dd8aef
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-28 12:58:10 +00:00
Paul Hu
5760d14c08 Merge changes Ife5e91de,I46c5dfeb
* changes:
  Change the sanitizeCaps signature in preparation for moving
  Clarify sanitization of caps from NetworkAgent
2022-07-28 12:11:29 +00:00
Motomu Utsumi
f688eeb10a Add flag to test BpfNetMaps refactoring
Following CLs will switch previous codepath (JNI) and new codepath
(Java) for bpf map operations based on this flag.

Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: I74f10d5c97390993acea110f6528ef8980bb2aa4
2022-07-28 02:32:41 +00:00
Motomu Utsumi
edbe05a67f Merge "Use java BpfMap in BpfNetMaps#replaceUidChain" am: 6bcb3c290c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2145584

Change-Id: I49e70a3e862b0eb66f3fc17d230c79e8784d2c54
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-27 13:32:36 +00:00
Chalard Jean
2f9a2b7453 Change the sanitizeCaps signature in preparation for moving
This will move to NetworkAgentInfo. The caps argument is always
the same and can be removed, while the nai argument will become
'this'. The authenticator will need to be passed.

This is a second step towards addressing the leftover
comment from aosp/1958906.

Bug: 238139913
Test: FrameworksNetTests CtsNetTestCases
Change-Id: Ife5e91de15d0571f1251d2cd6f1b3ecc256572c6
2022-07-27 10:45:26 +00:00
Chalard Jean
da7fe5732c Clarify sanitization of caps from NetworkAgent
This is a first step towards addressing the leftover
comment from aosp/1958906.

Bug: 238139913
Test: FrameworksNetTests CtsNetTestCases
Change-Id: I46c5dfebfc12c4db71f7c9c6624b8d6cdf0bf3b5
2022-07-27 10:31:30 +00:00
Motomu Utsumi
9be2ea0080 Use java BpfMap in BpfNetMaps#replaceUidChain
Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: Ib2a2c2646834110a3eeeb786a4ea7a3f85718be8
2022-07-27 06:01:47 +00:00
Chiachang Wang
d2e4c1f915 Merge "Correct javadoc usage" am: b7f81e4a6d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2153593

Change-Id: I72c6695348fb9b5f81f5e89064ec10d166fa23bf
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-15 07:56:03 +00:00
Chiachang Wang
b7f81e4a6d Merge "Correct javadoc usage" 2022-07-15 07:41:33 +00:00
chiachangwang
9473c59980 Correct javadoc usage
"{@see" aren't rendered properly. Replace them with "See {@link"
or @see depending on the usage.

Bug: 238753273
Test: make doc-comment-check-docs ; Check the doc result
Change-Id: I70cb2f36e7c5fa8102b5949054df5184d755202c
2022-07-15 03:44:46 +00:00
Paul Hu
130819c7f2 Merge "Use common methods to check/enforece mutiple permissions" am: 6d74747445
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1827913

Change-Id: I3a4cc99d29face8b0775dc3d6814437b1460cbc4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-14 06:33:42 +00:00
Paul Hu
6d74747445 Merge "Use common methods to check/enforece mutiple permissions" 2022-07-14 06:19:54 +00:00
Paul Hu
d515cb78e4 Merge "Reword comment for language quality" am: e79157578b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2001254

Change-Id: Ieed3572889aeabb0c6b6e3f96aee7a895dde82ec
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-06 02:10:31 +00:00
Paul Hu
e79157578b Merge "Reword comment for language quality" 2022-07-06 01:52:06 +00:00