Commit Graph

2558 Commits

Author SHA1 Message Date
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
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
Felipe Leme
0a5ae42e45 Ignore system apps on enforceMeteredApnPolicy().
BUG: 29514913
Fixes: 29448383
Change-Id: I19eb004c937e1c872bbf82caa7a919e43d48a259
2016-06-20 17:15:46 -07:00
Robin Lee
f2235f1a75 Merge \"Move \'is already always-on\' check into Vpn.java\" into nyc-dev
am: c32921dcda

Change-Id: I6532f2e654cfd9df8ee6c649344b0b915a8381c1
2016-06-16 10:10:23 +00:00
Robin Lee
c32921dcda Merge "Move 'is already always-on' check into Vpn.java" into nyc-dev 2016-06-16 10:06:11 +00:00
Robin Lee
8631caa822 Move 'is already always-on' check into Vpn.java
It's with the rest of the logic now and allows checking whether the
lockdown state matches, too, which led to a lot of misunderstandings.

Fix: 29199431
Change-Id: I94a2c38c4837f9c33b5b9c2becb52eeb7e2a2534
2016-06-14 13:24:17 +00:00
Paul Jensen
3ed407344a Merge \"Show sign-in to network notification to all users, not just owner.\" into nyc-dev
am: fa7453ed47

Change-Id: I4522f765c6166bd1c8216088b1605eac4c69d869
2016-06-14 11:16:12 +00:00
Paul Jensen
fa7453ed47 Merge "Show sign-in to network notification to all users, not just owner." into nyc-dev 2016-06-14 11:05:32 +00:00
Paul Jensen
b31cfb423c Show sign-in to network notification to all users, not just owner.
All users should be made aware a captive portal is in place and be
given the opportunity to sign into the network.  Without this fix
other users are not notified and given a chance to sign-in.

Change-Id: I1bf823d5f6a36f391dca4be5f6a584e8562a72a7
Fixes: 23079964
2016-06-13 09:39:28 -04:00
Robin Lee
a21c500b58 Merge \"Package changed/removed listeners for always-on VPN\" into nyc-dev
am: ee5e4cc836

Change-Id: I8f7054b5a2ac69677a0e124e9a616b3d58b604af
2016-06-08 10:50:42 +00:00
TreeHugger Robot
c5447626d7 Merge changes Ic98e3bcb,Idb0c55fc,Ia8649061,I5e7e5a87 into nyc-mr1-dev
* changes:
  Give WakeupMessage the ability to transport an object as well.
  Don't treat the lingerExpired broadcast specially.
  Add a test for mobile data always on.
  Add a FakeSettingsProvider and use it in ConnectivityServiceTest.
2016-06-08 06:35:32 +00:00
Lorenzo Colitti
e9a96608a9 Don't treat the lingerExpired broadcast specially.
NetworkMonitor no longer uses the broadcast for lingering, it
uses WakeupMessage instead.

Bug: 23113288
Change-Id: Idb0c55fc68cb8f45b3213c7134213904f227852e
2016-06-08 14:09:07 +09:00
Lorenzo Colitti
9fc66e020a Add a test for mobile data always on.
Bug: 23113288
Change-Id: Ia8649061a797367d135bb5576600a7cdc85a822e
2016-06-08 14:08:59 +09:00
Lorenzo Colitti
72d0da9899 Add a FakeSettingsProvider and use it in ConnectivityServiceTest.
This class makes it easier to test code that uses Settings:

1. Real device or emulator settings don't affect the code under
   test; all settings always start off empty.
2. It's possible to change settings from the test without
   affecting system settings.
3. No changes are needed to the code under test. The changes to
   the tests are simple: just add a fake ContentResolver to
   whatever mock Context is already used by the test, and make
   that ContentResolver use the fake provider.

Bug: 23113288
Change-Id: I5e7e5a87571444ae49ccf551705620675a36cd17
2016-06-08 14:05:55 +09:00
Robin Lee
1a0a77ba10 Package changed/removed listeners for always-on VPN
Fix 2 problems of always-on vpn after always-on package is removed
1. Prevent network being locked down (blocking all network traffic)
   Otherwise, user has no way to download the vpn app from Play Store,
   and never be able to gain control of the network again.
2. Allow user to connect other vpn app.

Implementation
1. Switch off always-on mode if the package gets removed.
2. Restart always-on mode if the package gets replaced/upgraded.

Bug: 29050764
Change-Id: Id3e389ae0b11c6002a5167919292d9634c2014cb
2016-06-06 15:42:50 +00:00
Paul Jensen
1209aef1ad Merge "Include network name in validation logs for dumpsys" into nyc-dev
am: 716fa18dcb

* commit '716fa18dcb00d78d98850c3eb0ce3f2963b3ce13':
  Include network name in validation logs for dumpsys

Change-Id: Ic5345cb7f309e509c7b9d7cb7b7ec4b95b8f1102
2016-06-06 11:23:51 +00:00
Paul Jensen
716fa18dcb Merge "Include network name in validation logs for dumpsys" into nyc-dev 2016-06-06 11:08:45 +00:00
Victor Chang
508eec87ac Merge "Fix that fail to setup any vpn after Network Settings reset and always-on vpn is on" into nyc-dev
am: 265f4113ee

