Commit Graph

732 Commits

Author SHA1 Message Date
paulhu
9dbe49f954 Centralize nsd associated files
Move all nsd associated files include framework, service and test
to package/Nsd first. After clear all hidden API dependencies, we
can easily migrate these files into connectivity mainline module.

Bug: 206893064
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: Id26f471a10fe7882e31ccc2dbb73219461f00dbd
2021-11-29 23:08:06 +08:00
Treehugger Robot
bf7cc5b5d7 Merge "[MS06] Add carrier template fields into cloud backup/restore" 2021-11-26 05:07:26 +00:00
Junyu Lai
d622cde7ee [MS06] Add carrier template fields into cloud backup/restore
NetworkTemplate with MATCH_CARRIER can be created in NPMS,
and can be backup by SettingsBackupAgent. However, since
the meteredness is not stored in the backup. After incorrectly
deducing from match rule, meteredness always becomes
METERED_ALL after restoring from backup.

This change also adds debug log if any non-persistable template
is being backed up.

Test: TH, dedicated test is included in the follow-up CL.
Bug: 204830222

Change-Id: I865b1d6e571ed998a75b776f01afc7c2534af2dc
2021-11-26 03:04:37 +00:00
Remi NGUYEN VAN
16d3da63f7 Merge "Remove AsyncChannel usage in NsdManager" 2021-11-22 05:58:15 +00:00
Maciej Żenczykowski
6516893555 replace R + 1 with S
Test: TreeHugger
Bug: 170424293
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic28aa1a568bbd0b6d4f06abb7294415afd695fff
2021-11-10 18:16:42 -08:00
Remi NGUYEN VAN
3d30b93d60 Remove AsyncChannel usage in NsdManager
Replace AsyncChannel with two AIDL interfaces: INsdManagerCallback and
INsdServiceConnector.

This will be helpful to move NsdManager into a module, avoiding the
dependency on the hidden AsyncChannel utility.

Bug: 190249673
Test: atest FrameworksNetTests CtsNetTestCases:NsdManagerTest
Change-Id: Id9e8feb95cbb5ba16f00893f6c3f37fced3358c1
2021-11-04 17:59:51 +09:00
Les Lee
1e1cd496f6 Fix normalize doesn't work on carrier template
From android 12, the subscriberId is being used for different network
types. For instances:
The TYPE_WIFI with subscriberId means that it is a merged wifi network.
The TYPE_CARRIER means that the network associate to specific carrier
network (subscriberId).

So remove the check "isMatchRuleMobile" and only check whether subscriberId
is being used in NetworkTemplate or not.

Bug: 194939211
Test: atest -c NetworkTemplateTest
Change-Id: I80c9f887cf8b4714716d657da92ed273a532ce27
2021-11-04 14:12:09 +08:00
Aaron Huang
0aed3102da Adapt NET_CAPABILITY_TEMPORARILY_NOT_METERED in NetworkIdentity
NET_CAPABILITY_TEMPORARILY_NOT_METERED is a capability indicates
networks are generally metered, but are currently unmetered.
NetworkIdentity currently did not consider it which will cause
Settings shows high data usage. To exclude unmetered 5g from the
metered usage, NetworkIdentity should consider a network with
NET_CAPABILITY_TEMPORARILY_NOT_METERED capabilities as not metered.

Bug: 183776809
Test: FrameworksNetTests:NetworkIdentityTest
Change-Id: Iadbc082b52f16708207e8aecf0904356bc0898ab
2021-10-26 05:57:24 +00:00
Aaron Huang
faf2c9e5d6 Have buildTemplateMobileWithRatType take metered parameter
To support unmetered 5g, have buildTemplateMobileWithRatType take
metered parameter to build a template which could be used to filter
an unmetered network.

Bug: 183776809
Test: atest FrameworksNetTests:NetworkStatsServiceTest
Change-Id: Ia310d90eceeb572a35ce9518de02b198cae16705
Merged-In: Ia310d90eceeb572a35ce9518de02b198cae16705
2021-10-25 15:10:15 +00:00
Aaron Huang
88c9babd37 Respect metered filter in matchesMobile*
In old design, only metered mobile network would be matched,
which means that only metered stats could be read if callers
query the mobile stats.

