Commit Graph

317 Commits

Author SHA1 Message Date
nharold
73c55104e8 Merge changes from topic "ipsec-svc-cleanup" am: 9778c7884f am: 83d7776121 am: 4e793fd0b5
am: 869d47e66d

Change-Id: I7418f23141b26f23555397d231e8a73692c04085
2017-10-04 21:14:17 +00:00
nharold
869d47e66d Merge changes from topic "ipsec-svc-cleanup" am: 9778c7884f am: 83d7776121
am: 4e793fd0b5

Change-Id: Ib7eae5c9e223493281524e862979e16d25984dde
2017-10-04 20:53:04 +00:00
Nathan Harold
f69cb0a207 Split IpSecServiceTest to add IPv6 Tests
-Split IpSecServiceTest into parameterized
 and single tests.
-Add IPv6 parameters

Bug: 66954381
Test: this
Change-Id: Ib98c112560014f73bccc3d2842c31d297c7a07ef
2017-10-03 19:45:59 -07:00
Nathan Harold
4f4459d8c3 Add equals() for IpSecAlgorithm and IpSecConfig
Add equality testing methods to support tests
for parceling and un-parceling IpSecConfig.

Bug: 38397094
Test: runtest -x IpSecConfigTest.java
Change-Id: I31e318334d39ed6e9daf5ec8f3be7dcec75e12ad
2017-10-03 19:45:58 -07:00
Nathan Harold
bfbda18d48 Input Validation for IpSecService
All of the input to IpSecService over the Binder
interface needs to be validated both for sanity
and for safety.

-Sanity check all the parameters coming from binder.
-Added setters for IpSecConfig to decouple the test
 from the IpSecManager. This was needed because the
 input validation caused the tests to fail due to a
 null parameter that was previously un-tested.
-Added the mode flag to the IpSecConfig bundle this
 oversight was found during testing.
-Expose the getResourceId() methods for testing in
 UdpEncapsulationSocket, SecurityParameterIndex, and
 IpSecTransform classes.
-Remove the unneeded getIpSecConfig() from
 IpSecTransform: unneeded now that we can synthesize
 configs.

Bug: 38397094
Test: runtest frameworks-net
Change-Id: I5241fc7fbfa9816d54219acd8d81a9f7eef10dd4
2017-10-03 19:45:55 -07:00
Hugo Benichi
1cae2642ad Merge "DO NOT MERGE Ignore DUN in describeImmutableDifferences" into oc-mr1-dev
am: b2f4b2e05d

Change-Id: I0236132b8b497af5b1c26aa44e6494fe0510cb6d
2017-10-02 11:10:37 +00:00
Hugo Benichi
b2f4b2e05d Merge "DO NOT MERGE Ignore DUN in describeImmutableDifferences" into oc-mr1-dev 2017-10-02 10:57:01 +00:00
Hugo Benichi
a8565a7716 Merge "ConnectivityServiceTest: fix flaky testNetworkRequestMaximum" am: 1211941aa0 am: ca67954314
am: eced6cd14a

Change-Id: I53d0d6755c8e0be34db66da56efa483006e538ac
2017-10-02 10:51:21 +00:00
Hugo Benichi
2a84d1cbcf ConnectivityServiceTest: fix flaky testNetworkRequestMaximum
Registered requests are not keyed by PendingIntents in
ConnectivityService, which means that unregistering a request with a
PendingIntent causes a linear search in all registered requests.

testNetworkRequestMaximum was registering too many PendingIntents
simultaneously, causing the unregistration loop to have n^2
complexity and to take a long time to take effect.

To make the unregistering loop less likely to trigger a timeout on
waitForIdle, this patch changes the test to not register MAX_REQUEST
number of PendingIntent, but instead mixes a small number of
PendingIntents with NetworkCallbacks to reach MAX_REQUEST number of
simultaneously registered requests.

When unregistering these requests, callbacks are unregistered first.

