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

Commit 19999939 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: fix notifs not coming back after unmarking as spam



When a notification gets marked as spam, the view is removed from
SystemUI, but it is not removed from the internal
NotificationManagerService notifications list.

This is not a problem until removing the notification from the
spam filter. After that, any notifications posted try to go through
updateNotification() instead of addNotification(). SystemUI won't post
those notifications since there's not one to update.

When removing a notification from the spam filter, remove any internal
references to the notification so it can be posted new again.

We could remove the reference when the notification gets marked as spam,
but we need to eventually clear the cache *only* if it gets removed from
the spam list. The spam cache gets updated regularly on notification
posts.

Change-Id: Icecba34cf6de18d5f217c8c69ba8db5408e6db82
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent a5f63541
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -83,6 +83,28 @@ public class SpamMessageProvider extends ContentProvider {
        }
    }

    private String getPackageName(long packageId) {
        String packageName = null;

        Cursor pkgCursor = null;
        try {
            pkgCursor = mDbHelper.getReadableDatabase().query(PackageTable.TABLE_NAME,
                    new String[]{PackageTable.PACKAGE_NAME}, PackageTable.ID + "=?",
                    new String[]{String.valueOf(packageId)}, null, null, null);
            if (pkgCursor != null) {
                if (pkgCursor.moveToFirst()) {
                    packageName = pkgCursor.getString(0);
                }
                pkgCursor.close();
            }
        } finally {
            if (pkgCursor != null) {
                pkgCursor.close();
            }
        }
        return packageName;
    }

    private long getPackageId(String pkg) {
        long rowId = -1;
        Cursor idCursor = mDbHelper.getReadableDatabase().query(PackageTable.TABLE_NAME,
@@ -158,6 +180,7 @@ public class SpamMessageProvider extends ContentProvider {
        int match = sURIMatcher.match(uri);
        switch (match) {
        case MESSAGE_FOR_ID:
            String packageName = null;
            int packageId = -1;
            Cursor idCursor = mDbHelper.getReadableDatabase().query(NotificationTable.TABLE_NAME,
                    new String[]{NotificationTable.PACKAGE_ID}, NotificationTable.ID + "=?",
@@ -167,11 +190,17 @@ public class SpamMessageProvider extends ContentProvider {
                    packageId = idCursor.getInt(0);
                }
                idCursor.close();
                packageName = getPackageName(packageId);
            }
            int result = mDbHelper.getWritableDatabase().delete(NotificationTable.TABLE_NAME,
                    NotificationTable.ID + "=?", new String[]{uri.getLastPathSegment()});
            removePackageIfNecessary(packageId);
            notifyChange();
            if (packageName != null) {
                getContext().getContentResolver().notifyChange(
                        SpamFilter.NOTIFICATION_URI.buildUpon()
                                .appendPath("delete")
                                .appendPath(packageName).build(), null);
            }
            return result;
        default:
            return 0;
+40 −0
Original line number Diff line number Diff line
@@ -1394,6 +1394,44 @@ public class NotificationManagerService extends INotificationManager.Stub

    private LEDSettingsObserver mSettingsObserver;

    class SpamFilterObserver extends ContentObserver {
        SpamFilterObserver(Handler handler) {
            super(handler);
        }

        void observe() {
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(SpamFilter.NOTIFICATION_URI, true, this);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            if (uri.getPath() != null) {
                List<String> pathSegments = uri.getPathSegments();
                if (pathSegments.size() >= 2) {
                    if (pathSegments.get(0).equals("delete")) {
                        String pkg = pathSegments.get(1);
                        StatusBarNotification[] activeNotifications = getActiveNotifications(pkg);
                        for (StatusBarNotification notification : activeNotifications) {
                            int idx = indexOfNotificationLocked(pkg, notification.getTag(),
                                    notification.getId(), notification.getUserId());
                            if (idx < 0) {
                                // great!
                            } else {
                                // remove this manually
                                synchronized (mNotificationList) {
                                    mNotificationList.remove(idx);
                                }
                            }
                        }
                        // we need to rebuild our spam cache
                        mSpamCache.evictAll();
                    }
                }
            }
        }
    }

    static long[] getLongArray(Resources r, int resid, int maxlen, long[] def) {
        int[] ar = r.getIntArray(resid);
        if (ar == null) {
@@ -1495,6 +1533,8 @@ public class NotificationManagerService extends INotificationManager.Stub
        qhObserver.observe();
        mSettingsObserver = new LEDSettingsObserver(mHandler);
        mSettingsObserver.observe();
        SpamFilterObserver spamObserver = new SpamFilterObserver(mHandler);
        spamObserver.observe();

        // spin up NotificationScorers
        String[] notificationScorerNames = resources.getStringArray(