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

Commit f99f3253 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Clean up HeadsUpViewBinder logs

Bug: 198359689
Test: log inspection; hun unbind log now gone
Change-Id: I8bdf48590edf436afe8ce4145ed2549a87d81505
parent d0e75eb2
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -85,6 +85,10 @@ public class HeadsUpViewBinder {
        CancellationSignal signal = mStage.requestRebind(entry, en -> {
            mLogger.entryBoundSuccessfully(entry.getKey());
            en.getRow().setUsesIncreasedHeadsUpHeight(params.useIncreasedHeadsUpHeight());
            // requestRebing promises that if we called cancel before this callback would be
            // invoked, then we will not enter this callback, and because we always cancel before
            // adding to this map, we know this will remove the correct signal.
            mOngoingBindCallbacks.remove(entry);
            if (callback != null) {
                callback.onBindFinished(en);
            }
+73 −9
Original line number Diff line number Diff line
@@ -18,8 +18,9 @@ package com.android.systemui.statusbar.notification.interruption;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.testing.AndroidTestingRunner;
@@ -63,7 +64,7 @@ public class HeadsUpViewBinderTest extends SysuiTestCase {
    }

    @Test
    public void testLoggingWorks() {
    public void testLoggingForStandardFlow() {
        AtomicReference<NotifBindPipeline.BindCallback> callback = new AtomicReference<>();
        when(mBindStage.requestRebind(any(), any())).then(i -> {
            callback.set(i.getArgument(1));
@@ -71,19 +72,82 @@ public class HeadsUpViewBinderTest extends SysuiTestCase {
        });

        mViewBinder.bindHeadsUpView(mEntry, null);
        verify(mLogger, times(1)).startBindingHun(eq("key"));
        verify(mLogger, times(0)).entryBoundSuccessfully(eq("key"));
        verify(mLogger, times(0)).currentOngoingBindingAborted(eq("key"));
        verify(mLogger).startBindingHun(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        callback.get().onBindFinished(mEntry);
        verify(mLogger).entryBoundSuccessfully(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        verify(mLogger, times(1)).entryBoundSuccessfully(eq("key"));
        mViewBinder.bindHeadsUpView(mEntry, null);
        verify(mLogger).startBindingHun(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        callback.get().onBindFinished(mEntry);
        verify(mLogger).entryBoundSuccessfully(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        verify(mLogger, times(2)).startBindingHun(eq("key"));
        verify(mLogger, times(2)).entryBoundSuccessfully(eq("key"));
        verify(mLogger, times(1)).currentOngoingBindingAborted(eq("key"));
        mViewBinder.unbindHeadsUpView(mEntry);
        verify(mLogger).entryContentViewMarkedFreeable(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        callback.get().onBindFinished(mEntry);
        verify(mLogger).entryUnbound(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);
    }

    @Test
    public void testLoggingForAbortFlow() {
        AtomicReference<NotifBindPipeline.BindCallback> callback = new AtomicReference<>();
        when(mBindStage.requestRebind(any(), any())).then(i -> {
            callback.set(i.getArgument(1));
            return new CancellationSignal();
        });

        mViewBinder.bindHeadsUpView(mEntry, null);
        verify(mLogger).startBindingHun(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        mViewBinder.abortBindCallback(mEntry);
        verify(mLogger).currentOngoingBindingAborted(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        // second abort logs nothing
        mViewBinder.abortBindCallback(mEntry);
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);
    }

    @Test
    public void testLoggingForEarlyUnbindFlow() {
        AtomicReference<NotifBindPipeline.BindCallback> callback = new AtomicReference<>();
        when(mBindStage.requestRebind(any(), any())).then(i -> {
            callback.set(i.getArgument(1));
            return new CancellationSignal();
        });

        mViewBinder.bindHeadsUpView(mEntry, null);
        verify(mLogger).startBindingHun(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        mViewBinder.unbindHeadsUpView(mEntry);
        verify(mLogger).currentOngoingBindingAborted(eq("key"));
        verify(mLogger).entryContentViewMarkedFreeable(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);

        callback.get().onBindFinished(mEntry);
        verify(mLogger).entryUnbound(eq("key"));
        verifyNoMoreInteractions(mLogger);
        clearInvocations(mLogger);
    }
}