summaryrefslogtreecommitdiffstats
path: root/services/tests
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-03-22 15:29:40 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-03-22 15:29:40 -0700
commit6143f31537991d2cd0f27e4d8f48f109fb10bc52 (patch)
tree1824eb3c5da22dbf35eee7a9e257f818f6b3bc2d /services/tests
parentced11a5bc4495eaa51a4d6675b2d4e296a130049 (diff)
parentcae04a29da1334aa160ac44f7430411c23cebd1b (diff)
downloadframeworks_base-6143f31537991d2cd0f27e4d8f48f109fb10bc52.zip
frameworks_base-6143f31537991d2cd0f27e4d8f48f109fb10bc52.tar.gz
frameworks_base-6143f31537991d2cd0f27e4d8f48f109fb10bc52.tar.bz2
Merge "NetworkPolicy multi-user tests."
Diffstat (limited to 'services/tests')
-rw-r--r--services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java79
1 files changed, 68 insertions, 11 deletions
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
index a243e4d..88ee867 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
@@ -53,6 +53,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
+import android.content.pm.UserInfo;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.INetworkManagementEventObserver;
@@ -69,6 +70,7 @@ import android.os.Binder;
import android.os.INetworkManagementService;
import android.os.IPowerManager;
import android.os.MessageQueue.IdleHandler;
+import android.os.UserId;
import android.test.AndroidTestCase;
import android.test.mock.MockPackageManager;
import android.test.suitebuilder.annotation.LargeTest;
@@ -84,7 +86,9 @@ import org.easymock.EasyMock;
import org.easymock.IAnswer;
import java.io.File;
+import java.util.ArrayList;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -126,8 +130,16 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
private long mStartTime;
private long mElapsedRealtime;
- private static final int UID_A = android.os.Process.FIRST_APPLICATION_UID + 800;
- private static final int UID_B = android.os.Process.FIRST_APPLICATION_UID + 801;
+ private static final int USER_ID = 0;
+ private static final int USER_ID_GUEST = 1;
+
+ private static final int APP_ID_A = android.os.Process.FIRST_APPLICATION_UID + 800;
+ private static final int APP_ID_B = android.os.Process.FIRST_APPLICATION_UID + 801;
+
+ private static final int UID_A = UserId.getUid(USER_ID, APP_ID_A);
+ private static final int UID_B = UserId.getUid(USER_ID, APP_ID_B);
+ private static final int UID_A_GUEST = UserId.getUid(USER_ID_GUEST, APP_ID_A);
+ private static final int UID_B_GUEST = UserId.getUid(USER_ID_GUEST, APP_ID_B);
private static final int PID_1 = 400;
private static final int PID_2 = 401;
@@ -161,6 +173,14 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
info.signatures = new Signature[] { signature };
return info;
}
+
+ @Override
+ public List<UserInfo> getUsers() {
+ final ArrayList<UserInfo> users = new ArrayList<UserInfo>();
+ users.add(new UserInfo(USER_ID, "Primary", UserInfo.FLAG_PRIMARY));
+ users.add(new UserInfo(USER_ID_GUEST, "Guest", 0));
+ return users;
+ }
};
}
@@ -242,13 +262,13 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
@Suppress
public void testPolicyChangeTriggersBroadcast() throws Exception {
- mService.setAppPolicy(UID_A, POLICY_NONE);
+ mService.setAppPolicy(APP_ID_A, POLICY_NONE);
// change background policy and expect broadcast
final Future<Intent> backgroundChanged = mServiceContext.nextBroadcastIntent(
ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
- mService.setAppPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+ mService.setAppPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
backgroundChanged.get();
}
@@ -302,6 +322,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
public void testScreenChangesRules() throws Exception {
Future<Void> future;
+ Future<Void> futureGuest;
expectSetUidNetworkRules(UID_A, false);
expectSetUidForeground(UID_A, true);
@@ -314,10 +335,14 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
// push strict policy for foreground uid, verify ALLOW rule
expectSetUidNetworkRules(UID_A, false);
expectSetUidForeground(UID_A, true);
+ expectSetUidNetworkRules(UID_A_GUEST, true);
+ expectSetUidForeground(UID_A_GUEST, false);
future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+ futureGuest = expectRulesChanged(UID_A_GUEST, RULE_REJECT_METERED);
replay();
- mService.setAppPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+ mService.setAppPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
future.get();
+ futureGuest.get();
verifyAndReset();
// now turn screen off and verify REJECT rule
@@ -343,6 +368,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
public void testPolicyNone() throws Exception {
Future<Void> future;
+ Future<Void> futureGuest;
expectSetUidNetworkRules(UID_A, false);
expectSetUidForeground(UID_A, true);
@@ -355,10 +381,14 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
// POLICY_NONE should RULE_ALLOW in foreground
expectSetUidNetworkRules(UID_A, false);
expectSetUidForeground(UID_A, true);
+ expectSetUidNetworkRules(UID_A_GUEST, false);
+ expectSetUidForeground(UID_A_GUEST, false);
future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+ futureGuest = expectRulesChanged(UID_A_GUEST, RULE_ALLOW_ALL);
replay();
- mService.setAppPolicy(UID_A, POLICY_NONE);
+ mService.setAppPolicy(APP_ID_A, POLICY_NONE);
future.get();
+ futureGuest.get();
verifyAndReset();
// POLICY_NONE should RULE_ALLOW in background
@@ -373,14 +403,19 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
public void testPolicyReject() throws Exception {
Future<Void> future;
+ Future<Void> futureGuest;
// POLICY_REJECT should RULE_ALLOW in background
expectSetUidNetworkRules(UID_A, true);
expectSetUidForeground(UID_A, false);
+ expectSetUidNetworkRules(UID_A_GUEST, true);
+ expectSetUidForeground(UID_A_GUEST, false);
future = expectRulesChanged(UID_A, RULE_REJECT_METERED);
+ futureGuest = expectRulesChanged(UID_A_GUEST, RULE_REJECT_METERED);
replay();
- mService.setAppPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+ mService.setAppPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
future.get();
+ futureGuest.get();
verifyAndReset();
// POLICY_REJECT should RULE_ALLOW in foreground
@@ -404,33 +439,46 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
public void testPolicyRejectAddRemove() throws Exception {
Future<Void> future;
+ Future<Void> futureGuest;
// POLICY_NONE should have RULE_ALLOW in background
expectSetUidNetworkRules(UID_A, false);
expectSetUidForeground(UID_A, false);
+ expectSetUidNetworkRules(UID_A_GUEST, false);
+ expectSetUidForeground(UID_A_GUEST, false);
future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+ futureGuest = expectRulesChanged(UID_A_GUEST, RULE_ALLOW_ALL);
replay();
mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
- mService.setAppPolicy(UID_A, POLICY_NONE);
+ mService.setAppPolicy(APP_ID_A, POLICY_NONE);
future.get();
+ futureGuest.get();
verifyAndReset();
// adding POLICY_REJECT should cause RULE_REJECT
expectSetUidNetworkRules(UID_A, true);
expectSetUidForeground(UID_A, false);
+ expectSetUidNetworkRules(UID_A_GUEST, true);
+ expectSetUidForeground(UID_A_GUEST, false);
future = expectRulesChanged(UID_A, RULE_REJECT_METERED);
+ futureGuest = expectRulesChanged(UID_A_GUEST, RULE_REJECT_METERED);
replay();
- mService.setAppPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+ mService.setAppPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
future.get();
+ futureGuest.get();
verifyAndReset();
// removing POLICY_REJECT should return us to RULE_ALLOW
expectSetUidNetworkRules(UID_A, false);
expectSetUidForeground(UID_A, false);
+ expectSetUidNetworkRules(UID_A_GUEST, false);
+ expectSetUidForeground(UID_A_GUEST, false);
future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+ futureGuest = expectRulesChanged(UID_A_GUEST, RULE_ALLOW_ALL);
replay();
- mService.setAppPolicy(UID_A, POLICY_NONE);
+ mService.setAppPolicy(APP_ID_A, POLICY_NONE);
future.get();
+ futureGuest.get();
verifyAndReset();
}
@@ -599,25 +647,34 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
public void testUidRemovedPolicyCleared() throws Exception {
Future<Void> future;
+ Future<Void> futureGuest;
// POLICY_REJECT should RULE_REJECT in background
expectSetUidNetworkRules(UID_A, true);
expectSetUidForeground(UID_A, false);
+ expectSetUidNetworkRules(UID_A_GUEST, true);
+ expectSetUidForeground(UID_A_GUEST, false);
future = expectRulesChanged(UID_A, RULE_REJECT_METERED);
+ futureGuest = expectRulesChanged(UID_A_GUEST, RULE_REJECT_METERED);
replay();
- mService.setAppPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
+ mService.setAppPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
future.get();
+ futureGuest.get();
verifyAndReset();
// uninstall should clear RULE_REJECT
expectSetUidNetworkRules(UID_A, false);
expectSetUidForeground(UID_A, false);
+ expectSetUidNetworkRules(UID_A_GUEST, false);
+ expectSetUidForeground(UID_A_GUEST, false);
future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
+ futureGuest = expectRulesChanged(UID_A_GUEST, RULE_ALLOW_ALL);
replay();
final Intent intent = new Intent(ACTION_UID_REMOVED);
intent.putExtra(EXTRA_UID, UID_A);
mServiceContext.sendBroadcast(intent);
future.get();
+ futureGuest.get();
verifyAndReset();
}