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

Commit 00b4b2d9 authored by Ned Burns's avatar Ned Burns
Browse files

Encapsulate NotifEntry.key and .notification

NotificationEntry.key -> getKey()
NotificationEntry.notification -> getSbn()

.key -> mKey
.notification -> mSbn

Test: atest
Change-Id: Idcc56af5d941d600b2958afb9ed898fd7ab361cc
parent 291a46e4
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -50,13 +50,13 @@ public class ForegroundServiceLifetimeExtender implements NotificationLifetimeEx

    @Override
    public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) {
        if ((entry.notification.getNotification().flags
        if ((entry.getSbn().getNotification().flags
                & Notification.FLAG_FOREGROUND_SERVICE) == 0) {
            return false;
        }

        long currentTime = System.currentTimeMillis();
        return currentTime - entry.notification.getPostTime() < MIN_FGS_TIME_MS;
        return currentTime - entry.getSbn().getPostTime() < MIN_FGS_TIME_MS;
    }

    @Override
@@ -79,12 +79,12 @@ public class ForegroundServiceLifetimeExtender implements NotificationLifetimeEx
            if (mManagedEntries.contains(entry)) {
                mManagedEntries.remove(entry);
                if (mNotificationSafeToRemoveCallback != null) {
                    mNotificationSafeToRemoveCallback.onSafeToRemove(entry.key);
                    mNotificationSafeToRemoveCallback.onSafeToRemove(entry.getKey());
                }
            }
        };
        long delayAmt = MIN_FGS_TIME_MS
                - (System.currentTimeMillis() - entry.notification.getPostTime());
                - (System.currentTimeMillis() - entry.getSbn().getPostTime());
        mHandler.postDelayed(r, delayAmt);
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -50,12 +50,12 @@ public class ForegroundServiceNotificationListener {
        notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
            @Override
            public void onPendingEntryAdded(NotificationEntry entry) {
                addNotification(entry.notification, entry.getImportance());
                addNotification(entry.getSbn(), entry.getImportance());
            }

            @Override
            public void onPostEntryUpdated(NotificationEntry entry) {
                updateNotification(entry.notification, entry.getImportance());
                updateNotification(entry.getSbn(), entry.getImportance());
            }

            @Override
@@ -63,7 +63,7 @@ public class ForegroundServiceNotificationListener {
                    NotificationEntry entry,
                    NotificationVisibility visibility,
                    boolean removedByUser) {
                removeNotification(entry.notification);
                removeNotification(entry.getSbn());
            }
        });

