Commit Graph

11815 Commits

Author SHA1 Message Date
Remi NGUYEN VAN
be1081c632 Merge "Mark connectivity test utilities as module API" 2021-01-22 10:11:39 +00:00
paulhu
af50d7d24e Replace NetworkPolicyManagerInternal#isUidRestrictedOnMeteredNetworks()
Connectivity service is going to become a mainline module which
will not able to access hidden APIs. NetworkPolicyManagerInternal
is a internal serivce that CS can't be access after be a mainline
module. Thus, create NPMS#isUidRestrictedOnMeteredNetworks() and
NPM#isUidRestrictedOnMeteredNetworks() to replace
NPMI#isUidRestrictedOnMeteredNetworks().

Also correct the permission check in isUidNetworkingBlocked()
that needs to check OBSERVE_NETWORK_POLICY only.

Bug: 170598012
Test: atest FrameworksNetTests
Test: atest FrameworksCoreTests:NetworkPolicyManagerTest
Test: atest FrameworksServicesTests:NetworkPolicyManagerServiceTest
Test: atest CtsNetTestCases
Test: atest CtsHostsideNetworkTests
Change-Id: I5801a3a2076f3eb199a0226c38c85014b26c64e7
2021-01-22 16:14:28 +08:00
Remi NGUYEN VAN
761c7ad923 Mark connectivity test utilities as module API
The API surface is planned to move to the Connectivity module, meaning
that it will be maintained across multiple Android releases.
This is incompatible with TestApi semantics, which are designed to be
removable across releases. Effectively the APIs become SystemApi, so
mark them as such considering that TestApi is not supported by modules.

Remove the NetworkCapabilities.getCapabilities test API that is not
essential for tests, and mark other APIs as module API.

Test: m
Bug: 174436414
Change-Id: Ic04551a9874b3d756cf5e6c77ceabfc7c85d52a6
2021-01-22 16:16:57 +09:00
Daniel Bright
f9e945b074 Add Qos Callback support
* Provide App Developers Qos related info associated to
  a bound socket through ConnectivityManager
* Qos sessions are generated and filtered by Network Agents
  and sent back through the Connectivity Service to the
  API consumer.
* The structure of the code within com.android.server
  is designed to support different types of filters in the
  the future.
* The first type of Qos Attributes are related to EPS
  Bearers in order support RCS.

Bug: 155176305
Test: Added to cts/NetworkAgentTest
Test: Added to ConnectivityServiceTest
Change-Id: I145dd065d9deeee449eb9695ab3f6c8556ee7c09
2021-01-21 20:14:52 -08:00
Daniel Bright
f2a4eeb55d Add Qos Callback files
* Add QosCallback stub files

Bug: 155176305
Test: N/A
Change-Id: I7c231d60880c37ae1ce49fa8a621badf386ab8a7
2021-01-21 19:50:24 -08:00
Remi NGUYEN VAN
28d69fc2f7 Use network list in UNDERLYING_NETWORKS_CHANGED
The bundle is no longer necessary, as this message is not sent across
processes: the network list can be sent directly in the message obj
pair.

Bug: 173574274
Test: atest FrameworksNetTests CtsNetTestCasesLatestSdk
Change-Id: Iae049a24212ff9df19b29aead20bf4a594f05f99
2021-01-21 22:36:54 +09:00
Chiachang Wang
7f7db65552 Merge "[IT4.4] Host network activity related logic into a new class" 2021-01-21 08:41:15 +00:00
Chiachang Wang
34046e5920 Merge "Use ParcelFileDescriptor instead of FileDescriptor in the aidl" 2021-01-21 08:40:53 +00:00
Chiachang Wang
04a34b647d Use ParcelFileDescriptor instead of FileDescriptor in the aidl
Using FileDescriptor in the aidl will refer to
Parcel.readRawFileDescriptor() and Parcel.writeRawFileDescriptor()
whilie trying to do parcel operations. Those two APIs are hidden
and not accessible for the incoming ConnectivityService mainline
module. For such use cases in a module, it should be replaced by
using ParcelFileDescriptor that is designed for such usages.

