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);
}
}
}
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);
}
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;
}
}
}
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);
}
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);
}
}
Aggregations