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

Commit 08e5ad89 authored by Ned Burns's avatar Ned Burns Committed by Android (Google) Code Review
Browse files

Merge changes from topic "fix-event-dispatch"

* changes:
  Invert BubbleController <-> NEM dependency
  Inline a few methods in NotificationEntryManager
  Change onRemoteEntry() to only fire when entries are removed
parents 9d119703 01e3821a
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -61,15 +61,10 @@ public class ForegroundServiceNotificationListener {
            @Override
            public void onEntryRemoved(
                    NotificationData.Entry entry,
                    String key,
                    StatusBarNotification old,
                    NotificationVisibility visibility,
                    boolean lifetimeExtended,
                    boolean removedByUser) {
                if (entry != null && !lifetimeExtended) {
                removeNotification(entry.notification);
            }
            }
        });
    }

+38 −40
Original line number Diff line number Diff line
@@ -33,8 +33,11 @@ import android.view.WindowManager;
import android.widget.FrameLayout;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.NotificationData;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.phone.StatusBarWindowController;

import java.util.ArrayList;
@@ -57,46 +60,30 @@ public class BubbleController {
    private static final String TAG = "BubbleController";

    // Enables some subset of notifs to automatically become bubbles
    public static final boolean DEBUG_ENABLE_AUTO_BUBBLE = false;
    private static final boolean DEBUG_ENABLE_AUTO_BUBBLE = false;
    // When a bubble is dismissed, recreate it as a notification
    public static final boolean DEBUG_DEMOTE_TO_NOTIF = false;
    private static final boolean DEBUG_DEMOTE_TO_NOTIF = false;

    // Secure settings
    private static final String ENABLE_AUTO_BUBBLE_MESSAGES = "experiment_autobubble_messaging";
    private static final String ENABLE_AUTO_BUBBLE_ONGOING = "experiment_autobubble_ongoing";
    private static final String ENABLE_AUTO_BUBBLE_ALL = "experiment_autobubble_all";

    private Context mContext;
    private BubbleDismissListener mDismissListener;
    private final Context mContext;
    private final NotificationEntryManager mNotificationEntryManager;
    private BubbleStateChangeListener mStateChangeListener;
    private BubbleExpandListener mExpandListener;

    private Map<String, BubbleView> mBubbles = new HashMap<>();
    private final Map<String, BubbleView> mBubbles = new HashMap<>();
    private BubbleStackView mStackView;
    private Point mDisplaySize;
    private final Point mDisplaySize;

    // Bubbles get added to the status bar view
    @VisibleForTesting
    protected StatusBarWindowController mStatusBarWindowController;
    private final StatusBarWindowController mStatusBarWindowController;

    // Used for determining view rect for touch interaction
    private Rect mTempRect = new Rect();

    /**
     * Listener to find out about bubble / bubble stack dismissal events.
     */
    public interface BubbleDismissListener {
        /**
         * Called when the entire stack of bubbles is dismissed by the user.
         */
        void onStackDismissed();

        /**
         * Called when a specific bubble is dismissed by the user.
         */
        void onBubbleDismissed(String key);
    }

    /**
     * Listener to be notified when some states of the bubbles change.
     */
@@ -123,17 +110,13 @@ public class BubbleController {
    @Inject
    public BubbleController(Context context, StatusBarWindowController statusBarWindowController) {
        mContext = context;
        mNotificationEntryManager = Dependency.get(NotificationEntryManager.class);
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        mDisplaySize = new Point();
        wm.getDefaultDisplay().getSize(mDisplaySize);
        mStatusBarWindowController = statusBarWindowController;
    }

    /**
     * Set a listener to be notified of bubble dismissal events.
     */
    public void setDismissListener(BubbleDismissListener listener) {
        mDismissListener = listener;
        mNotificationEntryManager.addNotificationEntryListener(mEntryListener);
    }

    /**
@@ -180,7 +163,7 @@ public class BubbleController {
    /**
     * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack.
     */
    public void dismissStack() {
    void dismissStack() {
        if (mStackView == null) {
            return;
        }
@@ -190,9 +173,7 @@ public class BubbleController {
        for (String key: mBubbles.keySet()) {
            removeBubble(key);
        }
        if (mDismissListener != null) {
            mDismissListener.onStackDismissed();
        }
        mNotificationEntryManager.updateNotifications();
        updateBubblesShowing();
    }

@@ -238,18 +219,35 @@ public class BubbleController {
    /**
     * Removes the bubble associated with the {@param uri}.
     */
    public void removeBubble(String key) {
    void removeBubble(String key) {
        BubbleView bv = mBubbles.get(key);
        if (mStackView != null && bv != null) {
            mStackView.removeBubble(bv);
            bv.getEntry().setBubbleDismissed(true);
        }
        if (mDismissListener != null) {
            mDismissListener.onBubbleDismissed(key);

        NotificationData.Entry entry = mNotificationEntryManager.getNotificationData().get(key);
        if (entry != null) {
            entry.setBubbleDismissed(true);
            if (!DEBUG_DEMOTE_TO_NOTIF) {
                mNotificationEntryManager.performRemoveNotification(entry.notification);
            }
        }
        mNotificationEntryManager.updateNotifications();

        updateBubblesShowing();
    }

    @SuppressWarnings("FieldCanBeLocal")
    private final NotificationEntryListener mEntryListener = new NotificationEntryListener() {
        @Override
        public void onPendingEntryAdded(NotificationData.Entry entry) {
            if (shouldAutoBubble(mContext, entry)) {
                entry.setIsBubble(true);
            }
        }
    };

    private void updateBubblesShowing() {
        boolean hasBubblesShowing = false;
        for (BubbleView bv : mBubbles.values()) {
@@ -309,7 +307,7 @@ public class BubbleController {
    }

    @VisibleForTesting
    public BubbleStackView getStackView() {
    BubbleStackView getStackView() {
        return mStackView;
    }

@@ -317,7 +315,7 @@ public class BubbleController {
    /**
     * Gets an appropriate starting point to position the bubble stack.
     */
    public static Point getStartPoint(int size, Point displaySize) {
    private static Point getStartPoint(int size, Point displaySize) {
        final int x = displaySize.x - size + EDGE_OVERLAP;
        final int y = displaySize.y / 4;
        return new Point(x, y);
@@ -326,7 +324,7 @@ public class BubbleController {
    /**
     * Gets an appropriate position for the bubble when the stack is expanded.
     */
    public static Point getExpandPoint(BubbleStackView view, int size, Point displaySize) {
    static Point getExpandPoint(BubbleStackView view, int size, Point displaySize) {
        // Same place for now..
        return new Point(EDGE_OVERLAP, size);
    }
@@ -334,7 +332,7 @@ public class BubbleController {
    /**
     * Whether the notification should bubble or not.
     */
    public static boolean shouldAutoBubble(Context context, NotificationData.Entry entry) {
    private static boolean shouldAutoBubble(Context context, NotificationData.Entry entry) {
        if (entry.isBubbleDismissed()) {
            return false;
        }
+2 −8
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import android.media.session.PlaybackState;
import android.os.Handler;
import android.os.Trace;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
@@ -157,15 +156,10 @@ public class NotificationMediaManager implements Dumpable {
        notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
            @Override
            public void onEntryRemoved(
                    @Nullable Entry entry,
                    String key,
                    StatusBarNotification old,
                    Entry entry,
                    NotificationVisibility visibility,
                    boolean lifetimeExtended,
                    boolean removedByUser) {
                if (!lifetimeExtended) {
                    onNotificationRemoved(key);
                }
                onNotificationRemoved(entry.key);
            }
        });
    }
+1 −4
Original line number Diff line number Diff line
@@ -254,13 +254,10 @@ public class NotificationRemoteInputManager implements Dumpable {
            @Override
            public void onEntryRemoved(
                    @Nullable NotificationData.Entry entry,
                    String key,
                    StatusBarNotification old,
                    NotificationVisibility visibility,
                    boolean lifetimeExtended,
                    boolean removedByUser) {
                if (removedByUser && entry != null) {
                    onPerformRemoveNotification(entry, key);
                    onPerformRemoveNotification(entry, entry.key);
                }
            }
        });
+2 −6
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.systemui.statusbar.NotificationRemoteInputManager.FORC
import static com.android.systemui.statusbar.notification.row.NotificationInflater.FLAG_CONTENT_VIEW_AMBIENT;
import static com.android.systemui.statusbar.notification.row.NotificationInflater.FLAG_CONTENT_VIEW_HEADS_UP;

import android.annotation.Nullable;
import android.app.Notification;
import android.service.notification.StatusBarNotification;
import android.util.Log;
@@ -83,13 +82,10 @@ public class NotificationAlertingManager {

            @Override
            public void onEntryRemoved(
                    @Nullable NotificationData.Entry entry,
                    String key,
                    StatusBarNotification old,
                    NotificationData.Entry entry,
                    NotificationVisibility visibility,
                    boolean lifetimeExtended,
                    boolean removedByUser) {
                stopAlerting(key);
                stopAlerting(entry.key);
            }
        });
    }
Loading