Commit Graph

478 Commits

Author SHA1 Message Date
Remi NGUYEN VAN
0c334548f8 Merge "Ensure callbacks are run properly on executor" am: 411d2bd07d am: f8224f5364
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2111166

Change-Id: I70f6ccf9f42717b846e816067e90916792cec143
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-03 09:42:25 +00:00
Aaron Huang
ab097b28d5 Hold wifi and mobile interfaces since boot in NetworkStatsService am: a2f1cf3576
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/18710006

Change-Id: Ie53afd7a2c6cfdd46a1ed3954a1aceac9bd120eb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-03 09:25:50 +00:00
Remi NGUYEN VAN
411d2bd07d Merge "Ensure callbacks are run properly on executor" 2022-06-03 09:04:29 +00:00
Aaron Huang
a2f1cf3576 Hold wifi and mobile interfaces since boot in NetworkStatsService
In current design, the interface will be removed from the list if
the network disconnected which will cause getUidStatsForTransport()
returns unexpected snapshot to caller since the list is empty.

This change also remove interface name from all entries before
the method returns the result.

Ignore-AOSP-First: non-AOSP CL is included in the same topic
Bug: 231514741
Test: FrameworksNetTests
      manual test
Change-Id: Ie60829a65d0d9b5b63ad353695a820c0586e3665
2022-06-03 15:51:19 +09:00
Remi NGUYEN VAN
9133888e0c Ensure callbacks are run properly on executor
NsdManager callbacks were run on a provided executor by capturing the
handler message in a lambda, but the message will be recycled
immediately after handleMessage returns. This means that any non-inline
executor would see bogus callbacks, as they have an empty Message. Fix
it by not capturing the Message in the lambda, but capturing its
contents instead.
This was broken when updating the class to support executors in change
ID: I4c31e2d7ae601ea808b1fd64df32d116c6fff97f; before that, callbacks
were all run on the NsdManager handler.

Also, DelegatingDiscoveryListener is being run on the NsdManager handler
thread for notifyAllServicesLost, causing onServiceLost to be run there,
but other methods are run on the provided Executor, even though they
access maps maintained on the handler thread, like mPerNetworkListeners.

Revert DelegatingDiscoveryListener to run on the handler thread as
before, and only use the provided executor to execute any app-facing
callback instead.

Bug: 234419509
Test: atest NsdManagerTest

Change-Id: Icca64511b02dad2f725a2849d2a1e871135b3286
2022-06-02 18:16:42 +09:00
Paul Hu
6773b82577 Merge "Remove the DisabledState from NsdService" am: d65740346e am: 537e5289fe
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2110094

Change-Id: I86da81dbd9e5d55042a9cf2df8d5876a4f244e03
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-01 10:17:28 +00:00
Paul Hu
d65740346e Merge "Remove the DisabledState from NsdService" 2022-06-01 09:25:11 +00:00
Remi NGUYEN VAN
2bd25cdc84 Merge "Fix service resolve on tethering downstreams" am: 5eaefa21bf am: d0a31d8e08
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2110084

Change-Id: I14bf75238dd36a9d5c834f26964d1e861d1e714e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-01 06:09:12 +00:00
Paul Hu
29f4359856 Remove the DisabledState from NsdService
In order to increase the line coverage for the Connectivity
module, remove the DisabledState from NsdService which is
uselss for a while.

Bug: 234315786
Test: atest FrameworksNetTests CtsNetTestCases \
      ConnectivityCoverageTest
Change-Id: I29c7ef608d97037084b25daa70ad5829f474e20a
2022-06-01 05:57:59 +00:00
Remi NGUYEN VAN
0102c9440a Fix service resolve on tethering downstreams
Tethering downstreams do not have NetworkAgents, and although they have
a netid of 99, Networks with netId 99 are not usable by apps for most
connectivity APIs.

Recent refactoring in NsdService adds the Network of a found service
into its NsdServiceInfo, and uses that network to resolve the service.
In that case the Network has netId 99 and resolving the service fails.

Avoid that problem by:
 - Keeping the Network field null when a service is found on a tethering
   downstream; this avoids giving apps a confusing and unusable Network
   with netId 99
 - Using the interface index found during discovery to resolve the
   service, if the app uses the NsdServiceInfo that was obtained from
   discovery to resolve. If not, all interfaces will be used to resolve,
   as per legacy APIs.

Bug: 233979892
Test: atest NsdServiceTest
      Also manual test with 2 devices connected via hotspot
