Merge "Add basic initializer for new notification pipeline"

This commit is contained in:
Ned Burns
2019-09-25 19:26:16 +00:00
committed by Android (Google) Code Review
3 changed files with 102 additions and 1 deletions

View File

@@ -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<NotificationSettingsListener> mSettingsListeners = new ArrayList<>();
private final Context mContext;
private final ArrayList<NotificationSettingsListener> 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);
}
}

View File

@@ -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";
}

View File

@@ -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;
@@ -390,6 +391,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
@@ -1128,6 +1131,8 @@ public class StatusBar extends SystemUI implements DemoMode,
mGroupAlertTransferHelper.bind(mEntryManager, mGroupManager);
mNotificationListController.bind();
mNotifPipelineInitializer.initialize(mNotificationListener);
}
/**