Search in sources :

Example 11 with VUserInfo

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;
}
Also used : AtomicFile(com.lody.virtual.helper.utils.AtomicFile) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) AtomicFile(com.lody.virtual.helper.utils.AtomicFile) File(java.io.File) FileInputStream(java.io.FileInputStream) VUserInfo(com.lody.virtual.os.VUserInfo)

Example 12 with VUserInfo

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;
}
Also used : Intent(android.content.Intent) AtomicFile(com.lody.virtual.helper.utils.AtomicFile) File(java.io.File) 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