Search in sources :

Example 86 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 87 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 88 with UserManager

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

the class BaseSettingsProviderTest method setContext.

@Override
public void setContext(Context context) {
    super.setContext(context);
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    List<UserInfo> users = userManager.getUsers();
    final int userCount = users.size();
    for (int i = 0; i < userCount; i++) {
        UserInfo user = users.get(i);
        if (!user.isPrimary() && !user.isManagedProfile()) {
            mSecondaryUserId = user.id;
            break;
        }
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 89 with UserManager

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

the class SettingsHelper method setGpsLocation.

private void setGpsLocation(String value) {
    UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
        return;
    }
    final String GPS = LocationManager.GPS_PROVIDER;
    boolean enabled = GPS.equals(value) || value.startsWith(GPS + ",") || value.endsWith("," + GPS) || value.contains("," + GPS + ",");
    Settings.Secure.setLocationProviderEnabled(mContext.getContentResolver(), GPS, enabled);
}
Also used : UserManager(android.os.UserManager)

Example 90 with UserManager

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

the class SettingsProviderTest method testSettingsChangeForOtherUser.

@MediumTest
public void testSettingsChangeForOtherUser() {
    UserManager um = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
    ContentResolver r = getContext().getContentResolver();
    // Make sure there's an owner
    assertTrue(findUser(um, UserHandle.USER_SYSTEM));
    // create a new user to use for testing
    UserInfo otherUser = um.createUser("TestUser1", UserInfo.FLAG_GUEST);
    assertTrue(otherUser != null);
    try {
        assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId());
        final String testKey = "testSettingsChangeForOtherUser";
        final String testValue1 = "value1";
        final String testValue2 = "value2";
        Settings.Secure.putString(r, testKey, testValue1);
        Settings.Secure.putStringForUser(r, testKey, testValue2, otherUser.id);
        assertEquals(testValue1, Settings.Secure.getString(r, testKey));
        assertEquals(testValue2, Settings.Secure.getStringForUser(r, testKey, otherUser.id));
        assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId());
    } finally {
        // Tidy up
        um.removeUser(otherUser.id);
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

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