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