Add a provider to VPN
Test: FrameworksNetTests NetworkStackTests Change-Id: I982543cdee358bb62d3b56a7fd9d71dc18908b65
This commit is contained in:
@@ -5140,7 +5140,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onUserStart(int userId) {
|
private void onUserStarted(int userId) {
|
||||||
synchronized (mVpns) {
|
synchronized (mVpns) {
|
||||||
Vpn userVpn = mVpns.get(userId);
|
Vpn userVpn = mVpns.get(userId);
|
||||||
if (userVpn != null) {
|
if (userVpn != null) {
|
||||||
@@ -5155,7 +5155,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onUserStop(int userId) {
|
private void onUserStopped(int userId) {
|
||||||
synchronized (mVpns) {
|
synchronized (mVpns) {
|
||||||
Vpn userVpn = mVpns.get(userId);
|
Vpn userVpn = mVpns.get(userId);
|
||||||
if (userVpn == null) {
|
if (userVpn == null) {
|
||||||
@@ -5272,9 +5272,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (userId == UserHandle.USER_NULL) return;
|
if (userId == UserHandle.USER_NULL) return;
|
||||||
|
|
||||||
if (Intent.ACTION_USER_STARTED.equals(action)) {
|
if (Intent.ACTION_USER_STARTED.equals(action)) {
|
||||||
onUserStart(userId);
|
onUserStarted(userId);
|
||||||
} else if (Intent.ACTION_USER_STOPPED.equals(action)) {
|
} else if (Intent.ACTION_USER_STOPPED.equals(action)) {
|
||||||
onUserStop(userId);
|
onUserStopped(userId);
|
||||||
} else if (Intent.ACTION_USER_ADDED.equals(action)) {
|
} else if (Intent.ACTION_USER_ADDED.equals(action)) {
|
||||||
onUserAdded(userId);
|
onUserAdded(userId);
|
||||||
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
|
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
@@ -86,10 +87,10 @@ import android.os.Build.VERSION_CODES;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.ConditionVariable;
|
import android.os.ConditionVariable;
|
||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.os.test.TestLooper;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.security.Credentials;
|
import android.security.Credentials;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
@@ -224,6 +225,8 @@ public class VpnTest {
|
|||||||
.thenReturn(mNotificationManager);
|
.thenReturn(mNotificationManager);
|
||||||
when(mContext.getSystemService(eq(Context.CONNECTIVITY_SERVICE)))
|
when(mContext.getSystemService(eq(Context.CONNECTIVITY_SERVICE)))
|
||||||
.thenReturn(mConnectivityManager);
|
.thenReturn(mConnectivityManager);
|
||||||
|
when(mContext.getSystemServiceName(eq(ConnectivityManager.class)))
|
||||||
|
.thenReturn(Context.CONNECTIVITY_SERVICE);
|
||||||
when(mContext.getSystemService(eq(Context.IPSEC_SERVICE))).thenReturn(mIpSecManager);
|
when(mContext.getSystemService(eq(Context.IPSEC_SERVICE))).thenReturn(mIpSecManager);
|
||||||
when(mContext.getString(R.string.config_customVpnAlwaysOnDisconnectedDialogComponent))
|
when(mContext.getString(R.string.config_customVpnAlwaysOnDisconnectedDialogComponent))
|
||||||
.thenReturn(Resources.getSystem().getString(
|
.thenReturn(Resources.getSystem().getString(
|
||||||
@@ -1286,8 +1289,13 @@ public class VpnTest {
|
|||||||
doReturn(UserHandle.of(userId)).when(asUserContext).getUser();
|
doReturn(UserHandle.of(userId)).when(asUserContext).getUser();
|
||||||
when(mContext.createContextAsUser(eq(UserHandle.of(userId)), anyInt()))
|
when(mContext.createContextAsUser(eq(UserHandle.of(userId)), anyInt()))
|
||||||
.thenReturn(asUserContext);
|
.thenReturn(asUserContext);
|
||||||
return new Vpn(Looper.myLooper(), mContext, new TestDeps(), mNetService,
|
final TestLooper testLooper = new TestLooper();
|
||||||
|
final Vpn vpn = new Vpn(testLooper.getLooper(), mContext, new TestDeps(), mNetService,
|
||||||
userId, mKeyStore, mSystemServices, mIkev2SessionCreator);
|
userId, mKeyStore, mSystemServices, mIkev2SessionCreator);
|
||||||
|
verify(mConnectivityManager, times(1)).registerNetworkProvider(argThat(
|
||||||
|
provider -> provider.getName().contains("VpnNetworkProvider")
|
||||||
|
));
|
||||||
|
return vpn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertBlocked(Vpn vpn, int... uids) {
|
private static void assertBlocked(Vpn vpn, int... uids) {
|
||||||
|
|||||||
Reference in New Issue
Block a user