diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinder.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinder.java index ffec3671995f3..27610b9a2d90b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinder.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinder.java @@ -50,15 +50,17 @@ public class HeadsUpViewBinder { private final NotificationMessagingUtil mNotificationMessagingUtil; private final Map 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())); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderLogger.kt new file mode 100644 index 0000000000000..06651f2c1b4ce --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderLogger.kt @@ -0,0 +1,49 @@ +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 diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderTest.java new file mode 100644 index 0000000000000..7b10f5a090ec0 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinderTest.java @@ -0,0 +1,89 @@ +/* + * 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 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")); + } +}