Search in sources :

Example 1 with UidRange

use of android.net.UidRange in project android_frameworks_base by ResurrectionRemix.

the class VpnTest method testLockdownChangingPackage.

@SmallTest
public void testLockdownChangingPackage() throws Exception {
    final MockVpn vpn = new MockVpn(primaryUser.id);
    final UidRange user = UidRange.createForUser(primaryUser.id);
    // Default state.
    vpn.assertUnblocked(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));
    vpn.assertUnblocked(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) }));
    vpn.assertBlocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
    vpn.assertUnblocked(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) }));
    vpn.assertBlocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2]);
    vpn.assertUnblocked(user.start + PKG_UIDS[3]);
}
Also used : UidRange(android.net.UidRange) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with UidRange

use of android.net.UidRange in project android_frameworks_base by ResurrectionRemix.

the class Vpn method onUserAdded.

public void onUserAdded(int userHandle) {
    // If the user is restricted tie them to the parent user's VPN
    UserInfo user = UserManager.get(mContext).getUserInfo(userHandle);
    if (user.isRestricted() && user.restrictedProfileParentId == mUserHandle) {
        synchronized (Vpn.this) {
            if (mVpnUsers != null) {
                try {
                    addUserToRanges(mVpnUsers, userHandle, mConfig.allowedApplications, mConfig.disallowedApplications);
                    if (mNetworkAgent != null) {
                        final List<UidRange> ranges = uidRangesForUser(userHandle);
                        mNetworkAgent.addUidRanges(ranges.toArray(new UidRange[ranges.size()]));
                    }
                } catch (Exception e) {
                    Log.wtf(TAG, "Failed to add restricted user to owner", e);
                }
            }
            if (mAlwaysOn) {
                setVpnForcedLocked(mLockdown);
            }
        }
    }
}
Also used : UidRange(android.net.UidRange) UserInfo(android.content.pm.UserInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 3 with UidRange

use of android.net.UidRange in project android_frameworks_base by ResurrectionRemix.

the class Vpn method uidRangesForUser.

// Returns the subset of the full list of active UID ranges the VPN applies to (mVpnUsers) that
// apply to userHandle.
private List<UidRange> uidRangesForUser(int userHandle) {
    final UidRange userRange = UidRange.createForUser(userHandle);
    final List<UidRange> ranges = new ArrayList<UidRange>();
    for (UidRange range : mVpnUsers) {
        if (userRange.containsRange(range)) {
            ranges.add(range);
        }
    }
    return ranges;
}
Also used : UidRange(android.net.UidRange) ArrayList(java.util.ArrayList)

Example 4 with UidRange

use of android.net.UidRange in project android_frameworks_base by DirtyUnicorns.

the class VpnTest method testLockdownAddingAProfile.

@SmallTest
public void testLockdownAddingAProfile() throws Exception {
    final MockVpn vpn = new MockVpn(primaryUser.id);
    setMockedUsers(primaryUser);
    // Make a copy of the restricted profile, as we're going to mark it deleted halfway through.
    final UserInfo tempProfile = new UserInfo(restrictedProfileA.id, restrictedProfileA.name, restrictedProfileA.flags);
    tempProfile.restrictedProfileParentId = primaryUser.id;
    final UidRange user = UidRange.createForUser(primaryUser.id);
    final UidRange profile = UidRange.createForUser(tempProfile.id);
    // Set lockdown.
    assertTrue(vpn.setAlwaysOnPackage(PKGS[3], true));
    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) }));
    // Verify restricted user isn't affected at first.
    vpn.assertUnblocked(profile.start + PKG_UIDS[0]);
    // Add the restricted user.
    setMockedUsers(primaryUser, tempProfile);
    vpn.onUserAdded(tempProfile.id);
    verify(mNetService).setAllowOnlyVpnForUids(eq(true), aryEq(new UidRange[] { new UidRange(profile.start, profile.start + PKG_UIDS[3] - 1), new UidRange(profile.start + PKG_UIDS[3] + 1, profile.stop) }));
    // Remove the restricted user.
    tempProfile.partial = true;
    vpn.onUserRemoved(tempProfile.id);
    verify(mNetService).setAllowOnlyVpnForUids(eq(false), aryEq(new UidRange[] { new UidRange(profile.start, profile.start + PKG_UIDS[3] - 1), new UidRange(profile.start + PKG_UIDS[3] + 1, profile.stop) }));
}
Also used : UidRange(android.net.UidRange) UserInfo(android.content.pm.UserInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 5 with UidRange

use of android.net.UidRange in project android_frameworks_base by DirtyUnicorns.

the class VpnTest method testLockdownChangingPackage.

@SmallTest
public void testLockdownChangingPackage() throws Exception {
    final MockVpn vpn = new MockVpn(primaryUser.id);
    final UidRange user = UidRange.createForUser(primaryUser.id);
    // Default state.
    vpn.assertUnblocked(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));
    vpn.assertUnblocked(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) }));
    vpn.assertBlocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
    vpn.assertUnblocked(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) }));
    vpn.assertBlocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2]);
    vpn.assertUnblocked(user.start + PKG_UIDS[3]);
}
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