Commit Graph

2598 Commits

Author SHA1 Message Date
Lorenzo Colitti
65f957399f Update the avoid bad wifi settings on the handler thread.
am: 21924545a2

Change-Id: I595949881353f5779ed2bb55ff05f27b513cd6de
2016-09-16 17:32:09 +00:00
Lorenzo Colitti
21924545a2 Update the avoid bad wifi settings on the handler thread.
Currently, every call to avoidBadWifi fetches the current value
of the config variable and setting whenever it is called. This
means that the score of an unvalidated wifi network can
unpredictably change at any time, creating a data race.

Instead, persist the value and only update it when something
changes.

Bug: 31075769
Change-Id: I0f4e0e742c91ef77fabc95d3ebb494338396aca5
2016-09-17 00:57:38 +09:00
Lorenzo Colitti
26b930e3c7 Unit tests for avoid bad wifi networks setting.
am: 83633c897a

Change-Id: I6491f1a93f93f222e23ef6e5e437631556637e44
2016-09-15 16:05:45 +00:00
Lorenzo Colitti
2b5b0e027b Support displaying a dialog when wifi becomes unvalidated.
am: 199ecfc79f

Change-Id: I8b8e2b652510ca75407a9ad3c29ed111367941e0
2016-09-15 16:04:03 +00:00
Hugo Benichi
6630a620f9 Support ignoring penalty for bad wifi networks
am: c9048bc556

Change-Id: I6666ee45e9a08c02444c6268b2232bbe8aa2adec
2016-09-15 15:23:57 +00:00
Lorenzo Colitti
83633c897a Unit tests for avoid bad wifi networks setting.
Bug: 31075769
Change-Id: I21ba20df59ddce5731ef1ebe8846b3f00578a674
2016-09-15 23:45:07 +09:00
Lorenzo Colitti
199ecfc79f Support displaying a dialog when wifi becomes unvalidated.
Bug: 31075769
Change-Id: I7a6e7580769365bea930f638bd44edcaa28df134
2016-09-15 23:33:34 +09:00
Lorenzo Colitti
8121c2d0aa resolve merge conflicts of bbc1519 to nyc-mr1-dev
Change-Id: Ib1294563c6ae20454e44bfa5fc9fb2797864b8f5
2016-09-15 22:47:08 +09:00
Hugo Benichi
c9048bc556 Support ignoring penalty for bad wifi networks
This patch adds a way to configure devices so that a validated network
that becomes unvalidated is not penalized in the network scoring and
selection logic.

The intent is to prevent devices configured to do so from switching to a
lower scoring network such as cellular networks when a higher scoring
network such as wifi networks loses internet connectivity.

Bug: 31075769
Change-Id: Ie7e0f2607d214a178367fedfbef6c44768fa00a4
2016-09-15 18:34:13 +09:00
Hugo Benichi
bbc15194de Explicitly pass old score to updateCapabilities
This allows simplification of getCurrentScore function in
NetworkAgentInfo and its return value to depend on everValidated and
lastValidated.

Bug: 31075769
Change-Id: I0b3c85e3a61b006733e900e0a231424878317476
2016-09-15 18:33:23 +09:00
Lorenzo Colitti
d8a23ad61f Add test coverage for background networks.
Bug: 23113288
Change-Id: Idad62f5f025825f99007ccf7b20f530dc3cf6daa
2016-09-13 12:02:13 +09:00
Lorenzo Colitti
0f04220ffe Add a NET_CAPABILITY_FOREGROUND capability.
Bug: 23113288
Change-Id: I90cb9ffb5751f0d9ec822933f37680c401e49966
2016-09-13 12:02:13 +09:00
Lorenzo Colitti
2666be8ae7 Add a background NetworkRequest type for mobile data always on.
Like a normal (foreground) request, a background request is only
satisfied by one network and will keep that network up. Unlike a
foreground request, when a network only has background requests,
it will linger, and after lingering is complete, it will become
a background network.

Future CLs will cause the system to treat background networks
differently, e.g., by requiring different permissions.