Bug: 170598012
Test: atest FrameworksNetTests CtsNetTestCasesLatestSdk
Change-Id: Ia7e3a71ccb4b136cc55c9e90a384870c32cfd37b
2021-01-21 08:40:12 +00:00
Paul Hu
330798dd58 Merge "Replace Context @hide API in MultinetworkPolicyTracker" 2021-01-21 07:53:19 +00:00
lucaslin
1a8b4c6141 [IT4.4] Host network activity related logic into a new class
Create an inner class to handle the network activity related
logic to isolate the code for code cleanliness. It's helpful for
the follow-up modifications to move network activity logic from
NMS to CS to support Connectivityservice mainline.

Bug: 170598012
Test: atest FrameworksNetTests
Change-Id: I33b3b11f2700cb10eb6e3b58b6dfa52251bece80
2021-01-21 06:27:23 +00:00
Remi NGUYEN VAN
aa8c3fd4b1 Merge "Mark TestNetworkManager as module API" 2021-01-21 06:02:25 +00:00
Remi NGUYEN VAN
3c6ae335c1 Mark TestNetworkManager as module API
The API surface is planned to move to the Connectivity module, meaning
that it will be maintained across multiple Android releases.
This is incompatible with TestApi semantics, which are designed to be
removable across releases. Effectively the APIs become System/module
API, so mark them as such considering that TestApi is not supported by
modules.

Test: m
Bug: 174436414
Change-Id: Icd32fcbb65e9a4bb2b67cb9da7c971281be0781a
2021-01-21 10:45:04 +09:00
paulhu
54fdd61d0c Replace Context @hide API in MultinetworkPolicyTracker
MultinetworkPolicyTracker is part of Connectivity mainline module
which cannot call @hide API Context#registerReceiverAsUser. Thus,
replace it to Context#registerReceiverForAllUsers.

Bug: 170634463
Test: atest FrameworksNetTests
Test: Manully check that receiving intent and unregistering
      receiver can work normally.
Change-Id: Ie22a3aa40bc9243082672a64dba7c7940f9ff21a
2021-01-21 01:19:09 +08:00
lucaslin
af26922554 Use function inside NetdUtils instead of NetworkManagementService
TestNetworkService will be a part of mainline module, to prevent
using @hide API of NetworkManagementService in TestNetworkService,
use function inside NetdUtils instead.

Bug: 170598012
Test: atest CtsNetTestCasesLatestSdk
Change-Id: I738066ce2f1bcd616dc582a3ff1fd77bcd660c73
2021-01-20 18:09:46 +08:00
Lorenzo Colitti
4484070163 Fix legacy APIs when VPN switches to suspended underlying network.
Currently, when the VPN underlying network changes from a
network that is not suspended to one that is suspended (or vice
versa), some of the legacy APIs return incorrect results.

This is because the VPN's NetworkInfo can get into SUSPENDED
state even though the capabilities have the NOT_SUSPENDED
capability. This happens because the code in updateCapabilities
that checks for changes in NOT_SUSPENDED and NOT_ROAMING (which
are the capabilities that can affect the NetworkInfo state) is
only run when the capabilities change in a certain way.

Fix this by always checking for changes in these capabilities,
regardless of what else has changed.

This results in sending a lot more SUSPENDED and RESUMED
callbacks than the code sent previously. This should hopefully
not impact apps because those callback methods have never been
public API, though because they're just callbacks, it's possible
that apps found out via code inspection that the callbacks
existed and implemented them.

Bug: 172870110
Test: changes to existing tests in ConnectivityServiceTest
Change-Id: I6ec246a6a4e61f634956a165797fbb80296efd6a
2021-01-20 11:32:51 +09:00
Junyu Lai
bf49c1948a Merge "Revert "[VCN06] Support request background network"" 2021-01-19 10:24:47 +00:00
Junyu Lai
dfb7780384 Revert "[VCN06] Support request background network"
Revert submission 1545847-vcn06

