use of com.lody.virtual.os.VUserInfo in project VirtualApp by asLody.
the class HomePresenterImpl method addApp.
@Override
public void addApp(AppInfoLite info) {
class AddResult {
private PackageAppData appData;
private int userId;
}
AddResult addResult = new AddResult();
VUiKit.defer().when(() -> {
InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(info.packageName, 0);
if (installedAppInfo != null) {
int[] userIds = installedAppInfo.getInstalledUsers();
int nextUserId = userIds.length;
addResult.userId = nextUserId;
if (VUserManager.get().getUserInfo(nextUserId) == null) {
String nextUserName = "Space " + nextUserId + 1;
VUserInfo newUserInfo = VUserManager.get().createUser(nextUserName, VUserInfo.FLAG_ADMIN);
if (newUserInfo == null) {
throw new IllegalStateException();
}
}
boolean success = VirtualCore.get().installPackageAsUser(nextUserId, info.packageName);
if (!success) {
throw new IllegalStateException();
}
} else {
InstallResult res = mRepo.addVirtualApp(info);
if (!res.isSuccess) {
throw new IllegalStateException();
}
}
}).then((res) -> {
addResult.appData = PackageAppDataStorage.get().acquire(info.packageName);
}).done(res -> {
if (addResult.userId == 0) {
PackageAppData data = addResult.appData;
data.isLoading = true;
mView.addAppToLauncher(data);
handleOptApp(data);
} else {
MultiplePackageAppData data = new MultiplePackageAppData(addResult.appData, addResult.userId);
data.isLoading = true;
mView.addAppToLauncher(data);
handleMultipleApp(data);
}
});
}
use of com.lody.virtual.os.VUserInfo in project VirtualApp by asLody.
the class VUserManagerService method upgradeIfNecessary.
/**
* This fixes an incorrect initialization of user name for the owner.
* TODO: Remove in the next release.
*/
private void upgradeIfNecessary() {
int userVersion = mUserVersion;
if (userVersion < 1) {
// Assign a proper name for the owner, if not initialized correctly before
VUserInfo user = mUsers.get(VUserHandle.USER_OWNER);
if ("Primary".equals(user.name)) {
user.name = "Admin";
writeUserLocked(user);
}
userVersion = 1;
}
if (userVersion < USER_VERSION) {
VLog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to " + USER_VERSION);
} else {
mUserVersion = userVersion;
writeUserListLocked();
}
}
use of com.lody.virtual.os.VUserInfo in project VirtualApp by asLody.
the class VUserManagerService method userForeground.
/**
* Make a note of the last started time of a user.
* @param userId the user that was just foregrounded
*/
public void userForeground(int userId) {
synchronized (mPackagesLock) {
VUserInfo user = mUsers.get(userId);
long now = System.currentTimeMillis();
if (user == null || user.partial) {
VLog.w(LOG_TAG, "userForeground: unknown user #" + userId);
return;
}
if (now > EPOCH_PLUS_30_YEARS) {
user.lastLoggedInTime = now;
writeUserLocked(user);
}
}
}
use of com.lody.virtual.os.VUserInfo in project VirtualApp by asLody.
the class VUserManagerService method removeUser.
/**
* Removes a user and all data directories created for that user. This method should be called
* after the user's processes have been terminated.
* @param userHandle the user's id
*/
public boolean removeUser(int userHandle) {
checkManageUsersPermission("Only the system can remove users");
final VUserInfo user;
synchronized (mPackagesLock) {
user = mUsers.get(userHandle);
if (userHandle == 0 || user == null) {
return false;
}
mRemovingUserIds.add(userHandle);
// Set this to a partially created user, so that the user will be purged
// on next startup, in case the runtime stops now before stopping and
// removing the user completely.
user.partial = true;
writeUserLocked(user);
}
if (DBG)
VLog.i(LOG_TAG, "Stopping user " + userHandle);
int res = VActivityManagerService.get().stopUser(userHandle, new IStopUserCallback.Stub() {
@Override
public void userStopped(int userId) {
finishRemoveUser(userId);
}
@Override
public void userStopAborted(int userId) {
}
});
return res == ActivityManagerCompat.USER_OP_SUCCESS;
}
use of com.lody.virtual.os.VUserInfo in project VirtualApp by asLody.
the class VUserManagerService method writeUserListLocked.
/*
* Writes the user list file in this format:
*
* <users nextSerialNumber="3">
* <user id="0"></user>
* <user id="2"></user>
* </users>
*/
private void writeUserListLocked() {
FileOutputStream fos = null;
AtomicFile userListFile = new AtomicFile(mUserListFile);
try {
fos = userListFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, "utf-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_USERS);
serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber));
serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion));
for (int i = 0; i < mUsers.size(); i++) {
VUserInfo user = mUsers.valueAt(i);
serializer.startTag(null, TAG_USER);
serializer.attribute(null, ATTR_ID, Integer.toString(user.id));
serializer.endTag(null, TAG_USER);
}
serializer.endTag(null, TAG_USERS);
serializer.endDocument();
userListFile.finishWrite(fos);
} catch (Exception e) {
userListFile.failWrite(fos);
VLog.e(LOG_TAG, "Error writing user list");
}
}
Aggregations