Currently, the caller in NetworkPolicyManagerService was updated
to use the NetworkTemplate constructor with metered parameter in
aosp/1563312 which means that the template will be created by a
given meteredness. Thus, the hardcode metered can be removed.

Remove the metered check from matches method will cause a
different behavior. Therefore, to keep the original behavior,
if the match rule is MATCH_MOBILE or MATCH_MOBILE_WILDCARD,
it should pass METERED_YES to the constructor to build a
metered template.

Also, if a caller creates a template by calling the constructor
with metered as a parameter, the behavior will also be changed.
Therefore, if the caller expects to get metered stats then it
should change to pass METERED_YES. If the caller expects to get
both metered and unmetered stats then it should remain METERED_ALL
and it would be a bug that been fixed by this patch.

Bug: 183776809
Bug: 202092687
Test: atest FrameworksNetTests:NetworkStatsServiceTest
      manually test by generating traffic and check the data counts
      from "adb shell dumpsys netstats --uid" almost equal to the
      result from "adb shell cmd stats pull-source 10082"
Change-Id: I66dd51b020f6d895cd002acc05bef6b6315cd447
Merged-In: I66dd51b020f6d895cd002acc05bef6b6315cd447
2021-10-25 15:09:21 +00:00
Aaron Huang
15503f12d6 Merge "Remove forceAllNetworkTypes from test" am: bc48cdaf46
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1824613

Change-Id: I460b93a1a9d04ecdf687761eea3461ecf0346860
2021-09-17 12:25:04 +00:00
Aaron Huang
da213c052e Remove forceAllNetworkTypes from test
A test should test the actual behavior as much as possible.
However, if the flag is true, matchesMobile/matchesMobileWildcard
will always return true regardless of the network type and metered.
Thus, remove this flag would be closer to the actual behavior.

Bug: 183776809
Test: atest FrameworksNetTests
Change-Id: I0907a08ca1dd8a14a738db4057ea5ff6a0cd925a
2021-09-15 18:30:09 +08:00
Luke Huang
426fa1ef6b Merge "Keep the native mdns daemon alive for pre-S application" into sc-dev am: 5978eb6eb4
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15320524

Change-Id: I18b5ab0a0d332167db75d97b8d35595dedc56567
2021-07-22 03:26:43 +00:00
Luke Huang
b4fd4607d6 Keep the native mdns daemon alive for pre-S application
Roll back the behavior changes by checking the target SDK to ensure that
there are no compatibility issues with the pre-S application.
If the target SDK of the application <S, NsdManager will actively send a
cmd to start the native daemon, and NsdService will keep the daemon
until the last client with the target SDK <S disconnects.

Test: atest NsdManagerTest NsdServiceTest
Bug: 191844585
Change-Id: Ie93d5d585e126fe220ae865bbc7274f21a925984
2021-07-21 06:21:42 +00:00
Treehugger Robot
b48a138e4e Merge "Gracefully handle integer overflows." am: bd71f389de am: d4909b9aa9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1714119

Change-Id: I95ef9e71987fc39250e6edd107fe2ec597b1ea17
2021-07-20 08:15:13 +00:00
Treehugger Robot
bd71f389de Merge "Gracefully handle integer overflows." 2021-07-20 07:36:56 +00:00
Remi NGUYEN VAN
0f04dffd2b Merge "Rename FIRST_SDK_INT to DEVICE_INITIAL_SDK_INT" 2021-07-19 09:47:21 +00:00
paulhu
7c76978909 Rename FIRST_SDK_INT to DEVICE_INITIAL_SDK_INT
As API review feedback, rename Build#VERSION#FIRST_SDK_INT to
Build#VERSION#DEVICE_INITIAL_SDK_INT. As well as update all usage
in frameworks and tests.

Bug: 184735771
Test: m
Merged-In: I72660959cb4e638a8e80fcf2f4e96ea172969f44
(cherry-pick with minor conflicts)

Change-Id: I72660959cb4e638a8e80fcf2f4e96ea172969f44
2021-07-05 14:10:16 +09:00
Benedict Wong
9f97237115 Add support for app data accounting for in-kernel dataplanes
This change ensures that app data accounting works correctly within the
confines of in-kernel dataplanes, as used by platform VPNs and the VCN.

