Eliminates NotificationEntryManager.getNotificationLongClicker().
This method always returned NotificationGutsManager::openGuts, and only
existed so that CarSystemUI could override it to disable long presses.
In this change we accomplish this by making
NotificationStackScrollLayout injectable and providing a named flag for
whether to enable long presses or not as a dependency. This means that
NotificationEntryManager is no longer involved in handling long presses,
and CarNotificationEntryManager no longer needs to exist.
Test: atest SystemUITests, manual
Change-Id: Iae78601fea498a37ed47ef9a114e50de1652b6a8
diff --git a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java
index 3c0a297..0c35204 100644
--- a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java
+++ b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java
@@ -20,11 +20,9 @@
import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.ViewMediatorCallback;
-import com.android.systemui.car.CarNotificationEntryManager;
import com.android.systemui.car.CarNotificationInterruptionStateProvider;
import com.android.systemui.statusbar.car.CarFacetButtonController;
import com.android.systemui.statusbar.car.CarStatusBarKeyguardViewManager;
-import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.volume.CarVolumeDialogComponent;
@@ -65,16 +63,16 @@
}
@Override
- public NotificationEntryManager provideNotificationEntryManager(Context context) {
- return new CarNotificationEntryManager(context);
- }
-
- @Override
public NotificationInterruptionStateProvider provideNotificationInterruptionStateProvider(
Context context) {
return new CarNotificationInterruptionStateProvider(context);
}
+ @Override
+ public boolean provideAllowNotificationLongPress() {
+ return false;
+ }
+
@Module
protected static class ContextHolder {
private Context mContext;
diff --git a/packages/CarSystemUI/src/com/android/systemui/car/CarNotificationEntryManager.java b/packages/CarSystemUI/src/com/android/systemui/car/CarNotificationEntryManager.java
deleted file mode 100644
index 323cae0..0000000
--- a/packages/CarSystemUI/src/com/android/systemui/car/CarNotificationEntryManager.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2018 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.car;
-
-import android.content.Context;
-
-import com.android.systemui.statusbar.notification.NotificationEntryManager;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
-
-public class CarNotificationEntryManager extends NotificationEntryManager {
- public CarNotificationEntryManager(Context context) {
- super(context);
- }
-
- /**
- * Returns the
- * {@link ExpandableNotificationRow.LongPressListener} that will
- * be triggered when a notification card is long-pressed.
- */
- @Override
- public ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
- // For the automative use case, we do not want to the user to be able to interact with
- // a notification other than a regular click. As a result, just return null for the
- // long click listener.
- return null;
- }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index a8d3763..3d2f838 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -157,6 +157,12 @@
public static final String LEAK_REPORT_EMAIL_NAME = "leak_report_email";
/**
+ * Whether this platform supports long-pressing notifications to show notification channel
+ * settings.
+ */
+ public static final String ALLOW_NOTIFICATION_LONG_PRESS_NAME = "allow_notif_longpress";
+
+ /**
* Key for getting a background Looper for background work.
*/
public static final DependencyKey<Looper> BG_LOOPER = new DependencyKey<>(BG_LOOPER_NAME);
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
index e3bfdc9..073516e 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
@@ -16,6 +16,7 @@
package com.android.systemui;
+import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
import static com.android.systemui.Dependency.LEAK_REPORT_EMAIL_NAME;
import android.annotation.Nullable;
@@ -200,6 +201,13 @@
return new NotificationInterruptionStateProvider(context);
}
+ @Singleton
+ @Provides
+ @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME)
+ public boolean provideAllowNotificationLongPress() {
+ return true;
+ }
+
@Module
protected static class ContextHolder {
private Context mContext;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
index e0fa723..ab97e5e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
@@ -41,7 +41,6 @@
import com.android.systemui.statusbar.NotificationUiAdjustment;
import com.android.systemui.statusbar.NotificationUpdateHandler;
import com.android.systemui.statusbar.notification.NotificationData.KeyguardEnvironment;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.notification.row.NotificationInflater;
import com.android.systemui.statusbar.notification.row.NotificationInflater.InflationFlag;
@@ -195,10 +194,6 @@
return mPresenter;
}
- public ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
- return getRowBinder().getNotificationLongClicker();
- }
-
@Override
public void onReorderingAllowed() {
updateNotifications();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
index b241b8a..0bde99b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification;
import static com.android.internal.util.Preconditions.checkNotNull;
+import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT;
import static com.android.systemui.statusbar.notification.row.NotificationInflater.FLAG_CONTENT_VIEW_AMBIENT;
import static com.android.systemui.statusbar.notification.row.NotificationInflater.FLAG_CONTENT_VIEW_HEADS_UP;
@@ -51,6 +52,7 @@
import com.android.systemui.statusbar.policy.HeadsUpManager;
import javax.inject.Inject;
+import javax.inject.Named;
import javax.inject.Singleton;
/** Handles inflating and updating views for notifications. */
@@ -72,6 +74,7 @@
private final NotificationMessagingUtil mMessagingUtil;
private final ExpandableNotificationRow.ExpansionLogger mExpansionLogger =
this::logNotificationExpansion;
+ private final boolean mAllowLongPress;
private NotificationRemoteInputManager mRemoteInputManager;
private NotificationPresenter mPresenter;
@@ -83,9 +86,11 @@
private NotificationClicker mNotificationClicker;
@Inject
- public NotificationRowBinder(Context context) {
+ public NotificationRowBinder(Context context,
+ @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress) {
mContext = context;
mMessagingUtil = new NotificationMessagingUtil(context);
+ mAllowLongPress = allowLongPress;
mBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService(Context.STATUS_BAR_SERVICE));
}
@@ -147,7 +152,9 @@
row.setHeadsUpManager(mHeadsUpManager);
row.setOnExpandClickListener(mPresenter);
row.setInflationCallback(mInflationCallback);
- row.setLongPressListener(getNotificationLongClicker());
+ if (mAllowLongPress) {
+ row.setLongPressListener(mGutsManager::openGuts);
+ }
mListContainer.bindRow(row);
getRemoteInputManager().bindRow(row);
@@ -260,10 +267,6 @@
row.inflateViews();
}
- ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
- return mGutsManager::openGuts;
- }
-
private void logNotificationExpansion(String key, boolean userAction, boolean expanded) {
mUiOffloadThread.submit(() -> {
try {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
index f982ecf..8deb7d5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@@ -16,9 +16,11 @@
package com.android.systemui.statusbar.notification.stack;
+import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters;
import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_SWIPE;
import static com.android.systemui.statusbar.phone.NotificationIconAreaController.LOW_PRIORITY;
+import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -136,6 +138,9 @@
import java.util.List;
import java.util.function.BiConsumer;
+import javax.inject.Inject;
+import javax.inject.Named;
+
/**
* A layout which handles a dynamic amount of notifications and presents them in a scrollable stack.
*/
@@ -165,6 +170,7 @@
private final Paint mBackgroundPaint = new Paint();
private final boolean mShouldDrawNotificationBackground;
private boolean mLowPriorityBeforeSpeedBump;
+ private final boolean mAllowLongPress;
private float mExpandedHeight;
private int mOwnScrollY;
@@ -452,27 +458,16 @@
private final NotificationGutsManager
mNotificationGutsManager = Dependency.get(NotificationGutsManager.class);
- @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
- public NotificationStackScrollLayout(Context context) {
- this(context, null);
- }
-
- @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
- public NotificationStackScrollLayout(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
- public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr) {
- this(context, attrs, defStyleAttr, 0);
- }
-
- @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
- public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr,
- int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
+ @Inject
+ public NotificationStackScrollLayout(
+ @Named(VIEW_CONTEXT) Context context,
+ AttributeSet attrs,
+ @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress) {
+ super(context, attrs, 0, 0);
Resources res = getResources();
+ mAllowLongPress = allowLongPress;
+
for (int i = 0; i < NUM_SECTIONS; i++) {
mSections[i] = new NotificationSection(this);
}
@@ -532,7 +527,9 @@
inflateEmptyShadeView();
inflateFooterView();
mVisualStabilityManager.setVisibilityLocationProvider(this::isInVisibleLocation);
- setLongPressListener(mEntryManager.getNotificationLongClicker());
+ if (mAllowLongPress) {
+ setLongPressListener(mGutsManager::openGuts);
+ }
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java b/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
index 59aa522..faebf60 100644
--- a/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
+++ b/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
@@ -26,6 +26,7 @@
import com.android.systemui.SystemUIFactory;
import com.android.systemui.qs.QSFooterImpl;
import com.android.systemui.qs.QuickStatusBarHeader;
+import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -112,6 +113,11 @@
* Creates the QSFooterImpl.
*/
QSFooterImpl createQsFooter();
+
+ /**
+ * Creates the NotificationStackScrollLayout.
+ */
+ NotificationStackScrollLayout createNotificationStackScrollLayout();
}
/**
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java
index b8c7ee0..06be5f6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java
@@ -135,7 +135,8 @@
NotificationShelf notificationShelf = mock(NotificationShelf.class);
- mStackScroller = spy(new NotificationStackScrollLayout(getContext()));
+ mStackScroller = spy(new NotificationStackScrollLayout(getContext(), null,
+ true /* allowLongPress */));
mStackScroller.setShelf(notificationShelf);
mStackScroller.setStatusBar(mBar);
mStackScroller.setScrimController(mock(ScrimController.class));