Loading services/core/java/com/android/server/connectivity/Vpn.java +5 −1 Original line number Diff line number Diff line Loading @@ -1113,7 +1113,11 @@ public class Vpn { } // Remove always-on VPN if it's not supported. if (!isAlwaysOnPackageSupported(alwaysOnPackage)) { // Do not remove the always-on setting due to the restricted ability in safe mode. // The always-on VPN can then start after the device reboots to normal mode. if (!mContext.getPackageManager().isSafeMode()) { setAlwaysOnPackage(null, false, null); } return false; } // Skip if the service is already established. This isn't bulletproof: it's not bound Loading services/tests/VpnTests/java/com/android/server/connectivity/VpnTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -3186,6 +3186,32 @@ public class VpnTest extends VpnTestBase { assertEquals(profile, ikev2VpnProfile.toVpnProfile()); } @Test public void testStartAlwaysOnVpnOnSafeMode() throws Exception { final Vpn vpn = createVpn(PRIMARY_USER.id); setMockedUsers(PRIMARY_USER); // UID checks must return a different UID; otherwise it'll be treated as already prepared. final int uid = Process.myUid() + 1; when(mPackageManager.getPackageUidAsUser(eq(TEST_VPN_PKG), anyInt())) .thenReturn(uid); when(mVpnProfileStore.get(vpn.getProfileNameForPackage(TEST_VPN_PKG))) .thenReturn(mVpnProfile.encode()); setAndVerifyAlwaysOnPackage(vpn, uid, false); assertTrue(vpn.startAlwaysOnVpn()); assertEquals(TEST_VPN_PKG, vpn.getAlwaysOnPackage()); // Simulate safe mode and restart the always-on VPN to verify the always-on package is not // reset. doReturn(null).when(mVpnProfileStore).get(vpn.getProfileNameForPackage(TEST_VPN_PKG)); doReturn(null).when(mPackageManager).queryIntentServicesAsUser( any(), any(), eq(PRIMARY_USER.id)); doReturn(true).when(mPackageManager).isSafeMode(); assertFalse(vpn.startAlwaysOnVpn()); assertEquals(TEST_VPN_PKG, vpn.getAlwaysOnPackage()); } // Make it public and un-final so as to spy it public class TestDeps extends Vpn.Dependencies { TestDeps() {} Loading Loading
services/core/java/com/android/server/connectivity/Vpn.java +5 −1 Original line number Diff line number Diff line Loading @@ -1113,7 +1113,11 @@ public class Vpn { } // Remove always-on VPN if it's not supported. if (!isAlwaysOnPackageSupported(alwaysOnPackage)) { // Do not remove the always-on setting due to the restricted ability in safe mode. // The always-on VPN can then start after the device reboots to normal mode. if (!mContext.getPackageManager().isSafeMode()) { setAlwaysOnPackage(null, false, null); } return false; } // Skip if the service is already established. This isn't bulletproof: it's not bound Loading
services/tests/VpnTests/java/com/android/server/connectivity/VpnTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -3186,6 +3186,32 @@ public class VpnTest extends VpnTestBase { assertEquals(profile, ikev2VpnProfile.toVpnProfile()); } @Test public void testStartAlwaysOnVpnOnSafeMode() throws Exception { final Vpn vpn = createVpn(PRIMARY_USER.id); setMockedUsers(PRIMARY_USER); // UID checks must return a different UID; otherwise it'll be treated as already prepared. final int uid = Process.myUid() + 1; when(mPackageManager.getPackageUidAsUser(eq(TEST_VPN_PKG), anyInt())) .thenReturn(uid); when(mVpnProfileStore.get(vpn.getProfileNameForPackage(TEST_VPN_PKG))) .thenReturn(mVpnProfile.encode()); setAndVerifyAlwaysOnPackage(vpn, uid, false); assertTrue(vpn.startAlwaysOnVpn()); assertEquals(TEST_VPN_PKG, vpn.getAlwaysOnPackage()); // Simulate safe mode and restart the always-on VPN to verify the always-on package is not // reset. doReturn(null).when(mVpnProfileStore).get(vpn.getProfileNameForPackage(TEST_VPN_PKG)); doReturn(null).when(mPackageManager).queryIntentServicesAsUser( any(), any(), eq(PRIMARY_USER.id)); doReturn(true).when(mPackageManager).isSafeMode(); assertFalse(vpn.startAlwaysOnVpn()); assertEquals(TEST_VPN_PKG, vpn.getAlwaysOnPackage()); } // Make it public and un-final so as to spy it public class TestDeps extends Vpn.Dependencies { TestDeps() {} Loading