Notably, the VCN MUST NOT specify the IMSI, as that would lead to double
counting of the interface statistics.

Bug: 175853498
Bug: 190620024
Test: atest NetworkStatsTest FrameworksVcnTests
Original-Change: https://android-review.googlesource.com/1749070
Merged-In: I768907cd3dd2028c7040cddd81fc71a5ce69bbdb
Change-Id: I768907cd3dd2028c7040cddd81fc71a5ce69bbdb
2021-07-02 19:28:45 +00:00
Benedict Wong
9f61539d84 Merge "Add support for app data accounting for in-kernel dataplanes" am: b07a5e1413 am: cdb9503af4
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1749070

Change-Id: I583a872bcb18f1b749f4ab0b49cbc9323920f048
2021-07-02 19:12:24 +00:00
Benedict Wong
b07a5e1413 Merge "Add support for app data accounting for in-kernel dataplanes" 2021-07-02 18:42:15 +00:00
Benedict Wong
788a981922 Add support for app data accounting for in-kernel dataplanes
This change ensures that app data accounting works correctly within the
confines of in-kernel dataplanes, as used by platform VPNs and the VCN.

Notably, the VCN MUST NOT specify the IMSI, as that would lead to double
counting of the interface statistics.

Bug: 175853498
Bug: 190620024
Test: atest NetworkStatsTest FrameworksVcnTests
Change-Id: I768907cd3dd2028c7040cddd81fc71a5ce69bbdb
2021-07-01 19:49:50 -07:00
Luke Huang
c6a5826df7 Merge "Make NsdService only start the native daemon when needed and automatically clean it up." into sc-dev 2021-06-15 04:52:43 +00:00
Les Lee
6e1e9ef222 Fix: query TYPE_WIFI usage with empty string
Starting with API level 31, the subscriberId is applicable
for the wifi network. Considering applications may use
null or an empty string as subscriberId (for instance, cts),
frameworks create MATCH_WIFI_WILDCARD NetworkTemplate when querying
wifi network with null or an empty string which is the behavior before
API level 31.

Bug: 188915450
Test: atest -c NetworkStatsManagerTest
Test: atest -c NetworkUsageStatsTest
Merged-In: I084b69903f8ba7a6225b312560752e8508938714
Change-Id: I084b69903f8ba7a6225b312560752e8508938714
2021-06-15 10:52:49 +08:00
Les Lee
1f6d2d313f Merge "Fix: query TYPE_WIFI usage with empty string" am: 3bfd63e425 am: 6f52c7de10
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1727620

Change-Id: Ia869e47edec33397ccac5ec97fddf633fc9b8ab7
2021-06-14 16:59:57 +00:00
Les Lee
3bfd63e425 Merge "Fix: query TYPE_WIFI usage with empty string" 2021-06-14 16:30:12 +00:00
Luke Huang
e022ea5d80 Make NsdService only start the native daemon when needed and automatically clean it up.
Currently, NsdService starts the native mdnsresponder daemon if any
NsdManager connect to it, which results in that when any constant
service holds the NsdManager connection, the device would always be
in the mdns multicast group whatever the connection is not used or not.
This is because mdnsresponder will join the multicast group when it
starts.

To solve this problem, start the native daemon only when needed, and
clean it up after the given idle timeout.

1. Start the native daemon when a new request come.
2. If there is no pending request, clean up the daemon after 3 seconds
of idle time.

Bug: 181810560
Test: atest NsdManagerTest NsdServiceTest
Original-Change: https://android-review.googlesource.com/1717479
Merged-In: I3eb04552f6cf6c0c68c07abffe751bb4d0669215
Change-Id: I3eb04552f6cf6c0c68c07abffe751bb4d0669215
2021-06-14 06:54:52 +00:00
Luke Huang
333c4c91dc Merge "Make NsdService only start the native daemon when needed and automatically clean it up." am: 05081aa3b0 am: 27450253e2
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1717479

Change-Id: Idb9e8dcd7c38ee09e21a3e0af3e643c44f9aa357
2021-06-13 16:52:05 +00:00
Les Lee
c873a96dcc Fix: query TYPE_WIFI usage with empty string
Starting with API level 31, the subscriberId is applicable
for the wifi network. Considering applications may use
null or an empty string as subscriberId (for instance, cts),
frameworks create MATCH_WIFI_WILDCARD NetworkTemplate when querying
wifi network with null or an empty string which is the behavior before
API level 31.

