Commit Graph

10931 Commits

Author SHA1 Message Date
Benedict Wong
f3215117bc Expose MIN_MTU_V6 as a public, @hide constant
MIN_MTU_V6 is increasingly used, and the LinkProperties version is used
as a source of truth for the constant.

Bug: 163602123
Test: atest FrameworksNetTests
Change-Id: I67134cd4fb7e2cf59c36947b62f681ac9b94ea4a
2020-11-19 00:21:53 -08:00
lucaslin
5d358df3c7 Remove a comment from ConnectivityService
This comment is not true anymore since NetworkMonitor is not only
verifying the default network but also verifying VPN when private
DNS is enabled.

Test: Build pass.
Change-Id: Ib975aa28c84b9974a73d1baca9d5185c01b71217
2020-11-19 16:19:10 +08:00
Lorenzo Colitti
4489abdb15 Make MockVpn more realistic and easier to use.
MockVpn is very difficult to use because it requires the test
caller keeping track of both the MockVpn object and an
accompanying TestNetworkAgentWrapper.

It's also not very realistic: for example, connect() doesn't
actually connect anything, it just makes it so that if
ConnectivityService tries to update the capabilities, the attempt
will not be ignored. Also, unlike the real code in Vpn, it
connects with empty NetworkCapabilities (in particular, with
empty UID ranges).

Make this easier to use and a bit more realistic by:
- Allowing TestNetworkAgentWrapper to take a "NetworkCapabilities
  template" that will form the initial capabilities sent when the
  agent registers with ConnectivityService. This allows the VPN
  to register its agent with its UID ranges already set, like the
  production code does.
- Providing separate methods to register the NetworkAgent and
  mark it connected for cases where the test needs to make
  changes to the NetworkAgent before connecting (e.g., poking
  NetworkMonitor).
- Putting the TestNetworkAgentWrapper inside MockVpn and driving
  it through MockVpn's methods. In order not to have too many
  wrapper functions (and because we can't delegate like in
  Kotlin), there's still an agent() method that returns the
  TestNetworkAgentWrapper.

Bug: 173331190
Test: test-only change
Change-Id: I749ff325bc13ac96f512270b86d1f67686eec378
2020-11-19 16:23:07 +09:00
Lorenzo Colitti
e42d10a803 Increase test coverage for VPN info sent to NetworkStatsService.
Bug: 173331190
Test: test-only change
Change-Id: I3711b362f31cb92b759e9f5c9d244fb88d9bd5e7
2020-11-19 14:56:50 +09:00
Lorenzo Colitti
3581b34f69 Simplify MockVpn.
This CL removes four methods in MockVpn by slightly changing the
test code to leverage the actual methods implemented by the
(production) Vpn superclass.

This works because setting mInterface results in
isRunningLocked() returning true, which makes a number of methods
behave as if the VPN is connected (which is what the test
expects).

The more realistic behaviour exposes a minor bug in the treatment
of underlying networks. Add a TODO to fix it.

Bug: 173331190
Test: test-only change
Change-Id: I49421183538ba61ca790af71e309ece36b653bf9
2020-11-19 14:53:53 +09:00
Lorenzo Colitti
d00e0b8757 Test a VPN with an underlying network that does not yet exist.
This test checks that if a VPN declares an underlying network
that does not exist, the capabilities of that network are applied
to the VPN as soon as the network starts to exist.

Bug: 173331190
Test: test-only change
Change-Id: Icc0701cb4cea7d91f7738c1e426e94cd26686b74
2020-11-19 14:46:32 +09:00
Chiachang Wang
62740141dc Move BasicShellCommandHandler to frameworks/lib/modules-utils
BasicShellCommandHandler is used by mainline modules and the
framwork. There is a new repo that was created for putting
this kind of utility class. Move BasicShellCommandHandler for
the incoming ConnectivityService mainline and updating the
related usage.

Bug: 170598012
Test: m ; verify with adb shell cmd
Change-Id: I8a2873df6e7d8342b7a8b466bda155f74c807ee3
Merged-In: Ida30c877116090616d4bf3f87fdad835446dac84
2020-11-19 03:16:03 +00:00
Chiachang Wang
b823971656 Merge "Replace InterfaceConfiguration usage with stable aidl" 2020-11-18 09:05:59 +00:00
Lorenzo Colitti
1ea1cda675 Minor fixes to NetworkCapabilities#toString.
1. The current code only prints the array of administrator UIDs
   if it's empty. This is clearly an oversight. Print it only if
   it's non-empty.
2. Only print requestor UID and package name if they are set.
   This makes output shorter in the common case that they are
   unset.
