2929import android .content .Intent ;
3030import android .content .pm .PackageManager ;
3131import android .content .pm .UserInfo ;
32+ import android .graphics .Bitmap ;
33+ import android .graphics .BitmapFactory ;
3234import android .os .Binder ;
3335import android .os .Environment ;
3436import android .os .FileUtils ;
@@ -188,30 +190,35 @@ public void setUserName(int userId, String name) {
188190 writeUserLocked (info );
189191 }
190192 }
193+ sendUserInfoChangedBroadcast (userId );
191194 }
192195
193196 @ Override
194- public ParcelFileDescriptor setUserIcon (int userId ) {
197+ public void setUserIcon (int userId , Bitmap bitmap ) {
195198 checkManageUsersPermission ("update users" );
196199 synchronized (mPackagesLock ) {
197200 UserInfo info = mUsers .get (userId );
198- if (info == null ) return null ;
199- ParcelFileDescriptor fd = openIconBitmapLocked (info , true /* write */ );
200- if (fd != null ) {
201- writeUserLocked (info );
202- }
203- return fd ;
201+ if (info == null ) return ;
202+ writeBitmapLocked (info , bitmap );
203+ writeUserLocked (info );
204204 }
205+ sendUserInfoChangedBroadcast (userId );
206+ }
207+
208+ private void sendUserInfoChangedBroadcast (int userId ) {
209+ Intent changedIntent = new Intent (Intent .ACTION_USER_INFO_CHANGED );
210+ changedIntent .putExtra (Intent .EXTRA_USER_HANDLE , userId );
211+ changedIntent .addFlags (Intent .FLAG_RECEIVER_REGISTERED_ONLY );
212+ mContext .sendBroadcastAsUser (changedIntent , new UserHandle (userId ));
205213 }
206214
207215 @ Override
208- public ParcelFileDescriptor getUserIcon (int userId ) {
216+ public Bitmap getUserIcon (int userId ) {
209217 checkManageUsersPermission ("read users" );
210218 synchronized (mPackagesLock ) {
211219 UserInfo info = mUsers .get (userId );
212220 if (info == null || info .iconPath == null ) return null ;
213- ParcelFileDescriptor fd = openIconBitmapLocked (info , false /* read */ );
214- return fd ;
221+ return BitmapFactory .decodeFile (info .iconPath );
215222 }
216223 }
217224
@@ -289,7 +296,7 @@ private static final void checkManageUsersPermission(String message) {
289296 }
290297 }
291298
292- private ParcelFileDescriptor openIconBitmapLocked (UserInfo info , boolean toWrite ) {
299+ private void writeBitmapLocked (UserInfo info , Bitmap bitmap ) {
293300 try {
294301 File dir = new File (mUsersDir , Integer .toString (info .id ));
295302 File file = new File (dir , USER_PHOTO_FILENAME );
@@ -300,16 +307,18 @@ private ParcelFileDescriptor openIconBitmapLocked(UserInfo info, boolean toWrite
300307 FileUtils .S_IRWXU |FileUtils .S_IRWXG |FileUtils .S_IXOTH ,
301308 -1 , -1 );
302309 }
303- ParcelFileDescriptor fd = ParcelFileDescriptor .open (file ,
304- toWrite ? MODE_CREATE |MODE_READ_WRITE : MODE_READ_WRITE );
305- if (toWrite ) {
310+ FileOutputStream os ;
311+ if (bitmap .compress (Bitmap .CompressFormat .PNG , 100 , os = new FileOutputStream (file ))) {
306312 info .iconPath = file .getAbsolutePath ();
307313 }
308- return fd ;
314+ try {
315+ os .close ();
316+ } catch (IOException ioe ) {
317+ // What the ... !
318+ }
309319 } catch (FileNotFoundException e ) {
310320 Slog .w (LOG_TAG , "Error setting photo for user " , e );
311321 }
312- return null ;
313322 }
314323
315324 /**
0 commit comments