Bug: 32561414
Test: runtest frameworks-net
Change-Id: I48b882c884abe20b388190b7f28baee293446f37
2017-10-02 17:37:57 +09:00
Hugo Benichi
7f9a223134 DO NOT MERGE Ignore DUN in describeImmutableDifferences
This patch changes describeImmutableDifferences in NetworkCapabilities
to ignore differences in NET_CAPABILITY_DUN, so that updateCapabilities
in ConnectivityService to not report wtf errors when a NetworkAgent
degrades its NetworkCapabilities object by removing NET_CAPABILITY_DUN.

Bug: 65257223
Test: runtest frameworks-net
Change-Id: I115ed1b366da01a3f8c3c6e97e0db8ce995fd377
2017-10-02 15:03:57 +09:00
Hugo Benichi
66749201a1 Merge "Fix NPE in NsdServiceTest" am: c30decbfe8 am: a9177b3748
am: a5d620ae92

Change-Id: Ieb299771438fe55566b76271815e52d02da799c8
2017-09-28 12:35:03 +00:00
Hugo Benichi
c30decbfe8 Merge "Fix NPE in NsdServiceTest" 2017-09-28 12:13:18 +00:00
Hugo Benichi
210ab83b77 Fix NPE in NsdServiceTest
Continuous test dashboards report that quit() can crash sometimes
due to mThread being null.

This patch adds a null guard in tearDown().

Bug: 32561414
Test: runtest frameworks-net
Change-Id: If66fb47e31e77d25b4741a786f12eb78f0b9102e
2017-09-28 15:22:13 +09:00
Lorenzo Colitti
f384a58f79 Merge "Delete the legacy framework code for manipulating ND offload." am: 3c0bf71eee am: fc56002707
am: bb21618a86

Change-Id: I07d9753e214af311d3dcab6f8016442f60388700
2017-09-27 11:05:29 +00:00
Lorenzo Colitti
3c0bf71eee Merge "Delete the legacy framework code for manipulating ND offload." 2017-09-27 10:46:36 +00:00
Lorenzo Colitti
d6cc68dab4 Merge "Declare support for Ethernet if the service is running." am: 21fcca6818 am: 5b906e1d11
am: a6648cc90b

Change-Id: Iafd9807ab76ce4e4ab1fd506d7b0e2b2b7017751
2017-09-27 08:51:51 +00:00
Lorenzo Colitti
2c9dd64d94 Declare support for Ethernet if the service is running.
On some devices, support for TYPE_ETHERNET is not specified in
the networkAttributes config resource, even though the device is
capable of supporting Ethernet (e.g., via USB host adapters).
This leads to Ethernet working but various connectivity APIs
behaving as if it was not - for example, no CONNECTIVITY_ACTION
broadcasts will be issues when it connects or disconnects.

Ensure that ConnectivityService always treats Ethernet as
available if the service is running. Currently the service is
started if the device supports FEATURE_ETHERNET or
FEATURE_USB_HOST.

(cherry picked from commit 7bbe3eee52c08ee92a81b7bed395ca5499554cc4)

Bug: 37359230
Test: bullhead builds, boots
Test: ConnectivityServiceTest passes
Test: Ethernet is available even if removed from networkAttributes resource
Test: ConnectivityManagerTest CTS test passes
Change-Id: I9b6db4edeaf966ee6715011dd92770b9d25dd938
Merged-In: I9b6db4edeaf966ee6715011dd92770b9d25dd938
2017-09-27 17:35:06 +09:00
Treehugger Robot
21fcca6818 Merge "Declare support for Ethernet if the service is running." 2017-09-27 08:23:34 +00:00
Lorenzo Colitti
19d4cd99f5 Delete the legacy framework code for manipulating ND offload.
This only worked on broadcom devices, and was superseded in
M by a wifi HAL call made by IpManager.

Test: bullhead builds, boots
Change-Id: I711cae7dafe171c2c8b4e84a229adbcad27f3d14
2017-09-27 16:47:36 +09:00
Lorenzo Colitti
23e9afc702 Declare support for Ethernet if the service is running.
On some devices, support for TYPE_ETHERNET is not specified in
the networkAttributes config resource, even though the device is
capable of supporting Ethernet (e.g., via USB host adapters).
This leads to Ethernet working but various connectivity APIs
behaving as if it was not - for example, no CONNECTIVITY_ACTION
broadcasts will be issues when it connects or disconnects.

