Merge "Verify if the VPN app has been added into power save whilte list"
This commit is contained in:
@@ -45,6 +45,7 @@ import static org.junit.Assume.assumeTrue;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
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.anyLong;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
@@ -111,6 +112,7 @@ import android.os.ConditionVariable;
|
|||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.os.PowerWhitelistManager;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
@@ -129,6 +131,7 @@ import com.android.internal.net.VpnConfig;
|
|||||||
import com.android.internal.net.VpnProfile;
|
import com.android.internal.net.VpnProfile;
|
||||||
import com.android.internal.util.HexDump;
|
import com.android.internal.util.HexDump;
|
||||||
import com.android.modules.utils.build.SdkLevel;
|
import com.android.modules.utils.build.SdkLevel;
|
||||||
|
import com.android.server.DeviceIdleInternal;
|
||||||
import com.android.server.IpSecService;
|
import com.android.server.IpSecService;
|
||||||
import com.android.server.vcn.util.PersistableBundleUtils;
|
import com.android.server.vcn.util.PersistableBundleUtils;
|
||||||
import com.android.testutils.DevSdkIgnoreRule;
|
import com.android.testutils.DevSdkIgnoreRule;
|
||||||
@@ -235,6 +238,7 @@ public class VpnTest {
|
|||||||
@Mock private ConnectivityManager mConnectivityManager;
|
@Mock private ConnectivityManager mConnectivityManager;
|
||||||
@Mock private IpSecService mIpSecService;
|
@Mock private IpSecService mIpSecService;
|
||||||
@Mock private VpnProfileStore mVpnProfileStore;
|
@Mock private VpnProfileStore mVpnProfileStore;
|
||||||
|
@Mock DeviceIdleInternal mDeviceIdleInternal;
|
||||||
private final VpnProfile mVpnProfile;
|
private final VpnProfile mVpnProfile;
|
||||||
|
|
||||||
private IpSecManager mIpSecManager;
|
private IpSecManager mIpSecManager;
|
||||||
@@ -408,6 +412,12 @@ public class VpnTest {
|
|||||||
disallow);
|
disallow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyPowerSaveTempWhitelistApp(String packageName) {
|
||||||
|
verify(mDeviceIdleInternal).addPowerSaveTempWhitelistApp(anyInt(), eq(packageName),
|
||||||
|
anyLong(), anyInt(), eq(false), eq(PowerWhitelistManager.REASON_VPN),
|
||||||
|
eq("VpnManager event"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAlwaysAndOnGetLockDown() throws Exception {
|
public void testGetAlwaysAndOnGetLockDown() throws Exception {
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
@@ -1144,6 +1154,8 @@ public class VpnTest {
|
|||||||
verifyPlatformVpnIsActivated(TEST_VPN_PKG);
|
verifyPlatformVpnIsActivated(TEST_VPN_PKG);
|
||||||
vpn.stopVpnProfile(TEST_VPN_PKG);
|
vpn.stopVpnProfile(TEST_VPN_PKG);
|
||||||
verifyPlatformVpnIsDeactivated(TEST_VPN_PKG);
|
verifyPlatformVpnIsDeactivated(TEST_VPN_PKG);
|
||||||
|
verifyPowerSaveTempWhitelistApp(TEST_VPN_PKG);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
// CATEGORY_EVENT_DEACTIVATED_BY_USER is not an error event, so both of errorClass and
|
// CATEGORY_EVENT_DEACTIVATED_BY_USER is not an error event, so both of errorClass and
|
||||||
// errorCode won't be set.
|
// errorCode won't be set.
|
||||||
verifyVpnManagerEvent(sessionKey1, VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER,
|
verifyVpnManagerEvent(sessionKey1, VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER,
|
||||||
@@ -1155,6 +1167,8 @@ public class VpnTest {
|
|||||||
verifyPlatformVpnIsActivated(TEST_VPN_PKG);
|
verifyPlatformVpnIsActivated(TEST_VPN_PKG);
|
||||||
vpn.prepare(TEST_VPN_PKG, "com.new.vpn" /* newPackage */, TYPE_VPN_PLATFORM);
|
vpn.prepare(TEST_VPN_PKG, "com.new.vpn" /* newPackage */, TYPE_VPN_PLATFORM);
|
||||||
verifyPlatformVpnIsDeactivated(TEST_VPN_PKG);
|
verifyPlatformVpnIsDeactivated(TEST_VPN_PKG);
|
||||||
|
verifyPowerSaveTempWhitelistApp(TEST_VPN_PKG);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
// CATEGORY_EVENT_DEACTIVATED_BY_USER is not an error event, so both of errorClass and
|
// CATEGORY_EVENT_DEACTIVATED_BY_USER is not an error event, so both of errorClass and
|
||||||
// errorCode won't be set.
|
// errorCode won't be set.
|
||||||
verifyVpnManagerEvent(sessionKey2, VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER,
|
verifyVpnManagerEvent(sessionKey2, VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER,
|
||||||
@@ -1170,6 +1184,8 @@ public class VpnTest {
|
|||||||
// Enable VPN always-on for PKGS[1].
|
// Enable VPN always-on for PKGS[1].
|
||||||
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false /* lockdown */,
|
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false /* lockdown */,
|
||||||
null /* lockdownAllowlist */));
|
null /* lockdownAllowlist */));
|
||||||
|
verifyPowerSaveTempWhitelistApp(PKGS[1]);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
verifyVpnManagerEvent(null /* sessionKey */,
|
verifyVpnManagerEvent(null /* sessionKey */,
|
||||||
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
||||||
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
||||||
@@ -1178,6 +1194,8 @@ public class VpnTest {
|
|||||||
// Enable VPN lockdown for PKGS[1].
|
// Enable VPN lockdown for PKGS[1].
|
||||||
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], true /* lockdown */,
|
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], true /* lockdown */,
|
||||||
null /* lockdownAllowlist */));
|
null /* lockdownAllowlist */));
|
||||||
|
verifyPowerSaveTempWhitelistApp(PKGS[1]);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
verifyVpnManagerEvent(null /* sessionKey */,
|
verifyVpnManagerEvent(null /* sessionKey */,
|
||||||
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
||||||
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
||||||
@@ -1186,6 +1204,8 @@ public class VpnTest {
|
|||||||
// Disable VPN lockdown for PKGS[1].
|
// Disable VPN lockdown for PKGS[1].
|
||||||
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false /* lockdown */,
|
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false /* lockdown */,
|
||||||
null /* lockdownAllowlist */));
|
null /* lockdownAllowlist */));
|
||||||
|
verifyPowerSaveTempWhitelistApp(PKGS[1]);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
verifyVpnManagerEvent(null /* sessionKey */,
|
verifyVpnManagerEvent(null /* sessionKey */,
|
||||||
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
||||||
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
||||||
@@ -1194,6 +1214,8 @@ public class VpnTest {
|
|||||||
// Disable VPN always-on.
|
// Disable VPN always-on.
|
||||||
assertTrue(vpn.setAlwaysOnPackage(null, false /* lockdown */,
|
assertTrue(vpn.setAlwaysOnPackage(null, false /* lockdown */,
|
||||||
null /* lockdownAllowlist */));
|
null /* lockdownAllowlist */));
|
||||||
|
verifyPowerSaveTempWhitelistApp(PKGS[1]);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
verifyVpnManagerEvent(null /* sessionKey */,
|
verifyVpnManagerEvent(null /* sessionKey */,
|
||||||
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
||||||
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
||||||
@@ -1202,6 +1224,8 @@ public class VpnTest {
|
|||||||
// Enable VPN always-on for PKGS[1] again.
|
// Enable VPN always-on for PKGS[1] again.
|
||||||
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false /* lockdown */,
|
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false /* lockdown */,
|
||||||
null /* lockdownAllowlist */));
|
null /* lockdownAllowlist */));
|
||||||
|
verifyPowerSaveTempWhitelistApp(PKGS[1]);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
verifyVpnManagerEvent(null /* sessionKey */,
|
verifyVpnManagerEvent(null /* sessionKey */,
|
||||||
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED, -1 /* errorClass */,
|
||||||
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
-1 /* errorCode */, new VpnProfileState(VpnProfileState.STATE_DISCONNECTED,
|
||||||
@@ -1210,6 +1234,8 @@ public class VpnTest {
|
|||||||
// Enable VPN always-on for PKGS[2].
|
// Enable VPN always-on for PKGS[2].
|
||||||
assertTrue(vpn.setAlwaysOnPackage(PKGS[2], false /* lockdown */,
|
assertTrue(vpn.setAlwaysOnPackage(PKGS[2], false /* lockdown */,
|
||||||
null /* lockdownAllowlist */));
|
null /* lockdownAllowlist */));
|
||||||
|
verifyPowerSaveTempWhitelistApp(PKGS[2]);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
// PKGS[1] is replaced with PKGS[2].
|
// PKGS[1] is replaced with PKGS[2].
|
||||||
// Pass 2 VpnProfileState objects to verifyVpnManagerEvent(), the first one is sent to
|
// Pass 2 VpnProfileState objects to verifyVpnManagerEvent(), the first one is sent to
|
||||||
// PKGS[1] to notify PKGS[1] that the VPN always-on is disabled, the second one is sent to
|
// PKGS[1] to notify PKGS[1] that the VPN always-on is disabled, the second one is sent to
|
||||||
@@ -1310,6 +1336,8 @@ public class VpnTest {
|
|||||||
final IkeSessionCallback ikeCb = captor.getValue();
|
final IkeSessionCallback ikeCb = captor.getValue();
|
||||||
ikeCb.onClosedWithException(exception);
|
ikeCb.onClosedWithException(exception);
|
||||||
|
|
||||||
|
verifyPowerSaveTempWhitelistApp(TEST_VPN_PKG);
|
||||||
|
reset(mDeviceIdleInternal);
|
||||||
verifyVpnManagerEvent(sessionKey, category, errorType, errorCode, null /* profileState */);
|
verifyVpnManagerEvent(sessionKey, category, errorType, errorCode, null /* profileState */);
|
||||||
if (errorType == VpnManager.ERROR_CLASS_NOT_RECOVERABLE) {
|
if (errorType == VpnManager.ERROR_CLASS_NOT_RECOVERABLE) {
|
||||||
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS))
|
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS))
|
||||||
@@ -1532,7 +1560,7 @@ public class VpnTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TestDeps extends Vpn.Dependencies {
|
private final class TestDeps extends Vpn.Dependencies {
|
||||||
public final CompletableFuture<String[]> racoonArgs = new CompletableFuture();
|
public final CompletableFuture<String[]> racoonArgs = new CompletableFuture();
|
||||||
public final CompletableFuture<String[]> mtpdArgs = new CompletableFuture();
|
public final CompletableFuture<String[]> mtpdArgs = new CompletableFuture();
|
||||||
public final File mStateFile;
|
public final File mStateFile;
|
||||||
@@ -1661,6 +1689,11 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBlocking(FileDescriptor fd, boolean blocking) {}
|
public void setBlocking(FileDescriptor fd, boolean blocking) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceIdleInternal getDeviceIdleInternal() {
|
||||||
|
return mDeviceIdleInternal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user