Commit Graph

144 Commits

Author SHA1 Message Date
Remi NGUYEN VAN
bee2ee14f3 Move ConnectivityResources to service-connectivity
The ConnectivityResources class is only usable with QUERY_ALL_PACKAGES
permission, so it is not generally usable in framework-connectivity. It
is also backed by the ServiceConnectivityResources APK, which is
intended as resources for service-connectivity.

Move the class to service-connectivity and update callers. CTS needs a
way to determine the supported keepalive count as it used the
resources from KeepaliveUtils as @hide API, so provide a
ConnectivityManager @hide API for testing.

Bug: 279108992
Test: atest
Change-Id: I3c9a77c580b5ab87c922c32778bce15dc33b4d1d
2023-04-28 19:18:39 +09:00
Junyu Lai
9d25241337 Merge changes from topic "statsaccess"
* changes:
  Check MAINLINE_NETWORK_STACK as well to make GTS can access proper stats
  Move checkAnyPermissionOf to PermissionUtils
2023-04-14 09:54:49 +00:00
Junyu Lai
e68c42b888 Check MAINLINE_NETWORK_STACK as well to make GTS can access proper stats
Follow up from aosp/1933093. The test failed because certain
devices use a flattened apex that lacks the NETWORK_STACK
permission for sharing with the GTS apk.
Additionally, the NetworkStatsAccess does not recognize the
GTS apk, which holds the MAINLINE_NETWORK_STACK permission.

Test: TH
Bug: 275532605
Change-Id: Icce80a3d3dbea4a84fbd369d9b5fbe0029ab463e
2023-04-11 14:56:15 +08:00
Junyu Lai
2c12f922de Do not crash when passing null into buildTemplateMobileAll
Test: atest FrameworksNetTests:android.net.connectivity.android.net.NetworkTemplateTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.netstats.NetworkTemplateTest
Bug: 273963543
Change-Id: I0a8f94df124147e92d35cf474b3d69d1dee6902c
2023-03-30 13:59:02 +08:00
Paul Hu
62503cfef1 Merge "Add a CompatChange flag to enable platform backend" 2023-03-17 13:14:19 +00:00
Paul Hu
2e0a88c0fa Add a CompatChange flag to enable platform backend
Apps targeting sdk < U are considered to use a legacy native
daemon as NsdManager backend, but other apps use a
platform-integration mDNS implementation as backend. So add a
CompatChange flag to enable platform backend for non-legacy
apps.

Bug: 270306772
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I7ba58f8a5186fb49ad5f8aeacc8b8234bef1eabe
2023-03-17 09:10:46 +08:00
Aaron Huang
8ac1143594 Remove requireNonNull check from matchesWifiNetworkKey
matchesWifiNetworkKey expects a non-null value of the
wifiNetworkKey, however, it might be null in practice
and the null wifiNetworkKey will be stored into disk.
And then when the matchesWifiNetworkKey is called, the
requireNonNull will crash the system. Thus, remove the
requireNonNull from matchesWifiNetworkKey to avoid
system crash and handle if the wifiNetworkKey is null
then it should not match a template with non-empty
mMatchWifiNetworkKeys.

Check if WifiInfo contains a null network key then skip it
to prevent adding the identity to the network identity set.
Also, add a Log.wtf when setWifiNetworkKey(info.getNetworkKey()),
this might be useful to catch why the wifiNetworkKey is
null.

Bug: 267815242
Bug: 266598304
Test: FrmeworksNetTests
Change-Id: I9c21f7e3dca9482133c7e331741cf808105414e9
2023-03-07 18:16:55 +08:00
Kangping Dong
7dc4459d33 Merge "add TRANSPORT_THREAD to NetworkCapabilities" 2023-02-28 07:16:16 +00:00
chiachangwang
015b68b192 Add unit tests for new VpnProfile fields
Add and update tests for automaticNattKeepaliveTimerEnabled
and automaticIpVersionSelectionEnabled fields.

