use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.
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();
}
};
}
use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.
the class ResolverActivity method setProfileSwitchMessageId.
private void setProfileSwitchMessageId(int contentUserHint) {
if (contentUserHint != UserHandle.USER_CURRENT && contentUserHint != UserHandle.myUserId()) {
UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
UserInfo originUserInfo = userManager.getUserInfo(contentUserHint);
boolean originIsManaged = originUserInfo != null ? originUserInfo.isManagedProfile() : false;
boolean targetIsManaged = userManager.isManagedProfile();
if (originIsManaged && !targetIsManaged) {
mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_owner;
} else if (!originIsManaged && targetIsManaged) {
mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_work;
}
}
}
use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.
the class IntentForwarderActivity method getProfileParent.
/**
* Returns the userId of the profile parent or UserHandle.USER_NULL if there is
* no parent.
*/
private int getProfileParent() {
UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
UserInfo parent = userManager.getProfileParent(UserHandle.myUserId());
if (parent == null) {
Slog.wtf(TAG, FORWARD_INTENT_TO_PARENT + " has been called, but there is no parent");
return UserHandle.USER_NULL;
}
return parent.id;
}
use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.
the class SettingsProviderTest method testPerUserSettings.
@MediumTest
public void testPerUserSettings() {
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 user = um.createUser("TestUser1", UserInfo.FLAG_GUEST);
assertTrue(user != null);
try {
// Write some settings for that user as well as the current user
final String TEST_KEY = "test_setting";
final int SELF_VALUE = 40;
final int OTHER_VALUE = 27;
Settings.Secure.putInt(r, TEST_KEY, SELF_VALUE);
Settings.Secure.putIntForUser(r, TEST_KEY, OTHER_VALUE, user.id);
// Verify that they read back as intended
int myValue = Settings.Secure.getInt(r, TEST_KEY, 0);
int otherValue = Settings.Secure.getIntForUser(r, TEST_KEY, 0, user.id);
assertTrue("Running as user " + UserHandle.myUserId() + " and reading/writing as user " + user.id + ", expected to read " + SELF_VALUE + " but got " + myValue, myValue == SELF_VALUE);
assertTrue("Running as user " + UserHandle.myUserId() + " and reading/writing as user " + user.id + ", expected to read " + OTHER_VALUE + " but got " + otherValue, otherValue == OTHER_VALUE);
} finally {
// Tidy up
um.removeUser(user.id);
}
}
use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.
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