Commit Graph

63 Commits

Author SHA1 Message Date
Remi NGUYEN VAN
a89a2ae676 Merge "Move LocationPermissionChecker to libs/net" 2021-03-17 00:13:21 +00:00
Chalard Jean
5c4bb91134 [NS01] Add NetworkScore
As attested by numerous TODOs in the code, a new way of
representing network quality and policy is needed instead
of an int.

An int representing the quality of the network requires
all parties using it to know how all other parties are
using it, and implementation details about the decision
algorithm. For all intents and purposes, the selection
is left to individual network factories who try to
achieve a desired result while piecing together all
possible states of the system.

As the number of such cases and desires increases, this
becomes both intractable and unmaintainable. Indeed, at
this time in the codebase nobody can really predict exactly
how a given change in score will affect selection across
the board, and it is essentially impossible to figure out
the behavior of network selection by inspecting the code
because the moving parts are scattered throughout the
entire codebase.

Having an object encapsulating policy and quality values
will let us centralize the selection and make it again
possible to maintain without knowledge of all behaviors
of all network factories. It will also provide better
guarantees of respecting policy, and allow bugfixes that
were not possible before because they'd touch too many
parts of the code.

Test: FrameworksNetTests FrameworksWifiTests NetworkStackTests
Change-Id: I3185a6412b9b659798faf0c6882699e9c63cc115
2021-03-15 09:49:47 +00:00
Cody Kesting
a93e2f9545 Merge "Update Policy Listener API naming." 2021-03-12 21:32:08 +00:00
Cody Kesting
ae3c3593cb Update Policy Listener API naming.
This CL changes the policy listener API to be
VcnNetworkPolicyChangeListener (it was previously
VcnNetworkPolicyListener) per API Council guidance.

This CL also requires permission NETWORK_FACTORY for removing registered
policy listeners.

Bug: 181562364
Test: atest FrameworksVcnTests
Change-Id: I026eaefa62d8f64b9180fc182a7cf0605d83bf97
Merged-In: I026eaefa62d8f64b9180fc182a7cf0605d83bf97
(cherry picked from commit a96ec13821)
2021-03-11 09:48:22 -08:00
Benedict Wong
03c0059bb1 Merge changes Iad296830,I826711bb,Ieb2a9b20,I6b688b00
* changes:
  Declare VCN exposed networks as NOT_VCN_MANAGED
  Allow underlying cell without unwanted NOT_VCN_MANAGED capability
  Override network and use config IKE session
  Remove usage of hidden Connectivity APIs
2021-03-10 21:53:01 +00:00
Benedict Wong
de1f0c3edb Declare VCN exposed networks as NOT_VCN_MANAGED
This change marks VCN-exposed networks as generic use, NOT_VCN_MANAGED
networks. This is the result of changes to the default NetworkCapability
set, where NOT_VCN_MANAGED was removed from the default capabilities.

Bug: 182212201
Test: atest FrameworksVcnTests
Change-Id: Iad296830201d7317537fac6bea53c79d4e41cae3
2021-03-10 10:27:23 -08:00
Benedict Wong
dc1efbb3b2 Allow underlying cell without unwanted NOT_VCN_MANAGED capability
This change updates the UnderlyingNetworkTracker to rely on the
TelephonyNetworkSpecifier for selecting underlying networks. This
ensures that there is always a cellular NetworkRequest filed for
Cellular to bring up an underlying Network.

Bug: 182211364
Test: FrameworksVcnTests
Change-Id: I826711bb671440054c2090793315a5f1d57596c0
2021-03-09 17:58:39 -08:00
Benedict Wong
033a4308ce Override network and use config IKE session
This change ensures the IKE configs are used with the correct network

Bug: 163604823
Test: FrameworksVcnTests
Change-Id: Ieb2a9b202204577f6e6969ef30245baed6382aa6
2021-03-09 15:07:57 -08:00
Cody Kesting
cdc4d4adae Specify exposed capabilities for VCN gateway connection errors.
This CL updates VCN error callbacks to return the exposed capabilities
for a gateway connection for identification purposes. Previously, the
required underlying capabilities were returned (which are not meaningful
to the caller for identification purposes).

Bug: 182281888
Test: atest FrameworksVcnTests
Change-Id: Ic62bd0b524f24f2577d9abc7635112a6419d35ed
2021-03-09 11:22:46 -08:00
Remi NGUYEN VAN
0c4e4a2059 Move LocationPermissionChecker to libs/net
LocationPermissionChecker was written to be used by multiple
connectivity modules, so it belongs in the frameworks/libs/net library.

