Search in sources :

Example 1 with VUserInfo

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);
        }
    });
}
Also used : VUserInfo(com.lody.virtual.os.VUserInfo) PackageAppDataStorage(io.virtualapp.home.repo.PackageAppDataStorage) InstallResult(com.lody.virtual.remote.InstallResult) VirtualCore(com.lody.virtual.client.core.VirtualCore) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) VUserManager(com.lody.virtual.os.VUserManager) PackageAppData(io.virtualapp.home.models.PackageAppData) AppData(io.virtualapp.home.models.AppData) IOException(java.io.IOException) AppRepository(io.virtualapp.home.repo.AppRepository) VCommends(io.virtualapp.VCommends) AppInfoLite(io.virtualapp.home.models.AppInfoLite) Bitmap(android.graphics.Bitmap) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) VUiKit(io.virtualapp.abs.ui.VUiKit) Once(jonathanfinerty.once.Once) Activity(android.app.Activity) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData) InstallResult(com.lody.virtual.remote.InstallResult) VUserInfo(com.lody.virtual.os.VUserInfo)

Example 2 with VUserInfo

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();
    }
}
Also used : VUserInfo(com.lody.virtual.os.VUserInfo)

Example 3 with VUserInfo

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);
        }
    }
}
Also used : VUserInfo(com.lody.virtual.os.VUserInfo)

Example 4 with VUserInfo

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;
}
Also used : IStopUserCallback(android.app.IStopUserCallback) VUserInfo(com.lody.virtual.os.VUserInfo)

Example 5 with VUserInfo

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");
    }
}
Also used : FastXmlSerializer(com.lody.virtual.helper.utils.FastXmlSerializer) AtomicFile(com.lody.virtual.helper.utils.AtomicFile) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) FastXmlSerializer(com.lody.virtual.helper.utils.FastXmlSerializer) XmlSerializer(org.xmlpull.v1.XmlSerializer) VUserInfo(com.lody.virtual.os.VUserInfo)

Aggregations

VUserInfo (com.lody.virtual.os.VUserInfo)12 AtomicFile (com.lody.virtual.helper.utils.AtomicFile)4 IOException (java.io.IOException)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 Activity (android.app.Activity)1 IStopUserCallback (android.app.IStopUserCallback)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 VirtualCore (com.lody.virtual.client.core.VirtualCore)1 FastXmlSerializer (com.lody.virtual.helper.utils.FastXmlSerializer)1 VUserManager (com.lody.virtual.os.VUserManager)1 InstallResult (com.lody.virtual.remote.InstallResult)1 InstalledAppInfo (com.lody.virtual.remote.InstalledAppInfo)1 VCommends (io.virtualapp.VCommends)1 VUiKit (io.virtualapp.abs.ui.VUiKit)1 AppData (io.virtualapp.home.models.AppData)1 AppInfoLite (io.virtualapp.home.models.AppInfoLite)1