summaryrefslogtreecommitdiff
path: root/packages/CarSystemUI/src
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-06-19 22:41:19 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-06-19 22:41:19 +0000
commit4eaf0a6694febdf6ef6b4c4f7a809f8389fb5338 (patch)
tree273f89f6d0ff011a5e3d7f29055902a1b5489e7a /packages/CarSystemUI/src
parentb9f003b04fcde502b88b8de8a8ea5e2980ffe212 (diff)
parent489dd7154c0f62fb09eac01173efa0817ad6eb37 (diff)
Merge "Updated NotificationPanelViewController to listen to animateExpandNotificationsPanel and animateCollapsePanels." into rvc-dev am: 489dd7154c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11921452 Change-Id: I566bb0ca427d78aed9bc0f6b1783fe3f2d420fb7
Diffstat (limited to 'packages/CarSystemUI/src')
-rw-r--r--packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java71
-rw-r--r--packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationVisibilityLogger.java150
2 files changed, 220 insertions, 1 deletions
diff --git a/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java b/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java
index 1738091d14c9..1eead62c042a 100644
--- a/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java
+++ b/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java
@@ -48,17 +48,21 @@ import com.android.systemui.car.CarServiceProvider;
import com.android.systemui.car.window.OverlayPanelViewController;
import com.android.systemui.car.window.OverlayViewGlobalStateController;
import com.android.systemui.dagger.qualifiers.Main;
+import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.statusbar.StatusBarState;
+import java.util.concurrent.Executor;
+
import javax.inject.Inject;
import javax.inject.Singleton;
/** View controller for the notification panel. */
@Singleton
-public class NotificationPanelViewController extends OverlayPanelViewController {
+public class NotificationPanelViewController extends OverlayPanelViewController
+ implements CommandQueue.Callbacks {
private static final boolean DEBUG = true;
private static final String TAG = "NotificationPanelViewController";
@@ -68,12 +72,14 @@ public class NotificationPanelViewController extends OverlayPanelViewController
private final CarServiceProvider mCarServiceProvider;
private final IStatusBarService mBarService;
private final CommandQueue mCommandQueue;
+ private final Executor mUiBgExecutor;
private final NotificationDataManager mNotificationDataManager;
private final CarUxRestrictionManagerWrapper mCarUxRestrictionManagerWrapper;
private final CarNotificationListener mCarNotificationListener;
private final NotificationClickHandlerFactory mNotificationClickHandlerFactory;
private final StatusBarStateController mStatusBarStateController;
private final boolean mEnableHeadsUpNotificationWhenNotificationShadeOpen;
+ private final NotificationVisibilityLogger mNotificationVisibilityLogger;
private float mInitialBackgroundAlpha;
private float mBackgroundAlphaDiff;
@@ -98,6 +104,7 @@ public class NotificationPanelViewController extends OverlayPanelViewController
@Main Resources resources,
OverlayViewGlobalStateController overlayViewGlobalStateController,
FlingAnimationUtils.Builder flingAnimationUtilsBuilder,
+ @UiBackground Executor uiBgExecutor,
/* Other things */
CarServiceProvider carServiceProvider,
@@ -110,6 +117,7 @@ public class NotificationPanelViewController extends OverlayPanelViewController
CarUxRestrictionManagerWrapper carUxRestrictionManagerWrapper,
CarNotificationListener carNotificationListener,
NotificationClickHandlerFactory notificationClickHandlerFactory,
+ NotificationVisibilityLogger notificationVisibilityLogger,
/* Things that need to be replaced */
StatusBarStateController statusBarStateController
@@ -121,12 +129,15 @@ public class NotificationPanelViewController extends OverlayPanelViewController
mCarServiceProvider = carServiceProvider;
mBarService = barService;
mCommandQueue = commandQueue;
+ mUiBgExecutor = uiBgExecutor;
mNotificationDataManager = notificationDataManager;
mCarUxRestrictionManagerWrapper = carUxRestrictionManagerWrapper;
mCarNotificationListener = carNotificationListener;
mNotificationClickHandlerFactory = notificationClickHandlerFactory;
mStatusBarStateController = statusBarStateController;
+ mNotificationVisibilityLogger = notificationVisibilityLogger;
+ mCommandQueue.addCallback(this);
// Notification background setup.
mInitialBackgroundAlpha = (float) mResources.getInteger(
R.integer.config_initialNotificationBackgroundAlpha) / 100;
@@ -151,12 +162,36 @@ public class NotificationPanelViewController extends OverlayPanelViewController
.config_enableHeadsUpNotificationWhenNotificationShadeOpen);
}
+ // CommandQueue.Callbacks
+
+ @Override
+ public void animateExpandNotificationsPanel() {
+ if (!isPanelExpanded()) {
+ toggle();
+ }
+ }
+
+ @Override
+ public void animateCollapsePanels(int flags, boolean force) {
+ if (isPanelExpanded()) {
+ toggle();
+ }
+ }
+
+ // OverlayViewController
+
@Override
protected void onFinishInflate() {
reinflate();
}
@Override
+ protected void hideInternal() {
+ super.hideInternal();
+ mNotificationVisibilityLogger.stop();
+ }
+
+ @Override
protected boolean shouldShowNavigationBar() {
return true;
}
@@ -197,6 +232,11 @@ public class NotificationPanelViewController extends OverlayPanelViewController
mUnseenCountUpdateListener.onUnseenCountUpdate(
mNotificationDataManager.getUnseenNotificationCount());
}
+ mCarNotificationListener.setNotificationsShown(
+ mNotificationDataManager.getSeenNotifications());
+ // This logs both when the notification panel is expanded and when the notification
+ // panel is scrolled.
+ mNotificationVisibilityLogger.log(isPanelExpanded());
});
mNotificationClickHandlerFactory.setNotificationDataManager(mNotificationDataManager);
@@ -332,6 +372,8 @@ public class NotificationPanelViewController extends OverlayPanelViewController
mNotificationDataManager.clearAll();
}
+ // OverlayPanelViewController
+
@Override
protected boolean shouldAnimateCollapsePanel() {
return true;
@@ -364,6 +406,30 @@ public class NotificationPanelViewController extends OverlayPanelViewController
}
@Override
+ protected void onPanelVisible(boolean visible) {
+ super.onPanelVisible(visible);
+ mUiBgExecutor.execute(() -> {
+ try {
+ if (visible) {
+ // When notification panel is open even just a bit, we want to clear
+ // notification effects.
+ boolean clearNotificationEffects =
+ mStatusBarStateController.getState() != StatusBarState.KEYGUARD;
+ mBarService.onPanelRevealed(clearNotificationEffects,
+ mNotificationDataManager.getVisibleNotifications().size());
+ } else {
+ mBarService.onPanelHidden();
+ }
+ } catch (RemoteException ex) {
+ // Won't fail unless the world has ended.
+ Log.e(TAG, String.format(
+ "Unable to notify StatusBarService of panel visibility: %s", visible));
+ }
+ });
+
+ }
+
+ @Override
protected void onPanelExpanded(boolean expand) {
super.onPanelExpanded(expand);
@@ -373,6 +439,9 @@ public class NotificationPanelViewController extends OverlayPanelViewController
}
clearNotificationEffects();
}
+ if (!expand) {
+ mNotificationVisibilityLogger.log(isPanelExpanded());
+ }
}
/**
diff --git a/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationVisibilityLogger.java b/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationVisibilityLogger.java
new file mode 100644
index 000000000000..44c819711bd2
--- /dev/null
+++ b/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationVisibilityLogger.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2020 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.notification;
+
+import android.os.RemoteException;
+import android.util.ArraySet;
+import android.util.Log;
+
+import com.android.car.notification.AlertEntry;
+import com.android.car.notification.NotificationDataManager;
+import com.android.internal.statusbar.IStatusBarService;
+import com.android.internal.statusbar.NotificationVisibility;
+import com.android.systemui.dagger.qualifiers.UiBackground;
+
+import java.util.Set;
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+/**
+ * Handles notification logging, in particular, logging which notifications are visible and which
+ * are not.
+ */
+@Singleton
+public class NotificationVisibilityLogger {
+
+ private static final String TAG = "NotificationVisibilityLogger";
+
+ private final ArraySet<NotificationVisibility> mCurrentlyVisible = new ArraySet<>();
+ private final ArraySet<NotificationVisibility> mNewlyVisible = new ArraySet<>();
+ private final ArraySet<NotificationVisibility> mPreviouslyVisible = new ArraySet<>();
+ private final ArraySet<NotificationVisibility> mTmpCurrentlyVisible = new ArraySet<>();
+
+ private final IStatusBarService mBarService;
+ private final Executor mUiBgExecutor;
+ private final NotificationDataManager mNotificationDataManager;
+
+ private boolean mIsVisible;
+
+ private final Runnable mVisibilityReporter = new Runnable() {
+
+ @Override
+ public void run() {
+ if (mIsVisible) {
+ int count = mNotificationDataManager.getVisibleNotifications().size();
+ for (AlertEntry alertEntry : mNotificationDataManager.getVisibleNotifications()) {
+ NotificationVisibility visObj = NotificationVisibility.obtain(
+ alertEntry.getKey(),
+ /* rank= */ -1,
+ count,
+ mIsVisible,
+ NotificationVisibility.NotificationLocation.LOCATION_MAIN_AREA);
+ mTmpCurrentlyVisible.add(visObj);
+ if (!mCurrentlyVisible.contains(visObj)) {
+ mNewlyVisible.add(visObj);
+ }
+ }
+ }
+ mPreviouslyVisible.addAll(mCurrentlyVisible);
+ mPreviouslyVisible.removeAll(mTmpCurrentlyVisible);
+ onNotificationVisibilityChanged(mNewlyVisible, mPreviouslyVisible);
+
+ recycleAllVisibilityObjects(mCurrentlyVisible);
+ mCurrentlyVisible.addAll(mTmpCurrentlyVisible);
+
+ recycleAllVisibilityObjects(mPreviouslyVisible);
+ recycleAllVisibilityObjects(mNewlyVisible);
+ recycleAllVisibilityObjects(mTmpCurrentlyVisible);
+ }
+ };
+
+ @Inject
+ public NotificationVisibilityLogger(
+ @UiBackground Executor uiBgExecutor,
+ IStatusBarService barService,
+ NotificationDataManager notificationDataManager) {
+ mUiBgExecutor = uiBgExecutor;
+ mBarService = barService;
+ mNotificationDataManager = notificationDataManager;
+ }
+
+ /** Triggers a visibility report update to be sent to StatusBarService. */
+ public void log(boolean isVisible) {
+ mIsVisible = isVisible;
+ mUiBgExecutor.execute(mVisibilityReporter);
+ }
+
+ /** Stops logging, clearing all visibility objects. */
+ public void stop() {
+ recycleAllVisibilityObjects(mCurrentlyVisible);
+ }
+
+ /**
+ * Notify StatusBarService of change in notifications' visibility.
+ */
+ private void onNotificationVisibilityChanged(
+ Set<NotificationVisibility> newlyVisible, Set<NotificationVisibility> noLongerVisible) {
+ if (newlyVisible.isEmpty() && noLongerVisible.isEmpty()) {
+ return;
+ }
+
+ try {
+ mBarService.onNotificationVisibilityChanged(
+ cloneVisibilitiesAsArr(newlyVisible), cloneVisibilitiesAsArr(noLongerVisible));
+ } catch (RemoteException e) {
+ // Won't fail unless the world has ended.
+ Log.e(TAG, "Failed to notify StatusBarService of notification visibility change");
+ }
+ }
+
+ /**
+ * Clears array and recycles NotificationVisibility objects for reuse.
+ */
+ private static void recycleAllVisibilityObjects(ArraySet<NotificationVisibility> array) {
+ for (int i = 0; i < array.size(); i++) {
+ array.valueAt(i).recycle();
+ }
+ array.clear();
+ }
+
+ /**
+ * Converts Set of NotificationVisibility objects to primitive array.
+ */
+ private static NotificationVisibility[] cloneVisibilitiesAsArr(Set<NotificationVisibility> c) {
+ NotificationVisibility[] array = new NotificationVisibility[c.size()];
+ int i = 0;
+ for (NotificationVisibility nv : c) {
+ if (nv != null) {
+ array[i] = nv.clone();
+ }
+ i++;
+ }
+ return array;
+ }
+}