Ensure that ConnectivityService always treats Ethernet as
available if the service is running. Currently the service is
started if the device supports FEATURE_ETHERNET or
FEATURE_USB_HOST.

Bug: 37359230
Test: bullhead builds, boots
Test: ConnectivityServiceTest passes
Test: Ethernet is available even if removed from networkAttributes resource
Test: ConnectivityManagerTest CTS test passes
Change-Id: I58801bf4f0bbdc3ff6345ec6bfdc911ce045c8ab
2017-09-27 13:03:10 +09:00
Hugo Benichi
883604a9fd Merge changes Ia47e566b,Ib94d79a9 am: d8eae0de70 am: 53eee16439
am: b91bd88c5e

Change-Id: Ied2b31c9d1219b8aebf5fec085ab598b77bede6e
2017-09-26 13:05:41 +00:00
Hugo Benichi
bf737c0a6b Extract RingBuffer class from NetdEventListenerService
This patch takes out the ring buffer array added for NFLOG wakeup packet
events logging and extract it into its own class for reuse. This new
RingBuffer class has the two minimal useful functions append() and
toArray().

Bug: 65164242
Bug: 65700460
Test: runtest frameworks-net, with new unit test
Change-Id: Ib94d79a93f4e99661b7d0fac67117b91d57af980
2017-09-26 14:14:16 +09:00
Erik Kline
0bbe489393 Merge "Also support 464xlat on SUSPENDED networks" am: 995a28d334 am: 698b2ee406
am: 1347ac8109

Change-Id: I83ae39a2e36bc036dce419c80dd476d2358b4537
2017-09-21 12:06:05 +00:00
Erik Kline
0b01b0f191 Also support 464xlat on SUSPENDED networks
Test: as follows
    - built
    - flashed
    - booted
    - runtest frameworks-net passes
Bug: 65684232

Change-Id: I1b10aab01554b1f926ec7157dba78645fdaff90f
2017-09-21 18:06:29 +09:00
Hugo Benichi
49289269b1 Merge changes Ied9d0cec,I3087f446,Ibe706872 into oc-mr1-dev
* changes:
  Wakeup packet events: addressing a few comments
  Connectivity metrics: add WakeupStats events
  Connectivity metrics: collect NFLOG wakeup events
2017-09-20 00:58:35 +00:00
Charles He
e25293089d Merge changes from topic "vpn-dialog" am: 85afa50569 am: b692194f38
am: a9f6384b6a

Change-Id: I853f48a75865008ac8b976eec1af56fb1870a1b3
2017-09-19 08:25:16 +00:00
Charles He
85afa50569 Merge changes from topic "vpn-dialog"
* changes:
  Unbreak VPN unit tests.
  Add alert dialog when always-on VPN disconnects.
2017-09-19 07:56:44 +00:00
Charles He
ca55d7bda7 Unbreak VPN unit tests.
VpnTest was broken earlier due to a change to always-on VPN
notifications. This CL adds the corresponding mocks to the unit test to
fix it.

Bug: 36650087
Bug: 65439160
Test: runtest frameworks-net
Change-Id: Icff57c7e927c135d75a7d70ff347a579c5d45134
Merged-In: Icff57c7e927c135d75a7d70ff347a579c5d45134
(cherry picked from commit 5da89994b9)
2017-09-19 07:56:36 +00:00
Charles He
65e8bd2e04 Merge changes from topic "always-on-vpn"
* changes:
  Opt-out for always-on VPN: rename API.
  Opt-out for always-on VPN
2017-09-19 07:50:13 +00:00
Hugo Benichi
17d5101e99 Merge "Wakeup packet events: addressing a few comments" am: efd7e6d7a9 am: ca88876b58
am: 19625788a1

Change-Id: I8ca2a01a95acaaca2599563efd6a21e4372d1f95
2017-09-19 07:36:12 +00:00
Hugo Benichi
6c35b8082c Wakeup packet events: addressing a few comments
This patch addresses a few post-submit comment for
commits f562ac34a51dc and 60c9f63b66921.

