Merge "UIEvent logging for bluetooth stylus connection."

This commit is contained in:
Vania Januar
2023-02-09 14:05:44 +00:00
committed by Android (Google) Code Review
3 changed files with 72 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ import android.os.Handler
import android.util.ArrayMap
import android.util.Log
import android.view.InputDevice
import com.android.internal.logging.UiEventLogger
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.flags.FeatureFlags
@@ -47,6 +48,7 @@ constructor(
@Background private val handler: Handler,
@Background private val executor: Executor,
private val featureFlags: FeatureFlags,
private val uiEventLogger: UiEventLogger,
) :
InputManager.InputDeviceListener,
InputManager.InputDeviceBatteryListener,
@@ -186,6 +188,7 @@ constructor(
}
private fun onStylusBluetoothConnected(btAddress: String) {
uiEventLogger.log(StylusUiEvent.BLUETOOTH_STYLUS_CONNECTED)
val device: BluetoothDevice = bluetoothAdapter?.getRemoteDevice(btAddress) ?: return
try {
bluetoothAdapter.addOnMetadataChangedListener(device, executor, this)
@@ -195,6 +198,7 @@ constructor(
}
private fun onStylusBluetoothDisconnected(btAddress: String) {
uiEventLogger.log(StylusUiEvent.BLUETOOTH_STYLUS_DISCONNECTED)
val device: BluetoothDevice = bluetoothAdapter?.getRemoteDevice(btAddress) ?: return
try {
bluetoothAdapter.removeOnMetadataChangedListener(device, this)

View File

@@ -29,7 +29,9 @@ enum class StylusUiEvent(private val _id: Int) : UiEventLogger.UiEventEnum {
@UiEvent(doc = "UIEvent for Toast shown when stylus started charging")
STYLUS_STARTED_CHARGING(1302),
@UiEvent(doc = "UIEvent for Toast shown when stylus stopped charging")
STYLUS_STOPPED_CHARGING(1303);
STYLUS_STOPPED_CHARGING(1303),
@UiEvent(doc = "UIEvent for bluetooth stylus connected") BLUETOOTH_STYLUS_CONNECTED(1304),
@UiEvent(doc = "UIEvent for bluetooth stylus disconnected") BLUETOOTH_STYLUS_DISCONNECTED(1305);
override fun getId() = _id
}

View File

@@ -23,6 +23,7 @@ import android.os.Handler
import android.testing.AndroidTestingRunner
import android.view.InputDevice
import androidx.test.filters.SmallTest
import com.android.internal.logging.UiEventLogger
import com.android.systemui.SysuiTestCase
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
@@ -53,8 +54,11 @@ class StylusManagerTest : SysuiTestCase() {
@Mock lateinit var bluetoothAdapter: BluetoothAdapter
@Mock lateinit var bluetoothDevice: BluetoothDevice
@Mock lateinit var handler: Handler
@Mock lateinit var featureFlags: FeatureFlags
@Mock lateinit var uiEventLogger: UiEventLogger
@Mock lateinit var stylusCallback: StylusManager.StylusCallback
@Mock lateinit var otherStylusCallback: StylusManager.StylusCallback
@@ -75,7 +79,15 @@ class StylusManagerTest : SysuiTestCase() {
}
stylusManager =
StylusManager(mContext, inputManager, bluetoothAdapter, handler, EXECUTOR, featureFlags)
StylusManager(
mContext,
inputManager,
bluetoothAdapter,
handler,
EXECUTOR,
featureFlags,
uiEventLogger
)
whenever(otherDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(false)
whenever(stylusDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(true)
@@ -104,7 +116,15 @@ class StylusManagerTest : SysuiTestCase() {
@Test
fun startListener_hasNotStarted_registersInputDeviceListener() {
stylusManager =
StylusManager(mContext, inputManager, bluetoothAdapter, handler, EXECUTOR, featureFlags)
StylusManager(
mContext,
inputManager,
bluetoothAdapter,
handler,
EXECUTOR,
featureFlags,
uiEventLogger
)
stylusManager.startListener()
@@ -121,7 +141,15 @@ class StylusManagerTest : SysuiTestCase() {
@Test
fun onInputDeviceAdded_hasNotStarted_doesNothing() {
stylusManager =
StylusManager(mContext, inputManager, bluetoothAdapter, handler, EXECUTOR, featureFlags)
StylusManager(
mContext,
inputManager,
bluetoothAdapter,
handler,
EXECUTOR,
featureFlags,
uiEventLogger
)
stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
@@ -203,7 +231,15 @@ class StylusManagerTest : SysuiTestCase() {
@Test
fun onInputDeviceChanged_hasNotStarted_doesNothing() {
stylusManager =
StylusManager(mContext, inputManager, bluetoothAdapter, handler, EXECUTOR, featureFlags)
StylusManager(
mContext,
inputManager,
bluetoothAdapter,
handler,
EXECUTOR,
featureFlags,
uiEventLogger
)
stylusManager.onInputDeviceChanged(STYLUS_DEVICE_ID)
@@ -268,7 +304,15 @@ class StylusManagerTest : SysuiTestCase() {
@Test
fun onInputDeviceRemoved_hasNotStarted_doesNothing() {
stylusManager =
StylusManager(mContext, inputManager, bluetoothAdapter, handler, EXECUTOR, featureFlags)
StylusManager(
mContext,
inputManager,
bluetoothAdapter,
handler,
EXECUTOR,
featureFlags,
uiEventLogger
)
stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
stylusManager.onInputDeviceRemoved(STYLUS_DEVICE_ID)
@@ -336,6 +380,13 @@ class StylusManagerTest : SysuiTestCase() {
verify(bluetoothAdapter, never()).addOnMetadataChangedListener(any(), any(), any())
}
@Test
fun onStylusBluetoothConnected_logsEvent() {
stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
verify(uiEventLogger, times(1)).log(StylusUiEvent.BLUETOOTH_STYLUS_CONNECTED)
}
@Test
fun onStylusBluetoothDisconnected_unregistersMetadataListener() {
stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
@@ -345,6 +396,15 @@ class StylusManagerTest : SysuiTestCase() {
verify(bluetoothAdapter, times(1)).removeOnMetadataChangedListener(any(), any())
}
@Test
fun onStylusBluetoothDisconnected_logsEvent() {
stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
stylusManager.onInputDeviceRemoved(BT_STYLUS_DEVICE_ID)
verify(uiEventLogger, times(1)).log(StylusUiEvent.BLUETOOTH_STYLUS_DISCONNECTED)
}
@Test
fun onMetadataChanged_multipleRegisteredBatteryCallbacks_executesAll() {
stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)