Test: atest Ikev2VpnProfileTest VpnProfileTest
Change-Id: I4e424abd2197d9099a2efe0bd8c4b9120bfcfe3a
2023-02-15 15:01:28 +00:00
Aaron Huang
2a69e41772 Merge "Tempates with different subscriber ID should be not equal" 2023-02-10 08:06:07 +00:00
Aaron Huang
c9371d05fe Tempates with different subscriber ID should be not equal
mSubscriberId was removed from NetworkTemplate and equals/hashCode
does not check the mMatchSubscriberIds. This will cause tempates
with different subscriber ID matching that are equal now. Thus
adding the check for mMatchSubscriberIds to fix it.

Bug: 267968247
Test: FrameworksNetTests:NetworkTemplateTest
Change-Id: I2956bf4c8cf2c4d73ebe102d53e755fbcc5d7642
2023-02-10 08:04:53 +00:00
Yuyang Huang
90a2cbdd8d Moves all compatibility flags to ConnectivityCompatChanges.java
ConnectivityCompatChanges.java becomes the centralized place for all the
CompatChanges used in the Connectivity module. By putting all the
CompatChanges here, we are able to manage them under a single
platform_compat_config.

Bug: 268440216
Test: atest FrameworksNetTests
Change-Id: I3e17af545718073d7d1c96e27298e7790563fd33
2023-02-09 19:51:37 +09:00
Paul Hu
18aecccc9d New API to listen service update
Currently, the resolution is a one shot query, it only notifies
the first finding service information. There is no way to listen
the service update. Thus, add a new API that can register a
callback to listen to the service updates continuously.

Bug: 245369943
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I0e9d92b9028375feb3e344ab6c4acb515c5b2be9
2023-01-19 20:16:03 +09:00
Aaron Huang
2500069488 Merge "Remove *_WILDCARD constants from NetworkTemplate" 2023-01-16 07:56:09 +00:00
Aaron Huang
99348b1664 Merge "Remove mSubscriberId from NetworkTemplate" 2023-01-16 07:55:26 +00:00
Kangping Dong
707a996c9b add TRANSPORT_THREAD to NetworkCapabilities
This commit also updates to use V11 dnsresolver APIs which was V9.

Bug: 262683651
Test: unit tests
Change-Id: Ifbd71157012dc66ec0f377beef9fa59d1c8620b8
2023-01-16 10:51:56 +08:00
Yan Yan
81c2160a63 Expose APIs to migrate IpSecTransform
This commit exposes APIs to migrate a tunnel mode transform to
new source/destination addresses, as required by MOBIKE.

By calling the exposed API, the caller only caches the new
address in the transform. To complete the migration, caller
MUST apply the tranform to the appropriate tunnel.

This API design is mainly based on the kernel interface and use
cases. The Linux kernel requires Android to provide both the
IpSecTransform and the IpSecTunnelInterface to perform the
migration. And in most cases those two instances are managed
by different entities: IpSecTranform is managed by the key
exchange protocol (e.g. IKE) and IpSecTunnelInterface is managed by
the security tunnel provider (e.g. VPN, VCN, and IWLAN). Thus the
migration process has been designed to have two steps where the
key exchange protocol negotiates and caches the new address,
passes out the updated transform, and the security tunnel
provider applies the transform to a tunnel.

Another benefit of this API is it can also apply to the case
where the network peer does not support MOBIKE and thus cannot
update the existing transforms. In this case, the key exchange
protocol can create a new transform and give it to the security
tunnel provider, and the tunnel provider can still call "apply"
to perform migration without needing to know the details of the
transform update process.

Bug: 169171001
Test: atest FrameworksNetTests, IpSecManagerTunnelTest
Change-Id: I0658cdb09fb31f7e0fb9d0b07f37c2b72b6e705f
2023-01-10 19:09:05 +00:00
Aaron Huang
ece181997c Remove *_WILDCARD constants from NetworkTemplate
NetworkTemplate was moved into mainline module and
provide Builder for external users to build template.
MATCH_MOBILE_WILDCARD and MATCH_WIFI_WILDCARD are not
exposed so currently the usage of these two constants
only in module. This change is to remove the constants.