Bug: 188915450
Test: atest -c NetworkStatsManagerTest

Change-Id: I084b69903f8ba7a6225b312560752e8508938714
2021-06-11 18:14:50 +08:00
Luke Huang
17df73a1b8 Make NsdService only start the native daemon when needed and automatically clean it up.
Currently, NsdService starts the native mdnsresponder daemon if any
NsdManager connect to it, which results in that when any constant
service holds the NsdManager connection, the device would always be
in the mdns multicast group whatever the connection is not used or not.
This is because mdnsresponder will join the multicast group when it
starts.

To solve this problem, start the native daemon only when needed, and
clean it up after the given idle timeout.

1. Start the native daemon when a new request come.
2. If there is no pending request, clean up the daemon after 3 seconds
of idle time.

Bug: 181810560
Test: atest NsdManagerTest NsdServiceTest
Change-Id: I3eb04552f6cf6c0c68c07abffe751bb4d0669215
2021-06-08 10:09:30 +08:00
lesl
0d14803a32 carrier data usage: Use carrier template as default policy am: 35a6e5507e
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14782679

Change-Id: I8bdde6aaeea04c4c70a37d5a71ad31a5590323a9
2021-06-02 04:01:14 +00:00
Les Lee
acbea9a48e Merge "carrier data usage: Use carrier template as default policy" 2021-06-01 10:42:08 +00:00
lesl
35a6e5507e carrier data usage: Use carrier template as default policy
The carrier network means any network which linked with sepcific
subscriberId (for instances: merged Wifi or mobile).
Update default policy to use carrier network template to replace mobile
template.

No impact for current AOSP user because no any wifi network is merged
wifi. (Because the merged wifi network requires to support from the wifi module).

Also this change convert all of the old policies which template is
TYEP_MOBILE to TYPE_CARRIER to match the default policy.

Bug: 176396812
Test: atest -c NetworkPolicyManagerServiceTest
Test: atest -c CtsHostsideNetworkTests
Test: Manual Test with test code (Force wifi to merged wifi).
      The data will limit when using merged wifi.
      And mobile policy also work normally.

Merged-In: I33c10f7549e713c52ce9afd5b8c4cce2abbda616
Change-Id: I33c10f7549e713c52ce9afd5b8c4cce2abbda616
2021-06-01 18:12:56 +08:00
Pavan Kumar M
1c5ecec86d 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: I355fc9bd127da83c1dc70ab3b1261346d4fa5de0
2021-05-26 08:09:31 +00:00
Treehugger Robot
4ccd2e2d87 Improve documentation of IpSecTunnelInterface#setUnderlyingNetwork
Clarify the consequence of adding IpSecTunnelInterface to the
underlying network.

Bug: 169855650
Test: builds
Change-Id: I2e3c4fe735b3374b2ff6d23850970e36c0aafda5
Merged-In: I2e3c4fe735b3374b2ff6d23850970e36c0aafda5
2021-05-20 21:56:26 +00:00
Treehugger Robot
17304a67fd Merge "Improve documentation of IpSecTunnelInterface#setUnderlyingNetwork" am: 9625c2df35 am: de7add3201
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1590415

Change-Id: I02207954757c9135fbf6674720dd8e623fc9e435
2021-05-20 21:22:32 +00:00
Treehugger Robot
9625c2df35 Merge "Improve documentation of IpSecTunnelInterface#setUnderlyingNetwork" 2021-05-20 20:33:41 +00:00
lesl
41e74f4334 carrier data usage: Use carrier template as default policy
The carrier network means any network which linked with sepcific
subscriberId (for instances: merged Wifi or mobile).
Update default policy to use carrier network template to replace mobile
template.

No impact for current AOSP user because no any wifi network is merged
wifi. (Because the merged wifi network requires to support from the wifi module).

Also this change convert all of the old policies which template is
TYEP_MOBILE to TYPE_CARRIER to match the default policy.

Bug: 176396812
Test: atest -c NetworkPolicyManagerServiceTest
Test: atest -c CtsHostsideNetworkTests
Test: Manual Test with test code (Force wifi to merged wifi).
      The data will limit when using merged wifi.
      And mobile policy also work normally.