Bug: 34901696
Bug: 62179647
Test: runtest frameworks-net
Merged-In: I4abec57e0c6bc869dc57b5eb54582dd977b64c30

(cherry picked from commit 175b574e27daa0d8832b8cc9615a15fce998309a)

Change-Id: Ied9d0cec98685e5a91ed2ca2c81ad88d7ae8d751
2017-09-19 16:14:19 +09:00
Hugo Benichi
d4a29081c1 Wakeup packet events: addressing a few comments
This patch addresses a few post-submit comment for
commits f562ac34a51dc and 60c9f63b66921.

Bug: 34901696
Bug: 62179647
Test: runtest frameworks-net
Change-Id: I4abec57e0c6bc869dc57b5eb54582dd977b64c30
2017-09-19 14:07:47 +09:00
Hugo Benichi
611f62c6b9 Connectivity metrics: add WakeupStats events
This patch defines a new WakeupStats event in ipconnectivity.proto and
populates these events from the NFLOG wakeup events stored in
NetdEventListenerService.

There is one WakeupStats object per known interface on which ingress
packets arrive and may wake the system up.

Example from $ adb shell dumpsys connmetrics list:

...
WakeupStats(wlan0, total: 58, root: 0, system: 3, apps: 38, non-apps: 0, unrouted: 17, 6111s)
WakeupEvent(13:36:31.686, iface wlan0, uid -1)
WakeupEvent(13:38:50.846, iface wlan0, uid -1)
WakeupEvent(13:39:16.676, iface wlan0, uid 10065)
WakeupEvent(13:40:32.144, iface wlan0, uid 1000)
WakeupEvent(13:40:35.827, iface wlan0, uid 1000)
WakeupEvent(13:40:47.913, iface wlan0, uid 10004)
WakeupEvent(13:40:52.622, iface wlan0, uid 10014)
WakeupEvent(13:41:06.036, iface wlan0, uid 10004)
...

Bug: 34901696
Bug: 62179647
Test: runtest frameworks-net
Merged-In: Ie2676b20bfb411a1902f4942643df0c20e268d99

(cherry pick from commit 60c9f63b66926745603978e1bd6372b3a44561d1)

Change-Id: I3087f446fc998fc1ca895d975b80c4a1dd029bf3
2017-09-15 10:36:24 +09:00
Hugo Benichi
8b3f87160b Connectivity metrics: collect NFLOG wakeup events
This patch stores NFLOG packet wakeup events sent by Netd to the system
server into a ring buffer inside NetdEventListenerService. The content
of this buffer is accessible by $ dumpsys connmetrics or $ dumpsys
connmetrics list, and is added to bug reports.

The wakeup event buffer stores currently uid and timestamps.

Bug: 34901696
Bug: 62179647
Test: runtest frameworks-net, new unit tests

Merged-In: Ie8db6f8572b1a929a20398d8dc03e189bc488382

(cherry picked from commit f562ac34a51da55e4d15e34f0cd1cb597e7d926c)

Change-Id: Ibe706872a80dfd06abd9779a2116ca7e4bc0fb77
2017-09-15 10:35:17 +09:00
Hugo Benichi
46510068bc Merge changes I4719b4dc,I0308cdf4,I38db1bb7 am: e5090f2547 am: 1cbdfb6460
am: b025492a6b

Change-Id: I5385a3747e039a42e86034f7632edd0f855b2eb1
2017-09-14 18:11:06 +00:00
Hugo Benichi
b5141eb1d4 Merge changes Ie2676b20,Ie8db6f85 am: f33207512a am: 3b0c20458d
am: 7d16886c7e

Change-Id: Ifd0ace409909d258db3738e58126bbf1c48af5dc
2017-09-14 18:02:14 +00:00
Hugo Benichi
e5090f2547 Merge changes I4719b4dc,I0308cdf4,I38db1bb7
* changes:
  IpManagerTest: fix flaky test
  Fix flaky NsdManagerTest
  Boostrap test for NetworkMonitor