Change-Id: Idd176153b67ccbd1d4f1b1fd66dafaa2f3a9e27a
(cherry picked from commit 1a8ee102d3)
Merged-In: Idd176153b67ccbd1d4f1b1fd66dafaa2f3a9e27a
2022-06-01 05:35:36 +00: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
Remi NGUYEN VAN
1a8ee102d3 Fix service resolve on tethering downstreams
Tethering downstreams do not have NetworkAgents, and although they have
a netid of 99, Networks with netId 99 are not usable by apps for most
connectivity APIs.

Recent refactoring in NsdService adds the Network of a found service
into its NsdServiceInfo, and uses that network to resolve the service.
In that case the Network has netId 99 and resolving the service fails.

Avoid that problem by:
 - Keeping the Network field null when a service is found on a tethering
   downstream; this avoids giving apps a confusing and unusable Network
   with netId 99
 - Using the interface index found during discovery to resolve the
   service, if the app uses the NsdServiceInfo that was obtained from
   discovery to resolve. If not, all interfaces will be used to resolve,
   as per legacy APIs.

Bug: 233979892
Test: atest NsdServiceTest
      Also manual test with 2 devices connected via hotspot
Change-Id: Idd176153b67ccbd1d4f1b1fd66dafaa2f3a9e27a
2022-05-31 13:06:22 +09:00
Junyu Lai
323b8b23d1 Return sorted NetworkStatsHistory am: 25c6d60f8a
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/18581718

Change-Id: I6335ae844d2fbbc1c325a92592da4f8d009c6fd3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-27 14:16:31 +00:00
Junyu Lai
25c6d60f8a Return sorted NetworkStatsHistory
NetworkStatsHistory internally assumes that bucketStart is
sorted at all times. However, in the fields, we've found there
are some buckets of NetworkStatsHistory do not preserve the
order of timestamp, which is caught by the IAE when addEntry
is called.

In order to provide backward compatibility, return sorted items
instead of throwing IAE when adding entry into
NetworkStatsHistory instance.

Ignore-AOSP-First: Base change not in AOSP, will cherry-pick
                   immediately after
Test: atest android.net.netstats.NetworkStatsHistoryTest#testBuilder
Bug: 233825704
Change-Id: If3187384bd1e90770ca5873b8ec73e852fff543d
2022-05-26 22:04:43 +08:00
Patrick Rohr
268e1c6d2e Merge "Remove automotive restriction from enable/disableInterface" am: 345655f7bc am: 1d0e33db3a
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2103746

Change-Id: Iaa4e13f6babe0074c7123c6a8728102b9d29b8a3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-25 02:51:26 +00:00
Patrick Rohr
345655f7bc Merge "Remove automotive restriction from enable/disableInterface" 2022-05-25 02:00:51 +00:00
Patrick Rohr
fd829a5cb2 Remove automotive restriction from enable/disableInterface
Allow calling enable/disableInterface on non-automotive devices. Also,
fixing the naming of these functions to be consistent with the API.

Test: atest EthernetManagerTest
Bug: 171872016
Bug: 225317990
Change-Id: Ic20185a855d0e639582132bf1103e0183f6f78c3
2022-05-24 03:54:38 +00:00
Lorenzo Colitti
ec2fbb7159 Don't clobber existing history entries.
Currently, adding a history to a NetworkStatsCollection.Builder
will overwrite any history that was previously passed in with the
same key. This breaks the importer (which is the primary/only
caller of this code), because the importer re-uses the same
NetworkStatsCollection object to import multiple files.

Instead, simply add any passed-in entries after the ones that
were already there. Require the caller to pass in entries in
order, because NetworkStatsHistory internally assumes that
entris are always sorted.

Bug: 230289468
Test: manually verified this unbreaks the importer
Change-Id: Ic8647ff28fca78d579d5f759f96a864877f8158b
Merged-In: Ic8647ff28fca78d579d5f759f96a864877f8158b
  (pure cherry-picked from ag/18453213)
2022-05-24 11:37:42 +08:00
Remi NGUYEN VAN
c62261f140 Ensure NetworkStats migrated snapshot is identical
Read migration snapshot both from the platform API and the legacy
method, and Log.wtf if they are different. Use the legacy method data if
they are.

This ensures that using the migration API is a no-op, and that errors
are reported (through Log.wtf) if it would not have been if used as-is.

