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

Commit 7ac80e63 authored by Christoph Studer's avatar Christoph Studer
Browse files

NoMan: Optimize profile badge retrieval

Instead of stuffing the profile badge into extras, store the
originating user and read the badge via UserManager.

Bug: 16735645
Change-Id: Ia5f9b6f113dcbc88581af5308585edcf9b92b88d
parent 943aa677
Loading
Loading
Loading
Loading
+16 −15
Original line number Original line Diff line number Diff line
@@ -813,14 +813,12 @@ public class Notification implements Parcelable
     */
     */
    public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions";
    public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions";



    /**
    /**
     * {@link #extras} key: Bitmap representing the profile badge to be shown with the
     * {@link #extras} key: the user that built the notification.
     * notification.
     *
     *
     * @hide
     * @hide
     */
     */
    public static final String EXTRA_PROFILE_BADGE = "android.profileBadge";
    public static final String EXTRA_ORIGINATING_USERID = "android.originatingUserId";


    /**
    /**
     * Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification should not be
     * Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification should not be
@@ -1870,7 +1868,11 @@ public class Notification implements Parcelable
        private final NotificationColorUtil mColorUtil;
        private final NotificationColorUtil mColorUtil;
        private ArrayList<String> mPeople;
        private ArrayList<String> mPeople;
        private int mColor = COLOR_DEFAULT;
        private int mColor = COLOR_DEFAULT;
        private Bitmap mProfileBadge;

        /**
         * The user that built the notification originally.
         */
        private int mOriginatingUserId;


        /**
        /**
         * Contains extras related to rebuilding during the build phase.
         * Contains extras related to rebuilding during the build phase.
@@ -2579,8 +2581,10 @@ public class Notification implements Parcelable
        }
        }


        private Bitmap getProfileBadge() {
        private Bitmap getProfileBadge() {
            // Note: This assumes that the current user can read the profile badge of the
            // originating user.
            UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            Drawable badge = userManager.getBadgeForUser(android.os.Process.myUserHandle());
            Drawable badge = userManager.getBadgeForUser(new UserHandle(mOriginatingUserId));
            if (badge == null) {
            if (badge == null) {
                return null;
                return null;
            }
            }
@@ -2594,6 +2598,7 @@ public class Notification implements Parcelable
        }
        }


        private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
        private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
            Bitmap profileIcon = getProfileBadge();
            RemoteViews contentView = new BuilderRemoteViews(mContext.getPackageName(), resId);
            RemoteViews contentView = new BuilderRemoteViews(mContext.getPackageName(), resId);
            boolean showLine3 = false;
            boolean showLine3 = false;
            boolean showLine2 = false;
            boolean showLine2 = false;
@@ -2601,8 +2606,8 @@ public class Notification implements Parcelable
            if (mPriority < PRIORITY_LOW) {
            if (mPriority < PRIORITY_LOW) {
                // TODO: Low priority presentation
                // TODO: Low priority presentation
            }
            }
            if (mProfileBadge != null) {
            if (profileIcon != null) {
                contentView.setImageViewBitmap(R.id.profile_icon, mProfileBadge);
                contentView.setImageViewBitmap(R.id.profile_icon, profileIcon);
                contentView.setViewVisibility(R.id.profile_icon, View.VISIBLE);
                contentView.setViewVisibility(R.id.profile_icon, View.VISIBLE);
            } else {
            } else {
                contentView.setViewVisibility(R.id.profile_icon, View.GONE);
                contentView.setViewVisibility(R.id.profile_icon, View.GONE);
@@ -2927,6 +2932,7 @@ public class Notification implements Parcelable
         */
         */
        public void populateExtras(Bundle extras) {
        public void populateExtras(Bundle extras) {
            // Store original information used in the construction of this object
            // Store original information used in the construction of this object
            extras.putInt(EXTRA_ORIGINATING_USERID, mOriginatingUserId);
            extras.putString(EXTRA_REBUILD_CONTEXT_PACKAGE, mContext.getPackageName());
            extras.putString(EXTRA_REBUILD_CONTEXT_PACKAGE, mContext.getPackageName());
            extras.putCharSequence(EXTRA_TITLE, mContentTitle);
            extras.putCharSequence(EXTRA_TITLE, mContentTitle);
            extras.putCharSequence(EXTRA_TEXT, mContentText);
            extras.putCharSequence(EXTRA_TEXT, mContentText);
@@ -2944,9 +2950,6 @@ public class Notification implements Parcelable
            if (!mPeople.isEmpty()) {
            if (!mPeople.isEmpty()) {
                extras.putStringArray(EXTRA_PEOPLE, mPeople.toArray(new String[mPeople.size()]));
                extras.putStringArray(EXTRA_PEOPLE, mPeople.toArray(new String[mPeople.size()]));
            }
            }
            if (mProfileBadge != null) {
                extras.putParcelable(EXTRA_PROFILE_BADGE, mProfileBadge);
            }
            // NOTE: If you're adding new extras also update restoreFromNotification().
            // NOTE: If you're adding new extras also update restoreFromNotification().
        }
        }


@@ -3157,6 +3160,7 @@ public class Notification implements Parcelable


            // Extras.
            // Extras.
            Bundle extras = n.extras;
            Bundle extras = n.extras;
            mOriginatingUserId = extras.getInt(EXTRA_ORIGINATING_USERID);
            mContentTitle = extras.getCharSequence(EXTRA_TITLE);
            mContentTitle = extras.getCharSequence(EXTRA_TITLE);
            mContentText = extras.getCharSequence(EXTRA_TEXT);
            mContentText = extras.getCharSequence(EXTRA_TEXT);
            mSubText = extras.getCharSequence(EXTRA_SUB_TEXT);
            mSubText = extras.getCharSequence(EXTRA_SUB_TEXT);
@@ -3174,9 +3178,6 @@ public class Notification implements Parcelable
                mPeople.clear();
                mPeople.clear();
                Collections.addAll(mPeople, extras.getStringArray(EXTRA_PEOPLE));
                Collections.addAll(mPeople, extras.getStringArray(EXTRA_PEOPLE));
            }
            }
            if (extras.containsKey(EXTRA_PROFILE_BADGE)) {
                mProfileBadge = extras.getParcelable(EXTRA_PROFILE_BADGE);
            }
        }
        }


        /**
        /**
@@ -3192,7 +3193,7 @@ public class Notification implements Parcelable
         * object.
         * object.
         */
         */
        public Notification build() {
        public Notification build() {
            mProfileBadge = getProfileBadge();
            mOriginatingUserId = mContext.getUserId();


            Notification n = buildUnstyled();
            Notification n = buildUnstyled();