Commit Graph

1750 Commits

Author SHA1 Message Date
Chalard Jean
c9077f2a38 Add a test for starting the legacy VPN.
The legacy VPN has, among many parameters, a host to connect to.
This host can be specified as a numeric address, or as a hostname.
When it's a name, resolution is required. Currently, name
resolution is performed by the native VPN daemons racoon and
mtpd. When a hostname is used, the framework does not know the
IP address of the VPN server and does not add a throw route for
the VPN server IP address. On older kernels this does not matter
because the legacy PPP kernel code binds the PPP socket to the
right network, but on newer devices that use the upstream PPP
code, this does not work. See b/133797637.

This patch instruments the legacy VPN code so that it can be
run in tests, and uses this instrumentation to simulate passing
a configuration that contains a host, and verifies that the
arguments passed to the mptd and racoon daemons receive the
expected server address, and that the expected throw route is
correctly installed.
It then adds two tests : one specifying the server as a numeric
address, and one as a hostname. As the resolution is currently
broken, the latter of these tests is added disabled, and the
followup fix to the issue enables it.

This test is basic and very targeted, but it's what we need right
now. Also there are plans to remove this entire code path in S, so
the test being ad-hoc is not much of a problem.

Test: this
Bug: 158974172
Change-Id: I420b63db03a58e8c67a98a85c9f4c2d6ed7ad078
(cherry picked from commit 45846a03051a13d667732288e457eab4336a691e)
2020-08-06 17:16:00 +09:00
Paul Hu
2933a04749 Merge "[RFPM04] Adjust hasRestrictedNetworkPermission method" 2020-08-03 10:37:52 +00:00
Peter Wang
c80aabbd2e Merge "[Telephony Mainline] Rename getActiveAndHiddenSubscriptionIdList and guard with permission" 2020-07-31 08:43:44 +00:00
Chalard Jean
3b7591e1f5 Move utils from network stack to libs.
This package is using some common utilities from
a library that used to live in the network stack.
A better home for these utilities is frameworks/libs,
so this topic moves the files ther and also changes
the package of some utilities.

See aosp/1350222 and aosp/1350182 for a detailed
description of the specific files that moved.

Test: checkbuild
Change-Id: I76a9b7790f3997e3e6b3c2f75ba6308286457cde
2020-07-29 21:15:48 +09:00
paulhu
de5b46c10b [RFPM04] Adjust hasRestrictedNetworkPermission method
There are two parts in hasRestrictedNetworkPermission method.
One is carryover package check and one is uid permission
check. Seperate carryover package check part to another method
to be clearer the usage of hasRestrictedNetworkPermission method.

Bug: 132784544
Test: atest FrameworksNetTests
Change-Id: Iab0609fcaa52acb0dfcb31ca957f22bfe8d62392
2020-07-29 14:14:27 +08:00
Paul Hu
563de5b8c7 Merge "[RFPM03] Check permission by uid." 2020-07-29 05:41:32 +00:00
Junyu Lai
cdb1f03144 Merge "Gracefully handle integer overflows." 2020-07-29 01:19:07 +00:00
Chiachang Wang
f702025bdf Merge "Update language to comply with Android's inclusive language guidance" 2020-07-28 10:51:53 +00:00
paulhu
8adb39a688 [RFPM03] Check permission by uid.
PermissionMonitor check permission by each package name but only
update the uid permission to netd. It's better to check
permission by uid directly. Thus, use
ActivityManager#checkUidPermission to check permissions for each
uid.

Bug: 132784544
Test: atest FrameworksNetTests
Change-Id: I057d34383b4dc408b2773e4c6b146774ba0c5eb2
2020-07-28 18:23:38 +08:00
Chiachang Wang
3b9549f408 Update language to comply with Android's inclusive language guidance
See https://source.android.com/setup/contribute/respectful-code
for reference.

Bug: 161896447
Test: m
Change-Id: I6c3c03c0c2d1302af6d5245486823c13a3432900
2020-07-28 15:36:30 +08:00
Pavan Kumar M
e55ab87e5d Gracefully handle integer overflows.
Avoid recording negative data by doing integer-based
math as much as possible, but switch to double-based
math if we detect that we'd end up causing an overflow.

Test :

    - Builds, Boots
    - High data throughput scenarios
    - NetworkStatsHistoryTest, NetworkStatsCollectionTest,
      NetworkStatsTest

Bug: 119527458
Change-Id: I55d4aa649bea3ae201ad513074ff2b71cb918dad
2020-07-28 11:36:49 +05:30
Treehugger Robot
dc4c9d51a1 Merge "Attribute data usage to virtual RAT type for 5G non-standalone mode" am: 0ac564e673 am: 0c55907a0a
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1364497

