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

Commit 110b1709 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix BubbleExtractor not looking up activity info in a user-based way

Use package manager to look up activity info with the userId for
the notification, instead of using package manager based on current
context which doesn't work for HSUM.

Flag: EXEMPT bug fix
Test: atest BubbleExtractorTest NotificationManagerServiceTest
Test: manual - make a secondary user and send an intent-based bubble
             - ensure the bubble button is on the notification
Bug: 362181768
Change-Id: I5359bc395f06cbb5d0706f81fa2be1a56efc63d5
parent 666c6eb4
Loading
Loading
Loading
Loading
+22 −16
Original line number Diff line number Diff line
@@ -27,10 +27,11 @@ import static com.android.internal.util.FrameworkStatsLog.BUBBLE_DEVELOPER_ERROR
import android.app.ActivityManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.util.Slog;

@@ -47,6 +48,7 @@ public class BubbleExtractor implements NotificationSignalExtractor {
    private ShortcutHelper mShortcutHelper;
    private RankingConfig mConfig;
    private ActivityManager mActivityManager;
    private PackageManager mPackageManager;
    private Context mContext;

    boolean mSupportsBubble;
@@ -76,6 +78,11 @@ public class BubbleExtractor implements NotificationSignalExtractor {
            return null;
        }

        if (mPackageManager == null) {
            if (DBG) Slog.d(TAG, "missing package manager");
            return null;
        }

        boolean notifCanPresentAsBubble = canPresentAsBubble(record)
                && !mActivityManager.isLowRamDevice()
                && record.isConversation()
@@ -133,6 +140,10 @@ public class BubbleExtractor implements NotificationSignalExtractor {
        mShortcutHelper = helper;
    }

    public void setPackageManager(PackageManager packageManager) {
        mPackageManager = packageManager;
    }

    @VisibleForTesting
    public void setActivityManager(ActivityManager manager) {
        mActivityManager = manager;
@@ -176,30 +187,25 @@ public class BubbleExtractor implements NotificationSignalExtractor {
            // TODO: check the shortcut intent / ensure it can show in activity view
            return true;
        }
        return canLaunchInTaskView(mContext, metadata.getIntent(), pkg);
        return canLaunchInTaskView(metadata.getIntent().getIntent(), pkg,
                r.getUser().getIdentifier());
    }

    /**
     * Whether an intent is properly configured to display in an {@link
     * TaskView} for bubbling.
     * Whether an intent is properly configured to display in a TaskView for bubbling.
     *
     * @param context       the context to use.
     * @param pendingIntent the pending intent of the bubble.
     * @param intent the intent of the bubble.
     * @param packageName the notification package name for this bubble.
     */
    // Keep checks in sync with BubbleController#canLaunchInTaskView.
    @VisibleForTesting
    protected boolean canLaunchInTaskView(Context context, PendingIntent pendingIntent,
            String packageName) {
        if (pendingIntent == null) {
    // Keep checks in sync with BubbleController#isResizableActivity.
    private boolean canLaunchInTaskView(Intent intent, String packageName, int userId) {
        if (intent == null) {
            Slog.w(TAG, "Unable to create bubble -- no intent");
            return false;
        }

        Intent intent = pendingIntent.getIntent();
        ActivityInfo info = intent != null
                ? intent.resolveActivityInfo(context.getPackageManager(), 0)
                : null;
        ResolveInfo resolveInfo = mPackageManager.resolveActivityAsUser(intent, 0, userId);
        ActivityInfo info = resolveInfo != null ? resolveInfo.activityInfo : null;
        if (info == null) {
            FrameworkStatsLog.write(FrameworkStatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED,
                    packageName,
+1 −0
Original line number Diff line number Diff line
@@ -3020,6 +3020,7 @@ public class NotificationManagerService extends SystemService {
            BubbleExtractor bubbsExtractor = mRankingHelper.findExtractor(BubbleExtractor.class);
            if (bubbsExtractor != null) {
                bubbsExtractor.setShortcutHelper(mShortcutHelper);
                bubbsExtractor.setPackageManager(mPackageManagerClient);
            }
            registerNotificationPreferencesPullers();
            if (mLockUtils == null) {
+105 −74

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -1255,7 +1255,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        info.resizeMode = RESIZE_MODE_RESIZEABLE;
        ResolveInfo ri = new ResolveInfo();
        ri.activityInfo = info;
        when(mPackageManagerClient.resolveActivity(any(), anyInt())).thenReturn(ri);
        when(mPackageManagerClient.resolveActivityAsUser(any(), anyInt(), anyInt())).thenReturn(ri);
        return new Notification.BubbleMetadata.Builder(
                mActivityIntent,