Bug: 23113288
Change-Id: I40f735269dad1042eb04fea15e64584fc903ccb3
2016-09-09 18:49:24 +09:00
Lorenzo Colitti
0c38d7c8cd Rematch requests first and listens second.
This CL splits rematching in two parts: first rematch requests,
then rematch listens. This will allow us to change a network's
capabilities depending on what requests are on that network, and
properly dispatch callbacks depending on those capabilities.

The behaviour changes are as follows:

- Before this CL, callbacks for requests and listens were sent
  intermingled. After this CL, all request callbacks will be
  grouped together, and all listen callbacks will be grouped
  together.
- Before this CL, the order was:
    1. Send onLost callbacks.
    2. If applicable, switch the default network.
    3. Send onAvailable callbacks.
  After this CL, the order is:
    1. Send onLost callbacks for requests.
    2. If applicable, switch the default network.
    3. Send onLost callbacks for listens.
    4. Send onAvailable callbacks for listens.
    5. Send onAvailable callbacks for requests.

These changes shouldn't affect any apps because:

1. The order of callbacks continues to be first all onLost,
   then all onAvailable.
2. Both the old and the new code send callbacks in no particular
   order. Thus, the possible ordering combinations of callbacks
   in the new code are a strict subset of the possible ordering
   combinations of the old code.
3. The default network is switched before any onAvailable
   callback is sent.
4. Even though the new code does not send all onLost callbacks
   before switching the default network, even before this CL
   there was no guarantee that those callbacks would be received
   before the default network switch anyway, because callbacks
   are asynchronous.

Bug: 23113288
Change-Id: Ia08900c50db9ff43895047e2f4f36b6c6c31a1f9
2016-09-09 18:28:00 +09:00
Lorenzo Colitti
9bf6fef270 Network switch notifications: rate & daily limits
This patch adds a daily limit to the maximum number of notifications
shown when switching networks.

It also adds a rate limit to prevent rapid successive notifications in
flapping scenarios.

Bug: 31132499
Change-Id: Iccb6d0899646ea6df3cfad32a421922263e0eb85
2016-08-31 00:36:11 +09:00
Hugo Benichi
01f7228f5c Network Switching Notifications: add unit tests
BUG: 31132499
Change-Id: I9c50a59fe48efdcb51d2517f0a756691700c3ebe
2016-08-31 00:35:16 +09:00
Lorenzo Colitti
fde640e59d Don't notify on network switch if source network is validated.
Sometimes we switch away from a network to another (e.g., wifi to
cell data) not because the old network is unvalidated, but
because the score is lowered by a low signal strength.

In this case, don't notify the user of a network switch.

Bug: 31132499
Change-Id: I996a6e00096f8cb864fa9b00b36921725a4edb53
2016-08-29 16:30:21 +09:00
Lorenzo Colitti
ddc5fd88fe Support notifying network switches via notifications and toasts.
Bug: 31025214
Change-Id: If1578f422f38a1dcfaec529882aed01ae5e8d53c
2016-08-25 18:14:18 +09:00
Lorenzo Colitti
c5391028ec Refactor NetworkNotificationManager.
1. Move from deprecated network types to transport types.
2. Rename and simplify (by passing in a NetworkAgentInfo object)
   the call signature of the method that displays notifications.
3. Add a method to clear notification, and unindent lots of code.
4. Move the legacy DcTracker-issued notification code to
   NetworkNotificationManager.

Bug: 31025214
Change-Id: Ie49c60126d0ed5bac620bc47e84fe038791b2d6c
2016-08-23 17:57:46 +09:00
Lorenzo Colitti
74c205f5ea Move notification code out of ConnectivityService.
Bug: 31025214
Change-Id: I4190be6b57f92298b79bea8868f1876ecbfd2d75
2016-08-23 15:31:59 +09:00
Hugo Benichi
208c01039f IpConnectivityMetrics: no metrics upload in tests
Similarly to ApfTest, this patch changes ConnectivityServiceTest to use
a mock object instead of IpConnectivityLog so that running
ConnectivityServiceTest does not generate android.net.metrics events.

