From 4b490fbc94fbf2fe4c7f981343b69a4cb5d1bfbe Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Mon, 24 Oct 2022 21:32:31 +0000 Subject: [PATCH] [Chipbar] Create a chipbar-specific logger and make some small updates to logging for both chipbar and temporary display. Bug: 245610654 Test: dumped ChipbarLog, MediaTttSender, and MediaTttReceiver and verify they have logs for events Test: atest TemporaryViewDisplayControllerTest Test: atest ChipbarCoordinatorTest Change-Id: I6bb3f8db8810b62a00f9336b6ea7a88d24f35409 --- .../systemui/dagger/SystemUIModule.java | 2 + .../TemporaryViewDisplayController.kt | 4 +- .../temporarydisplay/TemporaryViewLogger.kt | 10 ++-- .../chipbar/ChipbarCoordinator.kt | 20 +++++--- .../temporarydisplay/chipbar/ChipbarLogger.kt | 49 +++++++++++++++++++ .../temporarydisplay/dagger/ChipbarLog.kt | 25 ++++++++++ .../dagger/TemporaryDisplayModule.kt | 37 ++++++++++++++ .../sender/MediaTttSenderCoordinatorTest.kt | 4 +- .../TemporaryViewDisplayControllerTest.kt | 14 +++++- .../TemporaryViewLoggerTest.kt | 9 ++-- .../chipbar/ChipbarCoordinatorTest.kt | 28 ++++++++++- .../chipbar/FakeChipbarCoordinator.kt | 4 +- 12 files changed, 180 insertions(+), 26 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarLogger.kt create mode 100644 packages/SystemUI/src/com/android/systemui/temporarydisplay/dagger/ChipbarLog.kt create mode 100644 packages/SystemUI/src/com/android/systemui/temporarydisplay/dagger/TemporaryDisplayModule.kt diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 7e31626983e79..1b1b5b0a14f8e 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -83,6 +83,7 @@ import com.android.systemui.statusbar.policy.dagger.SmartRepliesInflationModule; import com.android.systemui.statusbar.policy.dagger.StatusBarPolicyModule; import com.android.systemui.statusbar.window.StatusBarWindowModule; import com.android.systemui.telephony.data.repository.TelephonyRepositoryModule; +import com.android.systemui.temporarydisplay.dagger.TemporaryDisplayModule; import com.android.systemui.tuner.dagger.TunerModule; import com.android.systemui.unfold.SysUIUnfoldModule; import com.android.systemui.user.UserModule; @@ -149,6 +150,7 @@ import dagger.Provides; SysUIConcurrencyModule.class, SysUIUnfoldModule.class, TelephonyRepositoryModule.class, + TemporaryDisplayModule.class, TunerModule.class, UserModule.class, UtilModule.class, diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt index a7ac8d48df79c..633a98523dc5d 100644 --- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt +++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt @@ -121,7 +121,7 @@ abstract class TemporaryViewDisplayController( +) : TemporaryViewDisplayController( context, logger, windowManager, @@ -103,7 +98,16 @@ open class ChipbarCoordinator @Inject constructor( newInfo: ChipbarInfo, currentView: ViewGroup ) { - // TODO(b/245610654): Adding logging here. + logger.logViewUpdate( + newInfo.windowTitle, + newInfo.text.loadText(context), + when (newInfo.endItem) { + null -> "null" + is ChipbarEndItem.Loading -> "loading" + is ChipbarEndItem.Error -> "error" + is ChipbarEndItem.Button -> "button(${newInfo.endItem.text.loadText(context)})" + } + ) // Detect falsing touches on the chip. parent = currentView.requireViewById(R.id.chipbar_root_view) diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarLogger.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarLogger.kt new file mode 100644 index 0000000000000..e477cd68673ab --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarLogger.kt @@ -0,0 +1,49 @@ +/* + * 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.temporarydisplay.chipbar + +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.plugins.log.LogBuffer +import com.android.systemui.plugins.log.LogLevel +import com.android.systemui.temporarydisplay.TemporaryViewLogger +import com.android.systemui.temporarydisplay.dagger.ChipbarLog +import javax.inject.Inject + +/** A logger for the chipbar. */ +@SysUISingleton +class ChipbarLogger +@Inject +constructor( + @ChipbarLog buffer: LogBuffer, +) : TemporaryViewLogger(buffer, "ChipbarLog") { + /** + * Logs that the chipbar was updated to display in a window named [windowTitle], with [text] and + * [endItemDesc]. + */ + fun logViewUpdate(windowTitle: String, text: String?, endItemDesc: String) { + buffer.log( + tag, + LogLevel.DEBUG, + { + str1 = windowTitle + str2 = text + str3 = endItemDesc + }, + { "Chipbar updated. window=$str1 text=$str2 endItem=$str3" } + ) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/dagger/ChipbarLog.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/dagger/ChipbarLog.kt new file mode 100644 index 0000000000000..5f101f2f388d0 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/dagger/ChipbarLog.kt @@ -0,0 +1,25 @@ +/* + * 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.temporarydisplay.dagger + +import javax.inject.Qualifier + +/** Status bar connectivity logs in table format. */ +@Qualifier +@MustBeDocumented +@kotlin.annotation.Retention(AnnotationRetention.RUNTIME) +annotation class ChipbarLog diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/dagger/TemporaryDisplayModule.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/dagger/TemporaryDisplayModule.kt new file mode 100644 index 0000000000000..cf0a1835c8e89 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/dagger/TemporaryDisplayModule.kt @@ -0,0 +1,37 @@ +/* + * 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.temporarydisplay.dagger + +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.log.LogBufferFactory +import com.android.systemui.plugins.log.LogBuffer +import dagger.Module +import dagger.Provides + +@Module +interface TemporaryDisplayModule { + @Module + companion object { + @JvmStatic + @Provides + @SysUISingleton + @ChipbarLog + fun provideChipbarLogBuffer(factory: LogBufferFactory): LogBuffer { + return factory.create("ChipbarLog", 40) + } + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt index fdeb3f5eb8577..ad19bc2a80e09 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt @@ -45,6 +45,7 @@ import com.android.systemui.statusbar.CommandQueue import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator +import com.android.systemui.temporarydisplay.chipbar.ChipbarLogger import com.android.systemui.temporarydisplay.chipbar.FakeChipbarCoordinator import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.any @@ -80,6 +81,7 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { @Mock private lateinit var configurationController: ConfigurationController @Mock private lateinit var falsingManager: FalsingManager @Mock private lateinit var falsingCollector: FalsingCollector + @Mock private lateinit var chipbarLogger: ChipbarLogger @Mock private lateinit var logger: MediaTttLogger @Mock private lateinit var mediaTttFlags: MediaTttFlags @Mock private lateinit var packageManager: PackageManager @@ -122,7 +124,7 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() { chipbarCoordinator = FakeChipbarCoordinator( context, - logger, + chipbarLogger, windowManager, fakeExecutor, accessibilityManager, diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayControllerTest.kt index 87ab607fad03a..91b5c35d96618 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayControllerTest.kt @@ -99,6 +99,18 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() { assertThat(windowParamsCaptor.value!!.title).isEqualTo("Fake Window Title") } + @Test + fun displayView_logged() { + underTest.displayView( + ViewInfo( + name = "name", + windowTitle = "Fake Window Title", + ) + ) + + verify(logger).logViewAddition("Fake Window Title") + } + @Test fun displayView_screenOff_screenWakes() { whenever(powerManager.isScreenOn).thenReturn(false) @@ -231,7 +243,7 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() { underTest.removeView(reason) verify(windowManager).removeView(any()) - verify(logger).logChipRemoval(reason) + verify(logger).logViewRemoval(reason) } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt index 13e9f608158e1..d155050ce932d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt @@ -43,20 +43,21 @@ class TemporaryViewLoggerTest : SysuiTestCase() { } @Test - fun logChipAddition_bufferHasLog() { - logger.logChipAddition() + fun logViewAddition_bufferHasLog() { + logger.logViewAddition("Test Window Title") val stringWriter = StringWriter() buffer.dump(PrintWriter(stringWriter), tailLength = 0) val actualString = stringWriter.toString() assertThat(actualString).contains(TAG) + assertThat(actualString).contains("Test Window Title") } @Test - fun logChipRemoval_bufferHasTagAndReason() { + fun logViewRemoval_bufferHasTagAndReason() { val reason = "test reason" - logger.logChipRemoval(reason) + logger.logViewRemoval(reason) val stringWriter = StringWriter() buffer.dump(PrintWriter(stringWriter), tailLength = 0) diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt index ce64d3a64b238..f64397325867c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt @@ -35,12 +35,12 @@ import com.android.systemui.common.shared.model.ContentDescription import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription import com.android.systemui.common.shared.model.Icon import com.android.systemui.common.shared.model.Text -import com.android.systemui.media.taptotransfer.common.MediaTttLogger import com.android.systemui.plugins.FalsingManager import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.any +import com.android.systemui.util.mockito.eq import com.android.systemui.util.time.FakeSystemClock import com.android.systemui.util.view.ViewUtil import com.google.common.truth.Truth.assertThat @@ -60,7 +60,7 @@ import org.mockito.MockitoAnnotations class ChipbarCoordinatorTest : SysuiTestCase() { private lateinit var underTest: FakeChipbarCoordinator - @Mock private lateinit var logger: MediaTttLogger + @Mock private lateinit var logger: ChipbarLogger @Mock private lateinit var accessibilityManager: AccessibilityManager @Mock private lateinit var configurationController: ConfigurationController @Mock private lateinit var powerManager: PowerManager @@ -331,6 +331,30 @@ class ChipbarCoordinatorTest : SysuiTestCase() { assertThat(chipbarView.getEndButton().visibility).isEqualTo(View.GONE) } + @Test + fun viewUpdates_logged() { + val drawable = context.getDrawable(R.drawable.ic_celebration)!! + underTest.displayView( + createChipbarInfo( + Icon.Loaded(drawable, contentDescription = ContentDescription.Loaded("loadedCD")), + Text.Loaded("title text"), + endItem = ChipbarEndItem.Loading, + ) + ) + + verify(logger).logViewUpdate(eq(WINDOW_TITLE), eq("title text"), any()) + + underTest.displayView( + createChipbarInfo( + Icon.Loaded(drawable, ContentDescription.Loaded("new CD")), + Text.Loaded("new title text"), + endItem = ChipbarEndItem.Error, + ) + ) + + verify(logger).logViewUpdate(eq(WINDOW_TITLE), eq("new title text"), any()) + } + private fun createChipbarInfo( startIcon: Icon, text: Text, diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/FakeChipbarCoordinator.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/FakeChipbarCoordinator.kt index 17d402319246b..574f70e7fddc1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/FakeChipbarCoordinator.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/FakeChipbarCoordinator.kt @@ -22,8 +22,6 @@ import android.view.ViewGroup import android.view.WindowManager import android.view.accessibility.AccessibilityManager import com.android.systemui.classifier.FalsingCollector -import com.android.systemui.media.taptotransfer.common.MediaTttLogger -import com.android.systemui.media.taptotransfer.receiver.MediaTttReceiverLogger import com.android.systemui.plugins.FalsingManager import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.policy.ConfigurationController @@ -33,7 +31,7 @@ import com.android.systemui.util.view.ViewUtil /** A fake implementation of [ChipbarCoordinator] for testing. */ class FakeChipbarCoordinator( context: Context, - @MediaTttReceiverLogger logger: MediaTttLogger, + logger: ChipbarLogger, windowManager: WindowManager, mainExecutor: DelayableExecutor, accessibilityManager: AccessibilityManager,