3. Reorder the output at the end: group all UIDs together, and
   place SSID and private DNS broken bit after that.
4. Make the private DNS broken indication a single word instead
   of a sentence. This saves space and makes it easier to write
   regexps.

New format:
... SignalStrength: -72 OwnerUid: 1000 AdminUids: [1000] SSID: ...
... Uid: 1000 RequestorUid: 1000 RequestorPkg: android ...

Test: manual
Change-Id: I2f5ccc1d9e4af6ddacc4d193185a17723822972b
2020-11-18 17:10:11 +09:00
Chiachang Wang
49ffc814eb Replace InterfaceConfiguration usage with stable aidl
Replace InterfaceConfiguration with InterfaceConfigurationParcel
for the incoming ConnectivityService mainline since mainline
modules could not use @hide API.

Bug: 170598012
Test: atest FrameworksNetTests
Change-Id: I17ce8741e985fd30e3c8f0c34e79564a82890dc6
2020-11-18 14:46:13 +08:00
Lucas Lin
459ad2aa4b Merge "Separate 2 tests to verify canBeSatisfiedBy()" 2020-11-17 08:38:07 +00:00
Lucas Lin
90a764cd5b Merge "Fix the comments left on aosp/1481197" 2020-11-17 07:06:46 +00:00
Junyu Lai
c6cd3d4f7b Merge changes I6a48d4db,I6741c41c,Ifec6bde5,Icd0717c5
* changes:
  Remove unused variables
  Return offloaded traffic when querying from TrafficStats API
  Add hardware tethering traffic in testTethering test
  Remove unused getTetherStats
2020-11-12 08:45:15 +00:00
junyulai
3c4242ca5e Add hardware tethering traffic in testTethering test
Test: atest com.android.server.net.NetworkStatsServiceTest#testTethering
Bug: 162292214
Change-Id: Ifec6bde5fd3231f2135f12536c42e42ec6b707de
2020-11-12 14:22:31 +08:00
lucaslin
20f7c6e60d Separate 2 tests to verify canBeSatisfiedBy()
In Android R, NetworkSpecifier#satisfiedBy() has changed to
NetworkSpecifier#canBeSatisfiedBy(), but its subclass -
MatchAllNetworkSpecifier hasn't.
In Android S, both of MatchAllNetworkSpecifier and
NetworkSpecifier has changed satisfiedBy() to canBeSatisfiedBy().
So if running the latest CTS on R device, it will verify
NetworkSpecifier#canBeSatisfiedBy() instead of
MatchAllNetworkSpecifier#satisfiedBy() and get the unexpected
result.
The fix is to separate 2 tests to verify canBeSatisfiedBy(), one
is for Android R or older version and the other is for Android
S+.

Bug: 172401624
Test: Run MatchAllNetworkSpecifierTest on Android R and S.
Change-Id: I1391bae9a0fc0298beb8fe80b5f388b492244566
2020-11-12 12:48:16 +08:00
Chiachang Wang
41da838f4d Merge "Replace the way to add legacy routing" 2020-11-11 05:06:58 +00:00
James Mattis
8806704457 Merge "Updating network preference comments" 2020-11-10 17:30:36 +00:00
lucaslin
64945ac754 Fix the comments left on aosp/1481197
Bug: 172040168
Test: atest FrameworksNetTests
Test: Manual test NO_INTERNET, SIGN_IN, PARTIAL_CONNECTIVITY,
      VPN_ALWAYS_ON notifications.
Change-Id: Ibd05366481e6ddadf8b323335c2c35d40d340d0d
2020-11-10 14:54:52 +08:00
Chiachang Wang
6f95279de6 Replace the way to add legacy routing
ConnectivityService is going to become a mainline module which
is not able to access hidden API. Thus, replace the usage from
NMS to INetd.

Bug: 170598012
Test: atest FrameworksNetTests ConnectivityManagerLegacyTest
Change-Id: Ice1bd1effab26555917bc1766354aeaebd41ad66
2020-11-10 14:53:55 +08:00
Lucas Lin
879f21b545 Merge changes I67e5fa23,I223b207c
* changes:
  Use hasIpv[4|6]DefaultRoute instead of hasIPv[4|6]DefaultRoute
  Use local defined constants for notification channels
2020-11-10 05:28:33 +00:00
James Mattis
82d1b93dfd Updating network preference comments
Updating comments for network preferences to better clarify that
preferences which include more than one network type will then rely on
scoring to determine which of those networks are chosen.

