Search in sources :

Example 81 with UserInfo

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

the class DevicePolicyManagerService method getMaximumTimeToLockForUserAndProfiles.

@Override
public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
    if (!mHasFeature) {
        return 0;
    }
    enforceFullCrossUsersPermission(userHandle);
    synchronized (this) {
        // All admins for this user.
        ArrayList<ActiveAdmin> admins = new ArrayList<ActiveAdmin>();
        for (UserInfo userInfo : mUserManager.getProfiles(userHandle)) {
            DevicePolicyData policy = getUserData(userInfo.id);
            admins.addAll(policy.mAdminList);
            // If it is a managed profile, it may have parent active admins
            if (userInfo.isManagedProfile()) {
                for (ActiveAdmin admin : policy.mAdminList) {
                    if (admin.hasParentActiveAdmin()) {
                        admins.add(admin.getParentActiveAdmin());
                    }
                }
            }
        }
        return getMaximumTimeToLockPolicyFromAdmins(admins);
    }
}
Also used : ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo)

Example 82 with UserInfo

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

the class DevicePolicyManagerService method getActiveAdminsForLockscreenPoliciesLocked.

private List<ActiveAdmin> getActiveAdminsForLockscreenPoliciesLocked(int userHandle, boolean parent) {
    if (!parent && isSeparateProfileChallengeEnabled(userHandle)) {
        // If this user has a separate challenge, only return its restrictions.
        return getUserDataUnchecked(userHandle).mAdminList;
    } else {
        // Return all admins for this user and the profiles that are visible from this
        // user that do not use a separate work challenge.
        ArrayList<ActiveAdmin> admins = new ArrayList<ActiveAdmin>();
        for (UserInfo userInfo : mUserManager.getProfiles(userHandle)) {
            DevicePolicyData policy = getUserData(userInfo.id);
            if (!userInfo.isManagedProfile()) {
                admins.addAll(policy.mAdminList);
            } else {
                // For managed profiles, we always include the policies set on the parent
                // profile. Additionally, we include the ones set on the managed profile
                // if no separate challenge is in place.
                boolean hasSeparateChallenge = isSeparateProfileChallengeEnabled(userInfo.id);
                final int N = policy.mAdminList.size();
                for (int i = 0; i < N; i++) {
                    ActiveAdmin admin = policy.mAdminList.get(i);
                    if (admin.hasParentActiveAdmin()) {
                        admins.add(admin.getParentActiveAdmin());
                    }
                    if (!hasSeparateChallenge) {
                        admins.add(admin);
                    }
                }
            }
        }
        return admins;
    }
}
Also used : ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo)

Example 83 with UserInfo

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

the class DevicePolicyManagerService method migrateUserRestrictionsIfNecessaryLocked.

/**
     * We didn't use to persist user restrictions for each owners but only persisted in user
     * manager.
     */
private void migrateUserRestrictionsIfNecessaryLocked() {
    boolean migrated = false;
    // except for the "system controlled" ones.
    if (mOwners.getDeviceOwnerUserRestrictionsNeedsMigration()) {
        if (VERBOSE_LOG) {
            Log.v(LOG_TAG, "Migrating DO user restrictions");
        }
        migrated = true;
        // Migrate user 0 restrictions to DO.
        final ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
        migrateUserRestrictionsForUser(UserHandle.SYSTEM, deviceOwnerAdmin, /* exceptionList =*/
        null, /* isDeviceOwner =*/
        true);
        // Push DO user restrictions to user manager.
        pushUserRestrictions(UserHandle.USER_SYSTEM);
        mOwners.setDeviceOwnerUserRestrictionsMigrated();
    }
    // Migrate for POs.
    // The following restrictions can be set on secondary users by the device owner, so we
    // assume they're not from the PO.
    final Set<String> secondaryUserExceptionList = Sets.newArraySet(UserManager.DISALLOW_OUTGOING_CALLS, UserManager.DISALLOW_SMS);
    for (UserInfo ui : mUserManager.getUsers()) {
        final int userId = ui.id;
        if (mOwners.getProfileOwnerUserRestrictionsNeedsMigration(userId)) {
            if (VERBOSE_LOG) {
                Log.v(LOG_TAG, "Migrating PO user restrictions for user " + userId);
            }
            migrated = true;
            final ActiveAdmin profileOwnerAdmin = getProfileOwnerAdminLocked(userId);
            final Set<String> exceptionList = (userId == UserHandle.USER_SYSTEM) ? null : secondaryUserExceptionList;
            migrateUserRestrictionsForUser(ui.getUserHandle(), profileOwnerAdmin, exceptionList, /* isDeviceOwner =*/
            false);
            // Note if a secondary user has no PO but has a DA that disables camera, we
            // don't get here and won't push the camera user restriction to UserManager
            // here.  That's okay because we'll push user restrictions anyway when a user
            // starts.  But we still do it because we want to let user manager persist
            // upon migration.
            pushUserRestrictions(userId);
            mOwners.setProfileOwnerUserRestrictionsMigrated(userId);
        }
    }
    if (VERBOSE_LOG && migrated) {
        Log.v(LOG_TAG, "User restrictions migrated.");
    }
}
Also used : UserInfo(android.content.pm.UserInfo) ParcelableString(com.android.internal.util.ParcelableString)

Example 84 with UserInfo

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

the class UserManagerServiceTest method testAddUserWithAccount.

public void testAddUserWithAccount() {
    UserManager um = UserManager.get(mContext);
    UserInfo user = um.createUser("Test User", 0);
    assertNotNull(user);
    tempUserId = user.id;
    String accountName = "Test Account";
    um.setUserAccount(tempUserId, accountName);
    assertEquals(accountName, um.getUserAccount(tempUserId));
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 85 with UserInfo

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

the class LockSettingsStorageTests method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mStorageDir = new File(getContext().getFilesDir(), "locksettings");
    mDb = getContext().getDatabasePath("locksettings.db");
    assertTrue(mStorageDir.exists() || mStorageDir.mkdirs());
    assertTrue(FileUtils.deleteContents(mStorageDir));
    assertTrue(!mDb.exists() || mDb.delete());
    final Context ctx = getContext();
    setContext(new ContextWrapper(ctx) {

        @Override
        public Object getSystemService(String name) {
            if (USER_SERVICE.equals(name)) {
                return new UserManager(ctx, null) {

                    @Override
                    public UserInfo getProfileParent(int userHandle) {
                        if (userHandle == 2) {
                            // User 2 is a profile of user 1.
                            return new UserInfo(1, "name", 0);
                        }
                        if (userHandle == 3) {
                            // User 3 is a profile of user 0.
                            return new UserInfo(0, "name", 0);
                        }
                        return null;
                    }
                };
            }
            return super.getSystemService(name);
        }
    });
    mStorage = new LockSettingsStorage(getContext(), new LockSettingsStorage.Callback() {

        @Override
        public void initialize(SQLiteDatabase db) {
            mStorage.writeKeyValue(db, "initializedKey", "initialValue", 0);
        }
    }) {

        @Override
        String getLockPatternFilename(int userId) {
            return new File(mStorageDir, super.getLockPatternFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getLockPasswordFilename(int userId) {
            return new File(mStorageDir, super.getLockPasswordFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getChildProfileLockFile(int userId) {
            return new File(mStorageDir, super.getChildProfileLockFile(userId).replace('/', '-')).getAbsolutePath();
        }
    };
}
Also used : Context(android.content.Context) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) File(java.io.File) ContextWrapper(android.content.ContextWrapper)

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