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

Commit f71a3a93 authored by Jay Aliomer's avatar Jay Aliomer Committed by Android (Google) Code Review
Browse files

Merge "add HUN logging to view binding"

parents c04ce54e 7e49455b
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -50,15 +50,17 @@ public class HeadsUpViewBinder {
    private final NotificationMessagingUtil mNotificationMessagingUtil;
    private final Map<NotificationEntry, CancellationSignal> mOngoingBindCallbacks =
            new ArrayMap<>();
    private final HeadsUpViewBinderLogger mLogger;

    private NotificationPresenter mNotificationPresenter;

    @Inject
    HeadsUpViewBinder(
            NotificationMessagingUtil notificationMessagingUtil,
            RowContentBindStage bindStage) {
            RowContentBindStage bindStage, HeadsUpViewBinderLogger logger) {
        mNotificationMessagingUtil = notificationMessagingUtil;
        mStage = bindStage;
        mLogger = logger;
    }

    /**
@@ -81,12 +83,14 @@ public class HeadsUpViewBinder {
        params.setUseIncreasedHeadsUpHeight(useIncreasedHeadsUp);
        params.requireContentViews(FLAG_CONTENT_VIEW_HEADS_UP);
        CancellationSignal signal = mStage.requestRebind(entry, en -> {
            mLogger.entryBoundSuccessfully(entry.getKey());
            en.getRow().setUsesIncreasedHeadsUpHeight(params.useIncreasedHeadsUpHeight());
            if (callback != null) {
                callback.onBindFinished(en);
            }
        });
        abortBindCallback(entry);
        mLogger.startBindingHun(entry.getKey());
        mOngoingBindCallbacks.put(entry, signal);
    }

@@ -97,6 +101,7 @@ public class HeadsUpViewBinder {
    public void abortBindCallback(NotificationEntry entry) {
        CancellationSignal ongoingBindCallback = mOngoingBindCallbacks.remove(entry);
        if (ongoingBindCallback != null) {
            mLogger.currentOngoingBindingAborted(entry.getKey());
            ongoingBindCallback.cancel();
        }
    }
@@ -107,6 +112,7 @@ public class HeadsUpViewBinder {
    public void unbindHeadsUpView(NotificationEntry entry) {
        abortBindCallback(entry);
        mStage.getStageParams(entry).markContentViewsFreeable(FLAG_CONTENT_VIEW_HEADS_UP);
        mStage.requestRebind(entry, null);
        mLogger.entryContentViewMarkedFreeable(entry.getKey());
        mStage.requestRebind(entry, e -> mLogger.entryUnbound(e.getKey()));
    }
}
+49 −0
Original line number Diff line number Diff line
package com.android.systemui.statusbar.notification.interruption

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel.INFO
import com.android.systemui.log.dagger.NotificationHeadsUpLog
import javax.inject.Inject

class HeadsUpViewBinderLogger @Inject constructor(@NotificationHeadsUpLog val buffer: LogBuffer) {
    fun startBindingHun(key: String) {
        buffer.log(TAG, INFO, {
            str1 = key
        }, {
            "start binding heads up entry $str1 "
        })
    }

    fun currentOngoingBindingAborted(key: String) {
        buffer.log(TAG, INFO, {
            str1 = key
        }, {
            "aborted potential ongoing heads up entry binding $str1 "
        })
    }

    fun entryBoundSuccessfully(key: String) {
        buffer.log(TAG, INFO, {
            str1 = key
        }, {
            "heads up entry bound successfully $str1 "
        })
    }

    fun entryUnbound(key: String) {
        buffer.log(TAG, INFO, {
            str1 = key
        }, {
            "heads up entry unbound successfully $str1 "
        })
    }

    fun entryContentViewMarkedFreeable(key: String) {
        buffer.log(TAG, INFO, {
            str1 = key
        }, {
            "start unbinding heads up entry $str1 "
        })
    }
}
const val TAG = "HeadsUpViewBinder"
 No newline at end of file
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.interruption;

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

import android.testing.AndroidTestingRunner;

import androidx.core.os.CancellationSignal;
import androidx.test.filters.SmallTest;

import com.android.internal.util.NotificationMessagingUtil;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.NotifBindPipeline;
import com.android.systemui.statusbar.notification.row.RowContentBindParams;
import com.android.systemui.statusbar.notification.row.RowContentBindStage;

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

import java.util.concurrent.atomic.AtomicReference;

@RunWith(AndroidTestingRunner.class)
@SmallTest
public class HeadsUpViewBinderTest extends SysuiTestCase {
    private HeadsUpViewBinder mViewBinder;
    @Mock private NotificationMessagingUtil mNotificationMessagingUtil;
    @Mock private RowContentBindStage mBindStage;
    @Mock private HeadsUpViewBinderLogger mLogger;
    @Mock private NotificationEntry mEntry;
    @Mock private ExpandableNotificationRow mRow;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mViewBinder = new HeadsUpViewBinder(mNotificationMessagingUtil, mBindStage, mLogger);
        when(mEntry.getKey()).thenReturn("key");
        when(mEntry.getRow()).thenReturn(mRow);
        when(mBindStage.getStageParams(eq(mEntry))).thenReturn(new RowContentBindParams());
    }

    @Test
    public void testLoggingWorks() {
        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, times(1)).startBindingHun(eq("key"));
        verify(mLogger, times(0)).entryBoundSuccessfully(eq("key"));
        verify(mLogger, times(0)).currentOngoingBindingAborted(eq("key"));

        callback.get().onBindFinished(mEntry);

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

        callback.get().onBindFinished(mEntry);

        verify(mLogger, times(2)).startBindingHun(eq("key"));
        verify(mLogger, times(2)).entryBoundSuccessfully(eq("key"));
        verify(mLogger, times(1)).currentOngoingBindingAborted(eq("key"));
    }
}