* commit '265f4113ee42e89f324b087a81044a9f1dab457e':
  Fix that fail to setup any vpn after Network Settings reset and always-on vpn is on

Change-Id: I86a8f5c9b2dbd8ea71bdc8fb6268f3d9dc7e329d
2016-06-06 10:30:42 +00:00
fionaxu
5310c30967 cold sim clean up
- add a new field: provisioningNotificationEnabled from NetworkMisc. set
  to false if we want to hide "sign in" notification and placed
  carrier-specific notification instead. it is set on connect, once set,
  it is carrier-app's responsibility to post new UI to users
- rework on the interaction between carrier app and framework
- code cleanup
- unit test support

Bug: 28567303
Change-Id: Ic84db7ffbb920d15344717f104496d3cb82e1a85
2016-06-03 11:45:12 -07:00
Paul Jensen
5912c7b350 Include network name in validation logs for dumpsys
Previously this was included in the log messages from NetworkMonitor
but that has been removed (ag/944107), making it frequently impossible
to know what network the logs apply to as there may be no way to
correlate NetIDs to WiFi SSIDs or Cellular networks if the log has wrapped.

Bug: 26075613
Change-Id: I2e3cd41fffb616ab9f855cb16790360bd3414793
2016-06-03 13:51:21 -04:00
Victor Chang
a81567b746 Fix that fail to setup any vpn after Network Settings reset and always-on vpn is on
Cause: It revoked the user consent of the vpn app without reseting always-on vpn.
In addition, prepareVpn sets legacy vpn as the current package, the state in
Vpn.class is broken, as it thought the current always-on package is legacy vpn,
(mAlwaysOn is only for app vpn, not for legacy vpn). As a result, prepareVpn rejects
all VpnService.prepare.

Bug: 29031820
Change-Id: Id6bf1d6f38cf134a872811806301b8a602fb5725
2016-06-03 17:14:32 +01:00
Robin Lee
4fb4490dfb Merge "Return legacy VPN info regardless of lockdown mode" into nyc-dev 2016-05-25 21:05:55 +00:00
TreeHugger Robot
3e0e975a38 Merge "API council feedback: hide and document." into nyc-dev 2016-05-25 20:43:56 +00:00
Hugo Benichi
c6246b996d Merge "Fix default network transition event recording" into nyc-dev 2016-05-25 03:22:32 +00:00
Hugo Benichi
d3e4645858 Fix default network transition event recording
When disconnecting from a default network X and falling back on another
connected network Y as the new default, ConnectivityService was
attempting to record this event as a X -> Y "atomic" transition.

In practice the default network connectivity is actually lost and
recovering default network takes some non-zero time.

This patch changes the event recording to always record disconnection as
X -> 0 events. At the same time, if there is a fallback network that is
elected as the new default ConnectivityService will also record a 0 -> Y
event.

This patch also improves pretty-printing of DefaultNetworkEvent.

Extract from $ adb shell dumpsys connectivity_metrics_logger --events
17:51:00.086: DefaultNetworkEvent(0 -> 100:CELLULAR)
17:51:25.232: DefaultNetworkEvent(100:IPv4 -> 101:WIFI) # wifi goes on
17:51:44.064: DefaultNetworkEvent(101:DUAL -> 0)        # wifi goes off
17:51:44.187: DefaultNetworkEvent(0 -> 100:CELLULAR)

Bug: 28204408
Change-Id: I63252633235bf6ba833b9ac431a80dda75a93e67
2016-05-25 10:03:38 +09:00
Felipe Leme
5902c444d7 Fixed enforceMeteredApnPolicy when Data Saver is on.
When enforceMeteredApnPolicy() is called when Data Saver mode is on and
the caller's UID is not whitelisted, it should add a
NET_CAPABILITY_NOT_METERED to the capabilities.

