From 3b49f07a452e0a77c1d22db2065255689a461d31 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Mon, 17 Sep 2012 10:21:43 -0700 Subject: 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 --- .../com/android/server/pm/UserManagerService.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'services') diff --git a/services/java/com/android/server/pm/UserManagerService.java b/services/java/com/android/server/pm/UserManagerService.java index a58c4ea..914ff67 100644 --- a/services/java/com/android/server/pm/UserManagerService.java +++ b/services/java/com/android/server/pm/UserManagerService.java @@ -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); } @@ -205,6 +205,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"); synchronized (mPackagesLock) { @@ -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); - info.iconPath = file.getAbsolutePath(); + 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); -- cgit v1.1