Loading packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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, Loading Loading @@ -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) Loading @@ -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) Loading packages/SystemUI/src/com/android/systemui/stylus/StylusUiEvent.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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 } packages/SystemUI/tests/src/com/android/systemui/stylus/StylusManagerTest.kt +65 −5 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading @@ -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) Loading Loading @@ -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() Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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) Loading @@ -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) Loading Loading
packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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, Loading Loading @@ -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) Loading @@ -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) Loading
packages/SystemUI/src/com/android/systemui/stylus/StylusUiEvent.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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 }
packages/SystemUI/tests/src/com/android/systemui/stylus/StylusManagerTest.kt +65 −5 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading @@ -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) Loading Loading @@ -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() Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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) Loading Loading @@ -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) Loading @@ -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) Loading