Change-Id: Idef0dd6e0e0486b76c0067540e580d444e97d6a0
2020-07-16 12:09:04 +00:00
junyulai
c3e3a1d0ef Attribute data usage to virtual RAT type for 5G non-standalone mode
Test: atest NetworkStatsSubscriptionsMonitorTest#test5g
Bug: 160727498
Change-Id: I8753e68140c0993773017c9a49bd8a666a364071
Merged-In: I8753e68140c0993773017c9a49bd8a666a364071
(cherry-picked from ag/12167624)
2020-07-16 18:22:09 +08:00
Peter Wang
1041764067 [Telephony Mainline] Rename getActiveAndHiddenSubscriptionIdList and
guard with permission

Bug: 150878235
Fix: 150878235
Test: Build
Change-Id: I7f3b1f5170e032336d9b39b322c49e2b92573586
Merged-In: I7f3b1f5170e032336d9b39b322c49e2b92573586
2020-07-16 02:01:06 -07:00
Treehugger Robot
a3d509537c Merge "Revert "Attribute data usage to 5G for 5G non-standalone mode"" am: 13c5ee8313 am: ce769a0d8e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1360157

Change-Id: If052329128326fba72ff27c024a2c6652b7bb1ef
2020-07-10 05:41:05 +00:00
Junyu Lai
43b3142dc3 Revert "Attribute data usage to 5G for 5G non-standalone mode"
This reverts commit dc31686c31.

Reason for revert: Revert and wait for the design is settled down.

Change-Id: I10fdfc37d6456678de1886698cd6ad08bf8aa810
2020-07-10 03:43:19 +00:00
Junyu Lai
7249a46c8e Merge "Attribute data usage to 5G for 5G non-standalone mode" am: c987a53a93 am: 214280263e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1359203

Change-Id: I860b0226157ee31f0488d6b2252ae157e86dc5eb
2020-07-10 03:10:15 +00:00
junyulai
dc31686c31 Attribute data usage to 5G for 5G non-standalone mode
Test: atest NetworkStatsSubscriptionsMonitorTest#test5g
Bug: 160727498

Change-Id: I563df14500caeb3602b381479afaf5163ad8e6a1
2020-07-09 16:56:54 +08:00
Paul Hu
99670e6e0c Merge "[RFPM02] Add Dependencies class for injection in tests." am: 27cba24934 am: 9778855eb6
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1318291

Change-Id: If53e1521327c8d9f1fd2a5debb94c58ed25b2880
2020-07-08 10:35:21 +00:00
paulhu
a1a8814b82 [RFPM02] Add Dependencies class for injection in tests.
Add Dependencies class in PermissionMonitor for injection
in tests easily.

Bug: 132784544
Test: atests FrameworksNetTests
Change-Id: Ibb84d548908f7a955fa0ff206794486733259978
2020-07-08 15:30:42 +08:00
Chalard Jean
aa02f30a39 Merge "Revert "Test IPv6ProvisioningLossParcelable in the NetworkAttrib..."" am: 8ec089e59a am: 007c9dd007
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1353491

Change-Id: Ibc8d633a6e04f7cd0f4c1a0d02ae586232cc0c6a
2020-07-01 05:33:41 +00:00
Chalard Jean
f90e5bcc2a Revert "Test IPv6ProvisioningLossParcelable in the NetworkAttrib..."
Revert "Add new network quirk parcelable in the NetworkAttributes."

Revert submission 1323251-ipv6_prov_loss_quirk_parcelable

Reason for revert: Breaks CtsStrictJavaPackagesTestCases
Reverted Changes:
I18e05c09f:Add new network quirk parcelable in the NetworkAtt...
I8dbff2377:Test IPv6ProvisioningLossParcelable in the Network...

Change-Id: Ie906919b344131cd768fbed787248d3caac2f74d
2020-07-01 01:46:26 +00:00
Xiao Ma
ec4d808567 Merge "Test IPv6ProvisioningLossParcelable in the NetworkAttributes." am: 111123c560 am: 22c1b251b6
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1322637

Change-Id: Iaf964024c44e6b78ccb3b8fcf3fc131479747a81
2020-06-29 12:17:26 +00:00
Paul Hu
de2cdb300b Merge "[RFPM01] Merge package added/removed methods" am: 6287112701 am: b67261dcc9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1317236

