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

Commit 52cba2b7 authored by András Kurucz's avatar András Kurucz
Browse files

Remove NotificationLogger

This class has been replaced by NotificationStatsLogger after the
rollout of the NotificationsLiveDataStoreRefactor flag.

Bug: 424001722
Test: smoke test the new NotificationLogger
Flag: EXEMPT mechanical refactor
Change-Id: If3fa21af718e2457b8a377ae7af47128fec2498e
parent 7dc31e36
Loading
Loading
Loading
Loading
+0 −190
Original line number Diff line number Diff line
/**
 * 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.statusbar.notification.logging;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.os.RemoteException;
import android.testing.TestableLooper;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.time.FakeSystemClock;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.util.Collections;

@SmallTest
@RunWith(AndroidJUnit4.class)
@TestableLooper.RunWithLooper
public class ExpansionStateLoggerTest extends SysuiTestCase {
    private static final String NOTIFICATION_KEY = "notin_key";

    private NotificationLogger.ExpansionStateLogger mLogger;
    @Mock
    private IStatusBarService mBarService;
    private FakeExecutor mUiBgExecutor = new FakeExecutor(new FakeSystemClock());

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mLogger = new NotificationLogger.ExpansionStateLogger(mUiBgExecutor);
        mLogger.mBarService = mBarService;
    }

    @Test
    public void testVisible() throws RemoteException {
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        mUiBgExecutor.runAllReady();

        verify(mBarService, Mockito.never()).onNotificationExpansionChanged(
                eq(NOTIFICATION_KEY), anyBoolean(), anyBoolean(), anyInt());
    }

    @Test
    public void testExpanded() throws RemoteException {
        mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
        mUiBgExecutor.runAllReady();

        verify(mBarService, Mockito.never()).onNotificationExpansionChanged(
                eq(NOTIFICATION_KEY), anyBoolean(), anyBoolean(), anyInt());
    }

    @Test
    public void testVisibleAndNotExpanded() throws RemoteException {
        mLogger.onExpansionChanged(NOTIFICATION_KEY, true, false,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        mUiBgExecutor.runAllReady();

        verify(mBarService, Mockito.never()).onNotificationExpansionChanged(
                eq(NOTIFICATION_KEY), anyBoolean(), anyBoolean(), anyInt());
    }

    @Test
    public void testVisibleAndExpanded() throws RemoteException {
        mLogger.onExpansionChanged(NOTIFICATION_KEY, true, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        mUiBgExecutor.runAllReady();

        verify(mBarService).onNotificationExpansionChanged(
                NOTIFICATION_KEY, true, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN.toMetricsEventEnum());
    }

    @Test
    public void testExpandedAndVisible_expandedBeforeVisible() throws RemoteException {
        mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true,
                    NotificationVisibility.NotificationLocation.LOCATION_MAIN_AREA)),
                Collections.emptyList());
        mUiBgExecutor.runAllReady();

        verify(mBarService).onNotificationExpansionChanged(
                NOTIFICATION_KEY, false, true,
                // The last location seen should be logged (the one passed to onVisibilityChanged).
                NotificationVisibility.NotificationLocation.LOCATION_MAIN_AREA.toMetricsEventEnum()
        );
    }

    @Test
    public void testExpandedAndVisible_visibleBeforeExpanded() throws RemoteException {
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
                NotificationVisibility.NotificationLocation.LOCATION_FIRST_HEADS_UP);
        mUiBgExecutor.runAllReady();

        verify(mBarService).onNotificationExpansionChanged(
                NOTIFICATION_KEY, false, true,
                // The last location seen should be logged (the one passed to onExpansionChanged).
                NotificationVisibility.NotificationLocation.LOCATION_FIRST_HEADS_UP.toMetricsEventEnum());
    }

    @Test
    public void testExpandedAndVisible_logOnceOnly() throws RemoteException {
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
        mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
        mUiBgExecutor.runAllReady();

        verify(mBarService).onNotificationExpansionChanged(
                NOTIFICATION_KEY, false, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN.toMetricsEventEnum());
    }

    @Test
    public void testOnEntryUpdated() throws RemoteException {
        mLogger.onExpansionChanged(NOTIFICATION_KEY, true, true,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        mUiBgExecutor.runAllReady();
        verify(mBarService).onNotificationExpansionChanged(
                NOTIFICATION_KEY, true, true, ExpandableViewState.LOCATION_UNKNOWN);

        mLogger.onEntryUpdated(NOTIFICATION_KEY);
        mLogger.onVisibilityChanged(
                Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
                Collections.emptyList());
        mUiBgExecutor.runAllReady();
        // onNotificationExpansionChanged is called the second time.
        verify(mBarService, times(2)).onNotificationExpansionChanged(
                NOTIFICATION_KEY, true, true, ExpandableViewState.LOCATION_UNKNOWN);
    }

    private NotificationVisibility createNotificationVisibility(String key, boolean visibility) {
        return createNotificationVisibility(key, visibility,
                NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
    }

    private NotificationVisibility createNotificationVisibility(String key, boolean visibility,
            NotificationVisibility.NotificationLocation location) {
        return NotificationVisibility.obtain(key, 0, 0, visibility, location);
    }
}
+0 −66
Original line number Diff line number Diff line
/*
 * 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.statusbar.notification.logging;

import com.android.systemui.statusbar.notification.collection.EntryAdapter;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.logging.nano.Notifications;

import java.util.ArrayList;
import java.util.List;

public class NotificationPanelLoggerFake implements NotificationPanelLogger {
    private List<CallRecord> mCalls = new ArrayList<>();

    List<CallRecord> getCalls() {
        return mCalls;
    }

    CallRecord get(int index) {
        return mCalls.get(index);
    }

    @Override
    public void logPanelShown(boolean isLockscreen, Notifications.NotificationList proto) {
        mCalls.add(new CallRecord(isLockscreen, proto));
    }

    @Override
    public void logPanelShown(boolean isLockscreen,
            List<NotificationEntry> visibleNotifications) {
        mCalls.add(new CallRecord(isLockscreen,
                NotificationPanelLogger.toNotificationProto(visibleNotifications)));
    }

    @Override
    public void logNotificationDrag(NotificationEntry draggedNotification) {
    }

    @Override
    public void logNotificationDrag(EntryAdapter draggedNotification) {

    }

    public static class CallRecord {
        public boolean isLockscreen;
        public Notifications.NotificationList list;
        CallRecord(boolean isLockscreen, Notifications.NotificationList list) {
            this.isLockscreen = isLockscreen;
            this.list = list;
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -63,9 +63,9 @@ import com.android.systemui.statusbar.notification.collection.EntryAdapter;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntry.EditedSuggestionInfo;
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi;
import com.android.systemui.statusbar.notification.stack.shared.NotificationLocationHelperKt;
import com.android.systemui.statusbar.phone.ExpandHeadsUpOnInlineReply;
import com.android.systemui.statusbar.policy.RemoteInputUriController;
import com.android.systemui.statusbar.policy.RemoteInputView;
@@ -371,7 +371,7 @@ public class NotificationRemoteInputManager implements CoreStartable {
                                entry.getSbn().getKey(),
                                entry.editedSuggestionInfo.index,
                                entry.editedSuggestionInfo.originalText,
                                NotificationLogger
                                NotificationLocationHelperKt
                                        .getNotificationLocation(entry)
                                        .toMetricsEventEnum(),
                                modifiedBeforeSending);
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ enum class StatusBarMode {
    /**
     * A mode where notification icons in the status bar are hidden and replaced by a dot (this mode
     * can be requested by apps).
     *
     * @see [com.android.systemui.statusbar.phone.domain.interactor.LightsOutInteractor].
     */
    LIGHTS_OUT,
+3 −3
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.notification.logging.NotificationLogger
import com.android.systemui.statusbar.notification.stack.shared.getNotificationLocation
import javax.inject.Inject

/** pipeline-agnostic implementation for getting [NotificationVisibility]. */
@@ -40,7 +40,7 @@ constructor(
        val count: Int = getCount()
        val rank = entry.ranking.rank
        val hasRow = entry.row != null
        val location = NotificationLogger.getNotificationLocation(entry)
        val location = getNotificationLocation(entry)
        return NotificationVisibility.obtain(entry.key, rank, count, visible && hasRow, location)
    }

@@ -50,7 +50,7 @@ constructor(
        } ?: NotificationVisibility.obtain(key, -1, getCount(), false)

    override fun getLocation(key: String): NotificationVisibility.NotificationLocation =
        NotificationLogger.getNotificationLocation(notifCollection.getEntry(key))
        getNotificationLocation(notifCollection.getEntry(key))

    private fun getCount() = activeNotificationsInteractor.allNotificationsCountValue
}
Loading