Change-Id: Ieed4f4a7634ee023ec58c91859263655e0ba62d4
Fixes: 28608499 (and https://code.google.com/p/android/issues/detail?id=208478)
2016-05-23 09:43:53 -07:00
Jeff Sharkey
ca4340007e API council feedback: hide and document.
Hide isMetered() and clarify moveDatabaseFrom() docs.

Bug: 28870582, 28775585
Change-Id: Iabe63045c39ce7f662488f4224b56387c3c59519
2016-05-20 11:34:55 -06:00
Erik Kline
bd4b5327db Merge "DHCPv4: lease expiration is fatal, renew failures are not" into nyc-dev 2016-05-19 04:12:40 +00:00
Robin Lee
f9773c5fdd Merge "Lock down networking when waiting for always-on" into nyc-dev 2016-05-18 23:37:24 +00:00
Robin Lee
1bb13dc5e1 Lock down networking when waiting for always-on
Fix: 26694104
Fix: 27042309
Fix: 28335277
Change-Id: I47a4c9d2b98235195b1356af3dabf7235870e4fa
2016-05-19 00:26:53 +01:00
Erik Kline
7b0a58168e DHCPv4: lease expiration is fatal, renew failures are not
Bug: 24837343

Change-Id: Ib330864f8376b0907390d581b48cff5446b3392b
2016-05-18 16:17:03 +09:00
TreeHugger Robot
8debc39f17 Merge "Added a onRestrictBackgroundBlacklistChanged() callback." into nyc-dev 2016-05-17 18:28:22 +00:00
TreeHugger Robot
89bf3e3aa2 Merge "Make some of the UID-based VPN code reusable" into nyc-dev 2016-05-17 17:30:01 +00:00
Robin Lee
2543ed8799 Return legacy VPN info regardless of lockdown mode
This stops Settings from telling the user detailed information, and
doesn't really protect anything secret -- privileged apps can already
tell that there's an active VPN by looking at network info.

Change-Id: I9c2a3cab6dff1b62e94a9e0735dccde226fd26a3
Fix: 28624328
2016-05-17 14:31:52 +01:00
Felipe Leme
3edc616bf6 Documented return value of getRestrictBackgroundStatus().
Change-Id: I2c15a6d5e23cbc3c9b59c975196c1c04c1294471
Fixes: 28775490
2016-05-16 13:57:19 -07:00
Felipe Leme
57fc863cce Added a onRestrictBackgroundBlacklistChanged() callback.
When an UID is added / removed to the Data Saver blacklist, it's
necessary to notify internal components such as the Settings UI (which
was erroneously listening to UID rules changes instead).

BUG: 28743623
BUG: 28791717

Change-Id: I11c85e141dfe074ad390fd324309d2412bfbbd45
2016-05-16 13:30:57 -07:00
TreeHugger Robot
bc26d925c6 Merge "Fixed connectivity state in some power saving scenarios." into nyc-dev 2016-05-13 17:14:13 +00:00
Robin Lee
722ee0bb43 Make some of the UID-based VPN code reusable
By changing some member refs into arguments and having one of the
functions create the UID range instead of adding to mVpnUsers.

This will be useful for other layers of UID filtering like having
UIDs explicitly blocked from the VPN.

Deleted one broken line of code that cleared the status intent when
a restricted profile is removed. Other than that, this commit shouldn't
change any behaviour. If it does, that's a bug.

Bug: 26694104
Change-Id: Ieb656835d3282a8ba63cc3f12a80bfae166bcf44
2016-05-13 16:03:11 +00:00
Paul Jensen
906b94c00b Merge "ApfFilter unit test" into nyc-dev 2016-05-13 14:33:25 +00:00
Felipe Leme
16e0f1b4c4 Fixed connectivity state in some power saving scenarios.
NetworkPolicyManagerService (NPMS) manages 4 type of network restriction
when apps are running on background:

- Data Saver Mode (data usage restriction on metered-networks)
- Battery Saver Mode (power restriction on all networks)
- Doze Mode (power restriction on all networks)
- App Idle (power restriction on all networks)

These restrictions affects 2 parts of the system:

- Internal framework state on NPMS which is propagated to other internal
  classes.
- External firewall rules (managed by netd).

Although each of the power-related restrictions have their own external firewall
rules, internally apps are whitelisted to them through the same
whitelist, and the current code is only updating the internal state (and
notifying the internal listeners) when Battery Saver Mode is on.

As a consequence of this problem, there are scenarios where an app
correctly does not have internet access (because the firewall rules are
properly set), but the NetworkInfo state returns the wrong state (like
CONNECTED / CONNECTED).

This CL fixes this problem by splitting the power-related logic from
updateRulesForRestrictBackgroundLocked() into its own
method (updateRulesForPowerRestrictionsLocked()), and making sure such
method is called whenever the firewall rules are updated.

Externally to this change, the CTS tests were also improved to verify
the apps get the proper connection state; it can be verified by running:

cts-tradefed run commandAndExit cts -m CtsHostsideNetworkTests \
    -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests

BUG: 28521946
Change-Id: Id5187eb7a59c549ef30e2b17627ae2d734afa789
2016-05-12 12:33:23 -07:00
Antonio Cansado
13726d128a Addressing API council comments on NetworkStatsManager.
Callbacks
 - DataUsageCallback renamed to UsageCallback
 - DataUsagePolicy removed; passing in params directly to register method
 - making it an abstract class
 - passing in (networkType, subscriberId) that reached its threshold
 - renaming onLimitReached to onThresholdReached to match existing naming
 - only monitor single network,subscriberId
 - no monitoring of specific uids; using device or user wide instead

Tags
 - only owner uid can read its tags
 - exposing only TAG_NONE to match service side

BUG: 27530098

Change-Id: I2b2664da71806868a1e937d2bf4d1f234637509b
2016-05-10 13:24:16 -07:00
Paul Jensen
a9ae8bb696 ApfFilter unit test
Bug: 26238573

Change-Id: I5171038228782bd54e91f5bcc663cc529d2c1150
2016-05-10 11:54:42 -04:00