Reason for revert: b/177876289 presubmit failure
Reverted Changes:
I8042ce197:[VCN06.1] Add CTS for request background network
If9aaa87b7:[VCN06] Support request background network

Change-Id: I9270b02a2d6d1ffcdd83b4f41becaf09a2b91e0a
2021-01-19 09:06:00 +00:00
Treehugger Robot
82a13fa884 Merge "Fix CaptivePortalDataTest#testParcelUnparcel on R" 2021-01-19 04:45:08 +00:00
Treehugger Robot
4b8630f65a Merge changes I475502fd,Ibf376a6f,Ia52f9caf
* changes:
  Address comments on aosp/1539753, aosp/1542487 and aosp/1547496.
  Fix propagating underlying caps when a network disconnects.
  Test for bugs with suspended VPN underlying networks.
2021-01-19 04:19:56 +00:00
Remi NGUYEN VAN
a162ff05e0 Fix CaptivePortalDataTest#testParcelUnparcel on R
CaptivePortalData only has 7 fields on R, not 8.

Bug: 177290955
Change-Id: I156738d07821fee43420d8af14c4bce36dd0e4a4
Test: atest CtsNetTestCasesLatestSdk:CaptivePortalDataTest on R
2021-01-19 02:33:09 +00:00
Lorenzo Colitti
c5ba160582 Address comments on aosp/1539753, aosp/1542487 and aosp/1547496.
Bug: 173331190
Test: test-only change
Change-Id: I475502fde55d24e7ae3f7fe9f43c54740c57a9cf
2021-01-19 10:35:43 +09:00
Junyu Lai
f5fdc60511 Merge "[VCN06] Support request background network" 2021-01-19 01:04:20 +00:00
Lorenzo Colitti
24c152ce87 Fix propagating underlying caps when a network disconnects.
aosp/1513052, which generalized support for underlying networks,
broke default network switching when the network underlying a VPN
disconnects.

This is because it calls propagateUnderlyingNetworkCapabilities
in the middle of the bookkeeping operations needed when a
network is disconnected (specifically, after all satisified
requests are removed from the disconnecting network, but before
mDefaultNetworkNai is updated). This is completely incorrect
because propagateUnderlyingNetworkCapabilities can trigger a
network rematch, and running a rematch when the request data
structures are inconsistent is obviously wrong. See the test
changes in this CL for an example of the damage.

Fix this by moving propagateUnderlyingNetworkCapabilities to
before the bookeeping operations begin. It must be before
mDefaultNetworkNai is updated, because otherwise it will not know
that the default network is disconnecting, and it will not be
able to propagate capabilities to VPNs that set underlying
networks to null (i.e., to the default network). It must be
after the nai is removed from mNetworkForNetId because
otherwise it will think that the underlying network is still
connected.

Bug: 173331190
Test: accompanying unit test shows lots of bugs removed
Change-Id: Ibf376a6fa4b34d1c96f8506fa8abbb7595a8c272
2021-01-19 09:40:53 +09:00
Lorenzo Colitti
b291ab6435 Test for bugs with suspended VPN underlying networks.
Test: atest --rerun-until-failure 100 ConnectivityServiceTest#testVpnSwitchFromSuspendedToNonSuspended
Change-Id: Ia52f9cafef3f49ae70ad135d017e207eb57fddfe
2021-01-19 00:42:46 +09:00
Lorenzo Colitti
c6244c74ad Merge changes Ic5750d4f,I9fa888c9,I4211475f
* changes:
  Deflake testNetworkBlockedStatusAlwaysOnVpn
  Simplify testVpnRestrictedUsers.
  Add test coverage for LockdownVpnTracker.
2021-01-18 14:03:54 +00:00
Treehugger Robot
b54fb4d4fd Merge "Enforce that NetworkAgentInfo fields are never null." 2021-01-18 09:32:39 +00:00
junyulai
75daea17c8 [VCN06] Support request background network
This will be mainly used by VCN management service which will
need to hold the networks but preserve the backgrounded-ness
of the networks.

Test: android.net.ConnectivityManagerTest#testRequestType
Test: android.net.cts.ConnectivityManagerTest#testRequestBackgroundNetwork /
      --rerun-until-failure 100