Test: NetworkStatsServiceTest
Bug: 230289468
Change-Id: I857ad18183d63d1aa16e89f89eb24009648720a2
Merged-In: I857ad18183d63d1aa16e89f89eb24009648720a2
  (pure cherry-picked from ag/18452103)
2022-05-24 11:37:12 +08:00
Yan Yan
3ca3e7cf2d Merge "Throw IAE when Network's LinkProperties is null" am: 5345fa1144 am: b5a6b0118a
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2101892

Change-Id: I7f2663d1a67141b652204d6fcc97f936c2f68b33
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-23 17:59:34 +00:00
Yan Yan
be3eb3d56a Throw IAE when Network's LinkProperties is null
Improve the setUnderlyingNetwork method by throwing IAE
when Network's LinkProperties is null. Also update the
API doc to give caller more guidance in using this API

Bug: 232309601
Test: UT: IpSecServiceParameterizedTest, IpSecServiceTest,
      IpSecServiceRefcountedResourceTest, IpSecManagerTest, VpnTest
Test: CTS: IpSecManagerTest, IpSecManagerTunnelTest, Ikev2VpnTest
Test: make doc-comment-check-docs
Change-Id: Idab4706b0db42ed2222fb48b168589ed005d2f2f
2022-05-20 17:03:07 -07:00
Lorenzo Colitti
b36e57a004 Don't clobber existing history entries.
Currently, adding a history to a NetworkStatsCollection.Builder
will overwrite any history that was previously passed in with the
same key. This breaks the importer (which is the primary/only
caller of this code), because the importer re-uses the same
NetworkStatsCollection object to import multiple files.

Instead, simply add any passed-in entries after the ones that
were already there. Require the caller to pass in entries in
order, because NetworkStatsHistory internally assumes that
entris are always sorted.

Ignore-AOSP-First: in a topic with internal-only changes
Bug: 230289468
Test: manually verified this unbreaks the importer
Change-Id: Ic8647ff28fca78d579d5f759f96a864877f8158b
2022-05-18 23:51:03 +08:00
Remi NGUYEN VAN
3776d862e2 Ensure NetworkStats migrated snapshot is identical
Read migration snapshot both from the platform API and the legacy
method, and Log.wtf if they are different. Use the legacy method data if
they are.

This ensures that using the migration API is a no-op, and that errors
are reported (through Log.wtf) if it would not have been if used as-is.

Ignore-AOSP-First: in a topic with internal-only changes
Test: NetworkStatsServiceTest
Bug: 230289468
Change-Id: I857ad18183d63d1aa16e89f89eb24009648720a2
2022-05-18 23:51:03 +08:00
Junyu Lai
108d20f84a [MS81] Support remove history before cutoff timestamp
This is needed to ensure corrupted data can be clean up if
the data migration process dones't go well.

Test: NetworkStatsCollectionTest
Bug: 197717846
Change-Id: Ic76ad6f3e96f03791b48988fb2622c9c647ffc7c
(cherry picked from commit 306a00316c)
Merged-In: Ic76ad6f3e96f03791b48988fb2622c9c647ffc7c
2022-05-16 05:53:02 +00:00
Junyu Lai
306a00316c [MS81] Support remove history before cutoff timestamp
This is needed to ensure corrupted data can be clean up if
the data migration process dones't go well.

Test: NetworkStatsCollectionTest
Bug: 197717846
Change-Id: Ic76ad6f3e96f03791b48988fb2622c9c647ffc7c
2022-05-12 16:31:39 +08:00
Xiao Ma
b60e77f257 Unicast state of existing ethernet interfaces when registering new Ethernet Listener.
When adding a listener via the addInterfaceStateListener API, the
expectation is that ethernet service calls that listener immediately
with a list of all interfaces and their respective state. However,
this doesn't work as expectation due to the EthernetManager stores
all registered listeners within one global service listener class,
the new registered listener will be invoked until the state of any
interface has changed.

Instead of storing all registered listeners within one global service
listener class, associate each new registered listener to an instance
of IEthernetServiceListener, and pass it to the EthernetService, that
will be invoked when iterating the state of all existing interfaces.

In order to avoid the scanning of all registered listeners, that would
be slow if there are lots of registered callbacks, moving the service
listener to the ListenerInfo class, where the service listener can
access the executor and listener passed from the caller naturely,
unnecessary to iterate the whole list.

