Search in sources :

Example 26 with UserManager

use of android.os.UserManager 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 27 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)

Example 28 with UserManager

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

the class PackageManagerService method prepareAppDataAfterInstallLIF.

/**
     * Prepare app data for the given app just after it was installed or
     * upgraded. This method carefully only touches users that it's installed
     * for, and it forces a restorecon to handle any seinfo changes.
     * <p>
     * Verifies that directories exist and that ownership and labeling is
     * correct for all installed apps. If there is an ownership mismatch, it
     * will try recovering system apps by wiping data; third-party app data is
     * left intact.
     * <p>
     * <em>Note: To avoid a deadlock, do not call this method with {@code mPackages} lock held</em>
     */
private void prepareAppDataAfterInstallLIF(PackageParser.Package pkg) {
    final PackageSetting ps;
    synchronized (mPackages) {
        ps = mSettings.mPackages.get(pkg.packageName);
        mSettings.writeKernelMappingLPr(ps);
    }
    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;
        }
        if (ps.getInstalled(user.id)) {
            // TODO: when user data is locked, mark that we're still dirty
            prepareAppDataLIF(pkg, user.id, flags);
        }
    }
}
Also used : UserManagerInternal(android.os.UserManagerInternal) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 29 with UserManager

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

the class WallpaperManagerService method isSetWallpaperAllowed.

@Override
public boolean isSetWallpaperAllowed(String callingPackage) {
    final PackageManager pm = mContext.getPackageManager();
    String[] uidPackages = pm.getPackagesForUid(Binder.getCallingUid());
    boolean uidMatchPackage = Arrays.asList(uidPackages).contains(callingPackage);
    if (!uidMatchPackage) {
        // callingPackage was faked.
        return false;
    }
    final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
    if (dpm.isDeviceOwnerApp(callingPackage) || dpm.isProfileOwnerApp(callingPackage)) {
        return true;
    }
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    return !um.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) UserManager(android.os.UserManager)

Example 30 with UserManager

use of android.os.UserManager 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

UserManager (android.os.UserManager)271 UserInfo (android.content.pm.UserInfo)146 UserHandle (android.os.UserHandle)44 RemoteException (android.os.RemoteException)40 Intent (android.content.Intent)30 DevicePolicyManager (android.app.admin.DevicePolicyManager)29 ComponentName (android.content.ComponentName)29 Context (android.content.Context)25 PackageManager (android.content.pm.PackageManager)25 ArrayList (java.util.ArrayList)21 PendingIntent (android.app.PendingIntent)16 LockPatternUtils (com.android.internal.widget.LockPatternUtils)16 ApplicationInfo (android.content.pm.ApplicationInfo)15 File (java.io.File)15 ContentResolver (android.content.ContentResolver)14 ResolveInfo (android.content.pm.ResolveInfo)13 IPackageManager (android.content.pm.IPackageManager)12 Drawable (android.graphics.drawable.Drawable)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Resources (android.content.res.Resources)11