+16 −16
Original line number Diff line number Diff line
@@ -83,23 +83,23 @@ class Bubble {
    private boolean mSuppressFlyout;

    public static String groupId(NotificationEntry entry) {
        UserHandle user = entry.notification.getUser();
        return user.getIdentifier() + "|" + entry.notification.getPackageName();
        UserHandle user = entry.getSbn().getUser();
        return user.getIdentifier() + "|" + entry.getSbn().getPackageName();
    }

    /** Used in tests when no UI is required. */
    @VisibleForTesting(visibility = PRIVATE)
    Bubble(Context context, NotificationEntry e) {
        mEntry = e;
        mKey = e.key;
        mLastUpdated = e.notification.getPostTime();
        mKey = e.getKey();
        mLastUpdated = e.getSbn().getPostTime();
        mGroupId = groupId(e);

        PackageManager pm = context.getPackageManager();
        ApplicationInfo info;
        try {
            info = pm.getApplicationInfo(
                mEntry.notification.getPackageName(),
                mEntry.getSbn().getPackageName(),
                PackageManager.MATCH_UNINSTALLED_PACKAGES
                    | PackageManager.MATCH_DISABLED_COMPONENTS
                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
@@ -107,10 +107,10 @@ class Bubble {
            if (info != null) {
                mAppName = String.valueOf(pm.getApplicationLabel(info));
            }
            Drawable appIcon = pm.getApplicationIcon(mEntry.notification.getPackageName());
            mUserBadgedAppIcon = pm.getUserBadgedIcon(appIcon, mEntry.notification.getUser());
            Drawable appIcon = pm.getApplicationIcon(mEntry.getSbn().getPackageName());
            mUserBadgedAppIcon = pm.getUserBadgedIcon(appIcon, mEntry.getSbn().getUser());
        } catch (PackageManager.NameNotFoundException unused) {
            mAppName = mEntry.notification.getPackageName();
            mAppName = mEntry.getSbn().getPackageName();
        }
    }

@@ -127,7 +127,7 @@ class Bubble {
    }

    public String getPackageName() {
        return mEntry.notification.getPackageName();
        return mEntry.getSbn().getPackageName();
    }

    public String getAppName() {
@@ -190,7 +190,7 @@ class Bubble {

    void updateEntry(NotificationEntry entry) {
        mEntry = entry;
        mLastUpdated = entry.notification.getPostTime();
        mLastUpdated = entry.getSbn().getPostTime();
        if (mInflated) {
            mIconView.update(this);
            mExpandedView.update(this);
@@ -287,7 +287,7 @@ class Bubble {
     * is an ongoing bubble.
     */
    boolean isOngoing() {
        int flags = mEntry.notification.getNotification().flags;
        int flags = mEntry.getSbn().getNotification().flags;
        return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0;
    }

@@ -296,8 +296,8 @@ class Bubble {
        boolean useRes = data.getDesiredHeightResId() != 0;
        if (useRes) {
            return getDimenForPackageUser(context, data.getDesiredHeightResId(),
                    mEntry.notification.getPackageName(),
                    mEntry.notification.getUser().getIdentifier());
                    mEntry.getSbn().getPackageName(),
                    mEntry.getSbn().getUser().getIdentifier());
        } else {
            return data.getDesiredHeight()
                    * context.getResources().getDisplayMetrics().density;
@@ -316,7 +316,7 @@ class Bubble {

    @Nullable
    PendingIntent getBubbleIntent(Context context) {
        Notification notif = mEntry.notification.getNotification();
        Notification notif = mEntry.getSbn().getNotification();
        Notification.BubbleMetadata data = notif.getBubbleMetadata();
        if (BubbleController.canLaunchInActivityView(context, mEntry) && data != null) {
            return data.getIntent();
@@ -327,7 +327,7 @@ class Bubble {
    Intent getSettingsIntent() {
        final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS);
        intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
        intent.putExtra(Settings.EXTRA_APP_UID, mEntry.notification.getUid());
        intent.putExtra(Settings.EXTRA_APP_UID, mEntry.getSbn().getUid());
        intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
@@ -339,7 +339,7 @@ class Bubble {
     * notification, based on its type. Returns null if there should not be an update message.
     */
    CharSequence getUpdateMessage(Context context) {
        final Notification underlyingNotif = mEntry.notification.getNotification();
        final Notification underlyingNotif = mEntry.getSbn().getNotification();
        final Class<? extends Notification.Style> style = underlyingNotif.getNotificationStyle();

        try {
+22 −21
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                        // More notifications could be added causing summary to no longer
                        // be suppressed -- in this case need to remove the key.
                        final String groupKey = group.summary != null
                                ? group.summary.notification.getGroupKey()
                                ? group.summary.getSbn().getGroupKey()
                                : null;
                        if (!suppressed && groupKey != null
                                && mBubbleData.isSummarySuppressed(groupKey)) {
@@ -346,7 +346,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
            return;
        }
        for (NotificationEntry e : notificationData.getNotificationsForCurrentUser()) {
            if (savedBubbleKeys.contains(e.key)
            if (savedBubbleKeys.contains(e.getKey())
                    && mNotificationInterruptionStateProvider.shouldBubbleUp(e)
                    && canLaunchInActivityView(mContext, e)) {
                updateBubble(e, /* suppressFlyout= */ true);
@@ -445,7 +445,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
        boolean isBubbleAndSuppressed = mBubbleData.hasBubbleWithKey(key)
                && !mBubbleData.getBubbleWithKey(key).showInShadeWhenBubble();
        NotificationEntry entry = mNotificationEntryManager.getNotificationData().get(key);
        String groupKey = entry != null ? entry.notification.getGroupKey() : null;
        String groupKey = entry != null ? entry.getSbn().getGroupKey() : null;
        boolean isSuppressedSummary = mBubbleData.isSummarySuppressed(groupKey);
        boolean isSummary = key.equals(mBubbleData.getSummaryKey(groupKey));
        return (isSummary && isSuppressedSummary) || isBubbleAndSuppressed;
@@ -528,14 +528,14 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
            @Override
            public boolean onNotificationRemoveRequested(String key, int reason) {
                NotificationEntry entry = mNotificationEntryManager.getNotificationData().get(key);
                String groupKey = entry != null ? entry.notification.getGroupKey() : null;
                String groupKey = entry != null ? entry.getSbn().getGroupKey() : null;
                ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey);

                boolean inBubbleData = mBubbleData.hasBubbleWithKey(key);
                boolean isSuppressedSummary = (mBubbleData.isSummarySuppressed(groupKey)
                        && mBubbleData.getSummaryKey(groupKey).equals(key));
                boolean isSummary = entry != null
                        && entry.notification.getNotification().isGroupSummary();
                        && entry.getSbn().getNotification().isGroupSummary();
                boolean isSummaryOfBubbles = (isSuppressedSummary || isSummary)
                        && bubbleChildren != null && !bubbleChildren.isEmpty();

@@ -566,7 +566,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                    bubble.setShowInShadeWhenBubble(false);
                    bubble.setShowBubbleDot(false);
                    if (mStackView != null) {
                        mStackView.updateDotVisibility(entry.key);
                        mStackView.updateDotVisibility(entry.getKey());
                    }
                    mNotificationEntryManager.updateNotifications(
                            "BubbleController.onNotificationRemoveRequested");
@@ -582,7 +582,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi

    private boolean handleSummaryRemovalInterception(NotificationEntry summary,
            boolean userRemovedNotif) {
        String groupKey = summary.notification.getGroupKey();
        String groupKey = summary.getSbn().getGroupKey();
        ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey);

        if (userRemovedNotif) {
@@ -603,11 +603,11 @@ public class BubbleController implements ConfigurationController.ConfigurationLi

            // If the summary was auto-generated we don't need to keep that notification around
            // because apps can't cancel it; so we only intercept & suppress real summaries.
            boolean isAutogroupSummary = (summary.notification.getNotification().flags
            boolean isAutogroupSummary = (summary.getSbn().getNotification().flags
                    & FLAG_AUTOGROUP_SUMMARY) != 0;
            if (!isAutogroupSummary) {
                mBubbleData.addSummaryToSuppress(summary.notification.getGroupKey(),
                        summary.key);
                mBubbleData.addSummaryToSuppress(summary.getSbn().getGroupKey(),
                        summary.getKey());
                // Tell shade to update for the suppression
                mNotificationEntryManager.updateNotifications(
                        "BubbleController.handleSummaryRemovalInterception");
@@ -641,11 +641,11 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
        public void onPreEntryUpdated(NotificationEntry entry) {
            boolean shouldBubble = mNotificationInterruptionStateProvider.shouldBubbleUp(entry)
                    && canLaunchInActivityView(mContext, entry);
            if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.key)) {
            if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.getKey())) {
                // It was previously a bubble but no longer a bubble -- lets remove it
                removeBubble(entry.key, DISMISS_NO_LONGER_BUBBLE);
                removeBubble(entry.getKey(), DISMISS_NO_LONGER_BUBBLE);
            } else if (shouldBubble) {
                Bubble b = mBubbleData.getBubbleWithKey(entry.key);
                Bubble b = mBubbleData.getBubbleWithKey(entry.getKey());
                updateBubble(entry);
            }
        }
@@ -695,10 +695,10 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                            && !bubble.showInShadeWhenBubble()) {
                        // The bubble is gone & the notification is gone, time to actually remove it
                        mNotificationEntryManager.performRemoveNotification(
                                bubble.getEntry().notification, UNDEFINED_DISMISS_REASON);
                                bubble.getEntry().getSbn(), UNDEFINED_DISMISS_REASON);
                    } else {
                        // Update the flag for SysUI
                        bubble.getEntry().notification.getNotification().flags &= ~FLAG_BUBBLE;
                        bubble.getEntry().getSbn().getNotification().flags &= ~FLAG_BUBBLE;

                        // Make sure NoMan knows it's not a bubble anymore so anyone querying it
                        // will get right result back
@@ -712,7 +712,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi

                    // Check if removed bubble has an associated suppressed group summary that needs
                    // to be removed now.
                    final String groupKey = bubble.getEntry().notification.getGroupKey();
                    final String groupKey = bubble.getEntry().getSbn().getGroupKey();
                    if (mBubbleData.isSummarySuppressed(groupKey)
                            && mBubbleData.getBubblesInGroup(groupKey).isEmpty()) {
                        // Time to actually remove the summary.
@@ -721,20 +721,21 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                        NotificationEntry entry =
                                mNotificationEntryManager.getNotificationData().get(notifKey);
                        mNotificationEntryManager.performRemoveNotification(
                                entry.notification, UNDEFINED_DISMISS_REASON);
                                entry.getSbn(), UNDEFINED_DISMISS_REASON);
                    }

                    // Check if summary should be removed from NoManGroup
                    NotificationEntry summary = mNotificationGroupManager.getLogicalGroupSummary(
                            bubble.getEntry().notification);
                            bubble.getEntry().getSbn());
                    if (summary != null) {
                        ArrayList<NotificationEntry> summaryChildren =
                                mNotificationGroupManager.getLogicalChildren(summary.notification);
                        boolean isSummaryThisNotif = summary.key.equals(bubble.getEntry().key);
                                mNotificationGroupManager.getLogicalChildren(summary.getSbn());
                        boolean isSummaryThisNotif = summary.getKey().equals(
                                bubble.getEntry().getKey());
                        if (!isSummaryThisNotif
                                && (summaryChildren == null || summaryChildren.isEmpty())) {
                            mNotificationEntryManager.performRemoveNotification(
                                    summary.notification, UNDEFINED_DISMISS_REASON);
                                    summary.getSbn(), UNDEFINED_DISMISS_REASON);
                        }
                    }
                }
+5 −4
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ public class BubbleData {
        if (DEBUG_BUBBLE_DATA) {
            Log.d(TAG, "notificationEntryUpdated: " + entry);
        }
        Bubble bubble = getBubbleWithKey(entry.key);
        Bubble bubble = getBubbleWithKey(entry.getKey());
        suppressFlyout = !entry.isVisuallyInterruptive || suppressFlyout;

        if (bubble == null) {
@@ -217,7 +217,7 @@ public class BubbleData {
        if (DEBUG_BUBBLE_DATA) {
            Log.d(TAG, "notificationEntryRemoved: entry=" + entry + " reason=" + reason);
        }
        doRemove(entry.key, reason);
        doRemove(entry.getKey(), reason);
        dispatchPendingChanges();
    }

@@ -290,7 +290,7 @@ public class BubbleData {
            return bubbleChildren;
        }
        for (Bubble b : mBubbles) {
            if (groupKey.equals(b.getEntry().notification.getGroupKey())) {
            if (groupKey.equals(b.getEntry().getSbn().getGroupKey())) {
                bubbleChildren.add(b);
            }
        }
@@ -633,7 +633,8 @@ public class BubbleData {
                try {
                    deleteIntent.send();
                } catch (PendingIntent.CanceledException e) {
                    Log.w(TAG, "Failed to send delete intent for bubble with key: " + entry.key);
                    Log.w(TAG, "Failed to send delete intent for bubble with key: "
                            + entry.getKey());
                }
            }
        }
Loading