The file is moved as-is with minor modifications in the test to avoid
usage of the privileged ActivityManager.getCurrentUser API.

Bug: 181837977
Test: atest NetworkStaticLibTests
Change-Id: I63bce35ba87c45138b3aaf6244367e982dfec455
2021-03-09 17:00:39 +09:00
Cody Kesting
df8455eae2 Exit Safe Mode when a VCN gets new configs.
This CL updates VCN instances to exit Safe Mode when they receive a
new VcnConfig. When a VCN exits Safe Mode, they will re-register a
request listener to receive all cached requests and start the
needed VcnGatewayConnections.

Bug: 179429339
Test: atest FrameworksVcnTests
Change-Id: Id1c2dc287e1ec56f37821cf0ae77f066f22d22bb
2021-03-08 11:14:25 -08:00
Cody Kesting
212c06aaa6 Notify VcnStatusCallbacks for VCN start/stop.
This CL updates VcnManagementService to notify VcnStatusCallbacks when a
VCN is started or stopped. VcnStatusCallbacks will also be notified for
config changes that cause a VCN to exit Safe Mode.

Bug: 180659281
Test: atest FrameworksVcnTests
Change-Id: I4168c868185880621333855dfcb51e46cb662741
2021-03-08 11:14:25 -08:00
Cody Kesting
f38b347ca8 Call VcnStatusCallback#onVcnStatusChanged on register.
This CL updates VcnMangementService to notify VcnStatusCallbacks on
registration with the current status of the VCN for the specified
subscription group.

Bug: 180659281
Test: atest FrameworksVcnTests
Change-Id: Id2c74e855fa12d21d292ee94a72ad047f2d56aca
2021-03-03 14:06:55 -08:00
Benedict Wong
e145e06681 Call setUnderlyingNetwork to complete VCN MOBIKE
This change updates the underlying network for the VCN in order to
ensure full MOBIKE switches are handled.

Bug: 169788130
Test: atest FrameworksVcnTests
Change-Id: Ib439bde4217beeb28f425c08ed9f3376dfe0033c
2021-03-02 00:13:28 +00:00
Benedict Wong
6adf88b074 Rename isRunning to isQuitting, and flip all booleans
Per code reviews, this may increase readability

Bug: 179944275
Test: atest FrameworksVcnTests
Change-Id: I5bc0fe946b8da870a8e89f6e07b1d1ade5865710
2021-03-02 00:09:56 +00:00
Benedict Wong
685c909718 Notify Vcn of VcnGatewayConnection quits
This change updates the Vcn when any GatewayConnection StateMachine
quits, removing it from the map of active GatewayConnections, and
triggering a re-evaluation of all existing NetworkRequests. This may (in
the event of a updated policy) result in an immediate restart.

Bug: 179944275
Test: atest FrameworksVcnTests
Change-Id: I72abf1e270a772760a17a03173d5a110e15bd01d
2021-03-01 15:44:52 -08:00
Benedict Wong
75a32b9401 Allow NETWORK_LOST disconnections to retry
This change adds the ability for disconnection requests to specify
whether the full VcnGatewayConnection should be torn down. This is
useful in cases where the cause is an ephemeral failure, and can be
restarted at some later point (eg an underlying network appears, or a
new NetworkRequest is filed that brings the VCN up.)

Bug: 179944275
Test: atest FrameworksVcnTests
Change-Id: Id1813bcbbb80541be97cc383ea9d1fe08554b7ae
2021-03-01 15:36:24 -08:00
Cody Kesting
7458bf88a0 Notify VcnStatusCallback#onVcnStatusChanged for Safe Mode.
This CL updates VcnManagementService to notify callbacks when VCNs enter
Safe Mode via #onVcnStatusChanged. Callbacks were previously notified
via #onEnteredSafeMode - however, VcnStatusCallbacks were changed to
provide more status information by defining onVcnStatusChanged(int) per
API Council feedback.

Bug: 1597023
Test: atest FrameworksVcnTests
Change-Id: I34ef76ec29f4369390449b70b37bc3cf99c09c77
2021-02-22 17:35:29 -08:00
Cody Kesting
a65c2d8ad1 Implement VCN error callback use.
This CL updates VcnGatewayConnection to notify VcnManagementService
(through Vcn) when errors occur with a gateway. VcnManagementService
then notifies registered, permissioned VcnStatusCallbacks via