Bug: 171795464
Test: atest FrameworksNetTests
Change-Id: I9eb5683f2cd69281bbee9fb70028d45f07720914
2020-11-09 21:06:09 -08:00
Mathew Inwood
8b7da06e85 Merge "Add maxTargetSdk restriction to unused APIs." 2020-11-09 14:41:20 +00:00
junyulai
363c86274e Remove unused getTetherStats
Before Android R, getTetherStats were used to collect tethering
iface stats of all clients who extends ITetheringStatsProvider,
which typically contains NetdTetheringStatsProvider and
OffloadController.

However, this always returns 0 since Android R, because:
  1. OffloadController implemented NetworkStatsProvider and no
     longer reports stats through getTetherStats.
  2. NetdTetheringStatsProvider always return 0 by design since
     non-offloaded iface tethering stats are already included
     in native iface stats.

This change is a no-op refactoring to remove unused
getTetherStats and update test which is not pratical.
Fix for offloaded tethering stats will be in follow-up CLs.

Test: atest FrameworksNetTests TetheringTests
Bug: 162292214
Change-Id: Icd0717c5c2807ae3bd98626b897e4b148f142815
2020-11-06 19:02:44 +08:00
James Mattis
356a879404 Adding API stubs for application network routing
Bug: 171795464
Test: atest FrameworksNetTests
Change-Id: Ib055aa37a7bf0c48c335307afc2258aa869c4267
2020-11-06 00:08:13 -08:00
James Mattis
60b84b216b Adding multilayered requests to NetworkRequestInfo
Updating NetworkRequestInfo for "multilayered requests" functionality so that
requests can support a network hierarchy. I.e., requests network
with capability A first and if not available, request network with
capability B. This CL is the first step in adding that support by
updating the request object from a single request to a collection.

Bug: 171991028
Test: atest FrameworksNetTests
atest NetworkStackTests
atest FrameworksNetIntegrationTests
atest NetworkStackIntegrationTests
atest CtsNetTestCasesLatestSdk

Change-Id: I64a124802986e4cf4aa7de158c6690fdf9851cb2
2020-11-05 13:55:50 -08:00
Paul Hu
9869d309a6 Merge "Replace Context @hide APIs" 2020-11-05 08:05:09 +00:00
Paul Hu
55f45703ad Merge "Replace AppOpsManager @hide APIs" 2020-11-05 08:03:55 +00:00
James Mattis
4ebbddcf54 Adding @IgnoreUpTo for testOemPrivate
Adding @IgnoreUpTo for NetworkCapabilitiesTest.testOemPrivate so that
this test can run on previous releases.

Bug: 172400600
Bug: 171505922
Test: atest CtsNetTestCasesLatestSdk:NetworkCapabilitiesTest
Change-Id: Ibc728c986ad6faeed78c631ca2675956b95c6ac1
2020-11-04 16:52:11 -08:00
Eran Messeri
f8f47c569d DO NOT MERGE: Introduce DPMS shim for active DO/PO check
Introduce a shim into DevicePolicyManagerInternal &
DevicePolicyManagerService so that NetworkStatsAccessTest would not
diverge from internal development branches.

The DevicePolicyManagerService refactoring on the internal branch
removed isActiveAdminWithPolicy in favour of isActiveDeviceOwner and
isActiveProfileOwner.

These methods are being made available in AOSP for
NetworkStatsAccessTest.

Bug: 170459325
Test: atest NetworkStatsAccessTest
Change-Id: Ic7e0898989fb8222aaba2b35436765c04eb3250c
2020-11-04 10:07:06 +00:00
Mathew Inwood
e1a17baab9 Add maxTargetSdk restriction to unused APIs.
These are APIs that have @UnsupportedAppUsage but for which we don't
have any evidence of them currently being used, so should be safe to
remove from the unsupported list.

Bug: 170729553
Test: Treehugger
Merged-In: I626caf7c1fe46c5ab1f39c2895b42a34319f771a
Change-Id: I54e5ecd11e76ca1de3c5893e3a98b0108e735413
2020-11-04 09:45:53 +00:00
lucaslin
ec9ab79f1a Use hasIpv[4|6]DefaultRoute instead of hasIPv[4|6]DefaultRoute
ConnectivityService is going to be a mainline module, it can only
use formal APIs or @SystemApi. So use @SystemApi
hasIpv4DefaultRoute and hasIpv6DefaultRoute instead of
hasIPv4DefaultRoute and hasIPv6DefaultRoute.

Bug: 172183305
Test: atest FrameworksNetTests
Change-Id: I67e5fa234fbb6d0b9739ae3295eb0b0ea108f582
2020-11-04 01:29:53 +00:00
paulhu
edd411a28d Replace Context @hide APIs
Connectivity service module is using some Context @hide APIs but
they are not able to call after CS becomes a mainline module.
Thus, replace them with similar System APIs.

