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

Commit d39f0d52 authored by Dieter Hsu's avatar Dieter Hsu
Browse files

Add rank & count event to notification clicks and dismisses

For click/action click/dismiss, passing rank(0-based) and
count at the time of the actions to events.

Bug: 70724602
Test: runtest systemui-notification
Test: atest packages/SystemUI/tests/src/com/android/systemui/statusbar/notification
Change-Id: I07c440f84ccb745f744eb4e317881b72d2b41683
parent 52842feb
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -54,12 +54,13 @@ interface IStatusBarService
    void onPanelHidden();
    // Mark current notifications as "seen" and stop ringing, vibrating, blinking.
    void clearNotificationEffects();
    void onNotificationClick(String key);
    void onNotificationActionClick(String key, int actionIndex);
    void onNotificationClick(String key, in NotificationVisibility nv);
    void onNotificationActionClick(String key, int actionIndex, in NotificationVisibility nv);
    void onNotificationError(String pkg, String tag, int id,
            int uid, int initialPid, String message, int userId);
    void onClearAllNotifications(int userId);
    void onNotificationClear(String pkg, String tag, int id, int userId, String key, int dismissalSurface);
    void onNotificationClear(String pkg, String tag, int id, int userId, String key,
            int dismissalSurface, in NotificationVisibility nv);
    void onNotificationVisibilityChanged( in NotificationVisibility[] newlyVisibleKeys,
            in NotificationVisibility[] noLongerVisibleKeys);
    void onNotificationExpansionChanged(in String key, in boolean userAction, in boolean expanded);
+9 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public class NotificationVisibility implements Parcelable {

    public String key;
    public int rank;
    public int count;
    public boolean visible = true;
    /*package*/ int id;

@@ -39,10 +40,11 @@ public class NotificationVisibility implements Parcelable {
        id = sNexrId++;
    }

    private NotificationVisibility(String key, int rank, boolean visibile) {
    private NotificationVisibility(String key, int rank, int count, boolean visibile) {
        this();
        this.key = key;
        this.rank = rank;
        this.count = count;
        this.visible = visibile;
    }

@@ -51,13 +53,14 @@ public class NotificationVisibility implements Parcelable {
        return "NotificationVisibility(id=" + id
                + "key=" + key
                + " rank=" + rank
                + " count=" + count
                + (visible?" visible":"")
                + " )";
    }

    @Override
    public NotificationVisibility clone() {
        return obtain(this.key, this.rank, this.visible);
        return obtain(this.key, this.rank, this.count, this.visible);
    }

    @Override
@@ -85,12 +88,14 @@ public class NotificationVisibility implements Parcelable {
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(this.key);
        out.writeInt(this.rank);
        out.writeInt(this.count);
        out.writeInt(this.visible ? 1 : 0);
    }

    private void readFromParcel(Parcel in) {
        this.key = in.readString();
        this.rank = in.readInt();
        this.count = in.readInt();
        this.visible = in.readInt() != 0;
    }

@@ -98,10 +103,11 @@ public class NotificationVisibility implements Parcelable {
     * Return a new NotificationVisibility instance from the global pool. Allows us to
     * avoid allocating new objects in many cases.
     */
    public static NotificationVisibility obtain(String key, int rank, boolean visible) {
    public static NotificationVisibility obtain(String key, int rank, int count, boolean visible) {
        NotificationVisibility vo = obtain();
        vo.key = key;
        vo.rank = rank;
        vo.count = count;
        vo.visible = visible;
        return vo;
    }
+8 −0
Original line number Diff line number Diff line
@@ -509,6 +509,14 @@ public class NotificationData {
        return null;
    }

    public int getRank(String key) {
        if (mRankingMap != null) {
            getRanking(key, mTmpRanking);
            return mTmpRanking.getRank();
        }
        return 0;
    }

    public boolean shouldHide(String key) {
        if (mRankingMap != null) {
            getRanking(key, mTmpRanking);
+6 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.view.ViewGroup;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.internal.util.NotificationMessagingUtil;
import com.android.systemui.DejankUtils;
import com.android.systemui.Dependency;
@@ -367,6 +368,10 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
    }

    public void performRemoveNotification(StatusBarNotification n) {
        final int rank = mNotificationData.getRank(n.getKey());
        final int count = mNotificationData.getActiveNotifications().size();
        final NotificationVisibility nv = NotificationVisibility.obtain(n.getKey(), rank, count,
                true);
        NotificationData.Entry entry = mNotificationData.get(n.getKey());
        mRemoteInputManager.onPerformRemoveNotification(n, entry);
        final String pkg = n.getPackageName();
@@ -380,7 +385,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
            } else if (mListContainer.hasPulsingNotifications()) {
                dismissalSurface = NotificationStats.DISMISSAL_AOD;
            }
            mBarService.onNotificationClear(pkg, tag, id, userId, n.getKey(), dismissalSurface);
            mBarService.onNotificationClear(pkg, tag, id, userId, n.getKey(), dismissalSurface, nv);
            removeNotification(n.getKey(), null);

        } catch (RemoteException ex) {
+7 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.widget.TextView;
import android.widget.Toast;

import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.internal.widget.LockPatternUtils;
import com.android.systemui.Dependency;
import com.android.systemui.Dumpable;
@@ -129,8 +130,13 @@ public class NotificationLockscreenUserManager implements Dumpable {
                    }
                }
                if (notificationKey != null) {
                    final int count =
                            mEntryManager.getNotificationData().getActiveNotifications().size();
                    final int rank = mEntryManager.getNotificationData().getRank(notificationKey);
                    final NotificationVisibility nv = NotificationVisibility.obtain(notificationKey,
                            rank, count, true);
                    try {
                        mBarService.onNotificationClick(notificationKey);
                        mBarService.onNotificationClick(notificationKey, nv);
                    } catch (RemoteException e) {
                        /* ignore */
                    }
Loading