Search in sources :

Example 6 with UserManager

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

the class AccessibilityManagerService method switchUser.

private void switchUser(int userId) {
    synchronized (mLock) {
        if (mCurrentUserId == userId && mInitialized) {
            return;
        }
        // Disconnect from services for the old user.
        UserState oldUserState = getUserStateLocked(mCurrentUserId);
        oldUserState.onSwitchToAnotherUser();
        // Disable the local managers for the old user.
        if (oldUserState.mClients.getRegisteredCallbackCount() > 0) {
            mMainHandler.obtainMessage(MainHandler.MSG_SEND_CLEARED_STATE_TO_CLIENTS_FOR_USER, oldUserState.mUserId, 0).sendToTarget();
        }
        // Announce user changes only if more that one exist.
        UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        final boolean announceNewUser = userManager.getUsers().size() > 1;
        // The user changed.
        mCurrentUserId = userId;
        UserState userState = getCurrentUserStateLocked();
        if (userState.mUiAutomationService != null) {
            // Switching users disables the UI automation service.
            userState.mUiAutomationService.binderDied();
        }
        readConfigurationForUserStateLocked(userState);
        // Even if reading did not yield change, we have to update
        // the state since the context in which the current user
        // state was used has changed since it was inactive.
        onUserStateChangedLocked(userState);
        if (announceNewUser) {
            // Schedule announcement of the current user if needed.
            mMainHandler.sendEmptyMessageDelayed(MainHandler.MSG_ANNOUNCE_NEW_USER_IF_NEEDED, WAIT_FOR_USER_STATE_FULLY_INITIALIZED_MILLIS);
        }
    }
}
Also used : UserManager(android.os.UserManager)

Example 7 with UserManager

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

the class NetworkPolicyManagerService method updateRulesForRestrictBackgroundLocked.

/**
     * Update rules that might be changed by {@link #mRestrictBackground} value.
     */
private void updateRulesForRestrictBackgroundLocked() {
    final PackageManager pm = mContext.getPackageManager();
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    // update rules for all installed applications
    final List<UserInfo> users = um.getUsers();
    final List<ApplicationInfo> apps = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
    for (UserInfo user : users) {
        for (ApplicationInfo app : apps) {
            final int uid = UserHandle.getUid(user.id, app.uid);
            updateRulesForUidLocked(uid);
        }
    }
    // limit data usage for some internal system services
    updateRulesForUidLocked(android.os.Process.MEDIA_UID);
    updateRulesForUidLocked(android.os.Process.DRM_UID);
}
Also used : PackageManager(android.content.pm.PackageManager) UserManager(android.os.UserManager) ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo)

Example 8 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 9 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 10 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)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