Search in sources :

Example 81 with UserManager

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

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 82 with UserManager

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

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 83 with UserManager

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

the class ActivityStarter method startActivityMayWait.

final int startActivityMayWait(IApplicationThread caller, int callingUid, String callingPackage, Intent intent, String resolvedType, IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, IBinder resultTo, String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, IActivityManager.WaitResult outResult, Configuration config, Bundle bOptions, boolean ignoreTargetSecurity, int userId, IActivityContainer iContainer, TaskRecord inTask) {
    // Refuse possible leaked file descriptors
    if (intent != null && intent.hasFileDescriptors()) {
        throw new IllegalArgumentException("File descriptors passed in Intent");
    }
    mSupervisor.mActivityMetricsLogger.notifyActivityLaunching();
    boolean componentSpecified = intent.getComponent() != null;
    // Save a copy in case ephemeral needs it
    final Intent ephemeralIntent = new Intent(intent);
    // Don't modify the client's object!
    intent = new Intent(intent);
    ResolveInfo rInfo = mSupervisor.resolveIntent(intent, resolvedType, userId);
    if (rInfo == null) {
        UserInfo userInfo = mSupervisor.getUserInfo(userId);
        if (userInfo != null && userInfo.isManagedProfile()) {
            // Special case for managed profiles, if attempting to launch non-cryto aware
            // app in a locked managed profile from an unlocked parent allow it to resolve
            // as user will be sent via confirm credentials to unlock the profile.
            UserManager userManager = UserManager.get(mService.mContext);
            boolean profileLockedAndParentUnlockingOrUnlocked = false;
            long token = Binder.clearCallingIdentity();
            try {
                UserInfo parent = userManager.getProfileParent(userId);
                profileLockedAndParentUnlockingOrUnlocked = (parent != null) && userManager.isUserUnlockingOrUnlocked(parent.id) && !userManager.isUserUnlockingOrUnlocked(userId);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
            if (profileLockedAndParentUnlockingOrUnlocked) {
                rInfo = mSupervisor.resolveIntent(intent, resolvedType, userId, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
            }
        }
    }
    // Collect information about the target of the Intent.
    ActivityInfo aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, profilerInfo);
    ActivityOptions options = ActivityOptions.fromBundle(bOptions);
    ActivityStackSupervisor.ActivityContainer container = (ActivityStackSupervisor.ActivityContainer) iContainer;
    synchronized (mService) {
        if (container != null && container.mParentActivity != null && container.mParentActivity.state != RESUMED) {
            // Cannot start a child activity if the parent is not resumed.
            return ActivityManager.START_CANCELED;
        }
        final int realCallingPid = Binder.getCallingPid();
        final int realCallingUid = Binder.getCallingUid();
        int callingPid;
        if (callingUid >= 0) {
            callingPid = -1;
        } else if (caller == null) {
            callingPid = realCallingPid;
            callingUid = realCallingUid;
        } else {
            callingPid = callingUid = -1;
        }
        final ActivityStack stack;
        if (container == null || container.mStack.isOnHomeDisplay()) {
            stack = mSupervisor.mFocusedStack;
        } else {
            stack = container.mStack;
        }
        stack.mConfigWillChange = config != null && mService.mConfiguration.diff(config) != 0;
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG_CONFIGURATION, "Starting activity when config will change = " + stack.mConfigWillChange);
        final long origId = Binder.clearCallingIdentity();
        if (aInfo != null && (aInfo.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) {
            // have another, different heavy-weight process running.
            if (aInfo.processName.equals(aInfo.applicationInfo.packageName)) {
                final ProcessRecord heavy = mService.mHeavyWeightProcess;
                if (heavy != null && (heavy.info.uid != aInfo.applicationInfo.uid || !heavy.processName.equals(aInfo.processName))) {
                    int appCallingUid = callingUid;
                    if (caller != null) {
                        ProcessRecord callerApp = mService.getRecordForAppLocked(caller);
                        if (callerApp != null) {
                            appCallingUid = callerApp.info.uid;
                        } else {
                            Slog.w(TAG, "Unable to find app for caller " + caller + " (pid=" + callingPid + ") when starting: " + intent.toString());
                            ActivityOptions.abort(options);
                            return ActivityManager.START_PERMISSION_DENIED;
                        }
                    }
                    IIntentSender target = mService.getIntentSenderLocked(ActivityManager.INTENT_SENDER_ACTIVITY, "android", appCallingUid, userId, null, null, 0, new Intent[] { intent }, new String[] { resolvedType }, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT, null);
                    Intent newIntent = new Intent();
                    if (requestCode >= 0) {
                        // Caller is requesting a result.
                        newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_HAS_RESULT, true);
                    }
                    newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_INTENT, new IntentSender(target));
                    if (heavy.activities.size() > 0) {
                        ActivityRecord hist = heavy.activities.get(0);
                        newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_APP, hist.packageName);
                        newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_TASK, hist.task.taskId);
                    }
                    newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_NEW_APP, aInfo.packageName);
                    newIntent.setFlags(intent.getFlags());
                    newIntent.setClassName("android", HeavyWeightSwitcherActivity.class.getName());
                    intent = newIntent;
                    resolvedType = null;
                    caller = null;
                    callingUid = Binder.getCallingUid();
                    callingPid = Binder.getCallingPid();
                    componentSpecified = true;
                    rInfo = mSupervisor.resolveIntent(intent, null, /*resolvedType*/
                    userId);
                    aInfo = rInfo != null ? rInfo.activityInfo : null;
                    if (aInfo != null) {
                        aInfo = mService.getActivityInfoForUser(aInfo, userId);
                    }
                }
            }
        }
        final ActivityRecord[] outRecord = new ActivityRecord[1];
        int res = startActivityLocked(caller, intent, ephemeralIntent, resolvedType, aInfo, rInfo, voiceSession, voiceInteractor, resultTo, resultWho, requestCode, callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags, options, ignoreTargetSecurity, componentSpecified, outRecord, container, inTask);
        Binder.restoreCallingIdentity(origId);
        if (stack.mConfigWillChange) {
            // If the caller also wants to switch to a new configuration,
            // do so now.  This allows a clean switch, as we are waiting
            // for the current activity to pause (so we will not destroy
            // it), and have not yet started the next activity.
            mService.enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION, "updateConfiguration()");
            stack.mConfigWillChange = false;
            if (DEBUG_CONFIGURATION)
                Slog.v(TAG_CONFIGURATION, "Updating to new configuration after starting activity.");
            mService.updateConfigurationLocked(config, null, false);
        }
        if (outResult != null) {
            outResult.result = res;
            if (res == ActivityManager.START_SUCCESS) {
                mSupervisor.mWaitingActivityLaunched.add(outResult);
                do {
                    try {
                        mService.wait();
                    } catch (InterruptedException e) {
                    }
                } while (outResult.result != START_TASK_TO_FRONT && !outResult.timeout && outResult.who == null);
                if (outResult.result == START_TASK_TO_FRONT) {
                    res = START_TASK_TO_FRONT;
                }
            }
            if (res == START_TASK_TO_FRONT) {
                ActivityRecord r = stack.topRunningActivityLocked();
                if (r.nowVisible && r.state == RESUMED) {
                    outResult.timeout = false;
                    outResult.who = new ComponentName(r.info.packageName, r.info.name);
                    outResult.totalTime = 0;
                    outResult.thisTime = 0;
                } else {
                    outResult.thisTime = SystemClock.uptimeMillis();
                    mSupervisor.mWaitingActivityVisible.add(outResult);
                    do {
                        try {
                            mService.wait();
                        } catch (InterruptedException e) {
                        }
                    } while (!outResult.timeout && outResult.who == null);
                }
            }
        }
        final ActivityRecord launchedActivity = mReusedActivity != null ? mReusedActivity : outRecord[0];
        mSupervisor.mActivityMetricsLogger.notifyActivityLaunched(res, launchedActivity);
        return res;
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) HeavyWeightSwitcherActivity(com.android.internal.app.HeavyWeightSwitcherActivity) IActivityContainer(android.app.IActivityContainer) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) UserInfo(android.content.pm.UserInfo) ResolveInfo(android.content.pm.ResolveInfo) IIntentSender(android.content.IIntentSender) UserManager(android.os.UserManager) ComponentName(android.content.ComponentName) IntentSender(android.content.IntentSender) IIntentSender(android.content.IIntentSender) ActivityOptions(android.app.ActivityOptions)

