use of com.lody.virtual.os.VUserInfo in project VirtualApp by asLody.
the class VUserManagerService method readUser.
private VUserInfo readUser(int id) {
int flags = 0;
int serialNumber = id;
String name = null;
String iconPath = null;
long creationTime = 0L;
long lastLoggedInTime = 0L;
boolean partial = false;
FileInputStream fis = null;
try {
AtomicFile userFile = new AtomicFile(new File(mUsersDir, Integer.toString(id) + ".xml"));
fis = userFile.openRead();
XmlPullParser parser = Xml.newPullParser();
parser.setInput(fis, null);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
;
}
if (type != XmlPullParser.START_TAG) {
VLog.e(LOG_TAG, "Unable to read user " + id);
return null;
}
if (parser.getName().equals(TAG_USER)) {
int storedId = readIntAttribute(parser, ATTR_ID, -1);
if (storedId != id) {
VLog.e(LOG_TAG, "User id does not match the file name");
return null;
}
serialNumber = readIntAttribute(parser, ATTR_SERIAL_NO, id);
flags = readIntAttribute(parser, ATTR_FLAGS, 0);
iconPath = parser.getAttributeValue(null, ATTR_ICON_PATH);
creationTime = readLongAttribute(parser, ATTR_CREATION_TIME, 0);
lastLoggedInTime = readLongAttribute(parser, ATTR_LAST_LOGGED_IN_TIME, 0);
String valueString = parser.getAttributeValue(null, ATTR_PARTIAL);
if ("true".equals(valueString)) {
partial = true;
}
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
}
if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_NAME)) {
type = parser.next();
if (type == XmlPullParser.TEXT) {
name = parser.getText();
}
}
}
VUserInfo userInfo = new VUserInfo(id, name, iconPath, flags);
userInfo.serialNumber = serialNumber;
userInfo.creationTime = creationTime;
userInfo.lastLoggedInTime = lastLoggedInTime;
userInfo.partial = partial;
return userInfo;
} catch (IOException ioe) {
} catch (XmlPullParserException pe) {
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
}
return null;
}
use of com.lody.virtual.os.VUserInfo in project VirtualApp by asLody.
the class VUserManagerService method createUser.
@Override
public VUserInfo createUser(String name, int flags) {
checkManageUsersPermission("Only the system can create users");
final long ident = Binder.clearCallingIdentity();
final VUserInfo userInfo;
try {
synchronized (mInstallLock) {
synchronized (mPackagesLock) {
if (isUserLimitReachedLocked())
return null;
int userId = getNextAvailableIdLocked();
userInfo = new VUserInfo(userId, name, null, flags);
File userPath = new File(mBaseUserPath, Integer.toString(userId));
userInfo.serialNumber = mNextSerialNumber++;
long now = System.currentTimeMillis();
userInfo.creationTime = (now > EPOCH_PLUS_30_YEARS) ? now : 0;
userInfo.partial = true;
VEnvironment.getUserSystemDirectory(userInfo.id).mkdirs();
mUsers.put(userId, userInfo);
writeUserListLocked();
writeUserLocked(userInfo);
mPm.createNewUser(userId, userPath);
userInfo.partial = false;
writeUserLocked(userInfo);
updateUserIdsLocked();
}
}
Intent addedIntent = new Intent(Constants.ACTION_USER_ADDED);
addedIntent.putExtra(Constants.EXTRA_USER_HANDLE, userInfo.id);
VActivityManagerService.get().sendBroadcastAsUser(addedIntent, VUserHandle.ALL, null);
} finally {
Binder.restoreCallingIdentity(ident);
}
return userInfo;
}
Aggregations