2017-09-14 11:59:58 +00:00
Hugo Benichi
3c15d11b94 Connectivity metrics: add WakeupStats events
This patch defines a new WakeupStats event in ipconnectivity.proto and
populates these events from the NFLOG wakeup events stored in
NetdEventListenerService.

There is one WakeupStats object per known interface on which ingress
packets arrive and may wake the system up.

Example from $ adb shell dumpsys connmetrics list:

UPDATEME
...
WakeupStats(wlan0, total: 58, root: 0, system: 3, apps: 38, non-apps: 0, unrouted: 17, 6111s)
WakeupEvent(13:36:31.686, iface wlan0, uid -1)
WakeupEvent(13:38:50.846, iface wlan0, uid -1)
WakeupEvent(13:39:16.676, iface wlan0, uid 10065)
WakeupEvent(13:40:32.144, iface wlan0, uid 1000)
WakeupEvent(13:40:35.827, iface wlan0, uid 1000)
WakeupEvent(13:40:47.913, iface wlan0, uid 10004)
WakeupEvent(13:40:52.622, iface wlan0, uid 10014)
WakeupEvent(13:41:06.036, iface wlan0, uid 10004)
...

Bug: 34901696
Bug: 62179647
Test: runtest frameworks-net
Change-Id: Ie2676b20bfb411a1902f4942643df0c20e268d99
2017-09-14 13:29:56 +09:00
Hugo Benichi
ce2d1859b2 Fix flaky NsdManagerTest
Bad synchronization between the mock handler and the test assertions
were causing testDiscoverService() to sometime fails (1/50 ~ 1/100 repro
rate).

Bug: 32561414
Bug: 62918393
Test: runtest frameworks-net, NsdManager#testDiscoverService now passes
      1000 times without errors.
Change-Id: I0308cdf48fc6bdc2fc9b4e8f7d5241a1cf2ea443
2017-09-13 18:38:53 +09:00
Hugo Benichi
454d55d822 Boostrap test for NetworkMonitor
This will finally allow to write captive portal detection unit tests.

Bug: 32561414
Bug: 62918393
Test: runtest frameworks-net
Change-Id: I38db1bb79ae80a82b4199dc9cb1b56257e0cf222
2017-09-13 16:21:50 +09:00
Hugo Benichi
802e27811c Connectivity metrics: collect NFLOG wakeup events
This patch stores NFLOG packet wakeup events sent by Netd to the system
server into a ring buffer inside NetdEventListenerService. The content
of this buffer is accessible by $ dumpsys connmetrics or $ dumpsys
connmetrics list, and is added to bug reports.

The wakeup event buffer stores currently uid and timestamps.

Bug: 34901696
Bug: 62179647
Test: runtest frameworks-net, new unit tests
Change-Id: Ie8db6f8572b1a929a20398d8dc03e189bc488382
2017-09-12 10:02:13 +09:00
Charles He
a05761a80b Opt-out for always-on VPN: rename API.
Rename the opt-out flag in AndroidManifest to
SERVICE_META_DATA_SUPPORTS_ALWAYS_ON
as directed by the API Council.

Bug: 64331776
Bug: 36650087
Test: runtest --path java/com/android/server/connectivity/VpnTest.java
Change-Id: I24326fad7a89083a2409134640bda81ee0359d08
Merged-In: I24326fad7a89083a2409134640bda81ee0359d08
(cherry picked from commit d681363fd1)
2017-09-08 10:47:34 +01:00
Charles He
738a0a48ab Opt-out for always-on VPN
Always-on VPN is a feature introduced in N. Since then, all VPN apps
targeting N+ are assumed to support the feature, and the user or the DPC
can turn on / off always-on for any such VPN app. However, a few VPN
apps are not designed to support the always-on feature. Enabling
always-on for these apps will result in undefined behavior and confusing
"Always-on VPN disconnected" notification.

This feature provides a new manifest meta-data field through which a VPN
app can opt out of the always-on feature explicitly. This will stop the
always-on feature from being enabled for the app, both by the user and
by the DPC, and will clear its existing always-on state.

A @hide API is provided to check whether an app supports always-on VPN.
Documentation is updated to reflect the behavior change.