Bug: 30450301
Change-Id: Ibc0479f381f26e60baefbae15407c62aecbf6666
2016-07-29 16:58:35 +09:00
Hugo Benichi
bd0cc763ae Add CONNECTIVITY_USE_RESTRICTED_NETWORKS permission
This patch creates a new permission used by ConnectivityService to give
access to restricted networks without the NET_CAPABILITY_NOT_RESTRICTED
capability bit on.

Bug: 24497316
Change-Id: I5b6c8a9ef14395b2f1ab26cb17b24d7876ec79f1
2016-07-25 10:24:42 +09:00
Lorenzo Colitti
3ed97e63bb Add an isListen method to NetworkRequests.
This allows simplification of the ConnectivityService code.

Bug: 23113288
Change-Id: I124544b99c5a920124e9a3d31cda8c6d2abc21fd
2016-07-18 18:42:26 +09:00
Erik Kline
6f0405308b Add IPv6 tethering coordinator
Add an IPv6TetheringCoordinator to TetheringMaster StateMachine, which
receives and processes NetworkState updates and passes the necessary IPv6
information to the revelant TetherInterfaceStateMachine.

Add an IPv6TetheringInterfaceServices to TetherInterfaceStateMachine, which
is responsible for adding local network routes and managing an IPv6
RouterAdvertisementDaemon.

Bug: 9580643
Change-Id: I3eaae460b80752e2115359d7bde873a1e9ea515a
2016-07-13 12:08:06 +09:00
Hugo Benichi
d159fdd226 ConnectivityService dump: add apps blocked logs
This patch adds NetworkInfo BLOCKED/UNBLOCKED status of apps to
ConnectivityService's dump logs.

The BLOCKED or UNBLOCKED status of an app is logged with the app uid
when the app calls getActiveNetworkInfo().

Examples:
mNetworkInfoBlockingLogs (most recent first):
  07-11 11:04:43.139 - BLOCKED 10060
  07-11 11:04:39.056 - UNBLOCKED 10061
  07-11 11:04:38.851 - BLOCKED 10061

Bug: 29981766
Change-Id: I6e2fde446702b92b0964ed894409b5d733d8f8a7
2016-07-12 11:39:48 +09:00
Erik Kline
0c04b74781 Support requesting async LinkProperties/NetworkCapabilities updates
Bug: 9580643
Change-Id: I1d7ba7645c20d7d53f6eef777dfce43727940f13
2016-07-11 19:17:41 +09:00
Erik Kline
1a1cb0e914 Basic IPv6 Router Advertisement daemon
Bug: 9580643
Change-Id: Iebd4d1f694699ffd4daf7d71e9b9d8f49e9b632f
2016-07-11 18:37:25 +09:00
Lorenzo Colitti
673bdd122b Merge "Rewrite lingering." into nyc-mr1-dev 2016-07-07 10:55:39 +00:00
TreeHugger Robot
0ecfb2fd34 Merge "ConnectivityManager: no double callback remove" into nyc-mr1-dev 2016-07-07 09:33:35 +00:00
TreeHugger Robot
ef9c83a171 Merge "Prepare to delete useless loop in handleReleaseNetworkRequest." into nyc-mr1-dev 2016-07-07 07:33:07 +00:00
Lorenzo Colitti
79869eac2f Rewrite lingering.
The two major changes here are:

- Move lingering out of NetworkMonitor. The fact that lingering
  is currently its own state in NetworkMonitor complicates the
  logic there: while a network is lingering it cannot be in any
  other state, we have to take care not to leave LingeringState
  for the wrong reason, etc.
- Instead of keeping a single per-network boolean to indicate
  whether a network is lingered or not, keep a linger timer for
  every request. This allows us to fix various corner-case bugs
  in lingering.

The changes in behaviour compared to the current code can be seen
in the unit test changes. Specifically:

1. Bug fix: when a network is lingered, and a request is added
   and removed to it, the existing code tears the network down
   immediately. The new code just sends another CALLBACK_LOSING
   and resumes lingering with the original timeout.
