Fix: VPNs update caps upon underlying network disconnect.
Clean cherry-pick of ag/4083954 Bug: 79748782 Test: ConnectivityServiceTests still pass Change-Id: I21e866c723099e5c3dee54ff13e830d44427fc7a Merged-In: I12c948ebeb2b74290908f8320ff77220dc4a9fb9
This commit is contained in:
@@ -2465,6 +2465,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
ensureNetworkTransitionWakelock(nai.name());
|
ensureNetworkTransitionWakelock(nai.name());
|
||||||
}
|
}
|
||||||
mLegacyTypeTracker.remove(nai, wasDefault);
|
mLegacyTypeTracker.remove(nai, wasDefault);
|
||||||
|
if (!nai.networkCapabilities.hasTransport(TRANSPORT_VPN)) {
|
||||||
|
updateAllVpnsCapabilities();
|
||||||
|
}
|
||||||
rematchAllNetworksAndRequests(null, 0);
|
rematchAllNetworksAndRequests(null, 0);
|
||||||
mLingerMonitor.noteDisconnect(nai);
|
mLingerMonitor.noteDisconnect(nai);
|
||||||
if (nai.created) {
|
if (nai.created) {
|
||||||
@@ -3734,6 +3737,26 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask all VPN objects to recompute and update their capabilities.
|
||||||
|
*
|
||||||
|
* When underlying networks change, VPNs may have to update capabilities to reflect things
|
||||||
|
* like the metered bit, their transports, and so on. This asks the VPN objects to update
|
||||||
|
* their capabilities, and as this will cause them to send messages to the ConnectivityService
|
||||||
|
* handler thread through their agent, this is asynchronous. When the capabilities objects
|
||||||
|
* are computed they will be up-to-date as they are computed synchronously from here and
|
||||||
|
* this is running on the ConnectivityService thread.
|
||||||
|
* TODO : Fix this and call updateCapabilities inline to remove out-of-order events.
|
||||||
|
*/
|
||||||
|
private void updateAllVpnsCapabilities() {
|
||||||
|
synchronized (mVpns) {
|
||||||
|
for (int i = 0; i < mVpns.size(); i++) {
|
||||||
|
final Vpn vpn = mVpns.valueAt(i);
|
||||||
|
vpn.updateCapabilities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateLockdownVpn() {
|
public boolean updateLockdownVpn() {
|
||||||
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
|
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
|
||||||
@@ -4891,12 +4914,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (!newNc.hasTransport(TRANSPORT_VPN)) {
|
if (!newNc.hasTransport(TRANSPORT_VPN)) {
|
||||||
// Tell VPNs about updated capabilities, since they may need to
|
// Tell VPNs about updated capabilities, since they may need to
|
||||||
// bubble those changes through.
|
// bubble those changes through.
|
||||||
synchronized (mVpns) {
|
updateAllVpnsCapabilities();
|
||||||
for (int i = 0; i < mVpns.size(); i++) {
|
|
||||||
final Vpn vpn = mVpns.valueAt(i);
|
|
||||||
vpn.updateCapabilities();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4401,7 +4401,6 @@ public class ConnectivityServiceTest {
|
|||||||
&& !caps.hasCapability(NET_CAPABILITY_NOT_METERED),
|
&& !caps.hasCapability(NET_CAPABILITY_NOT_METERED),
|
||||||
vpnNetworkAgent);
|
vpnNetworkAgent);
|
||||||
|
|
||||||
if (false) { // TODO : reactivate this ; in the current state, the below fail.
|
|
||||||
// Disconnect cell. Receive update without even removing the dead network from the
|
// Disconnect cell. Receive update without even removing the dead network from the
|
||||||
// underlying networks – it's dead anyway. Not metered any more.
|
// underlying networks – it's dead anyway. Not metered any more.
|
||||||
mCellNetworkAgent.disconnect();
|
mCellNetworkAgent.disconnect();
|
||||||
@@ -4418,7 +4417,6 @@ public class ConnectivityServiceTest {
|
|||||||
&& !caps.hasTransport(TRANSPORT_CELLULAR) && !caps.hasTransport(TRANSPORT_WIFI)
|
&& !caps.hasTransport(TRANSPORT_CELLULAR) && !caps.hasTransport(TRANSPORT_WIFI)
|
||||||
&& caps.hasCapability(NET_CAPABILITY_NOT_METERED),
|
&& caps.hasCapability(NET_CAPABILITY_NOT_METERED),
|
||||||
vpnNetworkAgent);
|
vpnNetworkAgent);
|
||||||
}
|
|
||||||
|
|
||||||
mMockVpn.disconnect();
|
mMockVpn.disconnect();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user