Search in sources :

Example 11 with UserInfo

use of android.content.pm.UserInfo in project android_frameworks_base by ParanoidAndroid.

the class UserManagerService method createUser.

@Override
public UserInfo createUser(String name, int flags) {
    checkManageUsersPermission("Only the system can create users");
    final long ident = Binder.clearCallingIdentity();
    final UserInfo userInfo;
    try {
        synchronized (mInstallLock) {
            synchronized (mPackagesLock) {
                if (isUserLimitReachedLocked())
                    return null;
                int userId = getNextAvailableIdLocked();
                userInfo = new UserInfo(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;
                Environment.getUserSystemDirectory(userInfo.id).mkdirs();
                mUsers.put(userId, userInfo);
                writeUserListLocked();
                writeUserLocked(userInfo);
                mPm.createNewUserLILPw(userId, userPath);
                userInfo.partial = false;
                writeUserLocked(userInfo);
                updateUserIdsLocked();
                Bundle restrictions = new Bundle();
                mUserRestrictions.append(userId, restrictions);
            }
        }
        if (userInfo != null) {
            Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED);
            addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id);
            mContext.sendBroadcastAsUser(addedIntent, UserHandle.ALL, android.Manifest.permission.MANAGE_USERS);
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    return userInfo;
}
Also used : Bundle(android.os.Bundle) UserInfo(android.content.pm.UserInfo) Intent(android.content.Intent) AtomicFile(android.util.AtomicFile) File(java.io.File)

Example 12 with UserInfo

use of android.content.pm.UserInfo in project android_frameworks_base by ParanoidAndroid.

the class UserManagerService method fallbackToSingleUserLocked.

private void fallbackToSingleUserLocked() {
    // Create the primary user
    UserInfo primary = new UserInfo(UserHandle.USER_OWNER, mContext.getResources().getString(com.android.internal.R.string.owner_name), null, UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY | UserInfo.FLAG_INITIALIZED);
    mUsers.put(0, primary);
    mNextSerialNumber = MIN_USER_ID;
    Bundle restrictions = new Bundle();
    mUserRestrictions.append(UserHandle.USER_OWNER, restrictions);
    updateUserIdsLocked();
    writeUserListLocked();
    writeUserLocked(primary);
}
Also used : Bundle(android.os.Bundle) UserInfo(android.content.pm.UserInfo)

Example 13 with UserInfo

use of android.content.pm.UserInfo in project android_frameworks_base by ParanoidAndroid.

the class UserManagerService 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++) {
            UserInfo 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);
        Slog.e(LOG_TAG, "Error writing user list");
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) UserInfo(android.content.pm.UserInfo) BufferedOutputStream(java.io.BufferedOutputStream) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 14 with UserInfo

use of android.content.pm.UserInfo in project android_frameworks_base by ParanoidAndroid.

the class UserManagerService method readUserListLocked.

private void readUserListLocked() {
    mGuestEnabled = false;
    if (!mUserListFile.exists()) {
        fallbackToSingleUserLocked();
        return;
    }
    FileInputStream fis = null;
    AtomicFile userListFile = new AtomicFile(mUserListFile);
    try {
        fis = userListFile.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) {
            Slog.e(LOG_TAG, "Unable to read user list");
            fallbackToSingleUserLocked();
            return;
        }
        mNextSerialNumber = -1;
        if (parser.getName().equals(TAG_USERS)) {
            String lastSerialNumber = parser.getAttributeValue(null, ATTR_NEXT_SERIAL_NO);
            if (lastSerialNumber != null) {
                mNextSerialNumber = Integer.parseInt(lastSerialNumber);
            }
            String versionNumber = parser.getAttributeValue(null, ATTR_USER_VERSION);
            if (versionNumber != null) {
                mUserVersion = Integer.parseInt(versionNumber);
            }
        }
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
            if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) {
                String id = parser.getAttributeValue(null, ATTR_ID);
                UserInfo user = readUserLocked(Integer.parseInt(id));
                if (user != null) {
                    mUsers.put(user.id, user);
                    if (user.isGuest()) {
                        mGuestEnabled = true;
                    }
                    if (mNextSerialNumber < 0 || mNextSerialNumber <= user.id) {
                        mNextSerialNumber = user.id + 1;
                    }
                }
            }
        }
        updateUserIdsLocked();
        upgradeIfNecessary();
    } catch (IOException ioe) {
        fallbackToSingleUserLocked();
    } catch (XmlPullParserException pe) {
        fallbackToSingleUserLocked();
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : AtomicFile(android.util.AtomicFile) XmlPullParser(org.xmlpull.v1.XmlPullParser) UserInfo(android.content.pm.UserInfo) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 15 with UserInfo

use of android.content.pm.UserInfo in project android_frameworks_base by ParanoidAndroid.

the class UserManagerService method setUserName.

@Override
public void setUserName(int userId, String name) {
    checkManageUsersPermission("rename users");
    boolean changed = false;
    synchronized (mPackagesLock) {
        UserInfo info = mUsers.get(userId);
        if (info == null || info.partial) {
            Slog.w(LOG_TAG, "setUserName: unknown user #" + userId);
            return;
        }
        if (name != null && !name.equals(info.name)) {
            info.name = name;
            writeUserLocked(info);
            changed = true;
        }
    }
    if (changed) {
        sendUserInfoChangedBroadcast(userId);
    }
}
Also used : UserInfo(android.content.pm.UserInfo)

Aggregations

UserInfo (android.content.pm.UserInfo)814 UserManager (android.os.UserManager)156 RemoteException (android.os.RemoteException)144 ArrayList (java.util.ArrayList)73 UserHandle (android.os.UserHandle)66 Intent (android.content.Intent)58 IOException (java.io.IOException)52 File (java.io.File)47 Bundle (android.os.Bundle)43 ApplicationInfo (android.content.pm.ApplicationInfo)40 PackageManager (android.content.pm.PackageManager)39 ComponentName (android.content.ComponentName)32 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)31 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)30 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)29 AtomicFile (android.util.AtomicFile)28 PackageInfo (android.content.pm.PackageInfo)26 DevicePolicyManager (android.app.admin.DevicePolicyManager)25 LockPatternUtils (com.android.internal.widget.LockPatternUtils)24 PendingIntent (android.app.PendingIntent)23