Bug: 229125889
Test: atest android.net.cts.EthernetManagerTest --iterations
Change-Id: I111eba78d1066794c414ab5fb4a31258ea311413
(cherry picked from commit bb9a49cf72)
Merged-In: I111eba78d1066794c414ab5fb4a31258ea311413
2022-04-30 14:42:45 +00:00
Xiao Ma
bb9a49cf72 Unicast state of existing ethernet interfaces when registering new Ethernet Listener.
When adding a listener via the addInterfaceStateListener API, the
expectation is that ethernet service calls that listener immediately
with a list of all interfaces and their respective state. However,
this doesn't work as expectation due to the EthernetManager stores
all registered listeners within one global service listener class,
the new registered listener will be invoked until the state of any
interface has changed.

Instead of storing all registered listeners within one global service
listener class, associate each new registered listener to an instance
of IEthernetServiceListener, and pass it to the EthernetService, that
will be invoked when iterating the state of all existing interfaces.

In order to avoid the scanning of all registered listeners, that would
be slow if there are lots of registered callbacks, moving the service
listener to the ListenerInfo class, where the service listener can
access the executor and listener passed from the caller naturely,
unnecessary to iterate the whole list.

Bug: 229125889
Test: atest android.net.cts.EthernetManagerTest --iterations
Change-Id: I111eba78d1066794c414ab5fb4a31258ea311413
2022-04-28 18:59:44 +09:00
Aaron Huang
d79f543df0 Merge "Fix NullPointerException happens in dumpCheckin" am: 6b7e457988 am: 44a02af11a am: a4d60dd2ad
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2059628

Change-Id: If9933b6aad05abf79e85f9172ba6eb6f8492d648
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-20 06:12:50 +00:00
Junyu Lai
57fc24937a Merge "Fix NetworkTemplate generates non-metered carrier template" am: 481b2649f7 am: d3a90fb206 am: e6616d1c7c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2064758

Change-Id: If215ccdeb8b7161939efb5d4bd3d9c7f994450bd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-20 06:08:16 +00:00
Aaron Huang
6b7e457988 Merge "Fix NullPointerException happens in dumpCheckin" 2022-04-19 11:43:21 +00:00
Junyu Lai
481b2649f7 Merge "Fix NetworkTemplate generates non-metered carrier template" 2022-04-19 10:18:26 +00:00
Aaron Huang
c3a43b4063 Fix NullPointerException happens in dumpCheckin
Currently dumpCheckin passes a null object to create
the contructor of NetworkStatsCollection.Key but the
constructor requires non-null object. Thus, it caused
the NPE in dumpCheckin. To fix this exception, create
an NetworkIdentitySet() object instead of using an
null object.

Bug: 225131008
Bug: 226539404
Test: dumpsys netstats --checkin is fine
      FrameworksNetTests
Change-Id: I7f2dadf0647b3f42e0f667d96291d2ae37e23faf
2022-04-19 17:49:30 +08:00
Junyu Lai
74f7c8c907 Fix NetworkTemplate generates non-metered carrier template
From current design, NetworkPolicyManagerService should only
creates metered carrier/mobile templates. However, if someone
calls the hidden API interface or the template was created
before NetworkTemplate#Builder is published. The caller may
create a non-metered carrier template and persist into the
storage.

This CL elimates this possibility and mark non-metered carrier
template non-persistable, so devices could auto-recover from
this symptom after reboot.

Fix: 222382637
Test: TH
Change-Id: I5265e371b0126ce65c32fb09a6e04223afb3d286
2022-04-18 16:41:54 +08:00
junyulai
0f54d64db2 Make some NetworkStats APIs system-current
Move iterator and NetworkStats.Entry getters to system-current
according to API council feedback. This reverts parts of
ag/17117903.

Test: TH
Fix: 225168182
  (cherry-picked from ag/17397294)
Change-Id: Ia7fdf8d31a96a26b0bf1682f462292b051560477
Merged-In: Ia7fdf8d31a96a26b0bf1682f462292b051560477
2022-04-11 18:45:36 +08:00
junyulai
44e61e2140 [MS83.1] Make some APIs module-lib instead of system current
Some of the internal classes are not available for priv-apps.
Thus, make them module-lib instead.

This change also adds some nullability annotations for existing
APIs according to go/android-api-guidelines.

Test: m
Test: m frameworks-base-api-system-current-compat
Fix: 217479745
  (cherry-picked from ag/17117903)