Bug: 170593746
Test: atest FrameworksNetTests
Test: Manully check that receiving intent and starting activity
      can work normally.
Change-Id: I0f5b53ce0da4e3fc0f927896e9a9e444048401bd
2020-11-04 00:02:42 +08:00
paulhu
8dc153e6e7 Replace AppOpsManager @hide APIs
Connectivity service module is using some AppOpsManager @hide
APIs but they are not able to call after CS become a
mainline module. Thus, replace them with similar System APIs.

Bug: 170593746
Test: atest FrameworksNetTests
Change-Id: I51f66b64fcc3ebdbc2fddff8371eb8d9ff134137
2020-11-03 22:27:16 +08:00
lucaslin
42f8a914cf Use local defined constants for notification channels
ConnectivityService mainline module cannot call the members
inside SystemNotificationChannels.java. So use the local defined
constants instead.

Bug: 172040168
Test: atest FrameworksNetTests
Test: Manual test NO_INTERNET, SIGN_IN, PARTIAL_CONNECTIVITY,
      VPN_ALWAYS_ON notifications.
Change-Id: I223b207c4346e8239dee78e50dd2b0532a3e55b0
2020-11-02 11:53:16 +08:00
paulhu
539aa9a22c NetworkNotificationManager gets NotificationManager locally
It's confusing that NetworkNotificationManager uses
NotificationManager to put up notifcation which is passed from
ConnectivityService. And that NotificationManager should be
gotten from a context with UserHandle.ALL because the
notification should notify to all users. But the future developer
may not know this and pass incorrect NotificationManager
probably. Therefore, adjust the design that
NetworkNotificationManager will get NotificationManager locally.

Bug: 170593746
Test: atest FrameworksNetTests
Change-Id: Id65c998052b7b223171c5194ea46b49d7e84729d
2020-10-30 03:37:50 +00:00
Paul Hu
bc2369abe9 Merge "Replace NotificationManager @hide APIs" 2020-10-30 03:36:40 +00:00
Chalard Jean
e4d25c4287 Merge "Fix a bug where modern network agents start in UNKNOWN" 2020-10-29 12:31:03 +00:00
Chalard Jean
3a7110e160 Fix a bug where modern network agents start in UNKNOWN
Modern network agents are supposed to have the following
lifecycle :
• Construct the agent
• Declare itself to connectivity by calling #register()
• Possibly do some setup
• Declare connected by calling #markConnected()
• Declare disconnected by calling #unregister()

Internally ConnectivityService still manages the state
with deprecated NetworkInfo, which has a lot of possible
detailed states, most of which are now unused. Internally,
the steps above translate to the states below :
• When the agent calls #register() it starts in state
  CONNECTING
• When it calls #markConnected() it goes to CONNECTED
• When it calls #unregister() it goes to DISCONNECTED which
  triggers the flow that disconnects it immediately
• ConnectivityService also synthesizes the SUSPENDED state
  under some situations, but that's not relevant here.

The translation above is done by the NetworkAgent class,
which translates #register(), #markConnected() and
The only valid lifecyle for new agents is thus :

CONNECTING → CONNECTED → disconnect
                 ↕         ↑
             SUSPENDED ───┘

Note that in the above scheme, there is no space for the
UNKNOWN state, which is only used by legacy network agents.
However, the constructor for NetworkInfo still starts with
UNKNOWN. Ideally the constructor for NetworkInfo would set
the info to CONNECTING instead, but this would be a very
visible change in behavior affecting many apps (especially
their tests), so for backward compatibility we can't do
that.

New network agents however don't expose their NetworkInfo
to the client code, so they can just be made to start in
CONNECTING the way it was meant.

Note that this didn't really have a concrete impact beyond
printing some logs as by and large the ConnectivityService
code handles UNKNOWN and CONNECTING the same way, or more
exactly it handles transitions to CONNECTED from UNKNOWN
and CONNECTING in the same way. The exception to this is
VPNs, which are not using the new agent API yet, and the
upcoming conversion is why this fix is actually needed now.

