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

Commit 04ffb512 authored by Flavio Fiszman's avatar Flavio Fiszman
Browse files

Update People Space widget on channel modification

Test: Buld and run, and unit test.
Change-Id: I209c3a7ac12fa48f744d8f784c598ad359bf2de6
parent 5e687f45
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@

package com.android.systemui.plugins;

import android.app.NotificationChannel;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;

@@ -30,13 +32,32 @@ public interface NotificationListenerController extends Plugin {

    void onListenerConnected(NotificationProvider provider);

    /**
     * @return whether plugin wants to skip the default callbacks.
     */
    default boolean onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
        return false;
    }

    /**
     * @return whether plugin wants to skip the default callbacks.
     */
    default boolean onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) {
        return false;
    }

    /**
     * Called when a notification channel is modified.
     * @param modificationType One of {@link #NOTIFICATION_CHANNEL_OR_GROUP_ADDED},
     *                                {@link #NOTIFICATION_CHANNEL_OR_GROUP_UPDATED},
     *                                {@link #NOTIFICATION_CHANNEL_OR_GROUP_DELETED}.
     * @return whether a plugin wants to skip the default callbacks.
     */
    default boolean onNotificationChannelModified(
            String pkgName, UserHandle user, NotificationChannel channel, int modificationType) {
        return false;
    }

    default StatusBarNotification[] getActiveNotifications(
            StatusBarNotification[] activeNotifications) {
        return activeNotifications;
+14 −0
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package com.android.systemui.people.widget;

import android.app.NotificationChannel;
import android.content.ComponentName;
import android.content.Context;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
@@ -130,6 +132,18 @@ public class PeopleSpaceWidgetManager {
            if (DEBUG) Log.d(TAG, "onNotificationsInitialized");
            updateWidgets();
        }

        @Override
        public void onNotificationChannelModified(
                String pkgName,
                UserHandle user,
                NotificationChannel channel,
                int modificationType) {
            if (DEBUG) Log.d(TAG, "onNotificationChannelModified");
            if (channel.isConversation()) {
                updateWidgets();
            }
        }
    };

}
+22 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static com.android.systemui.statusbar.phone.StatusBar.DEBUG;

import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
@@ -158,6 +159,19 @@ public class NotificationListener extends NotificationListenerWithPlugins {
        }
    }

    @Override
    public void onNotificationChannelModified(
            String pkgName, UserHandle user, NotificationChannel channel, int modificationType) {
        if (DEBUG) Log.d(TAG, "onNotificationChannelModified");
        if (!onPluginNotificationChannelModified(pkgName, user, channel, modificationType)) {
            mMainHandler.post(() -> {
                for (NotificationHandler handler : mNotificationHandlers) {
                    handler.onNotificationChannelModified(pkgName, user, channel, modificationType);
                }
            });
        }
    }

    @Override
    public void onSilentStatusBarIconsVisibilityChanged(boolean hideSilentStatusIcons) {
        for (NotificationSettingsListener listener : mSettingsListeners) {
@@ -229,6 +243,14 @@ public class NotificationListener extends NotificationListenerWithPlugins {
        void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap, int reason);
        void onNotificationRankingUpdate(RankingMap rankingMap);

        /** Called after a notification channel is modified. */
        default void onNotificationChannelModified(
                String pkgName,
                UserHandle user,
                NotificationChannel channel,
                int modificationType) {
        }

        /**
         * Called after the listener has connected to NoMan and posted any current notifications.
         */
+11 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.systemui.statusbar.notification.collection.coalescer;
import static java.util.Objects.requireNonNull;

import android.annotation.MainThread;
import android.app.NotificationChannel;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
@@ -158,6 +160,15 @@ public class GroupCoalescer implements Dumpable {
        public void onNotificationsInitialized() {
            mHandler.onNotificationsInitialized();
        }

        @Override
        public void onNotificationChannelModified(
                String pkgName,
                UserHandle user,
                NotificationChannel channel,
                int modificationType) {
            mHandler.onNotificationChannelModified(pkgName, user, channel, modificationType);
        }
    };

    private void maybeEmitBatch(StatusBarNotification sbn) {
+18 −2
Original line number Diff line number Diff line
@@ -14,9 +14,11 @@

package com.android.systemui.statusbar.phone;

import android.app.NotificationChannel;
import android.content.ComponentName;
import android.content.Context;
import android.os.RemoteException;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;

@@ -78,7 +80,7 @@ public class NotificationListenerWithPlugins extends NotificationListenerService

    /**
     * Called when listener receives a onNotificationPosted.
     * Returns true to indicate this callback should be skipped.
     * Returns true if there's a plugin determining to skip the default callbacks.
     */
    public boolean onPluginNotificationPosted(StatusBarNotification sbn,
            final RankingMap rankingMap) {
@@ -92,7 +94,7 @@ public class NotificationListenerWithPlugins extends NotificationListenerService

    /**
     * Called when listener receives a onNotificationRemoved.
     * Returns true to indicate this callback should be skipped.
     * Returns true if there's a plugin determining to skip the default callbacks.
     */
    public boolean onPluginNotificationRemoved(StatusBarNotification sbn,
            final RankingMap rankingMap) {
@@ -104,6 +106,20 @@ public class NotificationListenerWithPlugins extends NotificationListenerService
        return false;
    }

    /**
     * Called when listener receives a onNotificationChannelModified.
     * Returns true if there's a plugin determining to skip the default callbacks.
     */
    public boolean onPluginNotificationChannelModified(
            String pkgName, UserHandle user, NotificationChannel channel, int modificationType) {
        for (NotificationListenerController plugin : mPlugins) {
            if (plugin.onNotificationChannelModified(pkgName, user, channel, modificationType)) {
                return true;
            }
        }
        return false;
    }

    public RankingMap onPluginRankingUpdate(RankingMap rankingMap) {
        return getCurrentRanking();
    }
Loading