Change-Id: Ida8f82d2ec5be1040a2bdf2aa65a94d53f68ea6c
2020-06-29 12:16:47 +00:00
Xiao Ma
0c140bf1ec Test IPv6ProvisioningLossParcelable in the NetworkAttributes.
Bug: 157534516
Test: atest FrameworksNetTests
Change-Id: I8dbff2377457bb8fd0f447be0a3cda9af952f2a2
2020-06-29 11:57:32 +00:00
Paul Hu
6287112701 Merge "[RFPM01] Merge package added/removed methods" 2020-06-29 11:50:57 +00:00
Luke Huang
caaee1d0ec Disable sockets and DNS if process lacks INTERNET permission.
This is a Client-only solution.
  - Add to NetdClient a per-process std::atomic_boolean
    similar to netIdForProcess and netIdForResolv.
  - The boolean says whether the process should be
    allowed Internet connectivity.
  - Add an @hide method to NetUtils.java to set the boolean;
    call it from the initialization code of the new
    process just after forking from zygote.
  - Make netdClientSocket and dnsOpenProxy check the
    boolean. If the boolean is false, return EPERM from
    socket calls.

Bug: 150028556
Test: atest NetworkUtilsTest
Test: atest CtsAppSecurityHostTestCases:UseProcessTest
(cherry-pick from internal branch, ag/11881939)
Merged-In: If002280fbad493dfc2db3d9d505c0257d49a9056
Change-Id: If002280fbad493dfc2db3d9d505c0257d49a9056
2020-06-24 11:58:57 +00:00
paulhu
aa4620914e [RFPM01] Merge package added/removed methods
There are two methods to handle package added/removed from
two differnt listeners. It can use one of listener to handle the
changes. Thus, keep PackageManagerInternal#PackageListObserver
but remove the listening from ConnectivityService.

Bug: 132784544
Test: atests FrameworksNetTests
Change-Id: Ib2db85e4108f9fda731bf6667d0af0610fc79fea
2020-06-23 16:10:03 +08:00
TreeHugger Robot
844bba26ba Merge "Update DnsManagerTest for AIDL interface change" into rvc-dev am: 6ef23fb8f3
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11954238

Change-Id: I1327794e6b8201d3c47c39838cfa516812cf273d
2020-06-22 15:18:45 +00:00
Ken Chen
fc7dd4c35e Update DnsManagerTest for AIDL interface change
Check one more parameter enforceDnsUid in ResolverOptionsParcel in
DnsManagerTest.

Bug: 159587277
Test: atest
com.android.server.connectivity.DnsManagerTest#testSendDnsConfiguration

Change-Id: Ic53f42b968626294c851dac252a70769846ba427
Merged-In: Ic53f42b968626294c851dac252a70769846ba427
2020-06-22 15:10:12 +00:00
TreeHugger Robot
6ef23fb8f3 Merge "Update DnsManagerTest for AIDL interface change" into rvc-dev 2020-06-22 15:09:54 +00:00
Ken Chen
8fb860bfe1 Update DnsManagerTest for AIDL interface change
Check one more parameter enforceDnsUid in ResolverOptionsParcel in
DnsManagerTest.

Bug: 159587277
Test: atest
com.android.server.connectivity.DnsManagerTest#testSendDnsConfiguration

Change-Id: Ic53f42b968626294c851dac252a70769846ba427
2020-06-22 21:44:07 +08:00
Mike Yu
b6b7e0c2be Support DNS-over-TLS probes in NetworkDiagnostics
Probe DNS servers to see they support DNS-over-TLS. Use system
CAs to verify whether the certificates sent by DNS servers are
trusted or not. An error is thrown to cause the probe failed if
DNS servers send untrusted certificates.

Unlike the DnsResolver which doesn't verify the certificates
in opportunistic mode, all of the DoT probes from NetworkDiagnostics
check certificates.

DoT probes apply to the DNS servers gotten from LinkProperties
and the DoT servers gotten from PrivateDnsConfig whatever private
DNS mode is.

A common example in DNS strict mode:
.  DNS TLS dst{8.8.8.8} hostname{dns.google} src{192.168.43.2:48436} qtype{1} qname{815149-android-ds.metric.gstatic.com}: SUCCEEDED: 1/1 NOERROR (432ms)
F  DNS TLS dst{192.168.43.144} hostname{}: FAILED: java.net.ConnectException: failed to connect to /192.168.43.144 (port 853) from /192.168.43.2 (port 41770) after 2500ms: isConnected failed: ECONNREFUSED (Connection refused) (172ms)
.  DNS TLS dst{8.8.4.4} hostname{dns.google} src{192.168.43.2:37598} qtype{1} qname{759312-android-ds.metric.gstatic.com}: SUCCEEDED: 1/1 NOERROR (427ms)

