Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b49f07a authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Add UserManager.getUserIcon()

So that we don't abuse the setUserIcon() for reading. So the new method won't try
to create the file, only return it if it exists.

Change-Id: I7a81d3f1b29d14d37e71f531744ce39f21d827ac
parent 5dbeb6a8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ interface IUserManager {
    boolean removeUser(int userHandle);
    void setUserName(int userHandle, String name);
    ParcelFileDescriptor setUserIcon(int userHandle);
    ParcelFileDescriptor getUserIcon(int userHandle);
    List<UserInfo> getUsers();
    UserInfo getUserInfo(int userHandle);
    void setGuestEnabled(boolean enable);
+16 −0
Original line number Diff line number Diff line
@@ -165,6 +165,22 @@ public class UserManager {
        }
    }

    /**
     * Returns a file descriptor for the user's photo. PNG data can be read from this file.
     * @param userHandle the user whose photo we want to read.
     * @return a {@link ParcelFileDescriptor} from which to read the file, or null if there's no
     * photo.
     * @hide
     */
    public ParcelFileDescriptor getUserIcon(int userHandle) {
        try {
            return mService.getUserIcon(userHandle);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not set the user icon ", re);
            return null;
        }
    }

    /**
     * Enable or disable the use of a guest account. If disabled, the existing guest account
     * will be wiped.
+17 −4
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ public class UserManagerService extends IUserManager.Stub {
        synchronized (mPackagesLock) {
            UserInfo info = mUsers.get(userId);
            if (info == null) return null;
            ParcelFileDescriptor fd = updateIconBitmapLocked(info);
            ParcelFileDescriptor fd = openIconBitmapLocked(info, true /* write */);
            if (fd != null) {
                writeUserLocked(info);
            }
@@ -204,6 +204,17 @@ public class UserManagerService extends IUserManager.Stub {
        }
    }

    @Override
    public ParcelFileDescriptor getUserIcon(int userId) {
        checkManageUsersPermission("read users");
        synchronized (mPackagesLock) {
            UserInfo info = mUsers.get(userId);
            if (info == null || info.iconPath == null) return null;
            ParcelFileDescriptor fd = openIconBitmapLocked(info, false /* read */);
            return fd;
        }
    }

    @Override
    public void setGuestEnabled(boolean enable) {
        checkManageUsersPermission("enable guest users");
@@ -278,7 +289,7 @@ public class UserManagerService extends IUserManager.Stub {
        }
    }

    private ParcelFileDescriptor updateIconBitmapLocked(UserInfo info) {
    private ParcelFileDescriptor openIconBitmapLocked(UserInfo info, boolean toWrite) {
        try {
            File dir = new File(mUsersDir, Integer.toString(info.id));
            File file = new File(dir, USER_PHOTO_FILENAME);
@@ -290,8 +301,10 @@ public class UserManagerService extends IUserManager.Stub {
                        -1, -1);
            }
            ParcelFileDescriptor fd = ParcelFileDescriptor.open(file,
                    MODE_CREATE|MODE_READ_WRITE);
                    toWrite ? MODE_CREATE|MODE_READ_WRITE : MODE_READ_WRITE);
            if (toWrite) {
                info.iconPath = file.getAbsolutePath();
            }
            return fd;
        } catch (FileNotFoundException e) {
            Slog.w(LOG_TAG, "Error setting photo for user ", e);