Merge "Listen to USB_STATE events in the StylusUsbFirmwareController." into udc-qpr-dev am: a928e9202f

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24446427

Change-Id: Ic6326aaf9622027f8347d643b99565165e2b3efc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Vania Januar
2023-08-17 08:44:37 +00:00
committed by Automerger Merge Worker
2 changed files with 29 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ public class UsbStylusBroadcastReceiver extends BroadcastReceiver {
final IntentFilter intentFilter = new IntentFilter(); final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
intentFilter.addAction(UsbManager.ACTION_USB_STATE);
final Intent intent = mContext.registerReceiver(this, intentFilter); final Intent intent = mContext.registerReceiver(this, intentFilter);
if (intent != null) { if (intent != null) {
onReceive(mContext, intent); onReceive(mContext, intent);

View File

@@ -95,4 +95,32 @@ public class UsbStylusBroadcastReceiverTest {
verifyNoMoreInteractions(mListener); verifyNoMoreInteractions(mListener);
} }
@Test
public void onReceive_usbDeviceStateStylus_invokeCallback() {
when(mFeatureFactory.mStylusFeatureProvider.isUsbFirmwareUpdateEnabled(any()))
.thenReturn(true);
final UsbDevice usbDevice = mock(UsbDevice.class);
final Intent intent = new Intent();
intent.setAction(UsbManager.ACTION_USB_STATE);
intent.putExtra(UsbManager.EXTRA_DEVICE, usbDevice);
mReceiver.onReceive(mContext, intent);
verify(mListener).onUsbStylusConnectionChanged(usbDevice, false);
}
@Test
public void onReceive_usbDeviceStateNotStylus_doesNotInvokeCallback() {
when(mFeatureFactory.mStylusFeatureProvider.isUsbFirmwareUpdateEnabled(any()))
.thenReturn(false);
final UsbDevice usbDevice = mock(UsbDevice.class);
final Intent intent = new Intent();
intent.setAction(UsbManager.ACTION_USB_STATE);
intent.putExtra(UsbManager.EXTRA_DEVICE, usbDevice);
mReceiver.onReceive(mContext, intent);
verifyNoMoreInteractions(mListener);
}
} }