Search in sources :

Example 61 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class UserManagerTest method testAdd2Users.

public void testAdd2Users() throws Exception {
    UserInfo user1 = createUser("Guest 1", UserInfo.FLAG_GUEST);
    UserInfo user2 = createUser("User 2", UserInfo.FLAG_ADMIN);
    assertTrue(user1 != null);
    assertTrue(user2 != null);
    assertTrue(findUser(0));
    assertTrue(findUser(user1.id));
    assertTrue(findUser(user2.id));
}
Also used : UserInfo(android.content.pm.UserInfo)

Example 62 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class UserManagerTest method testAddManagedProfile.

// Make sure only one managed profile can be created
public void testAddManagedProfile() throws Exception {
    final int primaryUserId = mUserManager.getPrimaryUser().id;
    UserInfo userInfo1 = createProfileForUser("Managed 1", UserInfo.FLAG_MANAGED_PROFILE, primaryUserId);
    UserInfo userInfo2 = createProfileForUser("Managed 2", UserInfo.FLAG_MANAGED_PROFILE, primaryUserId);
    assertNotNull(userInfo1);
    assertNull(userInfo2);
    // Verify that current user is not a managed profile
    assertFalse(mUserManager.isManagedProfile());
}
Also used : UserInfo(android.content.pm.UserInfo)

Example 63 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class UserManagerTest method testAddUser.

public void testAddUser() throws Exception {
    UserInfo userInfo = createUser("Guest 1", UserInfo.FLAG_GUEST);
    assertTrue(userInfo != null);
    List<UserInfo> list = mUserManager.getUsers();
    boolean found = false;
    for (UserInfo user : list) {
        if (user.id == userInfo.id && user.name.equals("Guest 1") && user.isGuest() && !user.isAdmin() && !user.isPrimary()) {
            found = true;
            Bundle restrictions = mUserManager.getUserRestrictions(user.getUserHandle());
            assertTrue("Guest user should have DISALLOW_CONFIG_WIFI=true by default", restrictions.getBoolean(UserManager.DISALLOW_CONFIG_WIFI));
        }
    }
    assertTrue(found);
}
Also used : Bundle(android.os.Bundle) UserInfo(android.content.pm.UserInfo)

Example 64 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class UserManagerTest method testSerialNumber.

public void testSerialNumber() {
    UserInfo user1 = createUser("User 1", 0);
    int serialNumber1 = user1.serialNumber;
    assertEquals(serialNumber1, mUserManager.getUserSerialNumber(user1.id));
    assertEquals(user1.id, mUserManager.getUserHandle(serialNumber1));
    UserInfo user2 = createUser("User 2", 0);
    int serialNumber2 = user2.serialNumber;
    assertFalse(serialNumber1 == serialNumber2);
    assertEquals(serialNumber2, mUserManager.getUserSerialNumber(user2.id));
    assertEquals(user2.id, mUserManager.getUserHandle(serialNumber2));
}
Also used : UserInfo(android.content.pm.UserInfo)

Example 65 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class PermissionMonitor method startMonitoring.

// Intended to be called only once at startup, after the system is ready. Installs a broadcast
// receiver to monitor ongoing UID changes, so this shouldn't/needn't be called again.
public synchronized void startMonitoring() {
    log("Monitoring");
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_USER_ADDED);
    intentFilter.addAction(Intent.ACTION_USER_REMOVED);
    mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, intentFilter, null, null);
    intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, intentFilter, null, null);
    List<PackageInfo> apps = mPackageManager.getInstalledPackages(GET_PERMISSIONS);
    if (apps == null) {
        loge("No apps");
        return;
    }
    for (PackageInfo app : apps) {
        int uid = app.applicationInfo != null ? app.applicationInfo.uid : -1;
        if (uid < 0) {
            continue;
        }
        boolean isNetwork = hasNetworkPermission(app);
        boolean hasRestrictedPermission = hasRestrictedNetworkPermission(app);
        if (isNetwork || hasRestrictedPermission) {
            Boolean permission = mApps.get(uid);
            // permissions, don't downgrade (i.e., if it's already SYSTEM, leave it as is).
            if (permission == null || permission == NETWORK) {
                mApps.put(uid, hasRestrictedPermission);
            }
        }
    }
    // exclude dying users
    List<UserInfo> users = mUserManager.getUsers(true);
    if (users != null) {
        for (UserInfo user : users) {
            mUsers.add(user.id);
        }
    }
    log("Users: " + mUsers.size() + ", Apps: " + mApps.size());
    update(mUsers, mApps, true);
}
Also used : IntentFilter(android.content.IntentFilter) PackageInfo(android.content.pm.PackageInfo) UserInfo(android.content.pm.UserInfo)

Aggregations

UserInfo (android.content.pm.UserInfo)814 UserManager (android.os.UserManager)156 RemoteException (android.os.RemoteException)144 ArrayList (java.util.ArrayList)73 UserHandle (android.os.UserHandle)66 Intent (android.content.Intent)58 IOException (java.io.IOException)52 File (java.io.File)47 Bundle (android.os.Bundle)43 ApplicationInfo (android.content.pm.ApplicationInfo)40 PackageManager (android.content.pm.PackageManager)39 ComponentName (android.content.ComponentName)32 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)31 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)30 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)29 AtomicFile (android.util.AtomicFile)28 PackageInfo (android.content.pm.PackageInfo)26 DevicePolicyManager (android.app.admin.DevicePolicyManager)25 LockPatternUtils (com.android.internal.widget.LockPatternUtils)24 PendingIntent (android.app.PendingIntent)23