Search in sources :

Example 56 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class StorageMeasurement method measureExactStorage.

private void measureExactStorage(IMediaContainerService imcs) {
    final UserManager userManager = mContext.getSystemService(UserManager.class);
    final PackageManager packageManager = mContext.getPackageManager();
    final List<UserInfo> users = userManager.getUsers();
    final List<UserInfo> currentProfiles = userManager.getEnabledProfiles(ActivityManager.getCurrentUser());
    final MeasurementDetails details = new MeasurementDetails();
    final Message finished = mMeasurementHandler.obtainMessage(MeasurementHandler.MSG_COMPLETED, details);
    if (mVolume == null || !mVolume.isMountedReadable()) {
        finished.sendToTarget();
        return;
    }
    if (mSharedVolume != null && mSharedVolume.isMountedReadable()) {
        for (UserInfo currentUserInfo : currentProfiles) {
            final int userId = currentUserInfo.id;
            final File basePath = mSharedVolume.getPathForUser(userId);
            HashMap<String, Long> mediaMap = new HashMap<>(sMeasureMediaTypes.size());
            details.mediaSize.put(userId, mediaMap);
            // external volume
            for (String type : sMeasureMediaTypes) {
                final File path = new File(basePath, type);
                final long size = getDirectorySize(imcs, path);
                mediaMap.put(type, size);
            }
            // Measure misc files not counted under media
            addValue(details.miscSize, userId, measureMisc(imcs, basePath));
        }
        if (mSharedVolume.getType() == VolumeInfo.TYPE_EMULATED) {
            // will be spliced in later
            for (UserInfo user : users) {
                final File userPath = mSharedVolume.getPathForUser(user.id);
                final long size = getDirectorySize(imcs, userPath);
                addValue(details.usersSize, user.id, size);
            }
        }
    }
    final File file = mVolume.getPath();
    if (file != null) {
        details.totalSize = file.getTotalSpace();
        details.availSize = file.getFreeSpace();
    }
    // Measure all apps hosted on this volume for all users
    if (mVolume.getType() == VolumeInfo.TYPE_PRIVATE) {
        final List<ApplicationInfo> apps = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
        final List<ApplicationInfo> volumeApps = new ArrayList<>();
        for (ApplicationInfo app : apps) {
            if (Objects.equals(app.volumeUuid, mVolume.getFsUuid())) {
                volumeApps.add(app);
            }
        }
        final int count = users.size() * volumeApps.size();
        if (count == 0) {
            finished.sendToTarget();
            return;
        }
        final StatsObserver observer = new StatsObserver(true, details, ActivityManager.getCurrentUser(), currentProfiles, finished, count);
        for (UserInfo user : users) {
            for (ApplicationInfo app : volumeApps) {
                packageManager.getPackageSizeInfoAsUser(app.packageName, user.id, observer);
            }
        }
    } else {
        finished.sendToTarget();
        return;
    }
}
Also used : Message(android.os.Message) HashMap(java.util.HashMap) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) PackageManager(android.content.pm.PackageManager) UserManager(android.os.UserManager) File(java.io.File) IPackageStatsObserver(android.content.pm.IPackageStatsObserver)

Example 57 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class RestrictedLockUtils method isAdminInCurrentUserOrProfile.