Bug: 163433613
Test: atest FrameworksVcnTests
Change-Id: I3be3cac4b591b19a0b0075767fde0ba2eb6e12a2
2021-02-17 14:28:34 -08:00
Cody Kesting
f1d78f17c2 Merge changes I3242ad0e,I5daced20,Iefd284ae
* changes:
  Notify status callbacks when a VCN enters Safemode.
  Change all 'safemode' references to use 'safe mode'.
  Define VcnStatusCallback register/unregister.
2021-02-17 18:08:48 +00:00
Cody Kesting
59881b17b4 Notify status callbacks when a VCN enters Safemode.
This CL updates VcnManagementService to notify VcnStatusCallbacks when
the VCN for their specified subscription group enters Safemode. In order
to be notified, the registering app must also have permissions for the
specified permission.

Bug: 163433613
Test: atest FrameworksVcnTests
Change-Id: I3242ad0ee1dc406aef56253f884c2544a994869e
2021-02-16 21:41:03 -08:00
Cody Kesting
a3da6c886e Change all 'safemode' references to use 'safe mode'.
Bug: 163433613
Test: atest FrameworksVcnTests
Change-Id: I5daced209e4e6d8d1b87385b3f64660322908fa0
2021-02-16 21:41:03 -08:00
Cody Kesting
f14145e37a Define VcnStatusCallback register/unregister.
This CL defines VcnStatusCallbacks, which are callbacks used to register
for status updates to a specific subscription group. These Callbacks may
be registered with VcnManager at any time, but will only be invoked for
the specifies subscription group and only if the registering app has
carrier privileges for that subscription.

Bug: 163433613
Test: atest FrameworksVcnTests
Change-Id: Iefd284ae2d09676d195e2a12bf660be3596da59b
2021-02-16 21:33:40 -08:00
Benedict Wong
d301c8544e Merge "Implement ChildSessionCallback#onIpSecTransformsMigrated" 2021-02-17 04:02:40 +00:00
Benedict Wong
d6186bdf3c Implement ChildSessionCallback#onIpSecTransformsMigrated
This change implements the Migrated callback, proxying to
onIpSecTransformCreated

Bug: 180163196
Test: atest FrameworksVcnTests
Change-Id: Ibf07be667882ea35a4d7191b87d1193f38f9db3e
2021-02-16 22:10:42 +00:00
Cody Kesting
a282ea505f Implement Safemode alarm in VcnGatewayConnection.
This CL updates VcnGatewayConnection to use WakeupMessages to support
Safemode detection. Safemode is entered if the VcnGatewayConnection
instance takes more than SAFEMODE_TIMEOUT_SECONDS seconds to a) go from
DisconnectedState to ConnectedState, or b) exit and re-enter
ConnectedState. If this timeout is exceeded, the instance will notify
its managing Vcn via VcnGatewayStatusCallback#onEnteredSafemode.

Bug: 178140973
Test: atest FrameworksVcnTests
Change-Id: Iff40aba639b465c3959ef383f1001be419daba4d
2021-02-16 09:46:07 -08:00
Cody Kesting
57211bc8f5 Use WakeupMesage for delayed events in VcnGatewayConnection.
This CL updates VcnGatewayConnection to use WakeupMessages instead of
sendDelayedMessage() for delayed events. This change allows for
VcnGatewayConnection to guarantee that all its messages are processed
while holding WakeLocks.

Bug: 178140973
Test: atest FrameworksVcnTests
Change-Id: If8182378fe2e9dad08df88a84934b21e22e25752
2021-02-12 16:27:06 -08:00
Cody Kesting
a4bec019a7 Acquire WakeLock while processing Gateway messages.
This CL updates VcnGatewayConnection to acquire a WakeLock when sending
a message to the Handler queue. After every message is processed, the
state will check for additional messages and release the WakeLock if the
queue is empty.

Bug: 178140973
Test: atest FrameworksVcnTests
Change-Id: Ib108c834833cc8feb2c92c9a6c60f218618225ec
2021-02-12 16:01:32 -08:00
Benedict Wong
acf7a30f3e Lazy-create IpSecTunnelInterface
With the Network(int) constructor moving to mainline, we cannot use the
constructor, and should just create the IpSecTunnelInterface lazily, at
first use.

Bug: 165827287
Test: atest FrameworksVcnTests
Change-Id: Ic01858e0f9c80d316676cfbae5edca114655c3fe
2021-02-09 21:22:27 -08:00
Benedict Wong
cebde1ed9a Restrict Carrier Wifi while VCN is configured & privileged
This change removes the NOT_RESTRICTED capability for Carrier Wifi. This
is done even if a VCN is in safe mode, but will ONLY be performed if the
VCN is provisioned, and has the appropriate carrier privileges to run.