Bug: 170904131
Test: FrameworksNetTests NetworkStackTests
Test: new test in aosp/1460705
Change-Id: Ib7d906a7b29a0b9f000b90bc78558a7402852fa3
2020-10-29 12:30:44 +00:00
Treehugger Robot
04710577a4 Merge "Replace hidden NMS permission control API" 2020-10-29 07:03:37 +00:00
Xiao Ma
7167773060 Merge changes from topic "revert-1353490-revert-1323251-ipv6_prov_loss_quirk_parcelable-DVBHZDYMHA-MDHWFKJABZ"
* changes:
  Add jarjar rule for IPv6ProvisioningLossQuirk.
  Revert "Revert "Test IPv6ProvisioningLossParcelable in the NetworkAttributes"""
2020-10-29 05:39:16 +00:00
Chiachang Wang
cbcc4ae04c Merge changes I6a51d803,I162fae5c
* changes:
  Replace hidden NMS API for setting MTU
  Replace hidden NMS default network configuration API
2020-10-29 05:03:43 +00:00
Chiachang Wang
3fa68ae83a Merge "Replace hidden NMS interface to network API" 2020-10-29 05:02:21 +00:00
paulhu
117bde44fa Replace NotificationManager @hide APIs
Connectivity service module is using some NotificationManager
@hide APIs but they are not able to call after CS become a
mainline module. Thus, replace them with similar System APIs.

Bug: 170593746
Test: atest FrameworksNetTests
Change-Id: I2644867cfc01d8d651c7029134294a9d44fdb471
2020-10-28 16:24:37 +08:00
Chiachang Wang
edb833a1a5 Replace hidden NMS permission control API
Replace the hidden setNetworkPermission NMS APIs with accessing
INetd directly for the incoming ConnectivityService mainline.

Bug: 170598012
Test: atest FrameworksNetTests CtsNetTestCasesLatestSdk
Change-Id: I37ed1003355677b98cbb741f774ba0fa4d193572
2020-10-28 14:38:18 +08:00
Chiachang Wang
6d5c0e714b Replace hidden NMS API for setting MTU
Replace the hidden NMS setMtu API with calling INetd directly
for incoming ConnectivityService mainline.

Bug: 170598012
Test: atest FrameworksNetTests
Test: manually connect and disconnect network
Change-Id: I6a51d8033b3354824d4cfb953c2bbe3055d00102
2020-10-28 14:38:18 +08:00
Chiachang Wang
f83a718af1 Replace hidden NMS interface to network API
Replace the hidden NMS addInterfaceToNetwork and
removeInterfaceFromNetwork with calling INetd directly for
incoming ConnectivityService mainline.

Bug: 170598012
Test: atest FrameworksNetTests
Test: manually connect and disconnect network
Change-Id: I0f1f866be2f8084b992b340aeabfb5d62420686b
2020-10-28 14:38:18 +08:00
Chiachang Wang
1b7ae75c11 Replace hidden NMS default network configuration API
Replace the hidden setDefaultNetId and clearDefaultNetId NMS
APIs with accessing INetd directly for the incoming
ConnectivityService mainline.

Bug: 170598012
Test: atest FrameworksNetTests
Test: manually connect and disconnect wifi
Change-Id: I162fae5ca444207a037e5ac4bf8fa0a77a648ca1
2020-10-28 14:38:18 +08:00
James Mattis
4fcbb03489 Add OEM_PRIVATE NetworkCapability
Adding network capability to be used with networks to be only used by
OEM apps.

Bug: 171505922
Test: atest CtsNetTestCasesLatestSdk:NetworkCapabilitiesTest
Change-Id: Ib55ebec0e178b6317d92f17e1aff060dacdfb2b1
2020-10-27 13:14:06 -07:00
Xiao Ma
ed0fdd959d Add jarjar rule for IPv6ProvisioningLossQuirk.
A new stable parcelable IPv6ProvisioningLossQuirk added in network
stack module, which is used to record the network quirk info which
causes IPv6 provisioning loss, e.g. the router lifetime in RA is 0
and the default route will be removed from LinkProperties.

Previously this change breaks CtsStrictJavaPackagesTestCases due to
a jarjar rule is missed. Also rename the package name based on the
revert change.

Also include slight stable AIDL package and variable rename.

Bug: 157534516
Test: atest CtsStrictJavaPackagesTestCases FrameworksNetTests
Change-Id: Ic2f6b75beefb574f7e2fb4c157667e7734eccd05
2020-10-27 08:04:29 +00:00
Xiao Ma
7f8bb808a8 Revert "Revert "Test IPv6ProvisioningLossParcelable in the NetworkAttributes"""
Test IPv6ProvisioningLossParcelable in the NetworkAttributes.

Bug: 157534516
Test: atest NetworkStackTests

This reverts commit_3740bfadadaaf268f92aaf35dd92e4ce432b39cb

Reason for revert:
Roll forward the previous change, as the CtsStrictJavaPackagesTestCases
breakage has been addressed by adding the jarjar rule in wifi module.

Change-Id: Ib4d70ce557cad98643c811b219f51e9b68179ee8
2020-10-27 07:49:05 +00:00