public static boolean isAdminInCurrentUserOrProfile(Context context, ComponentName admin) {
    DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    UserManager um = UserManager.get(context);
    for (UserInfo userInfo : um.getProfiles(UserHandle.myUserId())) {
        if (dpm.isAdminActiveAsUser(admin, userInfo.id)) {
            return true;
        }
    }
    return false;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 58 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class RestrictedLockUtils method checkIfPasswordQualityIsSet.

/**
     * Checks if an admin has enforced minimum password quality requirements on the given user.
     *
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} if no quality requirements are set. If the requirements are set by
     * multiple device admins, then the admin component will be set to {@code null} and userId to
     * {@link UserHandle#USER_NULL}.
     *
     */
public static EnforcedAdmin checkIfPasswordQualityIsSet(Context context, int userId) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
    EnforcedAdmin enforcedAdmin = null;
    if (lockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
        // userId is managed profile and has a separate challenge, only consider
        // the admins in that user.
        final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId);
        if (admins == null) {
            return null;
        }
        for (ComponentName admin : admins) {
            if (dpm.getPasswordQuality(admin, userId) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                if (enforcedAdmin == null) {
                    enforcedAdmin = new EnforcedAdmin(admin, userId);
                } else {
                    return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                }
            }
        }
    } else {
        // Return all admins for this user and the profiles that are visible from this
        // user that do not use a separate work challenge.
        final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
        for (UserInfo userInfo : um.getProfiles(userId)) {
            final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id);
            if (admins == null) {
                continue;
            }
            final boolean isSeparateProfileChallengeEnabled = lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id);
            for (ComponentName admin : admins) {
                if (!isSeparateProfileChallengeEnabled) {
                    if (dpm.getPasswordQuality(admin, userInfo.id) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                        } else {
                            return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                        }
                        // has set policy on the parent admin.
                        continue;
                    }
                }
                if (userInfo.isManagedProfile()) {
                    // If userInfo.id is a managed profile, we also need to look at
                    // the policies set on the parent.
                    DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
                    if (parentDpm.getPasswordQuality(admin, userInfo.id) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                        } else {
                            return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                        }
                    }
                }
            }
        }
    }
    return enforcedAdmin;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) ComponentName(android.content.ComponentName) UserInfo(android.content.pm.UserInfo)

Example 59 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class LockSettingsStorage method removeUser.

public void removeUser(int userId) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE);
    final UserInfo parentInfo = um.getProfileParent(userId);
    if (parentInfo == null) {
        // This user owns its lock settings files - safe to delete them
        synchronized (mFileWriteLock) {
            String name = getLockPasswordFilename(userId);
            File file = new File(name);
            if (file.exists()) {
                file.delete();
                mCache.putFile(name, null);
            }
            name = getLockPatternFilename(userId);
            file = new File(name);
            if (file.exists()) {
                file.delete();
                mCache.putFile(name, null);
            }
        }
    } else {
        // Manged profile
        removeChildProfileLock(userId);
    }
    try {
        db.beginTransaction();
        db.delete(TABLE, COLUMN_USERID + "='" + userId + "'", null);
        db.setTransactionSuccessful();
        mCache.removeUser(userId);
    } finally {
        db.endTransaction();
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 60 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class MountService method enforceAdminUser.

private void enforceAdminUser() {
    UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    final int callingUserId = UserHandle.getCallingUserId();
    boolean isAdmin;
    long token = Binder.clearCallingIdentity();
    try {
        isAdmin = um.getUserInfo(callingUserId).isAdmin();
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    if (!isAdmin) {
        throw new SecurityException("Only admin users can adopt sd cards");
    }
}
Also used : UserManager(android.os.UserManager)

Aggregations

UserManager (android.os.UserManager)587 UserInfo (android.content.pm.UserInfo)209 UserHandle (android.os.UserHandle)83 Context (android.content.Context)75 Intent (android.content.Intent)67 Test (org.junit.Test)60 PackageManager (android.content.pm.PackageManager)59 ComponentName (android.content.ComponentName)54 RemoteException (android.os.RemoteException)54 View (android.view.View)54 ArrayList (java.util.ArrayList)50 DevicePolicyManager (android.app.admin.DevicePolicyManager)37 Preference (android.support.v7.preference.Preference)32 TextView (android.widget.TextView)31 ImageView (android.widget.ImageView)29 IOException (java.io.IOException)29 Bitmap (android.graphics.Bitmap)26 Bundle (android.os.Bundle)25 ShadowUserManager (com.android.settings.testutils.shadow.ShadowUserManager)25 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)24