After removing the constants, two methods matchesWifi
and matchesMobile are changed to adapt the original
matches[Wifi|Mobile]Wildcard behavior.

Bug: 238843364
Test: FrameworksNetTests
Change-Id: I9e156b504ce4eb903b39279e443fad27bc921186
2022-12-28 18:49:37 +08:00
Aaron Huang
ee23c03121 Remove mSubscriberId from NetworkTemplate
Currently NetworkTemplate provides Builder for users to build a
template and it supports multiple subscriber ids. The mSubscriberId
is a local variable in current design so it can be removed from
NetworkTemplate and also can be removed from the parameter of a
constructor as long as the constructor is not annotated with
@UnsupportedAppUsage.

Bug: 238843364
Test: build, FrameworksNetTests
      CtsNetTestCases
Change-Id: Ic6a695e1c1719111bf26ba905a38673952a24736
2022-12-28 12:09:21 +08:00
Aaron Huang
4854d055bb Remove mSubscriberIdMatchRule from NetworkTemplate
Currently, mSubscriberIdMatchRule is only used in NetworkTemplate
and it depends on if mMatchSubscriberIds is empty or not. Thus,
remove it since is not really necessary and replace it with
checking matchSubscriberIds if needed.

Bug: 238843364
Test: build, FrameworksNetTests
      CtsNetTestCases
Change-Id: Ic66d2ff2826846778b004bb15a4718a62fa1f470
2022-12-28 12:09:09 +08:00
Yan Yan
e114b38f07 Support IPsec transform migration
This commit adds methods to support migrating tunnel mode
IpSecTransform to new source/destination addresses.

Bug: 169171001
Test: atest FrameworksNetTests (new tests added)
Change-Id: Ic177015fba5b62d3f73009633118109d3631086f
2022-12-21 23:12:35 +00:00
Mark Chien
82eb31b346 Increased the timeout from 5 to 30 seconds
Increase the timeout to deal with the flaky test.

Bug: 260073439
Test: TH

Change-Id: I653d80cfa97256e139f8cf989a085b1133732092
2022-12-06 06:51:03 +00:00
Treehugger Robot
841b1f33d5 Merge "Revert consider TEMPORARILY_NOT_METERED as unmetered in data usage" 2022-12-02 11:27:27 +00:00
Aaron Huang
c5a05d1d8f Revert consider TEMPORARILY_NOT_METERED as unmetered in data usage
Currently, NET_CAPABILITY_TEMPORARILY_NOT_METERED traffic is
counted as unmetered data usage, and "mobile data usage"
settings screen shows metered data usage which means it doesn't
include TEMPORARILY_NOT_METERED traffic. However, some carriers
show TEMPORARILY_NOT_METERED data usage in customer's bill which
would be confusing if the data usage in the device shows different
results. Thus, revert the change to avoid confusing.

Bug: 183776809
Test: FrameworksNetTests
Change-Id: I4ef25095462adf30b1ecf82134996739f167930d
2022-12-02 16:04:55 +08:00
Aaron Huang
859884a48f Make mMatchSubscriberIds as a NonNull variable
In current design, mMatchSubscriberIds can be null which has the
same meaning with empty set, and is not easy to maintain since it
need more checks for this variable when mSubscriberId is null.
Thus make mMatchSubscriberIds NonNull for the maintenance.

Bug: 238843364
Test: build, FrameworksNetTests
Change-Id: I6cfc529b5f4a39ded8598283ff968f2f4d1bc89f
2022-11-30 16:38:24 +00:00
Aaron Huang
a8a6da0db9 Remove unused methods from NetworkTemplate
NetworkTemplate.Builder was introduced in Android T and the callers
outside of Connectivity module should use this Builder to build a
template instead. Thus remove the buildTemplate* methods from
NetworkTemplate class. Also, deprecate the methods which are
annotated with @UnsupportedAppUsage and also use Builder to build
the template.

