Listen to USB_STATE events in the StylusUsbFirmwareController.
Test: UsbStylusBroadcastReceiverTest Bug: 288850921 Change-Id: I415e5ca04d371a235eff31327b086d568bcc00f0
This commit is contained in:
@@ -41,6 +41,7 @@ public class UsbStylusBroadcastReceiver extends BroadcastReceiver {
|
||||
final IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
|
||||
intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
|
||||
intentFilter.addAction(UsbManager.ACTION_USB_STATE);
|
||||
final Intent intent = mContext.registerReceiver(this, intentFilter);
|
||||
if (intent != null) {
|
||||
onReceive(mContext, intent);
|
||||
|
@@ -95,4 +95,32 @@ public class UsbStylusBroadcastReceiverTest {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user