Test: ConnectivityServiceTest#testBackgroundNetworks
Test: m -j doc-comment-check-docs
Bug: 175662146
Change-Id: If9aaa87b7e71c2b695ac7b08858850e975b28bb6
2021-01-18 16:32:08 +08:00
Lorenzo Colitti
081a3a49e1 Deflake testNetworkBlockedStatusAlwaysOnVpn
This test flakes about 1% of the time on my device. This is due
to the test calling expectNetworkRejectNonSecureVpn() before the
handler thread has processed the call to setAlwaysOnVpnPackage.

Fix this by waiting for callbacks where it is possible to do so,
and by calling waitForIdle where it is not.

Test: test-only change
Change-Id: Ic5750d4fdf9e7e3654a2b6ade74da6bc5de18fb6
2021-01-18 17:28:52 +09:00
Lorenzo Colitti
3d37d92c09 Simplify testVpnRestrictedUsers.
Code review comments have suggested that this test is too long
and difficult to understand. Split it into two tests and put some
of the common setup into setup methods and statics.

Bug: 173331190
Test: test-only change
Change-Id: I9fa888c940d7048f1ba6836a5706fbdb84b5f5c9
2021-01-18 17:28:52 +09:00
Lorenzo Colitti
b7c3097f3f Add test coverage for LockdownVpnTracker.
Also add a comment to an existing test.

Bug: 173331190
Test: test-only change
Change-Id: I4211475f053f0cdf2b804132c52ce5205a772193
2021-01-18 17:28:50 +09:00
Lorenzo Colitti
bb4d45fb70 Enforce that NetworkAgentInfo fields are never null.
These fields have been recently audited, confirmed never to be
null, and annotated @NonNull. Ensure that they can never become
null by throwing exceptions in the codepaths that set them.
Also remove some null checks.

Test: atest FrameworksNetTests
Change-Id: I6ce5bb4d69a990f1c857c599b7e50e372352eb87
2021-01-18 07:49:26 +00:00
Lorenzo Colitti
ac155fc61e Merge "Mark several NetworkAgentInfo members @NonNull and address TODO." 2021-01-18 05:51:38 +00:00
Paul Hu
bab9a4577c Merge "Remove unused IpConnectivityMetrics in CS" 2021-01-18 05:26:35 +00:00
paulhu
caa2c0dabe Remove unused IpConnectivityMetrics in CS
ConnectivityService doesn't call any IpConnectivityMetrics
methods, so remove all usages from CS.

Bug: 177656797
Test: atest FrameworksNetTests
Test: atest FrameworksNetIntegrationTests
Change-Id: I2fb3b6b08cd8013eb8f75882f77ca699a2df927e
2021-01-18 04:03:32 +00:00
Chiachang Wang
b1a007e35c Merge "Replace hidden ParcelFileDescriptor constructor usage" 2021-01-18 01:59:10 +00:00
Chiachang Wang
619319a3f5 Replace hidden ParcelFileDescriptor constructor usage
If IOException happens while trying to start keepalives sockets,
an invalid fd will be constructed. It will fail with
ERROR_INVALID_SOCKET if the user later calls start(). Current
design to construct the invalid fd use the hidden
ParcelFileDescriptor constructor which will not work for the
incoming ConnectivityService mainline. Thus, replace it with
the other formal API.

Bug: 170598012
Test: atest FrameworksNetTests
Change-Id: I57fd7ec2281c5e8c75481200bbde723ecf96982a
2021-01-18 01:58:49 +00:00
Roshan Pius
67c62a89d9 Merge "LocationPermissionChecker: Exempt privileged components from location check" 2021-01-18 01:33:31 +00:00
paulhu
e2664cb6ce Replace Context#sendStickyBroadcastAsUser()
ConnectivityService is using Context#sendStickyBroadcastAsUser
to send sticky broadcast but this API is not able to call after
it becomes part of Connectivity mainline module. Thus, replace it
with Context#sendStickyBroadcast.

