From 876aef0254a913d443391b7d13b564582a880d23 Mon Sep 17 00:00:00 2001 From: Ned Burns Date: Fri, 13 Sep 2019 19:41:42 -0400 Subject: [PATCH] Add basic initializer for new notification pipeline - New code is initialized and set up in NotifInitializer - New pipeline will eventually implement NotifServiceListener and get all its events directly from NotificiationListener(Service). Test: manual Change-Id: I07fe8b1a360e73944ff19fcf4a56f9689d577582 --- .../statusbar/NotificationListener.java | 30 +++++++- .../NotifPipelineInitializer.java | 68 +++++++++++++++++++ .../systemui/statusbar/phone/StatusBar.java | 5 ++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/NotifPipelineInitializer.java diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java index 14009214bdc5c..6c0f90a65ae9f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java @@ -21,6 +21,7 @@ import static com.android.systemui.statusbar.notification.NotificationEntryManag import static com.android.systemui.statusbar.phone.StatusBar.DEBUG; import static com.android.systemui.statusbar.phone.StatusBar.ENABLE_CHILD_NOTIFICATIONS; +import android.annotation.Nullable; import android.annotation.SuppressLint; import android.app.NotificationManager; import android.content.ComponentName; @@ -57,8 +58,9 @@ public class NotificationListener extends NotificationListenerWithPlugins { private final NotificationGroupManager mGroupManager = Dependency.get(NotificationGroupManager.class); - private final ArrayList mSettingsListeners = new ArrayList<>(); private final Context mContext; + private final ArrayList mSettingsListeners = new ArrayList<>(); + @Nullable private NotifServiceListener mDownstreamListener; @Inject public NotificationListener(Context context) { @@ -69,6 +71,10 @@ public class NotificationListener extends NotificationListenerWithPlugins { mSettingsListeners.add(listener); } + public void setDownstreamListener(NotifServiceListener downstreamListener) { + mDownstreamListener = downstreamListener; + } + @Override public void onListenerConnected() { if (DEBUG) Log.d(TAG, "onListenerConnected"); @@ -81,6 +87,9 @@ public class NotificationListener extends NotificationListenerWithPlugins { final RankingMap currentRanking = getCurrentRanking(); Dependency.get(Dependency.MAIN_HANDLER).post(() -> { for (StatusBarNotification sbn : notifications) { + if (mDownstreamListener != null) { + mDownstreamListener.onNotificationPosted(sbn, currentRanking); + } mEntryManager.addNotification(sbn, currentRanking); } }); @@ -95,6 +104,11 @@ public class NotificationListener extends NotificationListenerWithPlugins { if (sbn != null && !onPluginNotificationPosted(sbn, rankingMap)) { Dependency.get(Dependency.MAIN_HANDLER).post(() -> { processForRemoteInput(sbn.getNotification(), mContext); + + if (mDownstreamListener != null) { + mDownstreamListener.onNotificationPosted(sbn, rankingMap); + } + String key = sbn.getKey(); boolean isUpdate = mEntryManager.getNotificationData().get(key) != null; @@ -133,6 +147,9 @@ public class NotificationListener extends NotificationListenerWithPlugins { if (sbn != null && !onPluginNotificationRemoved(sbn, rankingMap)) { final String key = sbn.getKey(); Dependency.get(Dependency.MAIN_HANDLER).post(() -> { + if (mDownstreamListener != null) { + mDownstreamListener.onNotificationRemoved(sbn, rankingMap, reason); + } mEntryManager.removeNotification(key, rankingMap, reason); }); } @@ -149,6 +166,9 @@ public class NotificationListener extends NotificationListenerWithPlugins { if (rankingMap != null) { RankingMap r = onPluginRankingUpdate(rankingMap); Dependency.get(Dependency.MAIN_HANDLER).post(() -> { + if (mDownstreamListener != null) { + mDownstreamListener.onNotificationRankingUpdate(rankingMap); + } mEntryManager.updateNotificationRanking(r); }); } @@ -175,4 +195,12 @@ public class NotificationListener extends NotificationListenerWithPlugins { default void onStatusBarIconsBehaviorChanged(boolean hideSilentStatusIcons) { } } + + /** Interface for listening to add/remove events that we receive from NotificationManager. */ + public interface NotifServiceListener { + void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap); + void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap); + void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap, int reason); + void onNotificationRankingUpdate(RankingMap rankingMap); + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotifPipelineInitializer.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotifPipelineInitializer.java new file mode 100644 index 0000000000000..df70828a46be8 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotifPipelineInitializer.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.notification; + +import android.service.notification.NotificationListenerService; +import android.service.notification.StatusBarNotification; +import android.util.Log; + +import com.android.systemui.statusbar.NotificationListener; + +import javax.inject.Inject; + +/** + * Initialization code for the new notification pipeline. + */ +public class NotifPipelineInitializer { + + @Inject + public NotifPipelineInitializer() { + } + + public void initialize( + NotificationListener notificationService) { + + // TODO Put real code here + notificationService.setDownstreamListener(new NotificationListener.NotifServiceListener() { + @Override + public void onNotificationPosted(StatusBarNotification sbn, + NotificationListenerService.RankingMap rankingMap) { + Log.d(TAG, "onNotificationPosted " + sbn.getKey()); + } + + @Override + public void onNotificationRemoved(StatusBarNotification sbn, + NotificationListenerService.RankingMap rankingMap) { + Log.d(TAG, "onNotificationRemoved " + sbn.getKey()); + } + + @Override + public void onNotificationRemoved(StatusBarNotification sbn, + NotificationListenerService.RankingMap rankingMap, int reason) { + Log.d(TAG, "onNotificationRemoved " + sbn.getKey()); + } + + @Override + public void onNotificationRankingUpdate( + NotificationListenerService.RankingMap rankingMap) { + Log.d(TAG, "onNotificationRankingUpdate"); + } + }); + } + + private static final String TAG = "NotifInitializer"; +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 7bc849d28c535..c6ba2fe05f681 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -197,6 +197,7 @@ import com.android.systemui.statusbar.VibratorHelper; import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; import com.android.systemui.statusbar.notification.BypassHeadsUpNotifier; import com.android.systemui.statusbar.notification.DynamicPrivacyController; +import com.android.systemui.statusbar.notification.NotifPipelineInitializer; import com.android.systemui.statusbar.notification.NotificationActivityStarter; import com.android.systemui.statusbar.notification.NotificationAlertingManager; import com.android.systemui.statusbar.notification.NotificationClicker; @@ -389,6 +390,8 @@ public class StatusBar extends SystemUI implements DemoMode, @Inject @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean mAllowNotificationLongPress; + @Inject + protected NotifPipelineInitializer mNotifPipelineInitializer; // expanded notifications protected NotificationPanelView mNotificationPanel; // the sliding/resizing panel within the notification window @@ -1129,6 +1132,8 @@ public class StatusBar extends SystemUI implements DemoMode, mGroupAlertTransferHelper.bind(mEntryManager, mGroupManager); mNotificationListController.bind(); + + mNotifPipelineInitializer.initialize(mNotificationListener); } /**