This change also fixes a test bug where the NOT_VCN_MANAGED capability
was not present in the query to getUnderlyingNetworkPolicy(), and
therefore was incorrectly passing.

Bug: 163432273
Test: atest FrameworksVcnTests
Change-Id: Iecb827b5341bdeb93ef8692c1d62f0eaf9d416ba
2021-02-09 18:43:21 -08:00
Benedict Wong
36cbdb5391 Implement RetryTimeout state
This change adds support for retries with incrementally increasing
delays.

Bug: 165827287
Test: atest FrameworksVcnTests
Change-Id: I414dce5882540bbe338d0bc1f40481df424821fe
2021-02-05 15:11:39 -08:00
Benedict Wong
2ef953a9a1 Test Network startup in ConnectedState
Add additional tests based on proxy implementations of
ChildSessionCallback and ChildSessionConfiguration

Bug: 165827287
Test: atest FrameworksVcnTests
Change-Id: I165716a0212da7c06b9723656ffe35921cf81854
2021-02-05 15:11:38 -08:00
Cody Kesting
204a2fed4f Support Safemode for VCNs.
This CL updates VcnManagementService to support Safemode for VCN
instances. Specifically, VcnGatewayConnections will notify their Vcn
instance when they enter Safemode. Vcn instances will in-turn notify
VcnManagementService, which notifies all registered
UnderlyingNetworkPolicyListeners to update their policies.

Bug: 178140973
Test: atest FrameworksVcnTests
Change-Id: I3336c150e9406b3eb2330d2e86cae2ed835730bb
2021-02-04 16:22:55 -08:00
Cody Kesting
f5915a7f3a Fix test method naming in VcnManagementServiceTest.
Bug: 175914059
Test: atest FrameworksVcnTests
Change-Id: I03be15d63adfccc357000ee670e373d0359a3c06
2021-02-03 20:28:51 -08:00
Cody Kesting
26409bfe5d Notify PolicyListeners to refresh their policy on VCN changes.
This CL updates VcnManagementService to notify all registered
VcnUnderlyingNetworkPolicyListeners to refresh their
UnderlyingNetworkPolicy when any VCN is added or removed.

Bug: 175914059
Test: atest FrameworksVcnTests
Change-Id: Ie87f4aa3401c6c4ba9f932130a1d475e35f59d4e
2021-02-03 20:28:51 -08:00
Cody Kesting
50e9bf04aa Unit test TelephonySubscriptionSnapshot changes for VCNs.
This CL adds unit testing for TelephonySubscriptionSnapshot updates in
UnderlyingNetworkTracker, Vcn, and VcnManagementService.

Bug: 177364490
Test: atest FrameworksVcnTests
Change-Id: I244744194a1360c7c7dee062a302e04f9b5efc32
2021-02-03 20:28:43 -08:00
Cody Kesting
2b0754517c Notify UnderlyingNetworkTracker for Subscription changes.
This CL updates VcnManagementService to notify active VCNs when it is
notified of subscription changes by TelephonySubscriptionTracker. These
subscription changes are passed down to each VCN's
UnderlyingNetworkTracker, which determines whether it needs to register
or unregister bringup NetworkRequests based on subIds within that VCN's
Subscription Group.

Bug: 177364490
Test: atest FrameworksVcnTests
Change-Id: I15bc9aaf3d5f97046d0ce9fcf1e12c9b1e0e1446
2021-02-03 19:04:01 -08:00
Benedict Wong
539ba24df4 Implement ConnectedState
This change implements the Connected state, ensuring that relevant
capabilities are mirrored from the underlying networks.

Bug: 165827287
Test: atest FrameworksVcnTests
Change-Id: Iedf6d879b4577d7efd40cce41cc1d5fd5021124f
2021-02-03 10:26:36 -08:00
Cody Kesting
07979a07cc Implement Network policy in VcnManagementService.
This CL implements #getUnderlyingNetworkPolicy() for
VcnManagementService. Specifically, it takes the provided
NetworkCapabilities and checks for a corresponding VCN. If one exists,
a VcnUnderlyingNetworkPolicy will be returned with a copy of the
original NetworkCapabilities without the capability NOT_VCN_MANAGED and
with the unwanted capability NOT_VCN_MANAGED.

Any NetworkCapabilities without a corresponding VCN will be returned a
VcnUnderlyingNetworkPolicy with the original NetworkCapabilities intact.