An example when the CA is not trusted:
F  DNS TLS dst{8.8.8.8} hostname{dns.google}: FAILED: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. (16ms)

An example when TCP/TLS handshake timeout:
F  DNS TLS dst{8.8.8.8} hostname{dns.google}: FAILED: java.net.SocketTimeoutException: failed to connect to /8.8.8.8 (port 853) from /192.168.2.108 (port 45680) after 2500ms (2514ms)

Bug: 132925257
Bug: 118369977
Test: atest FrameworksNetTests
Original-Change: https://android-review.googlesource.com/1011670
Merged-In: I1b54abed0e931ca4b8a97149459cde54da1c3d6f
Change-Id: I1b54abed0e931ca4b8a97149459cde54da1c3d6f
2020-06-22 08:57:49 +00:00
Mike Yu
3efb6bd1ec Merge "Support DNS-over-TLS probes in NetworkDiagnostics" am: 64ffa1762f am: 4e04c11379
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1011670

Change-Id: I25a06623d87e6971a9dac73bdea82a78fd6124d6
2020-06-22 06:56:39 +00:00
Mike Yu
6cad4b10db Support DNS-over-TLS probes in NetworkDiagnostics
Probe DNS servers to see they support DNS-over-TLS. Use system
CAs to verify whether the certificates sent by DNS servers are
trusted or not. An error is thrown to cause the probe failed if
DNS servers send untrusted certificates.

Unlike the DnsResolver which doesn't verify the certificates
in opportunistic mode, all of the DoT probes from NetworkDiagnostics
check certificates.

DoT probes apply to the DNS servers gotten from LinkProperties
and the DoT servers gotten from PrivateDnsConfig whatever private
DNS mode is.

A common example in DNS strict mode:
.  DNS TLS dst{8.8.8.8} hostname{dns.google} src{192.168.43.2:48436} qtype{1} qname{815149-android-ds.metric.gstatic.com}: SUCCEEDED: 1/1 NOERROR (432ms)
F  DNS TLS dst{192.168.43.144} hostname{}: FAILED: java.net.ConnectException: failed to connect to /192.168.43.144 (port 853) from /192.168.43.2 (port 41770) after 2500ms: isConnected failed: ECONNREFUSED (Connection refused) (172ms)
.  DNS TLS dst{8.8.4.4} hostname{dns.google} src{192.168.43.2:37598} qtype{1} qname{759312-android-ds.metric.gstatic.com}: SUCCEEDED: 1/1 NOERROR (427ms)

An example when the CA is not trusted:
F  DNS TLS dst{8.8.8.8} hostname{dns.google}: FAILED: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. (16ms)

An example when TCP/TLS handshake timeout:
F  DNS TLS dst{8.8.8.8} hostname{dns.google}: FAILED: java.net.SocketTimeoutException: failed to connect to /8.8.8.8 (port 853) from /192.168.2.108 (port 45680) after 2500ms (2514ms)

Bug: 132925257
Bug: 118369977
Test: atest FrameworksNetTests
Change-Id: I1b54abed0e931ca4b8a97149459cde54da1c3d6f
2020-06-20 16:22:35 +08:00
Aaron Huang
69b06f9369 Merge "Address comments from aosp/1298476" am: 48fbda02b0 am: 76d4f3513f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1340040

Change-Id: I7b119758ac7cd65defdec77692957287af17566d
2020-06-18 10:47:47 +00:00
Aaron Huang
69bfb5afea Address comments from aosp/1298476
This patch addresses the followings,
- Pass Looper to NetworkStatsSubscriptionsMonitor constructor
- Replace Looper with TestLooper in unit test
- Assert fail if result of condition check is not expected.

Bug: 154080205
Test: atest FrameworksNetTests:com.android.server.net.NetworkStatsServiceTest
      atest FrameworksNetTests:com.android.server.net.NetworkStatsSubscriptionsMonitorTest
Change-Id: Ibcaba2b38af80cc0ec9a4e428a3b3a1538bc4325
2020-06-18 15:05:19 +08:00
Aaron Huang
c98228cf54 Merge "Dynamically enable/disable watch for RAT type changes" am: 3fdad73a32 am: cc1d6b13d6
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1315574

Change-Id: I5a96774ad2104a6b03c9abab2b105b97195edea8
2020-06-18 04:22:21 +00:00
Aaron Huang
3fdad73a32 Merge "Dynamically enable/disable watch for RAT type changes" 2020-06-18 03:51:51 +00:00
Luke Huang
f12eff79db Merge "Disable sockets and DNS if process lacks INTERNET permission." into rvc-dev am: bbcd3b326b
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11881939

