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

Commit 07764011 authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Resolve message/conversation image Uris with the correct user id" into main

parents 5a39781c a67952e2
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -416,3 +416,14 @@ flag {
   bug: "282007590"
}

flag {
    name: "notification_row_user_context"
    namespace: "systemui"
    description: "Create a user-specific Context for the ImageResolver in ExpandableNotificationRow"
        " (based on the NotificationEntry's user)."
    bug: "317503801"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+36 −5
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.IndentingPrintWriter;
@@ -382,7 +383,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    private boolean mUseIncreasedHeadsUpHeight;
    private float mTranslationWhenRemoved;
    private boolean mWasChildInGroupWhenRemoved;
    private NotificationInlineImageResolver mImageResolver;
    private final NotificationInlineImageResolver mImageResolver;
    private BigPictureIconManager mBigPictureIconManager;
    @Nullable
    private OnExpansionChangedListener mExpansionChangedListener;
@@ -1700,13 +1701,43 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    /**
     * Constructs an ExpandableNotificationRow.
     * @param context context passed to image resolver
     * Constructs an ExpandableNotificationRow. Used by layout inflation.
     *
     * @param context passed to image resolver
     * @param attrs attributes used to initialize parent view
     */
    public ExpandableNotificationRow(Context context, AttributeSet attrs) {
        super(context, attrs);
        mImageResolver = new NotificationInlineImageResolver(context,
        this(context, attrs, context);
        if (com.android.systemui.Flags.notificationRowUserContext()) {
            Log.wtf(TAG, "This constructor shouldn't be called");
        }
    }

    /**
     * Constructs an ExpandableNotificationRow. Used by layout inflation (with a custom {@code
     * AsyncLayoutFactory} in {@link RowInflaterTask}.
     *
     * @param context context context of the view
     * @param attrs attributes used to initialize parent view
     * @param entry notification that the row will be associated to (determines the user for the
     *              ImageResolver)
     */
    public ExpandableNotificationRow(Context context, AttributeSet attrs, NotificationEntry entry) {
        this(context, attrs, userContextForEntry(context, entry));
    }

    private static Context userContextForEntry(Context base, NotificationEntry entry) {
        if (base.getUserId() == entry.getSbn().getNormalizedUserId()) {
            return base;
        }
        return base.createContextAsUser(
                UserHandle.of(entry.getSbn().getNormalizedUserId()), /* flags= */ 0);
    }

    private ExpandableNotificationRow(Context sysUiContext, AttributeSet attrs,
            Context userContext) {
        super(sysUiContext, attrs);
        mImageResolver = new NotificationInlineImageResolver(userContext,
                new NotificationInlineImageCache());
        float radius = getResources().getDimension(R.dimen.notification_corner_radius_small);
        mSmallRoundness = radius / getMaxRadius();
+11 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.widget.ImageResolver;
import com.android.internal.widget.LocalImageResolver;
import com.android.internal.widget.MessagingMessage;
import com.android.systemui.Flags;

import java.util.HashSet;
import java.util.List;
@@ -66,7 +67,11 @@ public class NotificationInlineImageResolver implements ImageResolver {
     * @param imageCache The implementation of internal cache.
     */
    public NotificationInlineImageResolver(Context context, ImageCache imageCache) {
        if (Flags.notificationRowUserContext()) {
            mContext = context;
        } else {
            mContext = context.getApplicationContext();
        }
        mImageCache = imageCache;

        if (mImageCache != null) {
@@ -76,6 +81,11 @@ public class NotificationInlineImageResolver implements ImageResolver {
        updateMaxImageSizes();
    }

    @VisibleForTesting
    public Context getContext() {
        return mContext;
    }

    /**
     * Check if this resolver has its internal cache implementation.
     * @return True if has its internal cache, false otherwise.
+34 −1
Original line number Diff line number Diff line
@@ -17,10 +17,15 @@
package com.android.systemui.statusbar.notification.row;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.asynclayoutinflater.view.AsyncLayoutFactory;
import androidx.asynclayoutinflater.view.AsyncLayoutInflater;

import com.android.systemui.res.R;
@@ -55,12 +60,40 @@ public class RowInflaterTask implements InflationTask, AsyncLayoutInflater.OnInf
            mInflateOrigin = new Throwable("inflate requested here");
        }
        mListener = listener;
        AsyncLayoutInflater inflater = new AsyncLayoutInflater(context);
        AsyncLayoutInflater inflater = com.android.systemui.Flags.notificationRowUserContext()
                ? new AsyncLayoutInflater(context, new RowAsyncLayoutInflater(entry))
                : new AsyncLayoutInflater(context);
        mEntry = entry;
        entry.setInflationTask(this);
        inflater.inflate(R.layout.status_bar_notification_row, parent, this);
    }

    @VisibleForTesting
    static class RowAsyncLayoutInflater implements AsyncLayoutFactory {
        private final NotificationEntry mEntry;

        RowAsyncLayoutInflater(NotificationEntry entry) {
            mEntry = entry;
        }

        @Nullable
        @Override
        public View onCreateView(@Nullable View parent, @NonNull String name,
                @NonNull Context context, @NonNull AttributeSet attrs) {
            if (name.equals(ExpandableNotificationRow.class.getName())) {
                return new ExpandableNotificationRow(context, attrs, mEntry);
            }
            return null;
        }

        @Nullable
        @Override
        public View onCreateView(@NonNull String name, @NonNull Context context,
                @NonNull AttributeSet attrs) {
            return null;
        }
    }

    @Override
    public void abort() {
        mCancelled = true;
+27 −4
Original line number Diff line number Diff line
@@ -16,10 +16,9 @@

package com.android.systemui.statusbar.notification.row;

import static android.app.NotificationManager.IMPORTANCE_DEFAULT;

import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;
import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_ALL;
import static com.android.systemui.statusbar.notification.row.NotificationTestHelper.PKG;
import static com.android.systemui.statusbar.notification.row.NotificationTestHelper.USER_HANDLE;

import static com.google.common.truth.Truth.assertThat;

@@ -40,11 +39,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.app.Notification;
import android.app.NotificationChannel;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.platform.test.annotations.EnableFlags;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
@@ -57,6 +58,7 @@ import androidx.test.filters.SmallTest;
import com.android.internal.R;
import com.android.internal.widget.CachingIconView;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.SysuiTestableContext;
import com.android.systemui.flags.FakeFeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
@@ -806,6 +808,27 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
        assertThat(row.isDrawingAppearAnimation()).isFalse();
    }

    @Test
    public void imageResolver_sameNotificationUser_usesContext() throws Exception {
        ExpandableNotificationRow row = mNotificationTestHelper.createRow(PKG,
                USER_HANDLE.getUid(1234), USER_HANDLE);

        assertThat(row.getImageResolver().getContext()).isSameInstanceAs(mContext);
    }

    @Test
    @EnableFlags(com.android.systemui.Flags.FLAG_NOTIFICATION_ROW_USER_CONTEXT)
    public void imageResolver_differentNotificationUser_createsUserContext() throws Exception {
        UserHandle user = new UserHandle(33);
        Context userContext = new SysuiTestableContext(mContext);
        mContext.prepareCreateContextAsUser(user, userContext);

        ExpandableNotificationRow row = mNotificationTestHelper.createRow(PKG,
                user.getUid(1234), user);

        assertThat(row.getImageResolver().getContext()).isSameInstanceAs(userContext);
    }

    private void setDrawableIconsInImageView(CachingIconView icon, Drawable iconDrawable,
            Drawable rightIconDrawable) {
        ImageView iconView = mock(ImageView.class);
Loading