Bug: 175914059
Test: atest FrameworksVcnTests
Change-Id: Icdffc4f586f58a0e5b6290d5c6449e2bbed5cab0
2021-02-01 14:46:58 -08:00
Cody Kesting
f029daa404 Unit test UnderlyingNetworkTracker.
Bug: 177364490
Test: atest FrameworksVcnTests
Change-Id: I681b0bef27cdd1974a574e81b4b435578cd6e9cd
2021-02-01 14:46:57 -08:00
Cody Kesting
a382c9ca0c Register NetworkCallbacks in UnderlyingNetworkTracker.
This CL updates UnderlyingNetworkTracker to register NetworkCallbacks.
UnderlyingNetworkTracker uses two types of NetworkCallbacks:
  - bringup requests
  - selection requests

Bringup requests ensure that VCN-managed Networks are not reaped.
Separate bringup requests are filed for wifi and cell Networks. One cell
request is filed for each subscription ID (subId) in the VCN's
subscription group.

Selection requests are used to allow ConnectivityService to perform
Network selection for the VCN's selected underlying Network (the Network
that VCN traffic will be routed through).

Bug: 177364490
Test: atest FrameworksVcnTests
Change-Id: Ic4dc13a3f7acf08589ddb25b343af2677cd7cf65
2021-02-01 14:46:57 -08:00
Cody Kesting
7de2e8443c Allow system components to request underlying network policies.
This CL updates VcnManager to allow system components with permission
NETWORK_FACTORY to request the current VcnUnderlingNetworkPolicy for a
specific Network's NetworkCapabilities and LinkProperties.

Bug: 175900686
Test: atest FrameworksVcnTests
Change-Id: I16416e619bdb03630582f5660260b0090730e9eb
2021-01-28 19:38:06 -08:00
Benedict Wong
b81d4e8547 Implement ConnectingState
This change implements the Connecting state, where the gateway
connection will be established. In the event of a network switch during
connection, the existing connection attempt will be aborted and
restarted on the new network in an attempt to avoid the case where the
old network is completely lost (eg wifi to cell switch), and IKE stalls
for the entire retry period.

Bug: 165827287
Test: atest FrameworksVcnTests
Change-Id: Id1c6337e8ba4cc1b97c6c20977153c230bd07723
2021-01-26 18:24:02 -08:00
Benedict Wong
1654a15f29 Implement DisconnectingState
This change implements the Disconnecting state, which provides facility
to attempt to gracefully close IKE sessions, and kill it after a few
seconds.

Bug: 165827287
Test: atest FrameworksVcnTests
Change-Id: I0d179085726b8125f2021679def75824cf71bd08
2021-01-25 18:37:21 -08:00
Benedict Wong
4f27883485 Merge "Implement Disconnected state" 2021-01-25 22:41:08 +00:00
Benedict Wong
60d326ba08 Implement Disconnected state
This change implements the signal handling for the Disconnected state.

Bug: 165827287
Test: atest FrameworksVcnTests
Change-Id: I4853b0801b82fddc4ef9e9c6e6a659f9b81e2ac3
2021-01-20 12:01:10 -08:00
Cody Kesting
88d43b69ea Implement Policy Listener add/remove in VcnService.
This CL updates VcnManagementService to implement
VcnUnderlyingNetworkPolicyListener add and remove operations. It also
adds functionality to remove any listeners if the registering app dies
without unregistering.

Bug: 175739863
Test: atest FrameworksVcnTests
Change-Id: I9db2729d404f232b84577d2d90909b9152d53b5a
2021-01-19 13:38:22 -08:00
Benedict Wong
739404474e Add utility methods for creation of NetInfo, NetCaps, and LinkProps
This change adds basic utility methods to create network info, network
capabilities and link properties

Bug: 165827287
Test: atest FrameworksVcnTests
Change-Id: I915e0c4e9ca989344b9a4785e200381db0b94fb8
2021-01-11 21:09:13 -08:00
Benedict Wong
db8cf2a13d Pull VcnNetworkProvider out into a separate class
This change makes the VcnNetworkProvider a separate class, and caches
all NetworkRequest(s) to ensure that VcnTunnel(s) satisfy all requests
that they can accept.

Bug: 163431879
Test: atest FrameworksVcnTests
Change-Id: I3b7695628d0153a33f7e7f40d839df1463d58b07
2021-01-07 17:13:39 -08:00
Benedict Wong
9cb5807845 Verify carrier privileges for VCN-providing packages
This change adds and verifies packages in the VcnManagmentService,
ensuring that carrier privilege gain/loss correctly starts/tears down
VCN instances.

Bug: 163431877
Test: atest FrameworksNetTests
Change-Id: I63203188c57fdde1cfc58aaf1108aa3e70eb4a50
2021-01-07 17:13:37 -08:00