Bug: 36650087
Test: runtest --path java/com/android/server/connectivity/VpnTest.java
Test: cts-tradefed run cts --module CtsDevicePolicyManagerTestCases --test 'com.android.cts.devicepolicy.MixedDeviceOwnerTest#testAlwaysOnVpnUnsupportedPackage'
Test: cts-tradefed run cts --module CtsDevicePolicyManagerTestCases --test 'com.android.cts.devicepolicy.MixedDeviceOwnerTest#testAlwaysOnVpnUnsupportedPackageReplaced'
Test: cts-tradefed run cts --module CtsDevicePolicyManagerTestCases --test 'com.android.cts.devicepolicy.MixedProfileOwnerTest#testAlwaysOnVpnUnsupportedPackage'
Test: cts-tradefed run cts --module CtsDevicePolicyManagerTestCases --test 'com.android.cts.devicepolicy.MixedProfileOwnerTest#testAlwaysOnVpnUnsupportedPackageReplaced'
Test: cts-tradefed run cts --module CtsDevicePolicyManagerTestCases --test 'com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testAlwaysOnVpnUnsupportedPackage'
Test: cts-tradefed run cts --module CtsDevicePolicyManagerTestCases --test 'com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testAlwaysOnVpnUnsupportedPackageReplaced'

Change-Id: I477897a29175e3994d4ecf8ec546e26043c90f13
Merged-In: I477897a29175e3994d4ecf8ec546e26043c90f13
(cherry picked from commit 9369e61e2d)
2017-09-08 10:18:36 +01:00
Rubin Xu
70b9208871 Always add local subnet routes to the interface's routing table
For some networks such as mobile data connections, its LinkProperties
does not contain routes for the local subnet so no such route is added
to the interface's routing table. This can be problematic especially
if the device is in VPN lockdown mode where there exists high-priority
PROHIBIT routing rule which in turn blocks the network's default gateway
route from being added (next hop address hitting the prohibit rule).

We fix this by patching LinkProperties to always include direct connected routes
when they are received by ConnectivityService. This has the added advantage that
when apps get LinkProperties, they see the directly connected routes as well.

Bug: 63662962
Test: runtest frameworks-core -c android.net.LinkPropertiesTest
Test: runtest frameworks-services -c com.android.server.ConnectivityServiceTest
Test: Start with device with mobile data, set up ics-OpenVPN in always-on
      lockdown mode. Turn off mobile data then turn it back on, observe
      mobile data connectivity is restored and VPN successfully reconnects.

(cherry picked from commit 1bb5c0818f0c4fb426e13b65a3ba3db7f36c3d88)

Change-Id: Ia14f88bcf49d37286519c26dff6b7180303e2cbe
2017-09-07 14:17:57 +01:00
Hugo Benichi
71449be2a7 IP connectivity metrics: fix tests after proto update
Update to ipconnectivity.proto in commit
6d2f506bfd788a3685292d404dc9d82a27357cfe broke the associated unit
tests (Change-Id: I4cf5b95956df721aecd63fddfb026a7266c190b9)

Bug: 34901696
Bug: 65439160
Test: runtest frameworks-net
Merged-In: I57a6bad8a9836b1c45690c4589b416786ce1dfa0

(cherry picked from commit 43b7474c08)

Change-Id: I98b23b2208bbd7d12237fcb000f3cf10c53d9e55
2017-09-07 22:17:18 +09:00
Rubin Xu
af3207c188 Merge "Always add local subnet routes to the interface's routing table" am: 609dd56140 am: 4bb100dcd0
am: e3469a426e

Change-Id: I21f4231c968b37cdcf1565279eedfb990dbc583b
2017-09-07 12:55:58 +00:00
Rubin Xu
ffd77d8f29 Always add local subnet routes to the interface's routing table
For some networks such as mobile data connections, its LinkProperties
does not contain routes for the local subnet so no such route is added
to the interface's routing table. This can be problematic especially
if the device is in VPN lockdown mode where there exists high-priority
PROHIBIT routing rule which in turn blocks the network's default gateway
route from being added (next hop address hitting the prohibit rule).