Change-Id: I33c10f7549e713c52ce9afd5b8c4cce2abbda616
2021-05-20 23:46:39 +08:00
Les Lee
aca6568d23 Merge "Support to query TYPE_WIFI usage with subscriberId" into sc-dev 2021-05-20 08:55:59 +00:00
Les Lee
255253242f Merge "Add metered filter for API: buildTemplateCarrier" into sc-dev 2021-05-19 14:32:29 +00:00
lesl
067a1d2448 Add metered filter for API: buildTemplateCarrier
This CL modifies NetworkTemplate#buildTemplateCarrier to force on
metered carrier network and rename to buildTemplateCarrierMetered.
This method was introduced recently and has no callers.

This method will be used in Settings and NetworkPolicyManagerService
to display and manage data usage on carrier metered networks.

Settings/NetworkPolicyManagerService will use it instead of the existing
method buildTemplateMobileAll method, which only matches metered networks.
That code will change from matching metered mobile networks to matching
metered carrier networks.

Note: The carrier metered network includes metered mobile network and
metered "merged carrier wifi network" that is a specific cerrier wifi network
which provides the same user experience as mobile.

Bug: 176396812
Test: atest -c NetworkTemplateTest
Change-Id: I7196d62bb60844458a6c4b1d94e2baccb71e15cd
Merged-In: I7196d62bb60844458a6c4b1d94e2baccb71e15cd
2021-05-19 02:53:39 +00:00
lesl
ee39c8deec Support to query TYPE_WIFI usage with subscriberId
Previous the API ignores subscriberId when network type is WIFI.
Allow caller to call querySummaryXXXX with TYPE: WIFI
+ subscriberId: IMSI to get carrier merged wifi usage which matches the wifi
network with the given IMSI.

Bug: 176396812
Test: atest -c NetworkStatsServiceTest
Change-Id: Ia033521a24e2bb56182d74a41bb2b39710571782
Merged-In: Ia033521a24e2bb56182d74a41bb2b39710571782
2021-05-19 02:53:16 +00:00
Chris Weir
138711ed9e Merge "Print human-readable OEM managed states" am: 9374ca2698 am: e71bec661e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1636561

Change-Id: I4ecc049acf7a5f2e3c99808c7e5f6c2f064d7e5c
2021-05-18 17:39:57 +00:00
Chris Weir
9374ca2698 Merge "Print human-readable OEM managed states" 2021-05-18 16:29:26 +00:00
Les Lee
d9f66d5beb Merge "Support to query TYPE_WIFI usage with subscriberId" am: 15672a8a12 am: 722aab0208
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1608057

Change-Id: Ifeaab15fbf20b318bb7b35aa6b4604f21e2c98a1
2021-05-18 13:57:43 +00:00
Les Lee
6736657d56 Merge "Add metered filter for API: buildTemplateCarrier" am: 7c60bfb320 am: 9366d34196
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1699687

Change-Id: I46d8d8f0d9b83fb0a817a3455cbbc28d558b871c
2021-05-18 13:57:06 +00:00
Les Lee
15672a8a12 Merge "Support to query TYPE_WIFI usage with subscriberId" 2021-05-18 13:02:07 +00:00
Les Lee
7c60bfb320 Merge "Add metered filter for API: buildTemplateCarrier" 2021-05-18 13:01:38 +00:00
junyulai
5f8c0b0b6b [FUI27] Fix internal naming of notifyNetworkStatus
Test: TH
Bug: 174123988
Merged-In: I970ee365ca221956ee85788005d331374b5fa71a
Change-Id: I970ee365ca221956ee85788005d331374b5fa71a
  (cherry-picked from aosp/1620539)
2021-05-17 14:07:00 +08:00
lesl
dfc7237743 Support to query TYPE_WIFI usage with subscriberId
Previous the API ignores subscriberId when network type is WIFI.
Allow caller to call querySummaryXXXX with TYPE: WIFI
+ subscriberId: IMSI to get carrier merged wifi usage which matches the wifi
network with the given IMSI.

Bug: 176396812
Test: atest -c NetworkStatsServiceTest
Change-Id: Ia033521a24e2bb56182d74a41bb2b39710571782
2021-05-16 22:18:32 +08:00