Bug: 238843364
Test: build, FrameworksNetTests
Change-Id: I3190325f6663e4771edf5c7a19bf5ecc7780bf12
2022-11-30 16:38:19 +00:00
Chiachang Wang
dfea18945c Merge "Move VpnTransportInfoTest to common test" 2022-11-18 05:44:20 +00:00
chiachangwang
91bac1953c Move VpnTransportInfoTest to common test
Move VpnTransportInfoTest to common test to add the cts
coverage.

Annotate @ConnectivityModuleTest so that the test will
not fail with module that is not up-to-date, and use
assertParcelingIsLossless to prevent similar order module
in device case.

Bug: 256775913
Test: atest CtsNetTestCases:android.net.VpnTransportInfoTest
Change-Id: I1c40a4fc42468748d71c3df5c18b2ceb5b3769e1
2022-11-18 02:17:33 +00:00
Chiachang Wang
89d4bda742 Merge "Expose vpn bypassability in VpnTransportInfo" 2022-11-15 05:35:08 +00:00
Aaron Huang
ac28a04c6e Merge "Enhance NetworkTemplate test" 2022-11-14 09:38:27 +00:00
chiachangwang
d12d2011cb Expose vpn bypassability in VpnTransportInfo
Bug: 256775913
Test: m framework-connectivity.stubs.source.system-update-current-api
Test: m lint-check
Test: atest FrameworksNetTests
Change-Id: I6aaad7b4372aa4f91df4bed89caea674031a6367
2022-11-11 08:38:17 +00:00
Maciej Żenczykowski
5d78c63662 ipsec - use ro.vendor.api_level instead of ro.product.first_api_level
Bug: 254143771
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9f91fc250e0fa40c9dc9ee3e7a2f7bc3cf2ebc75
2022-11-09 00:47:13 +00:00
Aaron Huang
fc4236b945 Enhance NetworkTemplate test
This change addresses comment from aosp/1784390 to improve test

Bug: 200454911
Test: FrameworksNetTests:NetworkTemplateTest#testMobileWildcardMatches
Change-Id: Ia0ac9e44d12e7c9e26cf46adaa26a2e2771947d0
2022-11-02 10:41:08 +00:00
Aaron Huang
0c8d808117 Merge "Make constants static import" 2022-10-17 04:25:25 +00:00
Aaron Huang
4c3159d3a7 Add test for NetworkStats.clearInterfaces
Test: FrameworksNetTests:NetworkStatsTest
Change-Id: Ic8ff1c3213e53a043ebbd3d7ddfeb295a198675d
2022-10-12 18:57:43 +00:00
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
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
Chalard Jean
f11ed8c699 Start listening to telephony changes in #start()
Starting to listen on the handler races with the rest of
the constructor. The class already has a #start() method
meant to start listening, so implement better practices
by leveraging this method.

Test: CtsNetTestCases
      FrameworksNetIntegrationTests
      FrameworksNetTests
Change-Id: I772f761d3ca5f9711b9d988e6330b0878814f491
2022-09-21 18:07:13 +09:00
chiachangwang
4e953f63dd Verify converting to Vpnprofile with IkeTunnelConnectionParams set
Add test to verify converting Ikev2VpnProfile to Vpnprofile with
IkeTunnelConnectionParams set. Some fields like server should
not be set since the information should contain in the assigned
IkeTunnelConnectionParams.

Bug: 243718982
Test: atest FrameworksNetTests
Change-Id: Ie019ea98932a6d079f213e3bff45f21b44d3fa4e
2022-09-14 02:38:26 +00:00
Aaron Huang
f4fbf8ed52 Make constants static import
Bug: 238843364
Test: FrameworksNetTests
Change-Id: Id88bcc175db0a599dd3205812b1bce78012e2216
2022-09-12 06:51:57 +00:00
Chiachang Wang
ebab250383 Merge "Add test to verify null ProxyInfo in Ikev2VpnProfile" 2022-09-02 12:15:09 +00:00
chiachangwang
715dc5b447 Add test to verify null ProxyInfo in Ikev2VpnProfile
Bug: 244281603
Test: atest FrameworksNetTests
Change-Id: Ice195b60a0f62ae541ede9277c6e36f9c72b2dbb
2022-09-02 03:51:43 +00:00
Junyu Lai
c9f1ca62d9 [ST01] Attributes data usage of test network by specifier
Currently, data usage of all test networks are all attributed to
the same NetworkIdentity, which does not allow services to
distinguish upload & download traffic of different test networks.

