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

Commit f892fe95 authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Add NotificationVisibility.NotificationLocation.

To represent the UI location of a Notification we add the class enum
NotificationVisibility.NotificationLocation.

Bug: 120767764
Test: atest SystemUITests
Change-Id: I572c1cb7e585158f29675afd5255898e7f78e820
parent a9b062d0
Loading
Loading
Loading
Loading
+54 −5
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

import java.util.ArrayDeque;
import java.util.Collection;

@@ -33,18 +35,53 @@ public class NotificationVisibility implements Parcelable {
    public int rank;
    public int count;
    public boolean visible = true;
    /** The visible location of the notification, could be e.g. notification shade or HUN. */
    public NotificationLocation location;
    /*package*/ int id;

    /**
     * The UI location of the notification.
     *
     * There is a one-to-one mapping between this enum and
     * MetricsProto.MetricsEvent.NotificationLocation.
     */
    public enum NotificationLocation {
        LOCATION_UNKNOWN(MetricsEvent.LOCATION_UNKNOWN),
        LOCATION_FIRST_HEADS_UP(MetricsEvent.LOCATION_FIRST_HEADS_UP), // visible heads-up
        LOCATION_HIDDEN_TOP(MetricsEvent.LOCATION_HIDDEN_TOP), // hidden/scrolled away on the top
        LOCATION_MAIN_AREA(MetricsEvent.LOCATION_MAIN_AREA), // visible in the shade
        // in the bottom stack, and peeking
        LOCATION_BOTTOM_STACK_PEEKING(MetricsEvent.LOCATION_BOTTOM_STACK_PEEKING),
        // in the bottom stack, and hidden
        LOCATION_BOTTOM_STACK_HIDDEN(MetricsEvent.LOCATION_BOTTOM_STACK_HIDDEN),
        LOCATION_GONE(MetricsEvent.LOCATION_GONE); // the view isn't laid out at all

        private final int mMetricsEventNotificationLocation;

        NotificationLocation(int metricsEventNotificationLocation) {
            mMetricsEventNotificationLocation = metricsEventNotificationLocation;
        }

        /**
         * Returns the field from MetricsEvent.NotificationLocation that corresponds to this object.
         */
        public int toMetricsEventEnum() {
            return mMetricsEventNotificationLocation;
        }
    }

    private NotificationVisibility() {
        id = sNexrId++;
    }

    private NotificationVisibility(String key, int rank, int count, boolean visibile) {
    private NotificationVisibility(String key, int rank, int count, boolean visible,
            NotificationLocation location) {
        this();
        this.key = key;
        this.rank = rank;
        this.count = count;
        this.visible = visibile;
        this.visible = visible;
        this.location = location;
    }

    @Override
@@ -54,12 +91,13 @@ public class NotificationVisibility implements Parcelable {
                + " rank=" + rank
                + " count=" + count
                + (visible?" visible":"")
                + " location=" + location.name()
                + " )";
    }

    @Override
    public NotificationVisibility clone() {
        return obtain(this.key, this.rank, this.count, this.visible);
        return obtain(this.key, this.rank, this.count, this.visible, this.location);
    }

    @Override
@@ -89,6 +127,7 @@ public class NotificationVisibility implements Parcelable {
        out.writeInt(this.rank);
        out.writeInt(this.count);
        out.writeInt(this.visible ? 1 : 0);
        out.writeString(this.location.name());
    }

    private void readFromParcel(Parcel in) {
@@ -96,18 +135,28 @@ public class NotificationVisibility implements Parcelable {
        this.rank = in.readInt();
        this.count = in.readInt();
        this.visible = in.readInt() != 0;
        this.location = NotificationLocation.valueOf(in.readString());
    }

    /**
     * Return a new NotificationVisibility instance from the global pool. Allows us to
     * avoid allocating new objects in many cases.
     * Create a new NotificationVisibility object.
     */
    public static NotificationVisibility obtain(String key, int rank, int count, boolean visible) {
        return obtain(key, rank, count, visible,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
    }

    /**
     * Create a new NotificationVisibility object.
     */
    public static NotificationVisibility obtain(String key, int rank, int count, boolean visible,
            NotificationLocation location) {
        NotificationVisibility vo = obtain();
        vo.key = key;
        vo.rank = rank;
        vo.count = count;
        vo.visible = visible;
        vo.location = location;
        return vo;
    }

+45 −0
Original line number Diff line number Diff line
/*
 * 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.internal.statusbar;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.lang.reflect.Field;

@RunWith(AndroidJUnit4.class)
@SmallTest
public final class NotificationVisibilityTest {

    @Test
    public void testNotificationLocation_sameValuesAsMetricsProto() throws Exception {
        for (NotificationVisibility.NotificationLocation location :
                NotificationVisibility.NotificationLocation.values()) {
            Field locationField = MetricsEvent.class.getField(location.name());
            int metricsValue = locationField.getInt(null);
            assertThat(metricsValue, is(location.toMetricsEventEnum()));
        }
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.systemui.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.KeyguardMonitor;

@@ -130,8 +131,11 @@ public class NotificationLockscreenUserManagerImpl implements
                    final int count =
                            getEntryManager().getNotificationData().getActiveNotifications().size();
                    final int rank = getEntryManager().getNotificationData().getRank(notificationKey);
                    NotificationVisibility.NotificationLocation location =
                            NotificationLogger.getNotificationLocation(
                                    getEntryManager().getNotificationData().get(notificationKey));
                    final NotificationVisibility nv = NotificationVisibility.obtain(notificationKey,
                            rank, count, true);
                            rank, count, true, location);
                    try {
                        mBarService.onNotificationClick(notificationKey, nv);
                    } catch (RemoteException e) {
+6 −1
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import com.android.systemui.Dumpable;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.policy.RemoteInputView;
@@ -181,7 +182,11 @@ public class NotificationRemoteInputManager implements Dumpable {
            final int rank = mEntryManager.getNotificationData().getRank(key);
            final Notification.Action action =
                    statusBarNotification.getNotification().actions[actionIndex];
            final NotificationVisibility nv = NotificationVisibility.obtain(key, rank, count, true);
            NotificationVisibility.NotificationLocation location =
                    NotificationLogger.getNotificationLocation(
                            mEntryManager.getNotificationData().get(key));
            final NotificationVisibility nv =
                    NotificationVisibility.obtain(key, rank, count, true, location);
            try {
                mBarService.onNotificationActionClick(key, buttonIndex, action, nv, false);
            } catch (RemoteException e) {
+5 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;

import java.util.Set;

@@ -74,8 +75,10 @@ public class SmartReplyController {
            boolean generatedByAssistant) {
        final int count = mEntryManager.getNotificationData().getActiveNotifications().size();
        final int rank = mEntryManager.getNotificationData().getRank(entry.key);
        final NotificationVisibility nv =
                NotificationVisibility.obtain(entry.key, rank, count, true);
        NotificationVisibility.NotificationLocation location =
                NotificationLogger.getNotificationLocation(entry);
        final NotificationVisibility nv = NotificationVisibility.obtain(
                entry.key, rank, count, true, location);
        try {
            mBarService.onNotificationActionClick(
                    entry.key, actionIndex, action, nv, generatedByAssistant);
Loading