2. Bug fix: if cell is unvalidated and wifi comes up and
   validates before cell does (as might happen on boot), the
   existing code immediately tears down cell. The new code
   lingers cell, which is correct because unvalidated cell was
   the default network, so an app might have been using it.
3. Correctness improvement: always send CALLBACK_AVAILABLE for
   the new network before sending CALLBACK_LOSING. This was not
   really an issue in practice, because the usual flow is:
    - Network A is the default.
    - Network B connects, CALLBACK_AVAILABLE.
    - Network B validates, CALLBACK_LOSING.

Bug: 23113288
Change-Id: I2f1e779ff6eb869e62921a95aa9d356f380cf30a
2016-07-07 16:18:57 +09:00
Lorenzo Colitti
a68fb676e6 Prepare to delete useless loop in handleReleaseNetworkRequest.
As explained in the TODO, the loop serves no purpose since only
one network can be satisfying a given request at a time.

Instead of looping, look up the nai in the mNetworkForRequestId
array that exists for this purpose.

Keep the loop around with an Slog.wtf statement on it so we can
see if we ever hit it, and add a TODO to delete it if we don't.

Bug: 23113288
Change-Id: I173de4bd45c5a4169b7a062a981f2ecccaa44143
2016-07-07 14:50:12 +09:00
Lorenzo Colitti
27ca325de9 Merge \"Make registerDefaultNetwork work on metered networks.\" into nyc-dev
am: 33cdc4d136  -s ours

Change-Id: Iacee53c01e7de163e677ab57bc2d7044f8aff952
2016-07-07 01:24:58 +00:00
Hugo Benichi
f778e2546f ConnectivityManager: no double callback remove
This patch partially undoes ag/869831 (Change-Id:
Ia42ed7aefaebd8caf3eada8e42b6cb7a940d7647) so that ConnectivityManager
does not remove callbacks from its internal request-to-callback map at
unregistration, but instead let the singleton CallbackHandler do it when
receiving a CALLBACK_RELEASED from ConnectivityService.

ag/869831 was thought to fix b/26749700 that reported a callback leak
from sNetworkCallback, but a finer analysis of the code shows that
callbacks were correctly removed by the CallbackHandler before
ag/869831. There was therefore no callback leak.

Bug: 26749700
Bug: 28537383
Change-Id: I421d889d0e225c0e3d1eebea664f44a1cc0f3191
2016-07-07 09:44:02 +09:00
TreeHugger Robot
833c839f0b Merge "Add test coverage for a bug in the lingering code." into nyc-mr1-dev 2016-07-05 03:35:40 +00:00
Lorenzo Colitti
0271c0d4ef Merge "Unbreak unregisterNetworkCallback." into nyc-mr1-dev 2016-07-05 02:07:06 +00:00
Lorenzo Colitti
70964d3a18 Unbreak unregisterNetworkCallback.
http://ag/1194313 broke unregisterNetworkCallback because the
system does not parcel the type of the request back to the app.
So when the app calls unregisterNetworkCallback, the
NetworkRequest that's passed in does not have a type and thus
doesn't match the request in mNetworkRequests.

Fix this by parceling over the type as well.

This was not caught by the unit test because the unit test all
runs in the same process with no parceling.

Bug: 23113288
Change-Id: I58b2ed651b9bf5cbdcca5b25c3ca24db53cffdf1
2016-07-05 01:59:49 +09:00
TreeHugger Robot
50d08eec57 Merge "Annotate public methods in ConnectivityService." into nyc-mr1-dev 2016-07-04 16:07:33 +00:00
Lorenzo Colitti
5c1bf510fb Make registerDefaultNetwork work on metered networks.
Bug: 29927488
Change-Id: I3b705c2ab0d1493546ffa5185bb5b07d5e25c897
2016-07-04 23:18:12 +09:00
Lorenzo Colitti
b5b9c71870 Add test coverage for a bug in the lingering code.
Bug: 23113288
Change-Id: I573ee5908b9d973931234eb7d2db8ea0aaa4b31e
2016-07-04 17:00:27 +09:00
Lorenzo Colitti
d645909273 Annotate public methods in ConnectivityService.
Ensure every public method is annotated with why it's public.
This can be either an @Override or @VisibleForTesting annotation
or a comment explaining why it's public.

