Search in sources :

Example 41 with UidRange

use of android.net.UidRange in project platform_frameworks_base by android.

the class VpnTest method testLockdownChangingPackage.

@SmallTest
public void testLockdownChangingPackage() throws Exception {
    final Vpn vpn = spyVpn(primaryUser.id);
    final UidRange user = UidRange.createForUser(primaryUser.id);
    // Default state.
    assertUnblocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
    // Set always-on without lockdown.
    assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false));
    assertUnblocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
    // Set always-on with lockdown.
    assertTrue(vpn.setAlwaysOnPackage(PKGS[1], true));
    verify(mNetService).setAllowOnlyVpnForUids(eq(true), aryEq(new UidRange[] { new UidRange(user.start, user.start + PKG_UIDS[1] - 1), new UidRange(user.start + PKG_UIDS[1] + 1, user.stop) }));
    assertBlocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
    assertUnblocked(vpn, user.start + PKG_UIDS[1]);
    // Switch to another app.
    assertTrue(vpn.setAlwaysOnPackage(PKGS[3], true));
    verify(mNetService).setAllowOnlyVpnForUids(eq(false), aryEq(new UidRange[] { new UidRange(user.start, user.start + PKG_UIDS[1] - 1), new UidRange(user.start + PKG_UIDS[1] + 1, user.stop) }));
    verify(mNetService).setAllowOnlyVpnForUids(eq(true), aryEq(new UidRange[] { new UidRange(user.start, user.start + PKG_UIDS[3] - 1), new UidRange(user.start + PKG_UIDS[3] + 1, user.stop) }));
    assertBlocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2]);
    assertUnblocked(vpn, user.start + PKG_UIDS[3]);
}
Also used : UidRange(android.net.UidRange) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 42 with UidRange

use of android.net.UidRange in project platform_frameworks_base by android.

the class VpnTest method testUidWhiteAndBlacklist.

@SmallTest
public void testUidWhiteAndBlacklist() throws Exception {
    final Vpn vpn = spyVpn(primaryUser.id);
    final UidRange user = UidRange.createForUser(primaryUser.id);
    final String[] packages = { PKGS[0], PKGS[1], PKGS[2] };
    // Whitelist
    final Set<UidRange> allow = vpn.createUserAndRestrictedProfilesRanges(primaryUser.id, Arrays.asList(packages), null);
    assertEquals(new ArraySet<>(Arrays.asList(new UidRange[] { new UidRange(user.start + PKG_UIDS[0], user.start + PKG_UIDS[0]), new UidRange(user.start + PKG_UIDS[1], user.start + PKG_UIDS[2]) })), allow);
    // Blacklist
    final Set<UidRange> disallow = vpn.createUserAndRestrictedProfilesRanges(primaryUser.id, null, Arrays.asList(packages));
    assertEquals(new ArraySet<>(Arrays.asList(new UidRange[] { new UidRange(user.start, user.start + PKG_UIDS[0] - 1), new UidRange(user.start + PKG_UIDS[0] + 1, user.start + PKG_UIDS[1] - 1), /* Empty range between UIDS[1] and UIDS[2], should be excluded, */
    new UidRange(user.start + PKG_UIDS[2] + 1, user.stop) })), disallow);
}
Also used : UidRange(android.net.UidRange) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

UidRange (android.net.UidRange)42 UserInfo (android.content.pm.UserInfo)19 RemoteException (android.os.RemoteException)15 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 NetworkAgent (android.net.NetworkAgent)10 IOException (java.io.IOException)10 PendingIntent (android.app.PendingIntent)5 Intent (android.content.Intent)5 ServiceConnection (android.content.ServiceConnection)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 ResolveInfo (android.content.pm.ResolveInfo)5 LinkAddress (android.net.LinkAddress)5 LinkProperties (android.net.LinkProperties)5 NetworkMisc (android.net.NetworkMisc)5 ParcelFileDescriptor (android.os.ParcelFileDescriptor)5 ServiceSpecificException (android.os.ServiceSpecificException)5 UserHandle (android.os.UserHandle)5 UserManager (android.os.UserManager)5 ArraySet (android.util.ArraySet)5 SparseIntArray (android.util.SparseIntArray)5