"when" is not thread-safe, as it relies on global state to find which
mock was called with the method to mock in its parameters.
This causes flakes where non-test code that interacts with the mock may
be called from another thread between the contents of "when" and the
"when" method another thread, causing UnfinishedStubbingExceptions or
other test errors. In particular
ConnectivityService#getNetworkCapabilitiesInternal was seen to be
wrongly identified as a mocking site for Dependencies.
Replace all usages with doReturn().when(mock).method() syntax, which has
better thread safety since global state is not necessary to tie the
mock, mocked method and return value.
Bug: 195626111
Test: atest ConnectivityServiceTest
Change-Id: I57c5ffb3b3f799fc59c3af4ccb323fb5d6794fad
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
Before sForceAllNetworkTypes is removed, the network
type and meteredness will be ignored when matchesMobile
or matchesMobileWildcard is called.
After sForceAllNetworkTypes is removed, the matches
method should check the network type and the meteredness.
Thus, if the test data contains different type or it's
not metered should not be counted.
Bug: 183776809
Test: FrameworksNetTests
Change-Id: Ie7194495d26c0f5ef7a247733f43c64688626c67
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
- This is a test only change.
- Remove calling startMonitoring() in setup() because this method
should be called only once, so each test needs to call
startMonitoring() if the testing function is running on it.
- Return empty list instead of null when getting installed
pacakges in setup(). This can help test to have default user
MOCK_USER1 when they call startMonitoring().
Bug: 192431153
Test: atests FrameworksNetTests
Change-Id: Id2ffb056b378873c3ba6a8bb31b7dedb56ad6d46
- Some code are used many times, it's better to make them as
common code for reducing inconsist behavior.
- Also stop using Boolean to represent network permissions and
replace them with int value. Because using Boolean for
permission comparison is really complicated and bizarre.
- Use PERMISSION_* for netd network permission directly.
Bug: 189705071
Test: atests FrameworksNetTests
Change-Id: I2a4e298b9a01f4b2874ae68e9d9539a0ab4aff4c
The test flakes with UnfinishedStubbingException, but the root cause
could not be identified. Add some logging to try to get more information
when that happens.
Bug: 195626111
Test: atest ConnectivityServiceTest
Change-Id: If12c1ea809789148ca9251386e5ee6ca6d74ff74
Some uids should be app ids, correct them for avoiding confusion
and incorrect use.
Bug: 189705071
Test: atests FrameworksNetTests
Change-Id: I4a5930e5dc63b4d901e1567f8935ad7203866c89
- This is a test only change.
- Some methods are very similar and duplicated. So merge them to
improve readability and reduce code complexity.
- Stop spying PermissionMonitor.
Bug: 189705071
Test: atests FrameworksNetTests
Change-Id: I8ec17bd2d396c4d49dd8b64be85d89d0145f4c3c
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
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
Currently, when a VPN app calls registerDefaultNetworkCallback,
it will always get its own VPN, even if the VPN app called
VpnService.Builder#addDisallowedApplication to take itself out
of the VPN's UID ranges.
Add a test for the current incorrect behaviour.
Also fix an indentation error elsewhere.
Bug: 195265065
Test: test-only change
Change-Id: Id9648ea71fc7ae10855aa311beeb7975569d17f2
testAvoidBadWifi could pass without issue. The refactor should
also be done. The test does not need to be ignored now. Remove
the annotation to bring the test coverage back.
Bug: 178071397
Test: atest ConnectivityServiceTest
Change-Id: I5652fa817f16b8c241f1e2066a0b04ad2156a3b7
The resolverOptions member of the ResolverParamsParcel has never
been set by AOSP code but was only used by OEMs modifying
DnsManager. Now that DnsManager is mainline code, this is no
longer possible. So the DNS resolver introduces a new
setResolverOptions IPC to allow OEMs to set the options and makes
the resolverOptions nullable.
Make DnsManager set resolverOptions to null, to ensure that when
DnsManager calls setResolverConfiguration, it does not overwrite
any options set by the OEM.
Bug: 194048056
Test: Device boots and has connectivity
Change-Id: I310a79521f5a365e50e2c65e9dd87d9b68f105d7
Merged-In: I310a79521f5a365e50e2c65e9dd87d9b68f105d7
The resolverOptions member of the ResolverParamsParcel has never
been set by AOSP code but was only used by OEMs modifying
DnsManager. Now that DnsManager is mainline code, this is no
longer possible. So the DNS resolver introduces a new
setResolverOptions IPC to allow OEMs to set the options and makes
the resolverOptions nullable.
Make DnsManager set resolverOptions to null, to ensure that when
DnsManager calls setResolverConfiguration, it does not overwrite
any options set by the OEM.
Bug: 194048056
Test: Device boots and has connectivity
Change-Id: I310a79521f5a365e50e2c65e9dd87d9b68f105d7
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)