Thus, this CL put specifier that comes along with
TestNetworkAgent into wifiNetworkKey field to build different
NetworkIdentity to attribute data usage to different for
individual networks. And allow querying test network usage with
wifiNetworkKeys.

Bug: 139774492
Test: atest FrameworksNetTests
      atest android.net.cts.ConnectivityManagerTest
Change-Id: I1bb38fd20781eaf3105735440a04b27bef36fcae
2022-08-29 13:55:08 +08:00
Chalard Jean
9cc32051ac Address comments on aosp/1781202
This also imports FunctionalUtils (ex-ExceptionUtils) with
its new name, as the companion change changes the name of
that class.

Test: ConnectivityServiceTest
Change-Id: I3fbc28835419864e536dd6727670328658a9b7cf
2022-08-17 07:11:55 +00:00
Aaron Huang
8b9ecdad6d Cleanup constructor of NetworkStats#Entry
Have all callers to use the same constructor and remove the
unused constructors.

Bug: 238843364
Test: FrameworksNetTests
Change-Id: Ieb1d0bc4ff8d2238c7a802189f8d91f4a9978eb8
2022-08-02 22:49:16 +08:00
Remi NGUYEN VAN
348bbb0231 Add back compat config for NSD
Add back compat config for RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS, which was
lost when moving NsdManager to framework-connectivity-t.

This causes NsdManager to start mdnsresponder again when used by apps
with target SDK < 31.

The change also changes the compat ID used, to make sure it does not
conflict with the ID already in use in S and below, when the module is
installed on such a platform. This is the only ChangeId used by
framework-t.

Also add a CtsNetTestCasesMaxTargetSdk30 test to verify that behavior.

Bug: 235355681
Test: atest CtsNetTestCasesMaxTargetSdk30
Change-Id: I7ca6051d0a4ba5aff3e44bece2cbac22eb1be32d
2022-07-27 19:53:25 +09:00
Aaron Huang
a4fcb8b4cf Replace buildTemplate* with NetworkTemplate.Builder
Use Builder API which was provided in Android T to
build a template.

Bug: 238843364
Test: build, FrameworksNetTests:NetworkStatsManagerTest
Change-Id: Ibf1ac16541d6f3ddaf9b241e2f47ae04acbedf93
2022-07-18 17:16:49 +08:00
Aaron Huang
80767e64ef Add wipeOnError flag to NetworkStatsRecorder
If reading data happens exception while doing data migration,
the file will be deleted by legacy recorders. This would cause
legacy persistent data being lost and cannot be retrieved by
any method. To avoid the files being deleted, add a wipeOnError
flag to recorder which indicates this recorder will wipe on
error or not . If the flag is set to true then deletes all files
when it throws, otherwise keeps all files.

(cherry-picked from ag/18910973)
Bug: 233828210
Test: FrameworksNetTests:NetworkStatsRecorderTest

Change-Id: Id7a3d8bebf8a00d814f9e84bf4c10d927e6ff749
Merged-In: Id7a3d8bebf8a00d814f9e84bf4c10d927e6ff749
2022-06-22 17:37:51 +08:00
Remi NGUYEN VAN
5eaefa21bf Merge "Fix service resolve on tethering downstreams" 2022-06-01 05:31:14 +00:00
Natasha Lee
bcdb3c12ee Merge changes from topic "stats-migration"
* changes:
  Skip PersistentIntTest on S- device
  Don't clobber existing history entries.
  Ensure NetworkStats migrated snapshot is identical
  [MS82.1] Support network stats data migration process
  Add a PersistentInt class.
2022-06-01 03:03:02 +00:00