Example 84 with UserManager

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

the class MediaSessionService method updateUser.

private void updateUser() {
    synchronized (mLock) {
        UserManager manager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
        int currentUser = ActivityManager.getCurrentUser();
        // Include all profiles even though they aren't yet enabled to handle work profile case.
        int[] userIds = manager.getProfileIdsWithDisabled(currentUser);
        mCurrentUserIdList.clear();
        if (userIds != null && userIds.length > 0) {
            for (int userId : userIds) {
                mCurrentUserIdList.add(userId);
            }
        } else {
            // This shouldn't happen.
            Log.w(TAG, "Failed to get enabled profiles.");
            mCurrentUserIdList.add(currentUser);
        }
        for (int userId : mCurrentUserIdList) {
            if (mUserRecords.get(userId) == null) {
                mUserRecords.put(userId, new UserRecord(getContext(), userId));
            }
        }
    }
}
Also used : UserManager(android.os.UserManager)

Example 85 with UserManager

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

the class PackageManagerService method loadPrivatePackagesInner.

private void loadPrivatePackagesInner(VolumeInfo vol) {
    final String volumeUuid = vol.fsUuid;
    if (TextUtils.isEmpty(volumeUuid)) {
        Slog.e(TAG, "Loading internal storage is probably a mistake; ignoring");
        return;
    }
    final ArrayList<PackageFreezer> freezers = new ArrayList<>();
    final ArrayList<ApplicationInfo> loaded = new ArrayList<>();
    final int parseFlags = mDefParseFlags | PackageParser.PARSE_EXTERNAL_STORAGE;
    final VersionInfo ver;
    final List<PackageSetting> packages;
    synchronized (mPackages) {
        ver = mSettings.findOrCreateVersion(volumeUuid);
        packages = mSettings.getVolumePackagesLPr(volumeUuid);
    }
    for (PackageSetting ps : packages) {
        freezers.add(freezePackage(ps.name, "loadPrivatePackagesInner"));
        synchronized (mInstallLock) {
            final PackageParser.Package pkg;
            try {
                pkg = scanPackageTracedLI(ps.codePath, parseFlags, SCAN_INITIAL, 0, null);
                loaded.add(pkg.applicationInfo);
            } catch (PackageManagerException e) {
                Slog.w(TAG, "Failed to scan " + ps.codePath + ": " + e.getMessage());
            }
            if (!Build.FINGERPRINT.equals(ver.fingerprint)) {
                clearAppDataLIF(ps.pkg, UserHandle.USER_ALL, StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE | Installer.FLAG_CLEAR_CODE_CACHE_ONLY);
            }
        }
    }
    // Reconcile app data for all started/unlocked users
    final StorageManager sm = mContext.getSystemService(StorageManager.class);
    final UserManager um = mContext.getSystemService(UserManager.class);
    UserManagerInternal umInternal = getUserManagerInternal();
    for (UserInfo user : um.getUsers()) {
        final int flags;
        if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
            flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
        } else if (umInternal.isUserRunning(user.id)) {
            flags = StorageManager.FLAG_STORAGE_DE;
        } else {
            continue;
        }
        try {
            sm.prepareUserStorage(volumeUuid, user.id, user.serialNumber, flags);
            synchronized (mInstallLock) {
                reconcileAppsDataLI(volumeUuid, user.id, flags);
            }
        } catch (IllegalStateException e) {
            // Device was probably ejected, and we'll process that event momentarily
            Slog.w(TAG, "Failed to prepare storage: " + e);
        }
    }
    synchronized (mPackages) {
        int updateFlags = UPDATE_PERMISSIONS_ALL;
        if (ver.sdkVersion != mSdkVersion) {
            logCriticalInfo(Log.INFO, "Platform changed from " + ver.sdkVersion + " to " + mSdkVersion + "; regranting permissions for " + volumeUuid);
            updateFlags |= UPDATE_PERMISSIONS_REPLACE_PKG | UPDATE_PERMISSIONS_REPLACE_ALL;
        }
        updatePermissionsLPw(null, null, volumeUuid, updateFlags);
        // Yay, everything is now upgraded
        ver.forceCurrent();
        mSettings.writeLPr();
    }
    for (PackageFreezer freezer : freezers) {
        freezer.close();
    }
    if (DEBUG_INSTALL)
        Slog.d(TAG, "Loaded packages " + loaded);
    sendResourcesChangedBroadcast(true, false, loaded, null);
}
Also used : ArrayList(java.util.ArrayList) EphemeralApplicationInfo(android.content.pm.EphemeralApplicationInfo) ApplicationInfo(android.content.pm.ApplicationInfo) StorageManager(android.os.storage.StorageManager) UserInfo(android.content.pm.UserInfo) VersionInfo(com.android.server.pm.Settings.VersionInfo) PackageParser(android.content.pm.PackageParser) UserManagerInternal(android.os.UserManagerInternal) 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