From 71caf698b48392ad824842dee1d3a0b598caf95d Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Thu, 14 Apr 2016 16:50:14 -0700 Subject: [PATCH] Set user icon to default when updating profile without photo If the user photo was deleted in the Myself contact, the change was not reflected neither in Settings/Users nor in expanded status bar. This was because the ProfileUpdateReceiver did not handle the case where the updated image was null (deleted). Fixed by assigning default user icon in UserManager if no photo found in the profile update. AOSP change: https://android-review.googlesource.com/#/c/153137 Bug: 28031914 Change-Id: I2f452f78dcf777414f50b133b1a9cee334bbd9a8 --- src/com/android/settings/Utils.java | 21 ++++++++++++------- .../android/settings/users/UserSettings.java | 18 ++++------------ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 4dd203cea55..9693ed93943 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -336,24 +336,31 @@ public final class Utils extends com.android.settingslib.Utils { } /* Used by UserSettings as well. Call this on a non-ui thread. */ - public static boolean copyMeProfilePhoto(Context context, UserInfo user) { + public static void copyMeProfilePhoto(Context context, UserInfo user) { Uri contactUri = Profile.CONTENT_URI; + int userId = user != null ? user.id : UserHandle.myUserId(); + InputStream avatarDataStream = Contacts.openContactPhotoInputStream( context.getContentResolver(), contactUri, true); // If there's no profile photo, assign a default avatar if (avatarDataStream == null) { - return false; + assignDefaultPhoto(context, userId); + } else { + UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); + Bitmap icon = BitmapFactory.decodeStream(avatarDataStream); + um.setUserIcon(userId, icon); } - int userId = user != null ? user.id : UserHandle.myUserId(); - UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); - Bitmap icon = BitmapFactory.decodeStream(avatarDataStream); - um.setUserIcon(userId, icon); try { avatarDataStream.close(); } catch (IOException ioe) { } - return true; + } + + public static void assignDefaultPhoto(Context context, int userId) { + UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); + Bitmap bitmap = getDefaultUserIconAsBitmap(userId); + um.setUserIcon(userId, bitmap); } public static String getMeProfileName(Context context, boolean full) { diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java index eb74c4bb699..bf93cd30e8a 100644 --- a/src/com/android/settings/users/UserSettings.java +++ b/src/com/android/settings/users/UserSettings.java @@ -331,7 +331,8 @@ public class UserSettings extends SettingsPreferenceFragment protected String doInBackground(Void... values) { UserInfo user = mUserManager.getUserInfo(UserHandle.myUserId()); if (user.iconPath == null || user.iconPath.equals("")) { - assignProfilePhoto(user); + // Assign profile photo. + Utils.copyMeProfilePhoto(getActivity(), user); } return user.name; } @@ -404,14 +405,14 @@ public class UserSettings extends SettingsPreferenceFragment private UserInfo createRestrictedProfile() { UserInfo newUserInfo = mUserManager.createRestrictedProfile(mAddingUserName); - assignDefaultPhoto(newUserInfo); + Utils.assignDefaultPhoto(getActivity(), newUserInfo.id); return newUserInfo; } private UserInfo createTrustedUser() { UserInfo newUserInfo = mUserManager.createUser(mAddingUserName, 0); if (newUserInfo != null) { - assignDefaultPhoto(newUserInfo); + Utils.assignDefaultPhoto(getActivity(), newUserInfo.id); } return newUserInfo; } @@ -898,17 +899,6 @@ public class UserSettings extends SettingsPreferenceFragment }.execute(missingIcons); } - private void assignProfilePhoto(final UserInfo user) { - if (!Utils.copyMeProfilePhoto(getActivity(), user)) { - assignDefaultPhoto(user); - } - } - - private void assignDefaultPhoto(UserInfo user) { - Bitmap bitmap = Utils.getDefaultUserIconAsBitmap(user.id); - mUserManager.setUserIcon(user.id, bitmap); - } - private Drawable getEncircledDefaultIcon() { if (mDefaultIconDrawable == null) { mDefaultIconDrawable = encircle(Utils.getDefaultUserIconAsBitmap(UserHandle.USER_NULL));