Change-Id: I18de46b11df7232ab82b9465856fdde621283156
Merged-In: I18de46b11df7232ab82b9465856fdde621283156
Merged-In: Ief3f2304f11b7940a18b98b8533fbca85ffa4dc1
2022-04-11 18:44:20 +08:00
Paul Hu
ac780d3bd0 Merge changes from topic "MDns_AIDL" am: 09475308b7 am: 06e59627bb
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2049246

Change-Id: I16b7ec71fbfee1dd0de84b1f64d5e9fbbd62f4e3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-07 03:10:55 +00:00
Paul Hu
09475308b7 Merge changes from topic "MDns_AIDL"
* changes:
  Use MDns aidl on NsdService
  Add MDnsManager
2022-04-07 02:06:35 +00:00
Maciej Żenczykowski
8a43622447 Merge changes Iafa8979d,I44eac159,I27ad3298 am: 6097358382 am: ec84e33d10
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2042596

Change-Id: I8f6867128057d092e916515049078c1d68b427a4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-06 01:20:45 +00:00
paulhu
2b9ed95ae5 Use MDns aidl on NsdService
- Use MDns aidl to communicate with mdns service and register
  event listener to receive callback.
- Remove all NDC relevant code on NsdService.
- Use MDns aidl on NsdServiceTest.

Bug: 209894875
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I65929dee3838fef753396e86c665abd66b6fec81
2022-04-04 15:18:27 +00:00
paulhu
541b72d03b Add MDnsManager
- Have MDnsManager to manage mdns native service binder call.
- Register it as a system service for NsdService.
- NsdService will use aidl to communicate with mdns, so add the
  relevant lib to framework-connectivity
- Add jarjar rule for mdns-aidl-interface classes.

Bug: 209894875
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: Ibc8b726c01a15015b450caf94d0afed570117b7f
2022-04-04 15:02:17 +00:00
Patrick Rohr
50c470e308 Address EthernetManager javadoc review comments
Test: TH
Change-Id: Iafa8979d8e96ea4d078b017e56ee61334d33b5f5
2022-04-04 14:59:42 +02:00
Patrick Rohr
0f2cbe92f1 Update javadoc to match expectation for UnsupportedOperationException
Test: builds
Change-Id: I44eac15972ed099fc12599a78a71557a7b16d593
2022-04-04 14:59:42 +02:00
junyulai
6801690383 Make some NetworkStats APIs system-current
Move iterator and NetworkStats.Entry getters to system-current
according to API council feedback. This reverts parts of
ag/17117903.

Ignore-AOSP-First: Parent CLs does not exist in aosp yet.
Test: TH
Fix: 225168182
Change-Id: Ia7fdf8d31a96a26b0bf1682f462292b051560477
2022-03-30 09:38:11 +00:00
Patrick Rohr
e38626a4a2 Merge "Add getInterfaceList module-lib API in EthernetManager." 2022-03-24 06:15:43 +00:00
Patrick Rohr
95738f7c18 Merge "Fix ethernet enable / disable API" 2022-03-24 06:09:28 +00:00
Xiao Ma
1edd4554e5 Add getInterfaceList module-lib API in EthernetManager.
Bug: 171872016
Test: m
Merged-In: Ib0e6c8f67c6ded7d17bb9e0ff49e7ff495c8819d
Change-Id: I94fd147d0f8cf09cb7445fd2b5bc8e4528e8390e
2022-03-22 13:59:40 +00:00
markchien
5912ab6906 Add setEthernetEnabled and its listener API
Bug: 171872016
Test: atest EthernetServiceTests

Merged-In: Iefd24d955572589c5bd3ca9a8139ea6e44979e8a
Change-Id: Iefd24d955572589c5bd3ca9a8139ea6e44979e8a
2022-03-22 13:58:14 +00:00
Aaron Huang
286f4e2c88 Merge "Fix proto invalid write type" 2022-03-22 12:18:39 +00:00
Patrick Rohr
3879cf1a78 Fix ethernet enable / disable API
The ethernet APIs connectNetwork() / disconnectNetwork() are
inaccurately named. Physical link state cannot be changed by calling an
API. This change renames these functions to enableInterface and
disableInterface, respectively, to better reflect their intention and
behavior.

Test: atest EthernetManagerPermissionTest
Merged-In: I3361ad0e01e761ffd77faf6c55924fa4612ede90
Change-Id: I3361ad0e01e761ffd77faf6c55924fa4612ede90
2022-03-22 12:12:48 +00:00