We fix this by patching LinkProperties to always include direct connected routes
when they are received by ConnectivityService. This has the added advantage that
when apps get LinkProperties, they see the directly connected routes as well.

Bug: 63662962
Test: runtest frameworks-core -c android.net.LinkPropertiesTest
Test: runtest frameworks-services -c com.android.server.ConnectivityServiceTest
Test: Start with device with mobile data, set up ics-OpenVPN in always-on
      lockdown mode. Turn off mobile data then turn it back on, observe
      mobile data connectivity is restored and VPN successfully reconnects.
Change-Id: I35b614eebccfd22c4a5270f40256f9be1e25abfb
2017-09-07 10:50:20 +01:00
Hugo Benichi
fa459ad7e2 Merge "Nat464Xlat: correct racefree teardown" into oc-mr1-dev 2017-09-05 22:35:45 +00:00
Hugo Benichi
45445770ab Nat464Xlat: correct racefree teardown
This patch relays the NetworkBaseObserver notifications about nat
464xlat stacked interfaces onto the ConnectivityService handler.

This allows to process interface up and down notifications in the
same thread context and eliminates several races:

  - NPE risk due to race between fixupLinkProperties called on
    ConnectivityService thread and interfaceRemoved called on
    NetworkManagementService thread.
  - stale LinkProperties pointer reads in both NetworkBaseObserver
    callbacks not called on ConnectivityService handler.
  - removes the race between stop() and interfaceRemoved().
  - removes superfluous LinkProperties notifications when stop() is
    called before the stacked interface goes up.

The teardown procedure logic common to stop() and interfaceRemoved() is
put into enterStoppedState() and enterIdleState().

This allows to distinguish and correctly handle the following teardown
scenarios:
 - an IPv4 appears -> ConnectivityService calls Nat464Xlat#stop()
                   -> Nat464Xlat calls stopClatd
                   -> clatd stops
                   -> if the stacked interface was up, it is removed
                   -> Nat464Xlat#interfaceRemoved() is triggered and
                      a LinkProperties update is sent.

 - network disconnects -> ConnectivityService calls Nat464Xlat#stop()
                       -> Nat464Xlat calls stopClatd
                       -> clatd stops
                       -> if the stacked interface was up, it is removed
                       -> Nat464Xlat#interfaceRemoved() is triggered and
                          a LinkProperties update is sent.

 - clatd crashes or exit -> Nat464Xlat#interfaceRemoved() is triggered
                         -> Nat464Xlat unregisters itself as a network
                            observer
                         -> ConnectivityService is updated about the
                            stacked interface missing, and restarts
                            Nat464Xlat if needed.

Note that the first two scenarios have two cases: stop() can be called
before the notification for the stacked interface going up (STARTED), or
after (RUNNING). In the first case, Nat464Xlat must unregister
immediately as a network observer to avoid leaks.

This patch also:
  - removes/simplifies comments related to the threading model which
    are no obsolete.
  - extract clatd management logic from ConnectivityService into
    NetworkAgentInfo
  - add new unit tests where there was none before.

Bug: 62918393
Bug: 62997041
Bug: 64571917
Bug: 65225023
Test: runtest frameworks-net
Merged-In: I27221a8a60fd9760b567ed322cc79228df877e56
Merged-In: I8f07dfbe5ea8259ff9f5793503f534945e67ad74
Merged-In: I8612db5e5050690db8cf41dd04944b4c22da340c
Merged-In: Icb2dc8229b5ea45e319233b588f2dbe39ea40d4c
Merged-In: Ibafea69224e832a6316c17dbb9b2d62a233088ac

(cherry picked from commit ef502887ec58886e9347afb841aa06cb0d13acea)

Change-Id: I9d075048873b0e1c5ed45b5674ada3fb303c2bfb
2017-09-05 22:12:01 +09:00
Hugo Benichi
646a1a4fb2 Merge "Nat464Xlat: correct racefree teardown" am: 4112ecb7a6 am: 403c46dadf
am: e92029d894

Change-Id: Ibafea69224e832a6316c17dbb9b2d62a233088ac
2017-09-05 13:06:59 +00:00