Bug: 177223402
Test: atest FrameworksNetTests
Test: atest CtsNetTestCases
Test: atest CtsNetApi23TestCases
Change-Id: I55156aeaf9baa9f2fd41853375edf87994789b81
2021-01-18 00:10:50 +08:00
Junyu Lai
9ca2f62117 Merge "[VCN05.1] Add unit test for invalid request types" 2021-01-16 02:27:28 +00:00
Serik Beketayev
0513030fcd [Mainline] Migrate com.google.android.collect pkg
Bug: 177698384
Test: mma
Change-Id: Ic86645f7a263a37c33443e5ec7d60961909f2cd2
2021-01-15 16:47:25 -08:00
Lorenzo Colitti
59fa1276a7 Mark several NetworkAgentInfo members @NonNull and address TODO.
1. network cannot be null because it's final and the only caller
   of the constructor passes in a fresh copy.
2. linkProperties cannot be null because:
   - The only caller of the constructor passes in a fresh copy.
   - The only assignment to nai.linkProperties is in
     updateLinkProperties, and that dereferences newLp a few
     lines before assigning it.
3. networkCapabilities cannot be null because:
   - The only caller of the constructor passes in a fresh copy.
   - There are no direct assignments to nai.networkCapabilities.
   - All 4 assignments happen via getAndSetNetworkCapabilities:
     - registerNetworkAgentInternal, updateCapabilities and
       applyBackgroundChangeForRematch all pass in the return
       value of mixInCapabilities, which is always non-null.
     - updateNetworkInfo re-assigns the capabilities that were
       already set in the object.
4. networkAgentConfig cannot be null because it's final and
   the only caller of the NetworkAgentInfo constructor passes
   in a fresh copy.

Address a TODO in ConnectivityService to remove a check for the
nai's capabilities being null.

Also fix a style nit pointed out by the linter.

Test: atest FrameworksNetTests
Change-Id: I2e265f1c60a73d6da0222dd6711bc53c32db06ec
2021-01-16 00:56:44 +09:00
Roshan Pius
c68c03ced4 LocationPermissionChecker: Exempt privileged components from location check
This is a port of the exemption that exists in WifiPermissionsUtil.
Settings, sysui, network stack needs to be able to access all network
state regardless of location toggle. If we want to move sysui, etc to
retrieve WifiInfo via NetworkCapabilities (which is the current plan),
this exemption is essential since UI should reflect wifi state
regardless of location toggle state.

Bug: 162602799
Test: atest LocationPermissionCheckerTest
Change-Id: I49ce465eccce27bb7a860d882360436fd9ec19c6
2021-01-15 06:51:39 -08:00
junyulai
7c51b4b463 [VCN05.1] Add unit test for invalid request types
Test: atest ConnectivityServiceTest#testInvalidRequestTypes
Bug: 175662146
Change-Id: I595b0bd1cfb88724581f67942cd3891f95c157ab
2021-01-15 21:19:49 +08:00
Aaron Huang
1000c8138f Merge "Refactor setCurrentProxyScriptUrl to a void method" 2021-01-15 10:01:10 +00:00
Treehugger Robot
6516373759 Merge "Fix CaptivePortalDataTest on R-" 2021-01-15 05:26:34 +00:00
Remi NGUYEN VAN
a82274021d Fix CaptivePortalDataTest on R-
The new venue friendly name field is not present on R-

Bug: 162783305
Change-Id: I63bd9c61d27c7d3b07826053373c9c5e38666948
Test: atest FrameworksNetTests
2021-01-15 01:13:27 +00:00
James Mattis
ef4488fb0d Merge "Waiting for idle in test" 2021-01-15 00:28:54 +00:00
Roshan Pius
d0cb8f3ec3 Merge "NetworkCapabilities: Embed location senstive TransportInfo" 2021-01-14 15:38:15 +00:00
Lorenzo Colitti
5da00cfb62 Merge changes I28e39400,Ibada8b42
* changes:
  UserManager restricted profile SystemApis
  Improve testing of CONNECTIVITY_ACTION broadcasts.
2021-01-14 10:39:48 +00:00