Merge "Add UserManager.getUserIcon()" into jb-mr1-dev

This commit is contained in:
Amith Yamasani
2012-09-17 12:46:01 -07:00
committed by Android (Google) Code Review
3 changed files with 34 additions and 4 deletions

View File

@@ -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);

View File

@@ -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.

View File

@@ -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);
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);