Change-Id: I7c285a848ac947e0acf1acc8bc32f3ece3456412
2020-06-18 03:23:46 +00:00
Luke Huang
5a42a4132f Disable sockets and DNS if process lacks INTERNET permission.
This is a Client-only solution.
  - Add to NetdClient a per-process std::atomic_boolean
    similar to netIdForProcess and netIdForResolv.
  - The boolean says whether the process should be
    allowed Internet connectivity.
  - Add an @hide method to NetUtils.java to set the boolean;
    call it from the initialization code of the new
    process just after forking from zygote.
  - Make netdClientSocket and dnsOpenProxy check the
    boolean. If the boolean is false, return EPERM from
    socket calls.

Bug: 150028556
Test: atest NetworkUtilsTest
Test: atest CtsAppSecurityHostTestCases:UseProcessTest
Change-Id: If002280fbad493dfc2db3d9d505c0257d49a9056
Exempt-From-Owner-Approval: OWNERS already approved identical patchset 5
2020-06-18 03:02:06 +00:00
Aaron Huang
0543f2328d Merge "Add unit test for NetworkStatsSubscriptionsMonitor" 2020-06-17 08:52:20 +00:00
Aaron Huang
7558938ce9 Dynamically enable/disable watch for RAT type changes
Add ContentObserver to observe the status of
NETSTATS_COMBINE_SUBTYPE_ENABLED to determine that
NetworkStatsSubscriptionsMonitor start or stop
monitoring data usage per RAT type changes.

Bug: 154080515
Test: atest NetworkStatsServiceTest#testDynamicWatchForNetworkRatTypeChanges
Change-Id: I272d589633c9186b45753228b05aa0b40b7c7b89
2020-06-17 17:09:10 +09:00
Chiachang Wang
1182d5a7fc Test extra info sent to NetworkMonitor
Test extra info sent to NetworkMonitor correctly if network
agent is created through new NetworkAgent constructor without
legacy network info taken as parameter.

Bug: 156173829
Test: atest FrameworkNetTests
Merged-In: I4f827664c528bea30cc957a0a617dd37693f4460
Change-Id: I4f827664c528bea30cc957a0a617dd37693f4460
2020-06-16 01:57:46 +00:00
Chiachang Wang
41b5925f01 Merge "Test extra info sent to NetworkMonitor" am: 9792742ee0 am: 26cd395a9e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1331060

Change-Id: Ice048df853589411ee1f1c935b929994af1c525b
2020-06-16 01:02:52 +00:00
Aaron Huang
b0e7dca43e Add unit test for NetworkStatsSubscriptionsMonitor
Bug: 154080205
Test: atest FrameworksNetTests:com.android.server.net.NetworkStatsSubscriptionsMonitorTest
(copy from ag/11788484 but getActiveAndHiddenSubscriptionIdList() since it's renamed
in internal)
Change-Id: Ia162f36efe96d90b2f6f70190d9fa855bba34484
Merged-In: I4ef3f1ab2e5ea1322133edd80db3ccd0022e9c91
2020-06-15 07:05:19 +00:00
Chiachang Wang
301bc7b40a Test extra info sent to NetworkMonitor
Test extra info sent to NetworkMonitor correctly if network
agent is created through new NetworkAgent constructor without
legacy network info taken as parameter.

Bug: 156173829
Test: atest FrameworkNetTests
Change-Id: I4f827664c528bea30cc957a0a617dd37693f4460
2020-06-12 18:13:00 +08:00
Aaron Huang
65556318aa Merge "Add unit test for NetworkStatsSubscriptionsMonitor" into rvc-dev am: 70afc75769
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11788484

Change-Id: Iac633487b359d751206e06b2352a2a9cb475811e
2020-06-12 02:11:29 +00:00
Aaron Huang
a8eab54eee Add unit test for NetworkStatsSubscriptionsMonitor
Bug: 154080205
Test: atest FrameworksNetTests:com.android.server.net.NetworkStatsSubscriptionsMonitorTest
Change-Id: I4ef3f1ab2e5ea1322133edd80db3ccd0022e9c91
2020-06-09 00:40:36 +08:00
Benedict Wong
f4a72ac0ff Merge "Add RequiresFeature annotations for IKEv2 VPN profiles" into rvc-dev am: 36d9c275ac
Change-Id: Ibc0f236234cd87d50a393c3dfaca7898b04e7432
2020-05-29 17:32:42 +00:00