Search in sources :

Example 71 with UserManager

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

the class UidDetailProvider method buildUidDetail.

/**
     * Build {@link UidDetail} object, blocking until all {@link Drawable}
     * lookup is finished.
     */
private UidDetail buildUidDetail(int uid) {
    final Resources res = mContext.getResources();
    final PackageManager pm = mContext.getPackageManager();
    final UidDetail detail = new UidDetail();
    detail.label = pm.getNameForUid(uid);
    detail.icon = pm.getDefaultActivityIcon();
    // handle special case labels
    switch(uid) {
        case android.os.Process.SYSTEM_UID:
            detail.label = res.getString(R.string.process_kernel_label);
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
        case TrafficStats.UID_REMOVED:
            detail.label = res.getString(UserManager.supportsMultipleUsers() ? R.string.data_usage_uninstalled_apps_users : R.string.data_usage_uninstalled_apps);
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
        case TrafficStats.UID_TETHERING:
            final ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
            detail.label = res.getString(Utils.getTetheringLabel(cm));
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
    }
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    // Handle keys that are actually user handles
    if (isKeyForUser(uid)) {
        final int userHandle = getUserIdForKey(uid);
        final UserInfo info = um.getUserInfo(userHandle);
        if (info != null) {
            detail.label = Utils.getUserLabel(mContext, info);
            detail.icon = Utils.getUserIcon(mContext, um, info);
            return detail;
        }
    }
    // otherwise fall back to using packagemanager labels
    final String[] packageNames = pm.getPackagesForUid(uid);
    final int length = packageNames != null ? packageNames.length : 0;
    try {
        final int userId = UserHandle.getUserId(uid);
        UserHandle userHandle = new UserHandle(userId);
        IPackageManager ipm = AppGlobals.getPackageManager();
        if (length == 1) {
            final ApplicationInfo info = ipm.getApplicationInfo(packageNames[0], 0, /* no flags */
            userId);
            if (info != null) {
                detail.label = info.loadLabel(pm).toString();
                detail.icon = um.getBadgedIconForUser(info.loadIcon(pm), new UserHandle(userId));
            }
        } else if (length > 1) {
            detail.detailLabels = new CharSequence[length];
            detail.detailContentDescriptions = new CharSequence[length];
            for (int i = 0; i < length; i++) {
                final String packageName = packageNames[i];
                final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
                final ApplicationInfo appInfo = ipm.getApplicationInfo(packageName, 0, /* no flags */
                userId);
                if (appInfo != null) {
                    detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
                    detail.detailContentDescriptions[i] = um.getBadgedLabelForUser(detail.detailLabels[i], userHandle);
                    if (packageInfo.sharedUserLabel != 0) {
                        detail.label = pm.getText(packageName, packageInfo.sharedUserLabel, packageInfo.applicationInfo).toString();
                        detail.icon = um.getBadgedIconForUser(appInfo.loadIcon(pm), userHandle);
                    }
                }
            }
        }
        detail.contentDescription = um.getBadgedLabelForUser(detail.label, userHandle);
    } catch (NameNotFoundException e) {
        Log.w(TAG, "Error while building UI detail for uid " + uid, e);
    } catch (RemoteException e) {
        Log.w(TAG, "Error while building UI detail for uid " + uid, e);
    }
    if (TextUtils.isEmpty(detail.label)) {
        detail.label = Integer.toString(uid);
    }
    return detail;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ConnectivityManager(android.net.ConnectivityManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Example 72 with UserManager

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

the class GuestResumeSessionReceiver method wipeGuestSession.

/**
     * Wipes the guest session.
     *
     * The guest must be the current user and its id must be {@param userId}.
     */
private static void wipeGuestSession(Context context, int userId) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    UserInfo currentUser;
    try {
        currentUser = ActivityManagerNative.getDefault().getCurrentUser();
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't wipe session because ActivityManager is dead");
        return;
    }
    if (currentUser.id != userId) {
        Log.w(TAG, "User requesting to start a new session (" + userId + ")" + " is not current user (" + currentUser.id + ")");
        return;
    }
    if (!currentUser.isGuest()) {
        Log.w(TAG, "User requesting to start a new session (" + userId + ")" + " is not a guest");
        return;
    }
    boolean marked = userManager.markGuestForDeletion(currentUser.id);
    if (!marked) {
        Log.w(TAG, "Couldn't mark the guest for deletion for user " + userId);
        return;
    }
    UserInfo newGuest = userManager.createGuest(context, currentUser.name);
    try {
        if (newGuest == null) {
            Log.e(TAG, "Could not create new guest, switching back to system user");
            ActivityManagerNative.getDefault().switchUser(UserHandle.USER_SYSTEM);
            userManager.removeUser(currentUser.id);
            WindowManagerGlobal.getWindowManagerService().lockNow(null);
            return;
        }
        ActivityManagerNative.getDefault().switchUser(newGuest.id);
        userManager.removeUser(currentUser.id);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't wipe session because ActivityManager or WindowManager is dead");
        return;
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException)

Example 73 with UserManager

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

the class RecentsTaskLoadPlan method migrateLegacyLastStackActiveTime.

/**
     * Migrate the last active time from the prefs to the secure settings.
     *
     * The first time this runs, it will:
     * 1) fetch the last stack active time from the prefs
     * 2) set the prefs to the last stack active time for all users
     * 3) clear the pref
     * 4) return the last stack active time
     *
     * Subsequent calls to this will return zero.
     */
private long migrateLegacyLastStackActiveTime(int currentUserId) {
    long legacyLastStackActiveTime = Prefs.getLong(mContext, Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, -1);
    if (legacyLastStackActiveTime != -1) {
        Prefs.remove(mContext, Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME);
        UserManager userMgr = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        List<UserInfo> users = userMgr.getUsers();
        for (int i = 0; i < users.size(); i++) {
            int userId = users.get(i).id;
            if (userId != currentUserId) {
                Settings.Secure.putLongForUser(mContext.getContentResolver(), Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, legacyLastStackActiveTime, userId);
            }
        }
        return legacyLastStackActiveTime;
    }
    return 0;
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 74 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class MtpDevice method open.

/**
     * Opens the MTP device.  Once the device is open it takes ownership of the
     * {@link android.hardware.usb.UsbDeviceConnection}.
     * The connection will be closed when you call {@link #close()}
     * The connection will also be closed if this method fails.
     *
     * @param connection an open {@link android.hardware.usb.UsbDeviceConnection} for the device
     * @return true if the device was successfully opened.
     */
public boolean open(UsbDeviceConnection connection) {
    boolean result = false;
    Context context = connection.getContext();
    if (context != null) {
        UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        if (!userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
            result = native_open(mDevice.getDeviceName(), connection.getFileDescriptor());
        }
    }
    if (!result) {
        connection.close();
    }
    return result;
}
Also used : Context(android.content.Context) UserManager(android.os.UserManager)

Example 75 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

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)

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