Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9313af68 authored by Bookatz's avatar Bookatz Committed by Adam Bookatz
Browse files

loadUnbadgedItemIcon doesn't crash from getUserIcon

AppicationPackageManager.loadUnbadgedItemIcon would call
UserManager.getUserIcon if the icon was supposed to represent
switching to another the parent user (from a work profile).
However, that call requires extra permissions which may not be
available, which would cause a crash. The work profile doesn't
generally have permission to see the parent's icon, so rather
than showing the actual icon, a generic user icon is shown instead.

Bug: 134177607
Test: Manual confirmation: create a work profile and try to share a
picture (from Photos) to the personal profile.

Change-Id: Id79ca50b8e0a26593addbacf1a0ea709a2bc4da2
parent 2aa255a7
Loading
Loading
Loading
Loading
+5 −6
Original line number Original line Diff line number Diff line
@@ -2754,12 +2754,11 @@ public class ApplicationPackageManager extends PackageManager {
    public Drawable loadUnbadgedItemIcon(@NonNull PackageItemInfo itemInfo,
    public Drawable loadUnbadgedItemIcon(@NonNull PackageItemInfo itemInfo,
            @Nullable ApplicationInfo appInfo) {
            @Nullable ApplicationInfo appInfo) {
        if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
        if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
            Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
            // Indicates itemInfo is for a different user (e.g. a profile's parent), so use a 
            if (bitmap == null) {
            // generic user icon (users generally lack permission to view each other's actual icons)
            int targetUserId = itemInfo.showUserIcon;
            return UserIcons.getDefaultUserIcon(
            return UserIcons.getDefaultUserIcon(
                        mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
                    mContext.getResources(), targetUserId, /* light= */ false);
            }
            return new BitmapDrawable(bitmap);
        }
        }
        Drawable dr = null;
        Drawable dr = null;
        if (itemInfo.packageName != null) {
        if (itemInfo.packageName != null) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -159,7 +159,7 @@ public class PackageItemInfo {
    public Bundle metaData;
    public Bundle metaData;


    /**
    /**
     * If different of UserHandle.USER_NULL, The icon of this item will be the one of that user.
     * If different of UserHandle.USER_NULL, The icon of this item will represent that user.
     * @hide
     * @hide
     */
     */
    public int showUserIcon;
    public int showUserIcon;