[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
This commit is contained in:
Caitlin Shkuratov
2022-10-24 21:32:31 +00:00
parent 13c529d3d9
commit 4b490fbc94
12 changed files with 180 additions and 26 deletions

View File

@@ -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,

View File

@@ -121,7 +121,7 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
"com.android.systemui:${newInfo.wakeReason}",
)
}
logger.logChipAddition()
logger.logViewAddition(newInfo.windowTitle)
inflateAndUpdateView(newInfo)
}
@@ -187,7 +187,7 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
val currentView = currentDisplayInfo.view
animateViewOut(currentView) { windowManager.removeView(currentView) }
logger.logChipRemoval(removalReason)
logger.logViewRemoval(removalReason)
configurationController.removeCallback(displayScaleListener)
// Re-set to null immediately (instead as part of the animation end runnable) so
// that if a new view event comes in while this view is animating out, we still display the

View File

@@ -24,13 +24,13 @@ open class TemporaryViewLogger(
internal val buffer: LogBuffer,
internal val tag: String,
) {
/** Logs that we added the chip to a new window. */
fun logChipAddition() {
buffer.log(tag, LogLevel.DEBUG, {}, { "Chip added" })
/** Logs that we added the view in a window titled [windowTitle]. */
fun logViewAddition(windowTitle: String) {
buffer.log(tag, LogLevel.DEBUG, { str1 = windowTitle }, { "View added. window=$str1" })
}
/** Logs that we removed the chip for the given [reason]. */
fun logChipRemoval(reason: String) {
buffer.log(tag, LogLevel.DEBUG, { str1 = reason }, { "Chip removed due to: $str1" })
fun logViewRemoval(reason: String) {
buffer.log(tag, LogLevel.DEBUG, { str1 = reason }, { "View removed due to: $str1" })
}
}

View File

@@ -38,8 +38,6 @@ import com.android.systemui.common.ui.binder.IconViewBinder
import com.android.systemui.common.ui.binder.TextViewBinder
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
import com.android.systemui.media.taptotransfer.sender.MediaTttSenderLogger
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.statusbar.policy.ConfigurationController
@@ -63,14 +61,11 @@ import javax.inject.Inject
* Only one chipbar may be shown at a time.
* TODO(b/245610654): Should we just display whichever chipbar was most recently requested, or do we
* need to maintain a priority ordering?
*
* TODO(b/245610654): Remove all media-related items from this class so it's just for generic
* chipbars.
*/
@SysUISingleton
open class ChipbarCoordinator @Inject constructor(
context: Context,
@MediaTttSenderLogger logger: MediaTttLogger,
logger: ChipbarLogger,
windowManager: WindowManager,
@Main mainExecutor: DelayableExecutor,
accessibilityManager: AccessibilityManager,
@@ -80,7 +75,7 @@ open class ChipbarCoordinator @Inject constructor(
private val falsingCollector: FalsingCollector,
private val viewUtil: ViewUtil,
private val vibratorHelper: VibratorHelper,
) : TemporaryViewDisplayController<ChipbarInfo, MediaTttLogger>(
) : TemporaryViewDisplayController<ChipbarInfo, ChipbarLogger>(
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)

View File

@@ -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" }
)
}
}

View File

@@ -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

View File

@@ -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)
}
}
}

View File

@@ -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,

View File

@@ -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

View File

@@ -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)

View File

@@ -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,

View File

@@ -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,