diff options
author | Amith Yamasani <yamasani@google.com> | 2012-09-17 10:21:43 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2012-09-17 12:42:00 -0700 |
commit | 3b49f07a452e0a77c1d22db2065255689a461d31 (patch) | |
tree | 8de76555cc4a5693e5adc959657f4524f40e81a5 /services | |
parent | 5dbeb6a8ff8ae30f59ba8335c2354b883302428e (diff) | |
download | frameworks_base-3b49f07a452e0a77c1d22db2065255689a461d31.zip frameworks_base-3b49f07a452e0a77c1d22db2065255689a461d31.tar.gz frameworks_base-3b49f07a452e0a77c1d22db2065255689a461d31.tar.bz2 |
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
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/pm/UserManagerService.java | 21 |
1 files changed, 17 insertions, 4 deletions
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); |