Bug: 29927488
Change-Id: I3582aef7997dc0d723718ca5e3dd115647d22979
2016-07-04 12:58:29 +09:00
Lorenzo Colitti
99236d14e3 Make the NetworkRequest list private to NetworkAgentInfo.
This allows us to keep track of how many live requests a network
is satisfying without having to count them every time.

Bug: 23113288
Change-Id: Ic4756676491e09071dbf80b7c48da3be028d68eb
2016-07-01 21:14:26 +09:00
Lorenzo Colitti
eafe85717c Move the request type from NetworkRequestInfo to NetworkRequest.
This will allow us to simplify code that deals with
NetworkRequests outside ConnectivityService.

Bug: 23113288
Change-Id: I9b3a859d0c68cad73d7f6baa4b584d13ffd2ae36
2016-07-01 20:15:19 +09:00
Lorenzo Colitti
ecd8ec7141 Make registerDefaultNetwork work on metered networks.
Bug: 29927488
Change-Id: I3b705c2ab0d1493546ffa5185bb5b07d5e25c897
2016-07-01 04:42:58 +00:00
Lorenzo Colitti
2dfee89086 Add detailed test coverage for lingering.
Bug: 23113288
Change-Id: I65784f3589378d97f3c824e600f21f361be8741e
2016-06-30 21:42:17 +09:00
Lorenzo Colitti
6dcf2e24c5 Add more test coverage for requests and callbacks.
1. Support multiple callbacks in TestNetworkCallback. This is
   necessary to test situations where multiple callbacks are
   generated by the same event (e.g., CALLBACK_LOSING on cell
   with CALLBACK_AVAILABLE on wifi when wifi connects), which is
   necessary to test callback order. So far this has not been
   covered because all callback testing was using per-network
   callbacks.
2. Add a benchmark test for registering NetworkRequests and for
   sending onAvailable and onLosing callbacks.

Bug: 23113288
Change-Id: Ib69373358ad766ab1bd989e864a5a51ef762c73c
2016-06-30 13:18:12 +09:00
Hugo Benichi
8fe7f1e666 Adding tests for DnsEventListenerService
Bug: 29035129
Change-Id: Iaf0d9ec781da7a473b6f7d8623060ecde44b9cbd
2016-06-29 14:28:51 +09:00
Hugo Benichi
be0c7651f6 Refactor IP connectivity event logging
This patch removes static methods for logging IP connectivity events
defined in android.net.metrics and replaces them with a single log()
instance method defined on IpConnectivityLog. Event constructors are
now public also. Every classes logging such events now create an
instance of IpConnectivityLog for logging event objects directly
instantiated with new.

Removing static dependencies allow straightforward testing of logging.

This patch also removes the base IpConnectivityEvent class which is not
needed any more.

Bug: 29035129
Change-Id: I3de700f93f46deaa48a759f938f7d00e1d8bff98
2016-06-29 14:28:51 +09:00
Hugo Benichi
389633f8d2 Fix unsafe concurrent access in LegacyTypeTracker
This patch adds synchronization inside LegacyTypeTracker so that
getNetworkForType() can safely run concurrently with remove().

Without synchronization if remove() removes the last network for a
given type while getNetworkForType() runs for the same type, it is
possible that getNetworkForType tries to access the head of an empty
list, resulting in a runtime exception.

This issue was found by zoran.jovanovic@sonymobile.com who proposed a
fix in AOSP (Change-Id: Ia963662edb9d643790e8d9439e4dbdcac4c2187b).

This patch differs from the fix proposed by the bug reporter and tries
instead to do the minimum amount of locking to make getNetworkForType
safe.

Bug: 29030387
Change-Id: I915aac527fc8828b32bf35fee870add2dfb11d8d
2016-06-27 15:04:27 +09:00
Felipe Leme
22bac76a06 resolve merge conflicts of fa2715e to nyc-mr1-dev
Change-Id: If0a1e7e70aa33e99f05694a37c2a54c567449507
2016-06-21 13:12:53 -07:00