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

Commit b64ffdf0 authored by Daniel Sandler's avatar Daniel Sandler Committed by Android (Google) Code Review
Browse files

Merge "Cleaning up the notification data structures."

parents c3cc7011 379020ae
Loading
Loading
Loading
Loading
+29 −42
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.view.View;


import com.android.internal.statusbar.StatusBarNotification;
import com.android.internal.statusbar.StatusBarNotification;


import java.util.Comparator;
import java.util.ArrayList;
import java.util.ArrayList;


/**
/**
@@ -43,30 +44,35 @@ public class NotificationData {
        }
        }
    }
    }
    private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
    private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
    private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
        public int compare(Entry a, Entry b) {
            return (int)(a.notification.notification.when - b.notification.notification.when);
        }
    };


    public int size() {
    public int size() {
        return mEntries.size();
        return mEntries.size();
    }
    }


    public Entry getEntryAt(int index) {
    public Entry findByKey(IBinder key) {
        return mEntries.get(index);
        for (Entry e : mEntries) {
    }
            if (e.key == key) {

                return e;
    public int findEntry(IBinder key) {
        final int N = mEntries.size();
        for (int i=0; i<N; i++) {
            Entry entry = mEntries.get(i);
            if (entry.key == key) {
                return i;
            }
            }
        }
        }
        return -1;
        return null;
    }
    }


    public int add(Entry entry) {
    public int add(Entry entry) {
        final int index = chooseIndex(entry.notification.notification.when);
        int i;
        mEntries.add(index, entry);
        int N = mEntries.size();
        return index;
        for (i=0; i<N; i++) {
            if (mEntryCmp.compare(mEntries.get(i), entry) > 0) {
                break;
            }
        }
        mEntries.add(i, entry);
        return i;
    }
    }


    public int add(IBinder key, StatusBarNotification notification, View row, View content,
    public int add(IBinder key, StatusBarNotification notification, View row, View content,
@@ -82,36 +88,19 @@ public class NotificationData {
    }
    }


    public Entry remove(IBinder key) {
    public Entry remove(IBinder key) {
        final int N = mEntries.size();
        Entry e = findByKey(key);
        for (int i=0; i<N; i++) {
        if (e != null) {
            Entry entry = mEntries.get(i);
            mEntries.remove(e);
            if (entry.key == key) {
                mEntries.remove(i);
                return entry;
            }
        }
        return null;
    }

    private int chooseIndex(final long when) {
        final int N = mEntries.size();
        for (int i=0; i<N; i++) {
            Entry entry = mEntries.get(i);
            if (entry.notification.notification.when > when) {
                return i;
            }
        }
        }
        return N;
        return e;
    }
    }


    /**
    /**
     * Return whether there are any visible items (i.e. items without an error).
     * Return whether there are any visible items (i.e. items without an error).
     */
     */
    public boolean hasVisibleItems() {
    public boolean hasVisibleItems() {
        final int N = mEntries.size();
        for (Entry e : mEntries) {
        for (int i=0; i<N; i++) {
            if (e.expanded != null) { // the view successfully inflated
            Entry entry = mEntries.get(i);
            if (entry.expanded != null) { // the view successfully inflated
                return true;
                return true;
            }
            }
        }
        }
@@ -122,11 +111,9 @@ public class NotificationData {
     * Return whether there are any clearable items (that aren't errors).
     * Return whether there are any clearable items (that aren't errors).
     */
     */
    public boolean hasClearableItems() {
    public boolean hasClearableItems() {
        final int N = mEntries.size();
        for (Entry e : mEntries) {
        for (int i=0; i<N; i++) {
            if (e.expanded != null) { // the view successfully inflated
            Entry entry = mEntries.get(i);
                if ((e.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) {
            if (entry.expanded != null) { // the view successfully inflated
                if ((entry.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) {
                    return true;
                    return true;
                }
                }
            }
            }
+5 −6
Original line number Original line Diff line number Diff line
@@ -353,7 +353,7 @@ public class PhoneStatusBarService extends StatusBarService {
        if (immersive) {
        if (immersive) {
            if ((notification.notification.flags & Notification.FLAG_HIGH_PRIORITY) != 0) {
            if ((notification.notification.flags & Notification.FLAG_HIGH_PRIORITY) != 0) {
                Slog.d(TAG, "Presenting high-priority notification in immersive activity");
                Slog.d(TAG, "Presenting high-priority notification in immersive activity");
                // @@@ special new transient ticker mode
                // special new transient ticker mode
                // 1. Populate mIntruderAlertView
                // 1. Populate mIntruderAlertView


                ImageView alertIcon = (ImageView) mIntruderAlertView.findViewById(R.id.alertIcon);
                ImageView alertIcon = (ImageView) mIntruderAlertView.findViewById(R.id.alertIcon);
@@ -399,18 +399,17 @@ public class PhoneStatusBarService extends StatusBarService {
        Slog.d(TAG, "updateNotification key=" + key + " notification=" + notification);
        Slog.d(TAG, "updateNotification key=" + key + " notification=" + notification);


        NotificationData oldList;
        NotificationData oldList;
        int oldIndex = mOngoing.findEntry(key);
        NotificationData.Entry oldEntry = mOngoing.findByKey(key);
        if (oldIndex >= 0) {
        if (oldEntry != null) {
            oldList = mOngoing;
            oldList = mOngoing;
        } else {
        } else {
            oldIndex = mLatest.findEntry(key);
            oldEntry = mLatest.findByKey(key);
            if (oldIndex < 0) {
            if (oldEntry == null) {
                Slog.w(TAG, "updateNotification for unknown key: " + key);
                Slog.w(TAG, "updateNotification for unknown key: " + key);
                return;
                return;
            }
            }
            oldList = mLatest;
            oldList = mLatest;
        }
        }
        final NotificationData.Entry oldEntry = oldList.getEntryAt(oldIndex);
        final StatusBarNotification oldNotification = oldEntry.notification;
        final StatusBarNotification oldNotification = oldEntry.notification;
        final RemoteViews oldContentView = oldNotification.notification.contentView;
        final RemoteViews oldContentView = oldNotification.notification.contentView;


+4 −6
Original line number Original line Diff line number Diff line
@@ -49,7 +49,7 @@ import com.android.systemui.statusbar.*;
import com.android.systemui.R;
import com.android.systemui.R;


public class TabletStatusBarService extends StatusBarService {
public class TabletStatusBarService extends StatusBarService {
    public static final boolean DEBUG = true;
    public static final boolean DEBUG = false;
    public static final String TAG = "TabletStatusBar";
    public static final String TAG = "TabletStatusBar";


    View mStatusBarView;
    View mStatusBarView;
@@ -195,15 +195,13 @@ public class TabletStatusBarService extends StatusBarService {


    public void updateNotification(IBinder key, StatusBarNotification notification) {
    public void updateNotification(IBinder key, StatusBarNotification notification) {
        if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO");
        if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO");
        NotificationData oldList = mHaps;
        
        
        int oldIndex = oldList.findEntry(key);
        final NotificationData.Entry oldEntry = mHaps.findByKey(key);
        if (oldIndex < 0) {
        if (oldEntry == null) {
            Slog.w(TAG, "updateNotification for unknown key: " + key);
            Slog.w(TAG, "updateNotification for unknown key: " + key);
            return;
            return;
        }
        }


        final NotificationData.Entry oldEntry = oldList.getEntryAt(oldIndex);
        final StatusBarNotification oldNotification = oldEntry.notification;
        final StatusBarNotification oldNotification = oldEntry.notification;
        final RemoteViews oldContentView = oldNotification.notification.contentView;
        final RemoteViews oldContentView = oldNotification.notification.contentView;