summaryrefslogtreecommitdiffstats
path: root/services/tests/servicestests
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2012-10-21 07:50:55 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-10-21 07:50:55 -0700
commit283d1409ddadd35cd41b5496659d3a24dc365fb0 (patch)
tree94875c181ba360a1960078173347726eb78e81b1 /services/tests/servicestests
parent27b94b3eac1bec47d9a5141e44eb093c290e4ce8 (diff)
parentf624d72cb0fe40fd5748d4f0d1a93bf267aa3ed8 (diff)
downloadframeworks_base-283d1409ddadd35cd41b5496659d3a24dc365fb0.zip
frameworks_base-283d1409ddadd35cd41b5496659d3a24dc365fb0.tar.gz
frameworks_base-283d1409ddadd35cd41b5496659d3a24dc365fb0.tar.bz2
am f624d72c: am 8074e98b: Merge "Fix crashes when quickly adding and removing users" into jb-mr1-dev
* commit 'f624d72cb0fe40fd5748d4f0d1a93bf267aa3ed8': Fix crashes when quickly adding and removing users
Diffstat (limited to 'services/tests/servicestests')
-rw-r--r--services/tests/servicestests/AndroidManifest.xml2
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java62
2 files changed, 56 insertions, 8 deletions
diff --git a/services/tests/servicestests/AndroidManifest.xml b/services/tests/servicestests/AndroidManifest.xml
index 8aeb2af..7848b1d 100644
--- a/services/tests/servicestests/AndroidManifest.xml
+++ b/services/tests/servicestests/AndroidManifest.xml
@@ -34,7 +34,7 @@
<uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.MANAGE_USERS" />
- <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<application>
<uses-library android:name="android.test.runner" />
diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
index 59a86c2..1758d93 100644
--- a/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
@@ -16,23 +16,37 @@
package com.android.server.pm;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.os.Debug;
import android.os.Environment;
import android.os.UserManager;
import android.test.AndroidTestCase;
+import java.util.ArrayList;
import java.util.List;
/** Test {@link UserManager} functionality. */
public class UserManagerTest extends AndroidTestCase {
UserManager mUserManager = null;
+ Object mUserLock = new Object();
@Override
public void setUp() throws Exception {
mUserManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
+ IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
+ getContext().registerReceiver(new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ synchronized (mUserLock) {
+ mUserLock.notifyAll();
+ }
+ }
+ }, filter);
}
public void testHasPrimary() throws Exception {
@@ -54,7 +68,7 @@ public class UserManagerTest extends AndroidTestCase {
}
}
assertTrue(found);
- mUserManager.removeUser(userInfo.id);
+ removeUser(userInfo.id);
}
public void testAdd2Users() throws Exception {
@@ -67,14 +81,13 @@ public class UserManagerTest extends AndroidTestCase {
assertTrue(findUser(0));
assertTrue(findUser(user1.id));
assertTrue(findUser(user2.id));
- mUserManager.removeUser(user1.id);
- mUserManager.removeUser(user2.id);
+ removeUser(user1.id);
+ removeUser(user2.id);
}
public void testRemoveUser() throws Exception {
UserInfo userInfo = mUserManager.createUser("Guest 1", UserInfo.FLAG_GUEST);
-
- mUserManager.removeUser(userInfo.id);
+ removeUser(userInfo.id);
assertFalse(findUser(userInfo.id));
}
@@ -95,12 +108,47 @@ public class UserManagerTest extends AndroidTestCase {
int serialNumber1 = user1.serialNumber;
assertEquals(serialNumber1, mUserManager.getUserSerialNumber(user1.id));
assertEquals(user1.id, mUserManager.getUserHandle(serialNumber1));
- mUserManager.removeUser(user1.id);
+ removeUser(user1.id);
UserInfo user2 = mUserManager.createUser("User 2", UserInfo.FLAG_RESTRICTED);
int serialNumber2 = user2.serialNumber;
assertFalse(serialNumber1 == serialNumber2);
assertEquals(serialNumber2, mUserManager.getUserSerialNumber(user2.id));
assertEquals(user2.id, mUserManager.getUserHandle(serialNumber2));
- mUserManager.removeUser(user2.id);
+ removeUser(user2.id);
+ }
+
+ public void testMaxUsers() {
+ int N = UserManager.getMaxSupportedUsers();
+ int count = mUserManager.getUsers().size();
+ List<UserInfo> created = new ArrayList<UserInfo>();
+ // Create as many users as permitted and make sure creation passes
+ while (count < N) {
+ UserInfo ui = mUserManager.createUser("User " + count, 0);
+ assertNotNull(ui);
+ created.add(ui);
+ count++;
+ }
+ // Try to create one more user and make sure it fails
+ UserInfo extra = null;
+ assertNull(extra = mUserManager.createUser("One more", 0));
+ if (extra != null) {
+ removeUser(extra.id);
+ }
+ while (!created.isEmpty()) {
+ UserInfo user = created.remove(0);
+ removeUser(user.id);
+ }
+ }
+
+ private void removeUser(int userId) {
+ synchronized (mUserLock) {
+ mUserManager.removeUser(userId);
+ while (mUserManager.getUserInfo(userId) != null) {
+ try {
+ mUserLock.wait(1000);
+ } catch (InterruptedException ie) {
+ }
+ }
+ }
}
}