Search in sources :

Example 1 with UserInfo

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

the class Pm method runCreateUser.

public void runCreateUser() {
    String name;
    String arg = nextArg();
    if (arg == null) {
        System.err.println("Error: no user name specified.");
        return;
    }
    name = arg;
    try {
        final UserInfo info = mUm.createUser(name, 0);
        if (info != null) {
            System.out.println("Success: created user id " + info.id);
        } else {
            System.err.println("Error: couldn't create User.");
        }
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
}
Also used : UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException)

Example 2 with UserInfo

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

the class ActivityManagerProxy method getCurrentUser.

public UserInfo getCurrentUser() throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    data.writeInterfaceToken(IActivityManager.descriptor);
    mRemote.transact(GET_CURRENT_USER_TRANSACTION, data, reply, 0);
    reply.readException();
    UserInfo userInfo = UserInfo.CREATOR.createFromParcel(reply);
    reply.recycle();
    data.recycle();
    return userInfo;
}
Also used : Parcel(android.os.Parcel) UserInfo(android.content.pm.UserInfo)

Example 3 with UserInfo

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

the class UserTile method queryForUserInformation.

private void queryForUserInformation() {
    Context currentUserContext = null;
    UserInfo userInfo = null;
    try {
        userInfo = ActivityManagerNative.getDefault().getCurrentUser();
        currentUserContext = mContext.createPackageContextAsUser("android", 0, new UserHandle(userInfo.id));
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Couldn't create user context", e);
        throw new RuntimeException(e);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't get user info", e);
    }
    final int userId = userInfo.id;
    final String userName = userInfo.name;
    final Context context = currentUserContext;
    mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {

        @Override
        protected Pair<String, Drawable> doInBackground(Void... params) {
            try {
                // The system needs some time to change the picture, if we try to load it when we receive the broadcast, we will load the old one
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            // Fall back to the UserManager nickname if we can't read the name from the local
            // profile below.
            String name = userName;
            Drawable avatar = null;
            Bitmap rawAvatar = um.getUserIcon(userId);
            if (rawAvatar != null) {
                avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
            } else {
                avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
            }
            // usually valid
            if (um.getUsers().size() <= 1) {
                // Try and read the display name from the local profile
                final Cursor cursor = context.getContentResolver().query(Profile.CONTENT_URI, new String[] { Phone._ID, Phone.DISPLAY_NAME }, null, null, null);
                if (cursor != null) {
                    try {
                        if (cursor.moveToFirst()) {
                            name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
                        }
                    } finally {
                        cursor.close();
                    }
                }
            }
            return new Pair<String, Drawable>(name, avatar);
        }

        @Override
        protected void onPostExecute(Pair<String, Drawable> result) {
            super.onPostExecute(result);
            setUserTileInfo(result.first, result.second);
            mUserInfoTask = null;
        }
    };
    mUserInfoTask.execute();
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) UserInfo(android.content.pm.UserInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cursor(android.database.Cursor) Bitmap(android.graphics.Bitmap) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException) Pair(android.util.Pair)

Example 4 with UserInfo

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

the class QuickSettings method queryForUserInformation.

private void queryForUserInformation() {
    Context currentUserContext = null;
    UserInfo userInfo = null;
    try {
        userInfo = ActivityManagerNative.getDefault().getCurrentUser();
        currentUserContext = mContext.createPackageContextAsUser("android", 0, new UserHandle(userInfo.id));
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Couldn't create user context", e);
        throw new RuntimeException(e);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't get user info", e);
    }
    final int userId = userInfo.id;
    final String userName = userInfo.name;
    final Context context = currentUserContext;
    mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {

        @Override
        protected Pair<String, Drawable> doInBackground(Void... params) {
            final UserManager um = UserManager.get(mContext);
            // Fall back to the UserManager nickname if we can't read the name from the local
            // profile below.
            String name = userName;
            Drawable avatar = null;
            Bitmap rawAvatar = um.getUserIcon(userId);
            if (rawAvatar != null) {
                avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
            } else {
                avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
                mUseDefaultAvatar = true;
            }
            // usually valid
            if (um.getUsers().size() <= 1) {
                // Try and read the display name from the local profile
                final Cursor cursor = context.getContentResolver().query(Profile.CONTENT_URI, new String[] { Phone._ID, Phone.DISPLAY_NAME }, null, null, null);
                if (cursor != null) {
                    try {
                        if (cursor.moveToFirst()) {
                            name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
                        }
                    } finally {
                        cursor.close();
                    }
                }
            }
            return new Pair<String, Drawable>(name, avatar);
        }

        @Override
        protected void onPostExecute(Pair<String, Drawable> result) {
            super.onPostExecute(result);
            mModel.setUserTileInfo(result.first, result.second);
            mUserInfoTask = null;
        }
    };
    mUserInfoTask.execute();
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) LevelListDrawable(android.graphics.drawable.LevelListDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) UserInfo(android.content.pm.UserInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cursor(android.database.Cursor) Bitmap(android.graphics.Bitmap) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException) Pair(android.util.Pair)

Example 5 with UserInfo

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

the class WallpaperManagerService method hasNamedWallpaper.

public boolean hasNamedWallpaper(String name) {
    synchronized (mLock) {
        List<UserInfo> users;
        long ident = Binder.clearCallingIdentity();
        try {
            users = ((UserManager) mContext.getSystemService(Context.USER_SERVICE)).getUsers();
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
        for (UserInfo user : users) {
            WallpaperData wd = mWallpaperMap.get(user.id);
            if (wd == null) {
                // User hasn't started yet, so load her settings to peek at the wallpaper
                loadSettingsLocked(user.id);
                wd = mWallpaperMap.get(user.id);
            }
            if (wd != null && name.equals(wd.name)) {
                return true;
            }
        }
    }
    return false;
}
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